The Trunk: Graphics-nice.240.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: Graphics-nice.240.mcz

commits-2
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!