[squeak-dev] TTFontReader deals only with unicode char mapping

Igor Stasenko siguctua at gmail.com
Sun May 23 23:55:46 UTC 2010


Hello,

i just found that for windoze-specific character maps (platform id =
3, and platform specific id = 1)
TTFontReader maps only first 256 characters, leaving all other glyphs
unmapped (and hence useless garbage in TTFontDescription).

However, as far as i can tell, pId=3, sId=1 contains a unicode character map,
so, it can be mapped as well as for pId=0.

Here the quote from http://support.microsoft.com/kb/241020
----------
Per the TrueType specification, the Unicode encoding is located in the
subtable marked with a PlatformId value of 3 and a SpecificId value of
1. The specification also defines the subtable referenced by this 3-1
encoding to be a Format 4 subtable. An encoding with a PlatformId of 3
and a SpecificId of 0 (zero) is also Format 4 encoding but the font
file is usually interpreted as a symbol font file. Per the symbol font
suggestion in the TrueType specification, one would expect this
encoding to contain character codes from the Unicode Private Use Area.

-----------

So, i think we can patch TTFontReader to handle this:


processCharMap: assoc
	"Process the given character map"

	| charTable glyph cmap |
	cmap := assoc value.

-	assoc key = 0 ifTrue: "Unicode table"
+	(assoc key = 3  or: [ assoc key = 0]) ifTrue: "Unicode table"
		[charTable := SparseLargeTable new: cmap size
			chunkSize: 256 arrayClass: Array base: 1
			defaultValue: glyphs first.
		1 to: charTable size do:
			[:i |
			glyph := glyphs at: (cmap at: i) + 1 ifAbsent: [glyphs first].
			charTable at: i put: glyph].
		charTable zapDefaultOnlyEntries.
		^charTable].

	charTable := Array new: 256 withAll: glyphs first. "Initialize with
default glyph"

	assoc key = 1 ifTrue: "Mac encoded table"
		[1 to: (cmap size min: charTable size) do:
			[:i |
			glyph := glyphs at: (cmap at: i) + 1.
			charTable at: (self macToWin: i) put: glyph]].

-	assoc key = 3 ifTrue: "Win encoded table"
-		[1 to: (cmap size min: charTable size) do:
-			[:i |
-			glyph := glyphs at: (cmap at: i) + 1.
-			charTable at: i put: glyph]].

	^ charTable


-- 
Best regards,
Igor Stasenko AKA sig.



More information about the Squeak-dev mailing list