@@ -608,7 +608,14 @@ protected PdfDictionary getCidFontType2(TrueTypeFont ttf, PdfDictionary fontDesc
608
608
* @return the stream representing this CMap or <CODE>null</CODE>
609
609
*/
610
610
public PdfStream getToUnicode (Object [] metrics ) {
611
- if (metrics .length == 0 )
611
+ ArrayList <Integer > unicodeGlyphs = new ArrayList <>(metrics .length );
612
+ for (int i = 0 ; i < metrics .length ; i ++) {
613
+ int [] metric = (int []) metrics [i ];
614
+ if (fontProgram .getGlyphByCode (metric [0 ]).getChars () != null ) {
615
+ unicodeGlyphs .add (metric [0 ]);
616
+ }
617
+ }
618
+ if (unicodeGlyphs .size () == 0 )
612
619
return null ;
613
620
StringBuilder buf = new StringBuilder (
614
621
"/CIDInit /ProcSet findresource begin\n " +
@@ -625,18 +632,17 @@ public PdfStream getToUnicode(Object[] metrics) {
625
632
"<0000><FFFF>\n " +
626
633
"endcodespacerange\n " );
627
634
int size = 0 ;
628
- for (int k = 0 ; k < metrics . length ; ++k ) {
635
+ for (int k = 0 ; k < unicodeGlyphs . size () ; ++k ) {
629
636
if (size == 0 ) {
630
637
if (k != 0 ) {
631
638
buf .append ("endbfrange\n " );
632
639
}
633
- size = Math .min (100 , metrics . length - k );
640
+ size = Math .min (100 , unicodeGlyphs . size () - k );
634
641
buf .append (size ).append (" beginbfrange\n " );
635
642
}
636
643
--size ;
637
- int [] metric = (int []) metrics [k ];
638
- String fromTo = CMapContentParser .toHex (metric [0 ]);
639
- Glyph glyph = fontProgram .getGlyphByCode (metric [0 ]);
644
+ String fromTo = CMapContentParser .toHex (unicodeGlyphs .get (k ));
645
+ Glyph glyph = fontProgram .getGlyphByCode (unicodeGlyphs .get (k ));
640
646
if (glyph .getChars () != null ) {
641
647
StringBuilder uni = new StringBuilder (glyph .getChars ().length );
642
648
for (char ch : glyph .getChars ()) {
0 commit comments