diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2015-10-21 13:29:23 -0400 |
---|---|---|
committer | Dan Sinclair <dsinclair@chromium.org> | 2015-10-21 13:29:23 -0400 |
commit | 316eb864137a0b8eeb0d0d4d698ba83f4946a89c (patch) | |
tree | 9268f9369d9382ca3ee8f7496ab71394dfa9daef /core | |
parent | 43ce9035a026c7b4f15aa938dc39444d9253ea9f (diff) | |
download | pdfium-316eb864137a0b8eeb0d0d4d698ba83f4946a89c.tar.xz |
Merge to XFA: Add type cast definitions for CPDF_String.
This Cl adds ToString, CPDF_Object::AsString and CPDF_Object::IsString and
updates the src to use them as needed.
BUG=pdfium:201
R=thestig@chromium.org
Review URL: https://codereview.chromium.org/1417933002 .
(cherry picked from commit 53d3ab125ef583be8cfac907b308a6551b93067a)
Review URL: https://codereview.chromium.org/1408323006 .
Diffstat (limited to 'core')
-rw-r--r-- | core/include/fpdfapi/fpdf_objects.h | 11 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp | 4 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp | 9 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp | 6 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp | 9 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp | 40 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp | 2 | ||||
-rw-r--r-- | core/src/fpdfdoc/doc_action.cpp | 32 | ||||
-rw-r--r-- | core/src/fpdfdoc/doc_ap.cpp | 2 | ||||
-rw-r--r-- | core/src/fpdfdoc/doc_basic.cpp | 3 | ||||
-rw-r--r-- | core/src/fpdfdoc/doc_bookmark.cpp | 8 | ||||
-rw-r--r-- | core/src/fpdfdoc/doc_formfield.cpp | 50 | ||||
-rw-r--r-- | core/src/fpdfdoc/doc_link.cpp | 2 | ||||
-rw-r--r-- | core/src/fpdftext/fpdf_text_int.cpp | 7 |
14 files changed, 89 insertions, 96 deletions
diff --git a/core/include/fpdfapi/fpdf_objects.h b/core/include/fpdfapi/fpdf_objects.h index 41b457799b..a790d349ad 100644 --- a/core/include/fpdfapi/fpdf_objects.h +++ b/core/include/fpdfapi/fpdf_objects.h @@ -83,6 +83,7 @@ class CPDF_Object { bool IsBoolean() const { return m_Type == PDFOBJ_BOOLEAN; } bool IsDictionary() const { return m_Type == PDFOBJ_DICTIONARY; } bool IsNumber() const { return m_Type == PDFOBJ_NUMBER; } + bool IsString() const { return m_Type == PDFOBJ_STRING; } CPDF_Boolean* AsBoolean(); const CPDF_Boolean* AsBoolean() const; @@ -93,6 +94,9 @@ class CPDF_Object { CPDF_Number* AsNumber(); const CPDF_Number* AsNumber() const; + CPDF_String* AsString(); + const CPDF_String* AsString() const; + protected: CPDF_Object(FX_DWORD type) : m_Type(type), m_ObjNum(0), m_GenNum(0) {} ~CPDF_Object() {} @@ -222,6 +226,13 @@ class CPDF_String : public CPDF_Object { FX_BOOL m_bHex; friend class CPDF_Object; }; +inline CPDF_String* ToString(CPDF_Object* obj) { + return obj ? obj->AsString() : nullptr; +} +inline const CPDF_String* ToString(const CPDF_Object* obj) { + return obj ? obj->AsString() : nullptr; +} + class CPDF_Name : public CPDF_Object { public: static CPDF_Name* Create(const CFX_ByteString& str) { diff --git a/core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp b/core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp index 3d669a0410..b097389160 100644 --- a/core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp +++ b/core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp @@ -42,7 +42,7 @@ int32_t PDF_CreatorAppendObject(const CPDF_Object* pObj, break; case PDFOBJ_STRING: { CFX_ByteString str = pObj->GetString(); - FX_BOOL bHex = ((CPDF_String*)pObj)->IsHex(); + FX_BOOL bHex = pObj->AsString()->IsHex(); if ((len = pFile->AppendString(PDF_EncodeString(str, bHex))) < 0) { return -1; } @@ -1116,7 +1116,7 @@ int32_t CPDF_Creator::WriteDirectObj(FX_DWORD objnum, break; case PDFOBJ_STRING: { CFX_ByteString str = pObj->GetString(); - FX_BOOL bHex = ((CPDF_String*)pObj)->IsHex(); + FX_BOOL bHex = pObj->AsString()->IsHex(); if (m_pCryptoHandler == NULL || !bEncrypt) { CFX_ByteString content = PDF_EncodeString(str, bHex); if ((len = m_File.AppendString(content)) < 0) { diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp index 3f0de2d416..584f9c24d3 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp @@ -906,12 +906,13 @@ FX_BOOL CPDF_IndexedCS::v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) { m_pCompMinMax[i * 2 + 1] -= m_pCompMinMax[i * 2]; } m_MaxIndex = pArray->GetInteger(2); + CPDF_Object* pTableObj = pArray->GetElementValue(3); - if (pTableObj == NULL) { + if (!pTableObj) return FALSE; - } - if (pTableObj->GetType() == PDFOBJ_STRING) { - m_Table = ((CPDF_String*)pTableObj)->GetString(); + + if (CPDF_String* pString = pTableObj->AsString()) { + m_Table = pString->GetString(); } else if (pTableObj->GetType() == PDFOBJ_STREAM) { CPDF_StreamAcc acc; acc.LoadAllData((CPDF_Stream*)pTableObj, FALSE); diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp index 1283a3a596..fbb364ee12 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp @@ -1359,10 +1359,8 @@ void CPDF_StreamContentParser::Handle_ShowText_Positioning() { } int n = pArray->GetCount(), nsegs = 0, i; for (i = 0; i < n; i++) { - CPDF_Object* pObj = pArray->GetElementValue(i); - if (pObj->GetType() == PDFOBJ_STRING) { + if (pArray->GetElementValue(i)->IsString()) nsegs++; - } } if (nsegs == 0) { for (i = 0; i < n; i++) { @@ -1379,7 +1377,7 @@ void CPDF_StreamContentParser::Handle_ShowText_Positioning() { FX_FLOAT fInitKerning = 0; for (i = 0; i < n; i++) { CPDF_Object* pObj = pArray->GetElementValue(i); - if (pObj->GetType() == PDFOBJ_STRING) { + if (pObj->IsString()) { CFX_ByteString str = pObj->GetString(); if (str.IsEmpty()) { continue; diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp index 82bfbb56eb..c766dd397f 100644 --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp @@ -100,12 +100,10 @@ CFX_WideString CFDF_Document::GetWin32Path() const { CPDF_Dictionary* pDict = m_pRootDict ? m_pRootDict->GetDict(FX_BSTRC("FDF")) : NULL; CPDF_Object* pFileSpec = pDict ? pDict->GetElementValue(FX_BSTRC("F")) : NULL; - if (pFileSpec == NULL) { + if (!pFileSpec) return CFX_WideString(); - } - if (pFileSpec->GetType() == PDFOBJ_STRING) { + if (pFileSpec->IsString()) return FPDF_FileSpec_GetWin32Path(m_pRootDict->GetDict(FX_BSTRC("FDF"))); - } return FPDF_FileSpec_GetWin32Path(pFileSpec); } static CFX_WideString ChangeSlash(const FX_WCHAR* str) { @@ -138,7 +136,8 @@ void FPDF_FileSpec_SetWin32Path(CPDF_Object* pFileSpec, } else { result = ChangeSlash(filepath.c_str()); } - if (pFileSpec->GetType() == PDFOBJ_STRING) { + + if (pFileSpec->IsString()) { pFileSpec->SetString(CFX_ByteString::FromUnicode(result)); } else if (CPDF_Dictionary* pFileDict = pFileSpec->AsDictionary()) { pFileDict->SetAtString(FX_BSTRC("F"), CFX_ByteString::FromUnicode(result)); diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp index a83d0e47b6..a4bc0c2fa5 100644 --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp @@ -19,7 +19,7 @@ void CPDF_Object::Release() { void CPDF_Object::Destroy() { switch (m_Type) { case PDFOBJ_STRING: - delete (CPDF_String*)this; + delete AsString(); break; case PDFOBJ_NAME: delete (CPDF_Name*)this; @@ -44,7 +44,7 @@ CFX_ByteString CPDF_Object::GetString() const { case PDFOBJ_NUMBER: return AsNumber()->GetString(); case PDFOBJ_STRING: - return ((CPDF_String*)this)->m_String; + return AsString()->m_String; case PDFOBJ_NAME: return ((CPDF_Name*)this)->m_Name; case PDFOBJ_REFERENCE: { @@ -64,9 +64,10 @@ CFX_ByteString CPDF_Object::GetString() const { } CFX_ByteStringC CPDF_Object::GetConstString() const { switch (m_Type) { - case PDFOBJ_STRING: - return CFX_ByteStringC((const uint8_t*)((CPDF_String*)this)->m_String, - ((CPDF_String*)this)->m_String.GetLength()); + case PDFOBJ_STRING: { + 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()); @@ -174,7 +175,7 @@ void CPDF_Object::SetString(const CFX_ByteString& str) { AsNumber()->SetString(str); return; case PDFOBJ_STRING: - ((CPDF_String*)this)->m_String = str; + AsString()->m_String = str; return; case PDFOBJ_NAME: ((CPDF_Name*)this)->m_Name = str; @@ -211,7 +212,7 @@ FX_BOOL CPDF_Object::IsIdentical(CPDF_Object* pOther) const { case PDFOBJ_NUMBER: return AsNumber()->Identical(pOther->AsNumber()); case PDFOBJ_STRING: - return (((CPDF_String*)this)->Identical((CPDF_String*)pOther)); + return AsString()->Identical(pOther->AsString()); case PDFOBJ_NAME: return (((CPDF_Name*)this)->Identical((CPDF_Name*)pOther)); case PDFOBJ_ARRAY: @@ -251,9 +252,10 @@ CPDF_Object* CPDF_Object::CloneInternal(FX_BOOL bDirect, return new CPDF_Number(pThis->m_bInteger ? pThis->m_Integer : pThis->m_Float); } - case PDFOBJ_STRING: - return new CPDF_String(((CPDF_String*)this)->m_String, - ((CPDF_String*)this)->IsHex()); + case PDFOBJ_STRING: { + const CPDF_String* pString = AsString(); + return new CPDF_String(pString->m_String, pString->IsHex()); + } case PDFOBJ_NAME: return new CPDF_Name(((CPDF_Name*)this)->m_Name); case PDFOBJ_ARRAY: { @@ -314,9 +316,9 @@ CPDF_Object* CPDF_Object::CloneRef(CPDF_IndirectObjects* pDoc) const { return Clone(); } CFX_WideString CPDF_Object::GetUnicodeText(CFX_CharMap* pCharMap) const { - if (m_Type == PDFOBJ_STRING) { - return PDF_DecodeText(((CPDF_String*)this)->m_String, pCharMap); - } + if (const CPDF_String* pString = AsString()) + return PDF_DecodeText(pString->m_String, pCharMap); + if (m_Type == PDFOBJ_STREAM) { CPDF_StreamAcc stream; stream.LoadAllData((CPDF_Stream*)this, FALSE); @@ -330,8 +332,8 @@ CFX_WideString CPDF_Object::GetUnicodeText(CFX_CharMap* pCharMap) const { return CFX_WideString(); } void CPDF_Object::SetUnicodeText(const FX_WCHAR* pUnicodes, int len) { - if (m_Type == PDFOBJ_STRING) { - ((CPDF_String*)this)->m_String = PDF_EncodeText(pUnicodes, len); + if (CPDF_String* pString = AsString()) { + pString->m_String = PDF_EncodeText(pUnicodes, len); } else if (m_Type == PDFOBJ_STREAM) { CFX_ByteString result = PDF_EncodeText(pUnicodes, len); ((CPDF_Stream*)this) @@ -363,6 +365,14 @@ const CPDF_Number* CPDF_Object::AsNumber() const { return IsNumber() ? static_cast<const CPDF_Number*>(this) : nullptr; } +CPDF_String* CPDF_Object::AsString() { + return IsString() ? static_cast<CPDF_String*>(this) : nullptr; +} + +const CPDF_String* CPDF_Object::AsString() const { + return IsString() ? static_cast<const CPDF_String*>(this) : nullptr; +} + CPDF_Number::CPDF_Number(int value) : CPDF_Object(PDFOBJ_NUMBER), m_bInteger(TRUE), m_Integer(value) {} diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp index c34d8122f8..84d1301c60 100644 --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp @@ -374,7 +374,7 @@ CFX_ByteTextBuf& operator<<(CFX_ByteTextBuf& buf, const CPDF_Object* pObj) { break; case PDFOBJ_STRING: { CFX_ByteString str = pObj->GetString(); - FX_BOOL bHex = ((CPDF_String*)pObj)->IsHex(); + FX_BOOL bHex = pObj->AsString()->IsHex(); buf << PDF_EncodeString(str, bHex); break; } diff --git a/core/src/fpdfdoc/doc_action.cpp b/core/src/fpdfdoc/doc_action.cpp index 409d050484..c55c20cb1d 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->GetType() == PDFOBJ_STRING || pDest->GetType() == PDFOBJ_NAME) { + if (pDest->IsString() || pDest->GetType() == PDFOBJ_NAME) { CPDF_NameTree name_tree(pDoc, FX_BSTRC("Dests")); CFX_ByteStringC name = pDest->GetString(); return CPDF_Dest(name_tree.LookupNamedDest(pDoc, name)); @@ -102,19 +102,14 @@ FX_DWORD CPDF_ActionFields::GetFieldsCount() const { } else { pFields = pDict->GetArray("Fields"); } - if (pFields == NULL) { + if (!pFields) return 0; - } - int iType = pFields->GetType(); - if (iType == PDFOBJ_DICTIONARY) { + if (pFields->IsDictionary()) return 1; - } - if (iType == PDFOBJ_STRING) { + if (pFields->IsString()) return 1; - } - if (iType == PDFOBJ_ARRAY) { + if (pFields->GetType() == PDFOBJ_ARRAY) return ((CPDF_Array*)pFields)->GetCount(); - } return 0; } void CPDF_ActionFields::GetAllFields(CFX_PtrArray& fieldObjects) const { @@ -133,13 +128,12 @@ void CPDF_ActionFields::GetAllFields(CFX_PtrArray& fieldObjects) const { } else { pFields = pDict->GetArray("Fields"); } - if (pFields == NULL) { + if (!pFields) return; - } - int iType = pFields->GetType(); - if (iType == PDFOBJ_DICTIONARY || iType == PDFOBJ_STRING) { + + if (pFields->IsDictionary() || pFields->IsString()) { fieldObjects.Add(pFields); - } else if (iType == PDFOBJ_ARRAY) { + } else if (pFields->GetType() == PDFOBJ_ARRAY) { CPDF_Array* pArray = (CPDF_Array*)pFields; FX_DWORD iCount = pArray->GetCount(); for (FX_DWORD i = 0; i < iCount; i++) { @@ -169,12 +163,10 @@ CPDF_Object* CPDF_ActionFields::GetField(FX_DWORD iIndex) const { return NULL; } CPDF_Object* pFindObj = NULL; - int iType = pFields->GetType(); - if (iType == PDFOBJ_DICTIONARY || iType == PDFOBJ_STRING) { - if (iIndex == 0) { + if (pFields->IsDictionary() || pFields->IsString()) { + if (iIndex == 0) pFindObj = pFields; - } - } else if (iType == PDFOBJ_ARRAY) { + } else if (pFields->GetType() == PDFOBJ_ARRAY) { pFindObj = ((CPDF_Array*)pFields)->GetElementValue(iIndex); } return pFindObj; diff --git a/core/src/fpdfdoc/doc_ap.cpp b/core/src/fpdfdoc/doc_ap.cpp index 2367d0e7e9..71025ec532 100644 --- a/core/src/fpdfdoc/doc_ap.cpp +++ b/core/src/fpdfdoc/doc_ap.cpp @@ -618,7 +618,7 @@ static FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc, } if (CPDF_Object* pOpt = pOpts->GetElementValue(i)) { CFX_WideString swItem; - if (pOpt->GetType() == PDFOBJ_STRING) { + if (pOpt->IsString()) { swItem = pOpt->GetUnicodeText(); } else if (pOpt->GetType() == PDFOBJ_ARRAY) { swItem = diff --git a/core/src/fpdfdoc/doc_basic.cpp b/core/src/fpdfdoc/doc_basic.cpp index bbf51139ad..cbf956bd9b 100644 --- a/core/src/fpdfdoc/doc_basic.cpp +++ b/core/src/fpdfdoc/doc_basic.cpp @@ -406,8 +406,7 @@ static void FPDFDOC_FILESPEC_SetFileName(CPDF_Object* pObj, } else { wsStr = FILESPEC_EncodeFileName(wsFileName); } - int32_t iType = pObj->GetType(); - if (iType == PDFOBJ_STRING) { + if (pObj->IsString()) { pObj->SetString(CFX_ByteString::FromUnicode(wsStr)); } else if (CPDF_Dictionary* pDict = pObj->AsDictionary()) { pDict->SetAtString(FX_BSTRC("F"), CFX_ByteString::FromUnicode(wsStr)); diff --git a/core/src/fpdfdoc/doc_bookmark.cpp b/core/src/fpdfdoc/doc_bookmark.cpp index 2fea810ecc..9d2a9f61ea 100644 --- a/core/src/fpdfdoc/doc_bookmark.cpp +++ b/core/src/fpdfdoc/doc_bookmark.cpp @@ -51,10 +51,10 @@ CFX_WideString CPDF_Bookmark::GetTitle() const { if (!m_pDict) { return CFX_WideString(); } - CPDF_String* pString = (CPDF_String*)m_pDict->GetElementValue("Title"); - if (!pString || pString->GetType() != PDFOBJ_STRING) { + CPDF_String* pString = ToString(m_pDict->GetElementValue("Title")); + if (!pString) return CFX_WideString(); - } + CFX_WideString title = pString->GetUnicodeText(); int len = title.GetLength(); if (!len) { @@ -75,7 +75,7 @@ CPDF_Dest CPDF_Bookmark::GetDest(CPDF_Document* pDocument) const { if (!pDest) { return CPDF_Dest(); } - if (pDest->GetType() == PDFOBJ_STRING || pDest->GetType() == PDFOBJ_NAME) { + if (pDest->IsString() || pDest->GetType() == PDFOBJ_NAME) { 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 aafc17f65c..7e734b4e2f 100644 --- a/core/src/fpdfdoc/doc_formfield.cpp +++ b/core/src/fpdfdoc/doc_formfield.cpp @@ -425,18 +425,10 @@ int CPDF_FormField::CountSelectedItems() { return 0; } } - if (pValue->GetType() == PDFOBJ_STRING) { - if (pValue->GetString().IsEmpty()) { - return 0; - } - return 1; - } - if (pValue->IsNumber()) { - if (pValue->GetString().IsEmpty()) { - return 0; - } - return 1; - } + + if (pValue->IsString() || pValue->IsNumber()) + return pValue->GetString().IsEmpty() ? 0 : 1; + if (pValue->GetType() != PDFOBJ_ARRAY) { return 0; } @@ -454,10 +446,10 @@ int CPDF_FormField::GetSelectedIndex(int index) { return pValue->GetInteger(); CFX_WideString sel_value; - if (pValue->GetType() == PDFOBJ_STRING) { - if (index != 0) { + if (pValue->IsString()) { + if (index != 0) return -1; - } + sel_value = pValue->GetUnicodeText(); } else { if (pValue->GetType() != PDFOBJ_ARRAY) { @@ -535,21 +527,16 @@ FX_BOOL CPDF_FormField::IsItemSelected(int index) { return FALSE; } } - if (pValue->GetType() == PDFOBJ_STRING) { - if (pValue->GetUnicodeText() == opt_value) { - return TRUE; - } - return FALSE; - } + + if (pValue->IsString()) + return (pValue->GetUnicodeText() == opt_value); + if (pValue->IsNumber()) { - if (pValue->GetString().IsEmpty()) { + if (pValue->GetString().IsEmpty()) return FALSE; - } - if (pValue->GetInteger() == index) { - return TRUE; - } - return FALSE; + return (pValue->GetInteger() == index); } + if (pValue->GetType() != PDFOBJ_ARRAY) { return FALSE; } @@ -593,7 +580,7 @@ FX_BOOL CPDF_FormField::SetItemSelection(int index, if (pValue != NULL) { if (m_Type == ListBox) { SelectOption(index, FALSE); - if (pValue->GetType() == PDFOBJ_STRING) { + if (pValue->IsString()) { if (pValue->GetUnicodeText() == opt_value) { m_pDict->RemoveAt("V"); } @@ -734,10 +721,9 @@ CFX_WideString CPDF_FormField::GetOptionText(int index, int sub_index) { if (pOption->GetType() == PDFOBJ_ARRAY) { pOption = ((CPDF_Array*)pOption)->GetElementValue(sub_index); } - if (pOption == NULL || pOption->GetType() != PDFOBJ_STRING) { - return CFX_WideString(); - } - return ((CPDF_String*)pOption)->GetUnicodeText(); + + CPDF_String* pString = ToString(pOption); + return pString ? pString->GetUnicodeText() : CFX_WideString(); } CFX_WideString CPDF_FormField::GetOptionLabel(int index) { return GetOptionText(index, 1); diff --git a/core/src/fpdfdoc/doc_link.cpp b/core/src/fpdfdoc/doc_link.cpp index fbf18f99e5..95411013b4 100644 --- a/core/src/fpdfdoc/doc_link.cpp +++ b/core/src/fpdfdoc/doc_link.cpp @@ -76,7 +76,7 @@ CPDF_Dest CPDF_Link::GetDest(CPDF_Document* pDoc) { if (pDest == NULL) { return CPDF_Dest(); } - if (pDest->GetType() == PDFOBJ_STRING || pDest->GetType() == PDFOBJ_NAME) { + if (pDest->IsString() || pDest->GetType() == PDFOBJ_NAME) { 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/fpdftext/fpdf_text_int.cpp b/core/src/fpdftext/fpdf_text_int.cpp index 152bb4448f..8931acdde4 100644 --- a/core/src/fpdftext/fpdf_text_int.cpp +++ b/core/src/fpdftext/fpdf_text_int.cpp @@ -1341,8 +1341,7 @@ int32_t CPDF_TextPage::PreMarkedContent(PDFTEXT_Obj Obj) { CFX_ByteString tagStr = (CFX_ByteString)item.GetName(); pDict = ToDictionary(static_cast<CPDF_Object*>(item.GetParam())); CPDF_String* temp = - (CPDF_String*)(pDict ? pDict->GetElement(FX_BSTRC("ActualText")) - : NULL); + ToString(pDict ? pDict->GetElement(FX_BSTRC("ActualText")) : nullptr); if (temp) { bExist = TRUE; actText = temp->GetUnicodeText(); @@ -1413,9 +1412,7 @@ void CPDF_TextPage::ProcessMarkedContent(PDFTEXT_Obj Obj) { pDict = ToDictionary(static_cast<CPDF_Object*>(item.GetParam())); CPDF_String* temp = - (CPDF_String*)(pDict ? pDict->GetElement(FX_BSTRC("ActualText")) - : NULL); - + ToString(pDict ? pDict->GetElement(FX_BSTRC("ActualText")) : nullptr); if (temp) { actText = temp->GetUnicodeText(); } |