diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2015-10-20 13:19:19 -0400 |
---|---|---|
committer | Dan Sinclair <dsinclair@chromium.org> | 2015-10-20 13:19:19 -0400 |
commit | 4816432671eef6467354aa252f22bb80acc315b7 (patch) | |
tree | 403313130206e70abf8ceae78353042a38221bec /core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp | |
parent | 8b8dfd7934d669b2c74a0502f82387e5df0f573b (diff) | |
download | pdfium-4816432671eef6467354aa252f22bb80acc315b7.tar.xz |
Add type cast definitions for CPDF_Dictionary.
This CL adds ToCPDFDictionary type definitions and updates one file to use
instead of straight casts. I had to fix two places where we'd casted off the
constness of the original pointer.
BUG=pdfium:201
R=tsepez@chromium.org
Review URL: https://codereview.chromium.org/1399233003 .
Diffstat (limited to 'core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp')
-rw-r--r-- | core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp index 19359ad7cf..82bfbb56eb 100644 --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp @@ -70,13 +70,11 @@ void CFDF_Document::ParseStream(IFX_FileRead* pFile, FX_BOOL bOwnFile) { if (word != FX_BSTRC("trailer")) { break; } - CPDF_Dictionary* pMainDict = - (CPDF_Dictionary*)parser.GetObject(this, 0, 0, 0); - if (pMainDict == NULL || pMainDict->GetType() != PDFOBJ_DICTIONARY) { - break; + if (CPDF_Dictionary* pMainDict = + ToDictionary(parser.GetObject(this, 0, 0, 0))) { + m_pRootDict = pMainDict->GetDict(FX_BSTRC("Root")); + pMainDict->Release(); } - m_pRootDict = pMainDict->GetDict(FX_BSTRC("Root")); - pMainDict->Release(); break; } } @@ -142,18 +140,17 @@ void FPDF_FileSpec_SetWin32Path(CPDF_Object* pFileSpec, } if (pFileSpec->GetType() == PDFOBJ_STRING) { pFileSpec->SetString(CFX_ByteString::FromUnicode(result)); - } 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")); + } 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")); } } CFX_WideString FPDF_FileSpec_GetWin32Path(const CPDF_Object* pFileSpec) { CFX_WideString wsFileName; - if (pFileSpec->GetType() == PDFOBJ_DICTIONARY) { - CPDF_Dictionary* pDict = (CPDF_Dictionary*)pFileSpec; + if (!pFileSpec) { + wsFileName = CFX_WideString(); + } else if (const CPDF_Dictionary* pDict = pFileSpec->AsDictionary()) { wsFileName = pDict->GetUnicodeText(FX_BSTRC("UF")); if (wsFileName.IsEmpty()) { wsFileName = CFX_WideString::FromLocal(pDict->GetString(FX_BSTRC("F"))); @@ -164,9 +161,7 @@ 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 if (!pFileSpec) - wsFileName = CFX_WideString(); - else { + } else { wsFileName = CFX_WideString::FromLocal(pFileSpec->GetString()); } if (wsFileName[0] != '/') { |