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

commits at source.squeak.org commits at source.squeak.org
Fri Feb 25 09:37:21 UTC 2022


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

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

Name: TrueType-mt.73
Author: mt
Time: 25 February 2022, 10:37:20.57863 am
UUID: 9a7bc579-7e0f-8c48-8a25-10f8a5466379
Ancestors: TrueType-mt.72

Move extral scale/gap from TTFontDescription up to TTCFont -- Step 2 of 2

Activate the use of TTCFont's #extraGlyphScale and #extraLineGap.

(Note that this also fixes clipping artifacts of over-height and over-wide glyphs. That is, left/top/right/bottom bearings in a glyph are not respected.)

=============== Diff against TrueType-mt.72 ===============

Item was changed:
  TTCFont subclass: #LinedTTCFont
  	instanceVariableNames: 'emphasis lineGlyph contourWidth'
  	classVariableNames: ''
  	poolDictionaries: ''
  	category: 'TrueType-Fonts'!
+ 
+ !LinedTTCFont commentStamp: 'mt 2/24/2022 16:24' prior: 0!
+ I am a TrueType font that uses the glyph for $_ to appear with underlined emphasis. If that glyph's decent is too close the baseline, the underlined font might look awkward.!

Item was changed:
  ----- Method: LinedTTCFont>>computeForm: (in category 'private') -----
  computeForm: char
  	"Overwritten to add line glyph."
  	
+ 	^ ttcDescription renderGlyph: char height: self height extraScale: self extraGlyphScale fgColor: foregroundColor bgColor: Color transparent depth: self depth lineGlyph: lineGlyph lineGlyphWidth: contourWidth emphasis: emphasis!
- 	^ ttcDescription renderGlyph: char height: self height fgColor: foregroundColor bgColor: Color transparent depth: self depth lineGlyph: lineGlyph lineGlyphWidth: contourWidth emphasis: emphasis!

Item was changed:
  ----- Method: TTCFont>>computeForm: (in category 'character shapes') -----
+ computeForm: aCharacter
- computeForm: char
  	"Compute the glyph form for the given character"
+ 
+ 	^ ttcDescription
+ 		renderGlyph: aCharacter
+ 		height: self height "in pixels"
+ 		extraScale: self extraGlyphScale
+ 		fgColor: foregroundColor
+ 		bgColor: Color transparent
+ 		depth: self depth!
- 	^ttcDescription renderGlyph: char height: self height fgColor: foregroundColor bgColor: Color transparent depth: self depth!

Item was changed:
  ----- Method: TTCFont>>displayString:on:from:to:at:kern:baselineY: (in category 'displaying') -----
  displayString: 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.
  	startIndex to: stopIndex do: [:charIndex |
  		self glyphInfoOf: (aString at: charIndex) into: glyphInfo.
  		form := glyphInfo at: 1.
  		hereX := glyphInfo at: 2.
  		nextX := glyphInfo at: 3.
  		(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 destX: destX.
  		aBitBlt destY: destY + form offset y. "Compensate overdraw. See #extraScale:."
  		aBitBlt sourceX: hereX; sourceY: 0.
+ 		aBitBlt width: form width.
- 		aBitBlt width: nextX - hereX.
  		aBitBlt height: form height.
  		aBitBlt copyBits.
  		destX := destX + (nextX - hereX) + kernDelta.
  	].
  	^ destX @ destY
  !

Item was changed:
  ----- Method: TTCFont>>glyphInfoOf:into: (in category 'displaying') -----
  glyphInfoOf: aCharacter into: glyphInfoArray
  	"return the glyph info for aCharacter; if I don't have such a character, try my fallback font"
  
  	| form |
  	(self hasGlyphOf: aCharacter) ifFalse: [
  		^ self fallbackFont glyphInfoOf: aCharacter into: glyphInfoArray.
  	].
  	form := self formOf: aCharacter.
  	glyphInfoArray at: 1 put: form;
+ 		at: 2 put: 0; "hereX -- relative, unlike StrikeFont"
+ 		at: 3 put: form advanceWidth; "nextX -- relative, unlike StrikeFont"
- 		at: 2 put: 0;
- 		at: 3 put: form width;
  		at: 4 put: self ascent "(self ascentOf: aCharacter)";
  		at: 5 put: self.
  	^ glyphInfoArray.
  !

Item was changed:
  ----- Method: TTCFont>>lineGap (in category 'accessing') -----
  lineGap
+ 	"Answer the line gap in pixels. Scale from #typographicLineGap to make larger texts more ledigble."
- 	"Answer the line gap from the ttf description. Use #typographicLineGap to make larger tests more ledigble."
  
+ 	^ lineGap ifNil: [lineGap := (self pixelTypoScale * (ttcDescription typographicLineGap + self extraLineGap)) rounded]
+ 	
+ "Do not use the non-typo values:
+ ^ (self pixelScale * (ttcDescription lineGap + ttcDescription extraGap) rounded
+ "!
- 	"^ (self pixelScale * (ttcDescription lineGap + ttcDescription extraGap) rounded"
- 	^ lineGap ifNil: [lineGap := (self pixelTypoScale * (ttcDescription typographicLineGap + ttcDescription extraGap)) rounded]!

Item was changed:
+ ----- Method: TTCFont>>widthOf: (in category 'measuring') -----
- ----- Method: TTCFont>>widthOf: (in category 'public') -----
  widthOf: aCharacter
+ 	"Overwritten to use the #advanceWidth and not the #width of the form. See TTGlyphForm"
+ 
- 	"This method cannot use #formOf: because formOf: discriminates the color and causes unnecessary bitmap creation."
  	(self hasGlyphOf: aCharacter)
  		ifFalse: [^ self fallbackFont widthOf: aCharacter].
+ 	^(self formOf: aCharacter) advanceWidth!
- 	^(self formOf: aCharacter) width!

Item was changed:
  ----- Method: TTFileDescription>>renderGlyph:height:fgColor:bgColor:depth: (in category 'rendering') -----
  renderGlyph: code height: fontHeight fgColor: fgColor bgColor: bgColor depth: depth
  	"Render the glyph with the given code point at the specified pixel height."
  
+ 	self flag: #deprecated.
  	^ self
+ 		renderGlyph: code height: fontHeight extraScale: 1.0
- 		renderGlyph: code height: fontHeight
  		fgColor: fgColor bgColor: bgColor depth: depth
  		lineGlyph: nil lineGlyphWidth: 0 emphasis: 0!

Item was changed:
  ----- Method: TTFileDescription>>renderGlyph:height:fgColor:bgColor:depth:lineGlyph:lineGlyphWidth:emphasis: (in category 'rendering') -----
+ renderGlyph: code height: fontHeight fgColor: fgColor bgColor: bgColor depth: depth lineGlyph: lineGlyphOrNil lineGlyphWidth: lWidth emphasis: emphasis
- renderGlyph: code height: fontHeight fgColor: fgColor bgColor: bgColor depth: depth lineGlyph: lineGlyph lineGlyphWidth: lWidth emphasis: emphasis
  	"Render the glyph with the given code point at the specified pixel height. Underline it with lineGlyph."
  	
+ 	self flag: #deprecated.
+ 	^ self
+ 		renderGlyph: code height: fontHeight extraScale: 1.0
- 	| form pixelScale  offset |
- 	pixelScale := fontHeight asFloat / self fontHeight.
- 	offset := 0 @ ( (((self ascender) - ((self ascender) * self extraScale)) * pixelScale) truncated).
- 	form := (self at: code) 
- 		asFormWithScale: pixelScale * self extraScale
- 		ascender: self ascender
- 		descender: self descender
  		fgColor: fgColor bgColor: bgColor depth: depth
+ 		lineGlyph: lineGlyphOrNil lineGlyphWidth: lWidth emphasis: emphasis!
- 		replaceColor: false
- 		lineGlyph: lineGlyph lineGlyphWidth: lWidth
- 		emphasis: emphasis.
- 	form offset: offset.
- 	^ form!

Item was changed:
  ----- Method: TTFontDescription>>renderGlyph:height:fgColor:bgColor:depth: (in category 'rendering') -----
  renderGlyph: code height: fontHeight fgColor: fgColor bgColor: bgColor depth: depth
  	"Render the glyph with the given code point at the specified pixel height."
  
+ 	self flag: #deprecated.
  	^ self
+ 		renderGlyph: code height: fontHeight extraScale: 1.0
- 		renderGlyph: code height: fontHeight
  		fgColor: fgColor bgColor: bgColor depth: depth
  		lineGlyph: nil lineGlyphWidth: 0 emphasis: 0!

Item was changed:
  ----- Method: TTFontDescription>>renderGlyph:height:fgColor:bgColor:depth:lineGlyph:lineGlyphWidth:emphasis: (in category 'rendering') -----
  renderGlyph: code height: fontHeight fgColor: fgColor bgColor: bgColor depth: depth lineGlyph: lineGlyphOrNil lineGlyphWidth: lWidth emphasis: emphasis
  	"Render the glyph with the given code point at the specified pixel height. Underline it with lineGlyph."
  	
+ 	self flag: #deprecated.
+ 	^ self
+ 		renderGlyph: code height: fontHeight extraScale: 1.0
- 	| form pixelScale  offset |
- 	pixelScale := fontHeight asFloat / self fontHeight.
- 	offset := 0 @ ( (((self ascender) - ((self ascender) * self extraScale)) * pixelScale) truncated).
- 	form := (self at: code) 
- 		asFormWithScale: pixelScale * self extraScale
- 		ascender: self ascender
- 		descender: self descender
  		fgColor: fgColor bgColor: bgColor depth: depth
+ 		lineGlyph: lineGlyphOrNil lineGlyphWidth: lWidth emphasis: emphasis!
- 		replaceColor: false
- 		lineGlyph: lineGlyphOrNil lineGlyphWidth: lWidth
- 		emphasis: emphasis.
- 	form offset: offset.
- 	^ form!

Item was changed:
  ----- Method: TTGlyph>>asFormWithScale:ascender:descender:fgColor:bgColor:depth:replaceColor:lineGlyph:lineGlyphWidth:emphasis: (in category 'converting') -----
  asFormWithScale: scale ascender: ascender descender: descender fgColor: fgColor bgColor: bgColor depth: depth replaceColor: replaceColorFlag lineGlyph: lineGlyph lineGlyphWidth: lWidth emphasis: code
  
+ 	| topBearing bottomBearing pixelBox pixelOutset form canvas newScale renderOffset |
+ 	topBearing := bounds bottom - ascender max: 0.
+ 	bottomBearing := bounds top - descender min: 0.
+ 	renderOffset := leftSideBearing abs @ (ascender+topBearing) negated.
+ 	
+ 	"Prepare the pixel box"
+ 	pixelBox := ((advanceWidth @ (ascender - descender)) * scale) rounded.
+ 	pixelOutset := ((leftSideBearing abs @ topBearing "abs" ) * scale) rounded 
+ 		corner: ((rightSideBearing abs @ bottomBearing abs ) * scale) rounded.
+ 	form := TTGlyphForm extent: pixelBox
+ 		+ pixelOutset left + pixelOutset top
+ 		+ pixelOutset right + pixelOutset bottom
+ 			depth: depth.
+ 	form advanceWidth: pixelBox x.
+ 	form offset: pixelOutset topLeft negated.
+ 	
- 	| form canvas newScale |
- 	form := Form extent: ((advanceWidth @ (ascender - descender)) * scale) rounded depth: depth.
  	form fillColor: bgColor.
  	canvas := form getCanvas asBalloonCanvas.
  	canvas aaLevel: 4.
  	canvas transformBy: (MatrixTransform2x3 withScale: scale asPoint * (1 @ -1)).
+ 	canvas transformBy: (MatrixTransform2x3 withOffset: renderOffset).
- 	canvas transformBy: (MatrixTransform2x3 withOffset: 0 @ ascender negated).
  	canvas
  		drawGeneralBezierShape: self contours
  		color: fgColor 
  		borderWidth: 0 
  		borderColor: fgColor.
  	((code bitAnd: 4) ~= 0 or: [(code bitAnd: 16) ~= 0]) ifTrue: [
+ 		newScale := (pixelBox x + 1) asFloat / lineGlyph calculateWidth asFloat.
- 		newScale := (form width + 1) asFloat / lineGlyph calculateWidth asFloat.
  		canvas transformBy: (MatrixTransform2x3 withScale: (newScale / scale)@1.0).
  
  		(code bitAnd: 4) ~= 0 ifTrue: [
  			canvas
  				drawGeneralBezierShape: lineGlyph contours
  				color: fgColor 
  				borderWidth: 0 
  				borderColor: fgColor.
  		].
  
+ 		(code bitAnd: 16) ~= 0 ifTrue: [ | renderLineOffset |
+ 			renderLineOffset := renderOffset x @ (renderOffset y negated // 2).
+ 			canvas transformBy: (MatrixTransform2x3 withOffset: renderLineOffset).
- 		(code bitAnd: 16) ~= 0 ifTrue: [
- 			canvas transformBy: (MatrixTransform2x3 withOffset: 0@(ascender // 2)).
  			canvas
  				drawGeneralBezierShape: lineGlyph contours
  				color: fgColor 
  				borderWidth: 0 
  				borderColor: fgColor.
  		].
  	].
  
  	replaceColorFlag ifTrue: [
  		form replaceColor: bgColor withColor: Color transparent.
  	].
  	^ form!

Item was added:
+ (PackageInfo named: 'TrueType') postscript: '"Moves extra glyph scale and extra line gap from font description (i.e., TTFontDescription) up to font instance (i.e., TTCFont). Restore glyph scale for default fonts. Note that we might want to rename their #familyName(:)  in the future to make that clear. Scale factors were chosen to look good on various scale factors at 10.5 pt."
+ 
+ #(
+ BitstreamVeraSans 1.059 24
+ BitstreamVeraSansMono 1.059 24
+ BitstreamVeraSerif 1.11 47
+ ) groupsDo: [:name :scale :gap |
+ 	(TextStyle named: name) defaultFont
+ 		extraGlyphScale: scale;
+ 		extraLineGap: gap].
+ TTCFont shutDown: true. "Reset glyph caches"'!



More information about the Squeak-dev mailing list