Nicolas Cellier uploaded a new version of Graphics to project The Trunk:
http://source.squeak.org/trunk/Graphics-nice.239.mcz ==================== Summary ==================== Name: Graphics-nice.239 Author: nice Time: 29 September 2013, 10:14:06.441 pm UUID: 2357b4a4-41d5-4083-8d0d-89b83f87ceb4 Ancestors: Graphics-nice.238 Remove some dust from CharacterBlockScanner surface (just sanitize before we operate deeper) - don't copy lastSpaceOrTabExtent or lastCharacterExtent Points, we do not mutate them (since 2000) but create anew (see lastSpaceOrTabExtentSetX: and lastCharacterExtentSetX:) - don't (ab)use == to compare numbers (even integer indices) =============== Diff against Graphics-nice.238 =============== Item was changed: ----- Method: CharacterBlockScanner>>characterBlockAtPoint:index:in: (in category 'scanning') ----- characterBlockAtPoint: aPoint index: index in: textLine "This method is the Morphic characterBlock finder. It combines MVC's characterBlockAtPoint:, -ForIndex:, and buildCharacterBlockIn:" | runLength lineStop stopCondition | line := textLine. rightMargin := line rightMargin. lastIndex := line first. self setStopConditions. "also sets font" characterIndex := index. " == nil means scanning for point" characterPoint := aPoint. (characterPoint isNil or: [characterPoint y > line bottom]) ifTrue: [characterPoint := line bottomRight]. destX := leftMargin := line leftMarginForAlignment: alignment. destY := line top. (text isEmpty or: [(characterPoint y < destY or: [characterPoint x < destX]) or: [characterIndex notNil and: [characterIndex < line first]]]) ifTrue: [^ (CharacterBlock new stringIndex: line first text: text topLeft: destX@destY extent: 0 @ textStyle lineGrid) textLine: line]. runLength := text runLengthFor: line first. lineStop := characterIndex "scanning for index" ifNil: [ line last ]. "scanning for point" runStopIndex := lastIndex + (runLength - 1) min: lineStop. lastCharacterExtent := 0 @ line lineHeight. spaceCount := 0. [ stopCondition := self scanCharactersFrom: lastIndex to: runStopIndex in: text string rightX: characterPoint x stopConditions: stopConditions kern: kern. "see setStopConditions for stopping conditions for character block operations." + self lastCharacterExtentSetX: (specialWidth ifNil: [font widthOf: (text at: lastIndex)]). - self lastCharacterExtentSetX: (specialWidth - ifNil: [font widthOf: (text at: lastIndex)] - ifNotNil: [specialWidth]). self perform: stopCondition ] whileFalse. characterIndex ifNil: [ "Result for characterBlockAtPoint: " + (stopCondition ~~ #cr and: [ lastIndex = line last - (stopCondition ~~ #cr and: [ lastIndex == line last and: [ aPoint x > ((characterPoint x) + (lastCharacterExtent x / 2)) ]]) ifTrue: [ "Correct for right half of last character in line" ^ (CharacterBlock new stringIndex: lastIndex + 1 text: text topLeft: characterPoint + (lastCharacterExtent x @ 0) + (font descentKern @ 0) extent: 0 @ lastCharacterExtent y) textLine: line ]. ^ (CharacterBlock new stringIndex: lastIndex text: text topLeft: characterPoint + (font descentKern @ 0) extent: lastCharacterExtent - (font baseKern @ 0)) textLine: line] ifNotNil: ["Result for characterBlockForIndex: " ^ (CharacterBlock new stringIndex: characterIndex text: text topLeft: characterPoint + ((font descentKern) - kern @ 0) extent: lastCharacterExtent) textLine: line]! 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 | pad := 0. spaceCount := spaceCount + 1. pad := line justifiedPadFor: spaceCount font: font. + lastSpaceOrTabExtent := lastCharacterExtent. - lastSpaceOrTabExtent := lastCharacterExtent copy. self lastSpaceOrTabExtentSetX: spaceWidth + pad. (destX + lastSpaceOrTabExtent x) >= characterPoint x + ifTrue: [lastCharacterExtent := lastSpaceOrTabExtent. - ifTrue: [lastCharacterExtent := lastSpaceOrTabExtent copy. ^self crossedX]. lastIndex := lastIndex + 1. destX := destX + lastSpaceOrTabExtent x. ^ false ! Item was changed: ----- Method: CharacterBlockScanner>>space (in category 'stop conditions') ----- space "Account for spaceWidth" spaceCount := spaceCount + 1. + lastSpaceOrTabExtent := lastCharacterExtent. - lastSpaceOrTabExtent := lastCharacterExtent copy. self lastSpaceOrTabExtentSetX: spaceWidth. + (destX + spaceWidth) >= characterPoint x + ifTrue: [lastCharacterExtent := lastSpaceOrTabExtent. - (destX + lastSpaceOrTabExtent x) >= characterPoint x - ifTrue: [lastCharacterExtent := lastSpaceOrTabExtent copy. ^self crossedX]. lastIndex := lastIndex + 1. + destX := destX + spaceWidth. - destX := destX + lastSpaceOrTabExtent x. ^ false ! Item was changed: ----- Method: CharacterBlockScanner>>tab (in category 'stop conditions') ----- tab | currentX | currentX := (alignment = Justified and: [self leadingTab not]) ifTrue: "imbedded tabs in justified text are weird" [destX + (textStyle tabWidth - (line justifiedTabDeltaFor: spaceCount)) max: destX] ifFalse: [textStyle nextTabXFrom: destX leftMargin: leftMargin rightMargin: rightMargin]. + lastSpaceOrTabExtent := lastCharacterExtent. - lastSpaceOrTabExtent := lastCharacterExtent copy. self lastSpaceOrTabExtentSetX: (currentX - destX max: 0). currentX >= characterPoint x ifTrue: + [lastCharacterExtent := lastSpaceOrTabExtent. - [lastCharacterExtent := lastSpaceOrTabExtent copy. ^ self crossedX]. destX := currentX. lastIndex := lastIndex + 1. ^false! |
Free forum by Nabble | Edit this page |