[squeak-dev] The Trunk: Collections-mt.995.mcz
Christoph.Thiede at student.hpi.uni-potsdam.de
Sat Mar 26 15:32:01 UTC 2022
Sigh, these things could be so much easier if we had something like a TextCharacter that could be put into a String. :D
Von: Squeak-dev <squeak-dev-bounces at lists.squeakfoundation.org> im Auftrag von commits at source.squeak.org <commits at source.squeak.org>
Gesendet: Montag, 14. März 2022 15:54:31
An: squeak-dev at lists.squeakfoundation.org; packages at lists.squeakfoundation.org
Betreff: [squeak-dev] The Trunk: Collections-mt.995.mcz
Marcel Taeumel uploaded a new version of Collections to project The Trunk:
==================== Summary ====================
Time: 14 March 2022, 3:54:27.937786 pm
Adds #withNoLineLongerThan: to Text. Complements Graphics-mt.498 (and also Morphic-mt.1933 in some sense).
Feel free to check all three implementors and learn about their differences. :-)
=============== Diff against Collections-mt.994 ===============
Item was added:
+ ----- Method: Text>>withNoLineLongerThan: (in category 'converting') -----
+ withNoLineLongerThan: numChars
+ "Font-specific version of String >> #withNoLineLongerThan: that supports font family and point size changes throughout the text. Compose the receiver's contents and answer a text that has all soft line breaks converted to hard line breaks.
+ NOTE THAT while we keep the name from the String protocol, it will happen that some lines are longer or shorter than numChars because composition happens in a rectangle. If you want a character-perfect result, call #withNoLineLongerThan: on the receiver's string contents. The average length of a line, however, will approximate numChars.
+ (Note that, in Morphic, you can use TextMorph if you want to keep the soft line breaks and not modify the text contents.)"
+ | style paragraph |
+ self ifEmpty: [^ self copy].
+ (self environment classNamed: #NewParagraph)
+ ifNil: [^ (self asString withNoLineLongerThan: numChars) asText]
+ ifNotNil: [:paragraphClass | paragraph := paragraphClass new].
+ "Configure the paragraph with a text style. Use the default text style only if the receiver has no custom font set for the first character. In that case, use the style that comes with that custom font. Use #asNewTextStyle to create a copy that has the correct #defaultFont (and point size) set."
+ compose: self
+ style: (style := (self fontAt: 1 withStyle: TextStyle default)
+ from: 1
+ in: (0 at 0 extent: (style compositionWidthFor: numChars) @ 9999999).
+ ^ paragraph asTextWithLineBreaks!
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Squeak-dev