[squeak-dev] The Trunk: TrueType-mt.90.mcz

commits at source.squeak.org commits at source.squeak.org
Wed Mar 16 14:07:35 UTC 2022


Marcel Taeumel uploaded a new version of TrueType to project The Trunk:
http://source.squeak.org/trunk/TrueType-mt.90.mcz

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

Name: TrueType-mt.90
Author: mt
Time: 16 March 2022, 3:07:34.672608 pm
UUID: ca5aebaf-2eb7-124d-ad9b-a83c58d9718c
Ancestors: TrueType-mt.89

Speed up text composition and display for TrueType fonts. Extra speed-up for single-byte strings.

Using "Text melvilleSample," composition time changed from roughly 1000 microseconds to 90 microseconds. Display speed is roughly the same but less pressure on the GC. Might be more noticeable on slower machines.

The three optimization strategies are:
1. Avoid expensive fail of primitive 103 in CharacterScanner.
2. Avoid extra #hasGlyphOf: checks when possible.
3. Do not support #fallbackFont in single-byte strings, i.e., latin-1 (or ascii).

=============== Diff against TrueType-mt.89 ===============

Item was changed:
  ----- Method: TTCFont>>basicHasGlyphOf: (in category 'private') -----
  basicHasGlyphOf: aCharacter
  	"Answer whether this font includes a glyph for the given character"
  
+ 	"^ self hasGlyphForCode: (self codeForCharacter: aCharacter)"
+ 	^ self hasGlyphForCode: aCharacter charCode!
- 	^ self hasGlyphForCode: (self codeForCharacter: aCharacter)!

Item was changed:
  ----- Method: TTCFont>>characterFormAt: (in category 'character shapes') -----
+ characterFormAt: aCharacter 
- characterFormAt: character 
- 	"Answer a Form copied out of the glyphs for the argument,  
- 	character. Use a cached copy if possible."
  
+ 	cache ifNil: [self foregroundColor: Color black]. "make sure we have a cache"
+ 	"^ self characterFormAtCode: (self codeForCharacter: aCharacter)"
+ 	^ self characterFormAtCode: aCharacter charCode!
- 	^self formOf: character!

Item was added:
+ ----- Method: TTCFont>>characterFormAtCode: (in category 'character shapes') -----
+ characterFormAtCode: characterCode 
+ 	"Answer a Form copied out of the glyphs for the argument,  
+ 	character. Use a cached copy if possible."
+ 
+ 	| form |
+ 	cache ifNil: [self foregroundColor: Color black]. "make sure we have a cache"
+ 
+ 	form := cache at: (characterCode + 1).
+ 
+ 	form ifNil: [
+ 		form := self computeForm: characterCode.
+ 		form ifNil:[^nil].
+ 		cache at: characterCode+1 put: form.
+ 		GlyphCacheData at: (GlyphCacheIndex := GlyphCacheIndex \\ GlyphCacheSize + 1) put: form.
+ 	].
+ 	^form
+ !

Item was added:
+ ----- Method: TTCFont>>displayByteString:on:from:to:at:kern:baselineY: (in category 'displaying') -----
+ displayByteString: aByteString on: aBitBlt from: startIndex to: stopIndex at: aPoint kern: kernDelta baselineY: baselineY
+ 	"Optimized path for rendering single-byte strings (i.e. ascii or latin-1) without support for fallback fonts. Which means that if you try to render a single-byte string with a font that does not support latin-1, you will get an unpleasant surprise. See #widthOfByteCharacter:."
+ 
+ 	| form code destX destY offsetX |
+ 	destX := aPoint x.
+ 	destY := baselineY - self ascent. 
+ 	aBitBlt sourceX: 0; sourceY: 0.
+ 	startIndex to: stopIndex do: [:charIndex |
+ 		code := (aByteString at: charIndex) asInteger. "Must be <= 16rFF !!!!"
+ 		form := self characterFormAtCode: code.
+ 		offsetX := form advanceWidth.
+ 		aBitBlt sourceForm: form.
+ 		aBitBlt destX: destX + form offset x.
+ 		aBitBlt destY: destY + form offset y.
+ 		aBitBlt width: form width.
+ 		aBitBlt height: form height.
+ 		aBitBlt copyBits.
+ 		destX := destX + offsetX + kernDelta].
+ 	^ destX @ destY
+ !

Item was added:
+ ----- Method: TTCFont>>displayMultiString:on:from:to:at:kern:baselineY: (in category 'displaying') -----
+ displayMultiString: aString on: aBitBlt from: startIndex to: stopIndex at: aPoint kern: kernDelta baselineY: baselineY
+ 
+ 	| form glyphInfo destX destY hereX nextX actualFont |
+ 	destX := aPoint x.
+ 	glyphInfo := Array new: 5. "Cached across fallback lookup."
+ 	startIndex to: stopIndex do: [:charIndex |
+ 		self flag: #fallbackFont.
+ 		self glyphInfoOf: (aString at: charIndex) into: glyphInfo.
+ 		form := glyphInfo at: 1.
+ 		hereX := glyphInfo at: 2.
+ 		nextX := glyphInfo at: 3.
+ 		self flag: #fallbackFont.
+ 		(actualFont := glyphInfo at: 5) ==  aBitBlt lastFont
+ 			ifFalse: [actualFont installOn: aBitBlt].
+ 		destY := baselineY - (glyphInfo at: 4). 
+ 		aBitBlt sourceForm: form.
+ 		aBitBlt destX: destX + form offset x.
+ 		aBitBlt destY: destY + form offset y.
+ 		aBitBlt sourceX: hereX; sourceY: 0.
+ 		aBitBlt width: form width.
+ 		aBitBlt height: form height.
+ 		aBitBlt copyBits.
+ 		destX := destX + (nextX - hereX) + kernDelta.
+ 	].
+ 	^ destX @ destY
+ !

Item was added:
+ ----- Method: TTCFont>>scanByteCharactersFrom:to:in:with:rightX: (in category 'character scanning') -----
+ scanByteCharactersFrom: startIndex to: stopIndex in: aByteString
+ with: aCharacterScanner rightX: rightX
+ 	"Overwritten to avoid primitive 103 for faster text composition bc. primitive-fail is too slow."
+ 	
+ 	^ aCharacterScanner
+ 		basicScanByteCharactersFrom: startIndex to: stopIndex
+ 		in: aByteString rightX: rightX!

Item was added:
+ ----- Method: TTCFont>>widthOfByteCharacter: (in category 'measuring') -----
+ widthOfByteCharacter: aCharacter
+ 	"Optimized path for composing single-byte strings (i.e. ascii or latin-1) without support for fallback fonts. Which means that if you try to compose a single-byte string with a font that does not support latin-1, you will get an unpleasant surprise. See #displayByteString:on:from:to:at:kern:baselineY:."
+ 
+ 	^(self characterFormAtCode: aCharacter asInteger "<= 16rFF !!") advanceWidth!



More information about the Squeak-dev mailing list