diff options
Diffstat (limited to 'core/fpdfdoc')
-rw-r--r-- | core/fpdfdoc/cpdf_annot.cpp | 75 | ||||
-rw-r--r-- | core/fpdfdoc/cpdf_annot.h | 10 |
2 files changed, 52 insertions, 33 deletions
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<CPDF_Dictionary> 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) { diff --git a/core/fpdfdoc/cpdf_annot.h b/core/fpdfdoc/cpdf_annot.h index 39448ba209..499c62dcba 100644 --- a/core/fpdfdoc/cpdf_annot.h +++ b/core/fpdfdoc/cpdf_annot.h @@ -118,7 +118,15 @@ class CPDF_Annot { CPDF_Annot* m_pPopupAnnot = nullptr; }; +// Get the AP in an annotation dict for a given appearance mode. +// If |eMode| is not Normal and there is not AP for that mode, falls back to +// the Normal AP. CPDF_Stream* FPDFDOC_GetAnnotAP(const CPDF_Dictionary* pAnnotDict, - CPDF_Annot::AppearanceMode mode); + CPDF_Annot::AppearanceMode eMode); + +// Get the AP in an annotation dict for a given appearance mode. +// No fallbacks to Normal like in FPDFDOC_GetAnnotAP. +CPDF_Stream* FPDFDOC_GetAnnotAPNoFallback(const CPDF_Dictionary* pAnnotDict, + CPDF_Annot::AppearanceMode eMode); #endif // CORE_FPDFDOC_CPDF_ANNOT_H_ |