From 1c77edb7b34e03787605b7965784cea38ef9f1d7 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Wed, 21 Oct 2015 13:55:38 -0400 Subject: Add type cast definitions for CPDF_Name. This Cl adds ToName, CPDF_Object::AsName and CPDF_Object::IsName and updates the src to use them as needed. BUG=pdfium:201 R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1417823005 . --- core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp | 29 ++++++++++------------ core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp | 25 ++++++++----------- .../fpdfapi/fpdf_page/fpdf_page_graph_state.cpp | 7 ++---- core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp | 29 +++++++++++----------- .../src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp | 2 +- 5 files changed, 42 insertions(+), 50 deletions(-) (limited to 'core/src/fpdfapi/fpdf_page') diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp index 584f9c24d3..73b1091856 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp @@ -1057,9 +1057,9 @@ FX_BOOL CPDF_SeparationCS::v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) { return FALSE; } CPDF_Object* pFuncObj = pArray->GetElementValue(3); - if (pFuncObj && pFuncObj->GetType() != PDFOBJ_NAME) { + if (pFuncObj && !pFuncObj->IsName()) m_pFunc = CPDF_Function::Load(pFuncObj); - } + if (m_pFunc && m_pFunc->CountOutputs() < m_pAltCS->CountComponents()) { delete m_pFunc; m_pFunc = NULL; @@ -1202,30 +1202,27 @@ CPDF_ColorSpace* _CSFromName(const CFX_ByteString& name) { return NULL; } CPDF_ColorSpace* CPDF_ColorSpace::Load(CPDF_Document* pDoc, CPDF_Object* pObj) { - if (pObj == NULL) { - return NULL; - } - if (pObj->GetType() == PDFOBJ_NAME) { + if (!pObj) + return nullptr; + if (pObj->IsName()) return _CSFromName(pObj->GetString()); - } + if (pObj->GetType() == PDFOBJ_STREAM) { CPDF_Dictionary* pDict = ((CPDF_Stream*)pObj)->GetDict(); - if (!pDict) { - return NULL; - } - CPDF_ColorSpace* pRet = NULL; + if (!pDict) + return nullptr; + + CPDF_ColorSpace* pRet = nullptr; FX_POSITION pos = pDict->GetStartPos(); while (pos) { CFX_ByteString bsKey; CPDF_Object* pValue = pDict->GetNextElement(pos, bsKey); - if (pValue && pValue->GetType() == PDFOBJ_NAME) { + if (ToName(pValue)) pRet = _CSFromName(pValue->GetString()); - } - if (pRet) { + if (pRet) return pRet; - } } - return NULL; + return nullptr; } if (pObj->GetType() != PDFOBJ_ARRAY) { return NULL; diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp index 210d5433be..9a1d48a416 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp @@ -308,27 +308,27 @@ void CPDF_DocPageData::ReleaseFont(CPDF_Dictionary* pFontDict) { CPDF_ColorSpace* CPDF_DocPageData::GetColorSpace(CPDF_Object* pCSObj, CPDF_Dictionary* pResources) { - if (!pCSObj) { - return NULL; - } - if (pCSObj->GetType() == PDFOBJ_NAME) { + if (!pCSObj) + return nullptr; + + if (pCSObj->IsName()) { CFX_ByteString name = pCSObj->GetConstString(); CPDF_ColorSpace* pCS = _CSFromName(name); if (!pCS && pResources) { CPDF_Dictionary* pList = pResources->GetDict(FX_BSTRC("ColorSpace")); if (pList) { pCSObj = pList->GetElementValue(name); - return GetColorSpace(pCSObj, NULL); + return GetColorSpace(pCSObj, nullptr); } } - if (pCS == NULL || pResources == NULL) { + if (!pCS || !pResources) return pCS; - } + CPDF_Dictionary* pColorSpaces = pResources->GetDict(FX_BSTRC("ColorSpace")); - if (pColorSpaces == NULL) { + if (!pColorSpaces) return pCS; - } - CPDF_Object* pDefaultCS = NULL; + + CPDF_Object* pDefaultCS = nullptr; switch (pCS->GetFamily()) { case PDFCS_DEVICERGB: pDefaultCS = pColorSpaces->GetElementValue(FX_BSTRC("DefaultRGB")); @@ -340,10 +340,7 @@ CPDF_ColorSpace* CPDF_DocPageData::GetColorSpace(CPDF_Object* pCSObj, pDefaultCS = pColorSpaces->GetElementValue(FX_BSTRC("DefaultCMYK")); break; } - if (pDefaultCS == NULL) { - return pCS; - } - return GetColorSpace(pDefaultCS, NULL); + return pDefaultCS ? GetColorSpace(pDefaultCS, nullptr) : pCS; } if (pCSObj->GetType() != PDFOBJ_ARRAY) diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp index 6d071f3ae0..62a3c67996 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp @@ -510,11 +510,8 @@ void CPDF_AllStates::ProcessExtGS(CPDF_Dictionary* pGS, continue; } case FXBSTR_ID('T', 'R', '2', 0): - if (pObject && pObject->GetType() != PDFOBJ_NAME) { - pGeneralState->m_pTR = pObject; - } else { - pGeneralState->m_pTR = NULL; - } + pGeneralState->m_pTR = + (pObject && !pObject->IsName()) ? pObject : nullptr; break; case FXBSTR_ID('B', 'M', 0, 0): { CFX_ByteString mode; diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp index fbb364ee12..6f186e6c3b 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp @@ -413,11 +413,10 @@ void CPDF_StreamContentParser::Handle_BeginMarkedContent_Dictionary() { return; } FX_BOOL bDirect = TRUE; - if (pProperty->GetType() == PDFOBJ_NAME) { + if (pProperty->IsName()) { pProperty = FindResourceObj(FX_BSTRC("Properties"), pProperty->GetString()); - if (pProperty == NULL) { + if (!pProperty) return; - } bDirect = FALSE; } if (CPDF_Dictionary* pDict = pProperty->AsDictionary()) { @@ -499,7 +498,8 @@ void _PDF_ReplaceAbbr(CPDF_Object* pObj) { pDict->ReplaceKey(key, fullname); key = fullname; } - if (value->GetType() == PDFOBJ_NAME) { + + if (value->IsName()) { CFX_ByteString name = value->GetString(); fullname = _PDF_FindFullName( _PDF_InlineValueAbbr, @@ -517,7 +517,7 @@ void _PDF_ReplaceAbbr(CPDF_Object* pObj) { CPDF_Array* pArray = (CPDF_Array*)pObj; for (FX_DWORD i = 0; i < pArray->GetCount(); i++) { CPDF_Object* pElement = pArray->GetElement(i); - if (pElement->GetType() == PDFOBJ_NAME) { + if (pElement->IsName()) { CFX_ByteString name = pElement->GetString(); CFX_ByteStringC fullname = _PDF_FindFullName( _PDF_InlineValueAbbr, @@ -562,7 +562,7 @@ void _PDF_ReplaceFull(CPDF_Object* pObj) { pDict->ReplaceKey(key, abbrName); key = abbrName; } - if (value->GetType() == PDFOBJ_NAME) { + if (value->IsName()) { CFX_ByteString name = value->GetString(); abbrName = _PDF_FindAbbrName( _PDF_InlineValueAbbr, @@ -580,7 +580,7 @@ void _PDF_ReplaceFull(CPDF_Object* pObj) { CPDF_Array* pArray = (CPDF_Array*)pObj; for (FX_DWORD i = 0; i < pArray->GetCount(); i++) { CPDF_Object* pElement = pArray->GetElement(i); - if (pElement->GetType() == PDFOBJ_NAME) { + if (pElement->IsName()) { CFX_ByteString name = pElement->GetString(); CFX_ByteStringC abbrName = _PDF_FindAbbrName( _PDF_InlineValueAbbr, @@ -1065,7 +1065,7 @@ void CPDF_StreamContentParser::Handle_SetColorPS_Fill() { } int nargs = m_ParamCount; int nvalues = nargs; - if (pLastParam->GetType() == PDFOBJ_NAME) { + if (pLastParam->IsName()) { nvalues--; } FX_FLOAT* values = NULL; @@ -1095,9 +1095,9 @@ void CPDF_StreamContentParser::Handle_SetColorPS_Stroke() { } int nargs = m_ParamCount; int nvalues = nargs; - if (pLastParam->GetType() == PDFOBJ_NAME) { + if (pLastParam->IsName()) nvalues--; - } + FX_FLOAT* values = NULL; if (nvalues) { values = FX_Alloc(FX_FLOAT, nvalues); @@ -1357,13 +1357,14 @@ void CPDF_StreamContentParser::Handle_ShowText_Positioning() { if (pArray == NULL) { return; } - int n = pArray->GetCount(), nsegs = 0, i; - for (i = 0; i < n; i++) { + int n = pArray->GetCount(); + int nsegs = 0; + for (int i = 0; i < n; i++) { if (pArray->GetElementValue(i)->IsString()) nsegs++; } if (nsegs == 0) { - for (i = 0; i < n; i++) { + for (int i = 0; i < n; i++) { m_pCurStates->m_TextX -= FXSYS_Mul(pArray->GetNumber(i), m_pCurStates->m_TextState.GetFontSize()) / @@ -1375,7 +1376,7 @@ void CPDF_StreamContentParser::Handle_ShowText_Positioning() { FX_FLOAT* pKerning = FX_Alloc(FX_FLOAT, nsegs); int iSegment = 0; FX_FLOAT fInitKerning = 0; - for (i = 0; i < n; i++) { + for (int i = 0; i < n; i++) { CPDF_Object* pObj = pArray->GetElementValue(i); if (pObj->IsString()) { CFX_ByteString str = pObj->GetString(); diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp index b1e89e8cc4..f051d0db5a 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp @@ -88,7 +88,7 @@ void CPDF_StreamContentParser::Handle_BeginImage() { CPDF_Object* pCSObj = NULL; if (pDict->KeyExist(FX_BSTRC("ColorSpace"))) { pCSObj = pDict->GetElementValue(FX_BSTRC("ColorSpace")); - if (pCSObj->GetType() == PDFOBJ_NAME) { + if (pCSObj->IsName()) { CFX_ByteString name = pCSObj->GetString(); if (name != FX_BSTRC("DeviceRGB") && name != FX_BSTRC("DeviceGray") && name != FX_BSTRC("DeviceCMYK")) { -- cgit v1.2.3