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