Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Side by Side Diff: core/fpdfapi/fpdf_font/cpdf_truetypefont.cpp

Issue 2248453002: Use a std::vector in fpdf_font code. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: nits Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/fpdfapi/fpdf_font/cpdf_simplefont.cpp ('k') | core/fpdfapi/fpdf_font/cpdf_type1font.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "core/fpdfapi/fpdf_font/cpdf_truetypefont.h" 7 #include "core/fpdfapi/fpdf_font/cpdf_truetypefont.h"
8 8
9 #include "core/fpdfapi/fpdf_font/font_int.h" 9 #include "core/fpdfapi/fpdf_font/font_int.h"
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h"
11 #include "core/fxge/include/fx_font.h" 11 #include "core/fxge/include/fx_font.h"
12 12
13 namespace {
14
15 const uint8_t kPrefix[4] = {0x00, 0xf0, 0xf1, 0xf2};
16
17 } // namespace
18
13 CPDF_TrueTypeFont::CPDF_TrueTypeFont() {} 19 CPDF_TrueTypeFont::CPDF_TrueTypeFont() {}
14 20
15 bool CPDF_TrueTypeFont::IsTrueTypeFont() const { 21 bool CPDF_TrueTypeFont::IsTrueTypeFont() const {
16 return true; 22 return true;
17 } 23 }
18 24
19 const CPDF_TrueTypeFont* CPDF_TrueTypeFont::AsTrueTypeFont() const { 25 const CPDF_TrueTypeFont* CPDF_TrueTypeFont::AsTrueTypeFont() const {
20 return this; 26 return this;
21 } 27 }
22 28
(...skipping 28 matching lines...) Expand all
51 if (baseEncoding == PDFFONT_ENCODING_WINANSI && !bSupportWin) { 57 if (baseEncoding == PDFFONT_ENCODING_WINANSI && !bSupportWin) {
52 baseEncoding = 58 baseEncoding =
53 bSupportMac ? PDFFONT_ENCODING_MACROMAN : PDFFONT_ENCODING_BUILTIN; 59 bSupportMac ? PDFFONT_ENCODING_MACROMAN : PDFFONT_ENCODING_BUILTIN;
54 } else if (baseEncoding == PDFFONT_ENCODING_MACROMAN && !bSupportMac) { 60 } else if (baseEncoding == PDFFONT_ENCODING_MACROMAN && !bSupportMac) {
55 baseEncoding = 61 baseEncoding =
56 bSupportWin ? PDFFONT_ENCODING_WINANSI : PDFFONT_ENCODING_BUILTIN; 62 bSupportWin ? PDFFONT_ENCODING_WINANSI : PDFFONT_ENCODING_BUILTIN;
57 } 63 }
58 } 64 }
59 if (((baseEncoding == PDFFONT_ENCODING_MACROMAN || 65 if (((baseEncoding == PDFFONT_ENCODING_MACROMAN ||
60 baseEncoding == PDFFONT_ENCODING_WINANSI) && 66 baseEncoding == PDFFONT_ENCODING_WINANSI) &&
61 !m_pCharNames) || 67 m_CharNames.empty()) ||
62 (m_Flags & PDFFONT_NONSYMBOLIC)) { 68 (m_Flags & PDFFONT_NONSYMBOLIC)) {
63 if (!FXFT_Has_Glyph_Names(m_Font.GetFace()) && 69 if (!FXFT_Has_Glyph_Names(m_Font.GetFace()) &&
64 (!m_Font.GetFace()->num_charmaps || !m_Font.GetFace()->charmaps)) { 70 (!m_Font.GetFace()->num_charmaps || !m_Font.GetFace()->charmaps)) {
65 int nStartChar = m_pFontDict->GetIntegerBy("FirstChar"); 71 int nStartChar = m_pFontDict->GetIntegerBy("FirstChar");
66 if (nStartChar < 0 || nStartChar > 255) 72 if (nStartChar < 0 || nStartChar > 255)
67 return; 73 return;
68 74
69 int charcode = 0; 75 int charcode = 0;
70 for (; charcode < nStartChar; charcode++) { 76 for (; charcode < nStartChar; charcode++) {
71 m_GlyphIndex[charcode] = 0; 77 m_GlyphIndex[charcode] = 0;
72 } 78 }
73 uint16_t nGlyph = charcode - nStartChar + 3; 79 uint16_t nGlyph = charcode - nStartChar + 3;
74 for (; charcode < 256; charcode++, nGlyph++) { 80 for (; charcode < 256; charcode++, nGlyph++) {
75 m_GlyphIndex[charcode] = nGlyph; 81 m_GlyphIndex[charcode] = nGlyph;
76 } 82 }
77 return; 83 return;
78 } 84 }
79 FX_BOOL bMSUnicode = FT_UseTTCharmap(m_Font.GetFace(), 3, 1); 85 bool bMSUnicode = FT_UseTTCharmap(m_Font.GetFace(), 3, 1);
80 FX_BOOL bMacRoman = FALSE, bMSSymbol = FALSE; 86 bool bMacRoman = false;
87 bool bMSSymbol = false;
81 if (!bMSUnicode) { 88 if (!bMSUnicode) {
82 if (m_Flags & PDFFONT_NONSYMBOLIC) { 89 if (m_Flags & PDFFONT_NONSYMBOLIC) {
83 bMacRoman = FT_UseTTCharmap(m_Font.GetFace(), 1, 0); 90 bMacRoman = FT_UseTTCharmap(m_Font.GetFace(), 1, 0);
84 bMSSymbol = !bMacRoman && FT_UseTTCharmap(m_Font.GetFace(), 3, 0); 91 bMSSymbol = !bMacRoman && FT_UseTTCharmap(m_Font.GetFace(), 3, 0);
85 } else { 92 } else {
86 bMSSymbol = FT_UseTTCharmap(m_Font.GetFace(), 3, 0); 93 bMSSymbol = FT_UseTTCharmap(m_Font.GetFace(), 3, 0);
87 bMacRoman = !bMSSymbol && FT_UseTTCharmap(m_Font.GetFace(), 1, 0); 94 bMacRoman = !bMSSymbol && FT_UseTTCharmap(m_Font.GetFace(), 1, 0);
88 } 95 }
89 } 96 }
90 FX_BOOL bToUnicode = m_pFontDict->KeyExist("ToUnicode"); 97 FX_BOOL bToUnicode = m_pFontDict->KeyExist("ToUnicode");
91 for (int charcode = 0; charcode < 256; charcode++) { 98 for (int charcode = 0; charcode < 256; charcode++) {
92 const FX_CHAR* name = 99 const FX_CHAR* name =
93 GetAdobeCharName(baseEncoding, m_pCharNames, charcode); 100 GetAdobeCharName(baseEncoding, m_CharNames, charcode);
94 if (!name) { 101 if (!name) {
95 m_GlyphIndex[charcode] = 102 m_GlyphIndex[charcode] =
96 m_pFontFile ? FXFT_Get_Char_Index(m_Font.GetFace(), charcode) : -1; 103 m_pFontFile ? FXFT_Get_Char_Index(m_Font.GetFace(), charcode) : -1;
97 continue; 104 continue;
98 } 105 }
99 m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name); 106 m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name);
100 if (bMSSymbol) { 107 if (bMSSymbol) {
101 const uint8_t prefix[4] = {0x00, 0xf0, 0xf1, 0xf2}; 108 for (size_t j = 0; j < FX_ArraySize(kPrefix); j++) {
102 for (int j = 0; j < 4; j++) { 109 uint16_t unicode = kPrefix[j] * 256 + charcode;
103 uint16_t unicode = prefix[j] * 256 + charcode;
104 m_GlyphIndex[charcode] = 110 m_GlyphIndex[charcode] =
105 FXFT_Get_Char_Index(m_Font.GetFace(), unicode); 111 FXFT_Get_Char_Index(m_Font.GetFace(), unicode);
106 if (m_GlyphIndex[charcode]) { 112 if (m_GlyphIndex[charcode]) {
107 break; 113 break;
108 } 114 }
109 } 115 }
110 } else if (m_Encoding.m_Unicodes[charcode]) { 116 } else if (m_Encoding.m_Unicodes[charcode]) {
111 if (bMSUnicode) { 117 if (bMSUnicode) {
112 m_GlyphIndex[charcode] = FXFT_Get_Char_Index( 118 m_GlyphIndex[charcode] = FXFT_Get_Char_Index(
113 m_Font.GetFace(), m_Encoding.m_Unicodes[charcode]); 119 m_Font.GetFace(), m_Encoding.m_Unicodes[charcode]);
(...skipping 29 matching lines...) Expand all
143 m_GlyphIndex[charcode] = 149 m_GlyphIndex[charcode] =
144 FXFT_Get_Char_Index(m_Font.GetFace(), charcode); 150 FXFT_Get_Char_Index(m_Font.GetFace(), charcode);
145 } 151 }
146 } 152 }
147 } 153 }
148 } 154 }
149 } 155 }
150 return; 156 return;
151 } 157 }
152 if (FT_UseTTCharmap(m_Font.GetFace(), 3, 0)) { 158 if (FT_UseTTCharmap(m_Font.GetFace(), 3, 0)) {
153 const uint8_t prefix[4] = {0x00, 0xf0, 0xf1, 0xf2}; 159 bool bFound = false;
154 FX_BOOL bGotOne = FALSE;
155 for (int charcode = 0; charcode < 256; charcode++) { 160 for (int charcode = 0; charcode < 256; charcode++) {
156 for (int j = 0; j < 4; j++) { 161 for (size_t j = 0; j < FX_ArraySize(kPrefix); j++) {
157 uint16_t unicode = prefix[j] * 256 + charcode; 162 uint16_t unicode = kPrefix[j] * 256 + charcode;
158 m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.GetFace(), unicode); 163 m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.GetFace(), unicode);
159 if (m_GlyphIndex[charcode]) { 164 if (m_GlyphIndex[charcode]) {
160 bGotOne = TRUE; 165 bFound = true;
161 break; 166 break;
162 } 167 }
163 } 168 }
164 } 169 }
165 if (bGotOne) { 170 if (bFound) {
166 if (baseEncoding != PDFFONT_ENCODING_BUILTIN) { 171 if (baseEncoding != PDFFONT_ENCODING_BUILTIN) {
167 for (int charcode = 0; charcode < 256; charcode++) { 172 for (int charcode = 0; charcode < 256; charcode++) {
168 const FX_CHAR* name = 173 const FX_CHAR* name =
169 GetAdobeCharName(baseEncoding, m_pCharNames, charcode); 174 GetAdobeCharName(baseEncoding, m_CharNames, charcode);
170 if (!name) { 175 if (name)
171 continue; 176 m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name);
172 }
173 m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name);
174 } 177 }
175 } else if (FT_UseTTCharmap(m_Font.GetFace(), 1, 0)) { 178 } else if (FT_UseTTCharmap(m_Font.GetFace(), 1, 0)) {
176 for (int charcode = 0; charcode < 256; charcode++) { 179 for (int charcode = 0; charcode < 256; charcode++) {
177 m_Encoding.m_Unicodes[charcode] = 180 m_Encoding.m_Unicodes[charcode] =
178 FT_UnicodeFromCharCode(FXFT_ENCODING_APPLE_ROMAN, charcode); 181 FT_UnicodeFromCharCode(FXFT_ENCODING_APPLE_ROMAN, charcode);
179 } 182 }
180 } 183 }
181 return; 184 return;
182 } 185 }
183 } 186 }
184 if (FT_UseTTCharmap(m_Font.GetFace(), 1, 0)) { 187 if (FT_UseTTCharmap(m_Font.GetFace(), 1, 0)) {
185 FX_BOOL bGotOne = FALSE; 188 bool bFound = false;
186 for (int charcode = 0; charcode < 256; charcode++) { 189 for (int charcode = 0; charcode < 256; charcode++) {
187 m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.GetFace(), charcode); 190 m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.GetFace(), charcode);
188 m_Encoding.m_Unicodes[charcode] = 191 m_Encoding.m_Unicodes[charcode] =
189 FT_UnicodeFromCharCode(FXFT_ENCODING_APPLE_ROMAN, charcode); 192 FT_UnicodeFromCharCode(FXFT_ENCODING_APPLE_ROMAN, charcode);
190 if (m_GlyphIndex[charcode]) { 193 if (m_GlyphIndex[charcode]) {
191 bGotOne = TRUE; 194 bFound = true;
192 } 195 }
193 } 196 }
194 if (m_pFontFile || bGotOne) { 197 if (m_pFontFile || bFound)
195 return; 198 return;
196 }
197 } 199 }
198 if (FXFT_Select_Charmap(m_Font.GetFace(), FXFT_ENCODING_UNICODE) == 0) { 200 if (FXFT_Select_Charmap(m_Font.GetFace(), FXFT_ENCODING_UNICODE) == 0) {
199 FX_BOOL bGotOne = FALSE; 201 bool bFound = false;
200 const uint16_t* pUnicodes = PDF_UnicodesForPredefinedCharSet(baseEncoding); 202 const uint16_t* pUnicodes = PDF_UnicodesForPredefinedCharSet(baseEncoding);
201 for (int charcode = 0; charcode < 256; charcode++) { 203 for (int charcode = 0; charcode < 256; charcode++) {
202 if (m_pFontFile) { 204 if (m_pFontFile) {
203 m_Encoding.m_Unicodes[charcode] = charcode; 205 m_Encoding.m_Unicodes[charcode] = charcode;
204 } else { 206 } else {
205 const FX_CHAR* name = GetAdobeCharName(0, m_pCharNames, charcode); 207 const FX_CHAR* name = GetAdobeCharName(0, m_CharNames, charcode);
206 if (name) { 208 if (name)
207 m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name); 209 m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name);
208 } else if (pUnicodes) { 210 else if (pUnicodes)
209 m_Encoding.m_Unicodes[charcode] = pUnicodes[charcode]; 211 m_Encoding.m_Unicodes[charcode] = pUnicodes[charcode];
210 }
211 } 212 }
212 m_GlyphIndex[charcode] = FXFT_Get_Char_Index( 213 m_GlyphIndex[charcode] = FXFT_Get_Char_Index(
213 m_Font.GetFace(), m_Encoding.m_Unicodes[charcode]); 214 m_Font.GetFace(), m_Encoding.m_Unicodes[charcode]);
214 if (m_GlyphIndex[charcode]) { 215 if (m_GlyphIndex[charcode])
215 bGotOne = TRUE; 216 bFound = true;
216 }
217 } 217 }
218 if (bGotOne) { 218 if (bFound)
219 return; 219 return;
220 }
221 } 220 }
222 for (int charcode = 0; charcode < 256; charcode++) { 221 for (int charcode = 0; charcode < 256; charcode++)
223 m_GlyphIndex[charcode] = charcode; 222 m_GlyphIndex[charcode] = charcode;
224 }
225 } 223 }
OLDNEW
« no previous file with comments | « core/fpdfapi/fpdf_font/cpdf_simplefont.cpp ('k') | core/fpdfapi/fpdf_font/cpdf_type1font.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698