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

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

Issue 361553002: Remove "this==NULL" and adjust corresponding callers (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: fix if check warning Created 6 years, 5 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 | « 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 "../../include/fpdfdoc/fpdf_doc.h" 7 #include "../../include/fpdfdoc/fpdf_doc.h"
8 #include "../../include/fpdfdoc/fpdf_vt.h" 8 #include "../../include/fpdfdoc/fpdf_vt.h"
9 #include "pdf_vt.h" 9 #include "pdf_vt.h"
10 #include "../../include/fpdfdoc/fpdf_ap.h" 10 #include "../../include/fpdfdoc/fpdf_ap.h"
11 FX_BOOL FPDF_GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) 11 FX_BOOL FPDF_GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict)
12 { 12 {
13 if (pAnnotDict->GetConstString("Subtype") != FX_BSTRC("Widget")) { 13 if (!pAnnotDict || pAnnotDict->GetConstString("Subtype") != FX_BSTRC("Widget ")) {
14 return FALSE; 14 return FALSE;
15 } 15 }
16 CFX_ByteString field_type = FPDF_GetFieldAttr(pAnnotDict, "FT")->GetString() ; 16 CFX_ByteString field_type = FPDF_GetFieldAttr(pAnnotDict, "FT")->GetString() ;
17 FX_DWORD flags = FPDF_GetFieldAttr(pAnnotDict, "Ff")->GetInteger(); 17 FX_DWORD flags = FPDF_GetFieldAttr(pAnnotDict, "Ff")? FPDF_GetFieldAttr(pAnn otDict, "Ff")->GetInteger() : 0;
18 if (field_type == "Tx") { 18 if (field_type == "Tx") {
19 return CPVT_GenerateAP::GenerateTextFieldAP(pDoc, pAnnotDict); 19 return CPVT_GenerateAP::GenerateTextFieldAP(pDoc, pAnnotDict);
20 } else if (field_type == "Ch") { 20 } else if (field_type == "Ch") {
21 if (flags & (1 << 17)) { 21 if (flags & (1 << 17)) {
22 return CPVT_GenerateAP::GenerateComboBoxAP(pDoc, pAnnotDict); 22 return CPVT_GenerateAP::GenerateComboBoxAP(pDoc, pAnnotDict);
23 } else { 23 } else {
24 return CPVT_GenerateAP::GenerateListBoxAP(pDoc, pAnnotDict); 24 return CPVT_GenerateAP::GenerateListBoxAP(pDoc, pAnnotDict);
25 } 25 }
26 } else if (field_type == "Btn") { 26 } else if (field_type == "Btn") {
27 if (!(flags & (1 << 16))) { 27 if (!(flags & (1 << 16))) {
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 } 246 }
247 static FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict , const FX_INT32 & nWidgetType) 247 static FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict , const FX_INT32 & nWidgetType)
248 { 248 {
249 CPDF_Dictionary* pFormDict = NULL; 249 CPDF_Dictionary* pFormDict = NULL;
250 if (CPDF_Dictionary * pRootDict = pDoc->GetRoot()) { 250 if (CPDF_Dictionary * pRootDict = pDoc->GetRoot()) {
251 pFormDict = pRootDict->GetDict("AcroForm"); 251 pFormDict = pRootDict->GetDict("AcroForm");
252 } 252 }
253 if (!pFormDict) { 253 if (!pFormDict) {
254 return FALSE; 254 return FALSE;
255 } 255 }
256 CFX_ByteString DA = FPDF_GetFieldAttr(pAnnotDict, "DA")->GetString(); 256 CFX_ByteString DA = FPDF_GetFieldAttr(pAnnotDict, "DA") ? FPDF_GetFieldAttr( pAnnotDict, "DA")->GetString() : CFX_ByteString();
257 if (DA.IsEmpty()) { 257 if (DA.IsEmpty()) {
258 DA = pFormDict->GetString("DA"); 258 DA = pFormDict->GetString("DA");
259 } 259 }
260 if (DA.IsEmpty()) { 260 if (DA.IsEmpty()) {
261 return FALSE; 261 return FALSE;
262 } 262 }
263 CPDF_SimpleParser syntax(DA); 263 CPDF_SimpleParser syntax(DA);
264 syntax.FindTagParam("Tf", 2); 264 syntax.FindTagParam("Tf", 2);
265 CFX_ByteString sFontName = syntax.GetWord(); 265 CFX_ByteString sFontName = syntax.GetWord();
266 sFontName = PDF_NameDecode(sFontName); 266 sFontName = PDF_NameDecode(sFontName);
267 if (sFontName.IsEmpty()) { 267 if (sFontName.IsEmpty()) {
268 return FALSE; 268 return FALSE;
269 } 269 }
270 FX_FLOAT fFontSize = FX_atof(syntax.GetWord()); 270 FX_FLOAT fFontSize = FX_atof(syntax.GetWord());
271 CPVT_Color crText = ParseColor(DA); 271 CPVT_Color crText = ParseColor(DA);
272 FX_BOOL bUseFormRes = FALSE; 272 FX_BOOL bUseFormRes = FALSE;
273 CPDF_Dictionary * pFontDict = NULL; 273 CPDF_Dictionary * pFontDict = NULL;
274 CPDF_Dictionary* pDRDict = pAnnotDict->GetDict(FX_BSTRC("DR")); 274 CPDF_Dictionary* pDRDict = pAnnotDict->GetDict(FX_BSTRC("DR"));
275 if (pDRDict == NULL) { 275 if (pDRDict == NULL) {
276 pDRDict = pFormDict->GetDict(FX_BSTRC("DR")); 276 pDRDict = pFormDict->GetDict(FX_BSTRC("DR"));
277 bUseFormRes = TRUE; 277 bUseFormRes = TRUE;
278 } 278 }
279 CPDF_Dictionary * pDRFontDict = NULL; 279 CPDF_Dictionary * pDRFontDict = NULL;
280 if ((pDRFontDict = pDRDict->GetDict("Font"))) { 280 if (pDRDict && (pDRFontDict = pDRDict->GetDict("Font"))) {
281 pFontDict = pDRFontDict->GetDict(sFontName.Mid(1)); 281 pFontDict = pDRFontDict->GetDict(sFontName.Mid(1));
282 if (!pFontDict && !bUseFormRes) { 282 if (!pFontDict && !bUseFormRes) {
283 pDRDict = pFormDict->GetDict(FX_BSTRC("DR")); 283 pDRDict = pFormDict->GetDict(FX_BSTRC("DR"));
284 pDRFontDict = pDRDict->GetDict("Font"); 284 pDRFontDict = pDRDict->GetDict("Font");
285 if (pDRFontDict) { 285 if (pDRFontDict) {
286 pFontDict = pDRFontDict->GetDict(sFontName.Mid(1)); 286 pFontDict = pDRFontDict->GetDict(sFontName.Mid(1));
287 } 287 }
288 } 288 }
289 } 289 }
290 if (!pDRFontDict) { 290 if (!pDRFontDict) {
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 if (!pStreamResFontList->KeyExist(sFontName)) { 423 if (!pStreamResFontList->KeyExist(sFontName)) {
424 pStreamResFontList->SetAtReference(sFontName, pDoc, pFontDict); 424 pStreamResFontList->SetAtReference(sFontName, pDoc, pFontDict);
425 } 425 }
426 } else { 426 } else {
427 pStreamDict->SetAt("Resources", pFormDict->GetDict("DR")->Clone()); 427 pStreamDict->SetAt("Resources", pFormDict->GetDict("DR")->Clone());
428 pStreamResList = pStreamDict->GetDict("Resources"); 428 pStreamResList = pStreamDict->GetDict("Resources");
429 } 429 }
430 } 430 }
431 switch (nWidgetType) { 431 switch (nWidgetType) {
432 case 0: { 432 case 0: {
433 CFX_WideString swValue = FPDF_GetFieldAttr(pAnnotDict, "V")->Get UnicodeText(); 433 CFX_WideString swValue = FPDF_GetFieldAttr(pAnnotDict, "V")? FPD F_GetFieldAttr(pAnnotDict, "V")->GetUnicodeText() : CFX_WideString();
434 FX_INT32 nAlign = FPDF_GetFieldAttr(pAnnotDict, "Q")->GetInteger (); 434 FX_INT32 nAlign = FPDF_GetFieldAttr(pAnnotDict, "Q")? FPDF_GetFi eldAttr(pAnnotDict, "Q")->GetInteger() : 0;
435 FX_DWORD dwFlags = FPDF_GetFieldAttr(pAnnotDict, "Ff")->GetInteg er(); 435 FX_DWORD dwFlags = FPDF_GetFieldAttr(pAnnotDict, "Ff")? FPDF_Get FieldAttr(pAnnotDict, "Ff")->GetInteger() : 0;
436 FX_DWORD dwMaxLen = FPDF_GetFieldAttr(pAnnotDict, "MaxLen")->Get Integer(); 436 FX_DWORD dwMaxLen = FPDF_GetFieldAttr(pAnnotDict, "MaxLen") ? FP DF_GetFieldAttr(pAnnotDict, "MaxLen")->GetInteger() : 0;
437 CPVT_FontMap map(pDoc, pStreamDict->GetDict("Resources"), pDefFo nt, sFontName.Right(sFontName.GetLength() - 1)); 437 CPVT_FontMap map(pDoc, pStreamDict ? pStreamDict->GetDict("Resou rces") : NULL , pDefFont, sFontName.Right(sFontName.GetLength() - 1));
438 CPVT_Provider prd(&map); 438 CPVT_Provider prd(&map);
439 CPDF_VariableText vt; 439 CPDF_VariableText vt;
440 vt.SetProvider(&prd); 440 vt.SetProvider(&prd);
441 vt.SetPlateRect(rcBody); 441 vt.SetPlateRect(rcBody);
442 vt.SetAlignment(nAlign); 442 vt.SetAlignment(nAlign);
443 if (IsFloatZero(fFontSize)) { 443 if (IsFloatZero(fFontSize)) {
444 vt.SetAutoFontSize(TRUE); 444 vt.SetAutoFontSize(TRUE);
445 } else { 445 } else {
446 vt.SetFontSize(fFontSize); 446 vt.SetFontSize(fFontSize);
447 } 447 }
(...skipping 27 matching lines...) Expand all
475 if (rcContent.Width() > rcBody.Width() || 475 if (rcContent.Width() > rcBody.Width() ||
476 rcContent.Height() > rcBody.Height()) { 476 rcContent.Height() > rcBody.Height()) {
477 sAppStream << rcBody.left << " " << rcBody.bottom << " " 477 sAppStream << rcBody.left << " " << rcBody.bottom << " "
478 << rcBody.Width() << " " << rcBody.Height() < < " re\nW\nn\n"; 478 << rcBody.Width() << " " << rcBody.Height() < < " re\nW\nn\n";
479 } 479 }
480 sAppStream << "BT\n" << CPVT_GenerateAP::GenerateColorAP(crT ext, TRUE) << sBody << "ET\n" << "Q\nEMC\n"; 480 sAppStream << "BT\n" << CPVT_GenerateAP::GenerateColorAP(crT ext, TRUE) << sBody << "ET\n" << "Q\nEMC\n";
481 } 481 }
482 } 482 }
483 break; 483 break;
484 case 1: { 484 case 1: {
485 CFX_WideString swValue = FPDF_GetFieldAttr(pAnnotDict, "V")->Get UnicodeText(); 485 CFX_WideString swValue = FPDF_GetFieldAttr(pAnnotDict, "V") ? FP DF_GetFieldAttr(pAnnotDict, "V")->GetUnicodeText() : CFX_WideString();
486 CPVT_FontMap map(pDoc, pStreamDict->GetDict("Resources"), pDefFo nt, sFontName.Right(sFontName.GetLength() - 1)); 486 CPVT_FontMap map(pDoc, pStreamDict ? pStreamDict->GetDict("Resou rces"):NULL, pDefFont, sFontName.Right(sFontName.GetLength() - 1));
487 CPVT_Provider prd(&map); 487 CPVT_Provider prd(&map);
488 CPDF_VariableText vt; 488 CPDF_VariableText vt;
489 vt.SetProvider(&prd); 489 vt.SetProvider(&prd);
490 CPDF_Rect rcButton = rcBody; 490 CPDF_Rect rcButton = rcBody;
491 rcButton.left = rcButton.right - 13; 491 rcButton.left = rcButton.right - 13;
492 rcButton.Normalize(); 492 rcButton.Normalize();
493 CPDF_Rect rcEdit = rcBody; 493 CPDF_Rect rcEdit = rcBody;
494 rcEdit.right = rcButton.left; 494 rcEdit.right = rcButton.left;
495 rcEdit.Normalize(); 495 rcEdit.Normalize();
496 vt.SetPlateRect(rcEdit); 496 vt.SetPlateRect(rcEdit);
(...skipping 30 matching lines...) Expand all
527 sAppStream << ptCenter.x - 3 << " " << ptCenter.y + 1.5f << " m\n"; 527 sAppStream << ptCenter.x - 3 << " " << ptCenter.y + 1.5f << " m\n";
528 sAppStream << ptCenter.x + 3 << " " << ptCenter.y + 1.5f << " l\n"; 528 sAppStream << ptCenter.x + 3 << " " << ptCenter.y + 1.5f << " l\n";
529 sAppStream << ptCenter.x << " " << ptCenter.y - 1.5f << " l\n"; 529 sAppStream << ptCenter.x << " " << ptCenter.y - 1.5f << " l\n";
530 sAppStream << ptCenter.x - 3 << " " << ptCenter.y + 1.5f << " l f\n"; 530 sAppStream << ptCenter.x - 3 << " " << ptCenter.y + 1.5f << " l f\n";
531 sAppStream << sButton << "Q\n"; 531 sAppStream << sButton << "Q\n";
532 } 532 }
533 } 533 }
534 } 534 }
535 break; 535 break;
536 case 2: { 536 case 2: {
537 CPVT_FontMap map(pDoc, pStreamDict->GetDict("Resources"), pDefFo nt, sFontName.Right(sFontName.GetLength() - 1)); 537 CPVT_FontMap map(pDoc, pStreamDict ? pStreamDict->GetDict("Resou rces"):NULL, pDefFont, sFontName.Right(sFontName.GetLength() - 1));
538 CPVT_Provider prd(&map); 538 CPVT_Provider prd(&map);
539 CPDF_Array * pOpts = FPDF_GetFieldAttr(pAnnotDict, "Opt")->GetAr ray(); 539 CPDF_Array * pOpts = FPDF_GetFieldAttr(pAnnotDict, "Opt") ? FPDF _GetFieldAttr(pAnnotDict, "Opt")->GetArray() : NULL;
540 CPDF_Array * pSels = FPDF_GetFieldAttr(pAnnotDict, "I")->GetArra y(); 540 CPDF_Array * pSels = FPDF_GetFieldAttr(pAnnotDict, "I") ? FPDF_G etFieldAttr(pAnnotDict, "I")->GetArray() : NULL;
541 FX_INT32 nTop = FPDF_GetFieldAttr(pAnnotDict, "TI")->GetInteger( ); 541 FX_INT32 nTop = FPDF_GetFieldAttr(pAnnotDict, "TI") ? FPDF_GetFi eldAttr(pAnnotDict, "TI")->GetInteger() : 0;
542 CFX_ByteTextBuf sBody; 542 CFX_ByteTextBuf sBody;
543 if (pOpts) { 543 if (pOpts) {
544 FX_FLOAT fy = rcBody.top; 544 FX_FLOAT fy = rcBody.top;
545 for (FX_INT32 i = nTop, sz = pOpts->GetCount(); i < sz; i++) { 545 for (FX_INT32 i = nTop, sz = pOpts->GetCount(); i < sz; i++) {
546 if (IsFloatSmaller(fy, rcBody.bottom)) { 546 if (IsFloatSmaller(fy, rcBody.bottom)) {
547 break; 547 break;
548 } 548 }
549 if (CPDF_Object* pOpt = pOpts->GetElementValue(i)) { 549 if (CPDF_Object* pOpt = pOpts->GetElementValue(i)) {
550 CFX_WideString swItem; 550 CFX_WideString swItem;
551 if (pOpt->GetType() == PDFOBJ_STRING) { 551 if (pOpt->GetType() == PDFOBJ_STRING) {
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 case CT_GRAY: 799 case CT_GRAY:
800 sColorStream << color.fColor1 << " " << (bFillOrStroke ? "g" : "G") << "\n"; 800 sColorStream << color.fColor1 << " " << (bFillOrStroke ? "g" : "G") << "\n";
801 break; 801 break;
802 case CT_CMYK: 802 case CT_CMYK:
803 sColorStream << color.fColor1 << " " << color.fColor2 << " " << colo r.fColor3 << " " << color.fColor4 << " " 803 sColorStream << color.fColor1 << " " << color.fColor2 << " " << colo r.fColor3 << " " << color.fColor4 << " "
804 << (bFillOrStroke ? "k" : "K") << "\n"; 804 << (bFillOrStroke ? "k" : "K") << "\n";
805 break; 805 break;
806 } 806 }
807 return sColorStream.GetByteString(); 807 return sColorStream.GetByteString();
808 } 808 }
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