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

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

Issue 2194853002: Cleanup CPDF_DocPageData release methods and callers. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: 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 | « no previous file | core/fpdfapi/fpdf_page/cpdf_color.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/include/cpdf_font.h" 7 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h"
8 8
9 #include <memory>
10
9 #include "core/fpdfapi/fpdf_font/cpdf_truetypefont.h" 11 #include "core/fpdfapi/fpdf_font/cpdf_truetypefont.h"
10 #include "core/fpdfapi/fpdf_font/cpdf_type1font.h" 12 #include "core/fpdfapi/fpdf_font/cpdf_type1font.h"
11 #include "core/fpdfapi/fpdf_font/cpdf_type3font.h" 13 #include "core/fpdfapi/fpdf_font/cpdf_type3font.h"
12 #include "core/fpdfapi/fpdf_font/font_int.h" 14 #include "core/fpdfapi/fpdf_font/font_int.h"
13 #include "core/fpdfapi/fpdf_font/include/cpdf_fontencoding.h" 15 #include "core/fpdfapi/fpdf_font/include/cpdf_fontencoding.h"
14 #include "core/fpdfapi/fpdf_page/cpdf_pagemodule.h" 16 #include "core/fpdfapi/fpdf_page/cpdf_pagemodule.h"
15 #include "core/fpdfapi/fpdf_page/pageint.h" 17 #include "core/fpdfapi/fpdf_page/pageint.h"
16 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" 18 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
17 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" 19 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h"
18 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" 20 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
19 #include "core/fpdfapi/fpdf_parser/include/cpdf_name.h" 21 #include "core/fpdfapi/fpdf_parser/include/cpdf_name.h"
20 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h" 22 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h"
21 #include "core/fpdfapi/include/cpdf_modulemgr.h" 23 #include "core/fpdfapi/include/cpdf_modulemgr.h"
22 #include "core/fxge/include/fx_freetype.h" 24 #include "core/fxge/include/fx_freetype.h"
23 25
24 namespace { 26 namespace {
25 27
26 const uint8_t ChineseFontNames[][5] = {{0xCB, 0xCE, 0xCC, 0xE5, 0x00}, 28 const uint8_t kChineseFontNames[][5] = {{0xCB, 0xCE, 0xCC, 0xE5, 0x00},
27 {0xBF, 0xAC, 0xCC, 0xE5, 0x00}, 29 {0xBF, 0xAC, 0xCC, 0xE5, 0x00},
28 {0xBA, 0xDA, 0xCC, 0xE5, 0x00}, 30 {0xBA, 0xDA, 0xCC, 0xE5, 0x00},
29 {0xB7, 0xC2, 0xCB, 0xCE, 0x00}, 31 {0xB7, 0xC2, 0xCB, 0xCE, 0x00},
30 {0xD0, 0xC2, 0xCB, 0xCE, 0x00}}; 32 {0xD0, 0xC2, 0xCB, 0xCE, 0x00}};
31 33
32 FX_BOOL GetPredefinedEncoding(int& basemap, const CFX_ByteString& value) { 34 void GetPredefinedEncoding(int& basemap, const CFX_ByteString& value) {
33 if (value == "WinAnsiEncoding") 35 if (value == "WinAnsiEncoding")
34 basemap = PDFFONT_ENCODING_WINANSI; 36 basemap = PDFFONT_ENCODING_WINANSI;
35 else if (value == "MacRomanEncoding") 37 else if (value == "MacRomanEncoding")
36 basemap = PDFFONT_ENCODING_MACROMAN; 38 basemap = PDFFONT_ENCODING_MACROMAN;
37 else if (value == "MacExpertEncoding") 39 else if (value == "MacExpertEncoding")
38 basemap = PDFFONT_ENCODING_MACEXPERT; 40 basemap = PDFFONT_ENCODING_MACEXPERT;
39 else if (value == "PDFDocEncoding") 41 else if (value == "PDFDocEncoding")
40 basemap = PDFFONT_ENCODING_PDFDOC; 42 basemap = PDFFONT_ENCODING_PDFDOC;
41 else
42 return FALSE;
43 return TRUE;
44 } 43 }
45 44
46 } // namespace 45 } // namespace
47 46
48 CPDF_Font::CPDF_Font() 47 CPDF_Font::CPDF_Font()
49 : m_pFontFile(nullptr), 48 : m_pFontFile(nullptr),
50 m_pFontDict(nullptr), 49 m_pFontDict(nullptr),
51 m_bToUnicodeLoaded(FALSE), 50 m_bToUnicodeLoaded(FALSE),
52 m_Flags(0), 51 m_Flags(0),
53 m_StemV(0), 52 m_StemV(0),
54 m_Ascent(0), 53 m_Ascent(0),
55 m_Descent(0), 54 m_Descent(0),
56 m_ItalicAngle(0) {} 55 m_ItalicAngle(0) {}
57 56
58 CPDF_Font::~CPDF_Font() { 57 CPDF_Font::~CPDF_Font() {
59 if (m_pFontFile) { 58 if (m_pFontFile) {
60 m_pDocument->GetPageData()->ReleaseFontFileStreamAcc( 59 m_pDocument->GetPageData()->ReleaseFontFileStreamAcc(
61 const_cast<CPDF_Stream*>(m_pFontFile->GetStream()->AsStream())); 60 m_pFontFile->GetStream()->AsStream());
62 } 61 }
63 } 62 }
64 63
65 bool CPDF_Font::IsType1Font() const { 64 bool CPDF_Font::IsType1Font() const {
66 return false; 65 return false;
67 } 66 }
68 67
69 bool CPDF_Font::IsTrueTypeFont() const { 68 bool CPDF_Font::IsTrueTypeFont() const {
70 return false; 69 return false;
71 } 70 }
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 return; 214 return;
216 215
217 m_pFontFile = m_pDocument->LoadFontFile(pFontFile); 216 m_pFontFile = m_pDocument->LoadFontFile(pFontFile);
218 if (!m_pFontFile) 217 if (!m_pFontFile)
219 return; 218 return;
220 219
221 const uint8_t* pFontData = m_pFontFile->GetData(); 220 const uint8_t* pFontData = m_pFontFile->GetData();
222 uint32_t dwFontSize = m_pFontFile->GetSize(); 221 uint32_t dwFontSize = m_pFontFile->GetSize();
223 if (!m_Font.LoadEmbedded(pFontData, dwFontSize)) { 222 if (!m_Font.LoadEmbedded(pFontData, dwFontSize)) {
224 m_pDocument->GetPageData()->ReleaseFontFileStreamAcc( 223 m_pDocument->GetPageData()->ReleaseFontFileStreamAcc(
225 const_cast<CPDF_Stream*>(m_pFontFile->GetStream()->AsStream())); 224 m_pFontFile->GetStream()->AsStream());
226 m_pFontFile = nullptr; 225 m_pFontFile = nullptr;
227 } 226 }
228 } 227 }
229 228
230 void CPDF_Font::CheckFontMetrics() { 229 void CPDF_Font::CheckFontMetrics() {
231 if (m_FontBBox.top == 0 && m_FontBBox.bottom == 0 && m_FontBBox.left == 0 && 230 if (m_FontBBox.top == 0 && m_FontBBox.bottom == 0 && m_FontBBox.left == 0 &&
232 m_FontBBox.right == 0) { 231 m_FontBBox.right == 0) {
233 FXFT_Face face = m_Font.GetFace(); 232 FXFT_Face face = m_Font.GetFace();
234 if (face) { 233 if (face) {
235 m_FontBBox.left = TT2PDF(FXFT_Get_Face_xMin(face), face); 234 m_FontBBox.left = TT2PDF(FXFT_Get_Face_xMin(face), face);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 pFontGlobals->Set(pDoc, font_id, pFont); 314 pFontGlobals->Set(pDoc, font_id, pFont);
316 return pFont; 315 return pFont;
317 } 316 }
318 317
319 CPDF_Font* CPDF_Font::CreateFontF(CPDF_Document* pDoc, 318 CPDF_Font* CPDF_Font::CreateFontF(CPDF_Document* pDoc,
320 CPDF_Dictionary* pFontDict) { 319 CPDF_Dictionary* pFontDict) {
321 CFX_ByteString type = pFontDict->GetStringBy("Subtype"); 320 CFX_ByteString type = pFontDict->GetStringBy("Subtype");
322 std::unique_ptr<CPDF_Font> pFont; 321 std::unique_ptr<CPDF_Font> pFont;
323 if (type == "TrueType") { 322 if (type == "TrueType") {
324 CFX_ByteString tag = pFontDict->GetStringBy("BaseFont").Left(4); 323 CFX_ByteString tag = pFontDict->GetStringBy("BaseFont").Left(4);
325 for (size_t i = 0; i < FX_ArraySize(ChineseFontNames); ++i) { 324 for (size_t i = 0; i < FX_ArraySize(kChineseFontNames); ++i) {
326 if (tag == CFX_ByteString(ChineseFontNames[i], 4)) { 325 if (tag == CFX_ByteString(kChineseFontNames[i], 4)) {
327 CPDF_Dictionary* pFontDesc = pFontDict->GetDictBy("FontDescriptor"); 326 CPDF_Dictionary* pFontDesc = pFontDict->GetDictBy("FontDescriptor");
328 if (!pFontDesc || !pFontDesc->KeyExist("FontFile2")) 327 if (!pFontDesc || !pFontDesc->KeyExist("FontFile2"))
329 pFont.reset(new CPDF_CIDFont); 328 pFont.reset(new CPDF_CIDFont);
330 break; 329 break;
331 } 330 }
332 } 331 }
333 if (!pFont) 332 if (!pFont)
334 pFont.reset(new CPDF_TrueTypeFont); 333 pFont.reset(new CPDF_TrueTypeFont);
335 } else if (type == "Type3") { 334 } else if (type == "Type3") {
336 pFont.reset(new CPDF_Type3Font); 335 pFont.reset(new CPDF_Type3Font);
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 } 442 }
444 443
445 if (pCharNames && !pCharNames[charcode].IsEmpty()) 444 if (pCharNames && !pCharNames[charcode].IsEmpty())
446 return pCharNames[charcode].c_str(); 445 return pCharNames[charcode].c_str();
447 446
448 const FX_CHAR* name = nullptr; 447 const FX_CHAR* name = nullptr;
449 if (iBaseEncoding) 448 if (iBaseEncoding)
450 name = PDF_CharNameFromPredefinedCharSet(iBaseEncoding, charcode); 449 name = PDF_CharNameFromPredefinedCharSet(iBaseEncoding, charcode);
451 return name && name[0] ? name : nullptr; 450 return name && name[0] ? name : nullptr;
452 } 451 }
OLDNEW
« no previous file with comments | « no previous file | core/fpdfapi/fpdf_page/cpdf_color.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698