Chromium Code Reviews| 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_annot.h" | |
| 17 #include "core/fpdfdoc/include/cpdf_formfield.h" | 18 #include "core/fpdfdoc/include/cpdf_formfield.h" |
| 18 #include "core/fpdfdoc/include/cpvt_word.h" | 19 #include "core/fpdfdoc/include/cpvt_word.h" |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 bool GenerateWidgetAP(CPDF_Document* pDoc, | 23 bool GenerateWidgetAP(CPDF_Document* pDoc, |
| 23 CPDF_Dictionary* pAnnotDict, | 24 CPDF_Dictionary* pAnnotDict, |
| 24 const int32_t& nWidgetType) { | 25 const int32_t& nWidgetType) { |
| 25 CPDF_Dictionary* pFormDict = nullptr; | 26 CPDF_Dictionary* pFormDict = nullptr; |
| 26 if (CPDF_Dictionary* pRootDict = pDoc->GetRoot()) | 27 if (CPDF_Dictionary* pRootDict = pDoc->GetRoot()) |
| (...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 605 CPDF_Dictionary* pAnnotDict) { | 606 CPDF_Dictionary* pAnnotDict) { |
| 606 return GenerateWidgetAP(pDoc, pAnnotDict, 2); | 607 return GenerateWidgetAP(pDoc, pAnnotDict, 2); |
| 607 } | 608 } |
| 608 | 609 |
| 609 // Static. | 610 // Static. |
| 610 bool CPVT_GenerateAP::GenerateTextFieldAP(CPDF_Document* pDoc, | 611 bool CPVT_GenerateAP::GenerateTextFieldAP(CPDF_Document* pDoc, |
| 611 CPDF_Dictionary* pAnnotDict) { | 612 CPDF_Dictionary* pAnnotDict) { |
| 612 return GenerateWidgetAP(pDoc, pAnnotDict, 0); | 613 return GenerateWidgetAP(pDoc, pAnnotDict, 0); |
| 613 } | 614 } |
| 614 | 615 |
| 615 bool CPVT_GenerateAP::GenerateCircleAP(CPDF_Document* pDoc, | 616 static bool ShouldGenerateAPForAnnotation(CPDF_Dictionary* pAnnotDict) { |
|
Lei Zhang
2016/08/15 19:02:10
Move this into the anonymous namespace above and d
| |
| 616 CPDF_Dictionary* pAnnotDict) { | |
| 617 // If AP dictionary exists, we use the appearance defined in the | 617 // If AP dictionary exists, we use the appearance defined in the |
| 618 // existing AP dictionary. | 618 // existing AP dictionary. |
| 619 if (pAnnotDict->KeyExist("AP")) | 619 if (pAnnotDict->KeyExist("AP")) |
| 620 return false; | 620 return false; |
| 621 | 621 |
| 622 return !CPDF_Annot::IsAnnotationHidden(pAnnotDict); | |
| 623 } | |
| 624 | |
| 625 bool CPVT_GenerateAP::GenerateCircleAP(CPDF_Document* pDoc, | |
| 626 CPDF_Dictionary* pAnnotDict) { | |
| 627 if (!ShouldGenerateAPForAnnotation(pAnnotDict)) | |
| 628 return false; | |
| 629 | |
| 622 CFX_ByteTextBuf sAppStream; | 630 CFX_ByteTextBuf sAppStream; |
| 623 CFX_ByteString sExtGSDictName = "GS"; | 631 CFX_ByteString sExtGSDictName = "GS"; |
| 624 sAppStream << "/" << sExtGSDictName << " gs "; | 632 sAppStream << "/" << sExtGSDictName << " gs "; |
| 625 | 633 |
| 626 CPDF_Array* pInteriorColor = pAnnotDict->GetArrayBy("IC"); | 634 CPDF_Array* pInteriorColor = pAnnotDict->GetArrayBy("IC"); |
| 627 sAppStream << GetColorStringWithDefault(pInteriorColor, | 635 sAppStream << GetColorStringWithDefault(pInteriorColor, |
| 628 CPVT_Color(CPVT_Color::kTransparent), | 636 CPVT_Color(CPVT_Color::kTransparent), |
| 629 PaintOperation::FILL); | 637 PaintOperation::FILL); |
| 630 | 638 |
| 631 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), | 639 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 683 sAppStream << GetPaintOperatorString(bIsStrokeRect, bIsFillRect) << "\n"; | 691 sAppStream << GetPaintOperatorString(bIsStrokeRect, bIsFillRect) << "\n"; |
| 684 | 692 |
| 685 CPDF_Dictionary* pExtGStateDict = | 693 CPDF_Dictionary* pExtGStateDict = |
| 686 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); | 694 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); |
| 687 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict); | 695 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict); |
| 688 return true; | 696 return true; |
| 689 } | 697 } |
| 690 | 698 |
| 691 bool CPVT_GenerateAP::GenerateHighlightAP(CPDF_Document* pDoc, | 699 bool CPVT_GenerateAP::GenerateHighlightAP(CPDF_Document* pDoc, |
| 692 CPDF_Dictionary* pAnnotDict) { | 700 CPDF_Dictionary* pAnnotDict) { |
| 693 // If AP dictionary exists, we use the appearance defined in the | 701 if (!ShouldGenerateAPForAnnotation(pAnnotDict)) |
| 694 // existing AP dictionary. | |
| 695 if (pAnnotDict->KeyExist("AP")) | |
| 696 return false; | 702 return false; |
| 697 | 703 |
| 698 CFX_ByteTextBuf sAppStream; | 704 CFX_ByteTextBuf sAppStream; |
| 699 CFX_ByteString sExtGSDictName = "GS"; | 705 CFX_ByteString sExtGSDictName = "GS"; |
| 700 sAppStream << "/" << sExtGSDictName << " gs "; | 706 sAppStream << "/" << sExtGSDictName << " gs "; |
| 701 | 707 |
| 702 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), | 708 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), |
| 703 CPVT_Color(CPVT_Color::kRGB, 1, 1, 0), | 709 CPVT_Color(CPVT_Color::kRGB, 1, 1, 0), |
| 704 PaintOperation::FILL); | 710 PaintOperation::FILL); |
| 705 | 711 |
| 706 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); | 712 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); |
| 707 rect.Normalize(); | 713 rect.Normalize(); |
| 708 | 714 |
| 709 sAppStream << rect.left << " " << rect.top << " m " << rect.right << " " | 715 sAppStream << rect.left << " " << rect.top << " m " << rect.right << " " |
| 710 << rect.top << " l " << rect.right << " " << rect.bottom << " l " | 716 << rect.top << " l " << rect.right << " " << rect.bottom << " l " |
| 711 << rect.left << " " << rect.bottom << " l " | 717 << rect.left << " " << rect.bottom << " l " |
| 712 << "h f\n"; | 718 << "h f\n"; |
| 713 | 719 |
| 714 CPDF_Dictionary* pExtGStateDict = | 720 CPDF_Dictionary* pExtGStateDict = |
| 715 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Multiply"); | 721 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Multiply"); |
| 716 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict); | 722 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict); |
| 717 | 723 |
| 718 return true; | 724 return true; |
| 719 } | 725 } |
| 720 | 726 |
| 721 bool CPVT_GenerateAP::GenerateInkAP(CPDF_Document* pDoc, | 727 bool CPVT_GenerateAP::GenerateInkAP(CPDF_Document* pDoc, |
| 722 CPDF_Dictionary* pAnnotDict) { | 728 CPDF_Dictionary* pAnnotDict) { |
| 723 // If AP dictionary exists, we use the appearance defined in the | 729 if (!ShouldGenerateAPForAnnotation(pAnnotDict)) |
| 724 // existing AP dictionary. | |
| 725 if (pAnnotDict->KeyExist("AP")) | |
| 726 return false; | 730 return false; |
| 727 | 731 |
| 728 FX_FLOAT fBorderWidth = GetBorderWidth(*pAnnotDict); | 732 FX_FLOAT fBorderWidth = GetBorderWidth(*pAnnotDict); |
| 729 bool bIsStroke = fBorderWidth > 0; | 733 bool bIsStroke = fBorderWidth > 0; |
| 730 | 734 |
| 731 if (!bIsStroke) | 735 if (!bIsStroke) |
| 732 return false; | 736 return false; |
| 733 | 737 |
| 734 CPDF_Array* pInkList = pAnnotDict->GetArrayBy("InkList"); | 738 CPDF_Array* pInkList = pAnnotDict->GetArrayBy("InkList"); |
| 735 if (!pInkList || pInkList->IsEmpty()) | 739 if (!pInkList || pInkList->IsEmpty()) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 769 } | 773 } |
| 770 | 774 |
| 771 CPDF_Dictionary* pExtGStateDict = | 775 CPDF_Dictionary* pExtGStateDict = |
| 772 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); | 776 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); |
| 773 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict); | 777 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict); |
| 774 return true; | 778 return true; |
| 775 } | 779 } |
| 776 | 780 |
| 777 bool CPVT_GenerateAP::GenerateUnderlineAP(CPDF_Document* pDoc, | 781 bool CPVT_GenerateAP::GenerateUnderlineAP(CPDF_Document* pDoc, |
| 778 CPDF_Dictionary* pAnnotDict) { | 782 CPDF_Dictionary* pAnnotDict) { |
| 779 // If AP dictionary exists, we use the appearance defined in the | 783 if (!ShouldGenerateAPForAnnotation(pAnnotDict)) |
| 780 // existing AP dictionary. | |
| 781 if (pAnnotDict->KeyExist("AP")) | |
| 782 return false; | 784 return false; |
| 783 | 785 |
| 784 CFX_ByteTextBuf sAppStream; | 786 CFX_ByteTextBuf sAppStream; |
| 785 CFX_ByteString sExtGSDictName = "GS"; | 787 CFX_ByteString sExtGSDictName = "GS"; |
| 786 sAppStream << "/" << sExtGSDictName << " gs "; | 788 sAppStream << "/" << sExtGSDictName << " gs "; |
| 787 | 789 |
| 788 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), | 790 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), |
| 789 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), | 791 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), |
| 790 PaintOperation::STROKE); | 792 PaintOperation::STROKE); |
| 791 | 793 |
| 792 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); | 794 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); |
| 793 rect.Normalize(); | 795 rect.Normalize(); |
| 794 | 796 |
| 795 FX_FLOAT fLineWidth = 1.0; | 797 FX_FLOAT fLineWidth = 1.0; |
| 796 sAppStream << fLineWidth << " w " << rect.left << " " | 798 sAppStream << fLineWidth << " w " << rect.left << " " |
| 797 << rect.bottom + fLineWidth << " m " << rect.right << " " | 799 << rect.bottom + fLineWidth << " m " << rect.right << " " |
| 798 << rect.bottom + fLineWidth << " l S\n"; | 800 << rect.bottom + fLineWidth << " l S\n"; |
| 799 | 801 |
| 800 CPDF_Dictionary* pExtGStateDict = | 802 CPDF_Dictionary* pExtGStateDict = |
| 801 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); | 803 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); |
| 802 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict); | 804 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict); |
| 803 return true; | 805 return true; |
| 804 } | 806 } |
| 805 | 807 |
| 806 bool CPVT_GenerateAP::GenerateSquareAP(CPDF_Document* pDoc, | 808 bool CPVT_GenerateAP::GenerateSquareAP(CPDF_Document* pDoc, |
| 807 CPDF_Dictionary* pAnnotDict) { | 809 CPDF_Dictionary* pAnnotDict) { |
| 808 // If AP dictionary exists, we use the appearance defined in the | 810 if (!ShouldGenerateAPForAnnotation(pAnnotDict)) |
| 809 // existing AP dictionary. | |
| 810 if (pAnnotDict->KeyExist("AP")) | |
| 811 return false; | 811 return false; |
| 812 | 812 |
| 813 CFX_ByteTextBuf sAppStream; | 813 CFX_ByteTextBuf sAppStream; |
| 814 CFX_ByteString sExtGSDictName = "GS"; | 814 CFX_ByteString sExtGSDictName = "GS"; |
| 815 sAppStream << "/" << sExtGSDictName << " gs "; | 815 sAppStream << "/" << sExtGSDictName << " gs "; |
| 816 | 816 |
| 817 CPDF_Array* pInteriorColor = pAnnotDict->GetArrayBy("IC"); | 817 CPDF_Array* pInteriorColor = pAnnotDict->GetArrayBy("IC"); |
| 818 sAppStream << GetColorStringWithDefault(pInteriorColor, | 818 sAppStream << GetColorStringWithDefault(pInteriorColor, |
| 819 CPVT_Color(CPVT_Color::kTransparent), | 819 CPVT_Color(CPVT_Color::kTransparent), |
| 820 PaintOperation::FILL); | 820 PaintOperation::FILL); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 848 << GetPaintOperatorString(bIsStrokeRect, bIsFillRect) << "\n"; | 848 << GetPaintOperatorString(bIsStrokeRect, bIsFillRect) << "\n"; |
| 849 | 849 |
| 850 CPDF_Dictionary* pExtGStateDict = | 850 CPDF_Dictionary* pExtGStateDict = |
| 851 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); | 851 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); |
| 852 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict); | 852 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict); |
| 853 return true; | 853 return true; |
| 854 } | 854 } |
| 855 | 855 |
| 856 bool CPVT_GenerateAP::GenerateSquigglyAP(CPDF_Document* pDoc, | 856 bool CPVT_GenerateAP::GenerateSquigglyAP(CPDF_Document* pDoc, |
| 857 CPDF_Dictionary* pAnnotDict) { | 857 CPDF_Dictionary* pAnnotDict) { |
| 858 // If AP dictionary exists, we use the appearance defined in the | 858 if (!ShouldGenerateAPForAnnotation(pAnnotDict)) |
| 859 // existing AP dictionary. | |
| 860 if (pAnnotDict->KeyExist("AP")) | |
| 861 return false; | 859 return false; |
| 862 | 860 |
| 863 CFX_ByteTextBuf sAppStream; | 861 CFX_ByteTextBuf sAppStream; |
| 864 CFX_ByteString sExtGSDictName = "GS"; | 862 CFX_ByteString sExtGSDictName = "GS"; |
| 865 sAppStream << "/" << sExtGSDictName << " gs "; | 863 sAppStream << "/" << sExtGSDictName << " gs "; |
| 866 | 864 |
| 867 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), | 865 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), |
| 868 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), | 866 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), |
| 869 PaintOperation::STROKE); | 867 PaintOperation::STROKE); |
| 870 | 868 |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 899 sAppStream << "S\n"; | 897 sAppStream << "S\n"; |
| 900 | 898 |
| 901 CPDF_Dictionary* pExtGStateDict = | 899 CPDF_Dictionary* pExtGStateDict = |
| 902 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); | 900 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); |
| 903 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict); | 901 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict); |
| 904 return true; | 902 return true; |
| 905 } | 903 } |
| 906 | 904 |
| 907 bool CPVT_GenerateAP::GenerateStrikeOutAP(CPDF_Document* pDoc, | 905 bool CPVT_GenerateAP::GenerateStrikeOutAP(CPDF_Document* pDoc, |
| 908 CPDF_Dictionary* pAnnotDict) { | 906 CPDF_Dictionary* pAnnotDict) { |
| 909 // If AP dictionary exists, we use the appearance defined in the | 907 if (!ShouldGenerateAPForAnnotation(pAnnotDict)) |
| 910 // existing AP dictionary. | |
| 911 if (pAnnotDict->KeyExist("AP")) | |
| 912 return false; | 908 return false; |
| 913 | 909 |
| 914 CFX_ByteTextBuf sAppStream; | 910 CFX_ByteTextBuf sAppStream; |
| 915 CFX_ByteString sExtGSDictName = "GS"; | 911 CFX_ByteString sExtGSDictName = "GS"; |
| 916 sAppStream << "/" << sExtGSDictName << " gs "; | 912 sAppStream << "/" << sExtGSDictName << " gs "; |
| 917 | 913 |
| 918 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), | 914 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), |
| 919 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), | 915 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), |
| 920 PaintOperation::STROKE); | 916 PaintOperation::STROKE); |
| 921 | 917 |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1194 int32_t nFontIndex, | 1190 int32_t nFontIndex, |
| 1195 FX_FLOAT fFontSize) { | 1191 FX_FLOAT fFontSize) { |
| 1196 CFX_ByteTextBuf sRet; | 1192 CFX_ByteTextBuf sRet; |
| 1197 if (pFontMap) { | 1193 if (pFontMap) { |
| 1198 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); | 1194 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); |
| 1199 if (sFontAlias.GetLength() > 0 && fFontSize > 0) | 1195 if (sFontAlias.GetLength() > 0 && fFontSize > 0) |
| 1200 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; | 1196 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; |
| 1201 } | 1197 } |
| 1202 return sRet.MakeString(); | 1198 return sRet.MakeString(); |
| 1203 } | 1199 } |
| OLD | NEW |