[squeak-dev] The Trunk: Graphics-mt.478.mcz

commits at source.squeak.org commits at source.squeak.org
Thu Feb 10 15:49:34 UTC 2022

Marcel Taeumel uploaded a new version of Graphics to project The Trunk:

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

Name: Graphics-mt.478
Author: mt
Time: 10 February 2022, 4:49:27.975843 pm
UUID: 32a81c5c-3292-d14e-ab72-3f144adc8bad
Ancestors: Graphics-mt.477

Fixes lineGap for text paragraphs with mixed fonts (or point sizes).

=============== Diff against Graphics-mt.477 ===============

Item was changed:
  CharacterScanner subclass: #CompositionScanner
+ 	instanceVariableNames: 'spaceX spaceIndex lineHeight baseline lineGap lineGapSlice lineHeightAtSpace baselineAtSpace lastBreakIsNotASpace nextIndexAfterLineBreak'
- 	instanceVariableNames: 'spaceX spaceIndex lineHeight baseline lineHeightAtSpace baselineAtSpace lastBreakIsNotASpace nextIndexAfterLineBreak'
  	classVariableNames: ''
  	poolDictionaries: ''
  	category: 'Graphics-Text'!
  !CompositionScanner commentStamp: 'nice 10/6/2013 23:24' prior: 0!
  A CompositionScanner measures text and determines where line breaks.
  Given a rectangular zone on input, it is used to split text in horizontal lines, and produce information about those lines on output (at which index a line starts/stops, which vertical space does the line require, which horizontal space if left for adjusting inter-word spacing, etc...)
  Instance Variables
  	baseline:		<Number>
  	baselineAtSpace:		<Number>
  	lastBreakIsNotASpace:		<Boolean>
  	lineHeight:		<Number>
  	lineHeightAtSpace:		<Number>
  	nextIndexAfterLineBreak:		<Integer>
  	spaceIndex:		<Integer>
  	spaceX:		<Number>
  	- the distance between top of line and the base line (that is the bottom of latin characters abcdehiklmnorstuvwx in most fonts)
  	- memorize the baseline at last encountered space or other breakable character.
  	This is necessary because the CompositionScanner wants to break line at a breakable character.
  	If a word layout overflows the right margin, the scanner has to roll back and restore the line state to last encountered breakable character.
  	- indicates that the last breakable character was not a space.
  	This is necessary because handling a line break at a space differs from non space.
  	If line break occurs on space, the space won't be displayed in next line.
  	If it's another breakable character, it has to be displayed on next line.
  	- the total line height from top to bottom, including inter-line spacing.
  	- the line height at last encountered space or other breakable character.
  	See baselineAtSpace for explanation.
  	- the index of character after the last line break that was encountered.
  	- the index of last space or other breakable character that was encountered
  	- the distance from left of composition zone to left of last encountered space or other breakable character 
  	See baselineAtSpace for explanation.
  Note: if a line breaks on a space, a linefeed or a carriage return, then the space, linefeed or carriage return is integrated in the line.
  If there is a carriage return - linefeed pair, the pair is integrated to the line as if it were a single line break for compatibility with legacy software.!

Item was changed:
  ----- Method: CompositionScanner>>composeFrom:inRectangle:firstLine:leftSide:rightSide: (in category 'scanning') -----
  composeFrom: startIndex inRectangle: lineRectangle
  	firstLine: firstLine leftSide: leftSide rightSide: rightSide
  	"Answer an instance of TextLineInterval that represents the next line in the paragraph."
  	| runLength stopCondition |
  	"Set up margins"
  	leftMargin := lineRectangle left.
  	leftSide ifTrue: [leftMargin := leftMargin +
  						(firstLine ifTrue: [textStyle firstIndent]
  								ifFalse: [textStyle restIndent])].
  	destX := spaceX := leftMargin.
  	rightMargin := lineRectangle right.
  	rightSide ifTrue: [rightMargin := rightMargin - textStyle rightIndent].
  	lastIndex := startIndex.	"scanning sets last index"
  	destY := lineRectangle top.
+ 	lineHeight := baseline := lineGap := lineGapSlice := 0.  "Will be increased by setFont"
- 	lineHeight := baseline := 0.  "Will be increased by setFont"
  	line := (TextLine start: lastIndex stop: 0 internalSpaces: 0 paddingWidth: 0)
  				rectangle: lineRectangle.
  	self setStopConditions.	"also sets font"
  	runLength := text runLengthFor: startIndex.
  	runStopIndex := (lastIndex := startIndex) + (runLength - 1).
  	nextIndexAfterLineBreak := spaceCount := 0.
  	lastBreakIsNotASpace := false.
  	self handleIndentation.
  	leftMargin := destX.
  	line leftMargin: leftMargin.
  	[stopCondition := self scanCharactersFrom: lastIndex to: runStopIndex
  		in: text string rightX: rightMargin.
  	"See setStopConditions for stopping conditions for composing."
  	self perform: stopCondition] whileFalse.
  	^ line
+ 		lineHeight: lineHeight + lineGap
+ 		baseline: baseline + lineGapSlice!
- 		lineHeight: lineHeight + textStyle leading
- 		baseline: baseline + textStyle leadingSlice!

Item was changed:
  ----- Method: CompositionScanner>>computeDefaultLineHeight (in category 'scanning') -----
  	"Compute the default line height for a potentially empty text"
  	rightMargin notNil
  		ifTrue: [lastIndex := 1.
  			self setFont.
+ 			^ lineHeight + lineGap]
- 			^ lineHeight + textStyle leading]
  		ifFalse: [^textStyle lineGrid]!

Item was changed:
  ----- Method: CompositionScanner>>setActualFont: (in category 'text attributes') -----
  setActualFont: aFont
  	"Keep track of max height and ascent for auto lineheight"
  	| descent |
  	super setActualFont: aFont.
  	lineHeight == nil
  		ifTrue: [descent := font descent.
  				baseline := font ascent.
+ 				lineHeight := baseline + descent.
+ 				lineGap := aFont lineGap.
+ 				lineGapSlice := aFont lineGapSlice]
- 				lineHeight := baseline + descent]
  		ifFalse: [descent := lineHeight - baseline max: font descent.
  				baseline := baseline max: font ascent.
+ 				lineHeight := lineHeight max: baseline + descent.
+ 				lineGap := lineGap max: aFont lineGap.
+ 				lineGapSlice := lineGapSlice max: aFont lineGapSlice]!
- 				lineHeight := lineHeight max: baseline + descent]!

More information about the Squeak-dev mailing list