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

commits at source.squeak.org commits at source.squeak.org
Mon Mar 14 14:54:31 UTC 2022


Marcel Taeumel uploaded a new version of Collections to project The Trunk:
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!



More information about the Squeak-dev mailing list