[squeak-dev] The Trunk: Graphics-nice.253.mcz

commits at source.squeak.org commits at source.squeak.org
Sun Oct 6 14:21:59 UTC 2013


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

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

Name: Graphics-nice.253
Author: nice
Time: 31 August 2013, 6:18:17.172 pm
UUID: a6c5f5d3-77b5-417f-97bc-a7234830f298
Ancestors: Graphics-nice.252

Remove space stopCondition again now that it is unused and that a proper Monticello configuration Map enables gentle update.
Fix a subtle glitch related to this removal: the space width will now be indented by kern in CharacterBlockScanner and DisplayScanner, so the CompositionScanner must also do so (same for paddedSpace).
Arrange to have the CharacterBlockScanner behaving with embedded object like with any other character: click left of middle select before, right of middle select after the embedded object. Change the logic of placeEmbeddedObject: for this purpose:
- if the object fits, placeEmbeddedObject: is responsible for incrementing destX
- and embeddedObject is responsible for incrementing the character index (lastIndex)
- otherwise embeddedObject shall send crossedX if the object doesn't fit
Remove unnecessary runX inst var from DisplayScanner (written but never read).

=============== Diff against Graphics-nice.252 ===============

Item was changed:
  ----- Method: CharacterBlockScanner>>paddedSpace (in category 'stop conditions') -----
  paddedSpace
  	"When the line is justified, the spaces will not be the same as the font's 
  	space character. A padding of extra space must be considered in trying 
  	to find which character the cursor is pointing at. Answer whether the 
  	scanning has crossed the cursor."
  
  	| pad |
  	spaceCount := spaceCount + 1.
  	pad := line justifiedPadFor: spaceCount font: font.
  	lastCharacterWidth := spaceWidth + pad.
  	(destX + lastCharacterWidth)  >= characterPoint x
  		ifTrue:
  			[^self crossedX].
  	lastIndex := lastIndex + 1.
+ 	destX := destX + lastCharacterWidth + kern.
- 	destX := destX + lastCharacterWidth.
  	^ false
  !

Item was changed:
  ----- Method: CharacterBlockScanner>>placeEmbeddedObject: (in category 'private') -----
  placeEmbeddedObject: anchoredMorph
  	"Workaround: The following should really use #textAnchorType"
+ 	| w |
  	anchoredMorph relativeTextAnchorPosition ifNotNil:[^true].
+ 	w := anchoredMorph width.
+ 	specialWidth := w.
+ 	(destX + w > characterPoint x) ifTrue: [^false].
+ 	destX := destX + w + kern.
- 	(super placeEmbeddedObject: anchoredMorph) ifFalse: [^ false].
- 	specialWidth := anchoredMorph width.
  	^ true!

Item was removed:
- ----- Method: CharacterBlockScanner>>space (in category 'stop conditions') -----
- space
- 	"Account for spaceWidth"
- 
- 	spaceCount := spaceCount + 1.
- 	lastCharacterWidth := spaceWidth.
- 	(destX + lastCharacterWidth)  >= characterPoint x
- 		ifTrue:
- 			[^self crossedX].
- 	lastIndex := lastIndex + 1.
- 	destX := destX + lastCharacterWidth.
- 	^ false!

Item was changed:
  ----- Method: CharacterScanner>>embeddedObject (in category 'stop conditions') -----
  embeddedObject
+ 	pendingKernX := 0.
- 	| savedIndex |
- 	savedIndex := lastIndex.
  	text attributesAt: lastIndex do:[:attr| 
  		attr anchoredMorph ifNotNil:[
+ 			"Try to placeEmbeddedObject: - if it answers false, then there's no place left"
+ 			(self placeEmbeddedObject: attr anchoredMorph) ifFalse:[^self crossedX]]].
+ 	"Note: if ever several objects are embedded on same character, only indent lastIndex once"
+ 	lastIndex := lastIndex + 1.
- 			"Following may look strange but logic gets reversed.
- 			If the morph fits on this line we're not done (return false for true) 
- 			and if the morph won't fit we're done (return true for false)"
- 			(self placeEmbeddedObject: attr anchoredMorph) ifFalse:[^true]]].
- 	lastIndex := savedIndex + 1. "for multiple(!!) embedded morphs"
  	^false!

Item was changed:
  ----- Method: CharacterScanner>>placeEmbeddedObject: (in category 'private') -----
  placeEmbeddedObject: anchoredMorph
+ 	"Place the anchoredMorph or return false if it cannot be placed"
- 	"Place the anchoredMorph or return false if it cannot be placed.
- 	In any event, advance destX by its width."
- 	| w |
- 	"Workaround: The following should really use #textAnchorType"
- 	anchoredMorph relativeTextAnchorPosition ifNotNil:[^true].
- 	destX := destX + (w := anchoredMorph width).
- 	(destX > rightMargin and: [(leftMargin + w) <= rightMargin])
- 		ifTrue: ["Won't fit, but would on next line"
- 				^ false].
- 	lastIndex := lastIndex + 1.
- 	"self setFont."  "Force recalculation of emphasis for next run"
  	^ true!

Item was changed:
  ----- Method: CompositionScanner>>placeEmbeddedObject: (in category 'private') -----
  placeEmbeddedObject: anchoredMorph
+ 	| w descent |
- 	| descent |
  	"Workaround: The following should really use #textAnchorType"
  	anchoredMorph relativeTextAnchorPosition ifNotNil:[^true].
+ 	w := anchoredMorph width.
+ 	(destX + w > rightMargin and: [(leftMargin + w) <= rightMargin or: [lastIndex > line first]])
+ 		ifTrue: ["Won't fit, but would on next line"
+ 				^ false].
+ 	destX := destX + w + kern.
- 	(super placeEmbeddedObject: anchoredMorph) ifFalse: ["It doesn't fit"
- 		"But if it's the first character then leave it here"
- 		lastIndex < line first ifFalse:[
- 			line stop: lastIndex-1.
- 			^ false]].
  	descent := lineHeight - baseline.
  	lineHeight := lineHeight max: anchoredMorph height.
  	baseline := lineHeight - descent.
- 	line stop: lastIndex.
  	^ true!

Item was changed:
+ ----- Method: CompositionScanner>>setStopConditions (in category 'private') -----
- ----- Method: CompositionScanner>>setStopConditions (in category 'stop conditions') -----
  setStopConditions
  	"Set the font and the stop conditions for the current run."
  	
  	self setFont.
  	stopConditions := wantsColumnBreaks == true
  		ifTrue: [ColumnBreakStopConditions]
  		ifFalse: [CompositionStopConditions]!

Item was changed:
  ----- Method: CompositionScanner>>space (in category 'stop conditions') -----
  space
  	"Record left x and character index of the space character just encountered. 
  	Used for wrap-around. Answer whether the character has crossed the 
  	right edge of the composition rectangle of the paragraph."
  
  	pendingKernX := 0.
  	spaceX := destX.
- 	destX := spaceX + spaceWidth.
  	spaceIndex := lastIndex.
  	lineHeightAtSpace := lineHeight.
  	baselineAtSpace := baseline.
- 	lastIndex := lastIndex + 1.
  	spaceCount := spaceCount + 1.
  	lastBreakIsNotASpace := false.
+ 	destX + spaceWidth > rightMargin ifTrue:[^self crossedX].
+ 	destX := spaceX + spaceWidth + kern.
+ 	lastIndex := lastIndex + 1.
- 	destX > rightMargin ifTrue: 	[^self crossedX].
  	^false
  !

Item was changed:
  CharacterScanner subclass: #DisplayScanner
+ 	instanceVariableNames: 'bitBlt lineY foregroundColor backgroundColor fillBlt lineHeight paragraphColor morphicOffset ignoreColorChanges'
- 	instanceVariableNames: 'bitBlt lineY runX foregroundColor backgroundColor fillBlt lineHeight paragraphColor morphicOffset ignoreColorChanges'
  	classVariableNames: ''
  	poolDictionaries: ''
  	category: 'Graphics-Text'!
  
  !DisplayScanner commentStamp: '<historical>' prior: 0!
  My instances are used to scan text and display it on the screen or in a hidden form.!

Item was changed:
  ----- Method: DisplayScanner>>displayLine:offset:leftInRun: (in category 'scanning') -----
  displayLine: textLine offset: offset leftInRun: leftInRun
  	"The call on the primitive (scanCharactersFrom:to:in:rightX:) will be interrupted according to an array of stop conditions passed to the scanner at which time the code to handle the stop condition is run and the call on the primitive continued until a stop condition returns true (which means the line has terminated).  leftInRun is the # of characters left to scan in the current run; when 0, it is time to call setStopConditions."
  	| stopCondition nowLeftInRun startIndex string lastPos |
  	line := textLine.
  	morphicOffset := offset.
  	lineY := line top + offset y.
  	lineHeight := line lineHeight.
  	rightMargin := line rightMargin + offset x.
  	lastIndex := line first.
  	leftInRun <= 0 ifTrue: [self setStopConditions].
  	leftMargin := (line leftMarginForAlignment: alignment) + offset x.
+ 	destX := leftMargin.
- 	destX := runX := leftMargin.
  	fillBlt == nil ifFalse:
  		["Not right"
  		fillBlt destX: line left destY: lineY
  			width: line width left height: lineHeight; copyBits].
  	lastIndex := line first.
  	leftInRun <= 0
  		ifTrue: [nowLeftInRun := text runLengthFor: lastIndex]
  		ifFalse: [nowLeftInRun := leftInRun].
  	destY := lineY + line baseline - font ascent.
  	runStopIndex := lastIndex + (nowLeftInRun - 1) min: line last.
  	spaceCount := 0.
  	string := text string.
  	[
  		"remember where this portion of the line starts"
  		startIndex := lastIndex.
  		lastPos := destX at destY.
  		
  		"find the end of this portion of the line"
  		stopCondition := self scanCharactersFrom: lastIndex to: runStopIndex
  						in: string rightX: rightMargin stopConditions: stopConditions
  						kern: kern.
  
  		"display that portion of the line"
  		lastIndex >= startIndex ifTrue:[
  			font displayString: string on: bitBlt 
  				from: startIndex 
  	"XXXX: The following is an interesting bug. All stopConditions exept #endOfRun
  		have lastIndex past the last character displayed. #endOfRun sets it *on* the character.
  		If we display up until lastIndex then we will also display invisible characters like
  		CR and tab. This problem should be fixed in the scanner (i.e., position lastIndex
  		consistently) but I don't want to deal with the fallout right now so we keep the
  		fix minimally invasive."
  				to: (stopCondition == #endOfRun ifTrue:[lastIndex] ifFalse:[lastIndex-1]) 
  				at: lastPos kern: kern].
  
  		"handle the stop condition"
  		"see setStopConditions for stopping conditions for displaying."
  		self perform: stopCondition
  	] whileFalse.
  	^ runStopIndex - lastIndex   "Number of characters remaining in the current run"!

Item was changed:
  ----- Method: DisplayScanner>>endOfRun (in category 'stop conditions') -----
  endOfRun
  	"The end of a run in the display case either means that there is actually 
  	a change in the style (run code) to be associated with the string or the 
  	end of this line has been reached."
  	| runLength |
  	lastIndex = line last ifTrue: [^true].
- 	runX := destX.
  	runLength := text runLengthFor: (lastIndex := lastIndex + 1).
  	runStopIndex := lastIndex + (runLength - 1) min: line last.
  	self setStopConditions.
  	^ false!

Item was changed:
  ----- Method: DisplayScanner>>paddedSpace (in category 'stop conditions') -----
  paddedSpace
  	"Each space is a stop condition when the alignment is right justified. 
  	Padding must be added to the base width of the space according to 
  	which space in the line this space is and according to the amount of 
  	space that remained at the end of the line when it was composed."
  
  	spaceCount := spaceCount + 1.
+ 	destX := destX + spaceWidth + kern + (line justifiedPadFor: spaceCount font: font).
- 	destX := destX + spaceWidth + (line justifiedPadFor: spaceCount font: font).
  	lastIndex := lastIndex + 1.
  	pendingKernX := 0.
  	^ false!

Item was changed:
  ----- Method: DisplayScanner>>placeEmbeddedObject: (in category 'private') -----
  placeEmbeddedObject: anchoredMorph
  	anchoredMorph relativeTextAnchorPosition ifNotNil:[
  		anchoredMorph position: 
  			anchoredMorph relativeTextAnchorPosition +
  			(anchoredMorph owner textBounds origin x @ 0)
  			- (0 at morphicOffset y) + (0 at lineY).
  		^true
  	].
+ 	anchoredMorph relativeTextAnchorPosition ifNotNil:[^true].
- 	(super placeEmbeddedObject: anchoredMorph) ifFalse: [^ false].
  	(anchoredMorph isMorph or: [anchoredMorph isPrimitiveCostume]) ifTrue: [
+ 		anchoredMorph position: (destX at lineY) - morphicOffset
- 		anchoredMorph position: ((destX - anchoredMorph width)@lineY) - morphicOffset
  	] ifFalse: [
  		destY := lineY.
- 		runX := destX.
  		anchoredMorph 
  			displayOn: bitBlt destForm 
+ 			at: destX @ destY
- 			at: destX - anchoredMorph width @ destY
  			clippingBox: bitBlt clipRect
  	].
+ 	destX := destX + anchoredMorph width + kern.
  	^ true!

Item was removed:
- ----- Method: DisplayScanner>>space (in category 'stop conditions') -----
- space
- 	"Don't display the space, just skip the spaceWidth."
- 
- 	spaceCount := spaceCount + 1.
- 	destX := destX + spaceWidth.
- 	lastIndex := lastIndex + 1.
- 	pendingKernX := 0.
- 	^ false!



More information about the Squeak-dev mailing list