summaryrefslogtreecommitdiff
path: root/core/src/fpdfapi
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/fpdfapi')
-rw-r--r--core/src/fpdfapi/fpdf_edit/fpdf_edit_content.cpp15
-rw-r--r--core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp65
-rw-r--r--core/src/fpdfapi/fpdf_font/fpdf_font.cpp32
-rw-r--r--core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp7
-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
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_document.cpp5
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp71
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp83
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp2
-rw-r--r--core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp5
-rw-r--r--core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp36
-rw-r--r--core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp161
-rw-r--r--core/src/fpdfapi/fpdf_render/render_int.h2
19 files changed, 265 insertions, 320 deletions
diff --git a/core/src/fpdfapi/fpdf_edit/fpdf_edit_content.cpp b/core/src/fpdfapi/fpdf_edit/fpdf_edit_content.cpp
index 32802d0001..383284e6f9 100644
--- a/core/src/fpdfapi/fpdf_edit/fpdf_edit_content.cpp
+++ b/core/src/fpdfapi/fpdf_edit/fpdf_edit_content.cpp
@@ -131,12 +131,13 @@ void CPDF_PageContentGenerate::TransformContent(CFX_Matrix& matrix) {
int i = 0;
for (i = 0; i < iCount; ++i) {
pContent = pArray->GetElement(i);
- if (!pContent || pContent->GetType() != PDFOBJ_STREAM) {
+ CPDF_Stream* pStream = ToStream(pContent);
+ if (!pStream)
continue;
- }
- CPDF_StreamAcc* pStream = new CPDF_StreamAcc();
- pStream->LoadAllData((CPDF_Stream*)pContent);
- pContentArray[i] = pStream;
+
+ CPDF_StreamAcc* pStreamAcc = new CPDF_StreamAcc();
+ pStreamAcc->LoadAllData(pStream);
+ pContentArray[i] = pStreamAcc;
size += pContentArray[i]->GetSize() + 1;
}
int pos = 0;
@@ -151,9 +152,9 @@ void CPDF_PageContentGenerate::TransformContent(CFX_Matrix& matrix) {
ProcessForm(buf, pBuf, size, matrix);
FX_Free(pBuf);
FX_Free(pContentArray);
- } else if (pContent->GetType() == PDFOBJ_STREAM) {
+ } else if (CPDF_Stream* pStream = pContent->AsStream()) {
CPDF_StreamAcc contentStream;
- contentStream.LoadAllData((CPDF_Stream*)pContent);
+ contentStream.LoadAllData(pStream);
ProcessForm(buf, contentStream.GetData(), contentStream.GetSize(), matrix);
}
CPDF_Stream* pStream = new CPDF_Stream(NULL, 0, NULL);
diff --git a/core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp b/core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp
index d6522158f1..16124a3c38 100644
--- a/core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp
+++ b/core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp
@@ -146,7 +146,7 @@ int32_t PDF_CreatorAppendObject(const CPDF_Object* pObj,
break;
}
case PDFOBJ_STREAM: {
- CPDF_Stream* p = (CPDF_Stream*)pObj;
+ const CPDF_Stream* p = pObj->AsStream();
if (PDF_CreatorAppendObject(p->GetDict(), pFile, offset) < 0) {
return -1;
}
@@ -929,9 +929,9 @@ static FX_BOOL _IsXRefNeedEnd(CPDF_XRefStream* pXRef, FX_DWORD flag) {
return (iCount >= PDF_XREFSTREAM_MAXSIZE);
}
int32_t CPDF_Creator::WriteIndirectObjectToStream(const CPDF_Object* pObj) {
- if (!m_pXRefStream) {
+ if (!m_pXRefStream)
return 1;
- }
+
FX_DWORD objnum = pObj->GetObjNum();
if (m_pParser && m_pParser->m_ObjVersion.GetSize() > (int32_t)objnum &&
m_pParser->m_ObjVersion[objnum] > 0) {
@@ -942,36 +942,29 @@ int32_t CPDF_Creator::WriteIndirectObjectToStream(const CPDF_Object* pObj) {
return 1;
CPDF_Dictionary* pDict = pObj->GetDict();
- if (pObj->GetType() == PDFOBJ_STREAM) {
- if (pDict && pDict->GetString(FX_BSTRC("Type")) == FX_BSTRC("XRef")) {
+ if (pObj->IsStream())
+ if (pDict && pDict->GetString(FX_BSTRC("Type")) == FX_BSTRC("XRef"))
return 0;
- }
return 1;
- }
+
if (pDict) {
- if (pDict == m_pDocument->m_pRootDict || pDict == m_pEncryptDict) {
+ if (pDict == m_pDocument->m_pRootDict || pDict == m_pEncryptDict)
return 1;
- }
- if (IsSignatureDict(pDict)) {
+ if (IsSignatureDict(pDict))
return 1;
- }
- if (pDict->GetString(FX_BSTRC("Type")) == FX_BSTRC("Page")) {
+ if (pDict->GetString(FX_BSTRC("Type")) == FX_BSTRC("Page"))
return 1;
- }
}
+
m_pXRefStream->AddObjectNumberToIndexArray(objnum);
- if (m_pXRefStream->CompressIndirectObject(objnum, pObj, this) < 0) {
+ if (m_pXRefStream->CompressIndirectObject(objnum, pObj, this) < 0)
return -1;
- }
- if (!_IsXRefNeedEnd(m_pXRefStream, m_dwFlags)) {
+ if (!_IsXRefNeedEnd(m_pXRefStream, m_dwFlags))
return 0;
- }
- if (!m_pXRefStream->End(this)) {
+ if (!m_pXRefStream->End(this))
return -1;
- }
- if (!m_pXRefStream->Start()) {
+ if (!m_pXRefStream->Start())
return -1;
- }
return 0;
}
int32_t CPDF_Creator::WriteIndirectObjectToStream(FX_DWORD objnum,
@@ -1017,7 +1010,7 @@ int32_t CPDF_Creator::WriteStream(const CPDF_Object* pStream,
FX_DWORD objnum,
CPDF_CryptoHandler* pCrypto) {
CPDF_FlateEncoder encoder;
- encoder.Initialize((CPDF_Stream*)pStream,
+ encoder.Initialize(const_cast<CPDF_Stream*>(pStream->AsStream()),
pStream == m_pMetadata ? FALSE : m_bCompress);
CPDF_Encryptor encryptor;
if (!encryptor.Initialize(pCrypto, objnum, encoder.m_pData,
@@ -1050,33 +1043,30 @@ int32_t CPDF_Creator::WriteStream(const CPDF_Object* pStream,
int32_t CPDF_Creator::WriteIndirectObj(FX_DWORD objnum,
const CPDF_Object* pObj) {
int32_t len = m_File.AppendDWord(objnum);
- if (len < 0) {
+ if (len < 0)
return -1;
- }
+
m_Offset += len;
- if ((len = m_File.AppendString(FX_BSTRC(" 0 obj\r\n"))) < 0) {
+ if ((len = m_File.AppendString(FX_BSTRC(" 0 obj\r\n"))) < 0)
return -1;
- }
+
m_Offset += len;
- if (pObj->GetType() == PDFOBJ_STREAM) {
- CPDF_CryptoHandler* pHandler = NULL;
+ if (pObj->IsStream()) {
+ CPDF_CryptoHandler* pHandler = nullptr;
pHandler =
(pObj == m_pMetadata && !m_bEncryptMetadata) ? NULL : m_pCryptoHandler;
- if (WriteStream(pObj, objnum, pHandler) < 0) {
+ if (WriteStream(pObj, objnum, pHandler) < 0)
return -1;
- }
} else {
- if (WriteDirectObj(objnum, pObj) < 0) {
+ if (WriteDirectObj(objnum, pObj) < 0)
return -1;
- }
}
- if ((len = m_File.AppendString(FX_BSTRC("\r\nendobj\r\n"))) < 0) {
+ if ((len = m_File.AppendString(FX_BSTRC("\r\nendobj\r\n"))) < 0)
return -1;
- }
+
m_Offset += len;
- if (AppendObjectNumberToXRef(objnum) < 0) {
+ if (AppendObjectNumberToXRef(objnum) < 0)
return -1;
- }
return 0;
}
int32_t CPDF_Creator::WriteIndirectObj(const CPDF_Object* pObj) {
@@ -1139,7 +1129,8 @@ int32_t CPDF_Creator::WriteDirectObj(FX_DWORD objnum,
}
case PDFOBJ_STREAM: {
CPDF_FlateEncoder encoder;
- encoder.Initialize((CPDF_Stream*)pObj, m_bCompress);
+ encoder.Initialize(const_cast<CPDF_Stream*>(pObj->AsStream()),
+ m_bCompress);
CPDF_Encryptor encryptor;
CPDF_CryptoHandler* pHandler = m_pCryptoHandler;
encryptor.Initialize(pHandler, objnum, encoder.m_pData, encoder.m_dwSize);
diff --git a/core/src/fpdfapi/fpdf_font/fpdf_font.cpp b/core/src/fpdfapi/fpdf_font/fpdf_font.cpp
index 9954efcc5d..543816b03a 100644
--- a/core/src/fpdfapi/fpdf_font/fpdf_font.cpp
+++ b/core/src/fpdfapi/fpdf_font/fpdf_font.cpp
@@ -119,7 +119,7 @@ CPDF_Font::~CPDF_Font() {
if (m_pFontFile) {
m_pDocument->GetPageData()->ReleaseFontFileStreamAcc(
- (CPDF_Stream*)m_pFontFile->GetStream());
+ const_cast<CPDF_Stream*>(m_pFontFile->GetStream()->AsStream()));
}
}
FX_BOOL CPDF_Font::IsVertWriting() const {
@@ -275,7 +275,7 @@ void CPDF_Font::LoadFontDescriptor(CPDF_Dictionary* pFontDesc) {
FX_DWORD dwFontSize = m_pFontFile->GetSize();
if (!m_Font.LoadEmbedded(pFontData, dwFontSize)) {
m_pDocument->GetPageData()->ReleaseFontFileStreamAcc(
- (CPDF_Stream*)m_pFontFile->GetStream());
+ const_cast<CPDF_Stream*>(m_pFontFile->GetStream()->AsStream()));
m_pFontFile = nullptr;
}
}
@@ -1709,10 +1709,10 @@ void CPDF_Type3Font::CheckType3FontMetrics() {
CheckFontMetrics();
}
CPDF_Type3Char* CPDF_Type3Font::LoadChar(FX_DWORD charcode, int level) {
- if (level >= _FPDF_MAX_TYPE3_FORM_LEVEL_) {
- return NULL;
- }
- CPDF_Type3Char* pChar = NULL;
+ if (level >= _FPDF_MAX_TYPE3_FORM_LEVEL_)
+ return nullptr;
+
+ CPDF_Type3Char* pChar = nullptr;
if (m_CacheMap.Lookup((void*)(uintptr_t)charcode, (void*&)pChar)) {
if (pChar->m_bPageRequired && m_pPageResources) {
delete pChar;
@@ -1723,19 +1723,19 @@ CPDF_Type3Char* CPDF_Type3Font::LoadChar(FX_DWORD charcode, int level) {
}
const FX_CHAR* name =
GetAdobeCharName(m_BaseEncoding, m_pCharNames, charcode);
- if (name == NULL) {
- return NULL;
- }
+ if (!name)
+ return nullptr;
+
CPDF_Stream* pStream =
- (CPDF_Stream*)(m_pCharProcs ? m_pCharProcs->GetElementValue(name) : NULL);
- if (pStream == NULL || pStream->GetType() != PDFOBJ_STREAM) {
- return NULL;
- }
+ ToStream(m_pCharProcs ? m_pCharProcs->GetElementValue(name) : nullptr);
+ if (!pStream)
+ return nullptr;
+
pChar = new CPDF_Type3Char;
pChar->m_pForm = new CPDF_Form(
m_pDocument, m_pFontResources ? m_pFontResources : m_pPageResources,
- pStream, NULL);
- pChar->m_pForm->ParseContent(NULL, NULL, pChar, NULL, level + 1);
+ pStream, nullptr);
+ pChar->m_pForm->ParseContent(nullptr, nullptr, pChar, nullptr, level + 1);
FX_FLOAT scale = m_FontMatrix.GetXUnit();
pChar->m_Width = (int32_t)(pChar->m_Width * scale + 0.5f);
FX_RECT& rcBBox = pChar->m_BBox;
@@ -1753,7 +1753,7 @@ CPDF_Type3Char* CPDF_Type3Font::LoadChar(FX_DWORD charcode, int level) {
m_CacheMap.SetAt((void*)(uintptr_t)charcode, pChar);
if (pChar->m_pForm->CountObjects() == 0) {
delete pChar->m_pForm;
- pChar->m_pForm = NULL;
+ pChar->m_pForm = nullptr;
}
return pChar;
}
diff --git a/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp b/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp
index 8972201b66..02f0933f36 100644
--- a/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp
+++ b/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp
@@ -1215,9 +1215,8 @@ FX_BOOL CPDF_CIDFont::_Load() {
->GetPageModule()
->GetFontGlobals()
->m_CMapManager.GetPredefinedCMap(cmap, m_pFontFile && m_bType1);
- } else if (pEncoding->GetType() == PDFOBJ_STREAM) {
+ } else if (CPDF_Stream* pStream = pEncoding->AsStream()) {
m_pAllocatedCMap = m_pCMap = new CPDF_CMap;
- CPDF_Stream* pStream = (CPDF_Stream*)pEncoding;
CPDF_StreamAcc acc;
acc.LoadAllData(pStream, FALSE);
m_pCMap->LoadEmbedded(acc.GetData(), acc.GetSize());
@@ -1265,9 +1264,9 @@ FX_BOOL CPDF_CIDFont::_Load() {
CPDF_Object* pmap =
pCIDFontDict->GetElementValue(FX_BSTRC("CIDToGIDMap"));
if (pmap) {
- if (pmap->GetType() == PDFOBJ_STREAM) {
+ if (CPDF_Stream* pStream = pmap->AsStream()) {
m_pCIDToGIDMap = new CPDF_StreamAcc;
- m_pCIDToGIDMap->LoadAllData((CPDF_Stream*)pmap, FALSE);
+ m_pCIDToGIDMap->LoadAllData(pStream, FALSE);
} else if (pmap->GetString() == FX_BSTRC("Identity")) {
#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
if (m_pFontFile) {
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..a24da0adc1 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->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;
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_document.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_document.cpp
index 2396261276..5333fe8087 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_document.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_document.cpp
@@ -338,8 +338,9 @@ FX_BOOL CPDF_Document::IsFormStream(FX_DWORD objnum, FX_BOOL& bForm) const {
{
CPDF_Object* pObj;
if (m_IndirectObjs.Lookup((void*)(uintptr_t)objnum, (void*&)pObj)) {
- bForm = pObj->GetType() == PDFOBJ_STREAM &&
- ((CPDF_Stream*)pObj)->GetDict()->GetString(FX_BSTRC("Subtype")) ==
+ CPDF_Stream* pStream = pObj->AsStream();
+ bForm = pStream &&
+ pStream->GetDict()->GetString(FX_BSTRC("Subtype")) ==
FX_BSTRC("Form");
return TRUE;
}
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp
index 6a090ce64d..fc473319fc 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp
@@ -31,7 +31,7 @@ void CPDF_Object::Destroy() {
delete AsDictionary();
break;
case PDFOBJ_STREAM:
- delete (CPDF_Stream*)this;
+ delete AsStream();
break;
default:
delete this;
@@ -144,7 +144,7 @@ CPDF_Dictionary* CPDF_Object::GetDict() const {
// See bug #234.
return const_cast<CPDF_Dictionary*>(AsDictionary());
case PDFOBJ_STREAM:
- return ((CPDF_Stream*)this)->GetDict();
+ return AsStream()->GetDict();
case PDFOBJ_REFERENCE: {
CPDF_Reference* pRef = (CPDF_Reference*)this;
CPDF_IndirectObjects* pIndirect = pRef->GetObjList();
@@ -222,7 +222,7 @@ FX_BOOL CPDF_Object::IsIdentical(CPDF_Object* pOther) const {
case PDFOBJ_NULL:
return TRUE;
case PDFOBJ_STREAM:
- return (((CPDF_Stream*)this)->Identical((CPDF_Stream*)pOther));
+ return AsStream()->Identical(pOther->AsStream());
case PDFOBJ_REFERENCE:
return (((CPDF_Reference*)this)->Identical((CPDF_Reference*)pOther));
}
@@ -284,7 +284,7 @@ CPDF_Object* CPDF_Object::CloneInternal(FX_BOOL bDirect,
return new CPDF_Null;
}
case PDFOBJ_STREAM: {
- CPDF_Stream* pThis = (CPDF_Stream*)this;
+ const CPDF_Stream* pThis = AsStream();
CPDF_StreamAcc acc;
acc.LoadAllData(pThis, TRUE);
FX_DWORD streamSize = acc.GetSize();
@@ -319,9 +319,9 @@ CFX_WideString CPDF_Object::GetUnicodeText(CFX_CharMap* pCharMap) const {
if (const CPDF_String* pString = AsString())
return PDF_DecodeText(pString->m_String, pCharMap);
- if (m_Type == PDFOBJ_STREAM) {
+ if (const CPDF_Stream* pStream = AsStream()) {
CPDF_StreamAcc stream;
- stream.LoadAllData((CPDF_Stream*)this, FALSE);
+ stream.LoadAllData(pStream, FALSE);
CFX_WideString result =
PDF_DecodeText(stream.GetData(), stream.GetSize(), pCharMap);
return result;
@@ -333,10 +333,10 @@ CFX_WideString CPDF_Object::GetUnicodeText(CFX_CharMap* pCharMap) const {
void CPDF_Object::SetUnicodeText(const FX_WCHAR* pUnicodes, int len) {
if (CPDF_String* pString = AsString()) {
pString->m_String = PDF_EncodeText(pUnicodes, len);
- } else if (m_Type == PDFOBJ_STREAM) {
+ } else if (CPDF_Stream* pStream = AsStream()) {
CFX_ByteString result = PDF_EncodeText(pUnicodes, len);
- ((CPDF_Stream*)this)
- ->SetData((uint8_t*)result.c_str(), result.GetLength(), FALSE, FALSE);
+ pStream->SetData((uint8_t*)result.c_str(), result.GetLength(), FALSE,
+ FALSE);
}
}
@@ -380,6 +380,14 @@ const CPDF_Number* CPDF_Object::AsNumber() const {
return IsNumber() ? static_cast<const CPDF_Number*>(this) : nullptr;
}
+CPDF_Stream* CPDF_Object::AsStream() {
+ return IsStream() ? static_cast<CPDF_Stream*>(this) : nullptr;
+}
+
+const CPDF_Stream* CPDF_Object::AsStream() const {
+ return IsStream() ? static_cast<const CPDF_Stream*>(this) : nullptr;
+}
+
CPDF_String* CPDF_Object::AsString() {
return IsString() ? static_cast<CPDF_String*>(this) : nullptr;
}
@@ -487,23 +495,16 @@ FX_FLOAT CPDF_Array::GetNumber(FX_DWORD i) const {
}
CPDF_Dictionary* CPDF_Array::GetDict(FX_DWORD i) const {
CPDF_Object* p = GetElementValue(i);
- if (!p) {
+ if (!p)
return NULL;
- }
- if (CPDF_Dictionary* pDict = p->AsDictionary()) {
+ if (CPDF_Dictionary* pDict = p->AsDictionary())
return pDict;
- }
- if (p->GetType() == PDFOBJ_STREAM) {
- return ((CPDF_Stream*)p)->GetDict();
- }
+ if (CPDF_Stream* pStream = p->AsStream())
+ return pStream->GetDict();
return NULL;
}
CPDF_Stream* CPDF_Array::GetStream(FX_DWORD i) const {
- CPDF_Object* p = GetElementValue(i);
- if (p == NULL || p->GetType() != PDFOBJ_STREAM) {
- return NULL;
- }
- return (CPDF_Stream*)p;
+ return ToStream(GetElementValue(i));
}
CPDF_Array* CPDF_Array::GetArray(FX_DWORD i) const {
return ToArray(GetElementValue(i));
@@ -703,26 +704,19 @@ FX_BOOL CPDF_Dictionary::GetBoolean(const CFX_ByteStringC& key,
}
CPDF_Dictionary* CPDF_Dictionary::GetDict(const CFX_ByteStringC& key) const {
CPDF_Object* p = GetElementValue(key);
- if (!p) {
+ if (!p)
return nullptr;
- }
- if (CPDF_Dictionary* pDict = p->AsDictionary()) {
+ if (CPDF_Dictionary* pDict = p->AsDictionary())
return pDict;
- }
- if (p->GetType() == PDFOBJ_STREAM) {
- return ((CPDF_Stream*)p)->GetDict();
- }
+ if (CPDF_Stream* pStream = p->AsStream())
+ return pStream->GetDict();
return nullptr;
}
CPDF_Array* CPDF_Dictionary::GetArray(const CFX_ByteStringC& key) const {
return ToArray(GetElementValue(key));
}
CPDF_Stream* CPDF_Dictionary::GetStream(const CFX_ByteStringC& key) const {
- CPDF_Object* p = GetElementValue(key);
- if (p == NULL || p->GetType() != PDFOBJ_STREAM) {
- return NULL;
- }
- return (CPDF_Stream*)p;
+ return ToStream(GetElementValue(key));
}
CFX_FloatRect CPDF_Dictionary::GetRect(const CFX_ByteStringC& key) const {
CFX_FloatRect rect;
@@ -1035,9 +1029,9 @@ void CPDF_StreamAcc::LoadAllData(const CPDF_Stream* pStream,
FX_BOOL bRawAccess,
FX_DWORD estimated_size,
FX_BOOL bImageAcc) {
- if (pStream == NULL || pStream->GetType() != PDFOBJ_STREAM) {
+ if (!pStream)
return;
- }
+
m_pStream = pStream;
if (pStream->IsMemoryBased() &&
(!pStream->GetDict()->KeyExist(FX_BSTRC("Filter")) || bRawAccess)) {
@@ -1047,14 +1041,13 @@ void CPDF_StreamAcc::LoadAllData(const CPDF_Stream* pStream,
}
uint8_t* pSrcData;
FX_DWORD dwSrcSize = pStream->m_dwSize;
- if (dwSrcSize == 0) {
+ if (dwSrcSize == 0)
return;
- }
+
if (!pStream->IsMemoryBased()) {
pSrcData = m_pSrcData = FX_Alloc(uint8_t, dwSrcSize);
- if (!pStream->ReadRawData(0, pSrcData, dwSrcSize)) {
+ if (!pStream->ReadRawData(0, pSrcData, dwSrcSize))
return;
- }
} else {
pSrcData = pStream->m_pDataBuf;
}
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
index 8b822a8b9c..12e2a3946c 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
@@ -784,29 +784,20 @@ FX_BOOL CPDF_Parser::RebuildCrossRef() {
FX_FILESIZE obj_end = 0;
CPDF_Object* pObject = ParseIndirectObjectAtByStrict(
m_pDocument, obj_pos, objnum, NULL, &obj_end);
- if (pObject) {
- int iType = pObject->GetType();
- if (iType == PDFOBJ_STREAM) {
- CPDF_Stream* pStream = (CPDF_Stream*)pObject;
- CPDF_Dictionary* pDict = pStream->GetDict();
- if (pDict) {
- if (pDict->KeyExist(FX_BSTRC("Type"))) {
- CFX_ByteString bsValue =
- pDict->GetString(FX_BSTRC("Type"));
- if (bsValue == FX_BSTRC("XRef") &&
- pDict->KeyExist(FX_BSTRC("Size"))) {
- CPDF_Object* pRoot =
- pDict->GetElement(FX_BSTRC("Root"));
- if (pRoot && pRoot->GetDict() &&
- pRoot->GetDict()->GetElement(FX_BSTRC("Pages"))) {
- if (m_pTrailer) {
- m_pTrailer->Release();
- }
- m_pTrailer = ToDictionary(pDict->Clone());
- }
+ if (CPDF_Stream* pStream = ToStream(pObject)) {
+ if (CPDF_Dictionary* pDict = pStream->GetDict()) {
+ if ((pDict->KeyExist(FX_BSTRC("Type"))) &&
+ (pDict->GetString(FX_BSTRC("Type")) ==
+ FX_BSTRC("XRef") &&
+ pDict->KeyExist(FX_BSTRC("Size")))) {
+ CPDF_Object* pRoot = pDict->GetElement(FX_BSTRC("Root"));
+ if (pRoot && pRoot->GetDict() &&
+ pRoot->GetDict()->GetElement(FX_BSTRC("Pages"))) {
+ if (m_pTrailer)
+ m_pTrailer->Release();
+ m_pTrailer = ToDictionary(pDict->Clone());
}
}
- }
}
}
FX_FILESIZE offset = 0;
@@ -855,16 +846,12 @@ 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->IsDictionary() && !pObj->AsStream()) {
pObj->Release();
} else {
- CPDF_Dictionary* pTrailer = NULL;
- if (pObj->GetType() == PDFOBJ_STREAM) {
- pTrailer = ((CPDF_Stream*)pObj)->GetDict();
- } else {
- pTrailer = pObj->AsDictionary();
- }
- if (pTrailer) {
+ CPDF_Stream* pStream = pObj->AsStream();
+ if (CPDF_Dictionary* pTrailer =
+ pStream ? pStream->GetDict() : pObj->AsDictionary()) {
if (m_pTrailer) {
CPDF_Object* pRoot =
pTrailer->GetElement(FX_BSTRC("Root"));
@@ -886,7 +873,7 @@ FX_BOOL CPDF_Parser::RebuildCrossRef() {
pObj->Release();
}
} else {
- if (pObj->GetType() == PDFOBJ_STREAM) {
+ if (pObj->IsStream()) {
m_pTrailer = ToDictionary(pTrailer->Clone());
pObj->Release();
} else {
@@ -1005,25 +992,25 @@ FX_BOOL CPDF_Parser::RebuildCrossRef() {
FX_BOOL CPDF_Parser::LoadCrossRefV5(FX_FILESIZE pos,
FX_FILESIZE& prev,
FX_BOOL bMainXRef) {
- CPDF_Stream* pStream =
- (CPDF_Stream*)ParseIndirectObjectAt(m_pDocument, pos, 0, NULL);
- if (!pStream) {
+ CPDF_Object* pObject = ParseIndirectObjectAt(m_pDocument, pos, 0, nullptr);
+ if (!pObject)
return FALSE;
- }
+
if (m_pDocument) {
CPDF_Dictionary* pDict = m_pDocument->GetRoot();
- if (!pDict || pDict->GetObjNum() != pStream->m_ObjNum) {
- m_pDocument->InsertIndirectObject(pStream->m_ObjNum, pStream);
+ if (!pDict || pDict->GetObjNum() != pObject->m_ObjNum) {
+ m_pDocument->InsertIndirectObject(pObject->m_ObjNum, pObject);
} else {
- if (pStream->GetType() == PDFOBJ_STREAM) {
- pStream->Release();
- }
+ if (pObject->IsStream())
+ pObject->Release();
return FALSE;
}
}
- if (pStream->GetType() != PDFOBJ_STREAM) {
+
+ CPDF_Stream* pStream = pObject->AsStream();
+ if (!pStream)
return FALSE;
- }
+
prev = pStream->GetDict()->GetInteger(FX_BSTRC("Prev"));
int32_t size = pStream->GetDict()->GetInteger(FX_BSTRC("Size"));
if (size < 0) {
@@ -1245,15 +1232,15 @@ CPDF_Object* CPDF_Parser::ParseIndirectObject(CPDF_IndirectObjects* pObjList,
}
CPDF_StreamAcc* CPDF_Parser::GetObjectStream(FX_DWORD objnum) {
- CPDF_StreamAcc* pStreamAcc = NULL;
- if (m_ObjectStreamMap.Lookup((void*)(uintptr_t)objnum, (void*&)pStreamAcc)) {
+ CPDF_StreamAcc* pStreamAcc = nullptr;
+ if (m_ObjectStreamMap.Lookup((void*)(uintptr_t)objnum, (void*&)pStreamAcc))
return pStreamAcc;
- }
+
const CPDF_Stream* pStream =
- m_pDocument ? (CPDF_Stream*)m_pDocument->GetIndirectObject(objnum) : NULL;
- if (pStream == NULL || pStream->GetType() != PDFOBJ_STREAM) {
- return NULL;
- }
+ ToStream(m_pDocument ? m_pDocument->GetIndirectObject(objnum) : nullptr);
+ if (!pStream)
+ return nullptr;
+
pStreamAcc = new CPDF_StreamAcc;
pStreamAcc->LoadAllData(pStream);
m_ObjectStreamMap.SetAt((void*)(uintptr_t)objnum, pStreamAcc);
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp
index a2d65fa4bd..606bd0f569 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp
@@ -417,7 +417,7 @@ CFX_ByteTextBuf& operator<<(CFX_ByteTextBuf& buf, const CPDF_Object* pObj) {
break;
}
case PDFOBJ_STREAM: {
- CPDF_Stream* p = (CPDF_Stream*)pObj;
+ const CPDF_Stream* p = pObj->AsStream();
buf << p->GetDict() << FX_BSTRC("stream\r\n");
CPDF_StreamAcc acc;
acc.LoadAllData(p, TRUE);
diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp
index 2754223f3e..0acaeba14c 100644
--- a/core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp
+++ b/core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp
@@ -1055,10 +1055,9 @@ 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->IsDictionary() || pFuncObj->IsStream()))
pFunc = CPDF_Function::Load(pFuncObj);
- }
+
CFX_AffineMatrix matrix = *pMatrix;
matrix.TranslateI(-pClipRect->left, -pClipRect->top);
CPDF_Form form(m_pContext->m_pDocument, m_pContext->m_pPageResources, pGroup);
diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp
index fecd6da9b2..6af3ab4ce6 100644
--- a/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp
+++ b/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp
@@ -765,7 +765,7 @@ CPDF_DIBSource* CPDF_DIBSource::LoadMask(FX_DWORD& MatteColor) {
CPDF_Stream* pSoftMask = m_pDict->GetStream(FX_BSTRC("SMask"));
if (pSoftMask) {
CPDF_Array* pMatte = pSoftMask->GetDict()->GetArray(FX_BSTRC("Matte"));
- if (pMatte != NULL && m_pColorSpace &&
+ if (pMatte && m_pColorSpace &&
(FX_DWORD)m_pColorSpace->CountComponents() <= m_nComponents) {
FX_FLOAT* pColor = FX_Alloc(FX_FLOAT, m_nComponents);
for (FX_DWORD i = 0; i < m_nComponents; i++) {
@@ -779,14 +779,12 @@ CPDF_DIBSource* CPDF_DIBSource::LoadMask(FX_DWORD& MatteColor) {
}
return LoadMaskDIB(pSoftMask);
}
- CPDF_Object* pMask = m_pDict->GetElementValue(FX_BSTRC("Mask"));
- if (pMask == NULL) {
- return NULL;
- }
- if (pMask->GetType() == PDFOBJ_STREAM) {
- return LoadMaskDIB((CPDF_Stream*)pMask);
- }
- return NULL;
+
+ if (CPDF_Stream* pStream =
+ ToStream(m_pDict->GetElementValue(FX_BSTRC("Mask"))))
+ return LoadMaskDIB(pStream);
+
+ return nullptr;
}
int CPDF_DIBSource::StratLoadMask() {
m_MatteColor = 0XFFFFFFFF;
@@ -807,14 +805,9 @@ int CPDF_DIBSource::StratLoadMask() {
}
return StartLoadMaskDIB();
}
- m_pMaskStream = m_pDict->GetElementValue(FX_BSTRC("Mask"));
- if (m_pMaskStream == NULL) {
- return 1;
- }
- if (m_pMaskStream->GetType() == PDFOBJ_STREAM) {
- return StartLoadMaskDIB();
- }
- return 1;
+
+ m_pMaskStream = ToStream(m_pDict->GetElementValue(FX_BSTRC("Mask")));
+ return m_pMaskStream ? StartLoadMaskDIB() : 1;
}
int CPDF_DIBSource::ContinueLoadMaskDIB(IFX_Pause* pPause) {
if (m_pMask == NULL) {
@@ -849,17 +842,16 @@ CPDF_DIBSource* CPDF_DIBSource::LoadMaskDIB(CPDF_Stream* pMask) {
}
int CPDF_DIBSource::StartLoadMaskDIB() {
m_pMask = new CPDF_DIBSource;
- int ret = m_pMask->StartLoadDIBSource(
- m_pDocument, (CPDF_Stream*)m_pMaskStream, FALSE, NULL, NULL, TRUE);
+ int ret = m_pMask->StartLoadDIBSource(m_pDocument, m_pMaskStream, FALSE,
+ nullptr, nullptr, TRUE);
if (ret == 2) {
- if (m_Status == 0) {
+ if (m_Status == 0)
m_Status = 2;
- }
return 2;
}
if (!ret) {
delete m_pMask;
- m_pMask = NULL;
+ m_pMask = nullptr;
return 1;
}
return 1;
diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp
index b64002c13e..4ed6c07675 100644
--- a/core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp
+++ b/core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp
@@ -10,13 +10,13 @@
#include "../fpdf_page/pageint.h"
#include "render_int.h"
#define SHADING_STEPS 256
-static void _DrawAxialShading(CFX_DIBitmap* pBitmap,
- CFX_AffineMatrix* pObject2Bitmap,
- CPDF_Dictionary* pDict,
- CPDF_Function** pFuncs,
- int nFuncs,
- CPDF_ColorSpace* pCS,
- int alpha) {
+static void DrawAxialShading(CFX_DIBitmap* pBitmap,
+ CFX_AffineMatrix* pObject2Bitmap,
+ CPDF_Dictionary* pDict,
+ CPDF_Function** pFuncs,
+ int nFuncs,
+ CPDF_ColorSpace* pCS,
+ int alpha) {
ASSERT(pBitmap->GetFormat() == FXDIB_Argb);
CPDF_Array* pCoords = pDict->GetArray(FX_BSTRC("Coords"));
if (pCoords == NULL) {
@@ -101,13 +101,13 @@ static void _DrawAxialShading(CFX_DIBitmap* pBitmap,
}
}
}
-static void _DrawRadialShading(CFX_DIBitmap* pBitmap,
- CFX_AffineMatrix* pObject2Bitmap,
- CPDF_Dictionary* pDict,
- CPDF_Function** pFuncs,
- int nFuncs,
- CPDF_ColorSpace* pCS,
- int alpha) {
+static void DrawRadialShading(CFX_DIBitmap* pBitmap,
+ CFX_AffineMatrix* pObject2Bitmap,
+ CPDF_Dictionary* pDict,
+ CPDF_Function** pFuncs,
+ int nFuncs,
+ CPDF_ColorSpace* pCS,
+ int alpha) {
ASSERT(pBitmap->GetFormat() == FXDIB_Argb);
CPDF_Array* pCoords = pDict->GetArray(FX_BSTRC("Coords"));
if (pCoords == NULL) {
@@ -239,13 +239,13 @@ static void _DrawRadialShading(CFX_DIBitmap* pBitmap,
}
}
}
-static void _DrawFuncShading(CFX_DIBitmap* pBitmap,
- CFX_AffineMatrix* pObject2Bitmap,
- CPDF_Dictionary* pDict,
- CPDF_Function** pFuncs,
- int nFuncs,
- CPDF_ColorSpace* pCS,
- int alpha) {
+static void DrawFuncShading(CFX_DIBitmap* pBitmap,
+ CFX_AffineMatrix* pObject2Bitmap,
+ CPDF_Dictionary* pDict,
+ CPDF_Function** pFuncs,
+ int nFuncs,
+ CPDF_ColorSpace* pCS,
+ int alpha) {
ASSERT(pBitmap->GetFormat() == FXDIB_Argb);
CPDF_Array* pDomain = pDict->GetArray(FX_BSTRC("Domain"));
FX_FLOAT xmin = 0, ymin = 0, xmax = 1.0f, ymax = 1.0f;
@@ -323,9 +323,9 @@ FX_BOOL _GetScanlineIntersect(int y,
x = x1 + FXSYS_MulDiv(x2 - x1, y - y1, y2 - y1);
return TRUE;
}
-static void _DrawGouraud(CFX_DIBitmap* pBitmap,
- int alpha,
- CPDF_MeshVertex triangle[3]) {
+static void DrawGouraud(CFX_DIBitmap* pBitmap,
+ int alpha,
+ CPDF_MeshVertex triangle[3]) {
FX_FLOAT min_y = triangle[0].y, max_y = triangle[0].y;
for (int i = 1; i < 3; i++) {
if (min_y > triangle[i].y) {
@@ -408,21 +408,19 @@ static void _DrawGouraud(CFX_DIBitmap* pBitmap,
}
}
}
-static void _DrawFreeGouraudShading(CFX_DIBitmap* pBitmap,
- CFX_AffineMatrix* pObject2Bitmap,
- CPDF_Stream* pShadingStream,
- CPDF_Function** pFuncs,
- int nFuncs,
- CPDF_ColorSpace* pCS,
- int alpha) {
+static void DrawFreeGouraudShading(CFX_DIBitmap* pBitmap,
+ CFX_AffineMatrix* pObject2Bitmap,
+ CPDF_Stream* pShadingStream,
+ CPDF_Function** pFuncs,
+ int nFuncs,
+ CPDF_ColorSpace* pCS,
+ int alpha) {
ASSERT(pBitmap->GetFormat() == FXDIB_Argb);
- if (pShadingStream->GetType() != PDFOBJ_STREAM) {
- return;
- }
+
CPDF_MeshStream stream;
- if (!stream.Load(pShadingStream, pFuncs, nFuncs, pCS)) {
+ if (!stream.Load(pShadingStream, pFuncs, nFuncs, pCS))
return;
- }
+
CPDF_MeshVertex triangle[3];
FXSYS_memset(triangle, 0, sizeof(triangle));
@@ -441,28 +439,26 @@ static void _DrawFreeGouraudShading(CFX_DIBitmap* pBitmap,
triangle[1] = triangle[2];
triangle[2] = vertex;
}
- _DrawGouraud(pBitmap, alpha, triangle);
+ DrawGouraud(pBitmap, alpha, triangle);
}
}
-static void _DrawLatticeGouraudShading(CFX_DIBitmap* pBitmap,
- CFX_AffineMatrix* pObject2Bitmap,
- CPDF_Stream* pShadingStream,
- CPDF_Function** pFuncs,
- int nFuncs,
- CPDF_ColorSpace* pCS,
- int alpha) {
+static void DrawLatticeGouraudShading(CFX_DIBitmap* pBitmap,
+ CFX_AffineMatrix* pObject2Bitmap,
+ CPDF_Stream* pShadingStream,
+ CPDF_Function** pFuncs,
+ int nFuncs,
+ CPDF_ColorSpace* pCS,
+ int alpha) {
ASSERT(pBitmap->GetFormat() == FXDIB_Argb);
- if (pShadingStream->GetType() != PDFOBJ_STREAM) {
- return;
- }
+
int row_verts = pShadingStream->GetDict()->GetInteger("VerticesPerRow");
- if (row_verts < 2) {
+ if (row_verts < 2)
return;
- }
+
CPDF_MeshStream stream;
- if (!stream.Load(pShadingStream, pFuncs, nFuncs, pCS)) {
+ if (!stream.Load(pShadingStream, pFuncs, nFuncs, pCS))
return;
- }
+
CPDF_MeshVertex* vertex = FX_Alloc2D(CPDF_MeshVertex, row_verts, 2);
if (!stream.GetVertexRow(vertex, row_verts, pObject2Bitmap)) {
FX_Free(vertex);
@@ -481,9 +477,9 @@ static void _DrawLatticeGouraudShading(CFX_DIBitmap* pBitmap,
triangle[0] = last_row[i];
triangle[1] = this_row[i - 1];
triangle[2] = last_row[i - 1];
- _DrawGouraud(pBitmap, alpha, triangle);
+ DrawGouraud(pBitmap, alpha, triangle);
triangle[2] = this_row[i];
- _DrawGouraud(pBitmap, alpha, triangle);
+ DrawGouraud(pBitmap, alpha, triangle);
}
last_index = 1 - last_index;
}
@@ -748,29 +744,24 @@ FX_BOOL _CheckCoonTensorPara(const CPDF_MeshStream& stream) {
return bCoorBits && bCompBits && bFlagBits;
}
-static void _DrawCoonPatchMeshes(FX_BOOL bTensor,
- CFX_DIBitmap* pBitmap,
- CFX_AffineMatrix* pObject2Bitmap,
- CPDF_Stream* pShadingStream,
- CPDF_Function** pFuncs,
- int nFuncs,
- CPDF_ColorSpace* pCS,
- int fill_mode,
- int alpha) {
+static void DrawCoonPatchMeshes(FX_BOOL bTensor,
+ CFX_DIBitmap* pBitmap,
+ CFX_AffineMatrix* pObject2Bitmap,
+ CPDF_Stream* pShadingStream,
+ CPDF_Function** pFuncs,
+ int nFuncs,
+ CPDF_ColorSpace* pCS,
+ int fill_mode,
+ int alpha) {
ASSERT(pBitmap->GetFormat() == FXDIB_Argb);
- if (pShadingStream->GetType() != PDFOBJ_STREAM) {
- return;
- }
+
CFX_FxgeDevice device;
device.Attach(pBitmap);
CPDF_MeshStream stream;
- if (!stream.Load(pShadingStream, pFuncs, nFuncs, pCS)) {
+ if (!stream.Load(pShadingStream, pFuncs, nFuncs, pCS))
return;
- }
-
- if (!_CheckCoonTensorPara(stream)) {
+ if (!_CheckCoonTensorPara(stream))
return;
- }
CPDF_PatchDrawer patch;
patch.alpha = alpha;
@@ -878,32 +869,32 @@ void CPDF_RenderStatus::DrawShading(CPDF_ShadingPattern* pPattern,
int fill_mode = m_Options.m_Flags;
switch (pPattern->m_ShadingType) {
case 1:
- _DrawFuncShading(pBitmap, &FinalMatrix, pDict, pFuncs, nFuncs,
- pColorSpace, alpha);
+ DrawFuncShading(pBitmap, &FinalMatrix, pDict, pFuncs, nFuncs, pColorSpace,
+ alpha);
break;
case 2:
- _DrawAxialShading(pBitmap, &FinalMatrix, pDict, pFuncs, nFuncs,
- pColorSpace, alpha);
+ DrawAxialShading(pBitmap, &FinalMatrix, pDict, pFuncs, nFuncs,
+ pColorSpace, alpha);
break;
case 3:
- _DrawRadialShading(pBitmap, &FinalMatrix, pDict, pFuncs, nFuncs,
- pColorSpace, alpha);
+ DrawRadialShading(pBitmap, &FinalMatrix, pDict, pFuncs, nFuncs,
+ pColorSpace, alpha);
break;
case 4: {
- _DrawFreeGouraudShading(pBitmap, &FinalMatrix,
- (CPDF_Stream*)pPattern->m_pShadingObj, pFuncs,
- nFuncs, pColorSpace, alpha);
+ DrawFreeGouraudShading(pBitmap, &FinalMatrix,
+ ToStream(pPattern->m_pShadingObj), pFuncs, nFuncs,
+ pColorSpace, alpha);
} break;
case 5: {
- _DrawLatticeGouraudShading(pBitmap, &FinalMatrix,
- (CPDF_Stream*)pPattern->m_pShadingObj, pFuncs,
- nFuncs, pColorSpace, alpha);
+ DrawLatticeGouraudShading(pBitmap, &FinalMatrix,
+ ToStream(pPattern->m_pShadingObj), pFuncs,
+ nFuncs, pColorSpace, alpha);
} break;
case 6:
case 7: {
- _DrawCoonPatchMeshes(pPattern->m_ShadingType - 6, pBitmap, &FinalMatrix,
- (CPDF_Stream*)pPattern->m_pShadingObj, pFuncs,
- nFuncs, pColorSpace, fill_mode, alpha);
+ DrawCoonPatchMeshes(pPattern->m_ShadingType - 6, pBitmap, &FinalMatrix,
+ ToStream(pPattern->m_pShadingObj), pFuncs, nFuncs,
+ pColorSpace, fill_mode, alpha);
} break;
}
if (bAlphaMode) {
diff --git a/core/src/fpdfapi/fpdf_render/render_int.h b/core/src/fpdfapi/fpdf_render/render_int.h
index 4f86996589..c97cb7105d 100644
--- a/core/src/fpdfapi/fpdf_render/render_int.h
+++ b/core/src/fpdfapi/fpdf_render/render_int.h
@@ -547,7 +547,7 @@ class CPDF_DIBSource : public CFX_DIBSource {
CPDF_StreamAcc* m_pGlobalStream;
FX_BOOL m_bStdCS;
int m_Status;
- CPDF_Object* m_pMaskStream;
+ CPDF_Stream* m_pMaskStream;
FX_BOOL m_bHasMask;
private: