Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(247)

Unified Diff: core/src/fpdfapi/fpdf_page/fpdf_page_func.cpp

Issue 1402413004: Add type cast definitions for CPDF_Stream. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: core/src/fpdfapi/fpdf_page/fpdf_page_func.cpp
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_func.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_func.cpp
index d66a9efdaa7e46e761994a581d0ec6447d815889..2d35dd85bebce5daa082877cf22310b8c28f8850 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);

Powered by Google App Engine
This is Rietveld 408576698