0
|
1 |
"
|
6
|
2 |
COPYRIGHT (c) 1992 by Claus Gittinger
|
71
|
3 |
All Rights Reserved
|
0
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
|
13 |
Object subclass:#Font
|
|
14 |
instanceVariableNames:'family face style size encoding
|
71
|
15 |
device fontId replacementFont
|
|
16 |
ascent descent height width isFixedWidth
|
|
17 |
minWidth maxWidth'
|
23
|
18 |
classVariableNames:'Lobby Replacements'
|
0
|
19 |
poolDictionaries:''
|
|
20 |
category:'Graphics-Support'
|
|
21 |
!
|
|
22 |
|
|
23 |
Font comment:'
|
6
|
24 |
COPYRIGHT (c) 1992 by Claus Gittinger
|
71
|
25 |
All Rights Reserved
|
54
|
26 |
|
86
|
27 |
$Header: /cvs/stx/stx/libview/Font.st,v 1.12 1994-11-28 21:00:49 claus Exp $
|
0
|
28 |
'!
|
|
29 |
|
|
30 |
!Font class methodsFor:'documentation'!
|
|
31 |
|
46
|
32 |
copyright
|
|
33 |
"
|
|
34 |
COPYRIGHT (c) 1992 by Claus Gittinger
|
71
|
35 |
All Rights Reserved
|
46
|
36 |
|
|
37 |
This software is furnished under a license and may be used
|
|
38 |
only in accordance with the terms of that license and with the
|
|
39 |
inclusion of the above copyright notice. This software may not
|
|
40 |
be provided or otherwise made available to, or used by, any
|
|
41 |
other person. No title to or ownership of the software is
|
|
42 |
hereby transferred.
|
|
43 |
"
|
|
44 |
!
|
0
|
45 |
|
46
|
46 |
version
|
|
47 |
"
|
86
|
48 |
$Header: /cvs/stx/stx/libview/Font.st,v 1.12 1994-11-28 21:00:49 claus Exp $
|
46
|
49 |
"
|
|
50 |
!
|
0
|
51 |
|
46
|
52 |
documentation
|
|
53 |
"
|
|
54 |
Font represents fonts in a device independent manner; after being
|
|
55 |
created using 'Font family:family face:face style:style size:size',
|
|
56 |
the returned font is not associated to a specific device.
|
0
|
57 |
|
46
|
58 |
To get a device font, any font can be sent the message
|
|
59 |
'aFont on:aDevice' which returns an instance of Font which is
|
|
60 |
associated to a device (it returns the receiver, if that is already
|
|
61 |
associated to that device).
|
0
|
62 |
|
46
|
63 |
For proper operation, each graphics operation working with fonts
|
|
64 |
must get a device font before doing the draw.
|
|
65 |
Most draw methods in DeviceDrawable do that automatically for you,
|
|
66 |
before doing the draw.
|
|
67 |
|
81
|
68 |
However, some operations require explicit conversion to a device font
|
|
69 |
before being allowed. For example, a query for a fonts height (in device
|
|
70 |
units) can only be done if the font being asked is associated to
|
|
71 |
a device (which should be clear, since a 'courier-roman-12' font may
|
|
72 |
have a different number of pixels on a 75dpi vs. a 120dpi display. And
|
|
73 |
a total number of device units on a 600dpi laser printer.
|
|
74 |
Thus, to query a font for its height (or ascent, or descent, or width),
|
|
75 |
use something like:
|
|
76 |
|
|
77 |
myFont := Font family:'courier' ... size:12.
|
|
78 |
...
|
|
79 |
|
|
80 |
'want to know its height on the Display'
|
|
81 |
|
|
82 |
h := (myFont on:Display) height.
|
|
83 |
|
|
84 |
|
|
85 |
'want to know its height on a printer'
|
|
86 |
|
|
87 |
h := (myFont on:aPrinter) height.
|
|
88 |
|
|
89 |
Keep in mind, that each device is free to think in whatever units it
|
|
90 |
likes - a display may return units of pixels, a postscript printer may
|
|
91 |
think in (fractions of) inches, a dot matrix printer may think in dots.
|
|
92 |
Also, notice that currently only graphic displays are really supported;
|
|
93 |
printer devices are being developped and may or may not be in the current
|
|
94 |
system.
|
|
95 |
|
46
|
96 |
Sometimes, a font cannot be represented on a device, then a replacement
|
|
97 |
font is chosen and kept in the replacementFont instance variable.
|
0
|
98 |
|
46
|
99 |
Instance variables:
|
|
100 |
|
|
101 |
family <String> the fonts family ('courier', 'helvetica' etc)
|
|
102 |
face <String> the fonts face ('bold', 'medium' etc)
|
|
103 |
style <String> the fonts style ('roman', 'italic', 'oblique')
|
|
104 |
size <String> the fonts size (not in pixels)
|
|
105 |
encoding <Symbol> the fonts encoding (usually #iso8859)
|
0
|
106 |
|
46
|
107 |
device <Object> the device the font is associated to, or nil
|
|
108 |
fontId <Object> the id of the font on that device, or nil
|
|
109 |
replacement <Font> the replacement font or nil
|
0
|
110 |
|
46
|
111 |
ascent <Integer> the fonts ascent in device units on device
|
|
112 |
descent <Integer> the fonts descent in device units on device
|
|
113 |
height <Integer> the fonts height in device units on device
|
|
114 |
width <Integer> the character width in device units on device
|
71
|
115 |
(for variable fonts, its the width of a space)
|
46
|
116 |
isFixedWidth <Boolean> true if font is a fixed width font
|
|
117 |
minWidth <Integer> width of the smallest-width character in
|
71
|
118 |
in device units on device
|
46
|
119 |
maxWidth <Integer> width of the largest-width character in
|
71
|
120 |
in device units on device
|
0
|
121 |
|
46
|
122 |
class variables:
|
0
|
123 |
|
46
|
124 |
Lobby <Registry> keeps track of all known fonts
|
|
125 |
|
|
126 |
Replacements <Dictionary> replacement fonts
|
|
127 |
"
|
0
|
128 |
! !
|
|
129 |
|
|
130 |
!Font class methodsFor:'initialization'!
|
|
131 |
|
|
132 |
initialize
|
|
133 |
"initialize the font tracking array"
|
|
134 |
|
23
|
135 |
Lobby isNil ifTrue:[
|
71
|
136 |
Lobby := Registry new.
|
0
|
137 |
|
71
|
138 |
"
|
|
139 |
want to be informed when returning from snapshot
|
|
140 |
"
|
|
141 |
ObjectMemory addDependent:self.
|
0
|
142 |
|
71
|
143 |
"
|
|
144 |
replacement handling is not yet finished
|
|
145 |
"
|
|
146 |
Replacements := Dictionary new.
|
|
147 |
|
|
148 |
Replacements at:'clean' put:'courier'.
|
|
149 |
Replacements at:'fixed' put:'courier'.
|
|
150 |
Replacements at:'new century schoolbook' put:'times'.
|
|
151 |
Replacements at:'lucida' put:'helvetica'.
|
|
152 |
Replacements at:'lucidabright' put:'helvetica'.
|
|
153 |
Replacements at:'lucidatypewriter' put:'courier'.
|
|
154 |
Replacements at:'charter' put:'times'.
|
|
155 |
Replacements at:'terminal' put:'courier'.
|
0
|
156 |
]
|
|
157 |
!
|
|
158 |
|
|
159 |
flushDeviceFonts
|
|
160 |
"unassign all fonts from their device"
|
|
161 |
|
23
|
162 |
Lobby contentsDo:[:aFont |
|
71
|
163 |
aFont restored.
|
|
164 |
Lobby changed:aFont
|
0
|
165 |
]
|
|
166 |
!
|
|
167 |
|
|
168 |
update:something
|
|
169 |
(something == #restarted) ifTrue:[
|
71
|
170 |
"
|
|
171 |
this is sent by ObjectMemory when restarting from
|
|
172 |
an image. All device specific information (especially device
|
|
173 |
handles) are now invalid and have to be flushed
|
|
174 |
"
|
|
175 |
self flushDeviceFonts
|
0
|
176 |
]
|
|
177 |
! !
|
|
178 |
|
|
179 |
!Font class methodsFor:'instance creation'!
|
|
180 |
|
|
181 |
family:familyString face:faceString style:styleString size:sizeNum
|
|
182 |
"returns a font for given family, face, style and size.
|
12
|
183 |
The returned font is not associated to a specific device"
|
0
|
184 |
|
12
|
185 |
^ self family:familyString
|
71
|
186 |
face:faceString
|
|
187 |
style:styleString
|
|
188 |
size:sizeNum
|
|
189 |
encoding:#iso8859
|
0
|
190 |
!
|
|
191 |
|
|
192 |
family:familyString face:faceString style:styleString size:sizeNum encoding:encodingSym
|
|
193 |
"returns a font for given family, face, style, size and encoding.
|
71
|
194 |
The returned font is not associated to a specific device"
|
0
|
195 |
|
54
|
196 |
|family newFont|
|
0
|
197 |
|
|
198 |
(familyString at:1) isUppercase ifTrue:[
|
71
|
199 |
family := familyString asLowercase
|
0
|
200 |
] ifFalse:[
|
71
|
201 |
family := familyString
|
0
|
202 |
].
|
|
203 |
|
|
204 |
"look if this font is already known"
|
|
205 |
|
23
|
206 |
Lobby contentsDo:[:aFont |
|
71
|
207 |
(aFont family = family) ifTrue:[
|
|
208 |
(aFont face = faceString) ifTrue:[
|
|
209 |
(aFont style = styleString) ifTrue:[
|
|
210 |
(aFont size == sizeNum) ifTrue:[
|
|
211 |
(encodingSym isNil or:[aFont encoding == encodingSym]) ifTrue:[
|
|
212 |
^ aFont
|
|
213 |
]
|
|
214 |
]
|
|
215 |
]
|
|
216 |
]
|
|
217 |
]
|
0
|
218 |
].
|
12
|
219 |
newFont := self basicNew setFamily:familyString
|
71
|
220 |
face:faceString
|
|
221 |
style:styleString
|
|
222 |
size:sizeNum
|
|
223 |
encoding:encodingSym
|
|
224 |
device:nil.
|
23
|
225 |
Lobby register:newFont.
|
0
|
226 |
^ newFont
|
|
227 |
! !
|
|
228 |
|
|
229 |
!Font methodsFor:'instance release'!
|
|
230 |
|
71
|
231 |
shallowCopyForFinalization
|
|
232 |
|aCopy|
|
|
233 |
|
|
234 |
aCopy := self class basicNew.
|
|
235 |
aCopy setDevice:device fontId:fontId.
|
|
236 |
^ aCopy
|
|
237 |
!
|
|
238 |
|
0
|
239 |
disposed
|
|
240 |
"some Font has been collected - tell it to the x-server"
|
|
241 |
|
|
242 |
fontId notNil ifTrue:[
|
71
|
243 |
device releaseFont:fontId.
|
0
|
244 |
]
|
|
245 |
! !
|
|
246 |
|
|
247 |
!Font methodsFor:'getting a device font'!
|
|
248 |
|
|
249 |
on:aDevice
|
|
250 |
"create a new Font representing the same font as
|
|
251 |
myself on aDevice; if one already exists, return the one."
|
|
252 |
|
23
|
253 |
|newFont id rep|
|
0
|
254 |
|
|
255 |
"if I am already assigned to that device ..."
|
|
256 |
(device == aDevice) ifTrue:[^ self].
|
|
257 |
|
|
258 |
"first look if not already there"
|
23
|
259 |
Lobby contentsDo:[:aFont |
|
71
|
260 |
(aDevice == aFont device) ifTrue:[
|
|
261 |
(size == aFont size) ifTrue:[
|
|
262 |
(family = aFont family) ifTrue:[
|
|
263 |
(face = aFont face) ifTrue:[
|
|
264 |
(style = aFont style) ifTrue:[
|
|
265 |
(encoding == aFont encoding) ifTrue:[
|
|
266 |
^ aFont
|
|
267 |
]
|
|
268 |
]
|
|
269 |
]
|
|
270 |
]
|
|
271 |
]
|
|
272 |
]
|
0
|
273 |
].
|
|
274 |
|
|
275 |
"ask that device for the font"
|
|
276 |
id := aDevice getFontWithFamily:family face:face style:style size:size encoding:encoding.
|
|
277 |
id isNil ifTrue:[
|
71
|
278 |
"oops did not work - (device has no such font)"
|
0
|
279 |
|
71
|
280 |
rep := self replacementFontOn:aDevice.
|
|
281 |
device isNil ifTrue:[
|
|
282 |
device := aDevice.
|
|
283 |
replacementFont := rep.
|
|
284 |
Lobby changed:self.
|
|
285 |
^ self
|
|
286 |
].
|
|
287 |
newFont := (self class basicNew)
|
|
288 |
setFamily:family face:face style:style size:size encoding:encoding device:aDevice.
|
|
289 |
newFont setReplacementFont:rep.
|
|
290 |
Lobby register:newFont.
|
|
291 |
^ newFont
|
0
|
292 |
].
|
|
293 |
|
|
294 |
"receiver was not associated - do it now"
|
|
295 |
device isNil ifTrue:[
|
71
|
296 |
device := aDevice.
|
|
297 |
fontId := id.
|
0
|
298 |
|
71
|
299 |
self getFontInfos.
|
|
300 |
Lobby changed:self.
|
|
301 |
^ self
|
0
|
302 |
].
|
|
303 |
|
|
304 |
"receiver was already associated to another device - need a new font"
|
12
|
305 |
newFont := (self class basicNew) setFamily:family
|
71
|
306 |
face:face
|
|
307 |
style:style
|
|
308 |
size:size
|
|
309 |
encoding:encoding
|
|
310 |
device:aDevice.
|
0
|
311 |
newFont setFontId:id.
|
|
312 |
newFont getFontInfos.
|
23
|
313 |
Lobby register:newFont.
|
0
|
314 |
^ newFont
|
|
315 |
!
|
|
316 |
|
|
317 |
replacementFontOn:aDevice
|
12
|
318 |
"return a replacement font for the receiver - this is needed, if
|
|
319 |
an image is restored on another type of display, or one which has
|
|
320 |
a different set of fonts."
|
0
|
321 |
|
|
322 |
|id f alternative|
|
|
323 |
|
|
324 |
alternative := Replacements at:family.
|
|
325 |
alternative notNil ifTrue:[
|
71
|
326 |
id := aDevice getFontWithFamily:alternative
|
|
327 |
face:face
|
|
328 |
style:style
|
|
329 |
size:size
|
|
330 |
encoding:encoding.
|
|
331 |
id notNil ifTrue:[
|
|
332 |
('replaced ' , family , '- with ' , alternative , '-font') print.
|
|
333 |
] ifFalse:[
|
|
334 |
id := aDevice getDefaultFont.
|
|
335 |
('replaced ' , family , '- with default-font') print.
|
|
336 |
]
|
0
|
337 |
].
|
|
338 |
id isNil ifTrue:[
|
71
|
339 |
"oops did not work - this is a serious an error"
|
|
340 |
self error:'cannot get default font'.
|
|
341 |
^ nil
|
0
|
342 |
].
|
|
343 |
f := self class basicNew.
|
|
344 |
f setDevice:aDevice fontId:id.
|
|
345 |
f getFontInfos.
|
23
|
346 |
Lobby register:f.
|
0
|
347 |
^ f
|
|
348 |
! !
|
|
349 |
|
|
350 |
!Font methodsFor:'instance creation'!
|
|
351 |
|
81
|
352 |
asBold
|
0
|
353 |
"return the bold font corresponding to the receiver"
|
|
354 |
|
|
355 |
^ self class family:family face:'bold' style:style size:size encoding:encoding
|
81
|
356 |
!
|
|
357 |
|
|
358 |
asItalic
|
|
359 |
"return the italic font corresponding to the receiver"
|
|
360 |
|
|
361 |
^ self class family:family face:face style:'oblique' size:size encoding:encoding
|
|
362 |
!
|
|
363 |
|
|
364 |
size:newSize
|
|
365 |
"return a font corresponding to the receiver, but with different size."
|
|
366 |
|
|
367 |
^ self class
|
|
368 |
family:family
|
|
369 |
face:face
|
|
370 |
style:style
|
|
371 |
size:newSize
|
|
372 |
encoding:encoding
|
0
|
373 |
! !
|
|
374 |
|
|
375 |
!Font methodsFor:'private'!
|
|
376 |
|
|
377 |
setFamily:familyString face:faceString style:styleString size:sizeNum encoding:encodingSym device:aDevice
|
|
378 |
family := familyString.
|
|
379 |
face := faceString.
|
|
380 |
style := styleString.
|
|
381 |
size := sizeNum.
|
|
382 |
encoding := encodingSym.
|
|
383 |
device := aDevice
|
|
384 |
!
|
|
385 |
|
2
|
386 |
restored
|
0
|
387 |
device := nil.
|
|
388 |
fontId := nil.
|
|
389 |
replacementFont := nil
|
|
390 |
!
|
|
391 |
|
|
392 |
setReplacementFont:aFont
|
|
393 |
replacementFont := aFont
|
|
394 |
!
|
|
395 |
|
|
396 |
setDevice:aDevice
|
|
397 |
device := aDevice
|
|
398 |
!
|
|
399 |
|
|
400 |
setFontId:aFontId
|
|
401 |
fontId := aFontId
|
|
402 |
!
|
|
403 |
|
|
404 |
setDevice:aDevice fontId:aFontId
|
|
405 |
device := aDevice.
|
|
406 |
fontId := aFontId
|
|
407 |
!
|
|
408 |
|
|
409 |
getFontInfos
|
|
410 |
replacementFont isNil ifTrue:[
|
71
|
411 |
ascent := device ascentOf:fontId.
|
|
412 |
descent := device descentOf:fontId.
|
|
413 |
height := descent + ascent.
|
|
414 |
width := device widthOf:' ' inFont:fontId.
|
|
415 |
minWidth := device minWidthOfFont:fontId.
|
|
416 |
maxWidth := device maxWidthOfFont:fontId.
|
0
|
417 |
] ifFalse:[
|
71
|
418 |
ascent := replacementFont ascent.
|
|
419 |
descent := replacementFont descent.
|
|
420 |
height := descent + ascent.
|
|
421 |
width := replacementFont width.
|
|
422 |
minWidth := replacementFont minWidth.
|
|
423 |
maxWidth := replacementFont maxWidth.
|
0
|
424 |
].
|
|
425 |
isFixedWidth := minWidth == maxWidth
|
|
426 |
! !
|
|
427 |
|
|
428 |
!Font methodsFor:'comparing'!
|
|
429 |
|
|
430 |
= aFont
|
|
431 |
"two fonts are considered equal, if the font-name components are;
|
|
432 |
independent of the device, the font is on"
|
|
433 |
|
|
434 |
(aFont isKindOf:Font) ifTrue:[
|
71
|
435 |
(size == aFont size) ifTrue:[
|
|
436 |
(family = aFont family) ifTrue:[
|
|
437 |
(face = aFont face) ifTrue:[
|
|
438 |
(style = aFont style) ifTrue:[
|
|
439 |
(encoding == aFont encoding) ifTrue:[
|
|
440 |
^ true
|
|
441 |
]
|
|
442 |
]
|
|
443 |
]
|
|
444 |
]
|
|
445 |
]
|
0
|
446 |
].
|
|
447 |
^ false
|
|
448 |
! !
|
|
449 |
|
|
450 |
!Font methodsFor:'accessing'!
|
|
451 |
|
|
452 |
family
|
|
453 |
"return the family, a string"
|
|
454 |
|
|
455 |
^ family
|
|
456 |
!
|
|
457 |
|
|
458 |
face
|
|
459 |
"return the face, a string"
|
|
460 |
|
|
461 |
^ face
|
|
462 |
!
|
|
463 |
|
|
464 |
style
|
|
465 |
"return the style, a string"
|
|
466 |
|
|
467 |
^ style
|
|
468 |
!
|
|
469 |
|
|
470 |
size
|
|
471 |
"return the size, a number"
|
|
472 |
|
|
473 |
^ size
|
|
474 |
!
|
|
475 |
|
|
476 |
encoding
|
|
477 |
"return the encoding, a symbol such as #iso8859"
|
|
478 |
|
|
479 |
^ encoding
|
|
480 |
!
|
|
481 |
|
|
482 |
fontId
|
|
483 |
"return the device-dependent font-id"
|
|
484 |
|
|
485 |
^ fontId
|
|
486 |
!
|
|
487 |
|
|
488 |
device
|
|
489 |
"return the device I am on"
|
|
490 |
|
|
491 |
^ device
|
|
492 |
! !
|
|
493 |
|
|
494 |
!Font methodsFor:'errors'!
|
|
495 |
|
|
496 |
errorNoDevice
|
|
497 |
"a query was made for device-specific info"
|
|
498 |
|
71
|
499 |
"
|
|
500 |
this happens, when you ask a font for its height or width,
|
|
501 |
ascent or any other dimension which depends on the device on
|
86
|
502 |
which the font is rendered, AND the receiver font is not (yet)
|
71
|
503 |
associated to a device.
|
|
504 |
You should always use
|
|
505 |
font := font on:someDevice
|
|
506 |
to get a device font, before asking for device specifics.
|
|
507 |
"
|
0
|
508 |
self error:'query device independent font for for device specific info'
|
|
509 |
! !
|
|
510 |
|
|
511 |
!Font methodsFor:'queries'!
|
|
512 |
|
|
513 |
isFixedWidth
|
|
514 |
"return true, if all characters have same width (as in courier"
|
|
515 |
|
|
516 |
device isNil ifTrue:[
|
71
|
517 |
self errorNoDevice
|
0
|
518 |
].
|
|
519 |
^ isFixedWidth
|
|
520 |
!
|
|
521 |
|
|
522 |
height
|
|
523 |
"return the characters maximum height;
|
|
524 |
That is the number of units (usually pixels) on the device"
|
|
525 |
|
|
526 |
device isNil ifTrue:[
|
71
|
527 |
self errorNoDevice
|
0
|
528 |
].
|
|
529 |
^ height
|
|
530 |
!
|
|
531 |
|
|
532 |
width
|
|
533 |
"return the characters width;
|
|
534 |
That is the number of units (usually pixels) on the device.
|
|
535 |
For variable pitch fonts, the width of the space character is returned"
|
|
536 |
|
|
537 |
device isNil ifTrue:[
|
71
|
538 |
self errorNoDevice
|
0
|
539 |
].
|
|
540 |
^ width
|
|
541 |
!
|
|
542 |
|
|
543 |
minWidth
|
|
544 |
"return the width of the smallest character;
|
|
545 |
if the receiver is a fixed width font its the width of every character"
|
|
546 |
|
|
547 |
device isNil ifTrue:[
|
71
|
548 |
self errorNoDevice
|
0
|
549 |
].
|
|
550 |
^ minWidth
|
|
551 |
!
|
|
552 |
|
|
553 |
maxWidth
|
|
554 |
"return the width of the widest character;
|
|
555 |
if the receiver is a fixed width font its the width of every character"
|
|
556 |
|
|
557 |
device isNil ifTrue:[
|
71
|
558 |
self errorNoDevice
|
0
|
559 |
].
|
|
560 |
^ maxWidth
|
|
561 |
!
|
|
562 |
|
|
563 |
ascent
|
|
564 |
"return the font-ascent i.e. the maximum of all characters;
|
|
565 |
That is the number of units (usually pixels) above the baseline"
|
|
566 |
|
|
567 |
device isNil ifTrue:[
|
71
|
568 |
self errorNoDevice
|
0
|
569 |
].
|
|
570 |
^ ascent
|
|
571 |
!
|
|
572 |
|
|
573 |
descent
|
|
574 |
"return the font-descent i.e. the maximum of all characters;
|
|
575 |
That is the number of units (usually pixels) below the baseline"
|
|
576 |
|
|
577 |
device isNil ifTrue:[
|
71
|
578 |
self errorNoDevice
|
0
|
579 |
].
|
|
580 |
^ descent
|
|
581 |
!
|
|
582 |
|
71
|
583 |
widthOf:textOrString
|
0
|
584 |
"return the width (device specific) of the argument;
|
|
585 |
the argument may be a String or some Text;
|
|
586 |
in the later case the width of the longest line in the text is returned"
|
|
587 |
|
|
588 |
|this max|
|
|
589 |
|
|
590 |
device isNil ifTrue:[
|
71
|
591 |
self errorNoDevice.
|
|
592 |
^ 0
|
0
|
593 |
].
|
|
594 |
replacementFont notNil ifTrue:[
|
71
|
595 |
^ replacementFont widthOf:textOrString
|
0
|
596 |
].
|
|
597 |
|
71
|
598 |
(textOrString isString) ifTrue:[
|
|
599 |
isFixedWidth ifFalse:[
|
|
600 |
^ device widthOf:textOrString inFont:fontId
|
|
601 |
].
|
|
602 |
^ width * textOrString size
|
0
|
603 |
].
|
|
604 |
|
|
605 |
max := 0.
|
|
606 |
isFixedWidth ifFalse:[
|
71
|
607 |
textOrString do:[:line |
|
|
608 |
line notNil ifTrue:[
|
|
609 |
this := device widthOf:line inFont:fontId.
|
|
610 |
(this > max) ifTrue:[max := this]
|
|
611 |
]
|
|
612 |
].
|
|
613 |
^ max
|
0
|
614 |
].
|
|
615 |
|
71
|
616 |
textOrString do:[:lineString |
|
|
617 |
this := lineString size.
|
|
618 |
(this > max) ifTrue:[max := this]
|
0
|
619 |
].
|
|
620 |
^ max * width
|
|
621 |
!
|
|
622 |
|
|
623 |
widthOf:aString from:start to:stop
|
|
624 |
"return the width of a substring"
|
|
625 |
|
|
626 |
device isNil ifTrue:[
|
71
|
627 |
self errorNoDevice.
|
|
628 |
^ 0
|
0
|
629 |
].
|
|
630 |
replacementFont notNil ifTrue:[
|
71
|
631 |
^ replacementFont widthOf:aString from:start to:stop
|
0
|
632 |
].
|
|
633 |
(stop < start) ifTrue:[^ 0].
|
|
634 |
isFixedWidth ifFalse:[
|
71
|
635 |
^ device widthOf:aString from:start to:stop inFont:fontId
|
0
|
636 |
].
|
|
637 |
^ (stop - start + 1) * width
|
|
638 |
! !
|
|
639 |
|
2
|
640 |
!Font methodsFor:'st-80 queries'!
|
|
641 |
|
|
642 |
serif
|
|
643 |
"return true, if this font has serifs"
|
|
644 |
|
|
645 |
"this should be done in a better way ..."
|
|
646 |
|
|
647 |
family = 'Times' ifTrue:[^ true].
|
|
648 |
family = 'times' ifTrue:[^ true].
|
|
649 |
^ false.
|
|
650 |
!
|
|
651 |
|
|
652 |
fixedWidth
|
|
653 |
"return true, if this font is a fixed width font -
|
|
654 |
for st-80 compatibility"
|
|
655 |
|
|
656 |
^ self isFixedWidth
|
|
657 |
!
|
|
658 |
|
|
659 |
pixelSize
|
|
660 |
"return the height of the font in pixels -
|
|
661 |
for st-80 compatibility"
|
|
662 |
|
|
663 |
^ self height
|
|
664 |
!
|
|
665 |
|
|
666 |
italic
|
|
667 |
"return true if this is an italic font -
|
|
668 |
for st-80 compatibility"
|
|
669 |
|
|
670 |
face = 'italic' ifTrue:[^ true].
|
|
671 |
face = 'obligue' ifTrue:[^ true].
|
|
672 |
^ false
|
|
673 |
!
|
|
674 |
|
81
|
675 |
bold
|
86
|
676 |
"return true, if the receiver is a bold font -
|
81
|
677 |
for st-80 compatibility"
|
|
678 |
|
|
679 |
^ face = 'bold'
|
|
680 |
!
|
|
681 |
|
2
|
682 |
boldness
|
|
683 |
"return the boldness of the characters in this font 0 .. 1 -
|
|
684 |
for st-80 compatibility"
|
|
685 |
|
|
686 |
style = 'roman' ifTrue:[^ 0.5].
|
|
687 |
style = 'normal' ifTrue:[^ 0.5].
|
|
688 |
style = 'bold' ifTrue:[^ 0.75].
|
|
689 |
style = 'light' ifTrue:[^ 0.25].
|
|
690 |
^ 0.5
|
|
691 |
! !
|
|
692 |
|
0
|
693 |
!Font methodsFor:'printing & storing'!
|
|
694 |
|
|
695 |
printString
|
46
|
696 |
face isNil ifTrue:[
|
71
|
697 |
^ 'a ' , family , '-Font'
|
46
|
698 |
].
|
|
699 |
^ 'a ' , family , '-' , face , '-' , style , '-' , size printString , '-Font'
|
0
|
700 |
!
|
|
701 |
|
|
702 |
storeString
|
|
703 |
"return a String with a representation of myself, from which I can be
|
|
704 |
recreated"
|
|
705 |
|
|
706 |
^ ('(Font family:' , family ,
|
|
707 |
' face:' , face ,
|
|
708 |
' style:' , style ,
|
|
709 |
' size:' , size printString ,
|
|
710 |
' encoding:' , encoding storeString , ')')
|
|
711 |
! !
|
2
|
712 |
|
|
713 |
!Font methodsFor: 'binary storage'!
|
|
714 |
|
|
715 |
readBinaryContentsFrom: stream manager: manager
|
|
716 |
"tell the newly restored Font about restoration"
|
|
717 |
|
|
718 |
super readBinaryContentsFrom: stream manager: manager.
|
|
719 |
self restored
|
|
720 |
! !
|