@@ -201,12 +201,16 @@ type Font struct {
201
201
cmGlyphIDArray []uint8
202
202
charcodeToGID map [uint8 ]uint32
203
203
hasShortCmap bool
204
+ // support of cmap format 6
205
+ cmGlyphIDArrayUint16 []uint16
206
+ firstCode uint16
204
207
}
205
208
206
209
func (f * Font ) parseCmap () error {
207
210
const (
208
211
cmapFormat0 = 0
209
212
cmapFormat4 = 4
213
+ cmapFormat6 = 6
210
214
cmapFormat12 = 12
211
215
languageIndependent = 0
212
216
)
@@ -301,6 +305,17 @@ func (f *Font) parseCmap() error {
301
305
f .charcodeToGID = charcodeMap
302
306
}
303
307
return nil
308
+ case cmapFormat6 :
309
+ firstCode := u16 (f .cmap , offset + 6 )
310
+ entryCount := u16 (f .cmap , offset + 8 )
311
+ glyphIDArray := make ([]uint16 , entryCount )
312
+ for i := 0 ; i < int (entryCount ); i ++ {
313
+ glyphIDArray [i ] = u16 (f .cmap , offset + 10 + 2 * i )
314
+ }
315
+ f .cmGlyphIDArrayUint16 = glyphIDArray
316
+ f .hasShortCmap = true
317
+ f .firstCode = firstCode
318
+ return nil
304
319
case cmapFormat12 :
305
320
if u16 (f .cmap , offset + 2 ) != 0 {
306
321
return FormatError (fmt .Sprintf ("cmap format: % x" , f .cmap [offset :offset + 4 ]))
@@ -455,6 +470,11 @@ func (f *Font) Index(x rune) Index {
455
470
return Index (val )
456
471
}
457
472
473
+ if len (f .cmGlyphIDArrayUint16 )+ int (f .firstCode ) > int (c ) && int (f .firstCode ) <= int (c ) {
474
+ val := f .cmGlyphIDArrayUint16 [c - uint32 (f .firstCode )]
475
+ return Index (val )
476
+ }
477
+
458
478
if len (f .charcodeToGID ) > 0 {
459
479
val := f .charcodeToGID [uint8 (c )]
460
480
return Index (val )
@@ -628,6 +648,8 @@ func parse(ttf []byte, offset int) (font *Font, err error) {
628
648
switch magic {
629
649
case 0x00010000 :
630
650
// No-op.
651
+ case 0x74727565 :
652
+ // No-op.
631
653
case 0x74746366 : // "ttcf" as a big-endian uint32.
632
654
if originalOffset != 0 {
633
655
err = FormatError ("recursive TTC" )
0 commit comments