From 710c909117da4297e5a9508bedb306fc5c49eb36 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Wed, 21 Oct 2015 15:46:10 -0400 Subject: Merge to XFA: 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 . (cherry picked from commit 1c77edb7b34e03787605b7965784cea38ef9f1d7) Review URL: https://codereview.chromium.org/1417033004 . --- core/include/fpdfapi/fpdf_objects.h | 12 +++++++++ core/src/fpdfapi/fpdf_font/fpdf_font.cpp | 13 +++++----- core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp | 8 +++--- 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 +- .../src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp | 5 ++-- .../fpdfapi/fpdf_parser/fpdf_parser_objects.cpp | 30 ++++++++++++++-------- .../src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp | 5 ++-- .../fpdfapi/fpdf_parser/fpdf_parser_utility.cpp | 7 ++--- core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp | 2 +- .../fpdfapi/fpdf_render/fpdf_render_loadimage.cpp | 6 ++--- core/src/fpdfdoc/doc_action.cpp | 2 +- core/src/fpdfdoc/doc_bookmark.cpp | 6 ++--- core/src/fpdfdoc/doc_formfield.cpp | 2 +- core/src/fpdfdoc/doc_link.cpp | 6 ++--- core/src/fpdfdoc/doc_tagged.cpp | 8 +++--- fpdfsdk/src/formfiller/FFL_Utils.cpp | 2 +- fpdfsdk/src/fpdfppo.cpp | 5 ++-- fpdfsdk/src/javascript/Document.cpp | 11 +++----- 22 files changed, 112 insertions(+), 110 deletions(-) diff --git a/core/include/fpdfapi/fpdf_objects.h b/core/include/fpdfapi/fpdf_objects.h index a790d349ad..bd7f5bf0c4 100644 --- a/core/include/fpdfapi/fpdf_objects.h +++ b/core/include/fpdfapi/fpdf_objects.h @@ -16,6 +16,7 @@ class CPDF_CryptoHandler; class CPDF_Dictionary; class CPDF_Document; class CPDF_IndirectObjects; +class CPDF_Name; class CPDF_Null; class CPDF_Number; class CPDF_Parser; @@ -82,6 +83,7 @@ class CPDF_Object { bool IsBoolean() const { return m_Type == PDFOBJ_BOOLEAN; } bool IsDictionary() const { return m_Type == PDFOBJ_DICTIONARY; } + bool IsName() const { return m_Type == PDFOBJ_NAME; } bool IsNumber() const { return m_Type == PDFOBJ_NUMBER; } bool IsString() const { return m_Type == PDFOBJ_STRING; } @@ -91,6 +93,9 @@ class CPDF_Object { CPDF_Dictionary* AsDictionary(); const CPDF_Dictionary* AsDictionary() const; + CPDF_Name* AsName(); + const CPDF_Name* AsName() const; + CPDF_Number* AsNumber(); const CPDF_Number* AsNumber() const; @@ -261,6 +266,13 @@ class CPDF_Name : public CPDF_Object { CFX_ByteString m_Name; friend class CPDF_Object; }; +inline CPDF_Name* ToName(CPDF_Object* obj) { + return obj ? obj->AsName() : nullptr; +} +inline const CPDF_Name* ToName(const CPDF_Object* obj) { + return obj ? obj->AsName() : nullptr; +} + class CPDF_Array : public CPDF_Object { public: static CPDF_Array* Create() { return new CPDF_Array(); } diff --git a/core/src/fpdfapi/fpdf_font/fpdf_font.cpp b/core/src/fpdfapi/fpdf_font/fpdf_font.cpp index 77f7f118fc..eb1f52333b 100644 --- a/core/src/fpdfapi/fpdf_font/fpdf_font.cpp +++ b/core/src/fpdfapi/fpdf_font/fpdf_font.cpp @@ -727,7 +727,7 @@ void CPDF_Font::LoadPDFEncoding(CPDF_Object* pEncoding, } return; } - if (pEncoding->GetType() == PDFOBJ_NAME) { + if (pEncoding->IsName()) { if (iBaseEncoding == PDFFONT_ENCODING_ADOBE_SYMBOL || iBaseEncoding == PDFFONT_ENCODING_ZAPFDINGBATS) { return; @@ -769,13 +769,12 @@ void CPDF_Font::LoadPDFEncoding(CPDF_Object* pEncoding, FX_DWORD cur_code = 0; for (FX_DWORD i = 0; i < pDiffs->GetCount(); i++) { CPDF_Object* pElement = pDiffs->GetElementValue(i); - if (pElement == NULL) { + if (!pElement) continue; - } - if (pElement->GetType() == PDFOBJ_NAME) { - if (cur_code < 256) { - pCharNames[cur_code] = ((CPDF_Name*)pElement)->GetString(); - } + + if (CPDF_Name* pName = pElement->AsName()) { + if (cur_code < 256) + pCharNames[cur_code] = pName->GetString(); cur_code++; } else { cur_code = pElement->GetInteger(); diff --git a/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp b/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp index 5095f1a74c..81ec84b2db 100644 --- a/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp +++ b/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp @@ -1206,11 +1206,9 @@ FX_BOOL CPDF_CIDFont::_Load() { return FALSE; } CFX_ByteString subtype = pCIDFontDict->GetString(FX_BSTRC("Subtype")); - m_bType1 = FALSE; - if (subtype == FX_BSTRC("CIDFontType0")) { - m_bType1 = TRUE; - } - if (pEncoding->GetType() == PDFOBJ_NAME) { + m_bType1 = (subtype == FX_BSTRC("CIDFontType0")); + + if (pEncoding->IsName()) { CFX_ByteString cmap = pEncoding->GetString(); m_pCMap = CPDF_ModuleMgr::Get() 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")) { diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp index 55c62e2878..cbbfbd7197 100644 --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp @@ -332,10 +332,9 @@ FX_BOOL PDF_DataDecode(const uint8_t* src_buf, { CPDF_Object* pDecoder = pDict ? pDict->GetElementValue(FX_BSTRC("Filter")) : NULL; - if (pDecoder == NULL || (pDecoder->GetType() != PDFOBJ_ARRAY && - pDecoder->GetType() != PDFOBJ_NAME)) { + if (!pDecoder || (pDecoder->GetType() != PDFOBJ_ARRAY && !pDecoder->IsName())) return FALSE; - } + CPDF_Object* pParams = pDict ? pDict->GetElementValue(FX_BSTRC("DecodeParms")) : NULL; CFX_ByteStringArray DecoderList; diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp index a4bc0c2fa5..dd25044dbc 100644 --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp @@ -22,7 +22,7 @@ void CPDF_Object::Destroy() { delete AsString(); break; case PDFOBJ_NAME: - delete (CPDF_Name*)this; + delete AsName(); break; case PDFOBJ_ARRAY: delete (CPDF_Array*)this; @@ -46,7 +46,7 @@ CFX_ByteString CPDF_Object::GetString() const { case PDFOBJ_STRING: return AsString()->m_String; case PDFOBJ_NAME: - return ((CPDF_Name*)this)->m_Name; + return AsName()->m_Name; case PDFOBJ_REFERENCE: { CPDF_Reference* pRef = (CPDF_Reference*)(void*)this; if (pRef->m_pObjList == NULL) { @@ -68,9 +68,10 @@ CFX_ByteStringC CPDF_Object::GetConstString() const { CFX_ByteString str = AsString()->m_String; return CFX_ByteStringC((const uint8_t*)str, str.GetLength()); } - case PDFOBJ_NAME: - return CFX_ByteStringC((const uint8_t*)((CPDF_Name*)this)->m_Name, - ((CPDF_Name*)this)->m_Name.GetLength()); + case PDFOBJ_NAME: { + CFX_ByteString name = AsName()->m_Name; + return CFX_ByteStringC((const uint8_t*)name, name.GetLength()); + } case PDFOBJ_REFERENCE: { CPDF_Reference* pRef = (CPDF_Reference*)(void*)this; if (pRef->m_pObjList == NULL) { @@ -178,7 +179,7 @@ void CPDF_Object::SetString(const CFX_ByteString& str) { AsString()->m_String = str; return; case PDFOBJ_NAME: - ((CPDF_Name*)this)->m_Name = str; + AsName()->m_Name = str; return; } ASSERT(FALSE); @@ -214,7 +215,7 @@ FX_BOOL CPDF_Object::IsIdentical(CPDF_Object* pOther) const { case PDFOBJ_STRING: return AsString()->Identical(pOther->AsString()); case PDFOBJ_NAME: - return (((CPDF_Name*)this)->Identical((CPDF_Name*)pOther)); + return AsName()->Identical(pOther->AsName()); case PDFOBJ_ARRAY: return (((CPDF_Array*)this)->Identical((CPDF_Array*)pOther)); case PDFOBJ_DICTIONARY: @@ -257,7 +258,7 @@ CPDF_Object* CPDF_Object::CloneInternal(FX_BOOL bDirect, return new CPDF_String(pString->m_String, pString->IsHex()); } case PDFOBJ_NAME: - return new CPDF_Name(((CPDF_Name*)this)->m_Name); + return new CPDF_Name(AsName()->m_Name); case PDFOBJ_ARRAY: { CPDF_Array* pCopy = new CPDF_Array(); CPDF_Array* pThis = (CPDF_Array*)this; @@ -326,9 +327,8 @@ CFX_WideString CPDF_Object::GetUnicodeText(CFX_CharMap* pCharMap) const { PDF_DecodeText(stream.GetData(), stream.GetSize(), pCharMap); return result; } - if (m_Type == PDFOBJ_NAME) { - return PDF_DecodeText(((CPDF_Name*)this)->m_Name, pCharMap); - } + if (const CPDF_Name* pName = AsName()) + return PDF_DecodeText(pName->m_Name, pCharMap); return CFX_WideString(); } void CPDF_Object::SetUnicodeText(const FX_WCHAR* pUnicodes, int len) { @@ -357,6 +357,14 @@ const CPDF_Dictionary* CPDF_Object::AsDictionary() const { return IsDictionary() ? static_cast(this) : nullptr; } +CPDF_Name* CPDF_Object::AsName() { + return IsName() ? static_cast(this) : nullptr; +} + +const CPDF_Name* CPDF_Object::AsName() const { + return IsName() ? static_cast(this) : nullptr; +} + CPDF_Number* CPDF_Object::AsNumber() { return IsNumber() ? static_cast(this) : nullptr; } diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp index 036b293792..f6e1ee895a 100644 --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp @@ -3813,8 +3813,9 @@ int32_t CPDF_DataAvail::CheckCrossRefStream(IFX_DownloadHints* pHints, return 0; } CPDF_Dictionary* pDict = pObj->GetDict(); - CPDF_Object* pName = pDict ? pDict->GetElement(FX_BSTRC("Type")) : NULL; - if (pName && pName->GetType() == PDFOBJ_NAME) { + CPDF_Name* pName = + ToName(pDict ? pDict->GetElement(FX_BSTRC("Type")) : nullptr); + if (pName) { if (pName->GetString() == FX_BSTRC("XRef")) { m_Pos += m_parser.m_Syntax.SavePos(); xref_offset = pObj->GetDict()->GetInteger(FX_BSTRC("Prev")); diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp index 84d1301c60..2c161a7dd4 100644 --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp @@ -372,12 +372,9 @@ CFX_ByteTextBuf& operator<<(CFX_ByteTextBuf& buf, const CPDF_Object* pObj) { case PDFOBJ_NUMBER: buf << " " << pObj->GetString(); break; - case PDFOBJ_STRING: { - CFX_ByteString str = pObj->GetString(); - FX_BOOL bHex = pObj->AsString()->IsHex(); - buf << PDF_EncodeString(str, bHex); + case PDFOBJ_STRING: + buf << PDF_EncodeString(pObj->GetString(), pObj->AsString()->IsHex()); break; - } case PDFOBJ_NAME: { CFX_ByteString str = pObj->GetString(); buf << FX_BSTRC("/") << PDF_NameEncode(str); diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp index e4afdd80c2..cdf2104f82 100644 --- a/core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp +++ b/core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp @@ -406,7 +406,7 @@ FX_BOOL CPDF_ImageRenderer::StartRenderDIBSource() { m_pImageObject->m_pImage->GetStream()->GetDict()->GetElementValue( FX_BSTRC("Filter")); if (pFilters) { - if (pFilters->GetType() == PDFOBJ_NAME) { + if (pFilters->IsName()) { CFX_ByteStringC bsDecodeType = pFilters->GetConstString(); if (bsDecodeType == FX_BSTRC("DCTDecode") || bsDecodeType == FX_BSTRC("JPXDecode")) { diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp index c3029e0091..79b4bba162 100644 --- a/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp +++ b/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp @@ -476,7 +476,7 @@ FX_BOOL CPDF_DIBSource::LoadColorInfo(CPDF_Dictionary* pFormResources, CPDF_Object* pFilter = m_pDict->GetElementValue(FX_BSTRC("Filter")); if (pFilter) { CFX_ByteString filter; - if (pFilter->GetType() == PDFOBJ_NAME) { + if (pFilter->IsName()) { filter = pFilter->GetString(); if (filter == FX_BSTRC("JPXDecode")) { m_bDoBpcCheck = FALSE; @@ -514,7 +514,7 @@ FX_BOOL CPDF_DIBSource::LoadColorInfo(CPDF_Dictionary* pFormResources, } m_Family = m_pColorSpace->GetFamily(); m_nComponents = m_pColorSpace->CountComponents(); - if (m_Family == PDFCS_ICCBASED && pCSObj->GetType() == PDFOBJ_NAME) { + if (m_Family == PDFCS_ICCBASED && pCSObj->IsName()) { CFX_ByteString cs = pCSObj->GetString(); if (cs == FX_BSTRC("DeviceGray")) { m_nComponents = 1; @@ -939,7 +939,7 @@ void CPDF_DIBSource::ValidateDictParam() { m_bpc = m_bpc_orig; CPDF_Object* pFilter = m_pDict->GetElementValue(FX_BSTRC("Filter")); if (pFilter) { - if (pFilter->GetType() == PDFOBJ_NAME) { + if (pFilter->IsName()) { CFX_ByteString filter = pFilter->GetString(); if (filter == FX_BSTRC("CCITTFaxDecode") || filter == FX_BSTRC("JBIG2Decode")) { diff --git a/core/src/fpdfdoc/doc_action.cpp b/core/src/fpdfdoc/doc_action.cpp index c55c20cb1d..bcbfe0f112 100644 --- a/core/src/fpdfdoc/doc_action.cpp +++ b/core/src/fpdfdoc/doc_action.cpp @@ -17,7 +17,7 @@ CPDF_Dest CPDF_Action::GetDest(CPDF_Document* pDoc) const { if (!pDest) { return CPDF_Dest(); } - if (pDest->IsString() || pDest->GetType() == PDFOBJ_NAME) { + if (pDest->IsString() || pDest->IsName()) { CPDF_NameTree name_tree(pDoc, FX_BSTRC("Dests")); CFX_ByteStringC name = pDest->GetString(); return CPDF_Dest(name_tree.LookupNamedDest(pDoc, name)); diff --git a/core/src/fpdfdoc/doc_bookmark.cpp b/core/src/fpdfdoc/doc_bookmark.cpp index 9d2a9f61ea..6b020e5957 100644 --- a/core/src/fpdfdoc/doc_bookmark.cpp +++ b/core/src/fpdfdoc/doc_bookmark.cpp @@ -72,10 +72,10 @@ CPDF_Dest CPDF_Bookmark::GetDest(CPDF_Document* pDocument) const { return CPDF_Dest(); } CPDF_Object* pDest = m_pDict->GetElementValue("Dest"); - if (!pDest) { + if (!pDest) return CPDF_Dest(); - } - if (pDest->IsString() || pDest->GetType() == PDFOBJ_NAME) { + + if (pDest->IsString() || pDest->IsName()) { CPDF_NameTree name_tree(pDocument, FX_BSTRC("Dests")); CFX_ByteStringC name = pDest->GetString(); return CPDF_Dest(name_tree.LookupNamedDest(pDocument, name)); diff --git a/core/src/fpdfdoc/doc_formfield.cpp b/core/src/fpdfdoc/doc_formfield.cpp index 7e734b4e2f..0766eb0bc0 100644 --- a/core/src/fpdfdoc/doc_formfield.cpp +++ b/core/src/fpdfdoc/doc_formfield.cpp @@ -529,7 +529,7 @@ FX_BOOL CPDF_FormField::IsItemSelected(int index) { } if (pValue->IsString()) - return (pValue->GetUnicodeText() == opt_value); + return pValue->GetUnicodeText() == opt_value; if (pValue->IsNumber()) { if (pValue->GetString().IsEmpty()) diff --git a/core/src/fpdfdoc/doc_link.cpp b/core/src/fpdfdoc/doc_link.cpp index 95411013b4..977efeafd1 100644 --- a/core/src/fpdfdoc/doc_link.cpp +++ b/core/src/fpdfdoc/doc_link.cpp @@ -73,10 +73,10 @@ CPDF_Rect CPDF_Link::GetRect() { } CPDF_Dest CPDF_Link::GetDest(CPDF_Document* pDoc) { CPDF_Object* pDest = m_pDict->GetElementValue("Dest"); - if (pDest == NULL) { + if (!pDest) return CPDF_Dest(); - } - if (pDest->IsString() || pDest->GetType() == PDFOBJ_NAME) { + + if (pDest->IsString() || pDest->IsName()) { CPDF_NameTree name_tree(pDoc, FX_BSTRC("Dests")); CFX_ByteStringC name = pDest->GetString(); return CPDF_Dest(name_tree.LookupNamedDest(pDoc, name)); diff --git a/core/src/fpdfdoc/doc_tagged.cpp b/core/src/fpdfdoc/doc_tagged.cpp index d9d439f730..ac29d90118 100644 --- a/core/src/fpdfdoc/doc_tagged.cpp +++ b/core/src/fpdfdoc/doc_tagged.cpp @@ -417,11 +417,11 @@ CFX_ByteString CPDF_StructElementImpl::GetName( FX_BOOL bInheritable, int subindex) { CPDF_Object* pAttr = GetAttr(owner, name, bInheritable, subindex); - if (pAttr == NULL || pAttr->GetType() != PDFOBJ_NAME) { - return default_value; - } - return pAttr->GetString(); + if (ToName(pAttr)) + return pAttr->GetString(); + return default_value; } + FX_ARGB CPDF_StructElementImpl::GetColor(const CFX_ByteStringC& owner, const CFX_ByteStringC& name, FX_ARGB default_value, diff --git a/fpdfsdk/src/formfiller/FFL_Utils.cpp b/fpdfsdk/src/formfiller/FFL_Utils.cpp index e3c8306a0a..3c1edc8455 100644 --- a/fpdfsdk/src/formfiller/FFL_Utils.cpp +++ b/fpdfsdk/src/formfiller/FFL_Utils.cpp @@ -84,7 +84,7 @@ FX_BOOL CFFL_Utils::TraceObject(CPDF_Object* pObj) { // TRACE(pObj->AsString()->GetString() + "\n"); break; case PDFOBJ_NAME: - // TRACE(((CPDF_Name*)pObj)->GetString() + "\n"); + // TRACE(pObj->AsName()->GetString() + "\n"); break; case PDFOBJ_NULL: // case PDFOBJ_KEYWORD: diff --git a/fpdfsdk/src/fpdfppo.cpp b/fpdfsdk/src/fpdfppo.cpp index 6521258485..c37ecca490 100644 --- a/fpdfsdk/src/fpdfppo.cpp +++ b/fpdfsdk/src/fpdfppo.cpp @@ -186,9 +186,8 @@ CPDF_Object* CPDF_PageOrganizer::PageDictGetInheritableTag( return NULL; CPDF_Object* pType = pDict->GetElement("Type")->GetDirect(); - if (!pType || pType->GetType() != PDFOBJ_NAME) - return NULL; - + if (!ToName(pType)) + return nullptr; if (pType->GetString().Compare("Page")) return NULL; if (!pDict->KeyExist("Parent")) diff --git a/fpdfsdk/src/javascript/Document.cpp b/fpdfsdk/src/javascript/Document.cpp index f69a39816f..a51a7a69db 100644 --- a/fpdfsdk/src/javascript/Document.cpp +++ b/fpdfsdk/src/javascript/Document.cpp @@ -850,17 +850,14 @@ FX_BOOL Document::info(IJS_Context* cc, CFX_ByteString bsKey; CPDF_Object* pValueObj = pDictionary->GetNextElement(pos, bsKey); CFX_WideString wsKey = CFX_WideString::FromUTF8(bsKey, bsKey.GetLength()); - if (pValueObj->IsString() || (pValueObj->GetType() == PDFOBJ_NAME)) { + + if (pValueObj->IsString() || pValueObj->IsName()) { FXJS_PutObjectString(isolate, pObj, wsKey.c_str(), pValueObj->GetUnicodeText().c_str()); - } - - if (pValueObj->IsNumber()) { + } else if (pValueObj->IsNumber()) { FXJS_PutObjectNumber(isolate, pObj, wsKey.c_str(), (float)pValueObj->GetNumber()); - } - - if (pValueObj->IsBoolean()) { + } else if (pValueObj->IsBoolean()) { FXJS_PutObjectBoolean(isolate, pObj, wsKey.c_str(), (bool)pValueObj->GetInteger()); } -- cgit v1.2.3