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

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
« 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"
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
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
616 static bool IsAnnotationHidden(CPDF_Dictionary* pAnnotDict) {
Lei Zhang 2016/08/15 00:10:08 Can you only implement this once? static bool CPDF
617 return pAnnotDict->GetIntegerBy("F") & ANNOTFLAG_HIDDEN;
618 }
619
615 bool CPVT_GenerateAP::GenerateCircleAP(CPDF_Document* pDoc, 620 bool CPVT_GenerateAP::GenerateCircleAP(CPDF_Document* pDoc,
616 CPDF_Dictionary* pAnnotDict) { 621 CPDF_Dictionary* pAnnotDict) {
617 // If AP dictionary exists, we use the appearance defined in the 622 // If AP dictionary exists, we use the appearance defined in the
618 // existing AP dictionary. 623 // existing AP dictionary.
619 if (pAnnotDict->KeyExist("AP")) 624 if (pAnnotDict->KeyExist("AP"))
620 return false; 625 return false;
621 626
627 if (IsAnnotationHidden(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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 AP dictionary exists, we use the appearance defined in the
694 // existing AP dictionary. 702 // existing AP dictionary.
695 if (pAnnotDict->KeyExist("AP")) 703 if (pAnnotDict->KeyExist("AP"))
696 return false; 704 return false;
697 705
706 if (IsAnnotationHidden(pAnnotDict))
707 return false;
708
698 CFX_ByteTextBuf sAppStream; 709 CFX_ByteTextBuf sAppStream;
699 CFX_ByteString sExtGSDictName = "GS"; 710 CFX_ByteString sExtGSDictName = "GS";
700 sAppStream << "/" << sExtGSDictName << " gs "; 711 sAppStream << "/" << sExtGSDictName << " gs ";
701 712
702 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), 713 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"),
703 CPVT_Color(CPVT_Color::kRGB, 1, 1, 0), 714 CPVT_Color(CPVT_Color::kRGB, 1, 1, 0),
704 PaintOperation::FILL); 715 PaintOperation::FILL);
705 716
706 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); 717 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect");
707 rect.Normalize(); 718 rect.Normalize();
(...skipping 10 matching lines...) Expand all
718 return true; 729 return true;
719 } 730 }
720 731
721 bool CPVT_GenerateAP::GenerateInkAP(CPDF_Document* pDoc, 732 bool CPVT_GenerateAP::GenerateInkAP(CPDF_Document* pDoc,
722 CPDF_Dictionary* pAnnotDict) { 733 CPDF_Dictionary* pAnnotDict) {
723 // If AP dictionary exists, we use the appearance defined in the 734 // If AP dictionary exists, we use the appearance defined in the
724 // existing AP dictionary. 735 // existing AP dictionary.
725 if (pAnnotDict->KeyExist("AP")) 736 if (pAnnotDict->KeyExist("AP"))
726 return false; 737 return false;
727 738
739 if (IsAnnotationHidden(pAnnotDict))
740 return false;
741
728 FX_FLOAT fBorderWidth = GetBorderWidth(*pAnnotDict); 742 FX_FLOAT fBorderWidth = GetBorderWidth(*pAnnotDict);
729 bool bIsStroke = fBorderWidth > 0; 743 bool bIsStroke = fBorderWidth > 0;
730 744
731 if (!bIsStroke) 745 if (!bIsStroke)
732 return false; 746 return false;
733 747
734 CPDF_Array* pInkList = pAnnotDict->GetArrayBy("InkList"); 748 CPDF_Array* pInkList = pAnnotDict->GetArrayBy("InkList");
735 if (!pInkList || pInkList->IsEmpty()) 749 if (!pInkList || pInkList->IsEmpty())
736 return false; 750 return false;
737 751
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 return true; 788 return true;
775 } 789 }
776 790
777 bool CPVT_GenerateAP::GenerateUnderlineAP(CPDF_Document* pDoc, 791 bool CPVT_GenerateAP::GenerateUnderlineAP(CPDF_Document* pDoc,
778 CPDF_Dictionary* pAnnotDict) { 792 CPDF_Dictionary* pAnnotDict) {
779 // If AP dictionary exists, we use the appearance defined in the 793 // If AP dictionary exists, we use the appearance defined in the
780 // existing AP dictionary. 794 // existing AP dictionary.
781 if (pAnnotDict->KeyExist("AP")) 795 if (pAnnotDict->KeyExist("AP"))
782 return false; 796 return false;
783 797
798 if (IsAnnotationHidden(pAnnotDict))
799 return false;
800
784 CFX_ByteTextBuf sAppStream; 801 CFX_ByteTextBuf sAppStream;
785 CFX_ByteString sExtGSDictName = "GS"; 802 CFX_ByteString sExtGSDictName = "GS";
786 sAppStream << "/" << sExtGSDictName << " gs "; 803 sAppStream << "/" << sExtGSDictName << " gs ";
787 804
788 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), 805 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"),
789 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), 806 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0),
790 PaintOperation::STROKE); 807 PaintOperation::STROKE);
791 808
792 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); 809 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect");
793 rect.Normalize(); 810 rect.Normalize();
794 811
795 FX_FLOAT fLineWidth = 1.0; 812 FX_FLOAT fLineWidth = 1.0;
796 sAppStream << fLineWidth << " w " << rect.left << " " 813 sAppStream << fLineWidth << " w " << rect.left << " "
797 << rect.bottom + fLineWidth << " m " << rect.right << " " 814 << rect.bottom + fLineWidth << " m " << rect.right << " "
798 << rect.bottom + fLineWidth << " l S\n"; 815 << rect.bottom + fLineWidth << " l S\n";
799 816
800 CPDF_Dictionary* pExtGStateDict = 817 CPDF_Dictionary* pExtGStateDict =
801 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); 818 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
802 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict); 819 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict);
803 return true; 820 return true;
804 } 821 }
805 822
806 bool CPVT_GenerateAP::GenerateSquareAP(CPDF_Document* pDoc, 823 bool CPVT_GenerateAP::GenerateSquareAP(CPDF_Document* pDoc,
807 CPDF_Dictionary* pAnnotDict) { 824 CPDF_Dictionary* pAnnotDict) {
808 // If AP dictionary exists, we use the appearance defined in the 825 // If AP dictionary exists, we use the appearance defined in the
809 // existing AP dictionary. 826 // existing AP dictionary.
810 if (pAnnotDict->KeyExist("AP")) 827 if (pAnnotDict->KeyExist("AP"))
811 return false; 828 return false;
812 829
830 if (IsAnnotationHidden(pAnnotDict))
831 return false;
832
813 CFX_ByteTextBuf sAppStream; 833 CFX_ByteTextBuf sAppStream;
814 CFX_ByteString sExtGSDictName = "GS"; 834 CFX_ByteString sExtGSDictName = "GS";
815 sAppStream << "/" << sExtGSDictName << " gs "; 835 sAppStream << "/" << sExtGSDictName << " gs ";
816 836
817 CPDF_Array* pInteriorColor = pAnnotDict->GetArrayBy("IC"); 837 CPDF_Array* pInteriorColor = pAnnotDict->GetArrayBy("IC");
818 sAppStream << GetColorStringWithDefault(pInteriorColor, 838 sAppStream << GetColorStringWithDefault(pInteriorColor,
819 CPVT_Color(CPVT_Color::kTransparent), 839 CPVT_Color(CPVT_Color::kTransparent),
820 PaintOperation::FILL); 840 PaintOperation::FILL);
821 841
822 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), 842 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"),
(...skipping 30 matching lines...) Expand all
853 return true; 873 return true;
854 } 874 }
855 875
856 bool CPVT_GenerateAP::GenerateSquigglyAP(CPDF_Document* pDoc, 876 bool CPVT_GenerateAP::GenerateSquigglyAP(CPDF_Document* pDoc,
857 CPDF_Dictionary* pAnnotDict) { 877 CPDF_Dictionary* pAnnotDict) {
858 // If AP dictionary exists, we use the appearance defined in the 878 // If AP dictionary exists, we use the appearance defined in the
859 // existing AP dictionary. 879 // existing AP dictionary.
860 if (pAnnotDict->KeyExist("AP")) 880 if (pAnnotDict->KeyExist("AP"))
861 return false; 881 return false;
862 882
883 if (IsAnnotationHidden(pAnnotDict))
884 return false;
885
863 CFX_ByteTextBuf sAppStream; 886 CFX_ByteTextBuf sAppStream;
864 CFX_ByteString sExtGSDictName = "GS"; 887 CFX_ByteString sExtGSDictName = "GS";
865 sAppStream << "/" << sExtGSDictName << " gs "; 888 sAppStream << "/" << sExtGSDictName << " gs ";
866 889
867 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), 890 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"),
868 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), 891 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0),
869 PaintOperation::STROKE); 892 PaintOperation::STROKE);
870 893
871 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); 894 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect");
872 rect.Normalize(); 895 rect.Normalize();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 return true; 927 return true;
905 } 928 }
906 929
907 bool CPVT_GenerateAP::GenerateStrikeOutAP(CPDF_Document* pDoc, 930 bool CPVT_GenerateAP::GenerateStrikeOutAP(CPDF_Document* pDoc,
908 CPDF_Dictionary* pAnnotDict) { 931 CPDF_Dictionary* pAnnotDict) {
909 // If AP dictionary exists, we use the appearance defined in the 932 // If AP dictionary exists, we use the appearance defined in the
910 // existing AP dictionary. 933 // existing AP dictionary.
911 if (pAnnotDict->KeyExist("AP")) 934 if (pAnnotDict->KeyExist("AP"))
912 return false; 935 return false;
913 936
937 if (IsAnnotationHidden(pAnnotDict))
938 return false;
939
914 CFX_ByteTextBuf sAppStream; 940 CFX_ByteTextBuf sAppStream;
915 CFX_ByteString sExtGSDictName = "GS"; 941 CFX_ByteString sExtGSDictName = "GS";
916 sAppStream << "/" << sExtGSDictName << " gs "; 942 sAppStream << "/" << sExtGSDictName << " gs ";
917 943
918 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), 944 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"),
919 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), 945 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0),
920 PaintOperation::STROKE); 946 PaintOperation::STROKE);
921 947
922 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); 948 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect");
923 rect.Normalize(); 949 rect.Normalize();
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
1194 int32_t nFontIndex, 1220 int32_t nFontIndex,
1195 FX_FLOAT fFontSize) { 1221 FX_FLOAT fFontSize) {
1196 CFX_ByteTextBuf sRet; 1222 CFX_ByteTextBuf sRet;
1197 if (pFontMap) { 1223 if (pFontMap) {
1198 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); 1224 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex);
1199 if (sFontAlias.GetLength() > 0 && fFontSize > 0) 1225 if (sFontAlias.GetLength() > 0 && fFontSize > 0)
1200 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; 1226 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n";
1201 } 1227 }
1202 return sRet.MakeString(); 1228 return sRet.MakeString();
1203 } 1229 }
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