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

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

Issue 1520063002: Get rid of most instance of 'foo == NULL' (Closed) Base URL: https://pdfium.googlesource.com/pdfium@bstr_isnull
Patch Set: rebase 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
« no previous file with comments | « core/src/fpdfdoc/doc_annot.cpp ('k') | core/src/fpdfdoc/doc_basic.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 "core/include/fpdfdoc/fpdf_ap.h" 7 #include "core/include/fpdfdoc/fpdf_ap.h"
8 #include "core/include/fpdfdoc/fpdf_doc.h" 8 #include "core/include/fpdfdoc/fpdf_doc.h"
9 #include "core/include/fpdfdoc/fpdf_vt.h" 9 #include "core/include/fpdfdoc/fpdf_vt.h"
10 #include "doc_utils.h" 10 #include "doc_utils.h"
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 CFX_ByteString sFontName = syntax.GetWord(); 285 CFX_ByteString sFontName = syntax.GetWord();
286 sFontName = PDF_NameDecode(sFontName); 286 sFontName = PDF_NameDecode(sFontName);
287 if (sFontName.IsEmpty()) { 287 if (sFontName.IsEmpty()) {
288 return FALSE; 288 return FALSE;
289 } 289 }
290 FX_FLOAT fFontSize = FX_atof(syntax.GetWord()); 290 FX_FLOAT fFontSize = FX_atof(syntax.GetWord());
291 CPVT_Color crText = ParseColor(DA); 291 CPVT_Color crText = ParseColor(DA);
292 FX_BOOL bUseFormRes = FALSE; 292 FX_BOOL bUseFormRes = FALSE;
293 CPDF_Dictionary* pFontDict = NULL; 293 CPDF_Dictionary* pFontDict = NULL;
294 CPDF_Dictionary* pDRDict = pAnnotDict->GetDict("DR"); 294 CPDF_Dictionary* pDRDict = pAnnotDict->GetDict("DR");
295 if (pDRDict == NULL) { 295 if (!pDRDict) {
296 pDRDict = pFormDict->GetDict("DR"); 296 pDRDict = pFormDict->GetDict("DR");
297 bUseFormRes = TRUE; 297 bUseFormRes = TRUE;
298 } 298 }
299 CPDF_Dictionary* pDRFontDict = NULL; 299 CPDF_Dictionary* pDRFontDict = NULL;
300 if (pDRDict && (pDRFontDict = pDRDict->GetDict("Font"))) { 300 if (pDRDict && (pDRFontDict = pDRDict->GetDict("Font"))) {
301 pFontDict = pDRFontDict->GetDict(sFontName.Mid(1)); 301 pFontDict = pDRFontDict->GetDict(sFontName.Mid(1));
302 if (!pFontDict && !bUseFormRes) { 302 if (!pFontDict && !bUseFormRes) {
303 pDRDict = pFormDict->GetDict("DR"); 303 pDRDict = pFormDict->GetDict("DR");
304 pDRFontDict = pDRDict->GetDict("Font"); 304 pDRFontDict = pDRDict->GetDict("Font");
305 if (pDRFontDict) { 305 if (pDRFontDict) {
306 pFontDict = pDRFontDict->GetDict(sFontName.Mid(1)); 306 pFontDict = pDRFontDict->GetDict(sFontName.Mid(1));
307 } 307 }
308 } 308 }
309 } 309 }
310 if (!pDRFontDict) { 310 if (!pDRFontDict) {
311 return FALSE; 311 return FALSE;
312 } 312 }
313 if (!pFontDict) { 313 if (!pFontDict) {
314 pFontDict = CPDF_Dictionary::Create(); 314 pFontDict = CPDF_Dictionary::Create();
315 if (pFontDict == NULL) { 315 if (!pFontDict) {
316 return FALSE; 316 return FALSE;
317 } 317 }
318 pFontDict->SetAtName("Type", "Font"); 318 pFontDict->SetAtName("Type", "Font");
319 pFontDict->SetAtName("Subtype", "Type1"); 319 pFontDict->SetAtName("Subtype", "Type1");
320 pFontDict->SetAtName("BaseFont", "Helvetica"); 320 pFontDict->SetAtName("BaseFont", "Helvetica");
321 pFontDict->SetAtName("Encoding", "WinAnsiEncoding"); 321 pFontDict->SetAtName("Encoding", "WinAnsiEncoding");
322 pDoc->AddIndirectObject(pFontDict); 322 pDoc->AddIndirectObject(pFontDict);
323 pDRFontDict->SetAtReference(sFontName.Mid(1), pDoc, pFontDict); 323 pDRFontDict->SetAtReference(sFontName.Mid(1), pDoc, pFontDict);
324 } 324 }
325 CPDF_Font* pDefFont = pDoc->LoadFont(pFontDict); 325 CPDF_Font* pDefFont = pDoc->LoadFont(pFontDict);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 rcBBox, fBorderWidth, crBorder, crLeftTop, crRightBottom, nBorderStyle, 411 rcBBox, fBorderWidth, crBorder, crLeftTop, crRightBottom, nBorderStyle,
412 dsBorder); 412 dsBorder);
413 if (sBorderStream.GetLength() > 0) { 413 if (sBorderStream.GetLength() > 0) {
414 sAppStream << "q\n" << sBorderStream << "Q\n"; 414 sAppStream << "q\n" << sBorderStream << "Q\n";
415 } 415 }
416 CPDF_Rect rcBody = 416 CPDF_Rect rcBody =
417 CPDF_Rect(rcBBox.left + fBorderWidth, rcBBox.bottom + fBorderWidth, 417 CPDF_Rect(rcBBox.left + fBorderWidth, rcBBox.bottom + fBorderWidth,
418 rcBBox.right - fBorderWidth, rcBBox.top - fBorderWidth); 418 rcBBox.right - fBorderWidth, rcBBox.top - fBorderWidth);
419 rcBody.Normalize(); 419 rcBody.Normalize();
420 CPDF_Dictionary* pAPDict = pAnnotDict->GetDict("AP"); 420 CPDF_Dictionary* pAPDict = pAnnotDict->GetDict("AP");
421 if (pAPDict == NULL) { 421 if (!pAPDict) {
422 pAPDict = CPDF_Dictionary::Create(); 422 pAPDict = CPDF_Dictionary::Create();
423 if (pAPDict == NULL) {
424 return FALSE;
425 }
426 pAnnotDict->SetAt("AP", pAPDict); 423 pAnnotDict->SetAt("AP", pAPDict);
427 } 424 }
428 CPDF_Stream* pNormalStream = pAPDict->GetStream("N"); 425 CPDF_Stream* pNormalStream = pAPDict->GetStream("N");
429 if (!pNormalStream) { 426 if (!pNormalStream) {
430 pNormalStream = new CPDF_Stream(nullptr, 0, nullptr); 427 pNormalStream = new CPDF_Stream(nullptr, 0, nullptr);
431 int32_t objnum = pDoc->AddIndirectObject(pNormalStream); 428 int32_t objnum = pDoc->AddIndirectObject(pNormalStream);
432 pAnnotDict->GetDict("AP")->SetAtReference("N", pDoc, objnum); 429 pAnnotDict->GetDict("AP")->SetAtReference("N", pDoc, objnum);
433 } 430 }
434 CPDF_Dictionary* pStreamDict = pNormalStream->GetDict(); 431 CPDF_Dictionary* pStreamDict = pNormalStream->GetDict();
435 if (pStreamDict) { 432 if (pStreamDict) {
436 pStreamDict->SetAtMatrix("Matrix", matrix); 433 pStreamDict->SetAtMatrix("Matrix", matrix);
437 pStreamDict->SetAtRect("BBox", rcBBox); 434 pStreamDict->SetAtRect("BBox", rcBBox);
438 CPDF_Dictionary* pStreamResList = pStreamDict->GetDict("Resources"); 435 CPDF_Dictionary* pStreamResList = pStreamDict->GetDict("Resources");
439 if (pStreamResList) { 436 if (pStreamResList) {
440 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDict("Font"); 437 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDict("Font");
441 if (!pStreamResFontList) { 438 if (!pStreamResFontList) {
442 pStreamResFontList = CPDF_Dictionary::Create(); 439 pStreamResFontList = CPDF_Dictionary::Create();
443 if (pStreamResFontList == NULL) { 440 if (!pStreamResFontList) {
444 return FALSE; 441 return FALSE;
445 } 442 }
446 pStreamResList->SetAt("Font", pStreamResFontList); 443 pStreamResList->SetAt("Font", pStreamResFontList);
447 } 444 }
448 if (!pStreamResFontList->KeyExist(sFontName)) { 445 if (!pStreamResFontList->KeyExist(sFontName)) {
449 pStreamResFontList->SetAtReference(sFontName, pDoc, pFontDict); 446 pStreamResFontList->SetAtReference(sFontName, pDoc, pFontDict);
450 } 447 }
451 } else { 448 } else {
452 pStreamDict->SetAt("Resources", pFormDict->GetDict("DR")->Clone()); 449 pStreamDict->SetAt("Resources", pFormDict->GetDict("DR")->Clone());
453 pStreamResList = pStreamDict->GetDict("Resources"); 450 pStreamResList = pStreamDict->GetDict("Resources");
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 sAppStream.GetSize(), FALSE, FALSE); 678 sAppStream.GetSize(), FALSE, FALSE);
682 pStreamDict = pNormalStream->GetDict(); 679 pStreamDict = pNormalStream->GetDict();
683 if (pStreamDict) { 680 if (pStreamDict) {
684 pStreamDict->SetAtMatrix("Matrix", matrix); 681 pStreamDict->SetAtMatrix("Matrix", matrix);
685 pStreamDict->SetAtRect("BBox", rcBBox); 682 pStreamDict->SetAtRect("BBox", rcBBox);
686 CPDF_Dictionary* pStreamResList = pStreamDict->GetDict("Resources"); 683 CPDF_Dictionary* pStreamResList = pStreamDict->GetDict("Resources");
687 if (pStreamResList) { 684 if (pStreamResList) {
688 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDict("Font"); 685 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDict("Font");
689 if (!pStreamResFontList) { 686 if (!pStreamResFontList) {
690 pStreamResFontList = CPDF_Dictionary::Create(); 687 pStreamResFontList = CPDF_Dictionary::Create();
691 if (pStreamResFontList == NULL) { 688 if (!pStreamResFontList) {
692 return FALSE; 689 return FALSE;
693 } 690 }
694 pStreamResList->SetAt("Font", pStreamResFontList); 691 pStreamResList->SetAt("Font", pStreamResFontList);
695 } 692 }
696 if (!pStreamResFontList->KeyExist(sFontName)) { 693 if (!pStreamResFontList->KeyExist(sFontName)) {
697 pStreamResFontList->SetAtReference(sFontName, pDoc, pFontDict); 694 pStreamResFontList->SetAtReference(sFontName, pDoc, pFontDict);
698 } 695 }
699 } else { 696 } else {
700 pStreamDict->SetAt("Resources", pFormDict->GetDict("DR")->Clone()); 697 pStreamDict->SetAt("Resources", pFormDict->GetDict("DR")->Clone());
701 pStreamResList = pStreamDict->GetDict("Resources"); 698 pStreamResList = pStreamDict->GetDict("Resources");
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
925 << "\n"; 922 << "\n";
926 break; 923 break;
927 case CT_CMYK: 924 case CT_CMYK:
928 sColorStream << color.fColor1 << " " << color.fColor2 << " " 925 sColorStream << color.fColor1 << " " << color.fColor2 << " "
929 << color.fColor3 << " " << color.fColor4 << " " 926 << color.fColor3 << " " << color.fColor4 << " "
930 << (bFillOrStroke ? "k" : "K") << "\n"; 927 << (bFillOrStroke ? "k" : "K") << "\n";
931 break; 928 break;
932 } 929 }
933 return sColorStream.GetByteString(); 930 return sColorStream.GetByteString();
934 } 931 }
OLDNEW
« no previous file with comments | « core/src/fpdfdoc/doc_annot.cpp ('k') | core/src/fpdfdoc/doc_basic.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698