From a74e75d69594e469906e2a95b5f2394c88acbe7a Mon Sep 17 00:00:00 2001 From: Henrique Nakashima Date: Wed, 10 Jan 2018 18:06:55 +0000 Subject: Add FPDFAnnot_GetAP to public API. The matching FPDFAnnot_SetAP will be added in a subsequent CL. Change-Id: If567e02c6c56138d218498879cb4a8ee91dff080 Reviewed-on: https://pdfium-review.googlesource.com/22450 Reviewed-by: dsinclair Commit-Queue: Henrique Nakashima --- core/fpdfdoc/cpdf_annot.cpp | 75 ++++++++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 32 deletions(-) (limited to 'core/fpdfdoc/cpdf_annot.cpp') diff --git a/core/fpdfdoc/cpdf_annot.cpp b/core/fpdfdoc/cpdf_annot.cpp index d1baef5052..02df3cff60 100644 --- a/core/fpdfdoc/cpdf_annot.cpp +++ b/core/fpdfdoc/cpdf_annot.cpp @@ -60,6 +60,43 @@ CPDF_Form* AnnotGetMatrix(const CPDF_Page* pPage, return pForm; } +CPDF_Stream* FPDFDOC_GetAnnotAPInternal(const CPDF_Dictionary* pAnnotDict, + CPDF_Annot::AppearanceMode eMode, + bool bFallbackToNormal) { + CPDF_Dictionary* pAP = pAnnotDict->GetDictFor("AP"); + if (!pAP) + return nullptr; + + const char* ap_entry = "N"; + if (eMode == CPDF_Annot::Down) + ap_entry = "D"; + else if (eMode == CPDF_Annot::Rollover) + ap_entry = "R"; + if (bFallbackToNormal && !pAP->KeyExist(ap_entry)) + ap_entry = "N"; + + CPDF_Object* psub = pAP->GetDirectObjectFor(ap_entry); + if (!psub) + return nullptr; + if (CPDF_Stream* pStream = psub->AsStream()) + return pStream; + + CPDF_Dictionary* pDict = psub->AsDictionary(); + if (!pDict) + return nullptr; + + ByteString as = pAnnotDict->GetStringFor("AS"); + if (as.IsEmpty()) { + ByteString value = pAnnotDict->GetStringFor("V"); + if (value.IsEmpty()) { + CPDF_Dictionary* pParentDict = pAnnotDict->GetDictFor("Parent"); + value = pParentDict ? pParentDict->GetStringFor("V") : ByteString(); + } + as = (!value.IsEmpty() && pDict->KeyExist(value)) ? value : "Off"; + } + return pDict->GetStreamFor(as); +} + } // namespace CPDF_Annot::CPDF_Annot(std::unique_ptr pDict, @@ -140,39 +177,13 @@ uint32_t CPDF_Annot::GetFlags() const { } CPDF_Stream* FPDFDOC_GetAnnotAP(const CPDF_Dictionary* pAnnotDict, - CPDF_Annot::AppearanceMode mode) { - CPDF_Dictionary* pAP = pAnnotDict->GetDictFor("AP"); - if (!pAP) - return nullptr; - - const char* ap_entry = "N"; - if (mode == CPDF_Annot::Down) - ap_entry = "D"; - else if (mode == CPDF_Annot::Rollover) - ap_entry = "R"; - if (!pAP->KeyExist(ap_entry)) - ap_entry = "N"; - - CPDF_Object* psub = pAP->GetDirectObjectFor(ap_entry); - if (!psub) - return nullptr; - if (CPDF_Stream* pStream = psub->AsStream()) - return pStream; - - CPDF_Dictionary* pDict = psub->AsDictionary(); - if (!pDict) - return nullptr; + CPDF_Annot::AppearanceMode eMode) { + return FPDFDOC_GetAnnotAPInternal(pAnnotDict, eMode, true); +} - ByteString as = pAnnotDict->GetStringFor("AS"); - if (as.IsEmpty()) { - ByteString value = pAnnotDict->GetStringFor("V"); - if (value.IsEmpty()) { - CPDF_Dictionary* pParentDict = pAnnotDict->GetDictFor("Parent"); - value = pParentDict ? pParentDict->GetStringFor("V") : ByteString(); - } - as = (!value.IsEmpty() && pDict->KeyExist(value)) ? value : "Off"; - } - return pDict->GetStreamFor(as); +CPDF_Stream* FPDFDOC_GetAnnotAPNoFallback(const CPDF_Dictionary* pAnnotDict, + CPDF_Annot::AppearanceMode eMode) { + return FPDFDOC_GetAnnotAPInternal(pAnnotDict, eMode, false); } CPDF_Form* CPDF_Annot::GetAPForm(const CPDF_Page* pPage, AppearanceMode mode) { -- cgit v1.2.3