228 |
228 |
229 family:familyString face:faceString style:styleString size:sizeNum encoding:encodingSym |
229 family:familyString face:faceString style:styleString size:sizeNum encoding:encodingSym |
230 "returns a font for given family, face, style, size and encoding. |
230 "returns a font for given family, face, style, size and encoding. |
231 The returned font is not associated to a specific device" |
231 The returned font is not associated to a specific device" |
232 |
232 |
|
233 ^ self |
|
234 family:familyString |
|
235 face:faceString |
|
236 style:styleString |
|
237 size:sizeNum |
|
238 pixelSize:nil |
|
239 encoding:encodingSym |
|
240 ! |
|
241 |
|
242 family:familyString face:faceString style:styleString size:sizeArgOrNil pixelSize:pixelSizeArgOrNil encoding:encodingSym |
|
243 "returns a font for given family, face, style, size and encoding. |
|
244 The returned font is not associated to a specific device. |
|
245 Either size, or pixelSize must be non-nil (points vs. pixels)" |
|
246 |
233 |family newFont| |
247 |family newFont| |
234 |
248 |
235 (familyString at:1) isUppercase ifTrue:[ |
249 (familyString at:1) isUppercase ifTrue:[ |
236 family := familyString asLowercase |
250 family := familyString asLowercase |
237 ] ifFalse:[ |
251 ] ifFalse:[ |
238 family := familyString |
252 family := familyString |
239 ]. |
253 ]. |
240 |
254 |
241 "look if this font is already known on the default device |
|
242 (the most common case)" |
|
243 |
|
244 Display notNil ifTrue:[ |
|
245 Display deviceFonts do:[:aFont | |
|
246 (family = aFont family) ifTrue:[ |
|
247 (faceString = aFont face) ifTrue:[ |
|
248 (styleString = aFont style |
|
249 or:[styleString = 'italic' and:[aFont style = 'oblique']]) ifTrue:[ |
|
250 (aFont size = sizeNum) ifTrue:[ |
|
251 (encodingSym isNil or:[aFont encoding = encodingSym]) ifTrue:[ |
|
252 ^ aFont |
|
253 ] |
|
254 ] |
|
255 ] |
|
256 ] |
|
257 ] |
|
258 ] |
|
259 ]. |
|
260 |
|
261 newFont := self basicNew |
255 newFont := self basicNew |
262 setFamily:familyString |
256 setFamily:familyString |
263 face:faceString |
257 face:faceString |
264 style:styleString |
258 style:styleString |
265 size:sizeNum |
259 size:sizeArgOrNil |
|
260 pixelSize:pixelSizeArgOrNil |
266 encoding:encodingSym |
261 encoding:encodingSym |
267 device:nil. |
262 device:nil. |
|
263 |
|
264 "look if this font is already known on the default device (the most common case)" |
|
265 |
|
266 Display notNil ifTrue:[ |
|
267 Display deviceFonts do:[:aFont | |
|
268 (newFont sameDeviceFontAs:aFont) ifTrue:[ |
|
269 ^ aFont |
|
270 ] |
|
271 ] |
|
272 ]. |
268 |
273 |
269 ^ newFont |
274 ^ newFont |
270 |
275 |
271 "Modified: / 26.9.1999 / 13:49:45 / cg" |
276 "Modified: / 26.9.1999 / 13:49:45 / cg" |
272 ! ! |
277 ! ! |
334 |
339 |
335 onDevice:aDevice |
340 onDevice:aDevice |
336 "create a new Font representing the same font as |
341 "create a new Font representing the same font as |
337 myself on aDevice; if one already exists, return the one." |
342 myself on aDevice; if one already exists, return the one." |
338 |
343 |
339 |newFont rep nearestFont| |
344 |newFont rep| |
340 |
345 |
341 "if I am already assigned to that device ..." |
346 "if I am already assigned to that device ..." |
342 (device == aDevice) ifTrue:[^ self]. |
347 (device == aDevice) ifTrue:[^ self]. |
343 |
348 |
344 aDevice isNil ifTrue:[^ self]. |
349 aDevice isNil ifTrue:[^ self]. |
345 |
350 |
346 aDevice deviceFonts do:[:aFont | |
351 aDevice deviceFonts do:[:aFont | |
347 (family = aFont family) ifTrue:[ |
352 (self sameDeviceFontAs:aFont) ifTrue:[ |
348 (face = aFont face) ifTrue:[ |
353 ^ aFont |
349 (style = aFont style) ifTrue:[ |
354 ]. |
350 (encoding isNil or:[encoding = aFont encoding]) ifTrue:[ |
|
351 (size = aFont size) ifTrue:[ |
|
352 ^ aFont |
|
353 ]. |
|
354 "/ nearestFont isNil ifTrue:[ |
|
355 "/ "font exists, but has different size, |
|
356 "/ remember the font with the nearest size" |
|
357 "/ nearestFont = aFont. |
|
358 "/ ] ifFalse:[ |
|
359 "/ ((nearestFont size - size) abs > (aFont size - size) abs) ifTrue:[ |
|
360 "/ nearestFont := aFont. |
|
361 "/ ]. |
|
362 "/ ]. |
|
363 ] |
|
364 ] |
|
365 ] |
|
366 ] |
|
367 ]. |
355 ]. |
368 |
356 |
369 newFont := self onDevice:aDevice ifAbsent:nil. |
357 newFont := self onDevice:aDevice ifAbsent:nil. |
370 newFont isNil ifTrue:[ |
358 newFont isNil ifTrue:[ |
371 "oops did not work - (device has no such font)" |
359 "oops did not work - (device has no such font)" |
410 |id| |
404 |id| |
411 |
405 |
412 "receiver was not associated - do it now" |
406 "receiver was not associated - do it now" |
413 device isNil ifTrue:[ |
407 device isNil ifTrue:[ |
414 "ask that device for the font" |
408 "ask that device for the font" |
415 id := aDevice getFontWithFamily:family face:face style:style size:size encoding:encoding. |
409 id := aDevice |
|
410 getFontWithFamily:family |
|
411 face:face |
|
412 style:style |
|
413 size:size |
|
414 pixelSize:pixelSize |
|
415 encoding:encoding. |
416 id isNil ifTrue:[ |
416 id isNil ifTrue:[ |
417 "oops did not work - (device has no such font)" |
417 "oops did not work - (device has no such font)" |
418 |
418 |
419 ^ exceptionBlock value |
419 ^ exceptionBlock value |
420 ]. |
420 ]. |
440 |
440 |
441 "try font with smaller size" |
441 "try font with smaller size" |
442 |
442 |
443 trySize := size - 1. |
443 trySize := size - 1. |
444 [ |
444 [ |
445 id := aDevice getFontWithFamily:family |
445 id := aDevice |
446 face:face |
446 getFontWithFamily:family |
447 style:style |
447 face:face |
448 size:trySize |
448 style:style |
449 encoding:encoding. |
449 size:trySize |
|
450 pixelSize:pixelSize |
|
451 encoding:encoding. |
450 ] doWhile:[id isNil and:[trySize := trySize - 1. trySize > 4]]. |
452 ] doWhile:[id isNil and:[trySize := trySize - 1. trySize > 4]]. |
451 |
453 |
452 id notNil ifTrue:[ |
454 id notNil ifTrue:[ |
453 ('Font [info]: use alternative size ', trySize printString, ' for ' , (self userFriendlyName)) infoPrintCR. |
455 ('Font [info]: use alternative size ', trySize printString, ' for ' , (self userFriendlyName)) infoPrintCR. |
454 ] ifFalse:[ |
456 ] ifFalse:[ |
455 alternative := Replacements at:family asLowercase ifAbsent:nil. |
457 alternative := Replacements at:family asLowercase ifAbsent:nil. |
456 alternative notNil ifTrue:[ |
458 alternative notNil ifTrue:[ |
457 trySize := size - 1. |
459 trySize := size - 1. |
458 [ |
460 [ |
459 id := aDevice getFontWithFamily:alternative |
461 id := aDevice |
460 face:face |
462 getFontWithFamily:alternative |
461 style:style |
463 face:face |
462 size:trySize |
464 style:style |
463 encoding:encoding. |
465 size:trySize |
|
466 pixelSize:pixelSize |
|
467 encoding:encoding. |
464 ] doWhile:[id isNil and:[trySize := trySize - 1. trySize > 4]]. |
468 ] doWhile:[id isNil and:[trySize := trySize - 1. trySize > 4]]. |
465 ]. |
469 ]. |
466 id notNil ifTrue:[ |
470 id notNil ifTrue:[ |
467 ('Font [info]: use alternative for ' , (self userFriendlyName)) infoPrintCR. |
471 ('Font [info]: use alternative for ' , (self userFriendlyName)) infoPrintCR. |
468 ] ifFalse:[ |
472 ] ifFalse:[ |
477 ]. |
481 ]. |
478 |
482 |
479 "/ if there already is a device font for that replacement, return that one |
483 "/ if there already is a device font for that replacement, return that one |
480 "/ to avoid allocating multiple replacements for the same font |
484 "/ to avoid allocating multiple replacements for the same font |
481 aDevice deviceFonts do:[:aFont | |
485 aDevice deviceFonts do:[:aFont | |
482 (family = aFont family) ifTrue:[ |
486 (self sameDeviceFontAs:aFont) ifTrue:[ |
483 (face = aFont face) ifTrue:[ |
487 ^ aFont |
484 (style = aFont style) ifTrue:[ |
|
485 (encoding isNil or:[encoding = aFont encoding]) ifTrue:[ |
|
486 (size = aFont size) ifTrue:[ |
|
487 ^ aFont |
|
488 ]. |
|
489 ] |
|
490 ] |
|
491 ] |
|
492 ] |
488 ] |
493 ]. |
489 ]. |
494 |
490 |
495 f := self class basicNew. |
491 f := self class basicNew. |
496 |
492 |
497 f setFamily:family face:face style:style size:size encoding:encoding device:aDevice. |
493 f setFamily:family face:face style:style size:size pixelSize:pixelSize encoding:encoding device:aDevice. |
498 f setDevice:aDevice fontId:id. |
494 f setDevice:aDevice fontId:id. |
499 f getFontInfos. |
495 f getFontInfos. |
500 aDevice registerFont:f. |
496 aDevice registerFont:f. |
501 ^ f |
497 ^ f |
502 |
498 |
683 device := aDevice |
679 device := aDevice |
684 |
680 |
685 "Modified: 20.4.1996 / 23:26:56 / cg" |
681 "Modified: 20.4.1996 / 23:26:56 / cg" |
686 ! |
682 ! |
687 |
683 |
|
684 setFamily:familyString face:faceString style:styleString size:sizeArgOrNil pixelSize:pixelSizeArgOrNil encoding:encodingSym device:aDevice |
|
685 "set my instance attributes" |
|
686 |
|
687 family := familyString. |
|
688 face := faceString. |
|
689 style := styleString. |
|
690 size := sizeArgOrNil. |
|
691 pixelSize := pixelSizeArgOrNil. |
|
692 encoding := encodingSym. |
|
693 device := aDevice |
|
694 |
|
695 "Modified: 20.4.1996 / 23:26:56 / cg" |
|
696 ! |
|
697 |
688 setFontId:aFontId |
698 setFontId:aFontId |
689 "set my font handle" |
699 "set my font handle" |
690 |
700 |
691 fontId := aFontId |
701 fontId := aFontId |
692 |
702 |