Nicolas Cellier uploaded a new version of Graphics to project The Trunk:
http://source.squeak.org/trunk/Graphics-nice.240.mcz
==================== Summary ====================
Name: Graphics-nice.240
Author: nice
Time: 29 September 2013, 11:37:28.204 pm
UUID: 8723c89d-2584-4aa3-bfb2-a863df2ee81d
Ancestors: Graphics-nice.239
Remove the inst. var. lastCharacter of CharacterBlockScanner, because it is not a state.
=============== Diff against Graphics-nice.239 ===============
Item was changed:
CharacterScanner subclass: #CharacterBlockScanner
+ instanceVariableNames: 'characterPoint characterIndex lastCharacterExtent lastSpaceOrTabExtent nextLeftMargin specialWidth'
- instanceVariableNames: 'characterPoint characterIndex lastCharacter lastCharacterExtent lastSpaceOrTabExtent nextLeftMargin specialWidth'
classVariableNames: ''
poolDictionaries: ''
category: 'Graphics-Text'!
!CharacterBlockScanner commentStamp: '<historical>' prior: 0!
My instances are used to scan text to compute the CharacterBlock for a character specified by its index in the text or its proximity to the cursor location.!
Item was changed:
----- Method: CharacterBlockScanner>>cr (in category 'stop conditions') -----
cr
"Answer a CharacterBlock that specifies the current location of the mouse
relative to a carriage return stop condition that has just been
encountered. The ParagraphEditor convention is to denote selections by
CharacterBlocks, sometimes including the carriage return (cursor is at
the end) and sometimes not (cursor is in the middle of the text)."
((characterIndex ~= nil
and: [characterIndex > text size])
or: [(line last = text size)
and: [(destY + line lineHeight) < characterPoint y]])
ifTrue: ["When off end of string, give data for next character"
destY := destY + line lineHeight.
- lastCharacter := nil.
characterPoint := (nextLeftMargin ifNil: [leftMargin]) @ destY.
(lastIndex < text size and: [(text at: lastIndex) = CR and: [(text at: lastIndex+1) = Character lf]])
ifTrue: [lastIndex := lastIndex + 2]
ifFalse: [lastIndex := lastIndex + 1].
self lastCharacterExtentSetX: 0.
^ true].
- lastCharacter := CR.
characterPoint := destX @ destY.
self lastCharacterExtentSetX: rightMargin - destX.
^true!
Item was changed:
----- Method: CharacterBlockScanner>>crossedX (in category 'stop conditions') -----
crossedX
"Text display has wrapping. The scanner just found a character past the x
location of the cursor. We know that the cursor is pointing at a character
or before one."
+ | currentX lastCharacter |
- | currentX |
characterIndex == nil ifFalse: [
"If the last character of the last line is a space,
and it crosses the right margin, then locating
the character block after it is impossible without this hack."
characterIndex > text size ifTrue: [
lastIndex := characterIndex.
characterPoint := (nextLeftMargin ifNil: [leftMargin]) @ (destY + line lineHeight).
^true]].
characterPoint x <= (destX + (lastCharacterExtent x // 2))
+ ifTrue: [characterPoint := destX @ destY.
- ifTrue: [lastCharacter := (text at: lastIndex).
- characterPoint := destX @ destY.
^true].
lastIndex >= line last
+ ifTrue: [characterPoint := destX @ destY.
- ifTrue: [lastCharacter := (text at: line last).
- characterPoint := destX @ destY.
^true].
"Pointing past middle of a character, return the next character."
lastIndex := lastIndex + 1.
lastCharacter := text at: lastIndex.
currentX := destX + lastCharacterExtent x + kern.
self lastCharacterExtentSetX: (font widthOf: lastCharacter).
characterPoint := currentX @ destY.
lastCharacter = Space ifFalse: [^ true].
"Yukky if next character is space or tab."
alignment = Justified ifTrue:
[self lastCharacterExtentSetX:
(lastCharacterExtent x + (line justifiedPadFor: (spaceCount + 1) font: font))].
^ true!
Item was changed:
----- Method: CharacterBlockScanner>>endOfRun (in category 'stop conditions') -----
endOfRun
"Before arriving at the cursor location, the selection has encountered an
end of run. Answer false if the selection continues, true otherwise. Set
up indexes for building the appropriate CharacterBlock."
+ | runLength lineStop lastCharacter |
- | runLength lineStop |
(((characterIndex ~~ nil and:
[runStopIndex < characterIndex and: [runStopIndex < text size]])
or: [characterIndex == nil and: [lastIndex < line last]]) or: [
((lastIndex < line last)
and: [((text at: lastIndex) leadingChar ~= (text at: lastIndex+1) leadingChar)
and: [lastIndex ~= characterIndex]])])
ifTrue: ["We're really at the end of a real run."
runLength := (text runLengthFor: (lastIndex := lastIndex + 1)).
characterIndex ~~ nil
ifTrue: [lineStop := characterIndex "scanning for index"]
ifFalse: [lineStop := line last "scanning for point"].
(runStopIndex := lastIndex + (runLength - 1)) > lineStop
ifTrue: [runStopIndex := lineStop].
self setStopConditions.
^false].
lastCharacter := text at: lastIndex.
characterPoint := destX @ destY.
((lastCharacter = Space and: [alignment = Justified])
or: [lastCharacter = Tab and: [lastSpaceOrTabExtent notNil]])
ifTrue: [lastCharacterExtent := lastSpaceOrTabExtent].
characterIndex ~~ nil
ifTrue: ["If scanning for an index and we've stopped on that index,
then we back destX off by the width of the character stopped on
(it will be pointing at the right side of the character) and return"
runStopIndex = characterIndex
ifTrue: [self characterPointSetX: destX - lastCharacterExtent x.
^true].
"Otherwise the requested index was greater than the length of the
string. Return string size + 1 as index, indicate further that off the
string by setting character to nil and the extent to 0."
lastIndex := lastIndex + 1.
- lastCharacter := nil.
self lastCharacterExtentSetX: 0.
^true].
"Scanning for a point and either off the end of the line or off the end of the string."
runStopIndex = text size
ifTrue: ["off end of string"
lastIndex := lastIndex + 1.
- lastCharacter := nil.
self lastCharacterExtentSetX: 0.
^true].
"just off end of line without crossing x"
lastIndex := lastIndex + 1.
^true!
Nicolas Cellier uploaded a new version of Graphics to project The Trunk:
http://source.squeak.org/trunk/Graphics-nice.240.mcz
==================== Summary ====================
Name: Graphics-nice.240
Author: nice
Time: 29 September 2013, 11:37:28.204 pm
UUID: 8723c89d-2584-4aa3-bfb2-a863df2ee81d
Ancestors: Graphics-nice.239
Remove the inst. var. lastCharacter of CharacterBlockScanner, because it is not a state.
=============== Diff against Graphics-nice.239 ===============
Item was changed:
CharacterScanner subclass: #CharacterBlockScanner
+ instanceVariableNames: 'characterPoint characterIndex lastCharacterExtent lastSpaceOrTabExtent nextLeftMargin specialWidth'
- instanceVariableNames: 'characterPoint characterIndex lastCharacter lastCharacterExtent lastSpaceOrTabExtent nextLeftMargin specialWidth'
classVariableNames: ''
poolDictionaries: ''
category: 'Graphics-Text'!
!CharacterBlockScanner commentStamp: '<historical>' prior: 0!
My instances are used to scan text to compute the CharacterBlock for a character specified by its index in the text or its proximity to the cursor location.!
Item was changed:
----- Method: CharacterBlockScanner>>cr (in category 'stop conditions') -----
cr
"Answer a CharacterBlock that specifies the current location of the mouse
relative to a carriage return stop condition that has just been
encountered. The ParagraphEditor convention is to denote selections by
CharacterBlocks, sometimes including the carriage return (cursor is at
the end) and sometimes not (cursor is in the middle of the text)."
((characterIndex ~= nil
and: [characterIndex > text size])
or: [(line last = text size)
and: [(destY + line lineHeight) < characterPoint y]])
ifTrue: ["When off end of string, give data for next character"
destY := destY + line lineHeight.
- lastCharacter := nil.
characterPoint := (nextLeftMargin ifNil: [leftMargin]) @ destY.
(lastIndex < text size and: [(text at: lastIndex) = CR and: [(text at: lastIndex+1) = Character lf]])
ifTrue: [lastIndex := lastIndex + 2]
ifFalse: [lastIndex := lastIndex + 1].
self lastCharacterExtentSetX: 0.
^ true].
- lastCharacter := CR.
characterPoint := destX @ destY.
self lastCharacterExtentSetX: rightMargin - destX.
^true!
Item was changed:
----- Method: CharacterBlockScanner>>crossedX (in category 'stop conditions') -----
crossedX
"Text display has wrapping. The scanner just found a character past the x
location of the cursor. We know that the cursor is pointing at a character
or before one."
+ | currentX lastCharacter |
- | currentX |
characterIndex == nil ifFalse: [
"If the last character of the last line is a space,
and it crosses the right margin, then locating
the character block after it is impossible without this hack."
characterIndex > text size ifTrue: [
lastIndex := characterIndex.
characterPoint := (nextLeftMargin ifNil: [leftMargin]) @ (destY + line lineHeight).
^true]].
characterPoint x <= (destX + (lastCharacterExtent x // 2))
+ ifTrue: [characterPoint := destX @ destY.
- ifTrue: [lastCharacter := (text at: lastIndex).
- characterPoint := destX @ destY.
^true].
lastIndex >= line last
+ ifTrue: [characterPoint := destX @ destY.
- ifTrue: [lastCharacter := (text at: line last).
- characterPoint := destX @ destY.
^true].
"Pointing past middle of a character, return the next character."
lastIndex := lastIndex + 1.
lastCharacter := text at: lastIndex.
currentX := destX + lastCharacterExtent x + kern.
self lastCharacterExtentSetX: (font widthOf: lastCharacter).
characterPoint := currentX @ destY.
lastCharacter = Space ifFalse: [^ true].
"Yukky if next character is space or tab."
alignment = Justified ifTrue:
[self lastCharacterExtentSetX:
(lastCharacterExtent x + (line justifiedPadFor: (spaceCount + 1) font: font))].
^ true!
Item was changed:
----- Method: CharacterBlockScanner>>endOfRun (in category 'stop conditions') -----
endOfRun
"Before arriving at the cursor location, the selection has encountered an
end of run. Answer false if the selection continues, true otherwise. Set
up indexes for building the appropriate CharacterBlock."
+ | runLength lineStop lastCharacter |
- | runLength lineStop |
(((characterIndex ~~ nil and:
[runStopIndex < characterIndex and: [runStopIndex < text size]])
or: [characterIndex == nil and: [lastIndex < line last]]) or: [
((lastIndex < line last)
and: [((text at: lastIndex) leadingChar ~= (text at: lastIndex+1) leadingChar)
and: [lastIndex ~= characterIndex]])])
ifTrue: ["We're really at the end of a real run."
runLength := (text runLengthFor: (lastIndex := lastIndex + 1)).
characterIndex ~~ nil
ifTrue: [lineStop := characterIndex "scanning for index"]
ifFalse: [lineStop := line last "scanning for point"].
(runStopIndex := lastIndex + (runLength - 1)) > lineStop
ifTrue: [runStopIndex := lineStop].
self setStopConditions.
^false].
lastCharacter := text at: lastIndex.
characterPoint := destX @ destY.
((lastCharacter = Space and: [alignment = Justified])
or: [lastCharacter = Tab and: [lastSpaceOrTabExtent notNil]])
ifTrue: [lastCharacterExtent := lastSpaceOrTabExtent].
characterIndex ~~ nil
ifTrue: ["If scanning for an index and we've stopped on that index,
then we back destX off by the width of the character stopped on
(it will be pointing at the right side of the character) and return"
runStopIndex = characterIndex
ifTrue: [self characterPointSetX: destX - lastCharacterExtent x.
^true].
"Otherwise the requested index was greater than the length of the
string. Return string size + 1 as index, indicate further that off the
string by setting character to nil and the extent to 0."
lastIndex := lastIndex + 1.
- lastCharacter := nil.
self lastCharacterExtentSetX: 0.
^true].
"Scanning for a point and either off the end of the line or off the end of the string."
runStopIndex = text size
ifTrue: ["off end of string"
lastIndex := lastIndex + 1.
- lastCharacter := nil.
self lastCharacterExtentSetX: 0.
^true].
"just off end of line without crossing x"
lastIndex := lastIndex + 1.
^true!
Nicolas Cellier uploaded a new version of 45Deprecated to project The Trunk:
http://source.squeak.org/trunk/45Deprecated-nice.10.mcz
==================== Summary ====================
Name: 45Deprecated-nice.10
Author: nice
Time: 29 September 2013, 7:07:40.687 pm
UUID: c616ca66-997d-45f3-b5a8-df386dfcc3e8
Ancestors: 45Deprecated-nice.9
Deprecate initializeStringMeasurer which is no longer required.
=============== Diff against 45Deprecated-nice.9 ===============
Item was added:
+ ----- Method: CharacterScanner>>initializeStringMeasurer (in category '*45Deprecated') -----
+ initializeStringMeasurer
+ "This method was once required to measure String but is now obsolescent."
+
+ self deprecated: 'initializeStringMeasurer is no longer required'
+ !
Nicolas Cellier uploaded a new version of 45Deprecated to project The Trunk:
http://source.squeak.org/trunk/45Deprecated-nice.10.mcz
==================== Summary ====================
Name: 45Deprecated-nice.10
Author: nice
Time: 29 September 2013, 7:07:40.687 pm
UUID: c616ca66-997d-45f3-b5a8-df386dfcc3e8
Ancestors: 45Deprecated-nice.9
Deprecate initializeStringMeasurer which is no longer required.
=============== Diff against 45Deprecated-nice.9 ===============
Item was added:
+ ----- Method: CharacterScanner>>initializeStringMeasurer (in category '*45Deprecated') -----
+ initializeStringMeasurer
+ "This method was once required to measure String but is now obsolescent."
+
+ self deprecated: 'initializeStringMeasurer is no longer required'
+ !
Nicolas Cellier uploaded a new version of 45Deprecated to project The Trunk:
http://source.squeak.org/trunk/45Deprecated-nice.10.mcz
==================== Summary ====================
Name: 45Deprecated-nice.10
Author: nice
Time: 29 September 2013, 7:07:40.687 pm
UUID: c616ca66-997d-45f3-b5a8-df386dfcc3e8
Ancestors: 45Deprecated-nice.9
Deprecate initializeStringMeasurer which is no longer required.
=============== Diff against 45Deprecated-nice.9 ===============
Item was added:
+ ----- Method: CharacterScanner>>initializeStringMeasurer (in category '*45Deprecated') -----
+ initializeStringMeasurer
+ "This method was once required to measure String but is now obsolescent."
+
+ self deprecated: 'initializeStringMeasurer is no longer required'
+ !
Nicolas Cellier uploaded a new version of Graphics to project The Trunk:
http://source.squeak.org/trunk/Graphics-nice.238.mcz
==================== Summary ====================
Name: Graphics-nice.238
Author: nice
Time: 29 September 2013, 7:06:35.509 pm
UUID: f7a0533e-2b32-4908-8666-d26204334a6e
Ancestors: Graphics-nice.237
Take font baseKern into account when measuring a String (a small diff with defunct Multi*).
Create a specially crafted MeasuringStopConditions and use it when measuringString.
This way, initializeStringMeasurer is no longer required and deprecated.
=============== Diff against Graphics-nice.237 ===============
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 DefaultStopConditions MeasuringStopConditions PaddedSpaceCondition'
- classVariableNames: 'ColumnBreakStopConditions DefaultStopConditions PaddedSpaceCondition'
poolDictionaries: 'TextConstants'
category: 'Graphics-Text'!
!CharacterScanner commentStamp: '<historical>' prior: 0!
My instances hold the state associated with scanning text. My subclasses scan characters for specified purposes, such as computing a CharacterBlock or placing characters into Forms.!
Item was changed:
----- Method: CharacterScanner class>>initialize (in category 'class initialization') -----
initialize
"
CharacterScanner initialize
"
| a |
a := TextStopConditions new.
a at: 1 + 1 put: #embeddedObject.
a at: Space asciiValue + 1 put: #space.
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.
ColumnBreakStopConditions := a copy.
ColumnBreakStopConditions at: TextComposer characterForColumnBreak asciiValue + 1 put: #columnBreak.
PaddedSpaceCondition := a copy.
PaddedSpaceCondition at: Space asciiValue + 1 put: #paddedSpace.
+
+ MeasuringStopConditions := TextStopConditions new!
- !
Item was removed:
- ----- Method: CharacterScanner>>initializeStringMeasurer (in category 'initialize') -----
- initializeStringMeasurer
-
- stopConditions := TextStopConditions new
- !
Item was changed:
----- Method: CharacterScanner>>measureString:inFont:from:to: (in category 'scanning') -----
measureString: aString inFont: aFont from: startIndex to: stopIndex
+ "Measure aString width in given font aFont.
+ The string shall not include line breaking, tab or other control character."
- "WARNING: In order to use this method the receiver has to be set up using #initializeStringMeasurer"
destX := destY := lastIndex := 0.
pendingKernX := 0.
font := aFont.
kern := 0 - font baseKern.
spaceWidth := font widthOf: Space.
+ stopConditions := MeasuringStopConditions.
+ self scanCharactersFrom: startIndex to: stopIndex in: aString rightX: 999999 stopConditions: stopConditions kern: kern.
- self scanCharactersFrom: startIndex to: stopIndex in: aString rightX: 999999 stopConditions: stopConditions kern: 0.
^destX!
Nicolas Cellier uploaded a new version of Graphics to project The Trunk:
http://source.squeak.org/trunk/Graphics-nice.238.mcz
==================== Summary ====================
Name: Graphics-nice.238
Author: nice
Time: 29 September 2013, 7:06:35.509 pm
UUID: f7a0533e-2b32-4908-8666-d26204334a6e
Ancestors: Graphics-nice.237
Take font baseKern into account when measuring a String (a small diff with defunct Multi*).
Create a specially crafted MeasuringStopConditions and use it when measuringString.
This way, initializeStringMeasurer is no longer required and deprecated.
=============== Diff against Graphics-nice.237 ===============
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 DefaultStopConditions MeasuringStopConditions PaddedSpaceCondition'
- classVariableNames: 'ColumnBreakStopConditions DefaultStopConditions PaddedSpaceCondition'
poolDictionaries: 'TextConstants'
category: 'Graphics-Text'!
!CharacterScanner commentStamp: '<historical>' prior: 0!
My instances hold the state associated with scanning text. My subclasses scan characters for specified purposes, such as computing a CharacterBlock or placing characters into Forms.!
Item was changed:
----- Method: CharacterScanner class>>initialize (in category 'class initialization') -----
initialize
"
CharacterScanner initialize
"
| a |
a := TextStopConditions new.
a at: 1 + 1 put: #embeddedObject.
a at: Space asciiValue + 1 put: #space.
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.
ColumnBreakStopConditions := a copy.
ColumnBreakStopConditions at: TextComposer characterForColumnBreak asciiValue + 1 put: #columnBreak.
PaddedSpaceCondition := a copy.
PaddedSpaceCondition at: Space asciiValue + 1 put: #paddedSpace.
+
+ MeasuringStopConditions := TextStopConditions new!
- !
Item was removed:
- ----- Method: CharacterScanner>>initializeStringMeasurer (in category 'initialize') -----
- initializeStringMeasurer
-
- stopConditions := TextStopConditions new
- !
Item was changed:
----- Method: CharacterScanner>>measureString:inFont:from:to: (in category 'scanning') -----
measureString: aString inFont: aFont from: startIndex to: stopIndex
+ "Measure aString width in given font aFont.
+ The string shall not include line breaking, tab or other control character."
- "WARNING: In order to use this method the receiver has to be set up using #initializeStringMeasurer"
destX := destY := lastIndex := 0.
pendingKernX := 0.
font := aFont.
kern := 0 - font baseKern.
spaceWidth := font widthOf: Space.
+ stopConditions := MeasuringStopConditions.
+ self scanCharactersFrom: startIndex to: stopIndex in: aString rightX: 999999 stopConditions: stopConditions kern: kern.
- self scanCharactersFrom: startIndex to: stopIndex in: aString rightX: 999999 stopConditions: stopConditions kern: 0.
^destX!