summaryrefslogtreecommitdiff
path: root/core/src/fpdfapi/fpdf_page
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2015-10-22 16:45:48 -0400
committerDan Sinclair <dsinclair@chromium.org>2015-10-22 16:45:48 -0400
commitaa435ba7fe0aacd9102e8c73311c5382ca112439 (patch)
treed37573646c6135126d3971358024a70ee222fb21 /core/src/fpdfapi/fpdf_page
parent2b11dc1220746d2f6f97a940fc9e4235c8ed4975 (diff)
downloadpdfium-aa435ba7fe0aacd9102e8c73311c5382ca112439.tar.xz
Merge to XFA: Add type cast definitions for CPDF_Stream.
This Cl adds ToStream, CPDF_Object::AsStream and CPDF_Object::IsStream and updates the src to use them as needed. BUG=pdfium:201 R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1402413004 . (cherry picked from commit 338805f1366dcdf9a5b48cf591541cf98d7490f1) Review URL: https://codereview.chromium.org/1422513004 .
Diffstat (limited to 'core/src/fpdfapi/fpdf_page')
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp8
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp2
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_func.cpp33
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_image.cpp11
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp11
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp9
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_pattern.cpp27
7 files changed, 46 insertions, 55 deletions
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp
index 4f54c01ce7..bed3cfbb2c 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp
@@ -913,9 +913,9 @@ FX_BOOL CPDF_IndexedCS::v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) {
if (CPDF_String* pString = pTableObj->AsString()) {
m_Table = pString->GetString();
- } else if (pTableObj->GetType() == PDFOBJ_STREAM) {
+ } else if (CPDF_Stream* pStream = pTableObj->AsStream()) {
CPDF_StreamAcc acc;
- acc.LoadAllData((CPDF_Stream*)pTableObj, FALSE);
+ acc.LoadAllData(pStream, FALSE);
m_Table = CFX_ByteStringC(acc.GetData(), acc.GetSize());
}
return TRUE;
@@ -1204,8 +1204,8 @@ CPDF_ColorSpace* CPDF_ColorSpace::Load(CPDF_Document* pDoc, CPDF_Object* pObj) {
if (pObj->IsName())
return _CSFromName(pObj->GetString());
- if (pObj->GetType() == PDFOBJ_STREAM) {
- CPDF_Dictionary* pDict = ((CPDF_Stream*)pObj)->GetDict();
+ if (CPDF_Stream* pStream = pObj->AsStream()) {
+ CPDF_Dictionary* pDict = pStream->GetDict();
if (!pDict)
return nullptr;
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp
index 436cca6d99..8656b72023 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp
@@ -470,7 +470,7 @@ CPDF_Image* CPDF_DocPageData::GetImage(CPDF_Object* pImageStream) {
}
CPDF_Image* pImage = new CPDF_Image(m_pPDFDoc);
- pImage->LoadImageF((CPDF_Stream*)pImageStream, FALSE);
+ pImage->LoadImageF(pImageStream->AsStream(), FALSE);
CPDF_CountedImage* imageData = new CPDF_CountedImage(pImage);
m_ImageMap[dwImageObjNum] = imageData;
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_func.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_func.cpp
index d66a9efdaa..2d35dd85be 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_func.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_func.cpp
@@ -491,10 +491,10 @@ CPDF_SampledFunc::~CPDF_SampledFunc() {
FX_Free(m_pDecodeInfo);
}
FX_BOOL CPDF_SampledFunc::v_Init(CPDF_Object* pObj) {
- if (pObj->GetType() != PDFOBJ_STREAM) {
- return FALSE;
- }
- CPDF_Stream* pStream = (CPDF_Stream*)pObj;
+ CPDF_Stream* pStream = pObj->AsStream();
+ if (!pStream)
+ return false;
+
CPDF_Dictionary* pDict = pStream->GetDict();
CPDF_Array* pSize = pDict->GetArray(FX_BSTRC("Size"));
CPDF_Array* pEncode = pDict->GetArray(FX_BSTRC("Encode"));
@@ -632,7 +632,7 @@ class CPDF_PSFunc : public CPDF_Function {
};
FX_BOOL CPDF_PSFunc::v_Init(CPDF_Object* pObj) {
- CPDF_Stream* pStream = (CPDF_Stream*)pObj;
+ CPDF_Stream* pStream = pObj->AsStream();
CPDF_StreamAcc acc;
acc.LoadAllData(pStream, FALSE);
return m_PS.Parse((const FX_CHAR*)acc.GetData(), acc.GetSize());
@@ -814,10 +814,8 @@ CPDF_Function* CPDF_Function::Load(CPDF_Object* pFuncObj) {
}
CPDF_Function* pFunc = NULL;
int type;
- if (pFuncObj->GetType() == PDFOBJ_STREAM) {
- type = ((CPDF_Stream*)pFuncObj)
- ->GetDict()
- ->GetInteger(FX_BSTRC("FunctionType"));
+ if (CPDF_Stream* pStream = pFuncObj->AsStream()) {
+ type = pStream->GetDict()->GetInteger(FX_BSTRC("FunctionType"));
} else if (CPDF_Dictionary* pDict = pFuncObj->AsDictionary()) {
type = pDict->GetInteger(FX_BSTRC("FunctionType"));
} else {
@@ -849,20 +847,17 @@ CPDF_Function::~CPDF_Function() {
FX_Free(m_pRanges);
}
FX_BOOL CPDF_Function::Init(CPDF_Object* pObj) {
- CPDF_Dictionary* pDict;
- if (pObj->GetType() == PDFOBJ_STREAM) {
- pDict = ((CPDF_Stream*)pObj)->GetDict();
- } else {
- pDict = pObj->AsDictionary();
- }
+ CPDF_Stream* pStream = pObj->AsStream();
+ CPDF_Dictionary* pDict = pStream ? pStream->GetDict() : pObj->AsDictionary();
+
CPDF_Array* pDomains = pDict->GetArray(FX_BSTRC("Domain"));
- if (pDomains == NULL) {
+ if (!pDomains)
return FALSE;
- }
+
m_nInputs = pDomains->GetCount() / 2;
- if (m_nInputs == 0) {
+ if (m_nInputs == 0)
return FALSE;
- }
+
m_pDomains = FX_Alloc2D(FX_FLOAT, m_nInputs, 2);
for (int i = 0; i < m_nInputs * 2; i++) {
m_pDomains[i] = pDomains->GetFloat(i);
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_image.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_image.cpp
index 9cdf00e717..06e2d2c187 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_image.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_image.cpp
@@ -45,15 +45,14 @@ void CPDF_Image::Release() {
}
}
CPDF_Image* CPDF_Image::Clone() {
- if (m_pStream->GetObjNum()) {
+ if (m_pStream->GetObjNum())
return m_pDocument->GetPageData()->GetImage(m_pStream);
- }
+
CPDF_Image* pImage = new CPDF_Image(m_pDocument);
- pImage->LoadImageF((CPDF_Stream*)((CPDF_Object*)m_pStream)->Clone(),
- m_bInline);
- if (m_bInline) {
+ pImage->LoadImageF(ToStream(m_pStream->CPDF_Object::Clone()), m_bInline);
+ if (m_bInline)
pImage->SetInlineDict(ToDictionary(m_pInlineDict->Clone(TRUE)));
- }
+
return pImage;
}
CPDF_Image::CPDF_Image(CPDF_Document* pDoc) {
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp
index 7aa2cf8aa3..3295b7f9e0 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp
@@ -716,12 +716,12 @@ void CPDF_StreamContentParser::Handle_ExecuteXObject() {
return;
}
}
- CPDF_Stream* pXObject =
- (CPDF_Stream*)FindResourceObj(FX_BSTRC("XObject"), name);
- if (pXObject == NULL || pXObject->GetType() != PDFOBJ_STREAM) {
+ CPDF_Stream* pXObject = ToStream(FindResourceObj(FX_BSTRC("XObject"), name));
+ if (!pXObject) {
m_bResourceMissing = TRUE;
return;
}
+
CFX_ByteStringC type =
pXObject->GetDict()
? pXObject->GetDict()->GetConstString(FX_BSTRC("Subtype"))
@@ -1151,7 +1151,7 @@ void CPDF_StreamContentParser::Handle_ShadeFill() {
bbox = m_BBox;
}
if (pShading->m_ShadingType >= 4) {
- bbox.Intersect(_GetShadingBBox((CPDF_Stream*)pShading->m_pShadingObj,
+ bbox.Intersect(_GetShadingBBox(ToStream(pShading->m_pShadingObj),
pShading->m_ShadingType, &pObj->m_Matrix,
pShading->m_pFunctions, pShading->m_nFuncs,
pShading->m_pCS));
@@ -1262,8 +1262,7 @@ 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 || (!pPattern->IsDictionary() && !pPattern->IsStream())) {
m_bResourceMissing = TRUE;
return NULL;
}
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 c27ede44cb..b86d00851c 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp
@@ -960,10 +960,10 @@ void CPDF_ContentParser::Start(CPDF_Page* pPage, CPDF_ParseOptions* pOptions) {
m_Status = Done;
return;
}
- if (pContent->GetType() == PDFOBJ_STREAM) {
+ if (CPDF_Stream* pStream = pContent->AsStream()) {
m_nStreams = 0;
m_pSingleStream = new CPDF_StreamAcc;
- m_pSingleStream->LoadAllData((CPDF_Stream*)pContent, FALSE);
+ m_pSingleStream->LoadAllData(pStream, FALSE);
} else if (CPDF_Array* pArray = pContent->AsArray()) {
m_nStreams = pArray->GetCount();
if (m_nStreams == 0) {
@@ -1078,9 +1078,8 @@ void CPDF_ContentParser::Continue(IFX_Pause* pPause) {
CPDF_Array* pContent =
m_pObjects->m_pFormDict->GetArray(FX_BSTRC("Contents"));
m_pStreamArray[m_CurrentOffset] = new CPDF_StreamAcc;
- CPDF_Stream* pStreamObj =
- (CPDF_Stream*)(pContent ? pContent->GetElementValue(m_CurrentOffset)
- : NULL);
+ CPDF_Stream* pStreamObj = ToStream(
+ pContent ? pContent->GetElementValue(m_CurrentOffset) : nullptr);
m_pStreamArray[m_CurrentOffset]->LoadAllData(pStreamObj, FALSE);
m_CurrentOffset++;
}
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_pattern.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_pattern.cpp
index a73bdc9e8e..7b04d8cd33 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_pattern.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_pattern.cpp
@@ -38,20 +38,21 @@ CPDF_TilingPattern::~CPDF_TilingPattern() {
m_pForm = NULL;
}
FX_BOOL CPDF_TilingPattern::Load() {
- if (m_pForm != NULL) {
+ if (m_pForm)
return TRUE;
- }
+
CPDF_Dictionary* pDict = m_pPatternObj->GetDict();
- if (pDict == NULL) {
+ if (!pDict)
return FALSE;
- }
+
m_bColored = pDict->GetInteger(FX_BSTRC("PaintType")) == 1;
m_XStep = (FX_FLOAT)FXSYS_fabs(pDict->GetNumber(FX_BSTRC("XStep")));
m_YStep = (FX_FLOAT)FXSYS_fabs(pDict->GetNumber(FX_BSTRC("YStep")));
- if (m_pPatternObj->GetType() != PDFOBJ_STREAM) {
+
+ CPDF_Stream* pStream = m_pPatternObj->AsStream();
+ if (!pStream)
return FALSE;
- }
- CPDF_Stream* pStream = (CPDF_Stream*)m_pPatternObj;
+
m_pForm = new CPDF_Form(m_pDocument, NULL, pStream);
m_pForm->ParseContent(NULL, &m_ParentMatrix, NULL, NULL);
m_BBox = pDict->GetRect(FX_BSTRC("BBox"));
@@ -253,14 +254,13 @@ CFX_FloatRect _GetShadingBBox(CPDF_Stream* pStream,
CPDF_Function** pFuncs,
int nFuncs,
CPDF_ColorSpace* pCS) {
- if (pStream == NULL || pStream->GetType() != PDFOBJ_STREAM ||
- pFuncs == NULL || pCS == NULL) {
+ if (!pStream || !pStream->IsStream() || !pFuncs || !pCS)
return CFX_FloatRect(0, 0, 0, 0);
- }
+
CPDF_MeshStream stream;
- if (!stream.Load(pStream, pFuncs, nFuncs, pCS)) {
+ if (!stream.Load(pStream, pFuncs, nFuncs, pCS))
return CFX_FloatRect(0, 0, 0, 0);
- }
+
CFX_FloatRect rect;
FX_BOOL bStarted = FALSE;
FX_BOOL bGouraud = type == 4 || type == 5;
@@ -288,9 +288,8 @@ CFX_FloatRect _GetShadingBBox(CPDF_Stream* pStream,
}
stream.m_BitStream.SkipBits(stream.m_nComps * stream.m_nCompBits *
color_count);
- if (bGouraud) {
+ if (bGouraud)
stream.m_BitStream.ByteAlign();
- }
}
rect.Transform(pMatrix);
return rect;