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

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

Issue 2520493002: Make CPDF_Stream() take unique_ptr's to its dictionary. (Closed)
Patch Set: Created 4 years, 1 month 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
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/font/cpdf_font.h" 9 #include "core/fpdfapi/font/cpdf_font.h"
10 #include "core/fpdfapi/page/cpdf_page.h" 10 #include "core/fpdfapi/page/cpdf_page.h"
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 164
165 CPDF_Stream* pStream = pAPDict->GetStreamFor(m_sAPType); 165 CPDF_Stream* pStream = pAPDict->GetStreamFor(m_sAPType);
166 if (!pStream) { 166 if (!pStream) {
167 pStream = m_pDocument->NewIndirect<CPDF_Stream>(); 167 pStream = m_pDocument->NewIndirect<CPDF_Stream>();
168 pAPDict->SetNewFor<CPDF_Reference>(m_sAPType, m_pDocument, 168 pAPDict->SetNewFor<CPDF_Reference>(m_sAPType, m_pDocument,
169 pStream->GetObjNum()); 169 pStream->GetObjNum());
170 } 170 }
171 171
172 CPDF_Dictionary* pStreamDict = pStream->GetDict(); 172 CPDF_Dictionary* pStreamDict = pStream->GetDict();
173 if (!pStreamDict) { 173 if (!pStreamDict) {
174 pStreamDict = new CPDF_Dictionary(m_pDocument->GetByteStringPool()); 174 auto pOwnedDict =
175 pStream->InitStream(nullptr, 0, pStreamDict); 175 pdfium::MakeUnique<CPDF_Dictionary>(m_pDocument->GetByteStringPool());
176 pStreamDict = pOwnedDict.get();
177 pStream->InitStream(nullptr, 0, std::move(pOwnedDict));
176 } 178 }
177 179
178 if (pStreamDict) { 180 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictFor("Resources");
179 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictFor("Resources"); 181 if (!pStreamResList)
180 if (!pStreamResList) 182 pStreamResList = pStreamDict->SetNewFor<CPDF_Dictionary>("Resources");
181 pStreamResList = pStreamDict->SetNewFor<CPDF_Dictionary>("Resources"); 183 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictFor("Font");
182 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictFor("Font"); 184 if (!pStreamResFontList) {
183 if (!pStreamResFontList) { 185 pStreamResFontList = m_pDocument->NewIndirect<CPDF_Dictionary>();
184 pStreamResFontList = m_pDocument->NewIndirect<CPDF_Dictionary>(); 186 pStreamResList->SetNewFor<CPDF_Reference>("Font", m_pDocument,
185 pStreamResList->SetNewFor<CPDF_Reference>( 187 pStreamResFontList->GetObjNum());
186 "Font", m_pDocument, pStreamResFontList->GetObjNum()); 188 }
187 } 189 if (!pStreamResFontList->KeyExist(sAlias)) {
188 if (!pStreamResFontList->KeyExist(sAlias)) { 190 pStreamResFontList->SetNewFor<CPDF_Reference>(
189 pStreamResFontList->SetNewFor<CPDF_Reference>( 191 sAlias, m_pDocument, pFont->GetFontDict()->GetObjNum());
190 sAlias, m_pDocument, pFont->GetFontDict()->GetObjNum());
191 }
192 } 192 }
193 } 193 }
194 194
195 CPDF_Font* CBA_FontMap::GetAnnotDefaultFont(CFX_ByteString& sAlias) { 195 CPDF_Font* CBA_FontMap::GetAnnotDefaultFont(CFX_ByteString& sAlias) {
196 CPDF_Dictionary* pAcroFormDict = nullptr; 196 CPDF_Dictionary* pAcroFormDict = nullptr;
197 const bool bWidget = (m_pAnnotDict->GetStringFor("Subtype") == "Widget"); 197 const bool bWidget = (m_pAnnotDict->GetStringFor("Subtype") == "Widget");
198 if (bWidget) { 198 if (bWidget) {
199 if (CPDF_Dictionary* pRootDict = m_pDocument->GetRoot()) 199 if (CPDF_Dictionary* pRootDict = m_pDocument->GetRoot())
200 pAcroFormDict = pRootDict->GetDictFor("AcroForm"); 200 pAcroFormDict = pRootDict->GetDictFor("AcroForm");
201 } 201 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 239
240 return pFontDict ? m_pDocument->LoadFont(pFontDict) : nullptr; 240 return pFontDict ? m_pDocument->LoadFont(pFontDict) : nullptr;
241 } 241 }
242 242
243 void CBA_FontMap::SetAPType(const CFX_ByteString& sAPType) { 243 void CBA_FontMap::SetAPType(const CFX_ByteString& sAPType) {
244 m_sAPType = sAPType; 244 m_sAPType = sAPType;
245 245
246 Reset(); 246 Reset();
247 Initialize(); 247 Initialize();
248 } 248 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698