author | Claus Gittinger <cg@exept.de> |
Sat, 11 Nov 1995 16:54:10 +0100 | |
changeset 219 | 9ff0660f447f |
parent 153 | c56277fa4865 |
child 229 | 099543e5d779 |
permissions | -rw-r--r-- |
52 | 1 |
" |
2 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
89 | 3 |
All Rights Reserved |
52 | 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:#FontDescription |
|
14 |
instanceVariableNames:'family face style size encoding' |
|
15 |
classVariableNames:'' |
|
16 |
poolDictionaries:'' |
|
17 |
category:'Graphics-Support' |
|
18 |
! |
|
19 |
||
20 |
!FontDescription class methodsFor:'documentation'! |
|
21 |
||
22 |
copyright |
|
23 |
" |
|
24 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
89 | 25 |
All Rights Reserved |
52 | 26 |
|
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
36 |
version |
|
219
9ff0660f447f
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
153
diff
changeset
|
37 |
^ '$Header: /cvs/stx/stx/libview/FontDescription.st,v 1.5 1995-11-11 15:50:20 cg Exp $' |
52 | 38 |
! |
39 |
||
40 |
documentation |
|
41 |
" |
|
42 |
FontDescription is just a place-holder for scanned font names. |
|
43 |
||
44 |
Instance variables: |
|
45 |
||
46 |
family <String> the fonts family ('courier', 'helvetica' etc) |
|
47 |
face <String> the fonts face ('bold', 'medium' etc) |
|
48 |
style <String> the fonts style ('roman', 'italic', 'oblique') |
|
49 |
size <String> the fonts size (not in pixels) |
|
50 |
encoding <Symbol> the fonts encoding (usually #iso8859) |
|
51 |
" |
|
52 |
! ! |
|
53 |
||
54 |
!FontDescription class methodsFor:'instance creation'! |
|
55 |
||
153 | 56 |
name:aFontName |
57 |
"returns a font with the given explicit name. |
|
58 |
You shuld not use explicit naming, since font names vary |
|
59 |
with operatingSystems, devices and architecture. |
|
60 |
This interface is provided for special purposes only. |
|
61 |
On X, the name given should be according the X fontname conventions; |
|
62 |
i.e. something like: '-*-times-bold-r-normal-*-*-240-*-*-*-*-iso8859-1'." |
|
63 |
||
64 |
^ self family:aFontName |
|
65 |
face:nil |
|
66 |
style:nil |
|
67 |
size:nil |
|
68 |
encoding:nil |
|
69 |
||
70 |
" |
|
71 |
Font name:'-*-times-bold-r-normal-*-*-240-*-*-*-*-iso8859-1' |
|
72 |
" |
|
73 |
! |
|
74 |
||
75 |
family:familyString |
|
76 |
"returns a font for given family and default (12pt) size |
|
77 |
with unspecified encoding. |
|
78 |
Face is taken as medium, style as roman. |
|
79 |
The returned font is not associated to a specific device" |
|
80 |
||
81 |
^ self family:familyString |
|
82 |
face:'medium' |
|
83 |
style:'roman' |
|
84 |
size:12 |
|
85 |
encoding:nil |
|
86 |
||
87 |
" |
|
88 |
Font family:'helvetica' |
|
89 |
Font family:'courier' |
|
90 |
" |
|
91 |
! |
|
92 |
||
109 | 93 |
family:familyString size:sizeNum |
94 |
"returns a font for given family and size with unspecified encoding. |
|
95 |
Face is taken as medium, style as roman. |
|
96 |
The returned font is not associated to a specific device" |
|
97 |
||
98 |
^ self family:familyString |
|
99 |
face:'medium' |
|
100 |
style:'roman' |
|
101 |
size:sizeNum |
|
102 |
encoding:nil |
|
103 |
||
104 |
" |
|
105 |
Font family:'helvetica' size:10 |
|
106 |
Font family:'courier' size:10 |
|
107 |
" |
|
108 |
! |
|
109 |
||
110 |
family:familyString face:faceString size:sizeNum |
|
111 |
"returns a font for given family and size with unspecified encoding. |
|
112 |
Style is taken as roman. |
|
113 |
The returned font is not associated to a specific device" |
|
114 |
||
115 |
^ self family:familyString |
|
116 |
face:faceString |
|
117 |
style:'roman' |
|
118 |
size:sizeNum |
|
119 |
encoding:nil |
|
120 |
||
121 |
" |
|
122 |
Font family:'helvetica' face:'medium' size:10 |
|
123 |
Font family:'helvetica' face:'bold' size:10 |
|
124 |
Font family:'courier' face:'bold' size:10 |
|
125 |
" |
|
126 |
! |
|
127 |
||
128 |
family:familyString face:faceString style:styleString size:sizeNum |
|
129 |
"returns a font for given family, face, style and size with |
|
130 |
unspecified encoding. |
|
131 |
The returned font is not associated to a specific device" |
|
132 |
||
133 |
^ self family:familyString |
|
134 |
face:faceString |
|
135 |
style:styleString |
|
136 |
size:sizeNum |
|
137 |
encoding:nil |
|
138 |
||
139 |
" |
|
140 |
Font family:'helvetica' face:'medium' style:'roman' size:10 |
|
141 |
Font family:'helvetica' face:'medium' style:'italic' size:10 |
|
142 |
Font family:'helvetica' face:'bold' style:'roman' size:10 |
|
143 |
Font family:'courier' face:'bold' style:'italic' size:10 |
|
144 |
" |
|
145 |
! |
|
146 |
||
52 | 147 |
family:familyString face:faceString style:styleString size:sizeNum encoding:encodingSym |
148 |
^ self new |
|
109 | 149 |
family:familyString |
150 |
face:faceString |
|
151 |
style:styleString |
|
152 |
size:sizeNum |
|
153 |
encoding:encodingSym |
|
52 | 154 |
! ! |
155 |
||
156 |
!FontDescription methodsFor:'accessing'! |
|
157 |
||
89 | 158 |
family:familyString face:faceString style:styleString size:sizeNum encoding:encodingString |
159 |
family := familyString asSymbol. |
|
160 |
faceString notNil ifTrue:[ |
|
161 |
face := faceString asSymbol. |
|
162 |
]. |
|
163 |
styleString notNil ifTrue:[ |
|
164 |
style := styleString asSymbol. |
|
165 |
]. |
|
52 | 166 |
size := sizeNum. |
89 | 167 |
encodingString notNil ifTrue:[ |
168 |
encoding := encodingString asSymbol. |
|
169 |
] |
|
52 | 170 |
! |
171 |
||
172 |
family |
|
173 |
"return the family, a string" |
|
174 |
||
175 |
^ family |
|
176 |
! |
|
177 |
||
178 |
face |
|
179 |
"return the face, a string" |
|
180 |
||
181 |
^ face |
|
182 |
! |
|
183 |
||
184 |
style |
|
185 |
"return the style, a string" |
|
186 |
||
187 |
^ style |
|
188 |
! |
|
189 |
||
190 |
size |
|
191 |
"return the size, a number" |
|
192 |
||
193 |
^ size |
|
194 |
! |
|
195 |
||
196 |
encoding |
|
197 |
"return the encoding, a symbol such as #iso8859" |
|
198 |
||
199 |
^ encoding |
|
200 |
! ! |
|
109 | 201 |
|
202 |
!FontDescription methodsFor:'queries'! |
|
203 |
||
204 |
species |
|
205 |
^ Font |
|
206 |
! |
|
207 |
||
208 |
serif |
|
209 |
"return true, if this font has serifs" |
|
210 |
||
211 |
"this should be done in a better way ..." |
|
212 |
||
213 |
family = 'Times' ifTrue:[^ true]. |
|
214 |
family = 'times' ifTrue:[^ true]. |
|
215 |
^ false. |
|
216 |
! |
|
217 |
||
218 |
italic |
|
219 |
"return true if this is an italic font - |
|
220 |
for st-80 compatibility" |
|
221 |
||
222 |
face = 'italic' ifTrue:[^ true]. |
|
223 |
face = 'obligue' ifTrue:[^ true]. |
|
224 |
^ false |
|
225 |
! |
|
226 |
||
227 |
bold |
|
228 |
"return true, if the receiver is a bold font - |
|
229 |
for st-80 compatibility" |
|
230 |
||
231 |
^ face = 'bold' |
|
232 |
! |
|
233 |
||
234 |
boldness |
|
235 |
"return the boldness of the characters in this font 0 .. 1 - |
|
236 |
for st-80 compatibility" |
|
237 |
||
238 |
style = 'roman' ifTrue:[^ 0.5]. |
|
239 |
style = 'normal' ifTrue:[^ 0.5]. |
|
240 |
style = 'bold' ifTrue:[^ 0.75]. |
|
241 |
style = 'light' ifTrue:[^ 0.25]. |
|
242 |
^ 0.5 |
|
243 |
! ! |
|
244 |
||
245 |
!FontDescription methodsFor:'errors'! |
|
246 |
||
247 |
errorNoDevice |
|
248 |
"a query was made for device-specific info" |
|
249 |
||
250 |
" |
|
251 |
this happens, when you ask a font for its height or width, |
|
252 |
ascent or any other dimension which depends on the device on |
|
253 |
which the font is rendered, AND the receiver font is not (yet) |
|
254 |
associated to a device. |
|
255 |
You should always use |
|
256 |
font := font on:someDevice |
|
257 |
to get a device font, before asking for device specifics. |
|
258 |
" |
|
259 |
self error:'query device independent font for for device specific info' |
|
260 |
! ! |
|
261 |
||
262 |
!FontDescription methodsFor:'comparing'! |
|
263 |
||
264 |
= aFont |
|
265 |
"two fonts are considered equal, if the font-name components are; |
|
266 |
independent of the device, the font is on" |
|
267 |
||
268 |
(aFont species == self species) ifTrue:[ |
|
269 |
(size == aFont size) ifTrue:[ |
|
270 |
(family = aFont family) ifTrue:[ |
|
271 |
(face = aFont face) ifTrue:[ |
|
272 |
(style = aFont style) ifTrue:[ |
|
273 |
(encoding == aFont encoding) ifTrue:[ |
|
274 |
^ true |
|
275 |
] |
|
276 |
] |
|
277 |
] |
|
278 |
] |
|
279 |
] |
|
280 |
]. |
|
281 |
^ false |
|
282 |
! ! |
|
283 |
||
284 |
!FontDescription methodsFor:'converting'! |
|
285 |
||
286 |
on:aDevice |
|
287 |
"given the receiver, return a device Font" |
|
288 |
||
289 |
^ (Font |
|
290 |
family:family |
|
291 |
face:'bold' |
|
292 |
style:style |
|
293 |
size:size |
|
294 |
encoding:encoding) on:aDevice |
|
295 |
! |
|
296 |
||
297 |
asBold |
|
298 |
"return the bold font corresponding to the receiver" |
|
299 |
||
300 |
^ self class |
|
301 |
family:family |
|
302 |
face:'bold' |
|
303 |
style:style |
|
304 |
size:size |
|
305 |
encoding:encoding |
|
306 |
! |
|
307 |
||
308 |
asItalic |
|
309 |
"return the italic font corresponding to the receiver" |
|
310 |
||
311 |
^ self class |
|
312 |
family:family |
|
313 |
face:face |
|
314 |
style:'oblique' |
|
315 |
size:size |
|
316 |
encoding:encoding |
|
317 |
! |
|
318 |
||
319 |
size:newSize |
|
320 |
"return a font corresponding to the receiver, but with different size." |
|
321 |
||
322 |
^ self class |
|
323 |
family:family |
|
324 |
face:face |
|
325 |
style:style |
|
326 |
size:newSize |
|
327 |
encoding:encoding |
|
328 |
! ! |
|
329 |
||
330 |
||
331 |