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