[squeak-dev] The Trunk: Collections-mt.995.mcz

Marcel Taeumel marcel.taeumel at hpi.de
Mon Mar 28 07:30:22 UTC 2022

Hi Christoph --

> Sigh, these things could be so much easier if we had something like a TextCharacter that could be put into a String. :D

Well, I think that it is a good thing that String is as simple as it is now. Text combines TextAttribute with String, which is a clean concept in itself. Messing around with this separation of concerns wouldn't help that much.

Think about the issue with ByteString and ByteArray we have already. Encoding is not that explicit and clients have to be very careful. See #squeakToUtf8 and #utf8ToSqueak as well as how the #binary mode is treated in out TextConverter variations, especially Utf8TextConverter.


Am 26.03.2022 16:32:12 schrieb Thiede, Christoph <christoph.thiede at student.hpi.uni-potsdam.de>:
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:
http://source.squeak.org/trunk/Collections-mt.995.mcz [http://source.squeak.org/trunk/Collections-mt.995.mcz]

==================== Summary ====================

Name: Collections-mt.995
Author: mt
Time: 14 March 2022, 3:54:27.937786 pm
UUID: 2b6b2cae-7f50-f74b-bf55-732ed03daed5
Ancestors: Collections-mt.994

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."
+        paragraph
+                compose: self
+                style: (style := (self fontAt: 1 withStyle: TextStyle default)
+                        asNewTextStyle)
+                from: 1
+                in: (0 at 0 extent: (style compositionWidthFor: numChars) @ 9999999).
+        ^ paragraph asTextWithLineBreaks!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20220328/96377c62/attachment.html>

More information about the Squeak-dev mailing list