[squeak-dev] The Trunk: Morphic-mt.1846.mcz
commits at source.squeak.org
commits at source.squeak.org
Mon Jan 17 16:14:00 UTC 2022
Marcel Taeumel uploaded a new version of Morphic to project The Trunk:
http://source.squeak.org/trunk/Morphic-mt.1846.mcz
==================== Summary ====================
Name: Morphic-mt.1846
Author: mt
Time: 17 January 2022, 5:13:49.392958 pm
UUID: e9cda770-83d4-3742-8732-43a4d226e066
Ancestors: Morphic-ct.1845
Complements Collections-mt.974.
Clean up code that explicitely sets a text-morph's #font:. Re-use that font's #textStyle if possible.
=============== Diff against Morphic-ct.1845 ===============
Item was changed:
----- Method: PluggableTextMorph>>font: (in category 'initialization') -----
font: aFont
+ textMorph font: aFont.!
- textMorph beAllFont: aFont!
Item was added:
+ ----- Method: PluggableTextMorph>>textStyle: (in category 'initialization') -----
+ textStyle: aTextStyle
+ textMorph textStyle: aTextStyle.!
Item was changed:
----- Method: TextMorph>>beAllFont: (in category 'initialization') -----
beAllFont: aFont
+ "Change the receiver's default font, which is used to draw its contents. Also see commentary in #font:."
+ self font: aFont.!
- textStyle := TextStyle fontArray: (Array with: aFont).
- text ifNotNil: [text addAttribute: (TextFontReference toFont: aFont)].
- self releaseParagraph.!
Item was changed:
----- Method: TextMorph>>font: (in category 'accessing') -----
font: aFont
+ "Change the receiver's default font, which is used to draw its contents. Remove all custom font-face-related attributes from the current contents. Try to lookup the matching #textStyle so that TextFontChange can be used from here on. For a less harsh approach, just use #textStyle: instead and rely on text attributes.
+
+ !! It is best practice to work with #textStyle: and rely on the text attributes TextFontChange and (sometimes) TextFontReference."
+
| newTextStyle |
+ self text removeAttributesThat: [:attr | attr isTextFontChange and: [attr canFontBeSubstituted]].
+
+ newTextStyle := aFont textStyleOrNil
+ ifNil: [TextStyle fontArray: {aFont}]
+ ifNotNil: [:style | style copy].
+ newTextStyle defaultFontIndex: (newTextStyle fontIndexOf: aFont).
+
+ self textStyle: newTextStyle.!
- newTextStyle := aFont textStyle copy ifNil: [ TextStyle fontArray: { aFont } ].
- textStyle := newTextStyle.
- text addAttribute: (TextFontChange fontNumber: (newTextStyle fontIndexOf: aFont)).
- self releaseParagraph.
- !
Item was changed:
----- Method: TextMorph>>fontName:pointSize: (in category 'initialization') -----
fontName: fontName pointSize: fontSize
+ "Change the receiver's default font, which is used to draw its contents. Also see commentary in #font:."
- | newTextStyle |
- newTextStyle := ((TextStyle named: fontName asSymbol) ifNil: [ TextStyle default ]) copy.
- newTextStyle ifNil: [self error: 'font ', fontName, ' not found.'].
+ self font: (((TextStyle named: fontName asSymbol) ifNil: [TextStyle default]) fontOfPointSize: fontSize).!
- textStyle := newTextStyle.
- text addAttribute: (TextFontChange fontNumber: (newTextStyle fontIndexOfPointSize: fontSize)).
- self releaseParagraph.!
Item was changed:
----- Method: TextMorph>>fontName:size: (in category 'initialization') -----
+ fontName: fontName size: pixelSize
+ "Change the receiver's default font, which is used to draw its contents. Also see commentary in #font:."
+
+ self font: (((TextStyle named: fontName asSymbol) ifNil: [TextStyle default]) fontOfSize: pixelSize).!
- fontName: fontName size: fontSize
- | newTextStyle |
- newTextStyle := ((TextStyle named: fontName asSymbol) ifNil: [ TextStyle default ]) copy.
- textStyle := newTextStyle.
- text addAttribute: (TextFontChange fontNumber: (newTextStyle fontIndexOfSize: fontSize)).
- self releaseParagraph.!
Item was added:
+ ----- Method: TextMorph>>textStyle: (in category 'accessing') -----
+ textStyle: aTextStyle
+ "Change the receiver's set of fonts to aTextStyle. You can access those fonts via the TextFontChange text attribute. If you want to enfore a specific font face or point size, use #font: instead."
+
+ textStyle := aTextStyle.
+ self releaseParagraph.!
More information about the Squeak-dev
mailing list
|