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

Side by Side Diff: fpdfsdk/src/formfiller/FFL_CBA_Fontmap.cpp

Issue 1720043003: Remove foo != NULL outside of xfa/ (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: rebase Created 4 years, 10 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/fxcrt/fx_basic_maps.cpp ('k') | fpdfsdk/src/formfiller/FFL_CheckBox.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 "fpdfsdk/include/formfiller/FFL_CBA_Fontmap.h" 7 #include "fpdfsdk/include/formfiller/FFL_CBA_Fontmap.h"
8 8
9 #include "core/include/fpdfapi/fpdf_page.h" 9 #include "core/include/fpdfapi/fpdf_page.h"
10 #include "fpdfsdk/include/fsdk_baseannot.h" 10 #include "fpdfsdk/include/fsdk_baseannot.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 AddFontToAnnotDict(m_pDefaultFont, m_sDefaultFontName); 52 AddFontToAnnotDict(m_pDefaultFont, m_sDefaultFontName);
53 } 53 }
54 } 54 }
55 55
56 if (nCharset != ANSI_CHARSET) 56 if (nCharset != ANSI_CHARSET)
57 CPWL_FontMap::Initialize(); 57 CPWL_FontMap::Initialize();
58 } 58 }
59 59
60 void CBA_FontMap::SetDefaultFont(CPDF_Font* pFont, 60 void CBA_FontMap::SetDefaultFont(CPDF_Font* pFont,
61 const CFX_ByteString& sFontName) { 61 const CFX_ByteString& sFontName) {
62 ASSERT(pFont != NULL); 62 ASSERT(pFont);
63 63
64 if (m_pDefaultFont) 64 if (m_pDefaultFont)
65 return; 65 return;
66 66
67 m_pDefaultFont = pFont; 67 m_pDefaultFont = pFont;
68 m_sDefaultFontName = sFontName; 68 m_sDefaultFontName = sFontName;
69 69
70 int32_t nCharset = DEFAULT_CHARSET; 70 int32_t nCharset = DEFAULT_CHARSET;
71 if (const CFX_SubstFont* pSubstFont = m_pDefaultFont->GetSubstFont()) 71 if (const CFX_SubstFont* pSubstFont = m_pDefaultFont->GetSubstFont())
72 nCharset = pSubstFont->m_Charset; 72 nCharset = pSubstFont->m_Charset;
73 AddFontData(m_pDefaultFont, m_sDefaultFontName, nCharset); 73 AddFontData(m_pDefaultFont, m_sDefaultFontName, nCharset);
74 } 74 }
75 75
76 CPDF_Font* CBA_FontMap::FindFontSameCharset(CFX_ByteString& sFontAlias, 76 CPDF_Font* CBA_FontMap::FindFontSameCharset(CFX_ByteString& sFontAlias,
77 int32_t nCharset) { 77 int32_t nCharset) {
78 ASSERT(m_pAnnotDict != NULL);
79
80 if (m_pAnnotDict->GetStringBy("Subtype") == "Widget") { 78 if (m_pAnnotDict->GetStringBy("Subtype") == "Widget") {
81 CPDF_Document* pDocument = GetDocument(); 79 CPDF_Document* pDocument = GetDocument();
82 ASSERT(pDocument != NULL);
83
84 CPDF_Dictionary* pRootDict = pDocument->GetRoot(); 80 CPDF_Dictionary* pRootDict = pDocument->GetRoot();
85 if (!pRootDict) 81 if (!pRootDict)
86 return NULL; 82 return NULL;
87 83
88 CPDF_Dictionary* pAcroFormDict = pRootDict->GetDictBy("AcroForm"); 84 CPDF_Dictionary* pAcroFormDict = pRootDict->GetDictBy("AcroForm");
89 if (!pAcroFormDict) 85 if (!pAcroFormDict)
90 return NULL; 86 return NULL;
91 87
92 CPDF_Dictionary* pDRDict = pAcroFormDict->GetDictBy("DR"); 88 CPDF_Dictionary* pDRDict = pAcroFormDict->GetDictBy("DR");
93 if (!pDRDict) 89 if (!pDRDict)
94 return NULL; 90 return NULL;
95 91
96 return FindResFontSameCharset(pDRDict, sFontAlias, nCharset); 92 return FindResFontSameCharset(pDRDict, sFontAlias, nCharset);
97 } 93 }
98 94
99 return NULL; 95 return NULL;
100 } 96 }
101 97
102 CPDF_Document* CBA_FontMap::GetDocument() { 98 CPDF_Document* CBA_FontMap::GetDocument() {
103 return m_pDocument; 99 return m_pDocument;
104 } 100 }
105 101
106 CPDF_Font* CBA_FontMap::FindResFontSameCharset(CPDF_Dictionary* pResDict, 102 CPDF_Font* CBA_FontMap::FindResFontSameCharset(CPDF_Dictionary* pResDict,
107 CFX_ByteString& sFontAlias, 103 CFX_ByteString& sFontAlias,
108 int32_t nCharset) { 104 int32_t nCharset) {
109 if (!pResDict) 105 if (!pResDict)
110 return NULL; 106 return NULL;
111 107
112 CPDF_Document* pDocument = GetDocument();
113 ASSERT(pDocument != NULL);
114
115 CPDF_Dictionary* pFonts = pResDict->GetDictBy("Font"); 108 CPDF_Dictionary* pFonts = pResDict->GetDictBy("Font");
116 if (!pFonts) 109 if (!pFonts)
117 return NULL; 110 return NULL;
118 111
112 CPDF_Document* pDocument = GetDocument();
119 CPDF_Font* pFind = NULL; 113 CPDF_Font* pFind = NULL;
120
121 for (const auto& it : *pFonts) { 114 for (const auto& it : *pFonts) {
122 const CFX_ByteString& csKey = it.first; 115 const CFX_ByteString& csKey = it.first;
123 CPDF_Object* pObj = it.second; 116 CPDF_Object* pObj = it.second;
124 if (!pObj) 117 if (!pObj)
125 continue; 118 continue;
126 119
127 CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); 120 CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect());
128 if (!pElement) 121 if (!pElement)
129 continue; 122 continue;
130 if (pElement->GetStringBy("Type") != "Font") 123 if (pElement->GetStringBy("Type") != "Font")
(...skipping 16 matching lines...) Expand all
147 void CBA_FontMap::AddedFont(CPDF_Font* pFont, 140 void CBA_FontMap::AddedFont(CPDF_Font* pFont,
148 const CFX_ByteString& sFontAlias) { 141 const CFX_ByteString& sFontAlias) {
149 AddFontToAnnotDict(pFont, sFontAlias); 142 AddFontToAnnotDict(pFont, sFontAlias);
150 } 143 }
151 144
152 void CBA_FontMap::AddFontToAnnotDict(CPDF_Font* pFont, 145 void CBA_FontMap::AddFontToAnnotDict(CPDF_Font* pFont,
153 const CFX_ByteString& sAlias) { 146 const CFX_ByteString& sAlias) {
154 if (!pFont) 147 if (!pFont)
155 return; 148 return;
156 149
157 ASSERT(m_pAnnotDict != NULL);
158 ASSERT(m_pDocument != NULL);
159
160 CPDF_Dictionary* pAPDict = m_pAnnotDict->GetDictBy("AP"); 150 CPDF_Dictionary* pAPDict = m_pAnnotDict->GetDictBy("AP");
161 151
162 if (!pAPDict) { 152 if (!pAPDict) {
163 pAPDict = new CPDF_Dictionary; 153 pAPDict = new CPDF_Dictionary;
164 m_pAnnotDict->SetAt("AP", pAPDict); 154 m_pAnnotDict->SetAt("AP", pAPDict);
165 } 155 }
166 156
167 // to avoid checkbox and radiobutton 157 // to avoid checkbox and radiobutton
168 CPDF_Object* pObject = pAPDict->GetElement(m_sAPType); 158 CPDF_Object* pObject = pAPDict->GetElement(m_sAPType);
169 if (ToDictionary(pObject)) 159 if (ToDictionary(pObject))
(...skipping 28 matching lines...) Expand all
198 pStreamResList->SetAtReference("Font", m_pDocument, objnum); 188 pStreamResList->SetAtReference("Font", m_pDocument, objnum);
199 } 189 }
200 if (!pStreamResFontList->KeyExist(sAlias)) 190 if (!pStreamResFontList->KeyExist(sAlias))
201 pStreamResFontList->SetAtReference(sAlias, m_pDocument, 191 pStreamResFontList->SetAtReference(sAlias, m_pDocument,
202 pFont->GetFontDict()); 192 pFont->GetFontDict());
203 } 193 }
204 } 194 }
205 } 195 }
206 196
207 CPDF_Font* CBA_FontMap::GetAnnotDefaultFont(CFX_ByteString& sAlias) { 197 CPDF_Font* CBA_FontMap::GetAnnotDefaultFont(CFX_ByteString& sAlias) {
208 ASSERT(m_pAnnotDict != NULL);
209 ASSERT(m_pDocument != NULL);
210
211 CPDF_Dictionary* pAcroFormDict = NULL; 198 CPDF_Dictionary* pAcroFormDict = NULL;
212 199
213 FX_BOOL bWidget = (m_pAnnotDict->GetStringBy("Subtype") == "Widget"); 200 FX_BOOL bWidget = (m_pAnnotDict->GetStringBy("Subtype") == "Widget");
214 201
215 if (bWidget) { 202 if (bWidget) {
216 if (CPDF_Dictionary* pRootDict = m_pDocument->GetRoot()) 203 if (CPDF_Dictionary* pRootDict = m_pDocument->GetRoot())
217 pAcroFormDict = pRootDict->GetDictBy("AcroForm"); 204 pAcroFormDict = pRootDict->GetDictBy("AcroForm");
218 } 205 }
219 206
220 CFX_ByteString sDA; 207 CFX_ByteString sDA;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 250
264 return pFontDict ? m_pDocument->LoadFont(pFontDict) : nullptr; 251 return pFontDict ? m_pDocument->LoadFont(pFontDict) : nullptr;
265 } 252 }
266 253
267 void CBA_FontMap::SetAPType(const CFX_ByteString& sAPType) { 254 void CBA_FontMap::SetAPType(const CFX_ByteString& sAPType) {
268 m_sAPType = sAPType; 255 m_sAPType = sAPType;
269 256
270 Reset(); 257 Reset();
271 Initialize(); 258 Initialize();
272 } 259 }
OLDNEW
« no previous file with comments | « core/src/fxcrt/fx_basic_maps.cpp ('k') | fpdfsdk/src/formfiller/FFL_CheckBox.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698