Nicolas Cellier uploaded a new version of Graphics to project The Trunk:
http://source.squeak.org/trunk/Graphics-nice.258.mcz ==================== Summary ==================== Name: Graphics-nice.258 Author: nice Time: 9 October 2013, 2:09:04.395 am UUID: 6b4eb183-6c37-4b74-aaf7-025d1c6b4a6b Ancestors: Graphics-nice.257 Take back the scanCharactersFrom:to:with:rightX:font: methods from *Collections For some reasons (renaming a protocol) this message is also required in Symbol. Give back those exlcusive MultiByte and Japanese CharacterScanner methods to *Multilingual. Remove the now obsolete CharacterScanner methods which tried to pass stopConditions:kern: Remove theFirstCharCrossedX which must be handled differently and uniformely =============== Diff against Graphics-nice.257 =============== Item was added: + ----- Method: ByteString>>scanCharactersFrom:to:with:rightX:font: (in category '*Graphics-Text') ----- + scanCharactersFrom: startIndex to: stopIndex with: aCharacterScanner rightX: rightX font: aFont + "NB: strongly consider getting almost all these parameters from the scanner" + "Since I'm a byte char string, I know that we have to scan single-byte characters and don't have to handle encodings etc" + startIndex > stopIndex + ifTrue: [^aCharacterScanner handleEndOfRunAt: stopIndex]. + ^aFont scanByteCharactersFrom: startIndex to: stopIndex in: self with: aCharacterScanner rightX: rightX! Item was added: + ----- Method: ByteSymbol>>scanCharactersFrom:to:with:rightX:font: (in category '*Graphics-Text') ----- + scanCharactersFrom: startIndex to: stopIndex with: aCharacterScanner rightX: rightX font: aFont + "NB: strongly consider getting almost all these parameters from the scanner" + "Since I'm a byte char string, I know that we have to scan single-byte characters and don't have to handle encodings etc" + startIndex > stopIndex + ifTrue: [^aCharacterScanner handleEndOfRunAt: stopIndex]. + ^aFont scanByteCharactersFrom: startIndex to: stopIndex in: self with: aCharacterScanner rightX: rightX! Item was removed: - ----- Method: CharacterBlockScanner>>theFirstCharCrossedX (in category 'private') ----- - theFirstCharCrossedX - "Note: it is hard to explain why, but this is required to keep selection of leftmost char possible." - ^false! Item was removed: - ----- Method: CharacterScanner>>basicScanCharactersFrom:to:in:rightX:stopConditions:kern: (in category 'scanning') ----- - basicScanCharactersFrom: startIndex to: stopIndex in: sourceString rightX: rightX stopConditions: stops kern: kernDelta - "In ancient days this would have called primitive 103 to scan a string with StrikeFont, but time moves on. See historicalScanCharactersFrom:to:in:rightX:stopConditions:kern: if you're curious. This code handles the newer shape of CharacterScanner but does *no* pair kerning. - There is a pretty deep assumption of simple ASCII strings and characters - beware" - | 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" - (stops at: ascii) - ifNotNil: [^ stops 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: [^ stops crossedX]. - "update destX and incorporate thr kernDelta" - destX := nextDestX + kernDelta. - lastIndex := lastIndex + 1]. - lastIndex := stopIndex. - ^ stops endOfRun! Item was removed: - ----- Method: CharacterScanner>>basicScanKernableCharactersFrom:to:in:rightX:stopConditions:kern: (in category 'scanning') ----- - basicScanKernableCharactersFrom: startIndex to: stopIndex in: sourceString rightX: rightX stopConditions: stops kern: kernDelta - "In ancient days this would have called primitive 103 to scan a string with StrikeFont, but time moves on. See historicalScanCharactersFrom:to:in:rightX:stopConditions:kern: if you're curious. This code handles the newer shape of CharacterScanner and provides some support for fonts that have pair-kerning; this may be removable with some better factoring. - There is a pretty deep assumption of simple ASCII strings and characters - beware" - | 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" - (stops at: ascii) - ifNotNil: [^ stops 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: [^ stops crossedX]. - "bump floatDestX by the *kerned* width of the current - character, which is where the *next* char will go" - floatDestX := floatDestX + kernDelta - + (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]. - lastIndex := stopIndex. - ^ stops endOfRun! Item was removed: - ----- Method: CharacterScanner>>isBreakableAt:in:in: (in category 'multilingual scanning') ----- - isBreakableAt: index in: sourceString in: encodingClass - "check with the encoding whether the character at index is a breakable character. - Only the JISX0208 & JapaneseEnvironments ever return true, so only the scanJapaneseCharacters... method calls this" - ^ encodingClass isBreakableAt: index in: sourceString. - ! Item was removed: - ----- Method: CharacterScanner>>registerBreakableIndex (in category 'multilingual scanning') ----- - registerBreakableIndex - - "Record left x and character index of the line-wrappable point. - The default implementation here does nothing." - - ^ false. - ! Item was changed: + ----- Method: CharacterScanner>>scanByteCharactersFrom:to:in:rightX: (in category 'scanning') ----- - ----- Method: CharacterScanner>>scanByteCharactersFrom:to:in:rightX: (in category 'multilingual 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: [^ stopConditions crossedX]. "update destX and incorporate thr kernDelta" destX := nextDestX + kern. lastIndex := lastIndex + 1]. ^self handleEndOfRunAt: stopIndex ! Item was removed: - ----- Method: CharacterScanner>>scanJapaneseCharactersFrom:to:in:rightX: (in category 'multilingual scanning') ----- - scanJapaneseCharactersFrom: startIndex to: stopIndex in: sourceString rightX: rightX - "this is a scanning method for - multibyte Japanese characters in a WideString - hence the isBreakable:in:in: - a font that does not do character-pair kerning " - - | ascii encoding nextDestX startEncoding char | - lastIndex := startIndex. - lastIndex > stopIndex ifTrue: [^self handleEndOfRunAt: stopIndex]. - startEncoding := (sourceString at: startIndex) leadingChar. - [lastIndex <= stopIndex] whileTrue: [ - char := sourceString at: lastIndex. - encoding := char leadingChar. - encoding ~= startEncoding ifTrue: [lastIndex := lastIndex - 1. ^ stopConditions endOfRun]. - ascii := char charCode. - (encoding = 0 and: [ascii < 256 and:[(stopConditions at: ascii + 1) notNil]]) - ifTrue: [^ stopConditions at: ascii + 1]. - (self isBreakableAt: lastIndex in: sourceString in: (EncodedCharSet charsetAt: encoding)) ifTrue: [ - self registerBreakableIndex. - ]. - nextDestX := destX + (font widthOf: char). - nextDestX > rightX ifTrue: [self theFirstCharCrossedX ifFalse: [^ stopConditions crossedX]]. - destX := nextDestX + kern. - lastIndex := lastIndex + 1. - ]. - ^self handleEndOfRunAt: stopIndex! Item was removed: - ----- Method: CharacterScanner>>scanJapaneseCharactersFrom:to:in:rightX:stopConditions:kern: (in category 'multilingual scanning') ----- - scanJapaneseCharactersFrom: startIndex to: stopIndex in: sourceString rightX: rightX stopConditions: stops kern: kernDelta - - | ascii encoding nextDestX startEncoding | - lastIndex := startIndex. - lastIndex > stopIndex ifTrue: [lastIndex := stopIndex. ^ stops endOfRun]. - startEncoding := (sourceString at: startIndex) leadingChar. - [lastIndex <= stopIndex] whileTrue: [ - encoding := (sourceString at: lastIndex) leadingChar. - encoding ~= startEncoding ifTrue: [lastIndex := lastIndex - 1. ^ stops endOfRun]. - ascii := (sourceString at: lastIndex) charCode. - (encoding = 0 and: [ascii < 256 and:[(stops at: ascii + 1) notNil]]) - ifTrue: [^ stops at: ascii + 1]. - (self isBreakableAt: lastIndex in: sourceString in: (EncodedCharSet charsetAt: encoding)) ifTrue: [ - self registerBreakableIndex. - ]. - nextDestX := destX + (font widthOf: (sourceString at: lastIndex)). - nextDestX > rightX ifTrue: [self theFirstCharCrossedX ifFalse: [^ stops crossedX]]. - destX := nextDestX + kernDelta. - lastIndex := lastIndex + 1. - ]. - lastIndex := stopIndex. - ^ stops endOfRun! Item was changed: + ----- Method: CharacterScanner>>scanKernableByteCharactersFrom:to:in:rightX: (in category 'scanning') ----- - ----- Method: CharacterScanner>>scanKernableByteCharactersFrom:to:in:rightX: (in category 'multilingual 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: [^ 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 ! Item was removed: - ----- Method: CharacterScanner>>scanKernableMultibyteCharactersFrom:to:in:rightX: (in category 'multilingual scanning') ----- - scanKernableMultibyteCharactersFrom: startIndex to: stopIndex in: sourceString rightX: rightX - "this is a scanning method for - multibyte characters in a WideString - a font that does do character-pair kerning via widthAndKernedWidthOfLeft:right:into:" - - | ascii encoding nextDestX startEncoding floatDestX widthAndKernedWidth nextChar atEndOfRun char | - lastIndex := startIndex. - lastIndex > stopIndex ifTrue: [^self handleEndOfRunAt: stopIndex]. - startEncoding := (sourceString at: startIndex) leadingChar. - floatDestX := destX. - widthAndKernedWidth := Array new: 2. - atEndOfRun := false. - [lastIndex <= stopIndex] whileTrue: [ - char := sourceString at: lastIndex. - encoding := char leadingChar. - encoding ~= startEncoding ifTrue: [lastIndex := lastIndex - 1. ^ stopConditions endOfRun]. - ascii := char charCode. - (ascii < 256 and: [(stopConditions at: ascii + 1) ~~ nil]) ifTrue: [^ stopConditions at: ascii + 1]. - nextChar := (lastIndex + 1 <= stopIndex) - ifTrue:[sourceString at: lastIndex + 1] - ifFalse:[ - atEndOfRun := true. - "if there is a next char in sourceString, then get the kern - and store it in pendingKernX" - lastIndex + 1 <= sourceString size - ifTrue:[sourceString at: lastIndex + 1] - ifFalse:[ nil]]. - font - widthAndKernedWidthOfLeft: char - right: nextChar - into: widthAndKernedWidth. - nextDestX := floatDestX + (widthAndKernedWidth at: 1). - nextDestX > rightX ifTrue: [self theFirstCharCrossedX ifFalse: [^stopConditions crossedX]]. - floatDestX := floatDestX + kern + (widthAndKernedWidth at: 2). - atEndOfRun - ifTrue:[ - pendingKernX := (widthAndKernedWidth at: 2) - (widthAndKernedWidth at: 1). - floatDestX := floatDestX - pendingKernX]. - destX := floatDestX . - lastIndex := lastIndex + 1. - ]. - ^self handleEndOfRunAt: stopIndex! Item was removed: - ----- Method: CharacterScanner>>scanMultiCharactersFrom:to:in:rightX:stopConditions:kern: (in category 'multilingual scanning') ----- - scanMultiCharactersFrom: startIndex to: stopIndex in: sourceString rightX: rightX stopConditions: stops kern: kernDelta - - | ascii encoding nextDestX startEncoding floatDestX widthAndKernedWidth nextChar atEndOfRun | - lastIndex := startIndex. - lastIndex > stopIndex ifTrue: [lastIndex := stopIndex. ^ stops endOfRun]. - startEncoding := (sourceString at: startIndex) leadingChar. - floatDestX := destX. - widthAndKernedWidth := Array new: 2. - atEndOfRun := false. - [lastIndex <= stopIndex] whileTrue: [ - encoding := (sourceString at: lastIndex) leadingChar. - encoding ~= startEncoding ifTrue: [lastIndex := lastIndex - 1. ^ stops endOfRun]. - ascii := (sourceString at: lastIndex) charCode. - (ascii < 256 and: [(stops at: ascii + 1) ~~ nil]) ifTrue: [^ stops at: ascii + 1]. - nextChar := (lastIndex + 1 <= stopIndex) - ifTrue:[sourceString at: lastIndex + 1] - ifFalse:[ - atEndOfRun := true. - "if there is a next char in sourceString, then get the kern - and store it in pendingKernX" - lastIndex + 1 <= sourceString size - ifTrue:[sourceString at: lastIndex + 1] - ifFalse:[ nil]]. - font - widthAndKernedWidthOfLeft: (sourceString at: lastIndex) - right: nextChar - into: widthAndKernedWidth. - nextDestX := floatDestX + (widthAndKernedWidth at: 1). - nextDestX > rightX ifTrue: [self theFirstCharCrossedX ifFalse: [^stops crossedX]]. - floatDestX := floatDestX + kernDelta + (widthAndKernedWidth at: 2). - atEndOfRun - ifTrue:[ - pendingKernX := (widthAndKernedWidth at: 2) - (widthAndKernedWidth at: 1). - floatDestX := floatDestX - pendingKernX]. - destX := floatDestX . - lastIndex := lastIndex + 1. - ]. - lastIndex := stopIndex. - ^ stops endOfRun! Item was removed: - ----- Method: CharacterScanner>>scanMultibyteCharactersFrom:to:in:rightX: (in category 'multilingual scanning') ----- - scanMultibyteCharactersFrom: startIndex to: stopIndex in: sourceString rightX: rightX - "this is a scanning method for - multibyte characters in a WideString - a font that does not do character-pair kerning" - | char ascii encoding nextDestX startEncoding | - lastIndex := startIndex. - startEncoding := (sourceString at: startIndex) leadingChar. - [lastIndex <= stopIndex] whileTrue: [ - char := sourceString at: lastIndex. - encoding := char leadingChar. - encoding ~= startEncoding ifTrue: [lastIndex := lastIndex - 1. ^ stopConditions endOfRun]. - ascii := char charCode. - (ascii < 256 and: [(stopConditions at: ascii + 1) ~~ nil]) ifTrue: [^ stopConditions at: ascii + 1]. - "bump nextDestX by the width of the current character" - nextDestX := destX + (font widthOf: char). - nextDestX > rightX ifTrue: [self theFirstCharCrossedX ifFalse: [^stopConditions crossedX]]. - destX := nextDestX + kern . - lastIndex := lastIndex + 1. - ]. - ^self handleEndOfRunAt: stopIndex! Item was removed: - ----- Method: CharacterScanner>>theFirstCharCrossedX (in category 'private') ----- - theFirstCharCrossedX - "Tell whether the left most char crossed the right margin boundary" - ^destX = leftMargin! Item was removed: - ----- Method: CompositionScanner>>registerBreakableIndex (in category 'multilingual scanning') ----- - registerBreakableIndex - "Record left x and character index of the line-wrappable point. - Used for wrap-around in eastern Asian languages." - - spaceX := destX. - lineHeightAtSpace := lineHeight. - baselineAtSpace := baseline. - spaceIndex := lastIndex. - lastBreakIsNotASpace := true.! Item was removed: - ----- Method: DisplayScanner>>isBreakableAt:in:in: (in category 'multilingual scanning') ----- - isBreakableAt: index in: sourceString in: encodingClass - - ^ false. - ! Item was added: + ----- Method: WideString>>scanCharactersFrom:to:with:rightX:font: (in category '*Graphics-Text') ----- + scanCharactersFrom: startIndex to: stopIndex with: aCharacterScanner rightX: rightX font: aFont + "NB: strongly consider getting almost all these parameters from the scanner" + "Since I'm a wide char string, I know that we have to scan multi-byte characters and handle encodings etc" + | charSet | + startIndex > stopIndex + ifTrue: [^aCharacterScanner handleEndOfRunAt: stopIndex]. + charSet := self encodedCharSetAt: startIndex. + ^charSet scanMultibyteCharactersFrom: startIndex to: stopIndex in: self with: aCharacterScanner rightX: rightX font: aFont ! Item was added: + ----- Method: WideSymbol>>scanCharactersFrom:to:with:rightX:font: (in category '*Graphics-Text') ----- + scanCharactersFrom: startIndex to: stopIndex with: aCharacterScanner rightX: rightX font: aFont + "NB: strongly consider getting almost all these parameters from the scanner" + "Since I'm a wide char string, I know that we have to scan multi-byte characters and handle encodings etc" + | charSet | + startIndex > stopIndex + ifTrue: [^aCharacterScanner handleEndOfRunAt: stopIndex]. + charSet := self encodedCharSetAt: startIndex. + ^charSet scanMultibyteCharactersFrom: startIndex to: stopIndex in: self with: aCharacterScanner rightX: rightX font: aFont ! |
Free forum by Nabble | Edit this page |