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

Side by Side Diff: core/src/fpdfdoc/doc_utils.cpp

Issue 1529553003: Merge to XFA: Get rid of most instance of 'foo != NULL' (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 5 years 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 "core/include/fpdfdoc/fpdf_doc.h" 7 #include "core/include/fpdfdoc/fpdf_doc.h"
8 #include "doc_utils.h" 8 #include "doc_utils.h"
9 9
10 static const int FPDFDOC_UTILS_MAXRECURSION = 32; 10 static const int FPDFDOC_UTILS_MAXRECURSION = 32;
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 FX_DWORD dwObjNum = pDocument->AddIndirectObject(pFormDict); 235 FX_DWORD dwObjNum = pDocument->AddIndirectObject(pFormDict);
236 CPDF_Dictionary* pRoot = pDocument->GetRoot(); 236 CPDF_Dictionary* pRoot = pDocument->GetRoot();
237 pRoot->SetAtReference("AcroForm", pDocument, dwObjNum); 237 pRoot->SetAtReference("AcroForm", pDocument, dwObjNum);
238 } 238 }
239 CFX_ByteString csDA; 239 CFX_ByteString csDA;
240 if (!pFormDict->KeyExist("DR")) { 240 if (!pFormDict->KeyExist("DR")) {
241 CPDF_Font* pFont = NULL; 241 CPDF_Font* pFont = NULL;
242 CFX_ByteString csBaseName, csDefault; 242 CFX_ByteString csBaseName, csDefault;
243 uint8_t charSet = CPDF_InterForm::GetNativeCharSet(); 243 uint8_t charSet = CPDF_InterForm::GetNativeCharSet();
244 pFont = CPDF_InterForm::AddStandardFont(pDocument, "Helvetica"); 244 pFont = CPDF_InterForm::AddStandardFont(pDocument, "Helvetica");
245 if (pFont != NULL) { 245 if (pFont) {
246 AddInterFormFont(pFormDict, pDocument, pFont, csBaseName); 246 AddInterFormFont(pFormDict, pDocument, pFont, csBaseName);
247 csDefault = csBaseName; 247 csDefault = csBaseName;
248 } 248 }
249 if (charSet != 0) { 249 if (charSet != 0) {
250 CFX_ByteString csFontName = CPDF_InterForm::GetNativeFont(charSet, NULL); 250 CFX_ByteString csFontName = CPDF_InterForm::GetNativeFont(charSet, NULL);
251 if (pFont == NULL || csFontName != "Helvetica") { 251 if (pFont == NULL || csFontName != "Helvetica") {
252 pFont = CPDF_InterForm::AddNativeFont(pDocument); 252 pFont = CPDF_InterForm::AddNativeFont(pDocument);
253 if (pFont != NULL) { 253 if (pFont) {
254 csBaseName = ""; 254 csBaseName = "";
255 AddInterFormFont(pFormDict, pDocument, pFont, csBaseName); 255 AddInterFormFont(pFormDict, pDocument, pFont, csBaseName);
256 csDefault = csBaseName; 256 csDefault = csBaseName;
257 } 257 }
258 } 258 }
259 } 259 }
260 if (pFont != NULL) { 260 if (pFont) {
261 csDA = "/" + PDF_NameEncode(csDefault) + " 0 Tf"; 261 csDA = "/" + PDF_NameEncode(csDefault) + " 0 Tf";
262 } 262 }
263 } 263 }
264 if (!csDA.IsEmpty()) { 264 if (!csDA.IsEmpty()) {
265 csDA += " "; 265 csDA += " ";
266 } 266 }
267 csDA += "0 g"; 267 csDA += "0 g";
268 if (!pFormDict->KeyExist("DA")) { 268 if (!pFormDict->KeyExist("DA")) {
269 pFormDict->SetAtString("DA", csDA); 269 pFormDict->SetAtString("DA", csDA);
270 } 270 }
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 } 445 }
446 return NULL; 446 return NULL;
447 } 447 }
448 CPDF_Font* GetNativeInterFormFont(CPDF_Dictionary* pFormDict, 448 CPDF_Font* GetNativeInterFormFont(CPDF_Dictionary* pFormDict,
449 CPDF_Document* pDocument, 449 CPDF_Document* pDocument,
450 CFX_ByteString& csNameTag) { 450 CFX_ByteString& csNameTag) {
451 csNameTag = ""; 451 csNameTag = "";
452 uint8_t charSet = CPDF_InterForm::GetNativeCharSet(); 452 uint8_t charSet = CPDF_InterForm::GetNativeCharSet();
453 CFX_SubstFont* pSubst; 453 CFX_SubstFont* pSubst;
454 CPDF_Font* pFont = GetDefaultInterFormFont(pFormDict, pDocument); 454 CPDF_Font* pFont = GetDefaultInterFormFont(pFormDict, pDocument);
455 if (pFont != NULL) { 455 if (pFont) {
456 pSubst = (CFX_SubstFont*)pFont->GetSubstFont(); 456 pSubst = (CFX_SubstFont*)pFont->GetSubstFont();
457 if (pSubst != NULL && pSubst->m_Charset == (int)charSet) { 457 if (pSubst && pSubst->m_Charset == (int)charSet) {
458 FindInterFormFont(pFormDict, pFont, csNameTag); 458 FindInterFormFont(pFormDict, pFont, csNameTag);
459 return pFont; 459 return pFont;
460 } 460 }
461 } 461 }
462 return GetNativeInterFormFont(pFormDict, pDocument, charSet, csNameTag); 462 return GetNativeInterFormFont(pFormDict, pDocument, charSet, csNameTag);
463 } 463 }
464 FX_BOOL FindInterFormFont(CPDF_Dictionary* pFormDict, 464 FX_BOOL FindInterFormFont(CPDF_Dictionary* pFormDict,
465 const CPDF_Font* pFont, 465 const CPDF_Font* pFont,
466 CFX_ByteString& csNameTag) { 466 CFX_ByteString& csNameTag) {
467 if (pFormDict == NULL || pFont == NULL) { 467 if (pFormDict == NULL || pFont == NULL) {
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 CPDF_Font* AddNativeInterFormFont(CPDF_Dictionary*& pFormDict, 585 CPDF_Font* AddNativeInterFormFont(CPDF_Dictionary*& pFormDict,
586 CPDF_Document* pDocument, 586 CPDF_Document* pDocument,
587 uint8_t charSet, 587 uint8_t charSet,
588 CFX_ByteString& csNameTag) { 588 CFX_ByteString& csNameTag) {
589 if (pFormDict == NULL) { 589 if (pFormDict == NULL) {
590 InitInterFormDict(pFormDict, pDocument); 590 InitInterFormDict(pFormDict, pDocument);
591 } 591 }
592 CFX_ByteString csTemp; 592 CFX_ByteString csTemp;
593 CPDF_Font* pFont = 593 CPDF_Font* pFont =
594 GetNativeInterFormFont(pFormDict, pDocument, charSet, csTemp); 594 GetNativeInterFormFont(pFormDict, pDocument, charSet, csTemp);
595 if (pFont != NULL) { 595 if (pFont) {
596 csNameTag = csTemp; 596 csNameTag = csTemp;
597 return pFont; 597 return pFont;
598 } 598 }
599 CFX_ByteString csFontName = CPDF_InterForm::GetNativeFont(charSet); 599 CFX_ByteString csFontName = CPDF_InterForm::GetNativeFont(charSet);
600 if (!csFontName.IsEmpty()) { 600 if (!csFontName.IsEmpty()) {
601 if (FindInterFormFont(pFormDict, pDocument, csFontName, pFont, csNameTag)) { 601 if (FindInterFormFont(pFormDict, pDocument, csFontName, pFont, csNameTag)) {
602 return pFont; 602 return pFont;
603 } 603 }
604 } 604 }
605 pFont = CPDF_InterForm::AddNativeFont(charSet, pDocument); 605 pFont = CPDF_InterForm::AddNativeFont(charSet, pDocument);
606 if (pFont != NULL) { 606 if (pFont) {
607 AddInterFormFont(pFormDict, pDocument, pFont, csNameTag); 607 AddInterFormFont(pFormDict, pDocument, pFont, csNameTag);
608 } 608 }
609 return pFont; 609 return pFont;
610 } 610 }
611 CPDF_Font* AddNativeInterFormFont(CPDF_Dictionary*& pFormDict, 611 CPDF_Font* AddNativeInterFormFont(CPDF_Dictionary*& pFormDict,
612 CPDF_Document* pDocument, 612 CPDF_Document* pDocument,
613 CFX_ByteString& csNameTag) { 613 CFX_ByteString& csNameTag) {
614 uint8_t charSet = CPDF_InterForm::GetNativeCharSet(); 614 uint8_t charSet = CPDF_InterForm::GetNativeCharSet();
615 return AddNativeInterFormFont(pFormDict, pDocument, charSet, csNameTag); 615 return AddNativeInterFormFont(pFormDict, pDocument, charSet, csNameTag);
616 } 616 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 return TRUE; 672 return TRUE;
673 } 673 }
674 return m_pDict->GetString("S", "P") != "A"; 674 return m_pDict->GetString("S", "P") != "A";
675 } 675 }
676 void CPDF_IconFit::GetIconPosition(FX_FLOAT& fLeft, FX_FLOAT& fBottom) { 676 void CPDF_IconFit::GetIconPosition(FX_FLOAT& fLeft, FX_FLOAT& fBottom) {
677 fLeft = fBottom = 0.5; 677 fLeft = fBottom = 0.5;
678 if (m_pDict == NULL) { 678 if (m_pDict == NULL) {
679 return; 679 return;
680 } 680 }
681 CPDF_Array* pA = m_pDict->GetArray("A"); 681 CPDF_Array* pA = m_pDict->GetArray("A");
682 if (pA != NULL) { 682 if (pA) {
683 FX_DWORD dwCount = pA->GetCount(); 683 FX_DWORD dwCount = pA->GetCount();
684 if (dwCount > 0) { 684 if (dwCount > 0) {
685 fLeft = pA->GetNumber(0); 685 fLeft = pA->GetNumber(0);
686 } 686 }
687 if (dwCount > 1) { 687 if (dwCount > 1) {
688 fBottom = pA->GetNumber(1); 688 fBottom = pA->GetNumber(1);
689 } 689 }
690 } 690 }
691 } 691 }
692 FX_BOOL CPDF_IconFit::GetFittingBounds() { 692 FX_BOOL CPDF_IconFit::GetFittingBounds() {
(...skipping 25 matching lines...) Expand all
718 CPDF_Object* pAttr = pFieldDict->GetElementValue(name); 718 CPDF_Object* pAttr = pFieldDict->GetElementValue(name);
719 if (pAttr) { 719 if (pAttr) {
720 return pAttr; 720 return pAttr;
721 } 721 }
722 CPDF_Dictionary* pParent = pFieldDict->GetDict("Parent"); 722 CPDF_Dictionary* pParent = pFieldDict->GetDict("Parent");
723 if (pParent == NULL) { 723 if (pParent == NULL) {
724 return NULL; 724 return NULL;
725 } 725 }
726 return FPDF_GetFieldAttr(pParent, name, nLevel + 1); 726 return FPDF_GetFieldAttr(pParent, name, nLevel + 1);
727 } 727 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698