summarylogtreecommitdiffstats
path: root/bug123562.patch
blob: 21261518f8ec1c2d2a1bbfbe0bb31096f1354dbb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
--- a/lib/Text/PDF/TTFont0.pm	2018-02-02 15:27:58.315775700 +0200
+++ b/lib/Text/PDF/TTFont0.pm	2019-07-17 08:25:04.000000000 +0200
@@ -106,25 +106,28 @@
     if ($opt{'ToUnicode'})
     {
         @rev = $font->{'cmap'}->read->reverse;
-        $unistr = '/CIDInit /ProcSet findresource being 12 dict begin begincmap
+        my $num = grep defined, @rev;
+        $unistr = '/CIDInit /ProcSet findresource begin 12 dict begin begincmap
 /CIDSystemInfo << /Registry (' . $self->{'BaseFont'}->val . '+0) /Ordering (XYZ)
 /Supplement 0 >> def
 /CMapName /' . $self->{'BaseFont'}->val . '+0 def /CMapType 2 def
-1 begincodespacerange ';
-        $unistr .= sprintf("<%04X> <%04X> endcodespacerange\n", 1, $num - 1);
-        $unistr .= $num - $i > 100 ? 100 : $num - $i;
-        $unistr .= " beginbfrange\n";
-        for ($i = 1; $i < $num; $i++)
+1 begincodespacerange <0000> <FFFF> endcodespacerange'."\n";
+        for (my $i = my $j = 0; $i < @rev; $i++, $j++)
         {
-            if ($i % 100 == 0)
+            next unless defined $rev[$i];
+            my $s = $num - $j > 100 ? 100 : $num - $j;
+            if ($j == 0)
             {
-                $unistr .= "endbfrange\n";
-                $unistr .= $num - $i > 100 ? 100 : $num - $i;
-                $unistr .= " beginbfrange\n";
+                $unistr .= "$s beginbfchar\n";
             }
-            $unistr .= sprintf("<%04X> <%04X> <%04X>\n", $i, $i, $rev[$i]);
+            elsif ($j % 100 == 0)
+            {
+                $unistr .= "endbfchar\n";
+                $unistr .= "$s beginbfchar\n";
+            }
+            $unistr .= sprintf("<%04X> <%04X>\n", $i, $rev[$i]);
         }
-        $unistr .= "endbfrange\nendcmap CMapName currendict /CMap defineresource pop end end\n";
+        $unistr .= "endbfchar\nendcmap CMapName currendict /CMap defineresource pop end end\n";
         $touni = PDFDict();
         $parent->new_obj($touni);
         $touni->{' stream'} = $unistr;