[Pkg] The Trunk: Graphics-nice.263.mcz

commits at source.squeak.org commits at source.squeak.org
Thu Oct 10 00:38:39 UTC 2013


Nicolas Cellier uploaded a new version of Graphics to project The Trunk:
http://source.squeak.org/trunk/Graphics-nice.263.mcz

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

Name: Graphics-nice.263
Author: nice
Time: 10 October 2013, 2:37:14.887 am
UUID: 1abc4a7b-b316-4839-b6e0-0760988fc284
Ancestors: Graphics-nice.262

Hardcode [^#endOfRun] and [^#crossedX] instead of [^stopConditions endOfRun] and [^stopConditions crossedX].
The possibility of having a different symbol are never used and cost an indirection in character scanning inner loop.
They also are a barrier to the restoring of primitive 103 for slow machines.
Initialize DefaulStopConditions and friends with an Array.
We'll then can get rid of TextStopConditions.

=============== Diff against Graphics-nice.262 ===============

Item was changed:
  Object subclass: #CharacterScanner
  	instanceVariableNames: 'destX lastIndex destY stopConditions text textStyle alignment leftMargin rightMargin font line runStopIndex spaceCount spaceWidth emphasisCode kern indentationLevel wantsColumnBreaks pendingKernX'
  	classVariableNames: 'ColumnBreakStopConditions CompositionStopConditions DefaultStopConditions MeasuringStopConditions PaddedSpaceCondition'
  	poolDictionaries: 'TextConstants'
  	category: 'Graphics-Text'!
  
+ !CharacterScanner commentStamp: 'nice 10/10/2013 02:32' prior: 0!
- !CharacterScanner commentStamp: 'nice 10/6/2013 23:18' prior: 0!
  A CharacterScanner holds the state associated with scanning text. Subclasses scan characters for specified purposes, such as computing a CharacterBlock or placing characters into Forms.
  
  Instance Variables
  	alignment:		<Integer>
  	destX:		<Number>
  	destY:		<Number>
  	emphasisCode:		<Object>
  	font:		<AbstractFont>
  	indentationLevel:		<Integer>
  	kern:		<Number>
  	lastIndex:		<Integer>
  	leftMargin:		<Number>
  	line:		<TextLine>
  	pendingKernX:		<Number>
  	rightMargin:		<Number>
  	runStopIndex:		<Integer>
  	spaceCount:		<Integer>
  	spaceWidth:		<Number>
+ 	stopConditions:		<Array>
- 	stopConditions:		<TextStopConditions>
  	text:		<Text>
  	textStyle:		<TextStyle>
  	wantsColumnBreaks:		<Boolean>
  
  alignment
  	- an Integer encoding the alignment of text
  
  destX
  	- horizontal position for next character (distance from left of composition area)
  
  destY
  	- vertical position for next character (distance from top of composition area)
  
  emphasisCode
  	- an Integer encoding the current text emphasis to use (bold, italic, ...)
  
  font
  	- the current font used for measuring/composing/displaying characters
  
  indentationLevel
  	- an Integer specifying a number of leading tabs to be inserted at beginning of new lines
  
  kern
  	- a Number specifying additional horizontal spacing to place between characters (spacing is reduced when kern is negative)
  
  lastIndex
  	- the Integer index of next character to be processed in the text
  
  leftMargin
  	- a Number specifying the distance between left of composition zone and left of first character in the line.
  
  line
  	- an object holding information about the line currently being displayed (like first and last index in text).
  	Note: this is either a TextLine in Morphic, or TextLineInterval for ST80 compatibility
  
  pendingKernX
  	- a Number to be added to horizontal spacing of next char if ever it is in the same font than previous one.
  	The inner scan loop is interrupted by a change of text run.
  	But some changes won't change the font, so the kerning must be remembered and applied later.
  
  rightMargin
  	- a Number specifying the distance between right of composition zone and right of last character in the line.
  
  runStopIndex
  	- the Integer index of last character in current text run.
  
  spaceCount
  	- the number of spaces encoutered so far in current line. This is useful for adjusting the spacing in cas of Justified alignment.
  
  spaceWidth
  	- the width of space character in current font.
  
  stopConditions
+ 	- an Array mapping a table of characters codes for which special actions are to be taken.
- 	- an object holding a table of characters for which special actions are to be taken.
  	These are typically control characters like carriage return or horizontal tab.
  
  text
  	- the text to be measured/composed/displayed
  
  textStyle
  	- an object holding a context for the text style (which set of font to use, which margins, etc...)
  
  wantsColumnBreaks
  	- a Boolean indicating whether some special handling for multiple columns is requested.
  	THIS ONLY MAKES SENSE IN CompositionScanner AND SHOULD BE MOVED TO THE SUBCLASS
  	
  
  !

Item was changed:
  ----- Method: CharacterScanner class>>initialize (in category 'class initialization') -----
  initialize
  "
  	CharacterScanner initialize
  "
  	| a |
+ 	a := Array new: 256.
- 	a := TextStopConditions new.
  	a at: 1 + 1 put: #embeddedObject.
  	a at: Tab asciiValue + 1 put: #tab.
  	a at: CR asciiValue + 1 put: #cr.
  	a at: Character lf asciiValue + 1 put: #cr.
  	
  	DefaultStopConditions := a copy.
  
  	CompositionStopConditions := a copy.
  	CompositionStopConditions at: Space asciiValue + 1 put: #space.
  	ColumnBreakStopConditions := CompositionStopConditions copy.
  	ColumnBreakStopConditions at: Character characterForColumnBreak asciiValue + 1 put: #columnBreak.
  
  	PaddedSpaceCondition := a copy.
  	PaddedSpaceCondition at: Space asciiValue + 1 put: #paddedSpace.
  
+ 	MeasuringStopConditions := Array new: 256!
- 	MeasuringStopConditions := TextStopConditions new!

Item was changed:
  ----- Method: CharacterScanner>>handleEndOfRunAt: (in category 'scanner methods') -----
  handleEndOfRunAt: stopIndex
  	" make sure the lastIndex is set to stopIndex and then return the stopCondition for endOfRun; important for  a couple of outside users"
  
  	lastIndex := stopIndex.
+ 	^#endOfRun!
- 	^ stopConditions endOfRun!

Item was changed:
  ----- Method: CharacterScanner>>scanByteCharactersFrom:to:in:rightX: (in category 'scanning') -----
  scanByteCharactersFrom: startIndex to: stopIndex in: sourceString rightX: rightX 
  "this is a scanning method for
  single byte characters in a ByteString
  a font that does not do character-pair kerning"
  	| ascii nextDestX char |
  	lastIndex := startIndex.
  	[lastIndex <= stopIndex]
  		whileTrue: [
  			"get the character value"
  			char := sourceString at: lastIndex.
  			ascii := char asciiValue + 1.
  			"if there is an entry in 'stops' for this value, return it"
  			(stopConditions at: ascii)
  				ifNotNil: [^ stopConditions at: ascii].
  			"bump nextDestX by the width of the current character"
  			nextDestX := destX + (font widthOf: char).
  			"if the next x is past the right edge, return crossedX"
  			nextDestX > rightX
+ 				ifTrue: [^#crossedX].
- 				ifTrue: [^ stopConditions crossedX].
  			"update destX and incorporate thr kernDelta"
  			destX := nextDestX + kern.
  			lastIndex := lastIndex + 1].
  	^self handleEndOfRunAt: stopIndex
  
  !

Item was changed:
  ----- Method: CharacterScanner>>scanKernableByteCharactersFrom:to:in:rightX: (in category 'scanning') -----
  scanKernableByteCharactersFrom: startIndex to: stopIndex in: sourceString rightX: rightX 
  "this is a scanning method for
  single byte characters in a ByteString
  a font that does do character-pair kerning via widthAndKernedWidthOfLeft:right:into:"
  	| ascii nextDestX char floatDestX widthAndKernedWidth nextCharOrNil atEndOfRun |
  	lastIndex := startIndex.
  	floatDestX := destX.
  	widthAndKernedWidth := Array new: 2.
  	atEndOfRun := false.
  	[lastIndex <= stopIndex]
  		whileTrue: [
  			"get the character value"
  			char := sourceString at: lastIndex.
  			ascii := char asciiValue + 1.
  			"if there is an entry in 'stops' for this value, return it"
  			(stopConditions at: ascii)
  				ifNotNil: [^ stopConditions at: ascii].
  			"get the next character..."
  			nextCharOrNil := lastIndex + 1 <= stopIndex
  						ifTrue: [sourceString at: lastIndex + 1]
  						ifFalse: ["if we're at or past the stopIndex, see if there is anything in the full string"
  							atEndOfRun := true.
  							lastIndex + 1 <= sourceString size
  								ifTrue: [sourceString at: lastIndex + 1]].
  			"get the font's kerning info for the pair of current character and next character"
  			"for almost all fonts in common use this is a waste of time since they don't support pair kerning and both values are #widthOf: char"
  			font
  				widthAndKernedWidthOfLeft: char
  				right: nextCharOrNil
  				into: widthAndKernedWidth.
  			"bump nextDestX by the width of the current character"
  			nextDestX := floatDestX
  						+ (widthAndKernedWidth at: 1).
  			"if the next x is past the right edge, return crossedX"
  			nextDestX > rightX
+ 				ifTrue: [^ #crossedX].
- 				ifTrue: [^ stopConditions crossedX].
  			"bump floatDestX by the *kerned* width of the current
  			character, which is where the *next* char will go"
  			floatDestX := floatDestX + kern
  						+ (widthAndKernedWidth at: 2).
  			"if we are at the end of this run we keep track of the
  			character-kern-delta for possible later use and then rather
  			insanely remove that character-kern-delta from floatDestX,
  			making it equivalent to (old floatDestX) + kernDelta +
  			width-of-character - no idea why"
  			atEndOfRun
  				ifTrue: [pendingKernX := (widthAndKernedWidth at: 2)
  								- (widthAndKernedWidth at: 1).
  					floatDestX := floatDestX - pendingKernX].
  			"save the next x for next time around the loop"
  			destX := floatDestX.
  			lastIndex := lastIndex + 1].
  	^self handleEndOfRunAt: stopIndex
  !



More information about the Packages mailing list