summaryrefslogtreecommitdiff
path: root/core/src/fpdfapi
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2015-10-20 13:30:34 -0400
committerDan Sinclair <dsinclair@chromium.org>2015-10-20 13:30:34 -0400
commit937840e1722d1f2b77d80575d6e710d760662c9c (patch)
treeff065615d6d91abe8e5c788da3a08386fc2d25d6 /core/src/fpdfapi
parentc29bee029cd5fe3f8a4ceb580235ac2d0e5ce8fd (diff)
downloadpdfium-937840e1722d1f2b77d80575d6e710d760662c9c.tar.xz
Revert "Add type cast definitions for CPDF_Dictionary."
This reverts commit 4816432671eef6467354aa252f22bb80acc315b7. Reason, broke the javascript_test Rendering PDF file /mnt/data/b/build/slave/linux/build/pdfium/out/Debug/gen/pdfium/testing/javascript/document_methods.pdf. Non-linearized path... FAILURE: document_methods.in; Command '['/mnt/data/b/build/slave/linux/build/pdfium/out/Debug/pdfium_test', '/mnt/data/b/build/slave/linux/build/pdfium/out/Debug/gen/pdfium/testing/javascript/document_methods.pdf']' returned non-zero exit status -11 BUG=pdfium:201 TBR=thestig@chromium.org Review URL: https://codereview.chromium.org/1412413002 .
Diffstat (limited to 'core/src/fpdfapi')
-rw-r--r--core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp11
-rw-r--r--core/src/fpdfapi/fpdf_font/fpdf_font.cpp8
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_func.cpp6
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp14
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_image.cpp5
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp23
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp11
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_document.cpp13
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp29
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp32
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp27
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp2
-rw-r--r--core/src/fpdfapi/fpdf_render/fpdf_render.cpp5
-rw-r--r--core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp4
14 files changed, 92 insertions, 98 deletions
diff --git a/core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp b/core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp
index 054cf10c22..4e6c72355d 100644
--- a/core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp
+++ b/core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp
@@ -110,7 +110,7 @@ int32_t PDF_CreatorAppendObject(const CPDF_Object* pObj,
return -1;
}
offset += 2;
- const CPDF_Dictionary* p = pObj->AsDictionary();
+ CPDF_Dictionary* p = (CPDF_Dictionary*)pObj;
FX_POSITION pos = p->GetStartPos();
while (pos) {
CFX_ByteString key;
@@ -334,8 +334,7 @@ CPDF_FlateEncoder::CPDF_FlateEncoder() {
}
void CPDF_FlateEncoder::CloneDict() {
if (!m_bCloned) {
- m_pDict = ToDictionary(m_pDict->Clone());
- ASSERT(m_pDict);
+ m_pDict = (CPDF_Dictionary*)m_pDict->Clone();
m_bCloned = TRUE;
}
}
@@ -350,7 +349,7 @@ FX_BOOL CPDF_FlateEncoder::Initialize(CPDF_Stream* pStream,
destAcc.LoadAllData(pStream);
m_dwSize = destAcc.GetSize();
m_pData = (uint8_t*)destAcc.DetachData();
- m_pDict = ToDictionary(pStream->GetDict()->Clone());
+ m_pDict = (CPDF_Dictionary*)pStream->GetDict()->Clone();
m_pDict->RemoveAt(FX_BSTRC("Filter"));
m_bNewData = TRUE;
m_bCloned = TRUE;
@@ -366,7 +365,7 @@ FX_BOOL CPDF_FlateEncoder::Initialize(CPDF_Stream* pStream,
m_bNewData = TRUE;
m_bCloned = TRUE;
::FlateEncode(m_Acc.GetData(), m_Acc.GetSize(), m_pData, m_dwSize);
- m_pDict = ToDictionary(pStream->GetDict()->Clone());
+ m_pDict = (CPDF_Dictionary*)pStream->GetDict()->Clone();
m_pDict->SetAtInteger("Length", m_dwSize);
m_pDict->SetAtName("Filter", "FlateDecode");
m_pDict->RemoveAt("DecodeParms");
@@ -1228,7 +1227,7 @@ int32_t CPDF_Creator::WriteDirectObj(FX_DWORD objnum,
return -1;
}
m_Offset += 2;
- const CPDF_Dictionary* p = pObj->AsDictionary();
+ CPDF_Dictionary* p = (CPDF_Dictionary*)pObj;
FX_BOOL bSignDict = IsSignatureDict(p);
FX_POSITION pos = p->GetStartPos();
while (pos) {
diff --git a/core/src/fpdfapi/fpdf_font/fpdf_font.cpp b/core/src/fpdfapi/fpdf_font/fpdf_font.cpp
index 10ca3113e3..7a57889a35 100644
--- a/core/src/fpdfapi/fpdf_font/fpdf_font.cpp
+++ b/core/src/fpdfapi/fpdf_font/fpdf_font.cpp
@@ -746,11 +746,10 @@ void CPDF_Font::LoadPDFEncoding(CPDF_Object* pEncoding,
GetPredefinedEncoding(iBaseEncoding, bsEncoding);
return;
}
-
- CPDF_Dictionary* pDict = pEncoding->AsDictionary();
- if (!pDict)
+ if (pEncoding->GetType() != PDFOBJ_DICTIONARY) {
return;
-
+ }
+ CPDF_Dictionary* pDict = (CPDF_Dictionary*)pEncoding;
if (iBaseEncoding != PDFFONT_ENCODING_ADOBE_SYMBOL &&
iBaseEncoding != PDFFONT_ENCODING_ZAPFDINGBATS) {
CFX_ByteString bsEncoding = pDict->GetString(FX_BSTRC("BaseEncoding"));
@@ -783,7 +782,6 @@ void CPDF_Font::LoadPDFEncoding(CPDF_Object* pEncoding,
}
}
}
-
FX_BOOL CPDF_Font::IsStandardFont() const {
if (m_FontType != PDFFONT_TYPE1)
return FALSE;
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_func.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_func.cpp
index d66a9efdaa..224c99bb69 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_func.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_func.cpp
@@ -818,8 +818,8 @@ CPDF_Function* CPDF_Function::Load(CPDF_Object* pFuncObj) {
type = ((CPDF_Stream*)pFuncObj)
->GetDict()
->GetInteger(FX_BSTRC("FunctionType"));
- } else if (CPDF_Dictionary* pDict = pFuncObj->AsDictionary()) {
- type = pDict->GetInteger(FX_BSTRC("FunctionType"));
+ } else if (pFuncObj->GetType() == PDFOBJ_DICTIONARY) {
+ type = ((CPDF_Dictionary*)pFuncObj)->GetInteger(FX_BSTRC("FunctionType"));
} else {
return NULL;
}
@@ -853,7 +853,7 @@ FX_BOOL CPDF_Function::Init(CPDF_Object* pObj) {
if (pObj->GetType() == PDFOBJ_STREAM) {
pDict = ((CPDF_Stream*)pObj)->GetDict();
} else {
- pDict = pObj->AsDictionary();
+ pDict = (CPDF_Dictionary*)pObj;
}
CPDF_Array* pDomains = pDict->GetArray(FX_BSTRC("Domain"));
if (pDomains == NULL) {
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..f11a2bb8d1 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp
@@ -530,7 +530,7 @@ void CPDF_AllStates::ProcessExtGS(CPDF_Dictionary* pGS,
break;
}
case FXBSTR_ID('S', 'M', 'a', 's'):
- if (ToDictionary(pObject)) {
+ if (pObject && pObject->GetType() == PDFOBJ_DICTIONARY) {
pGeneralState->m_pSoftMask = pObject;
FXSYS_memcpy(pGeneralState->m_SMaskMatrix,
&pParser->GetCurStates()->m_CTM, sizeof(CPDF_Matrix));
@@ -599,21 +599,20 @@ CPDF_ContentMarkItem::CPDF_ContentMarkItem(const CPDF_ContentMarkItem& src) {
m_MarkName = src.m_MarkName;
m_ParamType = src.m_ParamType;
if (m_ParamType == DirectDict) {
- m_pParam = ToDictionary(static_cast<CPDF_Object*>(src.m_pParam))->Clone();
+ m_pParam = ((CPDF_Dictionary*)src.m_pParam)->Clone();
} else {
m_pParam = src.m_pParam;
}
}
CPDF_ContentMarkItem::~CPDF_ContentMarkItem() {
if (m_ParamType == DirectDict && m_pParam) {
- ToDictionary(static_cast<CPDF_Object*>(m_pParam))->Release();
+ ((CPDF_Dictionary*)m_pParam)->Release();
}
}
FX_BOOL CPDF_ContentMarkItem::HasMCID() const {
if (m_pParam &&
(m_ParamType == DirectDict || m_ParamType == PropertiesDict)) {
- return ToDictionary(static_cast<CPDF_Object*>(m_pParam))
- ->KeyExist(FX_BSTRC("MCID"));
+ return ((CPDF_Dictionary*)m_pParam)->KeyExist(FX_BSTRC("MCID"));
}
return FALSE;
}
@@ -628,8 +627,7 @@ int CPDF_ContentMarkData::GetMCID() const {
type = m_Marks[i].GetParamType();
if (type == CPDF_ContentMarkItem::PropertiesDict ||
type == CPDF_ContentMarkItem::DirectDict) {
- CPDF_Dictionary* pDict =
- ToDictionary(static_cast<CPDF_Object*>(m_Marks[i].GetParam()));
+ CPDF_Dictionary* pDict = (CPDF_Dictionary*)m_Marks[i].GetParam();
if (pDict->KeyExist(FX_BSTRC("MCID"))) {
return pDict->GetInteger(FX_BSTRC("MCID"));
}
@@ -679,7 +677,7 @@ FX_BOOL CPDF_ContentMark::LookupMark(const CFX_ByteStringC& mark,
pDict = NULL;
if (item.GetParamType() == CPDF_ContentMarkItem::PropertiesDict ||
item.GetParamType() == CPDF_ContentMarkItem::DirectDict) {
- pDict = ToDictionary(static_cast<CPDF_Object*>(item.GetParam()));
+ pDict = (CPDF_Dictionary*)item.GetParam();
}
return TRUE;
}
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_image.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_image.cpp
index 9cdf00e717..e9f70c14db 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_image.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_image.cpp
@@ -52,7 +52,8 @@ CPDF_Image* CPDF_Image::Clone() {
pImage->LoadImageF((CPDF_Stream*)((CPDF_Object*)m_pStream)->Clone(),
m_bInline);
if (m_bInline) {
- pImage->SetInlineDict(ToDictionary(m_pInlineDict->Clone(TRUE)));
+ CPDF_Dictionary* pInlineDict = (CPDF_Dictionary*)m_pInlineDict->Clone(TRUE);
+ pImage->SetInlineDict(pInlineDict);
}
return pImage;
}
@@ -85,7 +86,7 @@ FX_BOOL CPDF_Image::LoadImageF(CPDF_Stream* pStream, FX_BOOL bInline) {
m_bInline = bInline;
CPDF_Dictionary* pDict = pStream->GetDict();
if (m_bInline) {
- m_pInlineDict = ToDictionary(pDict->Clone());
+ m_pInlineDict = (CPDF_Dictionary*)pDict->Clone();
}
m_pOC = pDict->GetDict(FX_BSTRC("OC"));
m_bIsMask = !pDict->KeyExist(FX_BSTRC("ColorSpace")) ||
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp
index ffa5e62a07..127fb93250 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp
@@ -418,9 +418,11 @@ void CPDF_StreamContentParser::Handle_BeginMarkedContent_Dictionary() {
}
bDirect = FALSE;
}
- if (CPDF_Dictionary* pDict = pProperty->AsDictionary()) {
- m_CurContentMark.GetModify()->AddMark(tag, pDict, bDirect);
+ if (pProperty->GetType() != PDFOBJ_DICTIONARY) {
+ return;
}
+ m_CurContentMark.GetModify()->AddMark(tag, (CPDF_Dictionary*)pProperty,
+ bDirect);
}
void CPDF_StreamContentParser::Handle_BeginMarkedContent() {
if (!m_Options.m_bMarkedContent) {
@@ -485,7 +487,7 @@ static CFX_ByteStringC _PDF_FindFullName(const _FX_BSTR* table,
void _PDF_ReplaceAbbr(CPDF_Object* pObj) {
switch (pObj->GetType()) {
case PDFOBJ_DICTIONARY: {
- CPDF_Dictionary* pDict = pObj->AsDictionary();
+ CPDF_Dictionary* pDict = (CPDF_Dictionary*)pObj;
FX_POSITION pos = pDict->GetStartPos();
while (pos) {
CFX_ByteString key;
@@ -548,7 +550,7 @@ static CFX_ByteStringC _PDF_FindAbbrName(const _FX_BSTR* table,
void _PDF_ReplaceFull(CPDF_Object* pObj) {
switch (pObj->GetType()) {
case PDFOBJ_DICTIONARY: {
- CPDF_Dictionary* pDict = pObj->AsDictionary();
+ CPDF_Dictionary* pDict = (CPDF_Dictionary*)pObj;
FX_POSITION pos = pDict->GetStartPos();
while (pos) {
CFX_ByteString key;
@@ -884,8 +886,8 @@ void CPDF_StreamContentParser::Handle_SetGray_Stroke() {
void CPDF_StreamContentParser::Handle_SetExtendGraphState() {
CFX_ByteString name = GetString(0);
CPDF_Dictionary* pGS =
- ToDictionary(FindResourceObj(FX_BSTRC("ExtGState"), name));
- if (!pGS) {
+ (CPDF_Dictionary*)FindResourceObj(FX_BSTRC("ExtGState"), name);
+ if (pGS == NULL || pGS->GetType() != PDFOBJ_DICTIONARY) {
m_bResourceMissing = TRUE;
return;
}
@@ -1215,12 +1217,11 @@ CPDF_Object* CPDF_StreamContentParser::FindResourceObj(
}
CPDF_Font* CPDF_StreamContentParser::FindFont(const CFX_ByteString& name) {
CPDF_Dictionary* pFontDict =
- ToDictionary(FindResourceObj(FX_BSTRC("Font"), name));
- if (!pFontDict) {
+ (CPDF_Dictionary*)FindResourceObj(FX_BSTRC("Font"), name);
+ if (pFontDict == NULL || pFontDict->GetType() != PDFOBJ_DICTIONARY) {
m_bResourceMissing = TRUE;
return CPDF_Font::GetStockFont(m_pDocument, FX_BSTRC("Helvetica"));
}
-
CPDF_Font* pFont = m_pDocument->LoadFont(pFontDict);
if (pFont && pFont->GetType3Font()) {
pFont->GetType3Font()->SetPageResources(m_pResources);
@@ -1260,8 +1261,8 @@ CPDF_Pattern* CPDF_StreamContentParser::FindPattern(const CFX_ByteString& name,
FX_BOOL bShading) {
CPDF_Object* pPattern = FindResourceObj(
bShading ? FX_BSTRC("Shading") : FX_BSTRC("Pattern"), name);
- if (pPattern == NULL ||
- (!pPattern->IsDictionary() && pPattern->GetType() != PDFOBJ_STREAM)) {
+ if (pPattern == NULL || (pPattern->GetType() != PDFOBJ_DICTIONARY &&
+ pPattern->GetType() != PDFOBJ_STREAM)) {
m_bResourceMissing = TRUE;
return NULL;
}
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
index 55c62e2878..2d6e9f3436 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
@@ -283,7 +283,7 @@ ICodec_ScanlineDecoder* FPDFAPI_CreateFlateDecoder(
int predictor = 0;
int Colors = 0, BitsPerComponent = 0, Columns = 0;
if (pParams) {
- predictor = pParams->GetInteger(FX_BSTRC("Predictor"));
+ predictor = ((CPDF_Dictionary*)pParams)->GetInteger(FX_BSTRC("Predictor"));
Colors = pParams->GetInteger(FX_BSTRC("Colors"), 1);
BitsPerComponent = pParams->GetInteger(FX_BSTRC("BitsPerComponent"), 8);
Columns = pParams->GetInteger(FX_BSTRC("Columns"), 1);
@@ -306,8 +306,9 @@ FX_DWORD FPDFAPI_FlateOrLZWDecode(FX_BOOL bLZW,
FX_BOOL bEarlyChange = TRUE;
int Colors = 0, BitsPerComponent = 0, Columns = 0;
if (pParams) {
- predictor = pParams->GetInteger(FX_BSTRC("Predictor"));
- bEarlyChange = pParams->GetInteger(FX_BSTRC("EarlyChange"), 1);
+ predictor = ((CPDF_Dictionary*)pParams)->GetInteger(FX_BSTRC("Predictor"));
+ bEarlyChange =
+ ((CPDF_Dictionary*)pParams)->GetInteger(FX_BSTRC("EarlyChange"), 1);
Colors = pParams->GetInteger(FX_BSTRC("Colors"), 1);
BitsPerComponent = pParams->GetInteger(FX_BSTRC("BitsPerComponent"), 8);
Columns = pParams->GetInteger(FX_BSTRC("Columns"), 1);
@@ -364,9 +365,7 @@ FX_BOOL PDF_DataDecode(const uint8_t* src_buf,
int estimated_size =
i == DecoderList.GetSize() - 1 ? last_estimated_size : 0;
CFX_ByteString decoder = DecoderList[i];
- // Use ToDictionary here because we can push NULL into the ParamList.
- CPDF_Dictionary* pParam =
- ToDictionary(static_cast<CPDF_Object*>(ParamList[i]));
+ CPDF_Dictionary* pParam = (CPDF_Dictionary*)ParamList[i];
uint8_t* new_buf = NULL;
FX_DWORD new_size = (FX_DWORD)-1;
int offset = -1;
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_document.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_document.cpp
index 29c1a007cf..2dff766187 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_document.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_document.cpp
@@ -143,15 +143,18 @@ CPDF_Dictionary* CPDF_Document::GetPage(int iPage) {
return nullptr;
if (m_bLinearized && (iPage == (int)m_dwFirstPageNo)) {
- if (CPDF_Dictionary* pDict =
- ToDictionary(GetIndirectObject(m_dwFirstPageObjNum)))
- return pDict;
+ CPDF_Object* pObj = GetIndirectObject(m_dwFirstPageObjNum);
+ if (pObj && pObj->GetType() == PDFOBJ_DICTIONARY) {
+ return static_cast<CPDF_Dictionary*>(pObj);
+ }
}
int objnum = m_PageList.GetAt(iPage);
if (objnum) {
- if (CPDF_Dictionary* pDict = ToDictionary(GetIndirectObject(objnum)))
- return pDict;
+ CPDF_Object* pObj = GetIndirectObject(objnum);
+ if (pObj && pObj->GetType() == PDFOBJ_DICTIONARY) {
+ return static_cast<CPDF_Dictionary*>(pObj);
+ }
}
CPDF_Dictionary* pRoot = GetRoot();
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp
index 82bfbb56eb..19359ad7cf 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp
@@ -70,11 +70,13 @@ void CFDF_Document::ParseStream(IFX_FileRead* pFile, FX_BOOL bOwnFile) {
if (word != FX_BSTRC("trailer")) {
break;
}
- if (CPDF_Dictionary* pMainDict =
- ToDictionary(parser.GetObject(this, 0, 0, 0))) {
- m_pRootDict = pMainDict->GetDict(FX_BSTRC("Root"));
- pMainDict->Release();
+ CPDF_Dictionary* pMainDict =
+ (CPDF_Dictionary*)parser.GetObject(this, 0, 0, 0);
+ if (pMainDict == NULL || pMainDict->GetType() != PDFOBJ_DICTIONARY) {
+ break;
}
+ m_pRootDict = pMainDict->GetDict(FX_BSTRC("Root"));
+ pMainDict->Release();
break;
}
}
@@ -140,17 +142,18 @@ void FPDF_FileSpec_SetWin32Path(CPDF_Object* pFileSpec,
}
if (pFileSpec->GetType() == PDFOBJ_STRING) {
pFileSpec->SetString(CFX_ByteString::FromUnicode(result));
- } else if (CPDF_Dictionary* pFileDict = pFileSpec->AsDictionary()) {
- pFileDict->SetAtString(FX_BSTRC("F"), CFX_ByteString::FromUnicode(result));
- pFileDict->SetAtString(FX_BSTRC("UF"), PDF_EncodeText(result));
- pFileDict->RemoveAt(FX_BSTRC("FS"));
+ } else if (pFileSpec->GetType() == PDFOBJ_DICTIONARY) {
+ ((CPDF_Dictionary*)pFileSpec)
+ ->SetAtString(FX_BSTRC("F"), CFX_ByteString::FromUnicode(result));
+ ((CPDF_Dictionary*)pFileSpec)
+ ->SetAtString(FX_BSTRC("UF"), PDF_EncodeText(result));
+ ((CPDF_Dictionary*)pFileSpec)->RemoveAt(FX_BSTRC("FS"));
}
}
CFX_WideString FPDF_FileSpec_GetWin32Path(const CPDF_Object* pFileSpec) {
CFX_WideString wsFileName;
- if (!pFileSpec) {
- wsFileName = CFX_WideString();
- } else if (const CPDF_Dictionary* pDict = pFileSpec->AsDictionary()) {
+ if (pFileSpec->GetType() == PDFOBJ_DICTIONARY) {
+ CPDF_Dictionary* pDict = (CPDF_Dictionary*)pFileSpec;
wsFileName = pDict->GetUnicodeText(FX_BSTRC("UF"));
if (wsFileName.IsEmpty()) {
wsFileName = CFX_WideString::FromLocal(pDict->GetString(FX_BSTRC("F")));
@@ -161,7 +164,9 @@ CFX_WideString FPDF_FileSpec_GetWin32Path(const CPDF_Object* pFileSpec) {
if (wsFileName.IsEmpty() && pDict->KeyExist(FX_BSTRC("DOS"))) {
wsFileName = CFX_WideString::FromLocal(pDict->GetString(FX_BSTRC("DOS")));
}
- } else {
+ } else if (!pFileSpec)
+ wsFileName = CFX_WideString();
+ else {
wsFileName = CFX_WideString::FromLocal(pFileSpec->GetString());
}
if (wsFileName[0] != '/') {
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp
index 317f96d1dc..e1e821c4c5 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp
@@ -28,7 +28,7 @@ void CPDF_Object::Destroy() {
delete (CPDF_Array*)this;
break;
case PDFOBJ_DICTIONARY:
- delete this->AsDictionary();
+ delete (CPDF_Dictionary*)this;
break;
case PDFOBJ_STREAM:
delete (CPDF_Stream*)this;
@@ -138,9 +138,7 @@ int CPDF_Object::GetInteger() const {
CPDF_Dictionary* CPDF_Object::GetDict() const {
switch (m_Type) {
case PDFOBJ_DICTIONARY:
- // The method should be made non-const if we want to not be const.
- // See bug #234.
- return const_cast<CPDF_Dictionary*>(this->AsDictionary());
+ return (CPDF_Dictionary*)this;
case PDFOBJ_STREAM:
return ((CPDF_Stream*)this)->GetDict();
case PDFOBJ_REFERENCE: {
@@ -217,7 +215,7 @@ FX_BOOL CPDF_Object::IsIdentical(CPDF_Object* pOther) const {
case PDFOBJ_ARRAY:
return (((CPDF_Array*)this)->Identical((CPDF_Array*)pOther));
case PDFOBJ_DICTIONARY:
- return this->AsDictionary()->Identical(pOther->AsDictionary());
+ return (((CPDF_Dictionary*)this)->Identical((CPDF_Dictionary*)pOther));
case PDFOBJ_NULL:
return TRUE;
case PDFOBJ_STREAM:
@@ -266,7 +264,7 @@ CPDF_Object* CPDF_Object::CloneInternal(FX_BOOL bDirect,
}
case PDFOBJ_DICTIONARY: {
CPDF_Dictionary* pCopy = new CPDF_Dictionary();
- const CPDF_Dictionary* pThis = this->AsDictionary();
+ CPDF_Dictionary* pThis = (CPDF_Dictionary*)this;
FX_POSITION pos = pThis->m_Map.GetStartPosition();
while (pos) {
CFX_ByteString key;
@@ -285,9 +283,9 @@ CPDF_Object* CPDF_Object::CloneInternal(FX_BOOL bDirect,
acc.LoadAllData(pThis, TRUE);
FX_DWORD streamSize = acc.GetSize();
CPDF_Dictionary* pDict = pThis->GetDict();
- if (pDict) {
- pDict = pDict->CloneInternal(bDirect, visited)->AsDictionary();
- }
+ if (pDict)
+ pDict = (CPDF_Dictionary*)((CPDF_Object*)pDict)
+ ->CloneInternal(bDirect, visited);
return new CPDF_Stream(acc.DetachData(), streamSize, pDict);
}
case PDFOBJ_REFERENCE: {
@@ -337,14 +335,6 @@ void CPDF_Object::SetUnicodeText(const FX_WCHAR* pUnicodes, int len) {
}
}
-CPDF_Dictionary* CPDF_Object::AsDictionary() {
- return IsDictionary() ? static_cast<CPDF_Dictionary*>(this) : nullptr;
-}
-
-const CPDF_Dictionary* CPDF_Object::AsDictionary() const {
- return IsDictionary() ? static_cast<const CPDF_Dictionary*>(this) : nullptr;
-}
-
CPDF_Number::CPDF_Number(int value)
: CPDF_Object(PDFOBJ_NUMBER), m_bInteger(TRUE), m_Integer(value) {}
@@ -452,8 +442,8 @@ CPDF_Dictionary* CPDF_Array::GetDict(FX_DWORD i) const {
if (!p) {
return NULL;
}
- if (CPDF_Dictionary* pDict = p->AsDictionary()) {
- return pDict;
+ if (p->GetType() == PDFOBJ_DICTIONARY) {
+ return (CPDF_Dictionary*)p;
}
if (p->GetType() == PDFOBJ_STREAM) {
return ((CPDF_Stream*)p)->GetDict();
@@ -673,8 +663,8 @@ CPDF_Dictionary* CPDF_Dictionary::GetDict(const CFX_ByteStringC& key) const {
if (!p) {
return nullptr;
}
- if (CPDF_Dictionary* pDict = p->AsDictionary()) {
- return pDict;
+ if (p->GetType() == PDFOBJ_DICTIONARY) {
+ return (CPDF_Dictionary*)p;
}
if (p->GetType() == PDFOBJ_STREAM) {
return ((CPDF_Stream*)p)->GetDict();
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
index b436ba16f5..a36850bc2e 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
@@ -277,8 +277,8 @@ FX_DWORD CPDF_Parser::SetEncryptHandler() {
}
CPDF_Object* pEncryptObj = m_pTrailer->GetElement(FX_BSTRC("Encrypt"));
if (pEncryptObj) {
- if (CPDF_Dictionary* pEncryptDict = pEncryptObj->AsDictionary()) {
- SetEncryptDictionary(pEncryptDict);
+ if (pEncryptObj->GetType() == PDFOBJ_DICTIONARY) {
+ SetEncryptDictionary((CPDF_Dictionary*)pEncryptObj);
} else if (pEncryptObj->GetType() == PDFOBJ_REFERENCE) {
pEncryptObj = m_pDocument->GetIndirectObject(
((CPDF_Reference*)pEncryptObj)->GetRefObjNum());
@@ -804,7 +804,7 @@ FX_BOOL CPDF_Parser::RebuildCrossRef() {
if (m_pTrailer) {
m_pTrailer->Release();
}
- m_pTrailer = ToDictionary(pDict->Clone());
+ m_pTrailer = (CPDF_Dictionary*)pDict->Clone();
}
}
}
@@ -857,14 +857,15 @@ FX_BOOL CPDF_Parser::RebuildCrossRef() {
m_Syntax.RestorePos(pos + i - m_Syntax.m_HeaderOffset);
CPDF_Object* pObj = m_Syntax.GetObject(m_pDocument, 0, 0, 0);
if (pObj) {
- if (!pObj->IsDictionary() && pObj->GetType() != PDFOBJ_STREAM) {
+ if (pObj->GetType() != PDFOBJ_DICTIONARY &&
+ pObj->GetType() != PDFOBJ_STREAM) {
pObj->Release();
} else {
CPDF_Dictionary* pTrailer = NULL;
if (pObj->GetType() == PDFOBJ_STREAM) {
pTrailer = ((CPDF_Stream*)pObj)->GetDict();
} else {
- pTrailer = pObj->AsDictionary();
+ pTrailer = (CPDF_Dictionary*)pObj;
}
if (pTrailer) {
if (m_pTrailer) {
@@ -889,7 +890,7 @@ FX_BOOL CPDF_Parser::RebuildCrossRef() {
}
} else {
if (pObj->GetType() == PDFOBJ_STREAM) {
- m_pTrailer = ToDictionary(pTrailer->Clone());
+ m_pTrailer = (CPDF_Dictionary*)pTrailer->Clone();
pObj->Release();
} else {
m_pTrailer = pTrailer;
@@ -1033,13 +1034,13 @@ FX_BOOL CPDF_Parser::LoadCrossRefV5(FX_FILESIZE pos,
return FALSE;
}
if (bMainXRef) {
- m_pTrailer = ToDictionary(pStream->GetDict()->Clone());
+ m_pTrailer = (CPDF_Dictionary*)pStream->GetDict()->Clone();
m_CrossRef.SetSize(size);
if (m_V5Type.SetSize(size)) {
FXSYS_memset(m_V5Type.GetData(), 0, size);
}
} else {
- m_Trailers.Add(ToDictionary(pStream->GetDict()->Clone()));
+ m_Trailers.Add((CPDF_Dictionary*)pStream->GetDict()->Clone());
}
std::vector<std::pair<int32_t, int32_t> > arrIndex;
CPDF_Array* pArray = pStream->GetDict()->GetArray(FX_BSTRC("Index"));
@@ -1489,9 +1490,9 @@ CPDF_Dictionary* CPDF_Parser::LoadTrailerV4() {
nonstd::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> pObj(
m_Syntax.GetObject(m_pDocument, 0, 0, 0));
- if (!ToDictionary(pObj.get()))
+ if (!pObj || pObj->GetType() != PDFOBJ_DICTIONARY)
return nullptr;
- return pObj.release()->AsDictionary();
+ return static_cast<CPDF_Dictionary*>(pObj.release());
}
FX_DWORD CPDF_Parser::GetPermissions(FX_BOOL bCheckRevision) {
@@ -3489,7 +3490,7 @@ FX_BOOL CPDF_DataAvail::CheckPage(IFX_DownloadHints* pHints) {
}
}
}
- if (!pObj->IsDictionary()) {
+ if (pObj->GetType() != PDFOBJ_DICTIONARY) {
pObj->Release();
continue;
}
@@ -4042,7 +4043,7 @@ FX_BOOL CPDF_DataAvail::CheckTrailer(IFX_DownloadHints* pHints) {
pHints->AddSegment(m_Pos, iTrailerSize);
return FALSE;
}
- if (!pTrailer->IsDictionary())
+ if (pTrailer->GetType() != PDFOBJ_DICTIONARY)
return FALSE;
CPDF_Dictionary* pTrailerDict = pTrailer->GetDict();
@@ -4157,7 +4158,7 @@ FX_BOOL CPDF_DataAvail::CheckUnkownPageNode(FX_DWORD dwPageNo,
pPage->Release();
return TRUE;
}
- if (!pPage->IsDictionary()) {
+ if (pPage->GetType() != PDFOBJ_DICTIONARY) {
pPage->Release();
m_docStatus = PDF_DATAAVAIL_ERROR;
return FALSE;
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp
index c34d8122f8..63454d2cb5 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp
@@ -403,7 +403,7 @@ CFX_ByteTextBuf& operator<<(CFX_ByteTextBuf& buf, const CPDF_Object* pObj) {
break;
}
case PDFOBJ_DICTIONARY: {
- const CPDF_Dictionary* p = pObj->AsDictionary();
+ CPDF_Dictionary* p = (CPDF_Dictionary*)pObj;
buf << FX_BSTRC("<<");
FX_POSITION pos = p->GetStartPos();
while (pos) {
diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render.cpp
index cf37f0c6f4..5b2158f17d 100644
--- a/core/src/fpdfapi/fpdf_render/fpdf_render.cpp
+++ b/core/src/fpdfapi/fpdf_render/fpdf_render.cpp
@@ -738,7 +738,7 @@ FX_BOOL CPDF_RenderStatus::ProcessTransparency(
return TRUE;
}
CPDF_Dictionary* pSMaskDict =
- pGeneralState ? pGeneralState->m_pSoftMask->AsDictionary() : NULL;
+ pGeneralState ? (CPDF_Dictionary*)pGeneralState->m_pSoftMask : NULL;
if (pSMaskDict) {
if (pPageObj->m_Type == PDFPAGE_IMAGE &&
((CPDF_ImageObject*)pPageObj)
@@ -1437,8 +1437,7 @@ FX_BOOL IPDF_OCContext::CheckObjectVisible(const CPDF_PageObject* pObj) {
CPDF_ContentMarkItem& item = pData->GetItem(i);
if (item.GetName() == FX_BSTRC("OC") &&
item.GetParamType() == CPDF_ContentMarkItem::PropertiesDict) {
- CPDF_Dictionary* pOCG =
- ToDictionary(static_cast<CPDF_Object*>(item.GetParam()));
+ CPDF_Dictionary* pOCG = (CPDF_Dictionary*)item.GetParam();
if (!CheckOCGVisible(pOCG)) {
return FALSE;
}
diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp
index e4afdd80c2..222f58c088 100644
--- a/core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp
+++ b/core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp
@@ -1056,8 +1056,8 @@ CFX_DIBitmap* CPDF_RenderStatus::LoadSMask(CPDF_Dictionary* pSMaskDict,
}
CPDF_Function* pFunc = NULL;
CPDF_Object* pFuncObj = pSMaskDict->GetElementValue(FX_BSTRC("TR"));
- if (pFuncObj &&
- (pFuncObj->IsDictionary() || pFuncObj->GetType() == PDFOBJ_STREAM)) {
+ if (pFuncObj && (pFuncObj->GetType() == PDFOBJ_DICTIONARY ||
+ pFuncObj->GetType() == PDFOBJ_STREAM)) {
pFunc = CPDF_Function::Load(pFuncObj);
}
CFX_AffineMatrix matrix = *pMatrix;