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

Side by Side Diff: core/fpdfapi/fpdf_font/cpdf_simplefont.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.h ('k') | core/fpdfapi/fpdf_font/cpdf_truetypefont.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_simplefont.h" 7 #include "core/fpdfapi/fpdf_font/cpdf_simplefont.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_array.h" 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
11 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h"
12 #include "core/fxge/include/fx_freetype.h" 12 #include "core/fxge/include/fx_freetype.h"
13 13
14 CPDF_SimpleFont::CPDF_SimpleFont() 14 CPDF_SimpleFont::CPDF_SimpleFont() : m_BaseEncoding(PDFFONT_ENCODING_BUILTIN) {
15 : m_pCharNames(nullptr), m_BaseEncoding(PDFFONT_ENCODING_BUILTIN) {
16 FXSYS_memset(m_CharWidth, 0xff, sizeof(m_CharWidth)); 15 FXSYS_memset(m_CharWidth, 0xff, sizeof(m_CharWidth));
17 FXSYS_memset(m_GlyphIndex, 0xff, sizeof(m_GlyphIndex)); 16 FXSYS_memset(m_GlyphIndex, 0xff, sizeof(m_GlyphIndex));
18 FXSYS_memset(m_ExtGID, 0xff, sizeof(m_ExtGID)); 17 FXSYS_memset(m_ExtGID, 0xff, sizeof(m_ExtGID));
19 } 18 }
20 19
21 CPDF_SimpleFont::~CPDF_SimpleFont() { 20 CPDF_SimpleFont::~CPDF_SimpleFont() {}
22 delete[] m_pCharNames;
23 }
24 21
25 int CPDF_SimpleFont::GlyphFromCharCode(uint32_t charcode, bool* pVertGlyph) { 22 int CPDF_SimpleFont::GlyphFromCharCode(uint32_t charcode, bool* pVertGlyph) {
26 if (pVertGlyph) 23 if (pVertGlyph)
27 *pVertGlyph = false; 24 *pVertGlyph = false;
28 25
29 if (charcode > 0xff) 26 if (charcode > 0xff)
30 return -1; 27 return -1;
31 28
32 int index = m_GlyphIndex[(uint8_t)charcode]; 29 int index = m_GlyphIndex[(uint8_t)charcode];
33 return index != 0xffff ? index : -1; 30 return index != 0xffff ? index : -1;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 if (m_BaseFont.GetLength() > 8 && m_BaseFont[7] == '+') { 129 if (m_BaseFont.GetLength() > 8 && m_BaseFont[7] == '+') {
133 m_BaseFont = m_BaseFont.Mid(8); 130 m_BaseFont = m_BaseFont.Mid(8);
134 } 131 }
135 } else { 132 } else {
136 LoadSubstFont(); 133 LoadSubstFont();
137 } 134 }
138 if (!(m_Flags & PDFFONT_SYMBOLIC)) { 135 if (!(m_Flags & PDFFONT_SYMBOLIC)) {
139 m_BaseEncoding = PDFFONT_ENCODING_STANDARD; 136 m_BaseEncoding = PDFFONT_ENCODING_STANDARD;
140 } 137 }
141 CPDF_Object* pEncoding = m_pFontDict->GetDirectObjectBy("Encoding"); 138 CPDF_Object* pEncoding = m_pFontDict->GetDirectObjectBy("Encoding");
142 LoadPDFEncoding(pEncoding, m_BaseEncoding, m_pCharNames, !!m_pFontFile, 139 LoadPDFEncoding(pEncoding, m_BaseEncoding, &m_CharNames, !!m_pFontFile,
143 m_Font.IsTTFont()); 140 m_Font.IsTTFont());
144 LoadGlyphMap(); 141 LoadGlyphMap();
145 delete[] m_pCharNames; 142 m_CharNames.clear();
146 m_pCharNames = nullptr;
147 if (!m_Font.GetFace()) 143 if (!m_Font.GetFace())
148 return TRUE; 144 return TRUE;
149 145
150 if (m_Flags & PDFFONT_ALLCAP) { 146 if (m_Flags & PDFFONT_ALLCAP) {
151 unsigned char lowercases[] = {'a', 'z', 0xe0, 0xf6, 0xf8, 0xfd}; 147 unsigned char kLowercases[][2] = {{'a', 'z'}, {0xe0, 0xf6}, {0xf8, 0xfd}};
152 for (size_t range = 0; range < sizeof lowercases / 2; range++) { 148 for (size_t range = 0; range < FX_ArraySize(kLowercases); ++range) {
153 for (int i = lowercases[range * 2]; i <= lowercases[range * 2 + 1]; i++) { 149 const auto& lower = kLowercases[range];
154 if (m_GlyphIndex[i] != 0xffff && m_pFontFile) { 150 for (int i = lower[0]; i <= lower[1]; ++i) {
151 if (m_GlyphIndex[i] != 0xffff && m_pFontFile)
155 continue; 152 continue;
156 } 153
157 m_GlyphIndex[i] = m_GlyphIndex[i - 32]; 154 int j = i - 32;
158 if (m_CharWidth[i - 32]) { 155 m_GlyphIndex[i] = m_GlyphIndex[j];
159 m_CharWidth[i] = m_CharWidth[i - 32]; 156 if (m_CharWidth[j]) {
160 m_CharBBox[i] = m_CharBBox[i - 32]; 157 m_CharWidth[i] = m_CharWidth[j];
158 m_CharBBox[i] = m_CharBBox[j];
161 } 159 }
162 } 160 }
163 } 161 }
164 } 162 }
165 CheckFontMetrics(); 163 CheckFontMetrics();
166 return TRUE; 164 return TRUE;
167 } 165 }
168 166
169 void CPDF_SimpleFont::LoadSubstFont() { 167 void CPDF_SimpleFont::LoadSubstFont() {
170 if (!m_bUseFontWidth && !(m_Flags & PDFFONT_FIXEDPITCH)) { 168 if (!m_bUseFontWidth && !(m_Flags & PDFFONT_FIXEDPITCH)) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 return CFX_WideString(); 201 return CFX_WideString();
204 return ret; 202 return ret;
205 } 203 }
206 204
207 uint32_t CPDF_SimpleFont::CharCodeFromUnicode(FX_WCHAR unicode) const { 205 uint32_t CPDF_SimpleFont::CharCodeFromUnicode(FX_WCHAR unicode) const {
208 uint32_t ret = CPDF_Font::CharCodeFromUnicode(unicode); 206 uint32_t ret = CPDF_Font::CharCodeFromUnicode(unicode);
209 if (ret) 207 if (ret)
210 return ret; 208 return ret;
211 return m_Encoding.CharCodeFromUnicode(unicode); 209 return m_Encoding.CharCodeFromUnicode(unicode);
212 } 210 }
OLDNEW
« no previous file with comments | « core/fpdfapi/fpdf_font/cpdf_simplefont.h ('k') | core/fpdfapi/fpdf_font/cpdf_truetypefont.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698