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

Side by Side Diff: core/fpdfdoc/cpvt_generateap.cpp

Issue 2310873002: Move ShouldGenerateAPForAnnotation check to CPDF_Annot::GenerateAPIfNeeded (Closed)
Patch Set: Created 4 years, 3 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/fpdfdoc/cpdf_annot.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 for (int i = 0; i < 3; ++i) { 667 for (int i = 0; i < 3; ++i) {
668 lineRect.top -= fYDelta; 668 lineRect.top -= fYDelta;
669 sAppStream << lineRect.left << " " << lineRect.top << " m\n" 669 sAppStream << lineRect.left << " " << lineRect.top << " m\n"
670 << lineRect.right << " " << lineRect.top << " l\n"; 670 << lineRect.right << " " << lineRect.top << " l\n";
671 } 671 }
672 sAppStream << "B*\n"; 672 sAppStream << "B*\n";
673 673
674 return sAppStream.MakeString(); 674 return sAppStream.MakeString();
675 } 675 }
676 676
677 bool ShouldGenerateAPForAnnotation(CPDF_Dictionary* pAnnotDict) {
678 // If AP dictionary exists, we use the appearance defined in the
679 // existing AP dictionary.
680 if (pAnnotDict->KeyExist("AP"))
681 return false;
682
683 return !CPDF_Annot::IsAnnotationHidden(pAnnotDict);
684 }
685
686 } // namespace 677 } // namespace
687 678
688 bool FPDF_GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) { 679 bool FPDF_GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) {
689 if (!pAnnotDict || pAnnotDict->GetStringBy("Subtype") != "Widget") 680 if (!pAnnotDict || pAnnotDict->GetStringBy("Subtype") != "Widget")
690 return false; 681 return false;
691 682
692 CFX_ByteString field_type = FPDF_GetFieldAttr(pAnnotDict, "FT")->GetString(); 683 CFX_ByteString field_type = FPDF_GetFieldAttr(pAnnotDict, "FT")->GetString();
693 uint32_t flags = FPDF_GetFieldAttr(pAnnotDict, "Ff") 684 uint32_t flags = FPDF_GetFieldAttr(pAnnotDict, "Ff")
694 ? FPDF_GetFieldAttr(pAnnotDict, "Ff")->GetInteger() 685 ? FPDF_GetFieldAttr(pAnnotDict, "Ff")->GetInteger()
695 : 0; 686 : 0;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 } 719 }
729 720
730 // Static. 721 // Static.
731 bool CPVT_GenerateAP::GenerateTextFieldAP(CPDF_Document* pDoc, 722 bool CPVT_GenerateAP::GenerateTextFieldAP(CPDF_Document* pDoc,
732 CPDF_Dictionary* pAnnotDict) { 723 CPDF_Dictionary* pAnnotDict) {
733 return GenerateWidgetAP(pDoc, pAnnotDict, 0); 724 return GenerateWidgetAP(pDoc, pAnnotDict, 0);
734 } 725 }
735 726
736 bool CPVT_GenerateAP::GenerateCircleAP(CPDF_Document* pDoc, 727 bool CPVT_GenerateAP::GenerateCircleAP(CPDF_Document* pDoc,
737 CPDF_Dictionary* pAnnotDict) { 728 CPDF_Dictionary* pAnnotDict) {
738 if (!ShouldGenerateAPForAnnotation(pAnnotDict))
739 return false;
740
741 CFX_ByteTextBuf sAppStream; 729 CFX_ByteTextBuf sAppStream;
742 CFX_ByteString sExtGSDictName = "GS"; 730 CFX_ByteString sExtGSDictName = "GS";
743 sAppStream << "/" << sExtGSDictName << " gs "; 731 sAppStream << "/" << sExtGSDictName << " gs ";
744 732
745 CPDF_Array* pInteriorColor = pAnnotDict->GetArrayBy("IC"); 733 CPDF_Array* pInteriorColor = pAnnotDict->GetArrayBy("IC");
746 sAppStream << GetColorStringWithDefault(pInteriorColor, 734 sAppStream << GetColorStringWithDefault(pInteriorColor,
747 CPVT_Color(CPVT_Color::kTransparent), 735 CPVT_Color(CPVT_Color::kTransparent),
748 PaintOperation::FILL); 736 PaintOperation::FILL);
749 737
750 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), 738 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"),
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 CPDF_Dictionary* pExtGStateDict = 792 CPDF_Dictionary* pExtGStateDict =
805 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); 793 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
806 CPDF_Dictionary* pResourceDict = 794 CPDF_Dictionary* pResourceDict =
807 GenerateResourceDict(pExtGStateDict, nullptr); 795 GenerateResourceDict(pExtGStateDict, nullptr);
808 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict); 796 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict);
809 return true; 797 return true;
810 } 798 }
811 799
812 bool CPVT_GenerateAP::GenerateHighlightAP(CPDF_Document* pDoc, 800 bool CPVT_GenerateAP::GenerateHighlightAP(CPDF_Document* pDoc,
813 CPDF_Dictionary* pAnnotDict) { 801 CPDF_Dictionary* pAnnotDict) {
814 if (!ShouldGenerateAPForAnnotation(pAnnotDict))
815 return false;
816
817 CFX_ByteTextBuf sAppStream; 802 CFX_ByteTextBuf sAppStream;
818 CFX_ByteString sExtGSDictName = "GS"; 803 CFX_ByteString sExtGSDictName = "GS";
819 sAppStream << "/" << sExtGSDictName << " gs "; 804 sAppStream << "/" << sExtGSDictName << " gs ";
820 805
821 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), 806 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"),
822 CPVT_Color(CPVT_Color::kRGB, 1, 1, 0), 807 CPVT_Color(CPVT_Color::kRGB, 1, 1, 0),
823 PaintOperation::FILL); 808 PaintOperation::FILL);
824 809
825 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); 810 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect");
826 rect.Normalize(); 811 rect.Normalize();
827 812
828 sAppStream << rect.left << " " << rect.top << " m " << rect.right << " " 813 sAppStream << rect.left << " " << rect.top << " m " << rect.right << " "
829 << rect.top << " l " << rect.right << " " << rect.bottom << " l " 814 << rect.top << " l " << rect.right << " " << rect.bottom << " l "
830 << rect.left << " " << rect.bottom << " l " 815 << rect.left << " " << rect.bottom << " l "
831 << "h f\n"; 816 << "h f\n";
832 817
833 CPDF_Dictionary* pExtGStateDict = 818 CPDF_Dictionary* pExtGStateDict =
834 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Multiply"); 819 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Multiply");
835 CPDF_Dictionary* pResourceDict = 820 CPDF_Dictionary* pResourceDict =
836 GenerateResourceDict(pExtGStateDict, nullptr); 821 GenerateResourceDict(pExtGStateDict, nullptr);
837 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict); 822 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict);
838 823
839 return true; 824 return true;
840 } 825 }
841 826
842 bool CPVT_GenerateAP::GenerateInkAP(CPDF_Document* pDoc, 827 bool CPVT_GenerateAP::GenerateInkAP(CPDF_Document* pDoc,
843 CPDF_Dictionary* pAnnotDict) { 828 CPDF_Dictionary* pAnnotDict) {
844 if (!ShouldGenerateAPForAnnotation(pAnnotDict))
845 return false;
846
847 FX_FLOAT fBorderWidth = GetBorderWidth(*pAnnotDict); 829 FX_FLOAT fBorderWidth = GetBorderWidth(*pAnnotDict);
848 bool bIsStroke = fBorderWidth > 0; 830 bool bIsStroke = fBorderWidth > 0;
849 831
850 if (!bIsStroke) 832 if (!bIsStroke)
851 return false; 833 return false;
852 834
853 CPDF_Array* pInkList = pAnnotDict->GetArrayBy("InkList"); 835 CPDF_Array* pInkList = pAnnotDict->GetArrayBy("InkList");
854 if (!pInkList || pInkList->IsEmpty()) 836 if (!pInkList || pInkList->IsEmpty())
855 return false; 837 return false;
856 838
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 CPDF_Dictionary* pExtGStateDict = 872 CPDF_Dictionary* pExtGStateDict =
891 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); 873 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
892 CPDF_Dictionary* pResourceDict = 874 CPDF_Dictionary* pResourceDict =
893 GenerateResourceDict(pExtGStateDict, nullptr); 875 GenerateResourceDict(pExtGStateDict, nullptr);
894 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict); 876 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict);
895 return true; 877 return true;
896 } 878 }
897 879
898 bool CPVT_GenerateAP::GenerateTextAP(CPDF_Document* pDoc, 880 bool CPVT_GenerateAP::GenerateTextAP(CPDF_Document* pDoc,
899 CPDF_Dictionary* pAnnotDict) { 881 CPDF_Dictionary* pAnnotDict) {
900 if (!ShouldGenerateAPForAnnotation(pAnnotDict))
901 return false;
902
903 CFX_ByteTextBuf sAppStream; 882 CFX_ByteTextBuf sAppStream;
904 CFX_ByteString sExtGSDictName = "GS"; 883 CFX_ByteString sExtGSDictName = "GS";
905 sAppStream << "/" << sExtGSDictName << " gs "; 884 sAppStream << "/" << sExtGSDictName << " gs ";
906 885
907 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); 886 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect");
908 const FX_FLOAT fNoteLength = 20; 887 const FX_FLOAT fNoteLength = 20;
909 CFX_FloatRect noteRect(rect.left, rect.bottom, rect.left + fNoteLength, 888 CFX_FloatRect noteRect(rect.left, rect.bottom, rect.left + fNoteLength,
910 rect.bottom + fNoteLength); 889 rect.bottom + fNoteLength);
911 pAnnotDict->SetAtRect("Rect", noteRect); 890 pAnnotDict->SetAtRect("Rect", noteRect);
912 891
913 sAppStream << GenerateTextSymbolAP(noteRect); 892 sAppStream << GenerateTextSymbolAP(noteRect);
914 893
915 CPDF_Dictionary* pExtGStateDict = 894 CPDF_Dictionary* pExtGStateDict =
916 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); 895 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
917 CPDF_Dictionary* pResourceDict = 896 CPDF_Dictionary* pResourceDict =
918 GenerateResourceDict(pExtGStateDict, nullptr); 897 GenerateResourceDict(pExtGStateDict, nullptr);
919 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict); 898 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict);
920 return true; 899 return true;
921 } 900 }
922 901
923 bool CPVT_GenerateAP::GenerateUnderlineAP(CPDF_Document* pDoc, 902 bool CPVT_GenerateAP::GenerateUnderlineAP(CPDF_Document* pDoc,
924 CPDF_Dictionary* pAnnotDict) { 903 CPDF_Dictionary* pAnnotDict) {
925 if (!ShouldGenerateAPForAnnotation(pAnnotDict))
926 return false;
927
928 CFX_ByteTextBuf sAppStream; 904 CFX_ByteTextBuf sAppStream;
929 CFX_ByteString sExtGSDictName = "GS"; 905 CFX_ByteString sExtGSDictName = "GS";
930 sAppStream << "/" << sExtGSDictName << " gs "; 906 sAppStream << "/" << sExtGSDictName << " gs ";
931 907
932 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), 908 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"),
933 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), 909 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0),
934 PaintOperation::STROKE); 910 PaintOperation::STROKE);
935 911
936 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); 912 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect");
937 rect.Normalize(); 913 rect.Normalize();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
982 if (!pDefFont) 958 if (!pDefFont)
983 return false; 959 return false;
984 960
985 sAppStream << GetPopupContentsString(pDoc, *pAnnotDict, pDefFont, sFontName); 961 sAppStream << GetPopupContentsString(pDoc, *pAnnotDict, pDefFont, sFontName);
986 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict); 962 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict);
987 return true; 963 return true;
988 } 964 }
989 965
990 bool CPVT_GenerateAP::GenerateSquareAP(CPDF_Document* pDoc, 966 bool CPVT_GenerateAP::GenerateSquareAP(CPDF_Document* pDoc,
991 CPDF_Dictionary* pAnnotDict) { 967 CPDF_Dictionary* pAnnotDict) {
992 if (!ShouldGenerateAPForAnnotation(pAnnotDict))
993 return false;
994
995 CFX_ByteTextBuf sAppStream; 968 CFX_ByteTextBuf sAppStream;
996 CFX_ByteString sExtGSDictName = "GS"; 969 CFX_ByteString sExtGSDictName = "GS";
997 sAppStream << "/" << sExtGSDictName << " gs "; 970 sAppStream << "/" << sExtGSDictName << " gs ";
998 971
999 CPDF_Array* pInteriorColor = pAnnotDict->GetArrayBy("IC"); 972 CPDF_Array* pInteriorColor = pAnnotDict->GetArrayBy("IC");
1000 sAppStream << GetColorStringWithDefault(pInteriorColor, 973 sAppStream << GetColorStringWithDefault(pInteriorColor,
1001 CPVT_Color(CPVT_Color::kTransparent), 974 CPVT_Color(CPVT_Color::kTransparent),
1002 PaintOperation::FILL); 975 PaintOperation::FILL);
1003 976
1004 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), 977 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"),
(...skipping 27 matching lines...) Expand all
1032 CPDF_Dictionary* pExtGStateDict = 1005 CPDF_Dictionary* pExtGStateDict =
1033 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); 1006 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
1034 CPDF_Dictionary* pResourceDict = 1007 CPDF_Dictionary* pResourceDict =
1035 GenerateResourceDict(pExtGStateDict, nullptr); 1008 GenerateResourceDict(pExtGStateDict, nullptr);
1036 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict); 1009 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict);
1037 return true; 1010 return true;
1038 } 1011 }
1039 1012
1040 bool CPVT_GenerateAP::GenerateSquigglyAP(CPDF_Document* pDoc, 1013 bool CPVT_GenerateAP::GenerateSquigglyAP(CPDF_Document* pDoc,
1041 CPDF_Dictionary* pAnnotDict) { 1014 CPDF_Dictionary* pAnnotDict) {
1042 if (!ShouldGenerateAPForAnnotation(pAnnotDict))
1043 return false;
1044
1045 CFX_ByteTextBuf sAppStream; 1015 CFX_ByteTextBuf sAppStream;
1046 CFX_ByteString sExtGSDictName = "GS"; 1016 CFX_ByteString sExtGSDictName = "GS";
1047 sAppStream << "/" << sExtGSDictName << " gs "; 1017 sAppStream << "/" << sExtGSDictName << " gs ";
1048 1018
1049 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), 1019 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"),
1050 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), 1020 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0),
1051 PaintOperation::STROKE); 1021 PaintOperation::STROKE);
1052 1022
1053 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); 1023 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect");
1054 rect.Normalize(); 1024 rect.Normalize();
(...skipping 28 matching lines...) Expand all
1083 CPDF_Dictionary* pExtGStateDict = 1053 CPDF_Dictionary* pExtGStateDict =
1084 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); 1054 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
1085 CPDF_Dictionary* pResourceDict = 1055 CPDF_Dictionary* pResourceDict =
1086 GenerateResourceDict(pExtGStateDict, nullptr); 1056 GenerateResourceDict(pExtGStateDict, nullptr);
1087 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict); 1057 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict);
1088 return true; 1058 return true;
1089 } 1059 }
1090 1060
1091 bool CPVT_GenerateAP::GenerateStrikeOutAP(CPDF_Document* pDoc, 1061 bool CPVT_GenerateAP::GenerateStrikeOutAP(CPDF_Document* pDoc,
1092 CPDF_Dictionary* pAnnotDict) { 1062 CPDF_Dictionary* pAnnotDict) {
1093 if (!ShouldGenerateAPForAnnotation(pAnnotDict))
1094 return false;
1095
1096 CFX_ByteTextBuf sAppStream; 1063 CFX_ByteTextBuf sAppStream;
1097 CFX_ByteString sExtGSDictName = "GS"; 1064 CFX_ByteString sExtGSDictName = "GS";
1098 sAppStream << "/" << sExtGSDictName << " gs "; 1065 sAppStream << "/" << sExtGSDictName << " gs ";
1099 1066
1100 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), 1067 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"),
1101 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), 1068 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0),
1102 PaintOperation::STROKE); 1069 PaintOperation::STROKE);
1103 1070
1104 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); 1071 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect");
1105 rect.Normalize(); 1072 rect.Normalize();
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
1378 int32_t nFontIndex, 1345 int32_t nFontIndex,
1379 FX_FLOAT fFontSize) { 1346 FX_FLOAT fFontSize) {
1380 CFX_ByteTextBuf sRet; 1347 CFX_ByteTextBuf sRet;
1381 if (pFontMap) { 1348 if (pFontMap) {
1382 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); 1349 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex);
1383 if (sFontAlias.GetLength() > 0 && fFontSize > 0) 1350 if (sFontAlias.GetLength() > 0 && fFontSize > 0)
1384 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; 1351 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n";
1385 } 1352 }
1386 return sRet.MakeString(); 1353 return sRet.MakeString();
1387 } 1354 }
OLDNEW
« no previous file with comments | « core/fpdfdoc/cpdf_annot.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698