diff options
author | Henrique Nakashima <hnakashima@chromium.org> | 2018-01-10 18:06:55 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-01-10 18:06:55 +0000 |
commit | a74e75d69594e469906e2a95b5f2394c88acbe7a (patch) | |
tree | 3c77b9358876819d50baa7f43a98e15dd33c2bbf /core | |
parent | 7d36c3e835bc32898f0064226d79a8f0f89e15ec (diff) | |
download | pdfium-a74e75d69594e469906e2a95b5f2394c88acbe7a.tar.xz |
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 <dsinclair@chromium.org>
Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
Diffstat (limited to 'core')
-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_ |