home *** CD-ROM | disk | FTP | other *** search
/ BURKS 2 / BURKS_AUG97.ISO / BURKS / LANGUAGE / SMALTALK / TEXTBOOK / AP07.ST (.txt) < prev    next >
Text File  |  1997-04-22  |  17KB  |  585 lines

  1.  
  2. 'Smalltalk Textbook Appendix 07'!
  3.  
  4.  
  5.  
  6.  
  7.  
  8. EngiVariable subclass: #EngiFontModel
  9.     instanceVariableNames: 'family size bold italic underline outline shadow width color '
  10.     classVariableNames: ''
  11.     poolDictionaries: ''
  12.     category: 'Engi-Text'!
  13. EngiFontModel comment:
  14. '
  15.  
  16. Engi 0.02 (25 January 1994)
  17. Copyright (C) 1994 by Atsushi Aoki
  18.  
  19. '!
  20.  
  21.  
  22. !EngiFontModel methodsFor: 'initialize-release'!
  23.  
  24. initialize
  25.     super initialize.
  26.     self initialize: TextAttributes default defaultFont.
  27.     ^self!
  28.  
  29. initialize: fontDescription 
  30.     self family: fontDescription family.
  31.     self size: fontDescription pixelSize.
  32.     self boldNumber: fontDescription boldness.
  33.     self italic: fontDescription italic.
  34.     self underline: fontDescription underline.
  35.     self outline: fontDescription outline.
  36.     self shadow: fontDescription shadow.
  37.     self widthNumber: fontDescription setWidth.
  38.     self color: fontDescription color! !
  39.  
  40. !EngiFontModel methodsFor: 'accessing'!
  41.  
  42. searchFontDescription
  43.     | fontDescription |
  44.     fontDescription := FontDescription new.
  45.     family notNil ifTrue: [fontDescription family: family].
  46.     size notNil ifTrue: [fontDescription pixelSize: size].
  47.     bold notNil ifTrue: [fontDescription boldness: bold].
  48.     italic notNil ifTrue: [fontDescription italic: italic].
  49.     underline notNil ifTrue: [fontDescription underline: underline].
  50.     outline notNil ifTrue: [fontDescription outline: outline].
  51.     shadow notNil ifTrue: [fontDescription shadow: shadow].
  52.     width notNil ifTrue: [fontDescription setWidth: width].
  53.     color notNil ifTrue: [fontDescription color: color].
  54.     Screen default defaultFontPolicy searchForFont: fontDescription allowance: 9.
  55.     ^fontDescription!
  56.  
  57. value
  58.     value isNil ifTrue: [self setValue: self visual].
  59.     ^value! !
  60.  
  61. !EngiFontModel methodsFor: 'visual accessing'!
  62.  
  63. visual
  64.     | fontDescription characterAttributes textAttributes deviceFont composedText |
  65.     fontDescription := self searchFontDescription.
  66.     characterAttributes := CharacterAttributes newWithDefaultAttributes.
  67.     characterAttributes setDefaultQuery: fontDescription.
  68.     textAttributes := TextAttributes new.
  69.     textAttributes setCharacterAttributes: characterAttributes.
  70.     deviceFont := Screen default defaultFontPolicy findFont: textAttributes defaultFont.
  71.     textAttributes lineGrid: deviceFont height.
  72.     textAttributes baseline: deviceFont ascent.
  73.     composedText := ComposedText withText: 'Smalltalk' asText style: textAttributes.
  74.     ^composedText!
  75.  
  76. visualView
  77.     | visualView edgeDecorator |
  78.     visualView := EngiDisplayView model: self.
  79.     edgeDecorator := LookPreferences edgeDecorator on: visualView.
  80.     edgeDecorator noMenuBar.
  81.     edgeDecorator noVerticalScrollBar.
  82.     edgeDecorator noHorizontalScrollBar.
  83.     ^edgeDecorator! !
  84.  
  85. !EngiFontModel methodsFor: 'family accessing'!
  86.  
  87. family
  88.     ^family!
  89.  
  90. family: aString 
  91.     family := aString.
  92.     self changed: #familySelection.
  93.     self changed: #sizeString!
  94.  
  95. familyList
  96.     ^self class allFontFamilies!
  97.  
  98. familyMenu
  99.     ^nil!
  100.  
  101. familySelection
  102.     ^self family!
  103.  
  104. familyView
  105.     | familyView edgeDecorator |
  106.     familyView := SelectionInListView
  107.                 on: self
  108.                 aspect: #family
  109.                 change: #family:
  110.                 list: #familyList
  111.                 menu: #familyMenu
  112.                 initialSelection: #familySelection.
  113.     edgeDecorator := LookPreferences edgeDecorator on: familyView.
  114.     edgeDecorator noMenuBar.
  115.     edgeDecorator useVerticalScrollBar.
  116.     edgeDecorator useHorizontalScrollBar.
  117.     ^edgeDecorator! !
  118.  
  119. !EngiFontModel methodsFor: 'size accessing'!
  120.  
  121. size
  122.     ^size!
  123.  
  124. size: anInteger 
  125.     size := anInteger.
  126.     self changed: #sizeSelection.
  127.     self changed: #visual!
  128.  
  129. sizeList
  130.     self family isNil ifTrue: [^nil].
  131.     ^(self class allFontSizes: self family)
  132.         collect: [:each | each printString]!
  133.  
  134. sizeMenu
  135.     ^nil!
  136.  
  137. sizeSelection
  138.     ^self sizeString!
  139.  
  140. sizeString
  141.     self size isNil ifTrue: [^nil].
  142.     ^self size printString!
  143.  
  144. sizeString: aString 
  145.     aString isNil
  146.         ifTrue: [self size: nil]
  147.         ifFalse: [self size: aString asNumber]!
  148.  
  149. sizeView
  150.     | sizeView edgeDecorator |
  151.     sizeView := SelectionInListView
  152.                 on: self
  153.                 aspect: #sizeString
  154.                 change: #sizeString:
  155.                 list: #sizeList
  156.                 menu: #sizeMenu
  157.                 initialSelection: #sizeSelection.
  158.     edgeDecorator := LookPreferences edgeDecorator on: sizeView.
  159.     edgeDecorator noMenuBar.
  160.     edgeDecorator useVerticalScrollBar.
  161.     edgeDecorator noHorizontalScrollBar.
  162.     ^edgeDecorator! !
  163.  
  164. !EngiFontModel methodsFor: 'bold accessing'!
  165.  
  166. bold
  167.     bold <= 0.3 ifTrue: [^#light].
  168.     (0.3 < bold and: [bold < 0.7])
  169.         ifTrue: [^#plain].
  170.     0.7 <= bold ifTrue: [^#bold].
  171.     ^nil!
  172.  
  173. bold: aSymbol 
  174.     aSymbol = #light ifTrue: [self boldNumber: 0.3].
  175.     aSymbol = #plain ifTrue: [self boldNumber: 0.5].
  176.     aSymbol = #bold ifTrue: [self boldNumber: 0.7].
  177.     self changed: #bold!
  178.  
  179. boldButtons
  180.     | baseModel pluggableAdaptor lightButton plainButton boldButton boldButtons |
  181.     baseModel := PluggableAdaptor on: self.
  182.     baseModel getSelector: #bold putSelector: #bold:.
  183.     pluggableAdaptor := PluggableAdaptor on: baseModel.
  184.     pluggableAdaptor selectValue: #light.
  185.     lightButton := Button toggle.
  186.     lightButton model: pluggableAdaptor.
  187.     lightButton label: 'light'.
  188.     baseModel := PluggableAdaptor on: self.
  189.     baseModel getSelector: #bold putSelector: #bold:.
  190.     pluggableAdaptor := PluggableAdaptor on: baseModel.
  191.     pluggableAdaptor selectValue: #plain.
  192.     plainButton := Button toggle.
  193.     plainButton model: pluggableAdaptor.
  194.     plainButton label: 'plain'.
  195.     baseModel := PluggableAdaptor on: self.
  196.     baseModel getSelector: #bold putSelector: #bold:.
  197.     pluggableAdaptor := PluggableAdaptor on: baseModel.
  198.     pluggableAdaptor selectValue: #bold.
  199.     boldButton := Button toggle.
  200.     boldButton model: pluggableAdaptor.
  201.     boldButton label: 'bold'.
  202.     boldButtons := CompositePart new.
  203.     boldButtons add: lightButton in: (0 @ 0 corner: 1 @ 0.333).
  204.     boldButtons add: plainButton in: (0 @ 0.333 corner: 1 @ 0.666).
  205.     boldButtons add: boldButton in: (0 @ 0.666 corner: 1 @ 1).
  206.     ^boldButtons!
  207.  
  208. boldNumber: anInteger 
  209.     | boldness |
  210.     anInteger isNil
  211.         ifTrue: [bold := 0.5]
  212.         ifFalse: 
  213.             [boldness := 0 max: (anInteger min: 1).
  214.             boldness <= 0.3 ifTrue: [bold := 0.3].
  215.             (0.3 < boldness and: [boldness < 0.7])
  216.                 ifTrue: [bold := 0.5].
  217.             0.7 <= boldness ifTrue: [bold := 0.7]]! !
  218.  
  219. !EngiFontModel methodsFor: 'italic accessing'!
  220.  
  221. italic
  222.     ^italic = true!
  223.  
  224. italic: aBoolean 
  225.     italic := aBoolean = true.
  226.     self changed: #italic!
  227.  
  228. italicButton
  229.     | baseModel pluggableAdaptor italicButton |
  230.     baseModel := PluggableAdaptor on: self.
  231.     baseModel getSelector: #italic putSelector: #italic:.
  232.     pluggableAdaptor := PluggableAdaptor on: baseModel.
  233.     pluggableAdaptor selectValue: true.
  234.     italicButton := Button switch.
  235.     italicButton model: pluggableAdaptor.
  236.     italicButton label: 'italic'.
  237.     ^italicButton! !
  238.  
  239. !EngiFontModel methodsFor: 'underline accessing'!
  240.  
  241. underline
  242.     ^underline = true!
  243.  
  244. underline: aBoolean 
  245.     underline := aBoolean = true.
  246.     self changed: #underline!
  247.  
  248. underlineButton
  249.     | baseModel pluggableAdaptor underlineButton |
  250.     baseModel := PluggableAdaptor on: self.
  251.     baseModel getSelector: #underline putSelector: #underline:.
  252.     pluggableAdaptor := PluggableAdaptor on: baseModel.
  253.     pluggableAdaptor selectValue: true.
  254.     underlineButton := Button switch.
  255.     underlineButton model: pluggableAdaptor.
  256.     underlineButton label: 'underline'.
  257.     ^underlineButton! !
  258.  
  259. !EngiFontModel methodsFor: 'outline accessing'!
  260.  
  261. outline
  262.     ^outline = true!
  263.  
  264. outline: aBoolean 
  265.     outline := aBoolean = true.
  266.     self changed: #outline!
  267.  
  268. outlineButton
  269.     | baseModel pluggableAdaptor outlineButton |
  270.     baseModel := PluggableAdaptor on: self.
  271.     baseModel getSelector: #outline putSelector: #outline:.
  272.     pluggableAdaptor := PluggableAdaptor on: baseModel.
  273.     pluggableAdaptor selectValue: true.
  274.     outlineButton := Button switch.
  275.     outlineButton model: pluggableAdaptor.
  276.     outlineButton label: 'outline'.
  277.     ^outlineButton! !
  278.  
  279. !EngiFontModel methodsFor: 'shadow accessing'!
  280.  
  281. shadow
  282.     ^shadow = true!
  283.  
  284. shadow: aBoolean 
  285.     shadow := aBoolean = true.
  286.     self changed: #shadow!
  287.  
  288. shadowButton
  289.     | baseModel pluggableAdaptor shadowButton |
  290.     baseModel := PluggableAdaptor on: self.
  291.     baseModel getSelector: #shadow putSelector: #shadow:.
  292.     pluggableAdaptor := PluggableAdaptor on: baseModel.
  293.     pluggableAdaptor selectValue: true.
  294.     shadowButton := Button switch.
  295.     shadowButton model: pluggableAdaptor.
  296.     shadowButton label: 'shadow'.
  297.     ^shadowButton! !
  298.  
  299. !EngiFontModel methodsFor: 'width accessing'!
  300.  
  301. width
  302.     width <= 0.3 ifTrue: [^#narrow].
  303.