[ENH] TTFontReader type 6 cmaps

Bob Arning arning at charm.net
Sun Sep 12 15:04:49 UTC 1999


A change to TTFontFreader to allow processing of type 6 cmaps.

Cheers,
Bob

=======

'From Squeak 2.5 of August 6, 1999 on 12 September 1999 at 11:04:20 am'!
"Change Set:		TTFR updates
Date:			12 September 1999
Author:			Bob Arning

A change to TTFontFreader to allow processing of type 6 cmaps."!


!TTFontReader methodsFor: 'processing' stamp: 'RAA 9/12/1999 10:52'!
processCharMap: assoc
	"Process the given character map"
	| charTable glyph cmap |
	cmap _ assoc value.
	charTable _ Array new: 256.
	charTable atAllPut: glyphs first. "Initialize with default glyph"

	assoc key = 1 ifTrue:["Mac encoded table"
		1 to: 256 do:[:i| 
			glyph _ glyphs at: (cmap at: 6+i ifAbsent: [cmap at: 7])+1.
			charTable at: i put: glyph]].

	assoc key = 3 ifTrue:["Win encoded table"
		1 to: 256 do:[:i| 
			glyph _ glyphs at: (cmap at: 6+i)+1.
			charTable at: (WinToMacTable at: i) put: glyph]].

	^charTable! !

!TTFontReader methodsFor: 'processing' stamp: 'RAA 9/12/1999 11:03'!
processCharacterMappingTable: entry
	"Read the font's character to glyph index mapping table.
	If an appropriate mapping can be found then return an association
	with the format identifier and the contents of the table"
	| copy initialOffset nSubTables pID sID offset cmapFmt tableLength cmap assoc firstCharCode entryCount |
	initialOffset _ entry offset.
	entry skip: 2. "Skip table version"
	nSubTables _ entry nextUShort.
	1 to: nSubTables do:[:i|
		pID _ entry nextUShort.
		sID _ entry nextUShort.
		offset _ entry nextULong.
		"Check if this is either a Macintosh encoded table
		or a Windows encoded table"
		(pID = 1 or:[pID = 3]) ifTrue:[
			"Go to the beginning of the table"
			copy _ entry copy.
			copy offset: initialOffset + offset.
			cmapFmt _ copy nextUShort.
			tableLength _ copy nextUShort.
			"We can only read cmaps of type 0 (e.g., byte encoded tables)"
			(cmapFmt = 0 "or:[cmapFmt = 4]") ifTrue:[
				cmap _ Array new: tableLength.
				copy nextBytes: tableLength into: cmap startingAt: initialOffset + offset
			].
			(cmapFmt = 6) ifTrue:[
				copy nextUShort.	"language code"
				firstCharCode _ copy nextUShort.
				entryCount _ copy nextUShort.
				cmap _ Array new: entryCount + firstCharCode + 6.	"slop to match type 0"
				1 to: entryCount do: [ :jj | cmap at: jj + firstCharCode + 6 put: copy nextUShort].
			].
			pID = 1 ifTrue:[^pID -> cmap]. "Prefer Macintosh encoding over everything else"
			assoc _ pID -> cmap. "Keep it in case we don't find a Mac encoded table"
		].
	].
	^assoc! !





More information about the Squeak-dev mailing list