home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BURKS 2
/
BURKS_AUG97.ISO
/
BURKS
/
LANGUAGE
/
SMALTALK
/
TEXTBOOK
/
AP07.ST
(
.txt
)
< prev
next >
Wrap
Text File
|
1997-04-22
|
17KB
|
585 lines
'Smalltalk Textbook Appendix 07'!
EngiVariable subclass: #EngiFontModel
instanceVariableNames: 'family size bold italic underline outline shadow width color '
classVariableNames: ''
poolDictionaries: ''
category: 'Engi-Text'!
EngiFontModel comment:
'
Engi 0.02 (25 January 1994)
Copyright (C) 1994 by Atsushi Aoki
'!
!EngiFontModel methodsFor: 'initialize-release'!
initialize
super initialize.
self initialize: TextAttributes default defaultFont.
^self!
initialize: fontDescription
self family: fontDescription family.
self size: fontDescription pixelSize.
self boldNumber: fontDescription boldness.
self italic: fontDescription italic.
self underline: fontDescription underline.
self outline: fontDescription outline.
self shadow: fontDescription shadow.
self widthNumber: fontDescription setWidth.
self color: fontDescription color! !
!EngiFontModel methodsFor: 'accessing'!
searchFontDescription
| fontDescription |
fontDescription := FontDescription new.
family notNil ifTrue: [fontDescription family: family].
size notNil ifTrue: [fontDescription pixelSize: size].
bold notNil ifTrue: [fontDescription boldness: bold].
italic notNil ifTrue: [fontDescription italic: italic].
underline notNil ifTrue: [fontDescription underline: underline].
outline notNil ifTrue: [fontDescription outline: outline].
shadow notNil ifTrue: [fontDescription shadow: shadow].
width notNil ifTrue: [fontDescription setWidth: width].
color notNil ifTrue: [fontDescription color: color].
Screen default defaultFontPolicy searchForFont: fontDescription allowance: 9.
^fontDescription!
value
value isNil ifTrue: [self setValue: self visual].
^value! !
!EngiFontModel methodsFor: 'visual accessing'!
visual
| fontDescription characterAttributes textAttributes deviceFont composedText |
fontDescription := self searchFontDescription.
characterAttributes := CharacterAttributes newWithDefaultAttributes.
characterAttributes setDefaultQuery: fontDescription.
textAttributes := TextAttributes new.
textAttributes setCharacterAttributes: characterAttributes.
deviceFont := Screen default defaultFontPolicy findFont: textAttributes defaultFont.
textAttributes lineGrid: deviceFont height.
textAttributes baseline: deviceFont ascent.
composedText := ComposedText withText: 'Smalltalk' asText style: textAttributes.
^composedText!
visualView
| visualView edgeDecorator |
visualView := EngiDisplayView model: self.
edgeDecorator := LookPreferences edgeDecorator on: visualView.
edgeDecorator noMenuBar.
edgeDecorator noVerticalScrollBar.
edgeDecorator noHorizontalScrollBar.
^edgeDecorator! !
!EngiFontModel methodsFor: 'family accessing'!
family
^family!
family: aString
family := aString.
self changed: #familySelection.
self changed: #sizeString!
familyList
^self class allFontFamilies!
familyMenu
^nil!
familySelection
^self family!
familyView
| familyView edgeDecorator |
familyView := SelectionInListView
on: self
aspect: #family
change: #family:
list: #familyList
menu: #familyMenu
initialSelection: #familySelection.
edgeDecorator := LookPreferences edgeDecorator on: familyView.
edgeDecorator noMenuBar.
edgeDecorator useVerticalScrollBar.
edgeDecorator useHorizontalScrollBar.
^edgeDecorator! !
!EngiFontModel methodsFor: 'size accessing'!
size
^size!
size: anInteger
size := anInteger.
self changed: #sizeSelection.
self changed: #visual!
sizeList
self family isNil ifTrue: [^nil].
^(self class allFontSizes: self family)
collect: [:each | each printString]!
sizeMenu
^nil!
sizeSelection
^self sizeString!
sizeString
self size isNil ifTrue: [^nil].
^self size printString!
sizeString: aString
aString isNil
ifTrue: [self size: nil]
ifFalse: [self size: aString asNumber]!
sizeView
| sizeView edgeDecorator |
sizeView := SelectionInListView
on: self
aspect: #sizeString
change: #sizeString:
list: #sizeList
menu: #sizeMenu
initialSelection: #sizeSelection.
edgeDecorator := LookPreferences edgeDecorator on: sizeView.
edgeDecorator noMenuBar.
edgeDecorator useVerticalScrollBar.
edgeDecorator noHorizontalScrollBar.
^edgeDecorator! !
!EngiFontModel methodsFor: 'bold accessing'!
bold
bold <= 0.3 ifTrue: [^#light].
(0.3 < bold and: [bold < 0.7])
ifTrue: [^#plain].
0.7 <= bold ifTrue: [^#bold].
^nil!
bold: aSymbol
aSymbol = #light ifTrue: [self boldNumber: 0.3].
aSymbol = #plain ifTrue: [self boldNumber: 0.5].
aSymbol = #bold ifTrue: [self boldNumber: 0.7].
self changed: #bold!
boldButtons
| baseModel pluggableAdaptor lightButton plainButton boldButton boldButtons |
baseModel := PluggableAdaptor on: self.
baseModel getSelector: #bold putSelector: #bold:.
pluggableAdaptor := PluggableAdaptor on: baseModel.
pluggableAdaptor selectValue: #light.
lightButton := Button toggle.
lightButton model: pluggableAdaptor.
lightButton label: 'light'.
baseModel := PluggableAdaptor on: self.
baseModel getSelector: #bold putSelector: #bold:.
pluggableAdaptor := PluggableAdaptor on: baseModel.
pluggableAdaptor selectValue: #plain.
plainButton := Button toggle.
plainButton model: pluggableAdaptor.
plainButton label: 'plain'.
baseModel := PluggableAdaptor on: self.
baseModel getSelector: #bold putSelector: #bold:.
pluggableAdaptor := PluggableAdaptor on: baseModel.
pluggableAdaptor selectValue: #bold.
boldButton := Button toggle.
boldButton model: pluggableAdaptor.
boldButton label: 'bold'.
boldButtons := CompositePart new.
boldButtons add: lightButton in: (0 @ 0 corner: 1 @ 0.333).
boldButtons add: plainButton in: (0 @ 0.333 corner: 1 @ 0.666).
boldButtons add: boldButton in: (0 @ 0.666 corner: 1 @ 1).
^boldButtons!
boldNumber: anInteger
| boldness |
anInteger isNil
ifTrue: [bold := 0.5]
ifFalse:
[boldness := 0 max: (anInteger min: 1).
boldness <= 0.3 ifTrue: [bold := 0.3].
(0.3 < boldness and: [boldness < 0.7])
ifTrue: [bold := 0.5].
0.7 <= boldness ifTrue: [bold := 0.7]]! !
!EngiFontModel methodsFor: 'italic accessing'!
italic
^italic = true!
italic: aBoolean
italic := aBoolean = true.
self changed: #italic!
italicButton
| baseModel pluggableAdaptor italicButton |
baseModel := PluggableAdaptor on: self.
baseModel getSelector: #italic putSelector: #italic:.
pluggableAdaptor := PluggableAdaptor on: baseModel.
pluggableAdaptor selectValue: true.
italicButton := Button switch.
italicButton model: pluggableAdaptor.
italicButton label: 'italic'.
^italicButton! !
!EngiFontModel methodsFor: 'underline accessing'!
underline
^underline = true!
underline: aBoolean
underline := aBoolean = true.
self changed: #underline!
underlineButton
| baseModel pluggableAdaptor underlineButton |
baseModel := PluggableAdaptor on: self.
baseModel getSelector: #underline putSelector: #underline:.
pluggableAdaptor := PluggableAdaptor on: baseModel.
pluggableAdaptor selectValue: true.
underlineButton := Button switch.
underlineButton model: pluggableAdaptor.
underlineButton label: 'underline'.
^underlineButton! !
!EngiFontModel methodsFor: 'outline accessing'!
outline
^outline = true!
outline: aBoolean
outline := aBoolean = true.
self changed: #outline!
outlineButton
| baseModel pluggableAdaptor outlineButton |
baseModel := PluggableAdaptor on: self.
baseModel getSelector: #outline putSelector: #outline:.
pluggableAdaptor := PluggableAdaptor on: baseModel.
pluggableAdaptor selectValue: true.
outlineButton := Button switch.
outlineButton model: pluggableAdaptor.
outlineButton label: 'outline'.
^outlineButton! !
!EngiFontModel methodsFor: 'shadow accessing'!
shadow
^shadow = true!
shadow: aBoolean
shadow := aBoolean = true.
self changed: #shadow!
shadowButton
| baseModel pluggableAdaptor shadowButton |
baseModel := PluggableAdaptor on: self.
baseModel getSelector: #shadow putSelector: #shadow:.
pluggableAdaptor := PluggableAdaptor on: baseModel.
pluggableAdaptor selectValue: true.
shadowButton := Button switch.
shadowButton model: pluggableAdaptor.
shadowButton label: 'shadow'.
^shadowButton! !
!EngiFontModel methodsFor: 'width accessing'!
width
width <= 0.3 ifTrue: [^#narrow].