@@ -439,13 +439,13 @@ impl ParsedFont {
439
439
}
440
440
441
441
pub trait PrepFont {
442
- fn lgi ( & self , codepoint : u32 ) -> Option < u32 > ;
442
+ fn lookup_glyph_index ( & self , codepoint : u32 ) -> Option < u16 > ;
443
443
444
444
fn index_to_cid ( & self , index : u16 ) -> Option < u16 > ;
445
445
}
446
446
447
447
impl PrepFont for ParsedFont {
448
- fn lgi ( & self , codepoint : u32 ) -> Option < u32 > {
448
+ fn lookup_glyph_index ( & self , codepoint : u32 ) -> Option < u16 > {
449
449
self . lookup_glyph_index ( codepoint) . map ( Into :: into)
450
450
}
451
451
@@ -590,7 +590,6 @@ impl ParsedFont {
590
590
} )
591
591
} )
592
592
. flatten ( )
593
- . map ( |x| x)
594
593
. collect :: < BTreeSet < _ > > ( ) ;
595
594
596
595
if codepoints. is_empty ( ) && chars. is_empty ( ) {
@@ -682,27 +681,34 @@ impl ParsedFont {
682
681
pub ( crate ) fn generate_cmap_string (
683
682
& self ,
684
683
font_id : & FontId ,
685
- gid_to_cid_map : & [ ( u16 , u16 ) ] ,
684
+ gid_to_cid_map : & [ ( u16 , u32 ) ] ,
686
685
) -> String {
687
686
// Convert the glyph_ids map to a ToUnicodeCMap structure
688
687
let mappings = gid_to_cid_map
689
688
. iter ( )
690
- . map ( |& ( gid, cp) | ( gid as u32 , vec ! [ cp as u32 ] ) )
689
+ . map ( |& ( gid, cp) | ( gid as u32 , vec ! [ cp] ) )
691
690
. collect ( ) ;
692
691
693
692
// Create the CMap and generate its string representation
694
693
let cmap = ToUnicodeCMap { mappings } ;
695
694
cmap. to_cmap_string ( & font_id. 0 )
696
695
}
697
696
698
- pub ( crate ) fn generate_gid_to_cid_map ( & self , glyph_ids : & [ u16 ] ) -> Vec < ( u16 , u16 ) > {
697
+ pub ( crate ) fn generate_gid_to_cid_map ( & self , glyph_ids : & [ ( u16 , char ) ] ) -> Vec < ( u16 , u32 ) > {
699
698
glyph_ids
700
699
. iter ( )
701
- . filter_map ( |gid| self . index_to_cid ( * gid) . map ( |cid| ( * gid, cid) ) )
700
+ . map ( |& ( gid, c) | {
701
+ self . index_to_cid ( gid)
702
+ . map ( |cid| ( gid, cid as u32 ) )
703
+ . unwrap_or ( ( gid, c as u32 ) )
704
+ } )
702
705
. collect ( )
703
706
}
704
707
705
- pub ( crate ) fn get_normalized_widths_ttf ( & self , glyph_ids : & [ u16 ] ) -> Vec < lopdf:: Object > {
708
+ pub ( crate ) fn get_normalized_widths_ttf (
709
+ & self ,
710
+ glyph_ids : & [ ( u16 , char ) ] ,
711
+ ) -> Vec < lopdf:: Object > {
706
712
let mut widths_list = Vec :: new ( ) ;
707
713
let mut current_low_gid = 0 ;
708
714
let mut current_high_gid = 0 ;
@@ -711,7 +717,7 @@ impl ParsedFont {
711
717
// scale the font width so that it sort-of fits into an 1000 unit square
712
718
let percentage_font_scaling = 1000.0 / ( self . font_metrics . units_per_em as f32 ) ;
713
719
714
- for & gid in glyph_ids {
720
+ for & ( gid, _ ) in glyph_ids {
715
721
let width = match self . get_glyph_width_internal ( gid) {
716
722
Some ( s) => s,
717
723
None => match self . get_space_width ( ) {
@@ -744,7 +750,7 @@ impl ParsedFont {
744
750
745
751
pub ( crate ) fn get_normalized_widths_cff (
746
752
& self ,
747
- gid_to_cid_map : & [ ( u16 , u16 ) ] ,
753
+ gid_to_cid_map : & [ ( u16 , u32 ) ] ,
748
754
) -> Vec < lopdf:: Object > {
749
755
let mut widths_list = Vec :: new ( ) ;
750
756
@@ -1447,8 +1453,7 @@ impl ParsedFont {
1447
1453
}
1448
1454
1449
1455
let glyph_index = glyph_index as u16 ;
1450
- // Create identity map for compatibility with CFF fonts
1451
- index_to_cid. insert ( glyph_index, glyph_index) ;
1456
+
1452
1457
let horz_advance = match allsorts_subset_browser:: glyph_info:: advance (
1453
1458
& maxp_table,
1454
1459
& hhea_table,
0 commit comments