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

Side by Side Diff: xfa/fxfa/app/xfa_ffdoc.cpp

Issue 1917493002: Use std::map in xfa_ffdoc.cpp (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 8 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 | xfa/fxfa/include/xfa_ffdoc.h » ('j') | xfa/fxfa/include/xfa_ffdoc.h » ('J')
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 "xfa/fxfa/include/xfa_ffdoc.h" 7 #include "xfa/fxfa/include/xfa_ffdoc.h"
8 8
9 #include <algorithm>
10
9 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" 12 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
11 #include "core/fpdfdoc/include/fpdf_doc.h" 13 #include "core/fpdfdoc/include/fpdf_doc.h"
12 #include "core/fxcrt/include/fx_ext.h" 14 #include "core/fxcrt/include/fx_ext.h"
13 #include "core/fxcrt/include/fx_memory.h" 15 #include "core/fxcrt/include/fx_memory.h"
14 #include "xfa/fde/xml/fde_xml_imp.h" 16 #include "xfa/fde/xml/fde_xml_imp.h"
15 #include "xfa/fgas/crt/fgas_algorithm.h" 17 #include "xfa/fgas/crt/fgas_algorithm.h"
16 #include "xfa/fwl/core/ifwl_notedriver.h" 18 #include "xfa/fwl/core/ifwl_notedriver.h"
17 #include "xfa/fxfa/app/xfa_ffnotify.h" 19 #include "xfa/fxfa/app/xfa_ffnotify.h"
18 #include "xfa/fxfa/include/xfa_checksum.h" 20 #include "xfa/fxfa/include/xfa_checksum.h"
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 CXFA_Node* pDynamicRender = 183 CXFA_Node* pDynamicRender =
182 pAcrobat7->GetFirstChildByClass(XFA_ELEMENT_DynamicRender); 184 pAcrobat7->GetFirstChildByClass(XFA_ELEMENT_DynamicRender);
183 if (!pDynamicRender) { 185 if (!pDynamicRender) {
184 return; 186 return;
185 } 187 }
186 CFX_WideString wsType; 188 CFX_WideString wsType;
187 if (pDynamicRender->TryContent(wsType) && wsType == FX_WSTRC(L"required")) { 189 if (pDynamicRender->TryContent(wsType) && wsType == FX_WSTRC(L"required")) {
188 m_dwDocType = XFA_DOCTYPE_Dynamic; 190 m_dwDocType = XFA_DOCTYPE_Dynamic;
189 } 191 }
190 } 192 }
193
191 CXFA_FFDocView* CXFA_FFDoc::CreateDocView(uint32_t dwView) { 194 CXFA_FFDocView* CXFA_FFDoc::CreateDocView(uint32_t dwView) {
192 CXFA_FFDocView* pDocView = 195 auto it = m_TypeToDocViewMap.find(dwView);
193 (CXFA_FFDocView*)m_mapTypeToDocView.GetValueAt((void*)(uintptr_t)dwView); 196 if (it != m_TypeToDocViewMap.end())
194 if (!pDocView) { 197 return it->second;
195 pDocView = new CXFA_FFDocView(this); 198
196 m_mapTypeToDocView.SetAt((void*)(uintptr_t)dwView, pDocView); 199 CXFA_FFDocView* pDocView = new CXFA_FFDocView(this);
197 } 200 m_TypeToDocViewMap[dwView] = pDocView;
198 return pDocView; 201 return pDocView;
199 } 202 }
203
200 CXFA_FFDocView* CXFA_FFDoc::GetDocView(CXFA_LayoutProcessor* pLayout) { 204 CXFA_FFDocView* CXFA_FFDoc::GetDocView(CXFA_LayoutProcessor* pLayout) {
201 FX_POSITION ps = m_mapTypeToDocView.GetStartPosition(); 205 auto it =
202 while (ps) { 206 std::find_if(m_TypeToDocViewMap.begin(), m_TypeToDocViewMap.end(),
203 void* pType; 207 [pLayout](const std::pair<uint32_t, CXFA_FFDocView*>& pair) {
204 CXFA_FFDocView* pDocView; 208 return pair.second->GetXFALayout() == pLayout;
205 m_mapTypeToDocView.GetNextAssoc(ps, pType, (void*&)pDocView); 209 });
206 if (pDocView->GetXFALayout() == pLayout) { 210 return it != m_TypeToDocViewMap.end() ? it->second : nullptr;
207 return pDocView;
208 }
209 }
210 return NULL;
211 } 211 }
212
212 CXFA_FFDocView* CXFA_FFDoc::GetDocView() { 213 CXFA_FFDocView* CXFA_FFDoc::GetDocView() {
213 FX_POSITION ps = m_mapTypeToDocView.GetStartPosition(); 214 auto it = m_TypeToDocViewMap.begin();
214 if (ps) { 215 return it != m_TypeToDocViewMap.end() ? it->second : nullptr;
215 void* pType;
216 CXFA_FFDocView* pDocView;
217 m_mapTypeToDocView.GetNextAssoc(ps, pType, (void*&)pDocView);
218 return pDocView;
219 }
220 return NULL;
221 } 216 }
217
222 FX_BOOL CXFA_FFDoc::OpenDoc(IFX_FileRead* pStream, FX_BOOL bTakeOverFile) { 218 FX_BOOL CXFA_FFDoc::OpenDoc(IFX_FileRead* pStream, FX_BOOL bTakeOverFile) {
223 m_bOwnStream = bTakeOverFile; 219 m_bOwnStream = bTakeOverFile;
224 m_pStream = pStream; 220 m_pStream = pStream;
225 return TRUE; 221 return TRUE;
226 } 222 }
227 FX_BOOL CXFA_FFDoc::OpenDoc(CPDF_Document* pPDFDoc) { 223 FX_BOOL CXFA_FFDoc::OpenDoc(CPDF_Document* pPDFDoc) {
228 if (pPDFDoc == NULL) { 224 if (pPDFDoc == NULL) {
229 return FALSE; 225 return FALSE;
230 } 226 }
231 CPDF_Dictionary* pRoot = pPDFDoc->GetRoot(); 227 CPDF_Dictionary* pRoot = pPDFDoc->GetRoot();
(...skipping 25 matching lines...) Expand all
257 m_pPDFDoc = pPDFDoc; 253 m_pPDFDoc = pPDFDoc;
258 if (m_pStream) { 254 if (m_pStream) {
259 m_pStream->Release(); 255 m_pStream->Release();
260 m_pStream = NULL; 256 m_pStream = NULL;
261 } 257 }
262 m_pStream = pFileRead; 258 m_pStream = pFileRead;
263 m_bOwnStream = TRUE; 259 m_bOwnStream = TRUE;
264 return TRUE; 260 return TRUE;
265 } 261 }
266 FX_BOOL CXFA_FFDoc::CloseDoc() { 262 FX_BOOL CXFA_FFDoc::CloseDoc() {
267 FX_POSITION psClose = m_mapTypeToDocView.GetStartPosition(); 263 for (const auto& pair : m_TypeToDocViewMap)
268 while (psClose) { 264 pair.second->RunDocClose();
269 void* pType; 265
270 CXFA_FFDocView* pDocView; 266 if (m_pDocument)
271 m_mapTypeToDocView.GetNextAssoc(psClose, pType, (void*&)pDocView); 267 m_pDocument->ClearLayoutData();
272 pDocView->RunDocClose(); 268
269 for (const auto& pair : m_TypeToDocViewMap)
270 delete pair.second;
271
272 m_TypeToDocViewMap.clear();
273
274 if (m_pDocument) {
275 m_pDocument->GetParser()->Release();
276 m_pDocument = nullptr;
273 } 277 }
274 if (m_pDocument) { 278
275 m_pDocument->ClearLayoutData(); 279 delete m_pNotify;
276 } 280 m_pNotify = nullptr;
277 FX_POSITION ps = m_mapTypeToDocView.GetStartPosition(); 281
278 while (ps) {
279 void* pType;
280 CXFA_FFDocView* pDocView;
281 m_mapTypeToDocView.GetNextAssoc(ps, pType, (void*&)pDocView);
282 delete pDocView;
283 }
284 m_mapTypeToDocView.RemoveAll();
285 if (m_pDocument) {
286 IXFA_Parser* pParser = m_pDocument->GetParser();
287 pParser->Release();
288 m_pDocument = NULL;
289 }
290 if (m_pNotify) {
291 delete m_pNotify;
292 m_pNotify = NULL;
293 }
294 m_pApp->GetXFAFontMgr()->ReleaseDocFonts(this); 282 m_pApp->GetXFAFontMgr()->ReleaseDocFonts(this);
283
295 if (m_dwDocType != XFA_DOCTYPE_XDP && m_pStream && m_bOwnStream) { 284 if (m_dwDocType != XFA_DOCTYPE_XDP && m_pStream && m_bOwnStream) {
296 m_pStream->Release(); 285 m_pStream->Release();
297 m_pStream = NULL; 286 m_pStream = nullptr;
298 } 287 }
299 ps = m_mapNamedImages.GetStartPosition(); 288
300 while (ps) { 289 for (const auto& pair : m_HashToDibDpiMap)
301 void* pName; 290 delete pair.second.pDibSource;
302 FX_IMAGEDIB_AND_DPI* pImage = NULL; 291
303 m_mapNamedImages.GetNextAssoc(ps, pName, (void*&)pImage); 292 m_HashToDibDpiMap.clear();
304 if (pImage) { 293
305 delete pImage->pDibSource; 294 FWL_GetApp()->GetNoteDriver()->ClearEventTargets(FALSE);
306 pImage->pDibSource = NULL;
307 FX_Free(pImage);
308 pImage = NULL;
309 }
310 }
311 m_mapNamedImages.RemoveAll();
312 IFWL_NoteDriver* pNoteDriver = FWL_GetApp()->GetNoteDriver();
313 pNoteDriver->ClearEventTargets(FALSE);
314 return TRUE; 295 return TRUE;
315 } 296 }
316 void CXFA_FFDoc::SetDocType(uint32_t dwType) { 297 void CXFA_FFDoc::SetDocType(uint32_t dwType) {
317 m_dwDocType = dwType; 298 m_dwDocType = dwType;
318 } 299 }
319 CPDF_Document* CXFA_FFDoc::GetPDFDoc() { 300 CPDF_Document* CXFA_FFDoc::GetPDFDoc() {
320 return m_pPDFDoc; 301 return m_pPDFDoc;
321 } 302 }
322 303
323 CFX_DIBitmap* CXFA_FFDoc::GetPDFNamedImage(const CFX_WideStringC& wsName, 304 CFX_DIBitmap* CXFA_FFDoc::GetPDFNamedImage(const CFX_WideStringC& wsName,
Tom Sepez 2016/04/22 19:16:41 Should this just return a DIBDPI struct?
Tom Sepez 2016/04/22 21:51:40 Ah, lets just leave it for the moment.
324 int32_t& iImageXDpi, 305 int32_t& iImageXDpi,
325 int32_t& iImageYDpi) { 306 int32_t& iImageYDpi) {
326 if (!m_pPDFDoc) 307 if (!m_pPDFDoc)
327 return nullptr; 308 return nullptr;
328 309
329 uint32_t dwHash = 310 uint32_t dwHash =
330 FX_HashCode_String_GetW(wsName.c_str(), wsName.GetLength(), FALSE); 311 FX_HashCode_String_GetW(wsName.c_str(), wsName.GetLength(), FALSE);
331 FX_IMAGEDIB_AND_DPI* imageDIBDpi = nullptr; 312 auto it = m_HashToDibDpiMap.find(dwHash);
332 if (m_mapNamedImages.Lookup((void*)(uintptr_t)dwHash, (void*&)imageDIBDpi)) { 313 if (it != m_HashToDibDpiMap.end()) {
333 iImageXDpi = imageDIBDpi->iImageXDpi; 314 iImageXDpi = it->second.iImageXDpi;
334 iImageYDpi = imageDIBDpi->iImageYDpi; 315 iImageYDpi = it->second.iImageYDpi;
335 return static_cast<CFX_DIBitmap*>(imageDIBDpi->pDibSource); 316 return static_cast<CFX_DIBitmap*>(it->second.pDibSource);
336 } 317 }
337 318
338 CPDF_Dictionary* pRoot = m_pPDFDoc->GetRoot(); 319 CPDF_Dictionary* pRoot = m_pPDFDoc->GetRoot();
339 if (!pRoot) 320 if (!pRoot)
340 return nullptr; 321 return nullptr;
341 322
342 CPDF_Dictionary* pNames = pRoot->GetDictBy("Names"); 323 CPDF_Dictionary* pNames = pRoot->GetDictBy("Names");
343 if (!pNames) 324 if (!pNames)
344 return nullptr; 325 return nullptr;
345 326
346 CPDF_Dictionary* pXFAImages = pNames->GetDictBy("XFAImages"); 327 CPDF_Dictionary* pXFAImages = pNames->GetDictBy("XFAImages");
347 if (!pXFAImages) 328 if (!pXFAImages)
348 return nullptr; 329 return nullptr;
349 330
350 CPDF_NameTree nametree(pXFAImages); 331 CPDF_NameTree nametree(pXFAImages);
351 CFX_ByteString bsName = PDF_EncodeText(wsName.c_str(), wsName.GetLength()); 332 CFX_ByteString bsName = PDF_EncodeText(wsName.c_str(), wsName.GetLength());
352 CPDF_Object* pObject = nametree.LookupValue(bsName); 333 CPDF_Object* pObject = nametree.LookupValue(bsName);
353 if (!pObject) { 334 if (!pObject) {
354 for (size_t i = 0; i < nametree.GetCount(); i++) { 335 for (size_t i = 0; i < nametree.GetCount(); i++) {
355 CFX_ByteString bsTemp; 336 CFX_ByteString bsTemp;
356 CPDF_Object* pTempObject = nametree.LookupValue(i, bsTemp); 337 CPDF_Object* pTempObject = nametree.LookupValue(i, bsTemp);
357 if (bsTemp == bsName) { 338 if (bsTemp == bsName) {
358 pObject = pTempObject; 339 pObject = pTempObject;
359 break; 340 break;
360 } 341 }
361 } 342 }
362 } 343 }
363 344
364 if (!pObject || !pObject->IsStream()) 345 if (!pObject || !pObject->IsStream())
Lei Zhang 2016/04/22 23:37:50 CPDF_Stream* pStream = ToStream(pObject); if (!pSt
Tom Sepez 2016/04/25 18:23:06 Done.
365 return nullptr; 346 return nullptr;
366 347
367 if (!imageDIBDpi) { 348 CPDF_StreamAcc streamAcc;
368 imageDIBDpi = FX_Alloc(FX_IMAGEDIB_AND_DPI, 1); 349 streamAcc.LoadAllData((CPDF_Stream*)pObject);
369 imageDIBDpi->pDibSource = nullptr; 350
370 imageDIBDpi->iImageXDpi = 0; 351 IFX_FileRead* pImageFileRead =
371 imageDIBDpi->iImageYDpi = 0; 352 FX_CreateMemoryStream((uint8_t*)streamAcc.GetData(), streamAcc.GetSize());
372 CPDF_StreamAcc streamAcc; 353
373 streamAcc.LoadAllData((CPDF_Stream*)pObject); 354 CFX_DIBitmap* pDibSource = XFA_LoadImageFromBuffer(
374 IFX_FileRead* pImageFileRead = FX_CreateMemoryStream( 355 pImageFileRead, FXCODEC_IMAGE_UNKNOWN, iImageXDpi, iImageYDpi);
375 (uint8_t*)streamAcc.GetData(), streamAcc.GetSize()); 356 m_HashToDibDpiMap[dwHash] = {pDibSource, iImageXDpi, iImageYDpi};
376 imageDIBDpi->pDibSource = XFA_LoadImageFromBuffer( 357 pImageFileRead->Release();
377 pImageFileRead, FXCODEC_IMAGE_UNKNOWN, iImageXDpi, iImageYDpi); 358 return pDibSource;
378 imageDIBDpi->iImageXDpi = iImageXDpi;
379 imageDIBDpi->iImageYDpi = iImageYDpi;
380 pImageFileRead->Release();
381 }
382 m_mapNamedImages.SetAt((void*)(uintptr_t)dwHash, imageDIBDpi);
383 return (CFX_DIBitmap*)imageDIBDpi->pDibSource;
384 } 359 }
385 360
386 CFDE_XMLElement* CXFA_FFDoc::GetPackageData(const CFX_WideStringC& wsPackage) { 361 CFDE_XMLElement* CXFA_FFDoc::GetPackageData(const CFX_WideStringC& wsPackage) {
387 uint32_t packetHash = 362 uint32_t packetHash =
388 FX_HashCode_String_GetW(wsPackage.c_str(), wsPackage.GetLength()); 363 FX_HashCode_String_GetW(wsPackage.c_str(), wsPackage.GetLength());
389 CXFA_Node* pNode = ToNode(m_pDocument->GetXFAObject(packetHash)); 364 CXFA_Node* pNode = ToNode(m_pDocument->GetXFAObject(packetHash));
390 if (!pNode) { 365 if (!pNode) {
391 return NULL; 366 return NULL;
392 } 367 }
393 CFDE_XMLNode* pXMLNode = pNode->GetXMLMappingNode(); 368 CFDE_XMLNode* pXMLNode = pNode->GetXMLMappingNode();
(...skipping 26 matching lines...) Expand all
420 } 395 }
421 pExport->Release(); 396 pExport->Release();
422 return bFlags; 397 return bFlags;
423 } 398 }
424 FX_BOOL CXFA_FFDoc::ImportData(IFX_FileRead* pStream, FX_BOOL bXDP) { 399 FX_BOOL CXFA_FFDoc::ImportData(IFX_FileRead* pStream, FX_BOOL bXDP) {
425 std::unique_ptr<CXFA_DataImporter, ReleaseDeleter<CXFA_DataImporter>> 400 std::unique_ptr<CXFA_DataImporter, ReleaseDeleter<CXFA_DataImporter>>
426 importer(new CXFA_DataImporter(m_pDocument)); 401 importer(new CXFA_DataImporter(m_pDocument));
427 402
428 return importer->ImportData(pStream); 403 return importer->ImportData(pStream);
429 } 404 }
OLDNEW
« no previous file with comments | « no previous file | xfa/fxfa/include/xfa_ffdoc.h » ('j') | xfa/fxfa/include/xfa_ffdoc.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698