summaryrefslogtreecommitdiff
path: root/core/src/fpdfapi/fpdf_edit
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_edit
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_edit')
-rw-r--r--core/src/fpdfapi/fpdf_edit/fpdf_edit_content.cpp15
-rw-r--r--core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp65
2 files changed, 36 insertions, 44 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);