• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #include "core/fpdfapi/font/cpdf_fontencoding.h"
8 
9 #include <utility>
10 
11 #include "core/fpdfapi/parser/cpdf_array.h"
12 #include "core/fpdfapi/parser/cpdf_dictionary.h"
13 #include "core/fpdfapi/parser/cpdf_name.h"
14 #include "core/fpdfapi/parser/cpdf_number.h"
15 #include "core/fpdfapi/parser/fpdf_parser_decode.h"
16 #include "core/fxge/fx_font.h"
17 #include "core/fxge/fx_freetype.h"
18 #include "third_party/base/ptr_util.h"
19 
20 namespace {
21 
22 const uint16_t MSSymbolEncoding[CPDF_FontEncoding::kEncodingTableSize] = {
23     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
24     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
25     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
26     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0020, 0x0021, 0x2200, 0x0023,
27     0x2203, 0x0025, 0x0026, 0x220b, 0x0028, 0x0029, 0x2217, 0x002b, 0x002c,
28     0x2212, 0x002e, 0x002f, 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035,
29     0x0036, 0x0037, 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e,
30     0x003f, 0x2245, 0x0391, 0x0392, 0x03a7, 0x0394, 0x0395, 0x03a6, 0x0393,
31     0x0397, 0x0399, 0x03d1, 0x039a, 0x039b, 0x039c, 0x039d, 0x039f, 0x03a0,
32     0x0398, 0x03a1, 0x03a3, 0x03a4, 0x03a5, 0x03c2, 0x03a9, 0x039e, 0x03a8,
33     0x0396, 0x005b, 0x2234, 0x005d, 0x22a5, 0x005f, 0x203e, 0x03b1, 0x03b2,
34     0x03c7, 0x03b4, 0x03b5, 0x03c6, 0x03b3, 0x03b7, 0x03b9, 0x03d5, 0x03ba,
35     0x03bb, 0x03bc, 0x03bd, 0x03bf, 0x03c0, 0x03b8, 0x03c1, 0x03c3, 0x03c4,
36     0x03c5, 0x03d6, 0x03c9, 0x03be, 0x03c8, 0x03b6, 0x007b, 0x007c, 0x007d,
37     0x223c, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
38     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
39     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
40     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x03d2,
41     0x2032, 0x2264, 0x2215, 0x221e, 0x0192, 0x2663, 0x2666, 0x2664, 0x2660,
42     0x2194, 0x2190, 0x2191, 0x2192, 0x2193, 0x00b0, 0x00b1, 0x2033, 0x2265,
43     0x00d7, 0x221d, 0x2202, 0x2219, 0x00f7, 0x2260, 0x2261, 0x2248, 0x22ef,
44     0x0000, 0x0000, 0x21b5, 0x0000, 0x2111, 0x211c, 0x2118, 0x2297, 0x2295,
45     0x2205, 0x2229, 0x222a, 0x2283, 0x2287, 0x2284, 0x2282, 0x2286, 0x2208,
46     0x2209, 0x2220, 0x2207, 0x00ae, 0x00a9, 0x2122, 0x220f, 0x221a, 0x22c5,
47     0x00ac, 0x2227, 0x2228, 0x21d4, 0x21d0, 0x21d1, 0x21d2, 0x21d3, 0x25ca,
48     0x2329, 0x0000, 0x0000, 0x0000, 0x2211, 0x0000, 0x0000, 0x0000, 0x0000,
49     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x232a, 0x222b,
50     0x2320, 0x0000, 0x2321, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
51     0x0000, 0x0000, 0x0000, 0x0000};
52 
53 const uint16_t StandardEncoding[CPDF_FontEncoding::kEncodingTableSize] = {
54     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
55     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
56     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
57     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0020, 0x0021, 0x0022, 0x0023,
58     0x0024, 0x0025, 0x0026, 0x2019, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c,
59     0x002d, 0x002e, 0x002f, 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035,
60     0x0036, 0x0037, 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e,
61     0x003f, 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
62     0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f, 0x0050,
63     0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059,
64     0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f, 0x2018, 0x0061, 0x0062,
65     0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006a, 0x006b,
66     0x006c, 0x006d, 0x006e, 0x006f, 0x0070, 0x0071, 0x0072, 0x0073, 0x0074,
67     0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d,
68     0x007e, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
69     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
70     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
71     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x00a1,
72     0x00a2, 0x00a3, 0x2044, 0x00a5, 0x0192, 0x00a7, 0x00a4, 0x0027, 0x201c,
73     0x00ab, 0x2039, 0x203a, 0xfb01, 0xfb02, 0x0000, 0x2013, 0x2020, 0x2021,
74     0x00b7, 0x0000, 0x00b6, 0x2022, 0x201a, 0x201e, 0x201d, 0x00bb, 0x2026,
75     0x2030, 0x0000, 0x00bf, 0x0000, 0x0060, 0x00b4, 0x02c6, 0x02dc, 0x00af,
76     0x02d8, 0x02d9, 0x00a8, 0x0000, 0x02da, 0x00b8, 0x0000, 0x02dd, 0x02db,
77     0x02c7, 0x2014, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
78     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
79     0x00c6, 0x0000, 0x00aa, 0x0000, 0x0000, 0x0000, 0x0000, 0x0141, 0x00d8,
80     0x0152, 0x00ba, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x00e6, 0x0000,
81     0x0000, 0x0000, 0x0131, 0x0000, 0x0000, 0x0142, 0x00f8, 0x0153, 0x00df,
82     0x0000, 0x0000, 0x0000, 0x0000};
83 
84 const uint16_t MacRomanEncoding[CPDF_FontEncoding::kEncodingTableSize] = {
85     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
86     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
87     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
88     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0020, 0x0021, 0x0022, 0x0023,
89     0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c,
90     0x002d, 0x002e, 0x002f, 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035,
91     0x0036, 0x0037, 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e,
92     0x003f, 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
93     0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f, 0x0050,
94     0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059,
95     0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f, 0x0060, 0x0061, 0x0062,
96     0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006a, 0x006b,
97     0x006c, 0x006d, 0x006e, 0x006f, 0x0070, 0x0071, 0x0072, 0x0073, 0x0074,
98     0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d,
99     0x007e, 0x0000, 0x00c4, 0x00c5, 0x00c7, 0x00c9, 0x00d1, 0x00d6, 0x00dc,
100     0x00e1, 0x00e0, 0x00e2, 0x00e4, 0x00e3, 0x00e5, 0x00e7, 0x00e9, 0x00e8,
101     0x00ea, 0x00eb, 0x00ed, 0x00ec, 0x00ee, 0x00ef, 0x00f1, 0x00f3, 0x00f2,
102     0x00f4, 0x00f6, 0x00f5, 0x00fa, 0x00f9, 0x00fb, 0x00fc, 0x2020, 0x00b0,
103     0x00a2, 0x00a3, 0x00a7, 0x2022, 0x00b6, 0x00df, 0x00ae, 0x00a9, 0x2122,
104     0x00b4, 0x00a8, 0x0000, 0x00c6, 0x00d8, 0x0000, 0x00b1, 0x0000, 0x0000,
105     0x00a5, 0x00b5, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x00aa, 0x00ba,
106     0x0000, 0x00e6, 0x00f8, 0x00bf, 0x00a3, 0x00ac, 0x0000, 0x0192, 0x0000,
107     0x0000, 0x00ab, 0x00bb, 0x2026, 0x0020, 0x00c0, 0x00c3, 0x00d5, 0x0152,
108     0x0153, 0x2013, 0x2014, 0x201c, 0x201d, 0x2018, 0x2019, 0x00f7, 0x0000,
109     0x00ff, 0x0178, 0x2044, 0x00a4, 0x2039, 0x203a, 0xfb01, 0xfb02, 0x2021,
110     0x00b7, 0x201a, 0x201e, 0x2030, 0x00c2, 0x00ca, 0x00c1, 0x00cb, 0x00c8,
111     0x00cd, 0x00ce, 0x00cf, 0x00cc, 0x00d3, 0x00d4, 0x0000, 0x00d2, 0x00da,
112     0x00db, 0x00d9, 0x0131, 0x02c6, 0x02dc, 0x00af, 0x02d8, 0x02d9, 0x02da,
113     0x00b8, 0x02dd, 0x02db, 0x02c7};
114 
115 const uint16_t AdobeWinAnsiEncoding[CPDF_FontEncoding::kEncodingTableSize] = {
116     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
117     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
118     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
119     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0020, 0x0021, 0x0022, 0x0023,
120     0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c,
121     0x002d, 0x002e, 0x002f, 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035,
122     0x0036, 0x0037, 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e,
123     0x003f, 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
124     0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f, 0x0050,
125     0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059,
126     0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f, 0x0060, 0x0061, 0x0062,
127     0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006a, 0x006b,
128     0x006c, 0x006d, 0x006e, 0x006f, 0x0070, 0x0071, 0x0072, 0x0073, 0x0074,
129     0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d,
130     0x007e, 0x2022, 0x20ac, 0x2022, 0x201a, 0x0192, 0x201e, 0x2026, 0x2020,
131     0x2021, 0x02c6, 0x2030, 0x0160, 0x2039, 0x0152, 0x2022, 0x017d, 0x2022,
132     0x2022, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, 0x02dc,
133     0x2122, 0x0161, 0x203a, 0x0153, 0x2022, 0x017e, 0x0178, 0x0020, 0x00a1,
134     0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, 0x00a8, 0x00a9, 0x00aa,
135     0x00ab, 0x00ac, 0x002d, 0x00ae, 0x00af, 0x00b0, 0x00b1, 0x00b2, 0x00b3,
136     0x00b4, 0x00b5, 0x00b6, 0x00b7, 0x00b8, 0x00b9, 0x00ba, 0x00bb, 0x00bc,
137     0x00bd, 0x00be, 0x00bf, 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5,
138     0x00c6, 0x00c7, 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce,
139     0x00cf, 0x00d0, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7,
140     0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x00de, 0x00df, 0x00e0,
141     0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, 0x00e8, 0x00e9,
142     0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, 0x00f0, 0x00f1, 0x00f2,
143     0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x00f9, 0x00fa, 0x00fb,
144     0x00fc, 0x00fd, 0x00fe, 0x00ff};
145 
146 const uint16_t MacExpertEncoding[CPDF_FontEncoding::kEncodingTableSize] = {
147     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
148     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
149     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
150     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0020, 0xf721, 0xf6f8, 0xf7a2,
151     0xf724, 0xf6e4, 0xf726, 0xf7b4, 0x207d, 0x207e, 0x2025, 0x2024, 0x002c,
152     0x002d, 0x002e, 0x2044, 0xf730, 0xf731, 0xf732, 0xf733, 0xf734, 0xf735,
153     0xf736, 0xf737, 0xf738, 0xf739, 0x003a, 0x003b, 0x0000, 0xf6de, 0x0000,
154     0xf73f, 0x0000, 0x0000, 0x0000, 0x0000, 0xf7f0, 0x0000, 0x0000, 0x00bc,
155     0x00bd, 0x00be, 0x215b, 0x215c, 0x215d, 0x215e, 0x2153, 0x2154, 0x0000,
156     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xfb00, 0xfb01, 0xfb02, 0xfb03,
157     0xfb04, 0x208d, 0x0000, 0x208e, 0xf6f6, 0xf6e5, 0xf760, 0xf761, 0xf762,
158     0xf763, 0xf764, 0xf765, 0xf766, 0xf767, 0xf768, 0xf769, 0xf76a, 0xf76b,
159     0xf76c, 0xf76d, 0xf76e, 0xf76f, 0xf770, 0xf771, 0xf772, 0xf773, 0xf774,
160     0xf775, 0xf776, 0xf777, 0xf778, 0xf779, 0xf77a, 0x20a1, 0xf6dc, 0xf6dd,
161     0xf6fe, 0x0000, 0x0000, 0xf6e9, 0xf6e0, 0x0000, 0x0000, 0x0000, 0x0000,
162     0xf7e1, 0xf7e0, 0xf7e2, 0xf7e4, 0xf7e3, 0xf7e5, 0xf7e7, 0xf7e9, 0xf7e8,
163     0xf7ea, 0xf7eb, 0xf7ed, 0xf7ec, 0xf7ee, 0xf7ef, 0xf7f1, 0xf7f3, 0xf7f2,
164     0xf7f4, 0xf7f6, 0xf7f5, 0xf7fa, 0xf7f9, 0xf7fb, 0xf7fc, 0x0000, 0x2078,
165     0x2084, 0x2083, 0x2086, 0x2088, 0x2087, 0xf6fd, 0x0000, 0xf6df, 0x2082,
166     0x0000, 0xf7a8, 0x0000, 0xf6f5, 0xf6fd, 0x2085, 0x0000, 0xf6e1, 0xf6e7,
167     0xf7fd, 0x0000, 0xf6e3, 0x0000, 0x0000, 0xf7fe, 0x0000, 0x2089, 0x2080,
168     0xf6ff, 0xf7e6, 0xf7f8, 0xf7bf, 0x2081, 0xf6e9, 0x0000, 0x0000, 0x0000,
169     0x0000, 0x0000, 0x0000, 0xf7b8, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
170     0xf6fa, 0x2012, 0xf6e6, 0x0000, 0x0000, 0x0000, 0x0000, 0xf7a1, 0x0000,
171     0xf7ff, 0x0000, 0x00b9, 0x00b2, 0x00b3, 0x2074, 0x2075, 0x2076, 0x2077,
172     0x2079, 0x2070, 0x0000, 0xf6ec, 0xf6f1, 0x0000, 0x0000, 0x0000, 0xf6ed,
173     0xf6f2, 0xf6eb, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xf6ee, 0xf6fb,
174     0xf6f4, 0xf7af, 0xf6ea, 0x207f, 0xf6ef, 0xf6e2, 0xf6e8, 0xf6f7, 0xf6fc,
175     0x0000, 0x0000, 0x0000, 0x0000};
176 
177 const uint16_t AdobeSymbolEncoding[CPDF_FontEncoding::kEncodingTableSize] = {
178     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
179     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
180     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
181     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0020, 0x0021, 0x2200, 0x0023,
182     0x2203, 0x0025, 0x0026, 0x220B, 0x0028, 0x0029, 0x2217, 0x002B, 0x002C,
183     0x2212, 0x002E, 0x002F, 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035,
184     0x0036, 0x0037, 0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E,
185     0x003F, 0x2245, 0x0391, 0x0392, 0x03A7, 0x0394, 0x0395, 0x03A6, 0x0393,
186     0x0397, 0x0399, 0x03D1, 0x039A, 0x039B, 0x039C, 0x039D, 0x039F, 0x03A0,
187     0x0398, 0x03A1, 0x03A3, 0x03A4, 0x03A5, 0x03C2, 0x03A9, 0x039E, 0x03A8,
188     0x0396, 0x005B, 0x2234, 0x005D, 0x22A5, 0x005F, 0xF8E5, 0x03B1, 0x03B2,
189     0x03C7, 0x03B4, 0x03B5, 0x03C6, 0x03B3, 0x03B7, 0x03B9, 0x03D5, 0x03BA,
190     0x03BB, 0x03BC, 0x03BD, 0x03BF, 0x03C0, 0x03B8, 0x03C1, 0x03C3, 0x03C4,
191     0x03C5, 0x03D6, 0x03C9, 0x03BE, 0x03C8, 0x03B6, 0x007B, 0x007C, 0x007D,
192     0x223C, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
193     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
194     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
195     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x20AC, 0x03D2,
196     0x2032, 0x2264, 0x2044, 0x221E, 0x0192, 0x2663, 0x2666, 0x2665, 0x2660,
197     0x2194, 0x2190, 0x2191, 0x2192, 0x2193, 0x00B0, 0x00B1, 0x2033, 0x2265,
198     0x00D7, 0x221D, 0x2202, 0x2022, 0x00F7, 0x2260, 0x2261, 0x2248, 0x2026,
199     0xF8E6, 0xF8E7, 0x21B5, 0x2135, 0x2111, 0x211C, 0x2118, 0x2297, 0x2295,
200     0x2205, 0x2229, 0x222A, 0x2283, 0x2287, 0x2284, 0x2282, 0x2286, 0x2208,
201     0x2209, 0x2220, 0x2207, 0xF6DA, 0xF6D9, 0xF6DB, 0x220F, 0x221A, 0x22C5,
202     0x00AC, 0x2227, 0x2228, 0x21D4, 0x21D0, 0x21D1, 0x21D2, 0x21D3, 0x25CA,
203     0x2329, 0xF8E8, 0xF8E9, 0xF8EA, 0x2211, 0xF8EB, 0xF8EC, 0xF8ED, 0xF8EE,
204     0xF8EF, 0xF8F0, 0xF8F1, 0xF8F2, 0xF8F3, 0xF8F4, 0x0000, 0x232A, 0x222B,
205     0x2320, 0xF8F5, 0x2321, 0xF8F6, 0xF8F7, 0xF8F8, 0xF8F9, 0xF8FA, 0xF8FB,
206     0xF8FC, 0xF8FD, 0xF8FE, 0x0000,
207 };
208 
209 const uint16_t ZapfEncoding[CPDF_FontEncoding::kEncodingTableSize] = {
210     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
211     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
212     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
213     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0020, 0x2701, 0x2702, 0x2703,
214     0x2704, 0x260E, 0x2706, 0x2707, 0x2708, 0x2709, 0x261B, 0x261E, 0x270C,
215     0x270D, 0x270E, 0x270F, 0x2710, 0x2711, 0x2712, 0x2713, 0x2714, 0x2715,
216     0x2716, 0x2717, 0x2718, 0x2719, 0x271A, 0x271B, 0x271C, 0x271D, 0x271E,
217     0x271F, 0x2720, 0x2721, 0x2722, 0x2723, 0x2724, 0x2725, 0x2726, 0x2727,
218     0x2605, 0x2729, 0x272A, 0x272B, 0x272C, 0x272D, 0x272E, 0x272F, 0x2730,
219     0x2731, 0x2732, 0x2733, 0x2734, 0x2735, 0x2736, 0x2737, 0x2738, 0x2739,
220     0x273A, 0x273B, 0x273C, 0x273D, 0x273E, 0x273F, 0x2740, 0x2741, 0x2742,
221     0x2743, 0x2744, 0x2745, 0x2746, 0x2747, 0x2748, 0x2749, 0x274A, 0x274B,
222     0x25CF, 0x274D, 0x25A0, 0x274F, 0x2750, 0x2751, 0x2752, 0x25B2, 0x25BC,
223     0x25C6, 0x2756, 0x25D7, 0x2758, 0x2759, 0x275A, 0x275B, 0x275C, 0x275D,
224     0x275E, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
225     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
226     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
227     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x2761,
228     0x2762, 0x2763, 0x2764, 0x2765, 0x2766, 0x2767, 0x2663, 0x2666, 0x2665,
229     0x2660, 0x2460, 0x2461, 0x2462, 0x2463, 0x2464, 0x2465, 0x2466, 0x2467,
230     0x2468, 0x2469, 0x2776, 0x2777, 0x2778, 0x2779, 0x277A, 0x277B, 0x277C,
231     0x277D, 0x277E, 0x277F, 0x2780, 0x2781, 0x2782, 0x2783, 0x2784, 0x2785,
232     0x2786, 0x2787, 0x2788, 0x2789, 0x278A, 0x278B, 0x278C, 0x278D, 0x278E,
233     0x278F, 0x2790, 0x2791, 0x2792, 0x2793, 0x2794, 0x2192, 0x2194, 0x2195,
234     0x2798, 0x2799, 0x279A, 0x279B, 0x279C, 0x279D, 0x279E, 0x279F, 0x27A0,
235     0x27A1, 0x27A2, 0x27A3, 0x27A4, 0x27A5, 0x27A6, 0x27A7, 0x27A8, 0x27A9,
236     0x27AA, 0x27AB, 0x27AC, 0x27AD, 0x27AE, 0x27AF, 0x0000, 0x27B1, 0x27B2,
237     0x27B3, 0x27B4, 0x27B5, 0x27B6, 0x27B7, 0x27B8, 0x27B9, 0x27BA, 0x27BB,
238     0x27BC, 0x27BD, 0x27BE, 0x0000,
239 };
240 
241 constexpr size_t kEncodingTableFirstChar = 32;
242 constexpr size_t kEncodingNamesTableSize =
243     CPDF_FontEncoding::kEncodingTableSize - kEncodingTableFirstChar;
244 constexpr size_t kPDFDocEncodingTableFirstChar = 24;
245 constexpr size_t kPDFDocEncodingNamesTableSize =
246     CPDF_FontEncoding::kEncodingTableSize - kPDFDocEncodingTableFirstChar;
247 
248 const char* const StandardEncodingNames[kEncodingNamesTableSize] = {
249     "space",
250     "exclam",
251     "quotedbl",
252     "numbersign",
253     "dollar",
254     "percent",
255     "ampersand",
256     "quoteright",
257     "parenleft",
258     "parenright",
259     "asterisk",
260     "plus",
261     "comma",
262     "hyphen",
263     "period",
264     "slash",
265     "zero",
266     "one",
267     "two",
268     "three",
269     "four",
270     "five",
271     "six",
272     "seven",
273     "eight",
274     "nine",
275     "colon",
276     "semicolon",
277     "less",
278     "equal",
279     "greater",
280     "question",
281     "at",
282     "A",
283     "B",
284     "C",
285     "D",
286     "E",
287     "F",
288     "G",
289     "H",
290     "I",
291     "J",
292     "K",
293     "L",
294     "M",
295     "N",
296     "O",
297     "P",
298     "Q",
299     "R",
300     "S",
301     "T",
302     "U",
303     "V",
304     "W",
305     "X",
306     "Y",
307     "Z",
308     "bracketleft",
309     "backslash",
310     "bracketright",
311     "asciicircum",
312     "underscore",
313     "quoteleft",
314     "a",
315     "b",
316     "c",
317     "d",
318     "e",
319     "f",
320     "g",
321     "h",
322     "i",
323     "j",
324     "k",
325     "l",
326     "m",
327     "n",
328     "o",
329     "p",
330     "q",
331     "r",
332     "s",
333     "t",
334     "u",
335     "v",
336     "w",
337     "x",
338     "y",
339     "z",
340     "braceleft",
341     "bar",
342     "braceright",
343     "asciitilde",
344     nullptr,
345     nullptr,
346     nullptr,
347     nullptr,
348     nullptr,
349     nullptr,
350     nullptr,
351     nullptr,
352     nullptr,
353     nullptr,
354     nullptr,
355     nullptr,
356     nullptr,
357     nullptr,
358     nullptr,
359     nullptr,
360     nullptr,
361     nullptr,
362     nullptr,
363     nullptr,
364     nullptr,
365     nullptr,
366     nullptr,
367     nullptr,
368     nullptr,
369     nullptr,
370     nullptr,
371     nullptr,
372     nullptr,
373     nullptr,
374     nullptr,
375     nullptr,
376     nullptr,
377     nullptr,
378     "exclamdown",
379     "cent",
380     "sterling",
381     "fraction",
382     "yen",
383     "florin",
384     "section",
385     "currency",
386     "quotesingle",
387     "quotedblleft",
388     "guillemotleft",
389     "guilsinglleft",
390     "guilsinglright",
391     "fi",
392     "fl",
393     nullptr,
394     "endash",
395     "dagger",
396     "daggerdbl",
397     "periodcentered",
398     nullptr,
399     "paragraph",
400     "bullet",
401     "quotesinglbase",
402     "quotedblbase",
403     "quotedblright",
404     "guillemotright",
405     "ellipsis",
406     "perthousand",
407     nullptr,
408     "questiondown",
409     nullptr,
410     "grave",
411     "acute",
412     "circumflex",
413     "tilde",
414     "macron",
415     "breve",
416     "dotaccent",
417     "dieresis",
418     nullptr,
419     "ring",
420     "cedilla",
421     nullptr,
422     "hungarumlaut",
423     "ogonek",
424     "caron",
425     "emdash",
426     nullptr,
427     nullptr,
428     nullptr,
429     nullptr,
430     nullptr,
431     nullptr,
432     nullptr,
433     nullptr,
434     nullptr,
435     nullptr,
436     nullptr,
437     nullptr,
438     nullptr,
439     nullptr,
440     nullptr,
441     nullptr,
442     "AE",
443     nullptr,
444     "ordfeminine",
445     nullptr,
446     nullptr,
447     nullptr,
448     nullptr,
449     "Lslash",
450     "Oslash",
451     "OE",
452     "ordmasculine",
453     nullptr,
454     nullptr,
455     nullptr,
456     nullptr,
457     nullptr,
458     "ae",
459     nullptr,
460     nullptr,
461     nullptr,
462     "dotlessi",
463     nullptr,
464     nullptr,
465     "lslash",
466     "oslash",
467     "oe",
468     "germandbls",
469     nullptr,
470     nullptr,
471     nullptr,
472     nullptr,
473 };
474 
475 const char* const AdobeWinAnsiEncodingNames[kEncodingNamesTableSize] = {
476     "space",
477     "exclam",
478     "quotedbl",
479     "numbersign",
480     "dollar",
481     "percent",
482     "ampersand",
483     "quotesingle",
484     "parenleft",
485     "parenright",
486     "asterisk",
487     "plus",
488     "comma",
489     "hyphen",
490     "period",
491     "slash",
492     "zero",
493     "one",
494     "two",
495     "three",
496     "four",
497     "five",
498     "six",
499     "seven",
500     "eight",
501     "nine",
502     "colon",
503     "semicolon",
504     "less",
505     "equal",
506     "greater",
507     "question",
508     "at",
509     "A",
510     "B",
511     "C",
512     "D",
513     "E",
514     "F",
515     "G",
516     "H",
517     "I",
518     "J",
519     "K",
520     "L",
521     "M",
522     "N",
523     "O",
524     "P",
525     "Q",
526     "R",
527     "S",
528     "T",
529     "U",
530     "V",
531     "W",
532     "X",
533     "Y",
534     "Z",
535     "bracketleft",
536     "backslash",
537     "bracketright",
538     "asciicircum",
539     "underscore",
540     "grave",
541     "a",
542     "b",
543     "c",
544     "d",
545     "e",
546     "f",
547     "g",
548     "h",
549     "i",
550     "j",
551     "k",
552     "l",
553     "m",
554     "n",
555     "o",
556     "p",
557     "q",
558     "r",
559     "s",
560     "t",
561     "u",
562     "v",
563     "w",
564     "x",
565     "y",
566     "z",
567     "braceleft",
568     "bar",
569     "braceright",
570     "asciitilde",
571     "bullet",
572     "Euro",
573     "bullet",
574     "quotesinglbase",
575     "florin",
576     "quotedblbase",
577     "ellipsis",
578     "dagger",
579     "daggerdbl",
580     "circumflex",
581     "perthousand",
582     "Scaron",
583     "guilsinglleft",
584     "OE",
585     "bullet",
586     "Zcaron",
587     "bullet",
588     "bullet",
589     "quoteleft",
590     "quoteright",
591     "quotedblleft",
592     "quotedblright",
593     "bullet",
594     "endash",
595     "emdash",
596     "tilde",
597     "trademark",
598     "scaron",
599     "guilsinglright",
600     "oe",
601     "bullet",
602     "zcaron",
603     "Ydieresis",
604     "space",
605     "exclamdown",
606     "cent",
607     "sterling",
608     "currency",
609     "yen",
610     "brokenbar",
611     "section",
612     "dieresis",
613     "copyright",
614     "ordfeminine",
615     "guillemotleft",
616     "logicalnot",
617     "hyphen",
618     "registered",
619     "macron",
620     "degree",
621     "plusminus",
622     "twosuperior",
623     "threesuperior",
624     "acute",
625     "mu",
626     "paragraph",
627     "periodcentered",
628     "cedilla",
629     "onesuperior",
630     "ordmasculine",
631     "guillemotright",
632     "onequarter",
633     "onehalf",
634     "threequarters",
635     "questiondown",
636     "Agrave",
637     "Aacute",
638     "Acircumflex",
639     "Atilde",
640     "Adieresis",
641     "Aring",
642     "AE",
643     "Ccedilla",
644     "Egrave",
645     "Eacute",
646     "Ecircumflex",
647     "Edieresis",
648     "Igrave",
649     "Iacute",
650     "Icircumflex",
651     "Idieresis",
652     "Eth",
653     "Ntilde",
654     "Ograve",
655     "Oacute",
656     "Ocircumflex",
657     "Otilde",
658     "Odieresis",
659     "multiply",
660     "Oslash",
661     "Ugrave",
662     "Uacute",
663     "Ucircumflex",
664     "Udieresis",
665     "Yacute",
666     "Thorn",
667     "germandbls",
668     "agrave",
669     "aacute",
670     "acircumflex",
671     "atilde",
672     "adieresis",
673     "aring",
674     "ae",
675     "ccedilla",
676     "egrave",
677     "eacute",
678     "ecircumflex",
679     "edieresis",
680     "igrave",
681     "iacute",
682     "icircumflex",
683     "idieresis",
684     "eth",
685     "ntilde",
686     "ograve",
687     "oacute",
688     "ocircumflex",
689     "otilde",
690     "odieresis",
691     "divide",
692     "oslash",
693     "ugrave",
694     "uacute",
695     "ucircumflex",
696     "udieresis",
697     "yacute",
698     "thorn",
699     "ydieresis",
700 };
701 
702 const char* const MacRomanEncodingNames[kEncodingNamesTableSize] = {
703     "space",
704     "exclam",
705     "quotedbl",
706     "numbersign",
707     "dollar",
708     "percent",
709     "ampersand",
710     "quotesingle",
711     "parenleft",
712     "parenright",
713     "asterisk",
714     "plus",
715     "comma",
716     "hyphen",
717     "period",
718     "slash",
719     "zero",
720     "one",
721     "two",
722     "three",
723     "four",
724     "five",
725     "six",
726     "seven",
727     "eight",
728     "nine",
729     "colon",
730     "semicolon",
731     "less",
732     "equal",
733     "greater",
734     "question",
735     "at",
736     "A",
737     "B",
738     "C",
739     "D",
740     "E",
741     "F",
742     "G",
743     "H",
744     "I",
745     "J",
746     "K",
747     "L",
748     "M",
749     "N",
750     "O",
751     "P",
752     "Q",
753     "R",
754     "S",
755     "T",
756     "U",
757     "V",
758     "W",
759     "X",
760     "Y",
761     "Z",
762     "bracketleft",
763     "backslash",
764     "bracketright",
765     "asciicircum",
766     "underscore",
767     "grave",
768     "a",
769     "b",
770     "c",
771     "d",
772     "e",
773     "f",
774     "g",
775     "h",
776     "i",
777     "j",
778     "k",
779     "l",
780     "m",
781     "n",
782     "o",
783     "p",
784     "q",
785     "r",
786     "s",
787     "t",
788     "u",
789     "v",
790     "w",
791     "x",
792     "y",
793     "z",
794     "braceleft",
795     "bar",
796     "braceright",
797     "asciitilde",
798     nullptr,
799     "Adieresis",
800     "Aring",
801     "Ccedilla",
802     "Eacute",
803     "Ntilde",
804     "Odieresis",
805     "Udieresis",
806     "aacute",
807     "agrave",
808     "acircumflex",
809     "adieresis",
810     "atilde",
811     "aring",
812     "ccedilla",
813     "eacute",
814     "egrave",
815     "ecircumflex",
816     "edieresis",
817     "iacute",
818     "igrave",
819     "icircumflex",
820     "idieresis",
821     "ntilde",
822     "oacute",
823     "ograve",
824     "ocircumflex",
825     "odieresis",
826     "otilde",
827     "uacute",
828     "ugrave",
829     "ucircumflex",
830     "udieresis",
831     "dagger",
832     "degree",
833     "cent",
834     "sterling",
835     "section",
836     "bullet",
837     "paragraph",
838     "germandbls",
839     "registered",
840     "copyright",
841     "trademark",
842     "acute",
843     "dieresis",
844     "notequal",
845     "AE",
846     "Oslash",
847     "infinity",
848     "plusminus",
849     "lessequal",
850     "greaterequal",
851     "yen",
852     "mu",
853     "partialdiff",
854     "summation",
855     "product",
856     "pi",
857     "integral",
858     "ordfeminine",
859     "ordmasculine",
860     "Omega",
861     "ae",
862     "oslash",
863     "questiondown",
864     "exclamdown",
865     "logicalnot",
866     "radical",
867     "florin",
868     "approxequal",
869     "Delta",
870     "guillemotleft",
871     "guillemotright",
872     "ellipsis",
873     "space",
874     "Agrave",
875     "Atilde",
876     "Otilde",
877     "OE",
878     "oe",
879     "endash",
880     "emdash",
881     "quotedblleft",
882     "quotedblright",
883     "quoteleft",
884     "quoteright",
885     "divide",
886     "lozenge",
887     "ydieresis",
888     "Ydieresis",
889     "fraction",
890     "currency",
891     "guilsinglleft",
892     "guilsinglright",
893     "fi",
894     "fl",
895     "daggerdbl",
896     "periodcentered",
897     "quotesinglbase",
898     "quotedblbase",
899     "perthousand",
900     "Acircumflex",
901     "Ecircumflex",
902     "Aacute",
903     "Edieresis",
904     "Egrave",
905     "Iacute",
906     "Icircumflex",
907     "Idieresis",
908     "Igrave",
909     "Oacute",
910     "Ocircumflex",
911     "apple",
912     "Ograve",
913     "Uacute",
914     "Ucircumflex",
915     "Ugrave",
916     "dotlessi",
917     "circumflex",
918     "tilde",
919     "macron",
920     "breve",
921     "dotaccent",
922     "ring",
923     "cedilla",
924     "hungarumlaut",
925     "ogonek",
926     "caron",
927 };
928 
929 const char* const MacExpertEncodingNames[kEncodingNamesTableSize] = {
930     "space",
931     "exclamsmall",
932     "Hungarumlautsmall",
933     "centoldstyle",
934     "dollaroldstyle",
935     "dollarsuperior",
936     "ampersandsmall",
937     "Acutesmall",
938     "parenleftsuperior",
939     "parenrightsuperior",
940     "twodotenleader",
941     "onedotenleader",
942     "comma",
943     "hyphen",
944     "period",
945     "fraction",
946     "zerooldstyle",
947     "oneoldstyle",
948     "twooldstyle",
949     "threeoldstyle",
950     "fouroldstyle",
951     "fiveoldstyle",
952     "sixoldstyle",
953     "sevenoldstyle",
954     "eightoldstyle",
955     "nineoldstyle",
956     "colon",
957     "semicolon",
958     nullptr,
959     "threequartersemdash",
960     nullptr,
961     "questionsmall",
962     nullptr,
963     nullptr,
964     nullptr,
965     nullptr,
966     "Ethsmall",
967     nullptr,
968     nullptr,
969     "onequarter",
970     "onehalf",
971     "threequarters",
972     "oneeighth",
973     "threeeighths",
974     "fiveeighths",
975     "seveneighths",
976     "onethird",
977     "twothirds",
978     nullptr,
979     nullptr,
980     nullptr,
981     nullptr,
982     nullptr,
983     nullptr,
984     "ff",
985     "fi",
986     "fl",
987     "ffi",
988     "ffl",
989     "parenleftinferior",
990     nullptr,
991     "parenrightinferior",
992     "Circumflexsmall",
993     "hypheninferior",
994     "Gravesmall",
995     "Asmall",
996     "Bsmall",
997     "Csmall",
998     "Dsmall",
999     "Esmall",
1000     "Fsmall",
1001     "Gsmall",
1002     "Hsmall",
1003     "Ismall",
1004     "Jsmall",
1005     "Ksmall",
1006     "Lsmall",
1007     "Msmall",
1008     "Nsmall",
1009     "Osmall",
1010     "Psmall",
1011     "Qsmall",
1012     "Rsmall",
1013     "Ssmall",
1014     "Tsmall",
1015     "Usmall",
1016     "Vsmall",
1017     "Wsmall",
1018     "Xsmall",
1019     "Ysmall",
1020     "Zsmall",
1021     "colonmonetary",
1022     "onefitted",
1023     "rupiah",
1024     "Tildesmall",
1025     nullptr,
1026     nullptr,
1027     "asuperior",
1028     "centsuperior",
1029     nullptr,
1030     nullptr,
1031     nullptr,
1032     nullptr,
1033     "Aacutesmall",
1034     "Agravesmall",
1035     "Acircumflexsmall",
1036     "Adieresissmall",
1037     "Atildesmall",
1038     "Aringsmall",
1039     "Ccedillasmall",
1040     "Eacutesmall",
1041     "Egravesmall",
1042     "Ecircumflexsmall",
1043     "Edieresissmall",
1044     "Iacutesmall",
1045     "Igravesmall",
1046     "Icircumflexsmall",
1047     "Idieresissmall",
1048     "Ntildesmall",
1049     "Oacutesmall",
1050     "Ogravesmall",
1051     "Ocircumflexsmall",
1052     "Odieresissmall",
1053     "Otildesmall",
1054     "Uacutesmall",
1055     "Ugravesmall",
1056     "Ucircumflexsmall",
1057     "Udieresissmall",
1058     nullptr,
1059     "eightsuperior",
1060     "fourinferior",
1061     "threeinferior",
1062     "sixinferior",
1063     "eightinferior",
1064     "seveninferior",
1065     "Scaronsmall",
1066     nullptr,
1067     "centinferior",
1068     "twoinferior",
1069     nullptr,
1070     "Dieresissmall",
1071     nullptr,
1072     "Caronsmall",
1073     "Scaronsmall",
1074     "fiveinferior",
1075     nullptr,
1076     "commainferior",
1077     "periodinferior",
1078     "Yacutesmall",
1079     nullptr,
1080     "dollarinferior",
1081     nullptr,
1082     nullptr,
1083     "Thornsmall",
1084     nullptr,
1085     "nineinferior",
1086     "zeroinferior",
1087     "Zcaronsmall",
1088     "AEsmall",
1089     "Oslashsmall",
1090     "questiondownsmall",
1091     "oneinferior",
1092     "asuperior",
1093     nullptr,
1094     nullptr,
1095     nullptr,
1096     nullptr,
1097     nullptr,
1098     nullptr,
1099     "Cedillasmall",
1100     nullptr,
1101     nullptr,
1102     nullptr,
1103     nullptr,
1104     nullptr,
1105     "OEsmall",
1106     "figuredash",
1107     "hyphensuperior",
1108     nullptr,
1109     nullptr,
1110     nullptr,
1111     nullptr,
1112     "exclamdownsmall",
1113     nullptr,
1114     "Ydieresissmall",
1115     nullptr,
1116     "onesuperior",
1117     "twosuperior",
1118     "threesuperior",
1119     "foursuperior",
1120     "fivesuperior",
1121     "sixsuperior",
1122     "sevensuperior",
1123     "ninesuperior",
1124     "zerosuperior",
1125     nullptr,
1126     "esuperior",
1127     "rsuperior",
1128     nullptr,
1129     nullptr,
1130     nullptr,
1131     "isuperior",
1132     "ssuperior",
1133     "dsuperior",
1134     nullptr,
1135     nullptr,
1136     nullptr,
1137     nullptr,
1138     nullptr,
1139     "lsuperior",
1140     "Ogoneksmall",
1141     "Brevesmall",
1142     "Macronsmall",
1143     "bsuperior",
1144     "nsuperior",
1145     "msuperior",
1146     "commasuperior",
1147     "periodsuperior",
1148     "Dotaccentsmall",
1149     "Ringsmall",
1150     nullptr,
1151     nullptr,
1152     nullptr,
1153     nullptr,
1154 };
1155 
1156 const char* const PDFDocEncodingNames[kPDFDocEncodingNamesTableSize] = {
1157     "breve",
1158     "caron",
1159     "circumflex",
1160     "dotaccent",
1161     "hungarumlaut",
1162     "ogonek",
1163     "ring",
1164     "tilde",
1165     "space",
1166     "exclam",
1167     "quotedbl",
1168     "numbersign",
1169     "dollar",
1170     "percent",
1171     "ampersand",
1172     "quotesingle",
1173     "parenleft",
1174     "parenright",
1175     "asterisk",
1176     "plus",
1177     "comma",
1178     "hyphen",
1179     "period",
1180     "slash",
1181     "zero",
1182     "one",
1183     "two",
1184     "three",
1185     "four",
1186     "five",
1187     "six",
1188     "seven",
1189     "eight",
1190     "nine",
1191     "colon",
1192     "semicolon",
1193     "less",
1194     "equal",
1195     "greater",
1196     "question",
1197     "at",
1198     "A",
1199     "B",
1200     "C",
1201     "D",
1202     "E",
1203     "F",
1204     "G",
1205     "H",
1206     "I",
1207     "J",
1208     "K",
1209     "L",
1210     "M",
1211     "N",
1212     "O",
1213     "P",
1214     "Q",
1215     "R",
1216     "S",
1217     "T",
1218     "U",
1219     "V",
1220     "W",
1221     "X",
1222     "Y",
1223     "Z",
1224     "bracketleft",
1225     "backslash",
1226     "bracketright",
1227     "asciicircum",
1228     "underscore",
1229     "grave",
1230     "a",
1231     "b",
1232     "c",
1233     "d",
1234     "e",
1235     "f",
1236     "g",
1237     "h",
1238     "i",
1239     "j",
1240     "k",
1241     "l",
1242     "m",
1243     "n",
1244     "o",
1245     "p",
1246     "q",
1247     "r",
1248     "s",
1249     "t",
1250     "u",
1251     "v",
1252     "w",
1253     "x",
1254     "y",
1255     "z",
1256     "braceleft",
1257     "bar",
1258     "braceright",
1259     "asciitilde",
1260     nullptr,
1261     "bullet3",
1262     "dagger",
1263     "daggerdbl",
1264     "ellipsis",
1265     "emdash",
1266     "endash",
1267     "florin",
1268     "fraction",
1269     "guilsinglleft",
1270     "guilsinglright",
1271     "minus",
1272     "perthousand",
1273     "quotedblbase",
1274     "quotedblleft",
1275     "quotedblright",
1276     "quoteleft",
1277     "quoteright",
1278     "quotesinglbase",
1279     "trademark",
1280     "fi",
1281     "fl",
1282     "Lslash",
1283     "OE",
1284     "Scaron",
1285     "Ydieresis",
1286     "Zcaron2",
1287     "dotlessi",
1288     "lslash",
1289     "oe",
1290     "scaron",
1291     "zcaron2",
1292     nullptr,
1293     "Euro",
1294     "exclamdown",
1295     "cent",
1296     "sterling",
1297     "currency",
1298     "yen",
1299     "brokenbar",
1300     "section",
1301     "dieresis",
1302     "copyright",
1303     "ordfeminine",
1304     "guillemotleft4",
1305     "logicalnot",
1306     nullptr,
1307     "registered",
1308     "macron",
1309     "degree",
1310     "plusminus",
1311     "twosuperior",
1312     "threesuperior",
1313     "acute",
1314     "mu",
1315     "paragraph",
1316     "periodcentered",
1317     "cedilla",
1318     "onesuperior",
1319     "ordmasculine",
1320     "guillemotright4",
1321     "onequarter",
1322     "onehalf",
1323     "threequarters",
1324     "questiondown",
1325     "Agrave",
1326     "Aacute",
1327     "Acircumflex",
1328     "Atilde",
1329     "Adieresis",
1330     "Aring",
1331     "AE",
1332     "Ccedilla",
1333     "Egrave",
1334     "Eacute",
1335     "Ecircumflex",
1336     "Edieresis",
1337     "Igrave",
1338     "Iacute",
1339     "Icircumflex",
1340     "Idieresis",
1341     "Eth",
1342     "Ntilde",
1343     "Ograve",
1344     "Oacute",
1345     "Ocircumflex",
1346     "Otilde",
1347     "Odieresis",
1348     "multiply",
1349     "Oslash",
1350     "Ugrave",
1351     "Uacute",
1352     "Ucircumflex",
1353     "Udieresis",
1354     "Yacute",
1355     "Thorn",
1356     "germandbls",
1357     "agrave",
1358     "aacute",
1359     "acircumflex",
1360     "atilde",
1361     "adieresis",
1362     "aring",
1363     "ae",
1364     "ccedilla",
1365     "egrave",
1366     "eacute",
1367     "ecircumflex",
1368     "edieresis",
1369     "igrave",
1370     "iacute",
1371     "icircumflex",
1372     "idieresis",
1373     "eth",
1374     "ntilde",
1375     "ograve",
1376     "oacute",
1377     "ocircumflex",
1378     "otilde",
1379     "odieresis",
1380     "divide",
1381     "oslash",
1382     "ugrave",
1383     "uacute",
1384     "ucircumflex",
1385     "udieresis",
1386     "yacute",
1387     "thorn",
1388     "ydieresis",
1389 };
1390 
1391 const char* const AdobeSymbolEncodingNames[kEncodingNamesTableSize] = {
1392     "space",
1393     "exclam",
1394     "universal",
1395     "numbersign",
1396     "existential",
1397     "percent",
1398     "ampersand",
1399     "suchthat",
1400     "parenleft",
1401     "parenright",
1402     "asteriskmath",
1403     "plus",
1404     "comma",
1405     "minus",
1406     "period",
1407     "slash",
1408     "zero",
1409     "one",
1410     "two",
1411     "three",
1412     "four",
1413     "five",
1414     "six",
1415     "seven",
1416     "eight",
1417     "nine",
1418     "colon",
1419     "semicolon",
1420     "less",
1421     "equal",
1422     "greater",
1423     "question",
1424     "congruent",
1425     "Alpha",
1426     "Beta",
1427     "Chi",
1428     "Delta",
1429     "Epsilon",
1430     "Phi",
1431     "Gamma",
1432     "Eta",
1433     "Iota",
1434     "theta1",
1435     "Kappa",
1436     "Lambda",
1437     "Mu",
1438     "Nu",
1439     "Omicron",
1440     "Pi",
1441     "Theta",
1442     "Rho",
1443     "Sigma",
1444     "Tau",
1445     "Upsilon",
1446     "sigma1",
1447     "Omega",
1448     "Xi",
1449     "Psi",
1450     "Zeta",
1451     "bracketleft",
1452     "therefore",
1453     "bracketright",
1454     "perpendicular",
1455     "underscore",
1456     "radicalex",
1457     "alpha",
1458     "beta",
1459     "chi",
1460     "delta",
1461     "epsilon",
1462     "phi",
1463     "gamma",
1464     "eta",
1465     "iota",
1466     "phi1",
1467     "kappa",
1468     "lambda",
1469     "mu",
1470     "nu",
1471     "omicron",
1472     "pi",
1473     "theta",
1474     "rho",
1475     "sigma",
1476     "tau",
1477     "upsilon",
1478     "omega1",
1479     "omega",
1480     "xi",
1481     "psi",
1482     "zeta",
1483     "braceleft",
1484     "bar",
1485     "braceright",
1486     "similar",
1487     nullptr,
1488     nullptr,
1489     nullptr,
1490     nullptr,
1491     nullptr,
1492     nullptr,
1493     nullptr,
1494     nullptr,
1495     nullptr,
1496     nullptr,
1497     nullptr,
1498     nullptr,
1499     nullptr,
1500     nullptr,
1501     nullptr,
1502     nullptr,
1503     nullptr,
1504     nullptr,
1505     nullptr,
1506     nullptr,
1507     nullptr,
1508     nullptr,
1509     nullptr,
1510     nullptr,
1511     nullptr,
1512     nullptr,
1513     nullptr,
1514     nullptr,
1515     nullptr,
1516     nullptr,
1517     nullptr,
1518     nullptr,
1519     nullptr,
1520     "Euro",
1521     "Upsilon1",
1522     "minute",
1523     "lessequal",
1524     "fraction",
1525     "infinity",
1526     "florin",
1527     "club",
1528     "diamond",
1529     "heart",
1530     "spade",
1531     "arrowboth",
1532     "arrowleft",
1533     "arrowup",
1534     "arrowright",
1535     "arrowdown",
1536     "degree",
1537     "plusminus",
1538     "second",
1539     "greaterequal",
1540     "multiply",
1541     "proportional",
1542     "partialdiff",
1543     "bullet",
1544     "divide",
1545     "notequal",
1546     "equivalence",
1547     "approxequal",
1548     "ellipsis",
1549     "arrowvertex",
1550     "arrowhorizex",
1551     "carriagereturn",
1552     "aleph",
1553     "Ifraktur",
1554     "Rfraktur",
1555     "weierstrass",
1556     "circlemultiply",
1557     "circleplus",
1558     "emptyset",
1559     "intersection",
1560     "union",
1561     "propersuperset",
1562     "reflexsuperset",
1563     "notsubset",
1564     "propersubset",
1565     "reflexsubset",
1566     "element",
1567     "notelement",
1568     "angle",
1569     "gradient",
1570     "registerserif",
1571     "copyrightserif",
1572     "trademarkserif",
1573     "product",
1574     "radical",
1575     "dotmath",
1576     "logicalnot",
1577     "logicaland",
1578     "logicalor",
1579     "arrowdblboth",
1580     "arrowdblleft",
1581     "arrowdblup",
1582     "arrowdblright",
1583     "arrowdbldown",
1584     "lozenge",
1585     "angleleft",
1586     "registersans",
1587     "copyrightsans",
1588     "trademarksans",
1589     "summation",
1590     "parenlefttp",
1591     "parenleftex",
1592     "parenleftbt",
1593     "bracketlefttp",
1594     "bracketleftex",
1595     "bracketleftbt",
1596     "bracelefttp",
1597     "braceleftmid",
1598     "braceleftbt",
1599     "braceex",
1600     nullptr,
1601     "angleright",
1602     "integral",
1603     "integraltp",
1604     "integralex",
1605     "integralbt",
1606     "parenrighttp",
1607     "parenrightex",
1608     "parenrightbt",
1609     "bracketrighttp",
1610     "bracketrightex",
1611     "bracketrightbt",
1612     "bracerighttp",
1613     "bracerightmid",
1614     "bracerightbt",
1615     nullptr,
1616 };
1617 
1618 const char* const ZapfEncodingNames[kEncodingNamesTableSize] = {
1619     "space", "a1",    "a2",    "a202",  "a3",    "a4",    "a5",    "a119",
1620     "a118",  "a117",  "a11",   "a12",   "a13",   "a14",   "a15",   "a16",
1621     "a105",  "a17",   "a18",   "a19",   "a20",   "a21",   "a22",   "a23",
1622     "a24",   "a25",   "a26",   "a27",   "a28",   "a6",    "a7",    "a8",
1623     "a9",    "a10",   "a29",   "a30",   "a31",   "a32",   "a33",   "a34",
1624     "a35",   "a36",   "a37",   "a38",   "a39",   "a40",   "a41",   "a42",
1625     "a43",   "a44",   "a45",   "a46",   "a47",   "a48",   "a49",   "a50",
1626     "a51",   "a52",   "a53",   "a54",   "a55",   "a56",   "a57",   "a58",
1627     "a59",   "a60",   "a61",   "a62",   "a63",   "a64",   "a65",   "a66",
1628     "a67",   "a68",   "a69",   "a70",   "a71",   "a72",   "a73",   "a74",
1629     "a203",  "a75",   "a204",  "a76",   "a77",   "a78",   "a79",   "a81",
1630     "a82",   "a83",   "a84",   "a97",   "a98",   "a99",   "a100",  nullptr,
1631     "a89",   "a90",   "a93",   "a94",   "a91",   "a92",   "a205",  "a85",
1632     "a206",  "a86",   "a87",   "a88",   "a95",   "a96",   nullptr, nullptr,
1633     nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
1634     nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
1635     nullptr, "a101",  "a102",  "a103",  "a104",  "a106",  "a107",  "a108",
1636     "a112",  "a111",  "a110",  "a109",  "a120",  "a121",  "a122",  "a123",
1637     "a124",  "a125",  "a126",  "a127",  "a128",  "a129",  "a130",  "a131",
1638     "a132",  "a133",  "a134",  "a135",  "a136",  "a137",  "a138",  "a139",
1639     "a140",  "a141",  "a142",  "a143",  "a144",  "a145",  "a146",  "a147",
1640     "a148",  "a149",  "a150",  "a151",  "a152",  "a153",  "a154",  "a155",
1641     "a156",  "a157",  "a158",  "a159",  "a160",  "a161",  "a163",  "a164",
1642     "a196",  "a165",  "a192",  "a166",  "a167",  "a168",  "a169",  "a170",
1643     "a171",  "a172",  "a173",  "a162",  "a174",  "a175",  "a176",  "a177",
1644     "a178",  "a179",  "a193",  "a180",  "a199",  "a181",  "a200",  "a182",
1645     nullptr, "a201",  "a183",  "a184",  "a197",  "a185",  "a194",  "a198",
1646     "a186",  "a195",  "a187",  "a188",  "a189",  "a190",  "a191",  nullptr};
1647 
PDF_FindCode(const uint16_t * pCodes,uint16_t unicode)1648 uint32_t PDF_FindCode(const uint16_t* pCodes, uint16_t unicode) {
1649   for (size_t i = 0; i < CPDF_FontEncoding::kEncodingTableSize; i++) {
1650     if (pCodes[i] == unicode)
1651       return i;
1652   }
1653   return 0;
1654 }
1655 
1656 }  // namespace
1657 
CharCodeFromUnicode(wchar_t unicode) const1658 int CPDF_FontEncoding::CharCodeFromUnicode(wchar_t unicode) const {
1659   for (size_t i = 0; i < FX_ArraySize(m_Unicodes); i++) {
1660     if (m_Unicodes[i] == unicode)
1661       return i;
1662   }
1663   return -1;
1664 }
1665 
CPDF_FontEncoding(int PredefinedEncoding)1666 CPDF_FontEncoding::CPDF_FontEncoding(int PredefinedEncoding) {
1667   const uint16_t* pSrc = PDF_UnicodesForPredefinedCharSet(PredefinedEncoding);
1668   if (pSrc) {
1669     for (size_t i = 0; i < FX_ArraySize(m_Unicodes); i++)
1670       m_Unicodes[i] = pSrc[i];
1671   } else {
1672     memset(m_Unicodes, 0, sizeof(m_Unicodes));
1673   }
1674 }
1675 
IsIdentical(const CPDF_FontEncoding * pAnother) const1676 bool CPDF_FontEncoding::IsIdentical(const CPDF_FontEncoding* pAnother) const {
1677   return memcmp(m_Unicodes, pAnother->m_Unicodes, sizeof(m_Unicodes)) == 0;
1678 }
1679 
Realize(WeakPtr<ByteStringPool> pPool) const1680 RetainPtr<CPDF_Object> CPDF_FontEncoding::Realize(
1681     WeakPtr<ByteStringPool> pPool) const {
1682   int predefined = 0;
1683   for (int cs = PDFFONT_ENCODING_WINANSI; cs < PDFFONT_ENCODING_ZAPFDINGBATS;
1684        cs++) {
1685     const uint16_t* pSrc = PDF_UnicodesForPredefinedCharSet(cs);
1686     bool match = true;
1687     for (size_t i = 0; i < FX_ArraySize(m_Unicodes); i++) {
1688       if (m_Unicodes[i] != pSrc[i]) {
1689         match = false;
1690         break;
1691       }
1692     }
1693     if (match) {
1694       predefined = cs;
1695       break;
1696     }
1697   }
1698   if (predefined) {
1699     const char* pName;
1700     if (predefined == PDFFONT_ENCODING_WINANSI)
1701       pName = "WinAnsiEncoding";
1702     else if (predefined == PDFFONT_ENCODING_MACROMAN)
1703       pName = "MacRomanEncoding";
1704     else if (predefined == PDFFONT_ENCODING_MACEXPERT)
1705       pName = "MacExpertEncoding";
1706     else
1707       return nullptr;
1708 
1709     return pdfium::MakeRetain<CPDF_Name>(pPool, pName);
1710   }
1711   const uint16_t* pStandard =
1712       PDF_UnicodesForPredefinedCharSet(PDFFONT_ENCODING_WINANSI);
1713   auto pDiff = pdfium::MakeRetain<CPDF_Array>();
1714   for (size_t i = 0; i < FX_ArraySize(m_Unicodes); i++) {
1715     if (pStandard[i] == m_Unicodes[i])
1716       continue;
1717 
1718     pDiff->AddNew<CPDF_Number>(static_cast<int>(i));
1719     pDiff->AddNew<CPDF_Name>(PDF_AdobeNameFromUnicode(m_Unicodes[i]));
1720   }
1721 
1722   auto pDict = pdfium::MakeRetain<CPDF_Dictionary>(pPool);
1723   pDict->SetNewFor<CPDF_Name>("BaseEncoding", "WinAnsiEncoding");
1724   pDict->SetFor("Differences", pDiff);
1725   return pDict;
1726 }
1727 
FT_CharCodeFromUnicode(int encoding,wchar_t unicode)1728 uint32_t FT_CharCodeFromUnicode(int encoding, wchar_t unicode) {
1729   switch (encoding) {
1730     case FT_ENCODING_UNICODE:
1731       return unicode;
1732     case FT_ENCODING_ADOBE_STANDARD:
1733       return PDF_FindCode(StandardEncoding, unicode);
1734     case FT_ENCODING_ADOBE_EXPERT:
1735       return PDF_FindCode(MacExpertEncoding, unicode);
1736     case FT_ENCODING_ADOBE_LATIN_1:
1737       return PDF_FindCode(AdobeWinAnsiEncoding, unicode);
1738     case FT_ENCODING_APPLE_ROMAN:
1739       return PDF_FindCode(MacRomanEncoding, unicode);
1740     case FT_ENCODING_ADOBE_CUSTOM:
1741       return PDF_FindCode(PDFDocEncoding, unicode);
1742     case FT_ENCODING_MS_SYMBOL:
1743       return PDF_FindCode(MSSymbolEncoding, unicode);
1744   }
1745   return 0;
1746 }
PDF_UnicodesForPredefinedCharSet(int encoding)1747 const uint16_t* PDF_UnicodesForPredefinedCharSet(int encoding) {
1748   switch (encoding) {
1749     case PDFFONT_ENCODING_WINANSI:
1750       return AdobeWinAnsiEncoding;
1751     case PDFFONT_ENCODING_MACROMAN:
1752       return MacRomanEncoding;
1753     case PDFFONT_ENCODING_MACEXPERT:
1754       return MacExpertEncoding;
1755     case PDFFONT_ENCODING_STANDARD:
1756       return StandardEncoding;
1757     case PDFFONT_ENCODING_ADOBE_SYMBOL:
1758       return AdobeSymbolEncoding;
1759     case PDFFONT_ENCODING_ZAPFDINGBATS:
1760       return ZapfEncoding;
1761     case PDFFONT_ENCODING_PDFDOC:
1762       return PDFDocEncoding;
1763     case PDFFONT_ENCODING_MS_SYMBOL:
1764       return MSSymbolEncoding;
1765   }
1766   return nullptr;
1767 }
1768 
PDF_CharNameFromPredefinedCharSet(int encoding,uint8_t charcode)1769 const char* PDF_CharNameFromPredefinedCharSet(int encoding, uint8_t charcode) {
1770   if (encoding == PDFFONT_ENCODING_PDFDOC) {
1771     if (charcode < kPDFDocEncodingTableFirstChar)
1772       return nullptr;
1773 
1774     charcode -= kPDFDocEncodingTableFirstChar;
1775   } else {
1776     if (charcode < kEncodingTableFirstChar)
1777       return nullptr;
1778 
1779     charcode -= kEncodingTableFirstChar;
1780   }
1781   switch (encoding) {
1782     case PDFFONT_ENCODING_WINANSI:
1783       return AdobeWinAnsiEncodingNames[charcode];
1784     case PDFFONT_ENCODING_MACROMAN:
1785       return MacRomanEncodingNames[charcode];
1786     case PDFFONT_ENCODING_MACEXPERT:
1787       return MacExpertEncodingNames[charcode];
1788     case PDFFONT_ENCODING_STANDARD:
1789       return StandardEncodingNames[charcode];
1790     case PDFFONT_ENCODING_ADOBE_SYMBOL:
1791       return AdobeSymbolEncodingNames[charcode];
1792     case PDFFONT_ENCODING_ZAPFDINGBATS:
1793       return ZapfEncodingNames[charcode];
1794     case PDFFONT_ENCODING_PDFDOC:
1795       return PDFDocEncodingNames[charcode];
1796   }
1797   return nullptr;
1798 }
1799 
FT_UnicodeFromCharCode(int encoding,uint32_t charcode)1800 wchar_t FT_UnicodeFromCharCode(int encoding, uint32_t charcode) {
1801   switch (encoding) {
1802     case FT_ENCODING_UNICODE:
1803       return (uint16_t)charcode;
1804     case FT_ENCODING_ADOBE_STANDARD:
1805       return StandardEncoding[(uint8_t)charcode];
1806     case FT_ENCODING_ADOBE_EXPERT:
1807       return MacExpertEncoding[(uint8_t)charcode];
1808     case FT_ENCODING_ADOBE_LATIN_1:
1809       return AdobeWinAnsiEncoding[(uint8_t)charcode];
1810     case FT_ENCODING_APPLE_ROMAN:
1811       return MacRomanEncoding[(uint8_t)charcode];
1812     case PDFFONT_ENCODING_PDFDOC:
1813       return PDFDocEncoding[(uint8_t)charcode];
1814   }
1815   return 0;
1816 }
1817