Revert "Add type cast definitions for CPDF_Dictionary."
authorDan Sinclair <dsinclair@chromium.org>
Tue, 20 Oct 2015 17:30:34 +0000 (13:30 -0400)
committerDan Sinclair <dsinclair@chromium.org>
Tue, 20 Oct 2015 17:30:34 +0000 (13:30 -0400)
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 .

35 files changed:
core/include/fpdfapi/fpdf_objects.h
core/include/fpdfdoc/fpdf_doc.h
core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp
core/src/fpdfapi/fpdf_font/fpdf_font.cpp
core/src/fpdfapi/fpdf_page/fpdf_page_func.cpp
core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp
core/src/fpdfapi/fpdf_page/fpdf_page_image.cpp
core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp
core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
core/src/fpdfapi/fpdf_parser/fpdf_parser_document.cpp
core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp
core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp
core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp
core/src/fpdfapi/fpdf_render/fpdf_render.cpp
core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp
core/src/fpdfdoc/doc_action.cpp
core/src/fpdfdoc/doc_annot.cpp
core/src/fpdfdoc/doc_basic.cpp
core/src/fpdfdoc/doc_form.cpp
core/src/fpdfdoc/doc_formcontrol.cpp
core/src/fpdfdoc/doc_ocg.cpp
core/src/fpdfdoc/doc_tagged.cpp
core/src/fpdfdoc/doc_utils.cpp
core/src/fpdftext/fpdf_text_int.cpp
fpdfsdk/src/formfiller/FFL_CBA_Fontmap.cpp
fpdfsdk/src/formfiller/FFL_Utils.cpp
fpdfsdk/src/fpdf_flatten.cpp
fpdfsdk/src/fpdf_transformpage.cpp
fpdfsdk/src/fpdfdoc.cpp
fpdfsdk/src/fpdfeditpage.cpp
fpdfsdk/src/fpdfppo.cpp
fpdfsdk/src/fpdfview.cpp
fpdfsdk/src/fsdk_baseform.cpp
fpdfsdk/src/fsdk_mgr.cpp

index 4141ec8..c2d838d 100644 (file)
@@ -78,11 +78,6 @@ class CPDF_Object {
 
   FX_BOOL IsModified() const { return FALSE; }
 
-  bool IsDictionary() const { return m_Type == PDFOBJ_DICTIONARY; }
-
-  CPDF_Dictionary* AsDictionary();
-  const CPDF_Dictionary* AsDictionary() const;
-
  protected:
   CPDF_Object(FX_DWORD type) : m_Type(type), m_ObjNum(0), m_GenNum(0) {}
   ~CPDF_Object() {}
@@ -407,13 +402,6 @@ class CPDF_Dictionary : public CPDF_Object {
 
   friend class CPDF_Object;
 };
-inline CPDF_Dictionary* ToDictionary(CPDF_Object* obj) {
-  return obj ? obj->AsDictionary() : nullptr;
-}
-inline const CPDF_Dictionary* ToDictionary(const CPDF_Object* obj) {
-  return obj ? obj->AsDictionary() : nullptr;
-}
-
 class CPDF_Stream : public CPDF_Object {
  public:
   static CPDF_Stream* Create(uint8_t* pData,
index 770133b..b0c129b 100644 (file)
@@ -717,10 +717,10 @@ class CPDF_InterForm : public CFX_PrivateData {
 
   CPDF_Object* GetFieldAttr(CPDF_Dictionary* pFieldDict, const FX_CHAR* name);
 
-  CPDF_FormField* AddTerminalField(CPDF_Dictionary* pFieldDict);
+  CPDF_FormField* AddTerminalField(const CPDF_Dictionary* pFieldDict);
 
   CPDF_FormControl* AddControl(const CPDF_FormField* pField,
-                               CPDF_Dictionary* pWidgetDict);
+                               const CPDF_Dictionary* pWidgetDict);
 
   void FDF_ImportField(CPDF_Dictionary* pField,
                        const CFX_WideString& parent_name,
index 054cf10..4e6c723 100644 (file)
@@ -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) {
index 10ca311..7a57889 100644 (file)
@@ -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;
index d66a9ef..224c99b 100644 (file)
@@ -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) {
index 6d071f3..f11a2bb 100644 (file)
@@ -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;
     }
index 9cdf00e..e9f70c1 100644 (file)
@@ -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")) ||
index ffa5e62..127fb93 100644 (file)
@@ -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;
   }
index 55c62e2..2d6e9f3 100644 (file)
@@ -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;
index 29c1a00..2dff766 100644 (file)
@@ -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();
index 82bfbb5..19359ad 100644 (file)
@@ -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] != '/') {
index 317f96d..e1e821c 100644 (file)
@@ -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();
index b436ba1..a36850b 100644 (file)
@@ -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;
index c34d812..63454d2 100644 (file)
@@ -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) {
index cf37f0c..5b2158f 100644 (file)
@@ -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;
       }
index e4afdd8..222f58c 100644 (file)
@@ -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;
index 409d050..759a06c 100644 (file)
@@ -251,10 +251,13 @@ CPDF_Action CPDF_Action::GetSubAction(FX_DWORD iIndex) const {
     return CPDF_Action();
   }
   CPDF_Object* pNext = m_pDict->GetElementValue("Next");
-  if (CPDF_Dictionary* pDict = ToDictionary(pNext)) {
-    if (iIndex == 0)
+  int iObjType = pNext->GetType();
+  if (iObjType == PDFOBJ_DICTIONARY) {
+    CPDF_Dictionary* pDict = static_cast<CPDF_Dictionary*>(pNext);
+    if (iIndex == 0) {
       return CPDF_Action(pDict);
-  } else if (pNext->GetType() == PDFOBJ_ARRAY) {
+    }
+  } else if (iObjType == PDFOBJ_ARRAY) {
     CPDF_Array* pArray = static_cast<CPDF_Array*>(pNext);
     return CPDF_Action(pArray->GetDict(iIndex));
   }
@@ -292,10 +295,9 @@ CPDF_Action CPDF_AAction::GetNextAction(FX_POSITION& pos,
     return CPDF_Action();
   }
   CPDF_Object* pDirect = pObj->GetDirect();
-  CPDF_Dictionary* pDict = ToDictionary(pDirect);
-  if (!pDict)
+  if (!pDirect || pDirect->GetType() != PDFOBJ_DICTIONARY) {
     return CPDF_Action();
-
+  }
   int i = 0;
   while (g_sAATypes[i][0] != '\0') {
     if (csKey == g_sAATypes[i]) {
@@ -304,7 +306,7 @@ CPDF_Action CPDF_AAction::GetNextAction(FX_POSITION& pos,
     i++;
   }
   eType = (AActionType)i;
-  return CPDF_Action(pDict);
+  return CPDF_Action(static_cast<CPDF_Dictionary*>(pDirect));
 }
 CPDF_DocJSActions::CPDF_DocJSActions(CPDF_Document* pDoc) {
   m_pDocument = pDoc;
@@ -319,7 +321,7 @@ CPDF_Action CPDF_DocJSActions::GetJSAction(int index,
   ASSERT(m_pDocument != NULL);
   CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript"));
   CPDF_Object* pAction = name_tree.LookupValue(index, csName);
-  if (!ToDictionary(pAction)) {
+  if (pAction == NULL || pAction->GetType() != PDFOBJ_DICTIONARY) {
     return CPDF_Action();
   }
   return CPDF_Action(pAction->GetDict());
@@ -328,7 +330,7 @@ CPDF_Action CPDF_DocJSActions::GetJSAction(const CFX_ByteString& csName) const {
   ASSERT(m_pDocument != NULL);
   CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript"));
   CPDF_Object* pAction = name_tree.LookupValue(csName);
-  if (!ToDictionary(pAction)) {
+  if (pAction == NULL || pAction->GetType() != PDFOBJ_DICTIONARY) {
     return CPDF_Action();
   }
   return CPDF_Action(pAction->GetDict());
index 4d0b703..6f5ff79 100644 (file)
@@ -23,8 +23,8 @@ CPDF_AnnotList::CPDF_AnnotList(CPDF_Page* pPage) {
   CPDF_Dictionary* pAcroForm = pRoot->GetDict("AcroForm");
   FX_BOOL bRegenerateAP = pAcroForm && pAcroForm->GetBoolean("NeedAppearances");
   for (FX_DWORD i = 0; i < pAnnots->GetCount(); ++i) {
-    CPDF_Dictionary* pDict = ToDictionary(pAnnots->GetElementValue(i));
-    if (!pDict) {
+    CPDF_Dictionary* pDict = (CPDF_Dictionary*)pAnnots->GetElementValue(i);
+    if (pDict == NULL || pDict->GetType() != PDFOBJ_DICTIONARY) {
       continue;
     }
     FX_DWORD dwObjNum = pDict->GetObjNum();
@@ -202,7 +202,7 @@ CPDF_Stream* FPDFDOC_GetAnnotAP(CPDF_Dictionary* pAnnotDict,
   CPDF_Stream* pStream = NULL;
   if (psub->GetType() == PDFOBJ_STREAM) {
     pStream = (CPDF_Stream*)psub;
-  } else if (CPDF_Dictionary* pDict = psub->AsDictionary()) {
+  } else if (psub->GetType() == PDFOBJ_DICTIONARY) {
     CFX_ByteString as = pAnnotDict->GetString("AS");
     if (as.IsEmpty()) {
       CFX_ByteString value = pAnnotDict->GetString(FX_BSTRC("V"));
@@ -210,13 +210,13 @@ 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() || !((CPDF_Dictionary*)psub)->KeyExist(value)) {
         as = FX_BSTRC("Off");
       } else {
         as = value;
       }
     }
-    pStream = pDict->GetStream(as);
+    pStream = ((CPDF_Dictionary*)psub)->GetStream(as);
   }
   return pStream;
 }
index e3b6308..39b5788 100644 (file)
@@ -17,7 +17,7 @@ int CPDF_Dest::GetPageIndex(CPDF_Document* pDoc) {
   if (pPage->GetType() == PDFOBJ_NUMBER) {
     return pPage->GetInteger();
   }
-  if (!pPage->IsDictionary()) {
+  if (pPage->GetType() != PDFOBJ_DICTIONARY) {
     return 0;
   }
   return pDoc->GetPageIndex(pPage->GetObjNum());
@@ -33,7 +33,7 @@ FX_DWORD CPDF_Dest::GetPageObjNum() {
   if (pPage->GetType() == PDFOBJ_NUMBER) {
     return pPage->GetInteger();
   }
-  if (pPage->IsDictionary()) {
+  if (pPage->GetType() == PDFOBJ_DICTIONARY) {
     return pPage->GetObjNum();
   }
   return 0;
@@ -243,8 +243,8 @@ CPDF_Array* CPDF_NameTree::LookupNamedDest(CPDF_Document* pDoc,
   if (pValue->GetType() == PDFOBJ_ARRAY) {
     return (CPDF_Array*)pValue;
   }
-  if (CPDF_Dictionary* pDict = pValue->AsDictionary()) {
-    return pDict->GetArray(FX_BSTRC("D"));
+  if (pValue->GetType() == PDFOBJ_DICTIONARY) {
+    return ((CPDF_Dictionary*)pValue)->GetArray(FX_BSTRC("D"));
   }
   return NULL;
 }
@@ -311,10 +311,11 @@ static CFX_WideString FILESPEC_DecodeFileName(const CFX_WideStringC& filepath) {
 #endif
 }
 FX_BOOL CPDF_FileSpec::GetFileName(CFX_WideString& csFileName) const {
-  if (!m_pObj) {
+  if (m_pObj == NULL) {
     return FALSE;
   }
-  if (CPDF_Dictionary* pDict = m_pObj->AsDictionary()) {
+  if (m_pObj->GetType() == PDFOBJ_DICTIONARY) {
+    CPDF_Dictionary* pDict = (CPDF_Dictionary*)m_pObj;
     csFileName = pDict->GetUnicodeText(FX_BSTRC("UF"));
     if (csFileName.IsEmpty()) {
       csFileName = CFX_WideString::FromLocal(pDict->GetString(FX_BSTRC("F")));
@@ -344,15 +345,20 @@ FX_BOOL CPDF_FileSpec::GetFileName(CFX_WideString& csFileName) const {
 }
 CPDF_FileSpec::CPDF_FileSpec() {
   m_pObj = CPDF_Dictionary::Create();
-  if (CPDF_Dictionary* pDict = ToDictionary(m_pObj)) {
-    pDict->SetAtName(FX_BSTRC("Type"), FX_BSTRC("Filespec"));
+  if (m_pObj != NULL) {
+    ((CPDF_Dictionary*)m_pObj)
+        ->SetAtName(FX_BSTRC("Type"), FX_BSTRC("Filespec"));
   }
 }
 FX_BOOL CPDF_FileSpec::IsURL() const {
-  if (CPDF_Dictionary* pDict = ToDictionary(m_pObj)) {
-    return pDict->GetString(FX_BSTRC("FS")) == FX_BSTRC("URL");
+  if (m_pObj == NULL) {
+    return FALSE;
+  }
+  if (m_pObj->GetType() != PDFOBJ_DICTIONARY) {
+    return FALSE;
   }
-  return FALSE;
+  return ((CPDF_Dictionary*)m_pObj)->GetString(FX_BSTRC("FS")) ==
+         FX_BSTRC("URL");
 }
 CFX_WideString FILESPEC_EncodeFileName(const CFX_WideStringC& filepath) {
   if (filepath.GetLength() <= 1) {
@@ -396,10 +402,15 @@ CPDF_Stream* CPDF_FileSpec::GetFileStream() const {
     return NULL;
   }
   int32_t iType = m_pObj->GetType();
-  if (iType == PDFOBJ_STREAM)
+  if (iType == PDFOBJ_STREAM) {
     return (CPDF_Stream*)m_pObj;
-  if (CPDF_Dictionary* pEF = m_pObj->AsDictionary()->GetDict(FX_BSTRC("EF")))
+  } else if (iType == PDFOBJ_DICTIONARY) {
+    CPDF_Dictionary* pEF = ((CPDF_Dictionary*)m_pObj)->GetDict(FX_BSTRC("EF"));
+    if (pEF == NULL) {
+      return NULL;
+    }
     return pEF->GetStream(FX_BSTRC("F"));
+  }
   return NULL;
 }
 static void FPDFDOC_FILESPEC_SetFileName(CPDF_Object* pObj,
@@ -415,7 +426,8 @@ static void FPDFDOC_FILESPEC_SetFileName(CPDF_Object* pObj,
   int32_t iType = pObj->GetType();
   if (iType == PDFOBJ_STRING) {
     pObj->SetString(CFX_ByteString::FromUnicode(wsStr));
-  } else if (CPDF_Dictionary* pDict = pObj->AsDictionary()) {
+  } else if (iType == PDFOBJ_DICTIONARY) {
+    CPDF_Dictionary* pDict = (CPDF_Dictionary*)pObj;
     pDict->SetAtString(FX_BSTRC("F"), CFX_ByteString::FromUnicode(wsStr));
     pDict->SetAtString(FX_BSTRC("UF"), PDF_EncodeText(wsStr));
   }
@@ -423,10 +435,8 @@ static void FPDFDOC_FILESPEC_SetFileName(CPDF_Object* pObj,
 void CPDF_FileSpec::SetFileName(const CFX_WideStringC& wsFileName,
                                 FX_BOOL bURL) {
   ASSERT(m_pObj != NULL);
-  if (bURL) {
-    if (CPDF_Dictionary* pDict = m_pObj->AsDictionary()) {
-      pDict->SetAtName(FX_BSTRC("FS"), "URL");
-    }
+  if (m_pObj->GetType() == PDFOBJ_DICTIONARY && bURL) {
+    ((CPDF_Dictionary*)m_pObj)->SetAtName(FX_BSTRC("FS"), "URL");
   }
   FPDFDOC_FILESPEC_SetFileName(m_pObj, wsFileName, bURL);
 }
@@ -507,7 +517,8 @@ CFX_WideString CPDF_PageLabel::GetLabel(int nPage) const {
   }
   if (pValue != NULL) {
     pValue = pValue->GetDirect();
-    if (CPDF_Dictionary* pLabel = pValue->AsDictionary()) {
+    if (pValue->GetType() == PDFOBJ_DICTIONARY) {
+      CPDF_Dictionary* pLabel = (CPDF_Dictionary*)pValue;
       if (pLabel->KeyExist(FX_BSTRC("P"))) {
         wsLabel += pLabel->GetUnicodeText(FX_BSTRC("P"));
       }
index 8078608..17f1808 100644 (file)
@@ -854,9 +854,9 @@ CPDF_FormField* CPDF_InterForm::GetFieldInCalculationOrder(int index) {
   if (pArray == NULL) {
     return NULL;
   }
-  if (CPDF_Dictionary* pElement =
-          ToDictionary(pArray->GetElementValue(index))) {
-    return GetFieldByDict(pElement);
+  CPDF_Object* pElement = pArray->GetElementValue(index);
+  if (pElement != NULL && pElement->GetType() == PDFOBJ_DICTIONARY) {
+    return GetFieldByDict((CPDF_Dictionary*)pElement);
   }
   return NULL;
 }
@@ -1049,24 +1049,25 @@ void CPDF_InterForm::FixPageFields(const CPDF_Page* pPage) {
     }
   }
 }
-CPDF_FormField* CPDF_InterForm::AddTerminalField(CPDF_Dictionary* pFieldDict) {
+CPDF_FormField* CPDF_InterForm::AddTerminalField(
+    const CPDF_Dictionary* pFieldDict) {
   if (!pFieldDict->KeyExist(FX_BSTRC("T"))) {
     return NULL;
   }
-  CPDF_Dictionary* pDict = pFieldDict;
-  CFX_WideString csWName = GetFullName(pFieldDict);
+  CPDF_Dictionary* pDict = (CPDF_Dictionary*)pFieldDict;
+  CFX_WideString csWName = GetFullName(pDict);
   if (csWName.IsEmpty()) {
     return NULL;
   }
   CPDF_FormField* pField = NULL;
   pField = m_pFieldTree->GetField(csWName);
   if (pField == NULL) {
-    CPDF_Dictionary* pParent = pFieldDict;
+    CPDF_Dictionary* pParent = (CPDF_Dictionary*)pFieldDict;
     if (!pFieldDict->KeyExist(FX_BSTRC("T")) &&
         pFieldDict->GetString(FX_BSTRC("Subtype")) == FX_BSTRC("Widget")) {
       pParent = pFieldDict->GetDict(FX_BSTRC("Parent"));
       if (!pParent) {
-        pParent = pFieldDict;
+        pParent = (CPDF_Dictionary*)pFieldDict;
       }
     }
     if (pParent && pParent != pFieldDict &&
@@ -1115,14 +1116,15 @@ CPDF_FormField* CPDF_InterForm::AddTerminalField(CPDF_Dictionary* pFieldDict) {
   }
   return pField;
 }
-CPDF_FormControl* CPDF_InterForm::AddControl(const CPDF_FormField* pField,
-                                             CPDF_Dictionary* pWidgetDict) {
+CPDF_FormControl* CPDF_InterForm::AddControl(
+    const CPDF_FormField* pField,
+    const CPDF_Dictionary* pWidgetDict) {
   const auto it = m_ControlMap.find(pWidgetDict);
   if (it != m_ControlMap.end())
     return it->second;
 
-  CPDF_FormControl* pControl =
-      new CPDF_FormControl((CPDF_FormField*)pField, pWidgetDict);
+  CPDF_FormControl* pControl = new CPDF_FormControl(
+      (CPDF_FormField*)pField, (CPDF_Dictionary*)pWidgetDict);
   m_ControlMap[pWidgetDict] = pControl;
   ((CPDF_FormField*)pField)->m_ControlList.Add(pControl);
   return pControl;
index c5f47d2..410f9a1 100644 (file)
@@ -61,10 +61,10 @@ void CPDF_FormControl::SetOnStateName(const CFX_ByteString& csOn) {
       continue;
     }
     CPDF_Object* pObjDirect1 = pObj1->GetDirect();
-    CPDF_Dictionary* pSubDict = pObjDirect1->AsDictionary();
-    if (!pSubDict)
+    if (pObjDirect1->GetType() != PDFOBJ_DICTIONARY) {
       continue;
-
+    }
+    CPDF_Dictionary* pSubDict = (CPDF_Dictionary*)pObjDirect1;
     FX_POSITION pos2 = pSubDict->GetStartPos();
     while (pos2) {
       CFX_ByteString csKey2;
@@ -287,8 +287,8 @@ CPDF_Font* CPDF_FormControl::GetDefaultControlFont() {
     return nullptr;
 
   CPDF_Object* pObj = FPDF_GetFieldAttr(m_pWidgetDict, "DR");
-  if (CPDF_Dictionary* pDict = ToDictionary(pObj)) {
-    CPDF_Dictionary* pFonts = pDict->GetDict("Font");
+  if (pObj && pObj->GetType() == PDFOBJ_DICTIONARY) {
+    CPDF_Dictionary* pFonts = ((CPDF_Dictionary*)pObj)->GetDict("Font");
     if (pFonts) {
       CPDF_Dictionary* pElement = pFonts->GetDict(csFontNameTag);
       if (pElement) {
@@ -304,8 +304,8 @@ CPDF_Font* CPDF_FormControl::GetDefaultControlFont() {
 
   CPDF_Dictionary* pPageDict = m_pWidgetDict->GetDict("P");
   pObj = FPDF_GetFieldAttr(pPageDict, "Resources");
-  if (CPDF_Dictionary* pDict = ToDictionary(pObj)) {
-    CPDF_Dictionary* pFonts = pDict->GetDict("Font");
+  if (pObj && pObj->GetType() == PDFOBJ_DICTIONARY) {
+    CPDF_Dictionary* pFonts = ((CPDF_Dictionary*)pObj)->GetDict("Font");
     if (pFonts) {
       CPDF_Dictionary* pElement = pFonts->GetDict(csFontNameTag);
       if (pElement) {
index e66b044..70ad9c7 100644 (file)
@@ -209,8 +209,9 @@ FX_BOOL CPDF_OCContext::GetOCGVE(CPDF_Array* pExpression,
     if (pOCGObj == NULL) {
       return FALSE;
     }
-    if (CPDF_Dictionary* pDict = pOCGObj->AsDictionary()) {
-      return !(bFromConfig ? LoadOCGState(pDict) : GetOCGVisible(pDict));
+    if (pOCGObj->GetType() == PDFOBJ_DICTIONARY) {
+      return !(bFromConfig ? LoadOCGState((CPDF_Dictionary*)pOCGObj)
+                           : GetOCGVisible((CPDF_Dictionary*)pOCGObj));
     }
     if (pOCGObj->GetType() == PDFOBJ_ARRAY) {
       return !GetOCGVE((CPDF_Array*)pOCGObj, bFromConfig, nLevel + 1);
@@ -225,8 +226,9 @@ FX_BOOL CPDF_OCContext::GetOCGVE(CPDF_Array* pExpression,
         continue;
       }
       FX_BOOL bItem = FALSE;
-      if (CPDF_Dictionary* pDict = pOCGObj->AsDictionary()) {
-        bItem = bFromConfig ? LoadOCGState(pDict) : GetOCGVisible(pDict);
+      if (pOCGObj->GetType() == PDFOBJ_DICTIONARY) {
+        bItem = bFromConfig ? LoadOCGState((CPDF_Dictionary*)pOCGObj)
+                            : GetOCGVisible((CPDF_Dictionary*)pOCGObj);
       } else if (pOCGObj->GetType() == PDFOBJ_ARRAY) {
         bItem = GetOCGVE((CPDF_Array*)pOCGObj, bFromConfig, nLevel + 1);
       }
@@ -256,8 +258,9 @@ FX_BOOL CPDF_OCContext::LoadOCMDState(const CPDF_Dictionary* pOCMDDict,
   if (pOCGObj == NULL) {
     return TRUE;
   }
-  if (const CPDF_Dictionary* pDict = pOCGObj->AsDictionary()) {
-    return bFromConfig ? LoadOCGState(pDict) : GetOCGVisible(pDict);
+  if (pOCGObj->GetType() == PDFOBJ_DICTIONARY) {
+    return bFromConfig ? LoadOCGState((CPDF_Dictionary*)pOCGObj)
+                       : GetOCGVisible((CPDF_Dictionary*)pOCGObj);
   }
   if (pOCGObj->GetType() != PDFOBJ_ARRAY) {
     return TRUE;
index fb3a05d..facad46 100644 (file)
@@ -54,9 +54,9 @@ void CPDF_StructTreeImpl::LoadDocTree() {
   if (pKids == NULL) {
     return;
   }
-  if (CPDF_Dictionary* pDict = pKids->AsDictionary()) {
+  if (pKids->GetType() == PDFOBJ_DICTIONARY) {
     CPDF_StructElementImpl* pStructElementImpl =
-        new CPDF_StructElementImpl(this, NULL, pDict);
+        new CPDF_StructElementImpl(this, NULL, (CPDF_Dictionary*)pKids);
     m_Kids.Add(pStructElementImpl);
     return;
   }
@@ -81,7 +81,7 @@ void CPDF_StructTreeImpl::LoadPageTree(const CPDF_Dictionary* pPageDict) {
     return;
   }
   FX_DWORD dwKids = 0;
-  if (pKids->IsDictionary()) {
+  if (pKids->GetType() == PDFOBJ_DICTIONARY) {
     dwKids = 1;
   } else if (pKids->GetType() == PDFOBJ_ARRAY) {
     dwKids = ((CPDF_Array*)pKids)->GetCount();
@@ -161,7 +161,7 @@ FX_BOOL CPDF_StructTreeImpl::AddTopLevelNode(CPDF_Dictionary* pDict,
   if (!pObj) {
     return FALSE;
   }
-  if (pObj->IsDictionary()) {
+  if (pObj->GetType() == PDFOBJ_DICTIONARY) {
     if (pObj->GetObjNum() == pDict->GetObjNum()) {
       if (m_Kids[0]) {
         m_Kids[0]->Release();
@@ -266,10 +266,10 @@ void CPDF_StructElementImpl::LoadKid(FX_DWORD PageObjNum,
     pKid->m_PageContent.m_PageObjNum = PageObjNum;
     return;
   }
-  CPDF_Dictionary* pKidDict = pKidObj->AsDictionary();
-  if (!pKidDict)
+  if (pKidObj->GetType() != PDFOBJ_DICTIONARY) {
     return;
-
+  }
+  CPDF_Dictionary* pKidDict = (CPDF_Dictionary*)pKidObj;
   CPDF_Object* pPageObj = pKidDict->GetElement(FX_BSTRC("Pg"));
   if (pPageObj && pPageObj->GetType() == PDFOBJ_REFERENCE) {
     PageObjNum = ((CPDF_Reference*)pPageObj)->GetRefObjNum();
@@ -322,8 +322,8 @@ static CPDF_Dictionary* FindAttrDict(CPDF_Object* pAttrs,
     return NULL;
   }
   CPDF_Dictionary* pDict = NULL;
-  if (pAttrs->IsDictionary()) {
-    pDict = pAttrs->AsDictionary();
+  if (pAttrs->GetType() == PDFOBJ_DICTIONARY) {
+    pDict = (CPDF_Dictionary*)pAttrs;
   } else if (pAttrs->GetType() == PDFOBJ_STREAM) {
     pDict = ((CPDF_Stream*)pAttrs)->GetDict();
   } else if (pAttrs->GetType() == PDFOBJ_ARRAY) {
index 7d3fdf2..1ed0017 100644 (file)
@@ -290,8 +290,9 @@ FX_DWORD CountInterFormFonts(CPDF_Dictionary* pFormDict) {
     if (pObj == NULL) {
       continue;
     }
-    if (CPDF_Dictionary* pDirect = ToDictionary(pObj->GetDirect())) {
-      if (pDirect->GetString("Type") == "Font") {
+    CPDF_Object* pDirect = pObj->GetDirect();
+    if (pDirect != NULL && pDirect->GetType() == PDFOBJ_DICTIONARY) {
+      if (((CPDF_Dictionary*)pDirect)->GetString("Type") == "Font") {
         dwCount++;
       }
     }
@@ -322,11 +323,14 @@ CPDF_Font* GetInterFormFont(CPDF_Dictionary* pFormDict,
     if (pObj == NULL) {
       continue;
     }
-    CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect());
-    if (!pElement)
+    CPDF_Object* pDirect = pObj->GetDirect();
+    if (pDirect == NULL || pDirect->GetType() != PDFOBJ_DICTIONARY) {
       continue;
-    if (pElement->GetString("Type") != "Font")
+    }
+    CPDF_Dictionary* pElement = (CPDF_Dictionary*)pDirect;
+    if (pElement->GetString("Type") != "Font") {
       continue;
+    }
     if (dwCount == index) {
       csNameTag = csKey;
       return pDocument->LoadFont(pElement);
@@ -382,16 +386,18 @@ CPDF_Font* GetInterFormFont(CPDF_Dictionary* pFormDict,
     if (pObj == NULL) {
       continue;
     }
-    CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect());
-    if (!pElement)
+    CPDF_Object* pDirect = pObj->GetDirect();
+    if (pDirect == NULL || pDirect->GetType() != PDFOBJ_DICTIONARY) {
       continue;
-    if (pElement->GetString("Type") != "Font")
+    }
+    CPDF_Dictionary* pElement = (CPDF_Dictionary*)pDirect;
+    if (pElement->GetString("Type") != "Font") {
       continue;
-
+    }
     CPDF_Font* pFind = pDocument->LoadFont(pElement);
-    if (!pFind)
+    if (pFind == NULL) {
       continue;
-
+    }
     CFX_ByteString csBaseFont;
     csBaseFont = pFind->GetBaseFont();
     csBaseFont.Remove(' ');
@@ -425,11 +431,14 @@ CPDF_Font* GetNativeInterFormFont(CPDF_Dictionary* pFormDict,
     if (pObj == NULL) {
       continue;
     }
-    CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect());
-    if (!pElement)
+    CPDF_Object* pDirect = pObj->GetDirect();
+    if (pDirect == NULL || pDirect->GetType() != PDFOBJ_DICTIONARY) {
       continue;
-    if (pElement->GetString("Type") != "Font")
+    }
+    CPDF_Dictionary* pElement = (CPDF_Dictionary*)pDirect;
+    if (pElement->GetString("Type") != "Font") {
       continue;
+    }
     CPDF_Font* pFind = pDocument->LoadFont(pElement);
     if (pFind == NULL) {
       continue;
@@ -483,9 +492,11 @@ FX_BOOL FindInterFormFont(CPDF_Dictionary* pFormDict,
     if (pObj == NULL) {
       continue;
     }
-    CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect());
-    if (!pElement)
+    CPDF_Object* pDirect = pObj->GetDirect();
+    if (pDirect == NULL || pDirect->GetType() != PDFOBJ_DICTIONARY) {
       continue;
+    }
+    CPDF_Dictionary* pElement = (CPDF_Dictionary*)pDirect;
     if (pElement->GetString("Type") != "Font") {
       continue;
     }
@@ -523,9 +534,11 @@ FX_BOOL FindInterFormFont(CPDF_Dictionary* pFormDict,
     if (pObj == NULL) {
       continue;
     }
-    CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect());
-    if (!pElement)
+    CPDF_Object* pDirect = pObj->GetDirect();
+    if (pDirect == NULL || pDirect->GetType() != PDFOBJ_DICTIONARY) {
       continue;
+    }
+    CPDF_Dictionary* pElement = (CPDF_Dictionary*)pDirect;
     if (pElement->GetString("Type") != "Font") {
       continue;
     }
index 99f36a0..906554d 100644 (file)
@@ -1286,7 +1286,7 @@ int32_t CPDF_TextPage::PreMarkedContent(PDFTEXT_Obj Obj) {
   for (n = 0; n < nContentMark; n++) {
     CPDF_ContentMarkItem& item = pMarkData->GetItem(n);
     CFX_ByteString tagStr = (CFX_ByteString)item.GetName();
-    pDict = ToDictionary(static_cast<CPDF_Object*>(item.GetParam()));
+    pDict = (CPDF_Dictionary*)item.GetParam();
     CPDF_String* temp =
         (CPDF_String*)(pDict ? pDict->GetElement(FX_BSTRC("ActualText"))
                              : NULL);
@@ -1357,7 +1357,7 @@ void CPDF_TextPage::ProcessMarkedContent(PDFTEXT_Obj Obj) {
   for (n = 0; n < nContentMark; n++) {
     CPDF_ContentMarkItem& item = pMarkData->GetItem(n);
     CFX_ByteString tagStr = (CFX_ByteString)item.GetName();
-    pDict = ToDictionary(static_cast<CPDF_Object*>(item.GetParam()));
+    pDict = (CPDF_Dictionary*)item.GetParam();
     CPDF_String* temp =
         (CPDF_String*)(pDict ? pDict->GetElement(FX_BSTRC("ActualText"))
                              : NULL);
index 147a058..3a8853c 100644 (file)
@@ -137,9 +137,11 @@ CPDF_Font* CBA_FontMap::FindResFontSameCharset(CPDF_Dictionary* pResDict,
     if (pObj == NULL)
       continue;
 
-    CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect());
-    if (!pElement)
+    CPDF_Object* pDirect = pObj->GetDirect();
+    if (pDirect == NULL || pDirect->GetType() != PDFOBJ_DICTIONARY)
       continue;
+
+    CPDF_Dictionary* pElement = (CPDF_Dictionary*)pDirect;
     if (pElement->GetString("Type") != "Font")
       continue;
 
@@ -179,7 +181,7 @@ void CBA_FontMap::AddFontToAnnotDict(CPDF_Font* pFont,
 
   // to avoid checkbox and radiobutton
   CPDF_Object* pObject = pAPDict->GetElement(m_sAPType);
-  if (ToDictionary(pObject))
+  if (pObject && pObject->GetType() == PDFOBJ_DICTIONARY)
     return;
 
   CPDF_Stream* pStream = pAPDict->GetStream(m_sAPType);
index a4463b7..d2ce56a 100644 (file)
@@ -51,7 +51,7 @@ FX_BOOL CFFL_Utils::TraceObject(CPDF_Object* pObj) {
     } break;
 
     case PDFOBJ_DICTIONARY: {
-      CPDF_Dictionary* pDict = pObj->AsDictionary();
+      CPDF_Dictionary* pDict = (CPDF_Dictionary*)pObj;
 
       FX_POSITION fPos = pDict->GetStartPos();
       CFX_ByteString csKey;
index fee93f2..b2303f3 100644 (file)
@@ -94,10 +94,11 @@ int ParserAnnots(CPDF_Document* pSourceDoc,
 
   FX_DWORD dwSize = pAnnots->GetCount();
   for (int i = 0; i < (int)dwSize; i++) {
-    CPDF_Dictionary* pAnnotDic = ToDictionary(pAnnots->GetElementValue(i));
-    if (!pAnnotDic)
+    CPDF_Object* pObj = pAnnots->GetElementValue(i);
+    if (!pObj || pObj->GetType() != PDFOBJ_DICTIONARY)
       continue;
 
+    CPDF_Dictionary* pAnnotDic = (CPDF_Dictionary*)pObj;
     CFX_ByteString sSubtype = pAnnotDic->GetString("Subtype");
     if (sSubtype == "Popup")
       continue;
index 1e24b68..cdc646a 100644 (file)
@@ -166,8 +166,8 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFPage_TransFormWithClip(FPDF_PAGE page,
         CPDF_Object* pObj = pPattenDict->GetNextElement(pos, key);
         if (pObj->GetType() == PDFOBJ_REFERENCE)
           pObj = pObj->GetDirect();
-        if (pObj->IsDictionary()) {
-          pDict = pObj->AsDictionary();
+        if (pObj->GetType() == PDFOBJ_DICTIONARY) {
+          pDict = (CPDF_Dictionary*)pObj;
         } else if (pObj->GetType() == PDFOBJ_STREAM) {
           pDict = ((CPDF_Stream*)pObj)->GetDict();
         } else
index ad8ef8b..b770295 100644 (file)
@@ -56,8 +56,7 @@ FPDFBookmark_GetFirstChild(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) {
   if (!pDoc)
     return nullptr;
   CPDF_BookmarkTree tree(pDoc);
-  CPDF_Bookmark bookmark =
-      CPDF_Bookmark(ToDictionary(static_cast<CPDF_Object*>(pDict)));
+  CPDF_Bookmark bookmark = CPDF_Bookmark((CPDF_Dictionary*)pDict);
   return tree.GetFirstChild(bookmark).GetDict();
 }
 
@@ -69,8 +68,7 @@ FPDFBookmark_GetNextSibling(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) {
   if (!pDoc)
     return nullptr;
   CPDF_BookmarkTree tree(pDoc);
-  CPDF_Bookmark bookmark =
-      CPDF_Bookmark(ToDictionary(static_cast<CPDF_Object*>(pDict)));
+  CPDF_Bookmark bookmark = CPDF_Bookmark((CPDF_Dictionary*)pDict);
   return tree.GetNextSibling(bookmark).GetDict();
 }
 
@@ -79,7 +77,7 @@ DLLEXPORT unsigned long STDCALL FPDFBookmark_GetTitle(FPDF_BOOKMARK pDict,
                                                       unsigned long buflen) {
   if (!pDict)
     return 0;
-  CPDF_Bookmark bookmark(ToDictionary(static_cast<CPDF_Object*>(pDict)));
+  CPDF_Bookmark bookmark((CPDF_Dictionary*)pDict);
   CFX_WideString title = bookmark.GetTitle();
   CFX_ByteString encodedTitle = title.UTF16LE_Encode();
   unsigned long len = encodedTitle.GetLength();
@@ -109,7 +107,7 @@ DLLEXPORT FPDF_DEST STDCALL FPDFBookmark_GetDest(FPDF_DOCUMENT document,
   CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
   if (!pDoc)
     return nullptr;
-  CPDF_Bookmark bookmark(ToDictionary(static_cast<CPDF_Object*>(pDict)));
+  CPDF_Bookmark bookmark((CPDF_Dictionary*)pDict);
   CPDF_Dest dest = bookmark.GetDest(pDoc);
   if (dest)
     return dest.GetObject();
@@ -124,7 +122,7 @@ DLLEXPORT FPDF_DEST STDCALL FPDFBookmark_GetDest(FPDF_DOCUMENT document,
 DLLEXPORT FPDF_ACTION STDCALL FPDFBookmark_GetAction(FPDF_BOOKMARK pDict) {
   if (!pDict)
     return NULL;
-  CPDF_Bookmark bookmark(ToDictionary(static_cast<CPDF_Object*>(pDict)));
+  CPDF_Bookmark bookmark((CPDF_Dictionary*)pDict);
   return bookmark.GetAction().GetDict();
 }
 
@@ -132,7 +130,7 @@ DLLEXPORT unsigned long STDCALL FPDFAction_GetType(FPDF_ACTION pDict) {
   if (!pDict)
     return PDFACTION_UNSUPPORTED;
 
-  CPDF_Action action(ToDictionary(static_cast<CPDF_Object*>(pDict)));
+  CPDF_Action action((CPDF_Dictionary*)pDict);
   CPDF_Action::ActionType type = action.GetType();
   switch (type) {
     case CPDF_Action::GoTo:
@@ -155,7 +153,7 @@ DLLEXPORT FPDF_DEST STDCALL FPDFAction_GetDest(FPDF_DOCUMENT document,
   CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
   if (!pDoc)
     return nullptr;
-  CPDF_Action action(ToDictionary(static_cast<CPDF_Object*>(pDict)));
+  CPDF_Action action((CPDF_Dictionary*)pDict);
   return action.GetDest(pDoc).GetObject();
 }
 
@@ -165,7 +163,7 @@ FPDFAction_GetFilePath(FPDF_ACTION pDict, void* buffer, unsigned long buflen) {
   if (type != PDFACTION_REMOTEGOTO && type != PDFACTION_LAUNCH)
     return 0;
 
-  CPDF_Action action(ToDictionary(static_cast<CPDF_Object*>(pDict)));
+  CPDF_Action action((CPDF_Dictionary*)pDict);
   CFX_ByteString path = action.GetFilePath().UTF8Encode();
   unsigned long len = path.GetLength() + 1;
   if (buffer && buflen >= len)
@@ -182,7 +180,7 @@ DLLEXPORT unsigned long STDCALL FPDFAction_GetURIPath(FPDF_DOCUMENT document,
   CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
   if (!pDoc)
     return 0;
-  CPDF_Action action(ToDictionary(static_cast<CPDF_Object*>(pDict)));
+  CPDF_Action action((CPDF_Dictionary*)pDict);
   CFX_ByteString path = action.GetURI(pDoc);
   unsigned long len = path.GetLength() + 1;
   if (buffer && buflen >= len)
@@ -237,7 +235,7 @@ DLLEXPORT FPDF_DEST STDCALL FPDFLink_GetDest(FPDF_DOCUMENT document,
   CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
   if (!pDoc)
     return nullptr;
-  CPDF_Link link(ToDictionary(static_cast<CPDF_Object*>(pDict)));
+  CPDF_Link link((CPDF_Dictionary*)pDict);
   FPDF_DEST dest = link.GetDest(pDoc).GetObject();
   if (dest)
     return dest;
@@ -252,7 +250,7 @@ DLLEXPORT FPDF_ACTION STDCALL FPDFLink_GetAction(FPDF_LINK pDict) {
   if (!pDict)
     return nullptr;
 
-  CPDF_Link link(ToDictionary(static_cast<CPDF_Object*>(pDict)));
+  CPDF_Link link((CPDF_Dictionary*)pDict);
   return link.GetAction().GetDict();
 }
 
@@ -268,9 +266,8 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFLink_Enumerate(FPDF_PAGE page,
   if (!pAnnots)
     return FALSE;
   for (int i = *startPos; i < (int)pAnnots->GetCount(); i++) {
-    CPDF_Dictionary* pDict =
-        ToDictionary(static_cast<CPDF_Object*>(pAnnots->GetElementValue(i)));
-    if (!pDict)
+    CPDF_Dictionary* pDict = (CPDF_Dictionary*)pAnnots->GetElementValue(i);
+    if (!pDict || pDict->GetType() != PDFOBJ_DICTIONARY)
       continue;
     if (pDict->GetString(FX_BSTRC("Subtype")).Equal(FX_BSTRC("Link"))) {
       *startPos = i + 1;
@@ -285,8 +282,7 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFLink_GetAnnotRect(FPDF_LINK linkAnnot,
                                                   FS_RECTF* rect) {
   if (!linkAnnot || !rect)
     return FALSE;
-  CPDF_Dictionary* pAnnotDict =
-      ToDictionary(static_cast<CPDF_Object*>(linkAnnot));
+  CPDF_Dictionary* pAnnotDict = (CPDF_Dictionary*)linkAnnot;
   CPDF_Rect rt = pAnnotDict->GetRect(FX_BSTRC("Rect"));
   rect->left = rt.left;
   rect->bottom = rt.bottom;
@@ -298,8 +294,7 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFLink_GetAnnotRect(FPDF_LINK linkAnnot,
 DLLEXPORT int STDCALL FPDFLink_CountQuadPoints(FPDF_LINK linkAnnot) {
   if (!linkAnnot)
     return 0;
-  CPDF_Dictionary* pAnnotDict =
-      ToDictionary(static_cast<CPDF_Object*>(linkAnnot));
+  CPDF_Dictionary* pAnnotDict = (CPDF_Dictionary*)linkAnnot;
   CPDF_Array* pArray = pAnnotDict->GetArray(FX_BSTRC("QuadPoints"));
   if (!pArray)
     return 0;
@@ -311,8 +306,7 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFLink_GetQuadPoints(FPDF_LINK linkAnnot,
                                                    FS_QUADPOINTSF* quadPoints) {
   if (!linkAnnot || !quadPoints)
     return FALSE;
-  CPDF_Dictionary* pAnnotDict =
-      ToDictionary(static_cast<CPDF_Object*>(linkAnnot));
+  CPDF_Dictionary* pAnnotDict = (CPDF_Dictionary*)linkAnnot;
   CPDF_Array* pArray = pAnnotDict->GetArray(FX_BSTRC("QuadPoints"));
   if (pArray) {
     if (quadIndex < 0 || quadIndex >= (int)pArray->GetCount() / 8 ||
index 7b70526..f2d13d6 100644 (file)
@@ -103,7 +103,7 @@ DLLEXPORT int STDCALL FPDFPage_GetRotation(FPDF_PAGE page) {
     else {
       if (pDict->KeyExist("Parent")) {
         CPDF_Dictionary* pPages =
-            ToDictionary(pDict->GetElement("Parent")->GetDirect());
+            (CPDF_Dictionary*)pDict->GetElement("Parent")->GetDirect();
         while (pPages) {
           if (pPages->KeyExist("Rotate")) {
             rotate =
@@ -113,7 +113,8 @@ DLLEXPORT int STDCALL FPDFPage_GetRotation(FPDF_PAGE page) {
                     : 0;
             break;
           } else if (pPages->KeyExist("Parent"))
-            pPages = ToDictionary(pPages->GetElement("Parent")->GetDirect());
+            pPages =
+                (CPDF_Dictionary*)pPages->GetElement("Parent")->GetDirect();
           else
             break;
         }
@@ -212,7 +213,7 @@ FPDFPageObj_HasTransparency(FPDF_PAGEOBJECT pageObject) {
     return TRUE;
 
   CPDF_Dictionary* pSMaskDict =
-      pGeneralState ? ToDictionary(pGeneralState->m_pSoftMask) : NULL;
+      pGeneralState ? (CPDF_Dictionary*)pGeneralState->m_pSoftMask : NULL;
   if (pSMaskDict)
     return TRUE;
 
index ab25b76..2508adc 100644 (file)
@@ -60,7 +60,7 @@ FX_BOOL CPDF_PageOrganizer::PDFDocInit(CPDF_Document* pDestPDFDoc,
 
   CPDF_Object* pElement = pNewRoot->GetElement("Pages");
   CPDF_Dictionary* pNewPages =
-      pElement ? ToDictionary(pElement->GetDirect()) : nullptr;
+      pElement ? (CPDF_Dictionary*)pElement->GetDirect() : nullptr;
   if (!pNewPages) {
     pNewPages = new CPDF_Dictionary;
     FX_DWORD NewPagesON = pDestPDFDoc->AddIndirectObject(pNewPages);
@@ -183,13 +183,14 @@ CPDF_Object* CPDF_PageOrganizer::PageDictGetInheritableTag(
   if (pType->GetString().Compare("Page"))
     return nullptr;
 
-  CPDF_Dictionary* pp = ToDictionary(pDict->GetElement("Parent")->GetDirect());
-  if (!pp)
+  CPDF_Object* pParent = pDict->GetElement("Parent")->GetDirect();
+  if (!pParent || pParent->GetType() != PDFOBJ_DICTIONARY)
     return nullptr;
 
   if (pDict->KeyExist((const char*)nSrctag))
     return pDict->GetElement((const char*)nSrctag);
 
+  CPDF_Dictionary* pp = (CPDF_Dictionary*)pParent;
   while (pp) {
     if (pp->KeyExist((const char*)nSrctag)) {
       return pp->GetElement((const char*)nSrctag);
@@ -197,8 +198,12 @@ CPDF_Object* CPDF_PageOrganizer::PageDictGetInheritableTag(
     if (!pp->KeyExist("Parent")) {
       break;
     }
-    pp = ToDictionary(pp->GetElement("Parent")->GetDirect());
+    pp = (CPDF_Dictionary*)pp->GetElement("Parent")->GetDirect();
+    if (pp->GetType() == PDFOBJ_NULL) {
+      break;
+    }
   }
+
   return nullptr;
 }
 
@@ -215,7 +220,7 @@ FX_BOOL CPDF_PageOrganizer::UpdateReference(CPDF_Object* pObj,
       break;
     }
     case PDFOBJ_DICTIONARY: {
-      CPDF_Dictionary* pDict = pObj->AsDictionary();
+      CPDF_Dictionary* pDict = (CPDF_Dictionary*)pObj;
 
       FX_POSITION pos = pDict->GetStartPos();
       while (pos) {
@@ -286,7 +291,8 @@ FX_DWORD CPDF_PageOrganizer::GetNewObjId(CPDF_Document* pDoc,
   if (!pClone)
     return 0;
 
-  if (CPDF_Dictionary* pDictClone = pClone->AsDictionary()) {
+  if (pClone->GetType() == PDFOBJ_DICTIONARY) {
+    CPDF_Dictionary* pDictClone = (CPDF_Dictionary*)pClone;
     if (pDictClone->KeyExist("Type")) {
       CFX_ByteString strType = pDictClone->GetString("Type");
       if (!FXSYS_stricmp(strType, "Pages")) {
index 0d6dcf2..19faea5 100644 (file)
@@ -882,8 +882,8 @@ DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDest(FPDF_DOCUMENT document,
   }
   if (!pDestObj)
     return NULL;
-  if (CPDF_Dictionary* pDict = pDestObj->AsDictionary()) {
-    pDestObj = pDict->GetArray(FX_BSTRC("D"));
+  if (pDestObj->GetType() == PDFOBJ_DICTIONARY) {
+    pDestObj = ((CPDF_Dictionary*)pDestObj)->GetArray(FX_BSTRC("D"));
     if (!pDestObj)
       return NULL;
   }
index b4aa822..7d0346c 100644 (file)
@@ -65,7 +65,8 @@ FX_BOOL CPDFSDK_Widget::IsWidgetAppearanceValid(
       return psub->GetType() == PDFOBJ_STREAM;
     case FIELDTYPE_CHECKBOX:
     case FIELDTYPE_RADIOBUTTON:
-      if (CPDF_Dictionary* pSubDict = psub->AsDictionary()) {
+      if (psub->GetType() == PDFOBJ_DICTIONARY) {
+        CPDF_Dictionary* pSubDict = (CPDF_Dictionary*)psub;
         return pSubDict->GetStream(GetAppState()) != NULL;
       }
       return FALSE;
index fccfbe9..5d765a4 100644 (file)
@@ -482,7 +482,8 @@ FX_BOOL CPDFSDK_Document::ProcOpenAction() {
   if (pOpenAction->GetType() == PDFOBJ_ARRAY)
     return TRUE;
 
-  if (CPDF_Dictionary* pDict = pOpenAction->AsDictionary()) {
+  if (pOpenAction->GetType() == PDFOBJ_DICTIONARY) {
+    CPDF_Dictionary* pDict = (CPDF_Dictionary*)pOpenAction;
     CPDF_Action action(pDict);
     if (m_pEnv->GetActionHander())
       m_pEnv->GetActionHander()->DoAction_DocOpen(action, this);