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

Side by Side Diff: fpdfsdk/formfiller/cba_fontmap.cpp

Issue 2361713002: Remove some objnum locals with AddIndirectObject (Closed)
Patch Set: Same treatment for arrays Created 4 years, 3 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 | « fpdfsdk/cpdfsdk_widget.cpp ('k') | fpdfsdk/fpdf_flatten.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/formfiller/cba_fontmap.h" 7 #include "fpdfsdk/formfiller/cba_fontmap.h"
8 8
9 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" 9 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h"
10 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" 10 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h"
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 const CFX_ByteString& sFontAlias) { 147 const CFX_ByteString& sFontAlias) {
148 AddFontToAnnotDict(pFont, sFontAlias); 148 AddFontToAnnotDict(pFont, sFontAlias);
149 } 149 }
150 150
151 void CBA_FontMap::AddFontToAnnotDict(CPDF_Font* pFont, 151 void CBA_FontMap::AddFontToAnnotDict(CPDF_Font* pFont,
152 const CFX_ByteString& sAlias) { 152 const CFX_ByteString& sAlias) {
153 if (!pFont) 153 if (!pFont)
154 return; 154 return;
155 155
156 CPDF_Dictionary* pAPDict = m_pAnnotDict->GetDictFor("AP"); 156 CPDF_Dictionary* pAPDict = m_pAnnotDict->GetDictFor("AP");
157
158 if (!pAPDict) { 157 if (!pAPDict) {
159 pAPDict = new CPDF_Dictionary; 158 pAPDict = new CPDF_Dictionary;
160 m_pAnnotDict->SetFor("AP", pAPDict); 159 m_pAnnotDict->SetFor("AP", pAPDict);
161 } 160 }
162 161
163 // to avoid checkbox and radiobutton 162 // to avoid checkbox and radiobutton
164 CPDF_Object* pObject = pAPDict->GetObjectFor(m_sAPType); 163 CPDF_Object* pObject = pAPDict->GetObjectFor(m_sAPType);
165 if (ToDictionary(pObject)) 164 if (ToDictionary(pObject))
166 return; 165 return;
167 166
168 CPDF_Stream* pStream = pAPDict->GetStreamFor(m_sAPType); 167 CPDF_Stream* pStream = pAPDict->GetStreamFor(m_sAPType);
169 if (!pStream) { 168 if (!pStream) {
170 pStream = new CPDF_Stream; 169 pStream = new CPDF_Stream;
171 int32_t objnum = m_pDocument->AddIndirectObject(pStream); 170 pAPDict->SetReferenceFor(m_sAPType, m_pDocument,
172 pAPDict->SetReferenceFor(m_sAPType, m_pDocument, objnum); 171 m_pDocument->AddIndirectObject(pStream));
173 } 172 }
174 173
175 CPDF_Dictionary* pStreamDict = pStream->GetDict(); 174 CPDF_Dictionary* pStreamDict = pStream->GetDict();
176
177 if (!pStreamDict) { 175 if (!pStreamDict) {
178 pStreamDict = new CPDF_Dictionary; 176 pStreamDict = new CPDF_Dictionary;
179 pStream->InitStream(nullptr, 0, pStreamDict); 177 pStream->InitStream(nullptr, 0, pStreamDict);
180 } 178 }
181 179
182 if (pStreamDict) { 180 if (pStreamDict) {
183 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictFor("Resources"); 181 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictFor("Resources");
184 if (!pStreamResList) { 182 if (!pStreamResList) {
185 pStreamResList = new CPDF_Dictionary(); 183 pStreamResList = new CPDF_Dictionary();
186 pStreamDict->SetFor("Resources", pStreamResList); 184 pStreamDict->SetFor("Resources", pStreamResList);
187 } 185 }
188 186 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictFor("Font");
189 if (pStreamResList) { 187 if (!pStreamResFontList) {
190 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictFor("Font"); 188 pStreamResFontList = new CPDF_Dictionary;
191 if (!pStreamResFontList) { 189 pStreamResList->SetReferenceFor(
192 pStreamResFontList = new CPDF_Dictionary; 190 "Font", m_pDocument,
193 int32_t objnum = m_pDocument->AddIndirectObject(pStreamResFontList); 191 m_pDocument->AddIndirectObject(pStreamResFontList));
194 pStreamResList->SetReferenceFor("Font", m_pDocument, objnum); 192 }
195 } 193 if (!pStreamResFontList->KeyExist(sAlias)) {
196 if (!pStreamResFontList->KeyExist(sAlias)) 194 pStreamResFontList->SetReferenceFor(sAlias, m_pDocument,
197 pStreamResFontList->SetReferenceFor(sAlias, m_pDocument, 195 pFont->GetFontDict()->GetObjNum());
198 pFont->GetFontDict());
199 } 196 }
200 } 197 }
201 } 198 }
202 199
203 CPDF_Font* CBA_FontMap::GetAnnotDefaultFont(CFX_ByteString& sAlias) { 200 CPDF_Font* CBA_FontMap::GetAnnotDefaultFont(CFX_ByteString& sAlias) {
204 CPDF_Dictionary* pAcroFormDict = nullptr; 201 CPDF_Dictionary* pAcroFormDict = nullptr;
205 const bool bWidget = (m_pAnnotDict->GetStringFor("Subtype") == "Widget"); 202 const bool bWidget = (m_pAnnotDict->GetStringFor("Subtype") == "Widget");
206 if (bWidget) { 203 if (bWidget) {
207 if (CPDF_Dictionary* pRootDict = m_pDocument->GetRoot()) 204 if (CPDF_Dictionary* pRootDict = m_pDocument->GetRoot())
208 pAcroFormDict = pRootDict->GetDictFor("AcroForm"); 205 pAcroFormDict = pRootDict->GetDictFor("AcroForm");
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 244
248 return pFontDict ? m_pDocument->LoadFont(pFontDict) : nullptr; 245 return pFontDict ? m_pDocument->LoadFont(pFontDict) : nullptr;
249 } 246 }
250 247
251 void CBA_FontMap::SetAPType(const CFX_ByteString& sAPType) { 248 void CBA_FontMap::SetAPType(const CFX_ByteString& sAPType) {
252 m_sAPType = sAPType; 249 m_sAPType = sAPType;
253 250
254 Reset(); 251 Reset();
255 Initialize(); 252 Initialize();
256 } 253 }
OLDNEW
« no previous file with comments | « fpdfsdk/cpdfsdk_widget.cpp ('k') | fpdfsdk/fpdf_flatten.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698