equal
deleted
inserted
replaced
1 "{ Package: 'stx:libview' }" |
1 "{ Package: 'stx:libview' }" |
2 |
2 |
3 FontDescription subclass:#XftFontDescription |
3 FontDescription subclass:#XftFontDescription |
4 instanceVariableNames:'device fontId drawId' |
4 instanceVariableNames:'device fontId drawId closestFont' |
5 classVariableNames:'FC_FAMILY FC_STYLE FC_SLANT FC_WEIGHT FC_SIZE FC_ASPECT |
5 classVariableNames:'FC_FAMILY FC_STYLE FC_SLANT FC_WEIGHT FC_SIZE FC_ASPECT |
6 FC_PIXEL_SIZE FC_SPACING FC_FOUNDRY FC_ANTIALIAS FC_HINTING |
6 FC_PIXEL_SIZE FC_SPACING FC_FOUNDRY FC_ANTIALIAS FC_HINTING |
7 FC_HINT_STYLE FC_VERTICAL_LAYOUT FC_AUTOHINT FC_WIDTH FC_FILE |
7 FC_HINT_STYLE FC_VERTICAL_LAYOUT FC_AUTOHINT FC_WIDTH FC_FILE |
8 FC_INDEX FC_FT_FACE FC_RASTERIZER FC_OUTLINE FC_SCALABLE FC_SCALE |
8 FC_INDEX FC_FT_FACE FC_RASTERIZER FC_OUTLINE FC_SCALABLE FC_SCALE |
9 FC_DPI FC_RGBA FC_MINSPACE FC_SOURCE FC_CHARSET FC_LANG |
9 FC_DPI FC_RGBA FC_MINSPACE FC_SOURCE FC_CHARSET FC_LANG |
319 top open. |
319 top open. |
320 |
320 |
321 "Created: / 30-12-2013 / 19:49:05 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
321 "Created: / 30-12-2013 / 19:49:05 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
322 ! ! |
322 ! ! |
323 |
323 |
|
324 !XftFontDescription methodsFor:'accessing-private'! |
|
325 |
|
326 getDevice |
|
327 |
|
328 ^ device |
|
329 |
|
330 "Created: / 02-01-2014 / 23:22:39 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
331 ! |
|
332 |
|
333 getFontId |
|
334 |
|
335 ^ fontId |
|
336 |
|
337 "Created: / 02-01-2014 / 23:29:04 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
338 ! ! |
|
339 |
324 !XftFontDescription methodsFor:'displaying'! |
340 !XftFontDescription methodsFor:'displaying'! |
325 |
341 |
326 displayString:aString from:index1 to:index2 x:x y:y in:aGC opaque:opaque |
342 displayString:aString from:index1 to:index2 x:x y:y in:aGC opaque:opaque |
327 "display a partial string at some position in aGC." |
343 "display a partial string at some position in aGC." |
328 |
344 |
379 |
395 |
380 (aGraphicsDevice isNil and:[device notNil]) ifTrue:[ |
396 (aGraphicsDevice isNil and:[device notNil]) ifTrue:[ |
381 ^ self |
397 ^ self |
382 ]. |
398 ]. |
383 |
399 |
|
400 (closestFont notNil and:[closestFont getDevice == aGraphicsDevice]) ifTrue:[ |
|
401 ^ closestFont onDevice: aGraphicsDevice. |
|
402 ]. |
|
403 |
384 aGraphicsDevice deviceFonts do:[:aFont | |
404 aGraphicsDevice deviceFonts do:[:aFont | |
385 (self sameDeviceFontAs:aFont) ifTrue:[ |
405 (self sameDeviceFontAs:aFont) ifTrue:[ |
386 ^ aFont |
406 ^ aFont |
387 ]. |
407 ]. |
388 ]. |
408 ]. |
|
409 |
389 |
410 |
390 [ |
411 [ |
391 myPatternId := self xftPatternCreate. |
412 myPatternId := self xftPatternCreate. |
392 self xftPatternAdd: myPatternId attribute: FC_FAMILY value: family. |
413 self xftPatternAdd: myPatternId attribute: FC_FAMILY value: family. |
393 pixelSize notNil ifTrue:[ |
414 pixelSize notNil ifTrue:[ |
401 newFontId := self xftFontOpenPattern: aGraphicsDevice displayId pattern: myPatternId. |
422 newFontId := self xftFontOpenPattern: aGraphicsDevice displayId pattern: myPatternId. |
402 newFontId notNil ifTrue:[ |
423 newFontId notNil ifTrue:[ |
403 "/ Good, this font exist!! |
424 "/ Good, this font exist!! |
404 fontId := newFontId. |
425 fontId := newFontId. |
405 device := aGraphicsDevice. |
426 device := aGraphicsDevice. |
406 self shouldImplement. "/ Register font... |
427 aGraphicsDevice registerFont:self. |
407 ^ self. |
428 ^ self. |
408 ] ifFalse:[ |
429 ] ifFalse:[ |
409 | family size | |
|
410 closestPatternId1 := self xftFontMatch: aGraphicsDevice displayId screen: aGraphicsDevice screen pattern: myPatternId. |
430 closestPatternId1 := self xftFontMatch: aGraphicsDevice displayId screen: aGraphicsDevice screen pattern: myPatternId. |
411 closestPatternId1 isNil ifTrue:[ |
431 closestPatternId1 isNil ifTrue:[ |
412 self error: 'No font matches'. |
432 self error: 'No font matches'. |
413 ]. |
433 ]. |
414 " |
434 " |
420 "/ !!!!!!!! closestPatternId is no longer valid !!!!!!!! |
440 "/ !!!!!!!! closestPatternId is no longer valid !!!!!!!! |
421 closestPatternId1 := nil. |
441 closestPatternId1 := nil. |
422 newFontId isNil ifTrue:[ |
442 newFontId isNil ifTrue:[ |
423 self error: 'Pattern matched, but font could be open (should not happen)'. |
443 self error: 'Pattern matched, but font could be open (should not happen)'. |
424 ]. |
444 ]. |
425 ^ self class new |
445 "/ Search for existing registered font. Note, that XftFont instances |
426 setDevice: aGraphicsDevice patternId: closestPatternId2 fontId: newFontId; |
446 "/ are shared (and refcounted) so newFontId = aFont getFontId is enough |
427 yourself. |
447 "/ to check whether some other font instance represents the same font... |
|
448 aGraphicsDevice deviceFonts do:[:aFont | |
|
449 ((self class == aFont class) and:[ newFontId = aFont getFontId ]) ifTrue:[ |
|
450 closestFont := aFont. |
|
451 ^ closestFont |
|
452 ]. |
|
453 ]. |
|
454 |
|
455 closestFont := self class new |
|
456 setDevice: aGraphicsDevice patternId: closestPatternId2 fontId: newFontId; |
|
457 yourself. |
|
458 aGraphicsDevice registerFont: closestFont. |
|
459 ^ closestFont |
428 ]. |
460 ]. |
429 ] ensure:[ |
461 ] ensure:[ |
430 self xftPatternDestroy: myPatternId. |
462 self xftPatternDestroy: myPatternId. |
431 self xftPatternDestroy: closestPatternId1. |
463 self xftPatternDestroy: closestPatternId1. |
432 self xftPatternDestroy: closestPatternId2. |
464 self xftPatternDestroy: closestPatternId2. |
435 " |
467 " |
436 (XftFontDescription family:'monospace' size:16) onDevice:Screen current |
468 (XftFontDescription family:'monospace' size:16) onDevice:Screen current |
437 " |
469 " |
438 |
470 |
439 "Modified: / 14-04-1997 / 18:22:31 / cg" |
471 "Modified: / 14-04-1997 / 18:22:31 / cg" |
440 "Modified: / 30-12-2013 / 12:41:15 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
472 "Modified: / 02-01-2014 / 23:43:27 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
441 ! |
473 ! |
442 |
474 |
443 onDevice:aDevice ifAbsent:exceptionBlock |
475 onDevice:aWorkstation ifAbsent:aBlock |
444 "Create a new XftFont representing the same font as |
476 "Create a new XftFont representing the same font as |
445 myself on aDevice. This does NOT try to look for existing |
477 myself on aWorkstation. This does NOT try to look for existing |
446 or replacement fonts (i.e. can be used to get physical fonts)." |
478 or replacement fonts (i.e. can be used to get physical fonts)." |
447 |
479 |
448 ^ self shouldImplement |
480 self shouldImplement |
449 |
481 |
450 "Modified: / 20-12-2013 / 10:54:56 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
482 "Modified: / 02-01-2014 / 23:15:27 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
451 ! ! |
483 ! ! |
452 |
484 |
453 !XftFontDescription methodsFor:'initialization'! |
485 !XftFontDescription methodsFor:'initialization'! |
454 |
486 |
455 setDevice: deviceArg patternId: patternIdArg fontId: fontIdArg |
487 setDevice: deviceArg patternId: patternIdArg fontId: fontIdArg |
1228 ! ! |
1260 ! ! |
1229 |
1261 |
1230 !XftFontDescription class methodsFor:'documentation'! |
1262 !XftFontDescription class methodsFor:'documentation'! |
1231 |
1263 |
1232 version |
1264 version |
1233 ^ '$Header: /cvs/stx/stx/libview/XftFontDescription.st,v 1.11 2014-01-01 18:24:58 cg Exp $' |
1265 ^ '$Header: /cvs/stx/stx/libview/XftFontDescription.st,v 1.12 2014-01-02 22:54:56 vrany Exp $' |
1234 ! |
1266 ! |
1235 |
1267 |
1236 version_CVS |
1268 version_CVS |
1237 ^ '$Header: /cvs/stx/stx/libview/XftFontDescription.st,v 1.11 2014-01-01 18:24:58 cg Exp $' |
1269 ^ '$Header: /cvs/stx/stx/libview/XftFontDescription.st,v 1.12 2014-01-02 22:54:56 vrany Exp $' |
1238 ! ! |
1270 ! ! |
1239 |
1271 |
1240 |
1272 |
1241 XftFontDescription initialize! |
1273 XftFontDescription initialize! |