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

Side by Side Diff: core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp

Issue 1297723002: CFX_MapByteStringToPtr considered harmful. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Const auto& Created 5 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/src/fpdfapi/fpdf_font/font_int.h ('k') | core/src/fpdfapi/fpdf_page/fpdf_page_doc.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 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 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 "../../../include/fpdfapi/fpdf_module.h" 7 #include "../../../include/fpdfapi/fpdf_module.h"
8 #include "../../../include/fpdfapi/fpdf_page.h" 8 #include "../../../include/fpdfapi/fpdf_page.h"
9 #include "../../../include/fpdfapi/fpdf_resource.h" 9 #include "../../../include/fpdfapi/fpdf_resource.h"
10 #include "../../../include/fxge/fx_freetype.h" 10 #include "../../../include/fxge/fx_freetype.h"
11 #include "../../../include/fxge/fx_ge.h" 11 #include "../../../include/fxge/fx_ge.h"
12 #include "../fpdf_cmaps/cmap_int.h" 12 #include "../fpdf_cmaps/cmap_int.h"
13 #include "font_int.h" 13 #include "font_int.h"
14 14
15 extern short TT2PDF(int m, FXFT_Face face); 15 extern short TT2PDF(int m, FXFT_Face face);
16 extern FX_BOOL FT_UseTTCharmap(FXFT_Face face, 16 extern FX_BOOL FT_UseTTCharmap(FXFT_Face face,
17 int platform_id, 17 int platform_id,
18 int encoding_id); 18 int encoding_id);
19 19
20 CPDF_CMapManager::CPDF_CMapManager() { 20 CPDF_CMapManager::CPDF_CMapManager() {
21 m_bPrompted = FALSE; 21 m_bPrompted = FALSE;
22 FXSYS_memset(m_CID2UnicodeMaps, 0, sizeof m_CID2UnicodeMaps); 22 FXSYS_memset(m_CID2UnicodeMaps, 0, sizeof m_CID2UnicodeMaps);
23 } 23 }
24 CPDF_CMapManager::~CPDF_CMapManager() { 24 CPDF_CMapManager::~CPDF_CMapManager() {
25 DropAll(FALSE); 25 for (const auto& pair : m_CMaps) {
26 delete pair.second;
27 }
28 m_CMaps.clear();
29 for (int i = 0; i < FX_ArraySize(m_CID2UnicodeMaps); ++i) {
30 delete m_CID2UnicodeMaps[i];
31 }
26 } 32 }
27 CPDF_CMap* CPDF_CMapManager::GetPredefinedCMap(const CFX_ByteString& name, 33 CPDF_CMap* CPDF_CMapManager::GetPredefinedCMap(const CFX_ByteString& name,
28 FX_BOOL bPromptCJK) { 34 FX_BOOL bPromptCJK) {
29 CPDF_CMap* pCMap; 35 auto it = m_CMaps.find(name);
30 if (m_CMaps.Lookup(name, (void*&)pCMap)) { 36 if (it != m_CMaps.end()) {
31 return pCMap; 37 return it->second;
32 } 38 }
33 pCMap = LoadPredefinedCMap(name, bPromptCJK); 39 CPDF_CMap* pCMap = LoadPredefinedCMap(name, bPromptCJK);
34 if (name.IsEmpty()) { 40 if (!name.IsEmpty()) {
35 return pCMap; 41 m_CMaps[name] = pCMap;
36 } 42 }
37 m_CMaps.SetAt(name, pCMap);
38 return pCMap; 43 return pCMap;
39 } 44 }
40 CPDF_CMap* CPDF_CMapManager::LoadPredefinedCMap(const CFX_ByteString& name, 45 CPDF_CMap* CPDF_CMapManager::LoadPredefinedCMap(const CFX_ByteString& name,
41 FX_BOOL bPromptCJK) { 46 FX_BOOL bPromptCJK) {
42 CPDF_CMap* pCMap = new CPDF_CMap; 47 CPDF_CMap* pCMap = new CPDF_CMap;
43 const FX_CHAR* pname = name; 48 const FX_CHAR* pname = name;
44 if (*pname == '/') { 49 if (*pname == '/') {
45 pname++; 50 pname++;
46 } 51 }
47 pCMap->LoadPredefined(this, pname, bPromptCJK); 52 pCMap->LoadPredefined(this, pname, bPromptCJK);
48 return pCMap; 53 return pCMap;
49 } 54 }
50 static const FX_CHAR* const g_CharsetNames[NUMBER_OF_CIDSETS] = { 55 static const FX_CHAR* const g_CharsetNames[NUMBER_OF_CIDSETS] = {
51 NULL, "GB1", "CNS1", "Japan1", "Korea1", "UCS"}; 56 NULL, "GB1", "CNS1", "Japan1", "Korea1", "UCS"};
52 static const int g_CharsetCPs[NUMBER_OF_CIDSETS] = {0, 936, 950, 57 static const int g_CharsetCPs[NUMBER_OF_CIDSETS] = {0, 936, 950,
53 932, 949, 1200}; 58 932, 949, 1200};
54 int _CharsetFromOrdering(const CFX_ByteString& Ordering) { 59 int _CharsetFromOrdering(const CFX_ByteString& Ordering) {
55 for (int charset = 1; charset < NUMBER_OF_CIDSETS; charset++) { 60 for (int charset = 1; charset < NUMBER_OF_CIDSETS; charset++) {
56 if (Ordering == CFX_ByteStringC(g_CharsetNames[charset])) 61 if (Ordering == CFX_ByteStringC(g_CharsetNames[charset]))
57 return charset; 62 return charset;
58 } 63 }
59 return CIDSET_UNKNOWN; 64 return CIDSET_UNKNOWN;
60 } 65 }
61 void CPDF_CMapManager::ReloadAll() { 66 void CPDF_CMapManager::ReloadAll() {
62 DropAll(TRUE); 67 for (const auto& pair : m_CMaps) {
63 } 68 CPDF_CMap* pCMap = pair.second;
64 void CPDF_CMapManager::DropAll(FX_BOOL bReload) { 69 pCMap->LoadPredefined(this, pair.first, FALSE);
65 FX_POSITION pos = m_CMaps.GetStartPosition();
66 while (pos) {
67 CFX_ByteString name;
68 CPDF_CMap* pCMap;
69 m_CMaps.GetNextAssoc(pos, name, (void*&)pCMap);
70 if (pCMap == NULL) {
71 continue;
72 }
73 if (bReload) {
74 pCMap->LoadPredefined(this, name, FALSE);
75 } else {
76 delete pCMap;
77 }
78 } 70 }
79 for (int i = 0; i < sizeof m_CID2UnicodeMaps / sizeof(CPDF_CID2UnicodeMap*); 71 for (int i = 0; i < FX_ArraySize(m_CID2UnicodeMaps); ++i) {
80 i++) { 72 if (CPDF_CID2UnicodeMap* pMap = m_CID2UnicodeMaps[i]) {
81 CPDF_CID2UnicodeMap* pMap = m_CID2UnicodeMaps[i];
82 if (pMap == NULL) {
83 continue;
84 }
85 if (bReload) {
86 pMap->Load(this, i, FALSE); 73 pMap->Load(this, i, FALSE);
87 } else {
88 delete pMap;
89 } 74 }
90 } 75 }
91 } 76 }
92 CPDF_CID2UnicodeMap* CPDF_CMapManager::GetCID2UnicodeMap(int charset, 77 CPDF_CID2UnicodeMap* CPDF_CMapManager::GetCID2UnicodeMap(int charset,
93 FX_BOOL bPromptCJK) { 78 FX_BOOL bPromptCJK) {
94 if (m_CID2UnicodeMaps[charset] == NULL) { 79 if (m_CID2UnicodeMaps[charset] == NULL) {
95 m_CID2UnicodeMaps[charset] = LoadCID2UnicodeMap(charset, bPromptCJK); 80 m_CID2UnicodeMaps[charset] = LoadCID2UnicodeMap(charset, bPromptCJK);
96 } 81 }
97 return m_CID2UnicodeMaps[charset]; 82 return m_CID2UnicodeMaps[charset];
98 } 83 }
(...skipping 1555 matching lines...) Expand 10 before | Expand all | Expand 10 after
1654 if (middlecode > CID) { 1639 if (middlecode > CID) {
1655 end = middle - 1; 1640 end = middle - 1;
1656 } else if (middlecode < CID) { 1641 } else if (middlecode < CID) {
1657 begin = middle + 1; 1642 begin = middle + 1;
1658 } else { 1643 } else {
1659 return &Japan1_VertCIDs[middle].a; 1644 return &Japan1_VertCIDs[middle].a;
1660 } 1645 }
1661 } 1646 }
1662 return NULL; 1647 return NULL;
1663 } 1648 }
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_font/font_int.h ('k') | core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698