Hidden annotations should not be drawn

Now that PDFium supports drawing of more annotation
types, it should also respect the "hidden" flag that
annotations might feature.
For instance, in IE/Acroread if an annotation is flagged as
"hidden" it does not get drawn.

CL adds a check for the specific "hidden" flag, not drawing
annotation that are flagged with it, in order to match IE + acrobat
reader behavior.

The "flags" definition can be seen by looking at "/F {value}"
syntax in a PDF file source, where {value} is an predefined
integer value.

Test: PDF files being added in [1].

[1] https://codereview.chromium.org/2239713003/

BUG=62625

Review-Url: https://codereview.chromium.org/2239853002
diff --git a/DEPS b/DEPS
index 73682c3..37daf56 100644
--- a/DEPS
+++ b/DEPS
@@ -14,7 +14,7 @@
   'gmock_revision': '29763965ab52f24565299976b936d1265cb6a271',
   'gtest_revision': '8245545b6dc9c4703e6496d1efd19e975ad2b038',
   'icu_revision': 'a5f86adbb0a58d04c035a5d1228747b1823cd485',
-  'pdfium_tests_revision': '4119f8ed4e89156e646c3fd235b61718da5e9b45',
+  'pdfium_tests_revision': '1fdec9eaee514481092dd8e066029db71644829a',
   'skia_revision': '36c38cbb29744e0b5390a38367e47c0c74287c2d',
   'tools_memory_revision': '427f10475e1a8d72424c29d00bf689122b738e5d',
   'trace_event_revision': '54b8455be9505c2cb0cf5c26bb86739c236471aa',
diff --git a/core/fpdfdoc/cpdf_annot.cpp b/core/fpdfdoc/cpdf_annot.cpp
index 2b9b936..617ea0f 100644
--- a/core/fpdfdoc/cpdf_annot.cpp
+++ b/core/fpdfdoc/cpdf_annot.cpp
@@ -133,11 +133,20 @@
   matrix.Concat(*pUser2Device);
   return pForm;
 }
+
+// static
+bool CPDF_Annot::IsAnnotationHidden(CPDF_Dictionary* pAnnotDict) {
+  return !!(pAnnotDict->GetIntegerBy("F") & ANNOTFLAG_HIDDEN);
+}
+
 FX_BOOL CPDF_Annot::DrawAppearance(CPDF_Page* pPage,
                                    CFX_RenderDevice* pDevice,
                                    const CFX_Matrix* pUser2Device,
                                    AppearanceMode mode,
                                    const CPDF_RenderOptions* pOptions) {
+  if (IsAnnotationHidden(m_pAnnotDict))
+    return FALSE;
+
   CFX_Matrix matrix;
   CPDF_Form* pForm =
       FPDFDOC_Annot_GetMatrix(pPage, this, mode, pUser2Device, matrix);
diff --git a/core/fpdfdoc/cpvt_generateap.cpp b/core/fpdfdoc/cpvt_generateap.cpp
index f15869b..da3c052 100644
--- a/core/fpdfdoc/cpvt_generateap.cpp
+++ b/core/fpdfdoc/cpvt_generateap.cpp
@@ -14,6 +14,7 @@
 #include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h"
 #include "core/fpdfdoc/cpvt_color.h"
 #include "core/fpdfdoc/cpvt_fontmap.h"
+#include "core/fpdfdoc/include/cpdf_annot.h"
 #include "core/fpdfdoc/include/cpdf_formfield.h"
 #include "core/fpdfdoc/include/cpvt_word.h"
 
@@ -562,6 +563,15 @@
   return bIsFillRect ? "f" : "n";
 }
 
+bool ShouldGenerateAPForAnnotation(CPDF_Dictionary* pAnnotDict) {
+  // If AP dictionary exists, we use the appearance defined in the
+  // existing AP dictionary.
+  if (pAnnotDict->KeyExist("AP"))
+    return false;
+
+  return !CPDF_Annot::IsAnnotationHidden(pAnnotDict);
+}
+
 }  // namespace
 
 bool FPDF_GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) {
@@ -614,9 +624,7 @@
 
 bool CPVT_GenerateAP::GenerateCircleAP(CPDF_Document* pDoc,
                                        CPDF_Dictionary* pAnnotDict) {
-  // If AP dictionary exists, we use the appearance defined in the
-  // existing AP dictionary.
-  if (pAnnotDict->KeyExist("AP"))
+  if (!ShouldGenerateAPForAnnotation(pAnnotDict))
     return false;
 
   CFX_ByteTextBuf sAppStream;
@@ -690,9 +698,7 @@
 
 bool CPVT_GenerateAP::GenerateHighlightAP(CPDF_Document* pDoc,
                                           CPDF_Dictionary* pAnnotDict) {
-  // If AP dictionary exists, we use the appearance defined in the
-  // existing AP dictionary.
-  if (pAnnotDict->KeyExist("AP"))
+  if (!ShouldGenerateAPForAnnotation(pAnnotDict))
     return false;
 
   CFX_ByteTextBuf sAppStream;
@@ -720,9 +726,7 @@
 
 bool CPVT_GenerateAP::GenerateInkAP(CPDF_Document* pDoc,
                                     CPDF_Dictionary* pAnnotDict) {
-  // If AP dictionary exists, we use the appearance defined in the
-  // existing AP dictionary.
-  if (pAnnotDict->KeyExist("AP"))
+  if (!ShouldGenerateAPForAnnotation(pAnnotDict))
     return false;
 
   FX_FLOAT fBorderWidth = GetBorderWidth(*pAnnotDict);
@@ -776,9 +780,7 @@
 
 bool CPVT_GenerateAP::GenerateUnderlineAP(CPDF_Document* pDoc,
                                           CPDF_Dictionary* pAnnotDict) {
-  // If AP dictionary exists, we use the appearance defined in the
-  // existing AP dictionary.
-  if (pAnnotDict->KeyExist("AP"))
+  if (!ShouldGenerateAPForAnnotation(pAnnotDict))
     return false;
 
   CFX_ByteTextBuf sAppStream;
@@ -805,9 +807,7 @@
 
 bool CPVT_GenerateAP::GenerateSquareAP(CPDF_Document* pDoc,
                                        CPDF_Dictionary* pAnnotDict) {
-  // If AP dictionary exists, we use the appearance defined in the
-  // existing AP dictionary.
-  if (pAnnotDict->KeyExist("AP"))
+  if (!ShouldGenerateAPForAnnotation(pAnnotDict))
     return false;
 
   CFX_ByteTextBuf sAppStream;
@@ -855,9 +855,7 @@
 
 bool CPVT_GenerateAP::GenerateSquigglyAP(CPDF_Document* pDoc,
                                          CPDF_Dictionary* pAnnotDict) {
-  // If AP dictionary exists, we use the appearance defined in the
-  // existing AP dictionary.
-  if (pAnnotDict->KeyExist("AP"))
+  if (!ShouldGenerateAPForAnnotation(pAnnotDict))
     return false;
 
   CFX_ByteTextBuf sAppStream;
@@ -906,9 +904,7 @@
 
 bool CPVT_GenerateAP::GenerateStrikeOutAP(CPDF_Document* pDoc,
                                           CPDF_Dictionary* pAnnotDict) {
-  // If AP dictionary exists, we use the appearance defined in the
-  // existing AP dictionary.
-  if (pAnnotDict->KeyExist("AP"))
+  if (!ShouldGenerateAPForAnnotation(pAnnotDict))
     return false;
 
   CFX_ByteTextBuf sAppStream;
diff --git a/core/fpdfdoc/include/cpdf_annot.h b/core/fpdfdoc/include/cpdf_annot.h
index 99efd98..4999349 100644
--- a/core/fpdfdoc/include/cpdf_annot.h
+++ b/core/fpdfdoc/include/cpdf_annot.h
@@ -37,6 +37,8 @@
  public:
   enum AppearanceMode { Normal, Rollover, Down };
 
+  static bool IsAnnotationHidden(CPDF_Dictionary* pAnnotDict);
+
   CPDF_Annot(CPDF_Dictionary* pDict, CPDF_Document* pDocument);
   ~CPDF_Annot();
 
diff --git a/testing/SUPPRESSIONS b/testing/SUPPRESSIONS
index 3717f75..f97e38c 100644
--- a/testing/SUPPRESSIONS
+++ b/testing/SUPPRESSIONS
@@ -436,12 +436,18 @@
 new_stamp4.pdf mac * *
 new_stamp5.pdf mac * *
 new_textmarkup1.pdf mac * *
+new_textmarkup1_hidden.pdf mac * *
 new_textmarkup2.pdf mac * *
+new_textmarkup2_hidden.pdf mac * *
 new_textmarkup4.pdf mac * *
+new_textmarkup4_hidden.pdf mac * *
 new_textmarkup5.pdf mac * *
+new_textmarkup5_hidden.pdf mac * *
 new_textmarkup6.pdf mac * *
 new_textmarkup7.pdf mac * *
+new_textmarkup7_hidden.pdf mac * *
 new_textmarkup8.pdf mac * *
+new_textmarkup8_hidden.pdf mac * *
 number.pdf * * *
 octest.pdf mac * *
 open_a_weblink.pdf mac * *