diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2015-10-22 15:02:06 -0400 |
---|---|---|
committer | Dan Sinclair <dsinclair@chromium.org> | 2015-10-22 15:02:06 -0400 |
commit | 2b11dc1220746d2f6f97a940fc9e4235c8ed4975 (patch) | |
tree | e25b2ba13112f4ead789260ee57fe5b40c13b83e /core/src/fpdfapi/fpdf_page | |
parent | bc6c6723c37772b02de9e6e43fa0fd9439874905 (diff) | |
download | pdfium-2b11dc1220746d2f6f97a940fc9e4235c8ed4975.tar.xz |
Merge to XFA: Add type cast definitions for CPDF_Array.
This Cl adds ToArray, CPDF_Object::AsArray and CPDF_Object::IsArray and
updates the src to use them as needed.
BUG=pdfium:201
R=thestig@chromium.org, tsepez@chromium.org
Review URL: https://codereview.chromium.org/1417893003 .
(cherry picked from commit c2bfc000e502c42c9a3017038fd9104c7997d126)
Review URL: https://codereview.chromium.org/1419643005 .
Diffstat (limited to 'core/src/fpdfapi/fpdf_page')
-rw-r--r-- | core/src/fpdfapi/fpdf_page/fpdf_page.cpp | 6 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp | 33 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp | 6 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp | 32 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp | 4 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp | 28 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_page/fpdf_page_pattern.cpp | 11 |
7 files changed, 53 insertions, 67 deletions
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page.cpp index f6f03336a0..162acfa898 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page.cpp @@ -814,8 +814,7 @@ void CPDF_Page::Load(CPDF_Document* pDocument, if (rotate < 0) { rotate += 4; } - CPDF_Array *pMediaBox, *pCropBox; - pMediaBox = (CPDF_Array*)GetPageAttr(FX_BSTRC("MediaBox")); + CPDF_Array* pMediaBox = ToArray(GetPageAttr(FX_BSTRC("MediaBox"))); CFX_FloatRect mediabox; if (pMediaBox) { mediabox = pMediaBox->GetRect(); @@ -824,7 +823,8 @@ void CPDF_Page::Load(CPDF_Document* pDocument, if (mediabox.IsEmpty()) { mediabox = CFX_FloatRect(0, 0, 612, 792); } - pCropBox = (CPDF_Array*)GetPageAttr(FX_BSTRC("CropBox")); + + CPDF_Array* pCropBox = ToArray(GetPageAttr(FX_BSTRC("CropBox"))); if (pCropBox) { m_BBox = pCropBox->GetRect(); m_BBox.Normalize(); diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp index 73b1091856..4f54c01ce7 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp @@ -1139,14 +1139,11 @@ void CPDF_DeviceNCS::GetDefaultValue(int iComponent, max = 1.0f; } FX_BOOL CPDF_DeviceNCS::v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) { - CPDF_Object* pObj = pArray->GetElementValue(1); - if (!pObj) { - return FALSE; - } - if (pObj->GetType() != PDFOBJ_ARRAY) { + CPDF_Array* pObj = ToArray(pArray->GetElementValue(1)); + if (!pObj) return FALSE; - } - m_nComponents = ((CPDF_Array*)pObj)->GetCount(); + + m_nComponents = pObj->GetCount(); CPDF_Object* pAltCS = pArray->GetElementValue(2); if (!pAltCS || pAltCS == m_pArray) { return FALSE; @@ -1224,21 +1221,19 @@ CPDF_ColorSpace* CPDF_ColorSpace::Load(CPDF_Document* pDoc, CPDF_Object* pObj) { } return nullptr; } - if (pObj->GetType() != PDFOBJ_ARRAY) { - return NULL; - } - CPDF_Array* pArray = (CPDF_Array*)pObj; - if (pArray->GetCount() == 0) { - return NULL; - } + + CPDF_Array* pArray = pObj->AsArray(); + if (!pArray || pArray->GetCount() == 0) + return nullptr; + CPDF_Object* pFamilyObj = pArray->GetElementValue(0); - if (!pFamilyObj) { - return NULL; - } + if (!pFamilyObj) + return nullptr; + CFX_ByteString familyname = pFamilyObj->GetString(); - if (pArray->GetCount() == 1) { + if (pArray->GetCount() == 1) return _CSFromName(familyname); - } + CPDF_ColorSpace* pCS = NULL; FX_DWORD id = familyname.GetID(); if (id == FXBSTR_ID('C', 'a', 'l', 'G')) { diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp index 9a1d48a416..436cca6d99 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp @@ -343,10 +343,8 @@ CPDF_ColorSpace* CPDF_DocPageData::GetColorSpace(CPDF_Object* pCSObj, return pDefaultCS ? GetColorSpace(pDefaultCS, nullptr) : pCS; } - if (pCSObj->GetType() != PDFOBJ_ARRAY) - return nullptr; - CPDF_Array* pArray = (CPDF_Array*)pCSObj; - if (pArray->GetCount() == 0) + CPDF_Array* pArray = pCSObj->AsArray(); + if (!pArray || pArray->GetCount() == 0) return nullptr; if (pArray->GetCount() == 1) return GetColorSpace(pArray->GetElementValue(0), pResources); 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 62a3c67996..78d3d26188 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp @@ -461,10 +461,10 @@ void CPDF_AllStates::ProcessExtGS(CPDF_Dictionary* pGS, while (pos) { CFX_ByteString key_str; CPDF_Object* pElement = pGS->GetNextElement(pos, key_str); - CPDF_Object* pObject = pElement ? pElement->GetDirect() : NULL; - if (pObject == NULL) { + CPDF_Object* pObject = pElement ? pElement->GetDirect() : nullptr; + if (!pObject) continue; - } + FX_DWORD key = key_str.GetID(); switch (key) { case FXBSTR_ID('L', 'W', 0, 0): @@ -482,14 +482,14 @@ void CPDF_AllStates::ProcessExtGS(CPDF_Dictionary* pGS, m_GraphState.GetModify()->m_MiterLimit = pObject->GetNumber(); break; case FXBSTR_ID('D', 0, 0, 0): { - if (pObject->GetType() != PDFOBJ_ARRAY) { + CPDF_Array* pDash = pObject->AsArray(); + if (!pDash) break; - } - CPDF_Array* pDash = (CPDF_Array*)pObject; + CPDF_Array* pArray = pDash->GetArray(0); - if (pArray == NULL) { + if (!pArray) break; - } + SetLineDash(pArray, pDash->GetNumber(1), 1.0f); break; } @@ -497,10 +497,10 @@ void CPDF_AllStates::ProcessExtGS(CPDF_Dictionary* pGS, m_GeneralState.SetRenderIntent(pObject->GetString()); break; case FXBSTR_ID('F', 'o', 'n', 't'): { - if (pObject->GetType() != PDFOBJ_ARRAY) { + CPDF_Array* pFont = pObject->AsArray(); + if (!pFont) break; - } - CPDF_Array* pFont = (CPDF_Array*)pObject; + m_TextState.GetModify()->m_FontSize = pFont->GetNumber(1); m_TextState.SetFont(pParser->FindFont(pFont->GetString(0))); break; @@ -514,12 +514,10 @@ void CPDF_AllStates::ProcessExtGS(CPDF_Dictionary* pGS, (pObject && !pObject->IsName()) ? pObject : nullptr; break; case FXBSTR_ID('B', 'M', 0, 0): { - CFX_ByteString mode; - if (pObject->GetType() == PDFOBJ_ARRAY) { - mode = ((CPDF_Array*)pObject)->GetString(0); - } else { - mode = pObject->GetString(); - } + CPDF_Array* pArray = pObject->AsArray(); + CFX_ByteString mode = + pArray ? pArray->GetString(0) : pObject->GetString(); + pGeneralState->SetBlendMode(mode); if (pGeneralState->m_BlendType > FXDIB_BLEND_MULTIPLY) { pParser->GetObjectList()->m_bBackgroundAlphaNeeded = TRUE; diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp index 6f186e6c3b..7aa2cf8aa3 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp @@ -514,7 +514,7 @@ void _PDF_ReplaceAbbr(CPDF_Object* pObj) { break; } case PDFOBJ_ARRAY: { - CPDF_Array* pArray = (CPDF_Array*)pObj; + CPDF_Array* pArray = pObj->AsArray(); for (FX_DWORD i = 0; i < pArray->GetCount(); i++) { CPDF_Object* pElement = pArray->GetElement(i); if (pElement->IsName()) { @@ -577,7 +577,7 @@ void _PDF_ReplaceFull(CPDF_Object* pObj) { break; } case PDFOBJ_ARRAY: { - CPDF_Array* pArray = (CPDF_Array*)pObj; + CPDF_Array* pArray = pObj->AsArray(); for (FX_DWORD i = 0; i < pArray->GetCount(); i++) { CPDF_Object* pElement = pArray->GetElement(i); if (pElement->IsName()) { diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp index f051d0db5a..c27ede44cb 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp @@ -332,16 +332,16 @@ CPDF_Stream* CPDF_StreamParser::ReadInlineStream(CPDF_Document* pDoc, CFX_ByteString Decoder; CPDF_Dictionary* pParam = NULL; CPDF_Object* pFilter = pDict->GetElementValue(FX_BSTRC("Filter")); - if (pFilter == NULL) { - } else if (pFilter->GetType() == PDFOBJ_ARRAY) { - Decoder = ((CPDF_Array*)pFilter)->GetString(0); - CPDF_Array* pParams = pDict->GetArray(FX_BSTRC("DecodeParms")); - if (pParams) { - pParam = pParams->GetDict(0); + if (pFilter) { + if (CPDF_Array* pArray = pFilter->AsArray()) { + Decoder = pArray->GetString(0); + CPDF_Array* pParams = pDict->GetArray(FX_BSTRC("DecodeParms")); + if (pParams) + pParam = pParams->GetDict(0); + } else { + Decoder = pFilter->GetString(); + pParam = pDict->GetDict(FX_BSTRC("DecodeParms")); } - } else { - Decoder = pFilter->GetString(); - pParam = pDict->GetDict(FX_BSTRC("DecodeParms")); } FX_DWORD width = pDict->GetInteger(FX_BSTRC("Width")); FX_DWORD height = pDict->GetInteger(FX_BSTRC("Height")); @@ -403,12 +403,11 @@ CPDF_Stream* CPDF_StreamParser::ReadInlineStream(CPDF_Document* pDoc, if (bDecode) { m_Pos += dwStreamSize; dwStreamSize = dwDestSize; - if (pFilter->GetType() == PDFOBJ_ARRAY) { - ((CPDF_Array*)pFilter)->RemoveAt(0); + if (CPDF_Array* pArray = pFilter->AsArray()) { + pArray->RemoveAt(0); CPDF_Array* pParams = pDict->GetArray(FX_BSTRC("DecodeParms")); - if (pParams) { + if (pParams) pParams->RemoveAt(0); - } } else { pDict->RemoveAt(FX_BSTRC("Filter")); pDict->RemoveAt(FX_BSTRC("DecodeParms")); @@ -965,8 +964,7 @@ void CPDF_ContentParser::Start(CPDF_Page* pPage, CPDF_ParseOptions* pOptions) { m_nStreams = 0; m_pSingleStream = new CPDF_StreamAcc; m_pSingleStream->LoadAllData((CPDF_Stream*)pContent, FALSE); - } else if (pContent->GetType() == PDFOBJ_ARRAY) { - CPDF_Array* pArray = (CPDF_Array*)pContent; + } else if (CPDF_Array* pArray = pContent->AsArray()) { m_nStreams = pArray->GetCount(); if (m_nStreams == 0) { m_Status = Done; diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_pattern.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_pattern.cpp index 3f915a7b79..a73bdc9e8e 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page_pattern.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page_pattern.cpp @@ -118,14 +118,11 @@ FX_BOOL CPDF_ShadingPattern::Load() { } CPDF_Object* pFunc = pShadingDict->GetElementValue(FX_BSTRC("Function")); if (pFunc) { - if (pFunc->GetType() == PDFOBJ_ARRAY) { - m_nFuncs = ((CPDF_Array*)pFunc)->GetCount(); - if (m_nFuncs > 4) { - m_nFuncs = 4; - } + if (CPDF_Array* pArray = pFunc->AsArray()) { + m_nFuncs = std::min<int>(pArray->GetCount(), 4); + for (int i = 0; i < m_nFuncs; i++) { - m_pFunctions[i] = - CPDF_Function::Load(((CPDF_Array*)pFunc)->GetElementValue(i)); + m_pFunctions[i] = CPDF_Function::Load(pArray->GetElementValue(i)); } } else { m_pFunctions[0] = CPDF_Function::Load(pFunc); |