Make CPDF_Annot::IsAnnotationHidden() non-static. All the callers pass in |CPDF_Annot::m_pAnnotDict|, so just make it a regular method in CPDF_Annot. This requires also moving ShouldGenerateAPForAnnotation() out of an anonymous namespace in cpdf_annot.cpp and making it a CPDF_Annot method as well. Change-Id: I38c2a6040c6a8ec0d636b4c01f066cd80f24a5a5 Reviewed-on: https://pdfium-review.googlesource.com/c/49651 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfdoc/cpdf_annot.cpp b/core/fpdfdoc/cpdf_annot.cpp index 1976ebe..dd49411 100644 --- a/core/fpdfdoc/cpdf_annot.cpp +++ b/core/fpdfdoc/cpdf_annot.cpp
@@ -35,16 +35,6 @@ type == CPDF_Annot::Subtype::UNDERLINE; } -bool ShouldGenerateAPForAnnotation(CPDF_Dictionary* pAnnotDict) { - // If AP dictionary exists and defines an appearance for normal mode, we use - // the appearance defined in the existing AP dictionary. - CPDF_Dictionary* pAP = pAnnotDict->GetDictFor(pdfium::annotation::kAP); - if (pAP && pAP->GetDictFor("N")) - return false; - - return !CPDF_Annot::IsAnnotationHidden(pAnnotDict); -} - CPDF_Form* AnnotGetMatrix(const CPDF_Page* pPage, CPDF_Annot* pAnnot, CPDF_Annot::AppearanceMode mode, @@ -126,7 +116,7 @@ } void CPDF_Annot::GenerateAPIfNeeded() { - if (!ShouldGenerateAPForAnnotation(m_pAnnotDict.Get())) + if (!ShouldGenerateAP()) return; if (!CPVT_GenerateAP::GenerateAnnotAP(m_nSubtype, m_pDocument.Get(), m_pAnnotDict.Get())) { @@ -137,8 +127,19 @@ m_bHasGeneratedAP = true; } +bool CPDF_Annot::ShouldGenerateAP() const { + // If AP dictionary exists and defines an appearance for normal mode, we use + // the appearance defined in the existing AP dictionary. + const CPDF_Dictionary* pAP = + m_pAnnotDict->GetDictFor(pdfium::annotation::kAP); + if (pAP && pAP->GetDictFor("N")) + return false; + + return !IsHidden(); +} + bool CPDF_Annot::ShouldDrawAnnotation() { - if (IsAnnotationHidden(m_pAnnotDict.Get())) + if (IsHidden()) return false; if (m_nSubtype == CPDF_Annot::Subtype::POPUP && !m_bOpenState) @@ -180,6 +181,10 @@ return m_pAnnotDict->GetIntegerFor(pdfium::annotation::kF); } +bool CPDF_Annot::IsHidden() const { + return !!(GetFlags() & ANNOTFLAG_HIDDEN); +} + CPDF_Stream* GetAnnotAP(CPDF_Dictionary* pAnnotDict, CPDF_Annot::AppearanceMode eMode) { return GetAnnotAPInternal(pAnnotDict, eMode, true); @@ -258,12 +263,6 @@ } // static -bool CPDF_Annot::IsAnnotationHidden(CPDF_Dictionary* pAnnotDict) { - return !!(pAnnotDict->GetIntegerFor(pdfium::annotation::kF) & - ANNOTFLAG_HIDDEN); -} - -// static CPDF_Annot::Subtype CPDF_Annot::StringToAnnotSubtype( const ByteString& sSubtype) { if (sSubtype == "Text")
diff --git a/core/fpdfdoc/cpdf_annot.h b/core/fpdfdoc/cpdf_annot.h index 00de807..43d8f58 100644 --- a/core/fpdfdoc/cpdf_annot.h +++ b/core/fpdfdoc/cpdf_annot.h
@@ -64,7 +64,6 @@ XFAWIDGET }; - static bool IsAnnotationHidden(CPDF_Dictionary* pAnnotDict); static CPDF_Annot::Subtype StringToAnnotSubtype(const ByteString& sSubtype); static ByteString AnnotSubtypeToString(CPDF_Annot::Subtype nSubtype); static CFX_FloatRect RectFromQuadPointsArray(const CPDF_Array* pArray, @@ -86,6 +85,8 @@ CPDF_Document* GetDocument() const { return m_pDocument.Get(); } CPDF_Dictionary* GetAnnotDict() const { return m_pAnnotDict.Get(); } + bool IsHidden() const; + bool DrawAppearance(CPDF_Page* pPage, CFX_RenderDevice* pDevice, const CFX_Matrix& mtUser2Device, @@ -108,6 +109,7 @@ private: void Init(); void GenerateAPIfNeeded(); + bool ShouldGenerateAP() const; bool ShouldDrawAnnotation(); CFX_FloatRect RectForDrawing() const;
diff --git a/fxjs/cjs_annot.cpp b/fxjs/cjs_annot.cpp index e23e4eb..9dc2b8c 100644 --- a/fxjs/cjs_annot.cpp +++ b/fxjs/cjs_annot.cpp
@@ -47,8 +47,7 @@ return CJS_Result::Failure(JSMessage::kBadObjectError); CPDF_Annot* pPDFAnnot = m_pAnnot->AsBAAnnot()->GetPDFAnnot(); - return CJS_Result::Success(pRuntime->NewBoolean( - CPDF_Annot::IsAnnotationHidden(pPDFAnnot->GetAnnotDict()))); + return CJS_Result::Success(pRuntime->NewBoolean(pPDFAnnot->IsHidden())); } CJS_Result CJS_Annot::set_hidden(CJS_Runtime* pRuntime,