@@ -543,15 +543,36 @@ def generate_pdf(pages, url_fetcher, metadata, fonts, target, zoom,
543
543
widths = [0 ] * (last - first + 1 )
544
544
glyphs_info = {}
545
545
for key , glyph in font_glyphs .items ():
546
+ glyph_format = glyph .getFormat ()
547
+ glyph_id = font .ttfont .getGlyphID (key )
548
+
546
549
# Get and store glyph metrics
547
- height , width = glyph .data [0 :2 ]
548
- bearing_x = int .from_bytes (
549
- glyph .data [2 :3 ], 'big' , signed = True )
550
- bearing_y = int .from_bytes (
551
- glyph .data [3 :4 ], 'big' , signed = True )
552
- advance = glyph .data [4 ]
550
+ if glyph_format == 5 :
551
+ data = glyph .data
552
+ subtables = font .ttfont ['EBLC' ].strikes [0 ].indexSubTables
553
+ for subtable in subtables :
554
+ first_index = subtable .firstGlyphIndex
555
+ last_index = subtable .lastGlyphIndex
556
+ if first_index <= glyph_id <= last_index :
557
+ height = subtable .metrics .height
558
+ advance = width = subtable .metrics .width
559
+ bearing_x = subtable .metrics .horiBearingX
560
+ bearing_y = subtable .metrics .horiBearingY
561
+ break
562
+ else :
563
+ LOGGER .warning (
564
+ f'Unknown bitmap metrics for glyph: { glyph_id } ' )
565
+ continue
566
+ else :
567
+ data_start = 5 if glyph_format in (1 , 2 , 8 ) else 8
568
+ data = glyph .data [data_start :]
569
+ height , width = glyph .data [0 :2 ]
570
+ bearing_x = int .from_bytes (
571
+ glyph .data [2 :3 ], 'big' , signed = True )
572
+ bearing_y = int .from_bytes (
573
+ glyph .data [3 :4 ], 'big' , signed = True )
574
+ advance = glyph .data [4 ]
553
575
position_y = bearing_y - height
554
- glyph_id = font .ttfont .getGlyphID (key )
555
576
if glyph_id in chars :
556
577
widths [glyph_id - first ] = advance
557
578
stride = math .ceil (width / 8 )
@@ -565,13 +586,10 @@ def generate_pdf(pages, url_fetcher, metadata, fonts, target, zoom,
565
586
'subglyphs' : None ,
566
587
}
567
588
568
- # Apply glyph format tweaks
569
- glyph_format = glyph .getFormat ()
570
- data_start = 5 if glyph_format in (1 , 2 , 8 ) else 8
571
- data = glyph .data [data_start :]
589
+ # Decode bitmaps
572
590
if glyph_format in (1 , 6 ):
573
591
glyph_info ['bitmap' ] = data
574
- elif glyph_format in (2 , 7 ):
592
+ elif glyph_format in (2 , 5 , 7 ):
575
593
padding = (8 - (width % 8 )) % 8
576
594
bits = bin (int (data .hex (), 16 ))[2 :]
577
595
bits = bits .zfill (8 * len (data ))
0 commit comments