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

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

Issue 2239853002: Hidden annotations should not be drawn (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Hidden annotations should not be drawn Created 4 years, 4 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
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"
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 585 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 bool CPVT_GenerateAP::GenerateCircleAP(CPDF_Document* pDoc,
616 CPDF_Dictionary* pAnnotDict) { 617 CPDF_Dictionary* pAnnotDict) {
617 // If AP dictionary exists, we use the appearance defined in the 618 // If AP dictionary exists, we use the appearance defined in the
618 // existing AP dictionary. 619 // existing AP dictionary.
619 if (pAnnotDict->KeyExist("AP")) 620 if (pAnnotDict->KeyExist("AP"))
620 return false; 621 return false;
621 622
623 if (CPDF_Annot::IsAnnotationHidden(pAnnotDict))
Lei Zhang 2016/08/15 18:39:39 Maybe it is time to combine the AP key check and t
tonikitoo 2016/08/15 18:59:31 Done.
624 return false;
625
622 CFX_ByteTextBuf sAppStream; 626 CFX_ByteTextBuf sAppStream;
623 CFX_ByteString sExtGSDictName = "GS"; 627 CFX_ByteString sExtGSDictName = "GS";
624 sAppStream << "/" << sExtGSDictName << " gs "; 628 sAppStream << "/" << sExtGSDictName << " gs ";
625 629
626 CPDF_Array* pInteriorColor = pAnnotDict->GetArrayBy("IC"); 630 CPDF_Array* pInteriorColor = pAnnotDict->GetArrayBy("IC");
627 sAppStream << GetColorStringWithDefault(pInteriorColor, 631 sAppStream << GetColorStringWithDefault(pInteriorColor,
628 CPVT_Color(CPVT_Color::kTransparent), 632 CPVT_Color(CPVT_Color::kTransparent),
629 PaintOperation::FILL); 633 PaintOperation::FILL);
630 634
631 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), 635 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"),
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 return true; 692 return true;
689 } 693 }
690 694
691 bool CPVT_GenerateAP::GenerateHighlightAP(CPDF_Document* pDoc, 695 bool CPVT_GenerateAP::GenerateHighlightAP(CPDF_Document* pDoc,
692 CPDF_Dictionary* pAnnotDict) { 696 CPDF_Dictionary* pAnnotDict) {
693 // If AP dictionary exists, we use the appearance defined in the 697 // If AP dictionary exists, we use the appearance defined in the
694 // existing AP dictionary. 698 // existing AP dictionary.
695 if (pAnnotDict->KeyExist("AP")) 699 if (pAnnotDict->KeyExist("AP"))
696 return false; 700 return false;
697 701
702 if (CPDF_Annot::IsAnnotationHidden(pAnnotDict))
703 return false;
704
698 CFX_ByteTextBuf sAppStream; 705 CFX_ByteTextBuf sAppStream;
699 CFX_ByteString sExtGSDictName = "GS"; 706 CFX_ByteString sExtGSDictName = "GS";
700 sAppStream << "/" << sExtGSDictName << " gs "; 707 sAppStream << "/" << sExtGSDictName << " gs ";
701 708
702 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), 709 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"),
703 CPVT_Color(CPVT_Color::kRGB, 1, 1, 0), 710 CPVT_Color(CPVT_Color::kRGB, 1, 1, 0),
704 PaintOperation::FILL); 711 PaintOperation::FILL);
705 712
706 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); 713 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect");
707 rect.Normalize(); 714 rect.Normalize();
(...skipping 10 matching lines...) Expand all
718 return true; 725 return true;
719 } 726 }
720 727
721 bool CPVT_GenerateAP::GenerateInkAP(CPDF_Document* pDoc, 728 bool CPVT_GenerateAP::GenerateInkAP(CPDF_Document* pDoc,
722 CPDF_Dictionary* pAnnotDict) { 729 CPDF_Dictionary* pAnnotDict) {
723 // If AP dictionary exists, we use the appearance defined in the 730 // If AP dictionary exists, we use the appearance defined in the
724 // existing AP dictionary. 731 // existing AP dictionary.
725 if (pAnnotDict->KeyExist("AP")) 732 if (pAnnotDict->KeyExist("AP"))
726 return false; 733 return false;
727 734
735 if (CPDF_Annot::IsAnnotationHidden(pAnnotDict))
736 return false;
737
728 FX_FLOAT fBorderWidth = GetBorderWidth(*pAnnotDict); 738 FX_FLOAT fBorderWidth = GetBorderWidth(*pAnnotDict);
729 bool bIsStroke = fBorderWidth > 0; 739 bool bIsStroke = fBorderWidth > 0;
730 740
731 if (!bIsStroke) 741 if (!bIsStroke)
732 return false; 742 return false;
733 743
734 CPDF_Array* pInkList = pAnnotDict->GetArrayBy("InkList"); 744 CPDF_Array* pInkList = pAnnotDict->GetArrayBy("InkList");
735 if (!pInkList || pInkList->IsEmpty()) 745 if (!pInkList || pInkList->IsEmpty())
736 return false; 746 return false;
737 747
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 return true; 784 return true;
775 } 785 }
776 786
777 bool CPVT_GenerateAP::GenerateUnderlineAP(CPDF_Document* pDoc, 787 bool CPVT_GenerateAP::GenerateUnderlineAP(CPDF_Document* pDoc,
778 CPDF_Dictionary* pAnnotDict) { 788 CPDF_Dictionary* pAnnotDict) {
779 // If AP dictionary exists, we use the appearance defined in the 789 // If AP dictionary exists, we use the appearance defined in the
780 // existing AP dictionary. 790 // existing AP dictionary.
781 if (pAnnotDict->KeyExist("AP")) 791 if (pAnnotDict->KeyExist("AP"))
782 return false; 792 return false;
783 793
794 if (CPDF_Annot::IsAnnotationHidden(pAnnotDict))
795 return false;
796
784 CFX_ByteTextBuf sAppStream; 797 CFX_ByteTextBuf sAppStream;
785 CFX_ByteString sExtGSDictName = "GS"; 798 CFX_ByteString sExtGSDictName = "GS";
786 sAppStream << "/" << sExtGSDictName << " gs "; 799 sAppStream << "/" << sExtGSDictName << " gs ";
787 800
788 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), 801 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"),
789 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), 802 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0),
790 PaintOperation::STROKE); 803 PaintOperation::STROKE);
791 804
792 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); 805 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect");
793 rect.Normalize(); 806 rect.Normalize();
794 807
795 FX_FLOAT fLineWidth = 1.0; 808 FX_FLOAT fLineWidth = 1.0;
796 sAppStream << fLineWidth << " w " << rect.left << " " 809 sAppStream << fLineWidth << " w " << rect.left << " "
797 << rect.bottom + fLineWidth << " m " << rect.right << " " 810 << rect.bottom + fLineWidth << " m " << rect.right << " "
798 << rect.bottom + fLineWidth << " l S\n"; 811 << rect.bottom + fLineWidth << " l S\n";
799 812
800 CPDF_Dictionary* pExtGStateDict = 813 CPDF_Dictionary* pExtGStateDict =
801 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); 814 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
802 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict); 815 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict);
803 return true; 816 return true;
804 } 817 }
805 818
806 bool CPVT_GenerateAP::GenerateSquareAP(CPDF_Document* pDoc, 819 bool CPVT_GenerateAP::GenerateSquareAP(CPDF_Document* pDoc,
807 CPDF_Dictionary* pAnnotDict) { 820 CPDF_Dictionary* pAnnotDict) {
808 // If AP dictionary exists, we use the appearance defined in the 821 // If AP dictionary exists, we use the appearance defined in the
809 // existing AP dictionary. 822 // existing AP dictionary.
810 if (pAnnotDict->KeyExist("AP")) 823 if (pAnnotDict->KeyExist("AP"))
811 return false; 824 return false;
812 825
826 if (CPDF_Annot::IsAnnotationHidden(pAnnotDict))
827 return false;
828
813 CFX_ByteTextBuf sAppStream; 829 CFX_ByteTextBuf sAppStream;
814 CFX_ByteString sExtGSDictName = "GS"; 830 CFX_ByteString sExtGSDictName = "GS";
815 sAppStream << "/" << sExtGSDictName << " gs "; 831 sAppStream << "/" << sExtGSDictName << " gs ";
816 832
817 CPDF_Array* pInteriorColor = pAnnotDict->GetArrayBy("IC"); 833 CPDF_Array* pInteriorColor = pAnnotDict->GetArrayBy("IC");
818 sAppStream << GetColorStringWithDefault(pInteriorColor, 834 sAppStream << GetColorStringWithDefault(pInteriorColor,
819 CPVT_Color(CPVT_Color::kTransparent), 835 CPVT_Color(CPVT_Color::kTransparent),
820 PaintOperation::FILL); 836 PaintOperation::FILL);
821 837
822 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), 838 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"),
(...skipping 30 matching lines...) Expand all
853 return true; 869 return true;
854 } 870 }
855 871
856 bool CPVT_GenerateAP::GenerateSquigglyAP(CPDF_Document* pDoc, 872 bool CPVT_GenerateAP::GenerateSquigglyAP(CPDF_Document* pDoc,
857 CPDF_Dictionary* pAnnotDict) { 873 CPDF_Dictionary* pAnnotDict) {
858 // If AP dictionary exists, we use the appearance defined in the 874 // If AP dictionary exists, we use the appearance defined in the
859 // existing AP dictionary. 875 // existing AP dictionary.
860 if (pAnnotDict->KeyExist("AP")) 876 if (pAnnotDict->KeyExist("AP"))
861 return false; 877 return false;
862 878
879 if (CPDF_Annot::IsAnnotationHidden(pAnnotDict))
880 return false;
881
863 CFX_ByteTextBuf sAppStream; 882 CFX_ByteTextBuf sAppStream;
864 CFX_ByteString sExtGSDictName = "GS"; 883 CFX_ByteString sExtGSDictName = "GS";
865 sAppStream << "/" << sExtGSDictName << " gs "; 884 sAppStream << "/" << sExtGSDictName << " gs ";
866 885
867 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), 886 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"),
868 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), 887 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0),
869 PaintOperation::STROKE); 888 PaintOperation::STROKE);
870 889
871 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); 890 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect");
872 rect.Normalize(); 891 rect.Normalize();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 return true; 923 return true;
905 } 924 }
906 925
907 bool CPVT_GenerateAP::GenerateStrikeOutAP(CPDF_Document* pDoc, 926 bool CPVT_GenerateAP::GenerateStrikeOutAP(CPDF_Document* pDoc,
908 CPDF_Dictionary* pAnnotDict) { 927 CPDF_Dictionary* pAnnotDict) {
909 // If AP dictionary exists, we use the appearance defined in the 928 // If AP dictionary exists, we use the appearance defined in the
910 // existing AP dictionary. 929 // existing AP dictionary.
911 if (pAnnotDict->KeyExist("AP")) 930 if (pAnnotDict->KeyExist("AP"))
912 return false; 931 return false;
913 932
933 if (CPDF_Annot::IsAnnotationHidden(pAnnotDict))
934 return false;
935
914 CFX_ByteTextBuf sAppStream; 936 CFX_ByteTextBuf sAppStream;
915 CFX_ByteString sExtGSDictName = "GS"; 937 CFX_ByteString sExtGSDictName = "GS";
916 sAppStream << "/" << sExtGSDictName << " gs "; 938 sAppStream << "/" << sExtGSDictName << " gs ";
917 939
918 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), 940 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"),
919 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), 941 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0),
920 PaintOperation::STROKE); 942 PaintOperation::STROKE);
921 943
922 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); 944 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect");
923 rect.Normalize(); 945 rect.Normalize();
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
1194 int32_t nFontIndex, 1216 int32_t nFontIndex,
1195 FX_FLOAT fFontSize) { 1217 FX_FLOAT fFontSize) {
1196 CFX_ByteTextBuf sRet; 1218 CFX_ByteTextBuf sRet;
1197 if (pFontMap) { 1219 if (pFontMap) {
1198 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); 1220 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex);
1199 if (sFontAlias.GetLength() > 0 && fFontSize > 0) 1221 if (sFontAlias.GetLength() > 0 && fFontSize > 0)
1200 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; 1222 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n";
1201 } 1223 }
1202 return sRet.MakeString(); 1224 return sRet.MakeString();
1203 } 1225 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698