OLD | NEW |
---|---|
1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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/fpdfdoc/cpvt_generateap.h" | 7 #include "core/fpdfdoc/cpvt_generateap.h" |
8 | 8 |
9 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" | 9 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" |
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" | 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" |
11 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
12 #include "core/fpdfapi/fpdf_parser/include/cpdf_simple_parser.h" | 12 #include "core/fpdfapi/fpdf_parser/include/cpdf_simple_parser.h" |
13 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" | 13 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" |
14 #include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h" | 14 #include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h" |
15 #include "core/fpdfdoc/cpvt_color.h" | 15 #include "core/fpdfdoc/cpvt_color.h" |
16 #include "core/fpdfdoc/cpvt_fontmap.h" | 16 #include "core/fpdfdoc/cpvt_fontmap.h" |
17 #include "core/fpdfdoc/include/cpdf_formfield.h" | 17 #include "core/fpdfdoc/include/cpdf_formfield.h" |
18 #include "core/fpdfdoc/include/cpvt_word.h" | 18 #include "core/fpdfdoc/include/cpvt_word.h" |
19 #include "core/fpdfdoc/pdf_vt.h" | 19 #include "core/fpdfdoc/pdf_vt.h" |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc, | 23 bool GenerateWidgetAP(CPDF_Document* pDoc, |
24 CPDF_Dictionary* pAnnotDict, | 24 CPDF_Dictionary* pAnnotDict, |
25 const int32_t& nWidgetType) { | 25 const int32_t& nWidgetType) { |
26 CPDF_Dictionary* pFormDict = nullptr; | 26 CPDF_Dictionary* pFormDict = nullptr; |
27 if (CPDF_Dictionary* pRootDict = pDoc->GetRoot()) | 27 if (CPDF_Dictionary* pRootDict = pDoc->GetRoot()) |
28 pFormDict = pRootDict->GetDictBy("AcroForm"); | 28 pFormDict = pRootDict->GetDictBy("AcroForm"); |
29 if (!pFormDict) | 29 if (!pFormDict) |
30 return FALSE; | 30 return FALSE; |
Lei Zhang
2016/07/30 00:38:20
return true/false
jaepark
2016/07/30 00:47:30
Done.
| |
31 | 31 |
32 CFX_ByteString DA; | 32 CFX_ByteString DA; |
33 if (CPDF_Object* pDAObj = FPDF_GetFieldAttr(pAnnotDict, "DA")) | 33 if (CPDF_Object* pDAObj = FPDF_GetFieldAttr(pAnnotDict, "DA")) |
34 DA = pDAObj->GetString(); | 34 DA = pDAObj->GetString(); |
35 if (DA.IsEmpty()) | 35 if (DA.IsEmpty()) |
36 DA = pFormDict->GetStringBy("DA"); | 36 DA = pFormDict->GetStringBy("DA"); |
37 if (DA.IsEmpty()) | 37 if (DA.IsEmpty()) |
38 return FALSE; | 38 return FALSE; |
39 | 39 |
40 CPDF_SimpleParser syntax(DA.AsStringC()); | 40 CPDF_SimpleParser syntax(DA.AsStringC()); |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
438 pStreamDict->SetAt("Resources", pFormDict->GetDictBy("DR")->Clone()); | 438 pStreamDict->SetAt("Resources", pFormDict->GetDictBy("DR")->Clone()); |
439 pStreamResList = pStreamDict->GetDictBy("Resources"); | 439 pStreamResList = pStreamDict->GetDictBy("Resources"); |
440 } | 440 } |
441 } | 441 } |
442 } | 442 } |
443 return TRUE; | 443 return TRUE; |
444 } | 444 } |
445 | 445 |
446 } // namespace | 446 } // namespace |
447 | 447 |
448 FX_BOOL FPDF_GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) { | 448 bool FPDF_GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) { |
449 if (!pAnnotDict || pAnnotDict->GetStringBy("Subtype") != "Widget") { | 449 if (!pAnnotDict || pAnnotDict->GetStringBy("Subtype") != "Widget") |
450 return FALSE; | 450 return false; |
451 } | 451 |
452 CFX_ByteString field_type = FPDF_GetFieldAttr(pAnnotDict, "FT")->GetString(); | 452 CFX_ByteString field_type = FPDF_GetFieldAttr(pAnnotDict, "FT")->GetString(); |
453 uint32_t flags = FPDF_GetFieldAttr(pAnnotDict, "Ff") | 453 uint32_t flags = FPDF_GetFieldAttr(pAnnotDict, "Ff") |
454 ? FPDF_GetFieldAttr(pAnnotDict, "Ff")->GetInteger() | 454 ? FPDF_GetFieldAttr(pAnnotDict, "Ff")->GetInteger() |
455 : 0; | 455 : 0; |
456 if (field_type == "Tx") { | 456 if (field_type == "Tx") { |
457 return CPVT_GenerateAP::GenerateTextFieldAP(pDoc, pAnnotDict); | 457 return CPVT_GenerateAP::GenerateTextFieldAP(pDoc, pAnnotDict); |
458 } | 458 } |
459 if (field_type == "Ch") { | 459 if (field_type == "Ch") { |
460 return (flags & (1 << 17)) | 460 return (flags & (1 << 17)) |
461 ? CPVT_GenerateAP::GenerateComboBoxAP(pDoc, pAnnotDict) | 461 ? CPVT_GenerateAP::GenerateComboBoxAP(pDoc, pAnnotDict) |
462 : CPVT_GenerateAP::GenerateListBoxAP(pDoc, pAnnotDict); | 462 : CPVT_GenerateAP::GenerateListBoxAP(pDoc, pAnnotDict); |
463 } | 463 } |
464 if (field_type == "Btn") { | 464 if (field_type == "Btn") { |
465 if (!(flags & (1 << 16))) { | 465 if (!(flags & (1 << 16))) { |
466 if (!pAnnotDict->KeyExist("AS")) { | 466 if (!pAnnotDict->KeyExist("AS")) { |
467 if (CPDF_Dictionary* pParentDict = pAnnotDict->GetDictBy("Parent")) { | 467 if (CPDF_Dictionary* pParentDict = pAnnotDict->GetDictBy("Parent")) { |
468 if (pParentDict->KeyExist("AS")) { | 468 if (pParentDict->KeyExist("AS")) { |
469 pAnnotDict->SetAtString("AS", pParentDict->GetStringBy("AS")); | 469 pAnnotDict->SetAtString("AS", pParentDict->GetStringBy("AS")); |
470 } | 470 } |
471 } | 471 } |
472 } | 472 } |
473 } | 473 } |
474 } | 474 } |
475 return FALSE; | 475 return false; |
476 } | 476 } |
477 | 477 |
478 // Static. | 478 // Static. |
479 FX_BOOL CPVT_GenerateAP::GenerateTextFieldAP(CPDF_Document* pDoc, | 479 bool CPVT_GenerateAP::GenerateComboBoxAP(CPDF_Document* pDoc, |
480 CPDF_Dictionary* pAnnotDict) { | 480 CPDF_Dictionary* pAnnotDict) { |
481 return GenerateWidgetAP(pDoc, pAnnotDict, 1); | |
482 } | |
483 | |
484 // Static. | |
485 bool CPVT_GenerateAP::GenerateListBoxAP(CPDF_Document* pDoc, | |
486 CPDF_Dictionary* pAnnotDict) { | |
487 return GenerateWidgetAP(pDoc, pAnnotDict, 2); | |
488 } | |
489 | |
490 // Static. | |
491 bool CPVT_GenerateAP::GenerateTextFieldAP(CPDF_Document* pDoc, | |
492 CPDF_Dictionary* pAnnotDict) { | |
481 return GenerateWidgetAP(pDoc, pAnnotDict, 0); | 493 return GenerateWidgetAP(pDoc, pAnnotDict, 0); |
482 } | 494 } |
483 | 495 |
484 // Static. | 496 // Static. |
485 FX_BOOL CPVT_GenerateAP::GenerateComboBoxAP(CPDF_Document* pDoc, | |
486 CPDF_Dictionary* pAnnotDict) { | |
487 return GenerateWidgetAP(pDoc, pAnnotDict, 1); | |
488 } | |
489 | |
490 // Static. | |
491 FX_BOOL CPVT_GenerateAP::GenerateListBoxAP(CPDF_Document* pDoc, | |
492 CPDF_Dictionary* pAnnotDict) { | |
493 return GenerateWidgetAP(pDoc, pAnnotDict, 2); | |
494 } | |
495 | |
496 // Static. | |
497 CFX_ByteString CPVT_GenerateAP::GenerateEditAP( | 497 CFX_ByteString CPVT_GenerateAP::GenerateEditAP( |
498 IPVT_FontMap* pFontMap, | 498 IPVT_FontMap* pFontMap, |
499 CPDF_VariableText::Iterator* pIterator, | 499 CPDF_VariableText::Iterator* pIterator, |
500 const CFX_FloatPoint& ptOffset, | 500 const CFX_FloatPoint& ptOffset, |
501 FX_BOOL bContinuous, | 501 FX_BOOL bContinuous, |
502 uint16_t SubWord) { | 502 uint16_t SubWord) { |
503 CFX_ByteTextBuf sEditStream; | 503 CFX_ByteTextBuf sEditStream; |
504 CFX_ByteTextBuf sLineStream; | 504 CFX_ByteTextBuf sLineStream; |
505 CFX_ByteTextBuf sWords; | 505 CFX_ByteTextBuf sWords; |
506 CFX_FloatPoint ptOld(0.0f, 0.0f); | 506 CFX_FloatPoint ptOld(0.0f, 0.0f); |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
751 int32_t nFontIndex, | 751 int32_t nFontIndex, |
752 FX_FLOAT fFontSize) { | 752 FX_FLOAT fFontSize) { |
753 CFX_ByteTextBuf sRet; | 753 CFX_ByteTextBuf sRet; |
754 if (pFontMap) { | 754 if (pFontMap) { |
755 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); | 755 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); |
756 if (sFontAlias.GetLength() > 0 && fFontSize > 0) | 756 if (sFontAlias.GetLength() > 0 && fFontSize > 0) |
757 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; | 757 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; |
758 } | 758 } |
759 return sRet.MakeString(); | 759 return sRet.MakeString(); |
760 } | 760 } |
OLD | NEW |