"
COPYRIGHT (c) 1994 by Claus Gittinger
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
"
Object subclass:#FontDescription
instanceVariableNames:'family face style size encoding'
classVariableNames:''
poolDictionaries:''
category:'Graphics-Support'
!
!FontDescription class methodsFor:'documentation'!
copyright
"
COPYRIGHT (c) 1994 by Claus Gittinger
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
"
!
version
^ '$Header: /cvs/stx/stx/libview/FontDescription.st,v 1.5 1995-11-11 15:50:20 cg Exp $'
!
documentation
"
FontDescription is just a place-holder for scanned font names.
Instance variables:
family <String> the fonts family ('courier', 'helvetica' etc)
face <String> the fonts face ('bold', 'medium' etc)
style <String> the fonts style ('roman', 'italic', 'oblique')
size <String> the fonts size (not in pixels)
encoding <Symbol> the fonts encoding (usually #iso8859)
"
! !
!FontDescription class methodsFor:'instance creation'!
name:aFontName
"returns a font with the given explicit name.
You shuld not use explicit naming, since font names vary
with operatingSystems, devices and architecture.
This interface is provided for special purposes only.
On X, the name given should be according the X fontname conventions;
i.e. something like: '-*-times-bold-r-normal-*-*-240-*-*-*-*-iso8859-1'."
^ self family:aFontName
face:nil
style:nil
size:nil
encoding:nil
"
Font name:'-*-times-bold-r-normal-*-*-240-*-*-*-*-iso8859-1'
"
!
family:familyString
"returns a font for given family and default (12pt) size
with unspecified encoding.
Face is taken as medium, style as roman.
The returned font is not associated to a specific device"
^ self family:familyString
face:'medium'
style:'roman'
size:12
encoding:nil
"
Font family:'helvetica'
Font family:'courier'
"
!
family:familyString size:sizeNum
"returns a font for given family and size with unspecified encoding.
Face is taken as medium, style as roman.
The returned font is not associated to a specific device"
^ self family:familyString
face:'medium'
style:'roman'
size:sizeNum
encoding:nil
"
Font family:'helvetica' size:10
Font family:'courier' size:10
"
!
family:familyString face:faceString size:sizeNum
"returns a font for given family and size with unspecified encoding.
Style is taken as roman.
The returned font is not associated to a specific device"
^ self family:familyString
face:faceString
style:'roman'
size:sizeNum
encoding:nil
"
Font family:'helvetica' face:'medium' size:10
Font family:'helvetica' face:'bold' size:10
Font family:'courier' face:'bold' size:10
"
!
family:familyString face:faceString style:styleString size:sizeNum
"returns a font for given family, face, style and size with
unspecified encoding.
The returned font is not associated to a specific device"
^ self family:familyString
face:faceString
style:styleString
size:sizeNum
encoding:nil
"
Font family:'helvetica' face:'medium' style:'roman' size:10
Font family:'helvetica' face:'medium' style:'italic' size:10
Font family:'helvetica' face:'bold' style:'roman' size:10
Font family:'courier' face:'bold' style:'italic' size:10
"
!
family:familyString face:faceString style:styleString size:sizeNum encoding:encodingSym
^ self new
family:familyString
face:faceString
style:styleString
size:sizeNum
encoding:encodingSym
! !
!FontDescription methodsFor:'accessing'!
family:familyString face:faceString style:styleString size:sizeNum encoding:encodingString
family := familyString asSymbol.
faceString notNil ifTrue:[
face := faceString asSymbol.
].
styleString notNil ifTrue:[
style := styleString asSymbol.
].
size := sizeNum.
encodingString notNil ifTrue:[
encoding := encodingString asSymbol.
]
!
family
"return the family, a string"
^ family
!
face
"return the face, a string"
^ face
!
style
"return the style, a string"
^ style
!
size
"return the size, a number"
^ size
!
encoding
"return the encoding, a symbol such as #iso8859"
^ encoding
! !
!FontDescription methodsFor:'queries'!
species
^ Font
!
serif
"return true, if this font has serifs"
"this should be done in a better way ..."
family = 'Times' ifTrue:[^ true].
family = 'times' ifTrue:[^ true].
^ false.
!
italic
"return true if this is an italic font -
for st-80 compatibility"
face = 'italic' ifTrue:[^ true].
face = 'obligue' ifTrue:[^ true].
^ false
!
bold
"return true, if the receiver is a bold font -
for st-80 compatibility"
^ face = 'bold'
!
boldness
"return the boldness of the characters in this font 0 .. 1 -
for st-80 compatibility"
style = 'roman' ifTrue:[^ 0.5].
style = 'normal' ifTrue:[^ 0.5].
style = 'bold' ifTrue:[^ 0.75].
style = 'light' ifTrue:[^ 0.25].
^ 0.5
! !
!FontDescription methodsFor:'errors'!
errorNoDevice
"a query was made for device-specific info"
"
this happens, when you ask a font for its height or width,
ascent or any other dimension which depends on the device on
which the font is rendered, AND the receiver font is not (yet)
associated to a device.
You should always use
font := font on:someDevice
to get a device font, before asking for device specifics.
"
self error:'query device independent font for for device specific info'
! !
!FontDescription methodsFor:'comparing'!
= aFont
"two fonts are considered equal, if the font-name components are;
independent of the device, the font is on"
(aFont species == self species) ifTrue:[
(size == aFont size) ifTrue:[
(family = aFont family) ifTrue:[
(face = aFont face) ifTrue:[
(style = aFont style) ifTrue:[
(encoding == aFont encoding) ifTrue:[
^ true
]
]
]
]
]
].
^ false
! !
!FontDescription methodsFor:'converting'!
on:aDevice
"given the receiver, return a device Font"
^ (Font
family:family
face:'bold'
style:style
size:size
encoding:encoding) on:aDevice
!
asBold
"return the bold font corresponding to the receiver"
^ self class
family:family
face:'bold'
style:style
size:size
encoding:encoding
!
asItalic
"return the italic font corresponding to the receiver"
^ self class
family:family
face:face
style:'oblique'
size:size
encoding:encoding
!
size:newSize
"return a font corresponding to the receiver, but with different size."
^ self class
family:family
face:face
style:style
size:newSize
encoding:encoding
! !