diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2015-10-22 15:34:16 -0400 |
---|---|---|
committer | Dan Sinclair <dsinclair@chromium.org> | 2015-10-22 15:34:16 -0400 |
commit | 338805f1366dcdf9a5b48cf591541cf98d7490f1 (patch) | |
tree | 161b722bbb0628b290084b20fa8aa8f1d436c896 /core/src/fpdfdoc | |
parent | c6d8683dbdd922c86375fb0520d420de13d683ed (diff) | |
download | pdfium-338805f1366dcdf9a5b48cf591541cf98d7490f1.tar.xz |
Add type cast definitions for CPDF_Stream.
This Cl adds ToStream, CPDF_Object::AsStream and CPDF_Object::IsStream and
updates the src to use them as needed.
BUG=pdfium:201
R=tsepez@chromium.org
Review URL: https://codereview.chromium.org/1402413004 .
Diffstat (limited to 'core/src/fpdfdoc')
-rw-r--r-- | core/src/fpdfdoc/doc_annot.cpp | 31 | ||||
-rw-r--r-- | core/src/fpdfdoc/doc_basic.cpp | 12 | ||||
-rw-r--r-- | core/src/fpdfdoc/doc_tagged.cpp | 9 |
3 files changed, 23 insertions, 29 deletions
diff --git a/core/src/fpdfdoc/doc_annot.cpp b/core/src/fpdfdoc/doc_annot.cpp index 4d0b703036..d37b1aaadb 100644 --- a/core/src/fpdfdoc/doc_annot.cpp +++ b/core/src/fpdfdoc/doc_annot.cpp @@ -187,22 +187,20 @@ CPDF_Stream* FPDFDOC_GetAnnotAP(CPDF_Dictionary* pAnnotDict, return NULL; } const FX_CHAR* ap_entry = "N"; - if (mode == CPDF_Annot::Down) { + if (mode == CPDF_Annot::Down) ap_entry = "D"; - } else if (mode == CPDF_Annot::Rollover) { + else if (mode == CPDF_Annot::Rollover) ap_entry = "R"; - } - if (!pAP->KeyExist(ap_entry)) { + if (!pAP->KeyExist(ap_entry)) ap_entry = "N"; - } + CPDF_Object* psub = pAP->GetElementValue(ap_entry); - if (psub == NULL) { - return NULL; - } - CPDF_Stream* pStream = NULL; - if (psub->GetType() == PDFOBJ_STREAM) { - pStream = (CPDF_Stream*)psub; - } else if (CPDF_Dictionary* pDict = psub->AsDictionary()) { + if (!psub) + return nullptr; + if (CPDF_Stream* pStream = psub->AsStream()) + return pStream; + + if (CPDF_Dictionary* pDict = psub->AsDictionary()) { CFX_ByteString as = pAnnotDict->GetString("AS"); if (as.IsEmpty()) { CFX_ByteString value = pAnnotDict->GetString(FX_BSTRC("V")); @@ -210,15 +208,14 @@ CPDF_Stream* FPDFDOC_GetAnnotAP(CPDF_Dictionary* pAnnotDict, CPDF_Dictionary* pDict = pAnnotDict->GetDict(FX_BSTRC("Parent")); value = pDict ? pDict->GetString(FX_BSTRC("V")) : CFX_ByteString(); } - if (value.IsEmpty() || !pDict->KeyExist(value)) { + if (value.IsEmpty() || !pDict->KeyExist(value)) as = FX_BSTRC("Off"); - } else { + else as = value; - } } - pStream = pDict->GetStream(as); + return pDict->GetStream(as); } - return pStream; + return nullptr; } CPDF_Form* CPDF_Annot::GetAPForm(const CPDF_Page* pPage, AppearanceMode mode) { CPDF_Stream* pStream = FPDFDOC_GetAnnotAP(m_pAnnotDict, mode); diff --git a/core/src/fpdfdoc/doc_basic.cpp b/core/src/fpdfdoc/doc_basic.cpp index b32e34bb4c..414f5749d0 100644 --- a/core/src/fpdfdoc/doc_basic.cpp +++ b/core/src/fpdfdoc/doc_basic.cpp @@ -380,15 +380,13 @@ CFX_WideString FILESPEC_EncodeFileName(const CFX_WideStringC& filepath) { #endif } CPDF_Stream* CPDF_FileSpec::GetFileStream() const { - if (m_pObj == NULL) { - return NULL; - } - int32_t iType = m_pObj->GetType(); - if (iType == PDFOBJ_STREAM) - return (CPDF_Stream*)m_pObj; + if (!m_pObj) + return nullptr; + if (CPDF_Stream* pStream = m_pObj->AsStream()) + return pStream; if (CPDF_Dictionary* pEF = m_pObj->AsDictionary()->GetDict(FX_BSTRC("EF"))) return pEF->GetStream(FX_BSTRC("F")); - return NULL; + return nullptr; } static void FPDFDOC_FILESPEC_SetFileName(CPDF_Object* pObj, const CFX_WideStringC& wsFileName, diff --git a/core/src/fpdfdoc/doc_tagged.cpp b/core/src/fpdfdoc/doc_tagged.cpp index 2b20e07bb8..f74aa7f6f5 100644 --- a/core/src/fpdfdoc/doc_tagged.cpp +++ b/core/src/fpdfdoc/doc_tagged.cpp @@ -317,8 +317,8 @@ static CPDF_Dictionary* FindAttrDict(CPDF_Object* pAttrs, CPDF_Dictionary* pDict = nullptr; if (pAttrs->IsDictionary()) { pDict = pAttrs->AsDictionary(); - } else if (pAttrs->GetType() == PDFOBJ_STREAM) { - pDict = ((CPDF_Stream*)pAttrs)->GetDict(); + } else if (CPDF_Stream* pStream = pAttrs->AsStream()) { + pDict = pStream->GetDict(); } else if (CPDF_Array* pArray = pAttrs->AsArray()) { for (FX_DWORD i = 0; i < pArray->GetCount(); i++) { CPDF_Object* pElement = pArray->GetElementValue(i); @@ -327,10 +327,9 @@ static CPDF_Dictionary* FindAttrDict(CPDF_Object* pAttrs, return pDict; } } - if (pDict && pDict->GetString(FX_BSTRC("O")) == owner) { + if (pDict && pDict->GetString(FX_BSTRC("O")) == owner) return pDict; - } - return NULL; + return nullptr; } CPDF_Object* CPDF_StructElementImpl::GetAttr(const CFX_ByteStringC& owner, const CFX_ByteStringC& name, |