summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/include/fpdfapi/fpdf_pageobj.h90
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page.cpp311
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp3
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_image.cpp17
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp7
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_path.cpp25
-rw-r--r--core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp2
-rw-r--r--core/src/fpdfapi/fpdf_render/fpdf_render_text.cpp3
-rw-r--r--core/src/fpdfapi/fpdf_render/render_int.h2
9 files changed, 100 insertions, 360 deletions
diff --git a/core/include/fpdfapi/fpdf_pageobj.h b/core/include/fpdfapi/fpdf_pageobj.h
index efb8e29bec..388409742a 100644
--- a/core/include/fpdfapi/fpdf_pageobj.h
+++ b/core/include/fpdfapi/fpdf_pageobj.h
@@ -288,12 +288,10 @@ class CPDF_PageObject : public CPDF_GraphicStates {
FORM,
};
- static CPDF_PageObject* Create(Type type);
+ CPDF_PageObject();
virtual ~CPDF_PageObject();
- CPDF_PageObject* Clone() const;
- void Copy(const CPDF_PageObject* pSrcObject);
-
+ virtual CPDF_PageObject* Clone() const = 0;
virtual Type GetType() const = 0;
virtual void Transform(const CFX_Matrix& matrix) = 0;
virtual bool IsText() const { return false; }
@@ -312,12 +310,8 @@ class CPDF_PageObject : public CPDF_GraphicStates {
virtual CPDF_FormObject* AsForm() { return nullptr; }
virtual const CPDF_FormObject* AsForm() const { return nullptr; }
- void RemoveClipPath();
- void AppendClipPath(CPDF_Path path, int type, FX_BOOL bAutoMerge);
- void CopyClipPath(CPDF_PageObject* pObj);
void TransformClipPath(CFX_Matrix& matrix);
void TransformGeneralState(CFX_Matrix& matrix);
- void SetColorState(CPDF_ColorState state) { m_ColorState = state; }
FX_RECT GetBBox(const CFX_Matrix* pMatrix) const;
FX_FLOAT m_Left;
@@ -327,9 +321,11 @@ class CPDF_PageObject : public CPDF_GraphicStates {
CPDF_ContentMark m_ContentMark;
protected:
- virtual void CopyData(const CPDF_PageObject* pSrcObject) = 0;
+ void CopyData(const CPDF_PageObject* pSrcObject);
- void RecalcBBox();
+ private:
+ CPDF_PageObject(const CPDF_PageObject& src) = delete;
+ void operator=(const CPDF_PageObject& src) = delete;
};
struct CPDF_TextObjectItem {
@@ -344,6 +340,7 @@ class CPDF_TextObject : public CPDF_PageObject {
~CPDF_TextObject() override;
// CPDF_PageObject:
+ CPDF_TextObject* Clone() const override;
Type GetType() const override { return TEXT; };
void Transform(const CFX_Matrix& matrix) override;
bool IsText() const override { return true; };
@@ -351,55 +348,20 @@ class CPDF_TextObject : public CPDF_PageObject {
const CPDF_TextObject* AsText() const override { return this; };
int CountItems() const { return m_nChars; }
-
void GetItemInfo(int index, CPDF_TextObjectItem* pInfo) const;
-
int CountChars() const;
-
void GetCharInfo(int index, FX_DWORD& charcode, FX_FLOAT& kerning) const;
void GetCharInfo(int index, CPDF_TextObjectItem* pInfo) const;
-
- void GetCharRect(int index, CFX_FloatRect& rect) const;
-
FX_FLOAT GetCharWidth(FX_DWORD charcode) const;
- FX_FLOAT GetSpaceCharWidth() const;
-
FX_FLOAT GetPosX() const { return m_PosX; }
-
FX_FLOAT GetPosY() const { return m_PosY; }
-
void GetTextMatrix(CFX_Matrix* pMatrix) const;
-
CPDF_Font* GetFont() const { return m_TextState.GetFont(); }
-
FX_FLOAT GetFontSize() const { return m_TextState.GetFontSize(); }
- void SetEmpty();
-
void SetText(const CFX_ByteString& text);
-
- void SetText(CFX_ByteString* pStrs, FX_FLOAT* pKerning, int nSegs);
-
- void SetText(int nChars, FX_DWORD* pCharCodes, FX_FLOAT* pKernings);
-
void SetPosition(FX_FLOAT x, FX_FLOAT y);
- void SetTextState(CPDF_TextState TextState);
-
- void CalcCharPos(FX_FLOAT* pPosArray) const;
-
- void SetData(int nChars,
- FX_DWORD* pCharCodes,
- FX_FLOAT* pCharPos,
- FX_FLOAT x,
- FX_FLOAT y);
-
- void GetData(int& nChars, FX_DWORD*& pCharCodes, FX_FLOAT*& pCharPos) {
- nChars = m_nChars;
- pCharCodes = m_pCharCodes;
- pCharPos = m_pCharPos;
- }
-
void RecalcPositionData() { CalcPositionData(nullptr, nullptr, 1); }
protected:
@@ -407,9 +369,6 @@ class CPDF_TextObject : public CPDF_PageObject {
friend class CPDF_StreamContentParser;
friend class CPDF_TextRenderer;
- // CPDF_PageObject:
- void CopyData(const CPDF_PageObject* pSrcObject) override;
-
void SetSegments(const CFX_ByteString* pStrs, FX_FLOAT* pKerning, int nSegs);
void CalcPositionData(FX_FLOAT* pTextAdvanceX,
@@ -419,40 +378,30 @@ class CPDF_TextObject : public CPDF_PageObject {
FX_FLOAT m_PosX;
FX_FLOAT m_PosY;
-
int m_nChars;
-
FX_DWORD* m_pCharCodes;
-
FX_FLOAT* m_pCharPos;
};
class CPDF_PathObject : public CPDF_PageObject {
public:
- CPDF_PathObject() {}
- ~CPDF_PathObject() override {}
+ CPDF_PathObject();
+ ~CPDF_PathObject() override;
// CPDF_PageObject:
+ CPDF_PathObject* Clone() const override;
Type GetType() const override { return PATH; };
void Transform(const CFX_Matrix& maxtrix) override;
bool IsPath() const override { return true; };
CPDF_PathObject* AsPath() override { return this; };
const CPDF_PathObject* AsPath() const override { return this; };
- void SetGraphState(CPDF_GraphState GraphState);
-
void CalcBoundingBox();
CPDF_Path m_Path;
-
int m_FillType;
-
FX_BOOL m_bStroke;
-
CFX_Matrix m_Matrix;
-
- protected:
- void CopyData(const CPDF_PageObject* pSrcObject) override;
};
class CPDF_ImageObject : public CPDF_PageObject {
@@ -461,20 +410,17 @@ class CPDF_ImageObject : public CPDF_PageObject {
~CPDF_ImageObject() override;
// CPDF_PageObject:
+ CPDF_ImageObject* Clone() const override;
Type GetType() const override { return IMAGE; };
void Transform(const CFX_Matrix& matrix) override;
bool IsImage() const override { return true; };
CPDF_ImageObject* AsImage() override { return this; };
const CPDF_ImageObject* AsImage() const override { return this; };
- CPDF_Image* m_pImage;
-
- CFX_Matrix m_Matrix;
-
void CalcBoundingBox();
- private:
- void CopyData(const CPDF_PageObject* pSrcObject) override;
+ CPDF_Image* m_pImage;
+ CFX_Matrix m_Matrix;
};
class CPDF_ShadingObject : public CPDF_PageObject {
@@ -483,6 +429,7 @@ class CPDF_ShadingObject : public CPDF_PageObject {
~CPDF_ShadingObject() override;
// CPDF_PageObject:
+ CPDF_ShadingObject* Clone() const override;
Type GetType() const override { return SHADING; };
void Transform(const CFX_Matrix& matrix) override;
bool IsShading() const override { return true; };
@@ -493,17 +440,15 @@ class CPDF_ShadingObject : public CPDF_PageObject {
CPDF_ShadingPattern* m_pShading;
CFX_Matrix m_Matrix;
-
- protected:
- void CopyData(const CPDF_PageObject* pSrcObject) override;
};
class CPDF_FormObject : public CPDF_PageObject {
public:
- CPDF_FormObject() : m_pForm(nullptr) {}
+ CPDF_FormObject();
~CPDF_FormObject() override;
// CPDF_PageObject:
+ CPDF_FormObject* Clone() const override;
Type GetType() const override { return FORM; };
void Transform(const CFX_Matrix& matrix) override;
bool IsForm() const override { return true; };
@@ -514,9 +459,6 @@ class CPDF_FormObject : public CPDF_PageObject {
CPDF_Form* m_pForm;
CFX_Matrix m_FormMatrix;
-
- protected:
- void CopyData(const CPDF_PageObject* pSrcObject) override;
};
#endif // CORE_INCLUDE_FPDFAPI_FPDF_PAGEOBJ_H_
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page.cpp
index 0bcd15be20..be038004ac 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page.cpp
@@ -12,64 +12,18 @@
#include "core/include/fpdfapi/fpdf_page.h"
#include "third_party/base/stl_util.h"
-CPDF_PageObject* CPDF_PageObject::Create(Type type) {
- switch (type) {
- case TEXT:
- return new CPDF_TextObject;
- case IMAGE:
- return new CPDF_ImageObject;
- case PATH:
- return new CPDF_PathObject;
- case SHADING:
- return new CPDF_ShadingObject;
- case FORM:
- return new CPDF_FormObject;
- }
- return NULL;
-}
+CPDF_PageObject::CPDF_PageObject() {}
+
CPDF_PageObject::~CPDF_PageObject() {}
-CPDF_PageObject* CPDF_PageObject::Clone() const {
- CPDF_PageObject* pObj = Create(GetType());
- pObj->Copy(this);
- return pObj;
-}
-void CPDF_PageObject::Copy(const CPDF_PageObject* pSrc) {
- if (GetType() != pSrc->GetType()) {
- return;
- }
- CopyData(pSrc);
+
+void CPDF_PageObject::CopyData(const CPDF_PageObject* pSrc) {
CopyStates(*pSrc);
m_Left = pSrc->m_Left;
m_Right = pSrc->m_Right;
m_Top = pSrc->m_Top;
m_Bottom = pSrc->m_Bottom;
}
-void CPDF_PageObject::AppendClipPath(CPDF_Path path,
- int type,
- FX_BOOL bAutoMerge) {
- m_ClipPath.AppendPath(path, type, bAutoMerge);
-}
-void CPDF_PageObject::CopyClipPath(CPDF_PageObject* pObj) {
- m_ClipPath = pObj->m_ClipPath;
-}
-void CPDF_PageObject::RemoveClipPath() {
- m_ClipPath.SetNull();
-}
-void CPDF_PageObject::RecalcBBox() {
- switch (GetType()) {
- case TEXT:
- ((CPDF_TextObject*)this)->RecalcPositionData();
- break;
- case PATH:
- ((CPDF_PathObject*)this)->CalcBoundingBox();
- break;
- case SHADING:
- ((CPDF_ShadingObject*)this)->CalcBoundingBox();
- break;
- default:
- break;
- }
-}
+
void CPDF_PageObject::TransformClipPath(CFX_Matrix& matrix) {
if (m_ClipPath.IsNull()) {
return;
@@ -77,6 +31,7 @@ void CPDF_PageObject::TransformClipPath(CFX_Matrix& matrix) {
m_ClipPath.GetModify();
m_ClipPath.Transform(matrix);
}
+
void CPDF_PageObject::TransformGeneralState(CFX_Matrix& matrix) {
if (m_GeneralState.IsNull()) {
return;
@@ -84,6 +39,7 @@ void CPDF_PageObject::TransformGeneralState(CFX_Matrix& matrix) {
CPDF_GeneralStateData* pGS = m_GeneralState.GetModify();
pGS->m_Matrix.Concat(matrix);
}
+
FX_RECT CPDF_PageObject::GetBBox(const CFX_Matrix* pMatrix) const {
CFX_FloatRect rect(m_Left, m_Bottom, m_Right, m_Top);
if (pMatrix) {
@@ -187,29 +143,23 @@ void CPDF_TextObject::GetCharInfo(int index, CPDF_TextObjectItem* pInfo) const {
}
}
-void CPDF_TextObject::CopyData(const CPDF_PageObject* pSrc) {
- const CPDF_TextObject* pSrcObj = (const CPDF_TextObject*)pSrc;
- if (m_nChars > 1) {
- FX_Free(m_pCharCodes);
- m_pCharCodes = nullptr;
- }
- FX_Free(m_pCharPos);
- m_pCharPos = nullptr;
- m_nChars = pSrcObj->m_nChars;
+CPDF_TextObject* CPDF_TextObject::Clone() const {
+ CPDF_TextObject* obj = new CPDF_TextObject;
+ obj->CopyData(this);
+
+ obj->m_nChars = m_nChars;
if (m_nChars > 1) {
- m_pCharCodes = FX_Alloc(FX_DWORD, m_nChars);
- m_pCharPos = FX_Alloc(FX_FLOAT, m_nChars - 1);
- for (int i = 0; i < m_nChars; ++i) {
- m_pCharCodes[i] = pSrcObj->m_pCharCodes[i];
- }
- for (int i = 0; i < m_nChars - 1; ++i) {
- m_pCharPos[i] = pSrcObj->m_pCharPos[i];
- }
+ obj->m_pCharCodes = FX_Alloc(FX_DWORD, m_nChars);
+ FXSYS_memcpy(obj->m_pCharCodes, m_pCharCodes, m_nChars * sizeof(FX_DWORD));
+ obj->m_pCharPos = FX_Alloc(FX_FLOAT, m_nChars - 1);
+ FXSYS_memcpy(obj->m_pCharPos, m_pCharPos,
+ (m_nChars - 1) * sizeof(FX_FLOAT));
} else {
- m_pCharCodes = pSrcObj->m_pCharCodes;
+ obj->m_pCharCodes = m_pCharCodes;
}
- m_PosX = pSrcObj->m_PosX;
- m_PosY = pSrcObj->m_PosY;
+ obj->m_PosX = m_PosX;
+ obj->m_PosY = m_PosY;
+ return obj;
}
void CPDF_TextObject::GetTextMatrix(CFX_Matrix* pMatrix) const {
@@ -260,61 +210,6 @@ void CPDF_TextObject::SetText(const CFX_ByteString& str) {
RecalcPositionData();
}
-void CPDF_TextObject::SetEmpty() {
- if (m_nChars > 1) {
- FX_Free(m_pCharCodes);
- }
- if (m_nChars > 1) {
- FX_Free(m_pCharPos);
- }
- m_nChars = 0;
- m_pCharCodes = nullptr;
- m_pCharPos = nullptr;
- m_Left = m_Right = m_PosX;
- m_Top = m_Bottom = m_PosY;
-}
-
-void CPDF_TextObject::SetText(CFX_ByteString* pStrs,
- FX_FLOAT* pKerning,
- int nSegs) {
- SetSegments(pStrs, pKerning, nSegs);
- RecalcPositionData();
-}
-
-void CPDF_TextObject::SetText(int nChars,
- FX_DWORD* pCharCodes,
- FX_FLOAT* pKernings) {
- if (m_nChars > 1) {
- FX_Free(m_pCharCodes);
- m_pCharCodes = nullptr;
- }
- FX_Free(m_pCharPos);
- m_pCharPos = nullptr;
- int nKernings = 0;
- int i;
- for (i = 0; i < nChars - 1; ++i) {
- if (pKernings[i] != 0) {
- ++nKernings;
- }
- }
- m_nChars = nChars + nKernings;
- if (m_nChars > 1) {
- m_pCharCodes = FX_Alloc(FX_DWORD, m_nChars);
- m_pCharPos = FX_Alloc(FX_FLOAT, m_nChars - 1);
- for (int i = 0, index = 0; i < nChars; ++i) {
- m_pCharCodes[index++] = pCharCodes[i];
- if (pKernings[i] != 0 && i != nChars - 1) {
- m_pCharCodes[index] = (FX_DWORD)-1;
- m_pCharPos[index - 1] = pKernings[i];
- ++index;
- }
- }
- } else {
- m_pCharCodes = (FX_DWORD*)(uintptr_t)pCharCodes[0];
- }
- RecalcPositionData();
-}
-
FX_FLOAT CPDF_TextObject::GetCharWidth(FX_DWORD charcode) const {
FX_FLOAT fontsize = m_TextState.GetFontSize() / 1000;
CPDF_Font* pFont = m_TextState.GetFont();
@@ -330,69 +225,6 @@ FX_FLOAT CPDF_TextObject::GetCharWidth(FX_DWORD charcode) const {
return pCIDFont->GetVertWidth(CID) * fontsize;
}
-FX_FLOAT CPDF_TextObject::GetSpaceCharWidth() const {
- CPDF_Font* pFont = m_TextState.GetFont();
- FX_DWORD charCode = m_TextState.GetFont()->CharCodeFromUnicode(32);
- if (charCode != (FX_DWORD)-1) {
- return GetCharWidth(charCode);
- }
- FX_FLOAT fontSize = m_TextState.GetFontSize() / 4000.0f;
- FX_BOOL bVertWriting = FALSE;
- CPDF_CIDFont* pCIDFont = pFont->GetCIDFont();
- if (pCIDFont) {
- bVertWriting = pCIDFont->IsVertWriting();
- }
- FX_RECT fontRect;
- pFont->GetFontBBox(fontRect);
- fontSize *=
- bVertWriting ? (FX_FLOAT)fontRect.Height() : (FX_FLOAT)fontRect.Width();
- return fontSize;
-}
-
-void CPDF_TextObject::GetCharRect(int index, CFX_FloatRect& rect) const {
- CPDF_Font* pFont = m_TextState.GetFont();
- FX_BOOL bVertWriting = FALSE;
- CPDF_CIDFont* pCIDFont = pFont->GetCIDFont();
- if (pCIDFont) {
- bVertWriting = pCIDFont->IsVertWriting();
- }
- FX_FLOAT fontsize = m_TextState.GetFontSize() / 1000;
- int count = 0;
- for (int i = 0; i < m_nChars; ++i) {
- FX_DWORD charcode =
- m_nChars == 1 ? (FX_DWORD)(uintptr_t)m_pCharCodes : m_pCharCodes[i];
- if (charcode == (FX_DWORD)-1) {
- continue;
- }
- if (count != index) {
- ++count;
- continue;
- }
- FX_FLOAT curpos = i > 0 ? m_pCharPos[i - 1] : 0;
- FX_RECT char_rect;
- pFont->GetCharBBox(charcode, char_rect, 0);
- if (!bVertWriting) {
- rect.left = curpos + char_rect.left * fontsize;
- rect.right = curpos + char_rect.right * fontsize;
- rect.top = char_rect.top * fontsize;
- rect.bottom = char_rect.bottom * fontsize;
- } else {
- FX_WORD CID = pCIDFont->CIDFromCharCode(charcode);
- short vx, vy;
- pCIDFont->GetVertOrigin(CID, vx, vy);
- char_rect.left -= vx;
- char_rect.right -= vx;
- char_rect.top -= vy;
- char_rect.bottom -= vy;
- rect.left = char_rect.left * fontsize;
- rect.right = char_rect.right * fontsize;
- rect.top = curpos + char_rect.top * fontsize;
- rect.bottom = curpos + char_rect.bottom * fontsize;
- }
- return;
- }
-}
-
void CPDF_TextObject::CalcPositionData(FX_FLOAT* pTextAdvanceX,
FX_FLOAT* pTextAdvanceY,
FX_FLOAT horz_scale,
@@ -529,33 +361,6 @@ void CPDF_TextObject::CalcPositionData(FX_FLOAT* pTextAdvanceX,
}
}
-void CPDF_TextObject::CalcCharPos(FX_FLOAT* pPosArray) const {
- CPDF_Font* pFont = m_TextState.GetFont();
- FX_BOOL bVertWriting = FALSE;
- CPDF_CIDFont* pCIDFont = pFont->GetCIDFont();
- if (pCIDFont) {
- bVertWriting = pCIDFont->IsVertWriting();
- }
- FX_FLOAT fontsize = m_TextState.GetFontSize();
- for (int i = 0, index = 0; i < m_nChars; ++i) {
- FX_DWORD charcode =
- m_nChars == 1 ? (FX_DWORD)(uintptr_t)m_pCharCodes : m_pCharCodes[i];
- if (charcode == (FX_DWORD)-1) {
- continue;
- }
- pPosArray[index++] = i ? m_pCharPos[i - 1] : 0;
- FX_FLOAT charwidth;
- if (bVertWriting) {
- FX_WORD CID = pCIDFont->CIDFromCharCode(charcode);
- charwidth = pCIDFont->GetVertWidth(CID) * fontsize / 1000;
- } else {
- charwidth = pFont->GetCharWidthF(charcode) * fontsize / 1000;
- }
- pPosArray[index] = pPosArray[index - 1] + charwidth;
- index++;
- }
-}
-
void CPDF_TextObject::Transform(const CFX_Matrix& matrix) {
m_TextState.GetModify();
CFX_Matrix text_matrix;
@@ -582,48 +387,24 @@ void CPDF_TextObject::SetPosition(FX_FLOAT x, FX_FLOAT y) {
m_Bottom += dy;
}
-void CPDF_TextObject::SetData(int nChars,
- FX_DWORD* pCharCodes,
- FX_FLOAT* pCharPos,
- FX_FLOAT x,
- FX_FLOAT y) {
- ASSERT(m_nChars == 0);
- m_nChars = nChars;
- m_PosX = x;
- m_PosY = y;
- if (nChars == 0) {
- return;
- }
- if (nChars == 1) {
- m_pCharCodes = (FX_DWORD*)(uintptr_t)*pCharCodes;
- } else {
- m_pCharCodes = FX_Alloc(FX_DWORD, nChars);
- FXSYS_memcpy(m_pCharCodes, pCharCodes, sizeof(FX_DWORD) * nChars);
- m_pCharPos = FX_Alloc(FX_FLOAT, nChars - 1);
- FXSYS_memcpy(m_pCharPos, pCharPos, sizeof(FX_FLOAT) * (nChars - 1));
- }
- RecalcPositionData();
-}
-
-void CPDF_TextObject::SetTextState(CPDF_TextState TextState) {
- m_TextState = TextState;
- CalcPositionData(nullptr, nullptr, 0);
-}
-
CPDF_ShadingObject::CPDF_ShadingObject() : m_pShading(nullptr) {}
CPDF_ShadingObject::~CPDF_ShadingObject() {}
-void CPDF_ShadingObject::CopyData(const CPDF_PageObject* pSrc) {
- CPDF_ShadingObject* pSrcObj = (CPDF_ShadingObject*)pSrc;
- m_pShading = pSrcObj->m_pShading;
- if (m_pShading && m_pShading->m_pDocument) {
- CPDF_DocPageData* pDocPageData = m_pShading->m_pDocument->GetPageData();
- m_pShading = (CPDF_ShadingPattern*)pDocPageData->GetPattern(
- m_pShading->m_pShadingObj, m_pShading->m_bShadingObj,
- &m_pShading->m_ParentMatrix);
+CPDF_ShadingObject* CPDF_ShadingObject::Clone() const {
+ CPDF_ShadingObject* obj = new CPDF_ShadingObject;
+ obj->CopyData(this);
+
+ obj->m_pShading = m_pShading;
+ if (obj->m_pShading && obj->m_pShading->m_pDocument) {
+ CPDF_DocPageData* pDocPageData =
+ obj->m_pShading->m_pDocument->GetPageData();
+ obj->m_pShading = (CPDF_ShadingPattern*)pDocPageData->GetPattern(
+ obj->m_pShading->m_pShadingObj, m_pShading->m_bShadingObj,
+ &obj->m_pShading->m_ParentMatrix);
}
- m_Matrix = pSrcObj->m_Matrix;
+ obj->m_Matrix = m_Matrix;
+ return obj;
}
void CPDF_ShadingObject::Transform(const CFX_Matrix& matrix) {
@@ -650,19 +431,26 @@ void CPDF_ShadingObject::CalcBoundingBox() {
m_Top = rect.top;
}
+CPDF_FormObject::CPDF_FormObject() : m_pForm(nullptr) {}
+
CPDF_FormObject::~CPDF_FormObject() {
delete m_pForm;
}
+
void CPDF_FormObject::Transform(const CFX_Matrix& matrix) {
m_FormMatrix.Concat(matrix);
CalcBoundingBox();
}
-void CPDF_FormObject::CopyData(const CPDF_PageObject* pSrc) {
- const CPDF_FormObject* pSrcObj = (const CPDF_FormObject*)pSrc;
- delete m_pForm;
- m_pForm = pSrcObj->m_pForm->Clone();
- m_FormMatrix = pSrcObj->m_FormMatrix;
+
+CPDF_FormObject* CPDF_FormObject::Clone() const {
+ CPDF_FormObject* obj = new CPDF_FormObject;
+ obj->CopyData(this);
+
+ obj->m_pForm = m_pForm->Clone();
+ obj->m_FormMatrix = m_FormMatrix;
+ return obj;
}
+
void CPDF_FormObject::CalcBoundingBox() {
CFX_FloatRect form_rect = m_pForm->CalcBoundingBox();
form_rect.Transform(&m_FormMatrix);
@@ -819,6 +607,7 @@ void CPDF_Page::Load(CPDF_Document* pDocument,
m_Transparency = PDFTRANS_ISOLATED;
LoadTransInfo();
}
+
void CPDF_Page::StartParse(CPDF_ParseOptions* pOptions) {
if (m_ParseState == CONTENT_PARSED || m_ParseState == CONTENT_PARSING) {
return;
@@ -827,16 +616,19 @@ void CPDF_Page::StartParse(CPDF_ParseOptions* pOptions) {
m_pParser->Start(this, pOptions);
m_ParseState = CONTENT_PARSING;
}
+
void CPDF_Page::ParseContent(CPDF_ParseOptions* pOptions) {
StartParse(pOptions);
ContinueParse(nullptr);
}
+
CPDF_Page::~CPDF_Page() {
if (m_pPageRender) {
IPDF_RenderModule* pModule = CPDF_ModuleMgr::Get()->GetRenderModule();
pModule->DestroyPageCache(m_pPageRender);
}
}
+
CPDF_Object* FPDFAPI_GetPageAttr(CPDF_Dictionary* pPageDict,
const CFX_ByteStringC& name) {
int level = 0;
@@ -856,9 +648,11 @@ CPDF_Object* FPDFAPI_GetPageAttr(CPDF_Dictionary* pPageDict,
}
}
}
+
CPDF_Object* CPDF_Page::GetPageAttr(const CFX_ByteStringC& name) const {
return FPDFAPI_GetPageAttr(m_pFormDict, name);
}
+
CPDF_Form::CPDF_Form(CPDF_Document* pDoc,
CPDF_Dictionary* pPageResources,
CPDF_Stream* pFormStream,
@@ -966,6 +760,7 @@ void CPDF_Page::GetDisplayMatrix(CFX_Matrix& matrix,
matrix = m_PageMatrix;
matrix.Concat(display_matrix);
}
+
CPDF_ParseOptions::CPDF_ParseOptions() {
m_bTextOnly = FALSE;
m_bMarkedContent = TRUE;
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 818ec8fd2f..bee4a5b707 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp
@@ -63,8 +63,7 @@ CPDF_ClipPathData::CPDF_ClipPathData(const CPDF_ClipPathData& src) {
m_pTextList = FX_Alloc(CPDF_TextObject*, m_TextCount);
for (int i = 0; i < m_TextCount; i++) {
if (src.m_pTextList[i]) {
- m_pTextList[i] = new CPDF_TextObject;
- m_pTextList[i]->Copy(src.m_pTextList[i]);
+ m_pTextList[i] = src.m_pTextList[i]->Clone();
} else {
m_pTextList[i] = NULL;
}
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_image.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_image.cpp
index 93c0aca4f1..c5e29a4b77 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_image.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_image.cpp
@@ -10,6 +10,7 @@
#include "core/include/fpdfapi/fpdf_pageobj.h"
CPDF_ImageObject::CPDF_ImageObject() : m_pImage(nullptr) {}
+
CPDF_ImageObject::~CPDF_ImageObject() {
if (!m_pImage) {
return;
@@ -21,14 +22,16 @@ CPDF_ImageObject::~CPDF_ImageObject() {
m_pImage->GetDocument()->GetPageData()->ReleaseImage(m_pImage->GetStream());
}
}
-void CPDF_ImageObject::CopyData(const CPDF_PageObject* pSrc) {
- const CPDF_ImageObject* pSrcObj = (const CPDF_ImageObject*)pSrc;
- if (m_pImage) {
- m_pImage->Release();
- }
- m_pImage = pSrcObj->m_pImage->Clone();
- m_Matrix = pSrcObj->m_Matrix;
+
+CPDF_ImageObject* CPDF_ImageObject::Clone() const {
+ CPDF_ImageObject* obj = new CPDF_ImageObject;
+ obj->CopyData(this);
+
+ obj->m_pImage = m_pImage->Clone();
+ obj->m_Matrix = m_Matrix;
+ return obj;
}
+
void CPDF_ImageObject::Transform(const CFX_Matrix& matrix) {
m_Matrix.Concat(matrix);
CalcBoundingBox();
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp
index d49186374f..efe0f25a9f 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp
@@ -1389,11 +1389,8 @@ void CPDF_StreamContentParser::AddTextObject(CFX_ByteString* pStrs,
m_pCurStates->m_TextHorzScale, m_Level);
m_pCurStates->m_TextX += x_advance;
m_pCurStates->m_TextY += y_advance;
- if (textmode > 3) {
- CPDF_TextObject* pCopy = new CPDF_TextObject;
- pCopy->Copy(pText.get());
- m_ClipTextList.Add(pCopy);
- }
+ if (textmode > 3)
+ m_ClipTextList.Add(pText->Clone());
m_pObjectHolder->GetPageObjectList()->push_back(std::move(pText));
}
if (pKerning && pKerning[nsegs - 1] != 0) {
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_path.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_path.cpp
index 09d7b87780..75d7d2a362 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_path.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_path.cpp
@@ -10,21 +10,26 @@
#include "core/include/fpdfapi/fpdf_page.h"
#include "core/include/fpdfapi/fpdf_pageobj.h"
-void CPDF_PathObject::CopyData(const CPDF_PageObject* pSrc) {
- const CPDF_PathObject* pSrcObj = (const CPDF_PathObject*)pSrc;
- m_Path = pSrcObj->m_Path;
- m_FillType = pSrcObj->m_FillType;
- m_bStroke = pSrcObj->m_bStroke;
- m_Matrix = pSrcObj->m_Matrix;
+CPDF_PathObject::CPDF_PathObject() {}
+
+CPDF_PathObject::~CPDF_PathObject() {}
+
+CPDF_PathObject* CPDF_PathObject::Clone() const {
+ CPDF_PathObject* obj = new CPDF_PathObject;
+ obj->CopyData(this);
+
+ obj->m_Path = m_Path;
+ obj->m_FillType = m_FillType;
+ obj->m_bStroke = m_bStroke;
+ obj->m_Matrix = m_Matrix;
+ return obj;
}
+
void CPDF_PathObject::Transform(const CFX_Matrix& matrix) {
m_Matrix.Concat(matrix);
CalcBoundingBox();
}
-void CPDF_PathObject::SetGraphState(CPDF_GraphState GraphState) {
- m_GraphState = GraphState;
- CalcBoundingBox();
-}
+
void CPDF_PathObject::CalcBoundingBox() {
if (m_Path.IsNull()) {
return;
diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp
index acfc083e0e..954d3886b5 100644
--- a/core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp
+++ b/core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp
@@ -462,7 +462,7 @@ FX_BOOL CPDF_ImageRenderer::Start(CPDF_RenderStatus* pStatus,
int blendType) {
m_pRenderStatus = pStatus;
m_bStdCS = bStdCS;
- m_pImageObject = (CPDF_ImageObject*)pObj;
+ m_pImageObject = pObj->AsImage();
m_BlendType = blendType;
m_pObj2Device = pObj2Device;
CPDF_Dictionary* pOC = m_pImageObject->m_pImage->GetOC();
diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render_text.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render_text.cpp
index 769ee05dc9..136c318339 100644
--- a/core/src/fpdfapi/fpdf_render/fpdf_render_text.cpp
+++ b/core/src/fpdfapi/fpdf_render/fpdf_render_text.cpp
@@ -731,8 +731,7 @@ void CPDF_RenderStatus::DrawTextPathWithPattern(const CPDF_TextObject* textobj,
FX_BOOL bStroke) {
if (!bStroke) {
CPDF_PathObject path;
- CPDF_TextObject* pCopy = new CPDF_TextObject;
- pCopy->Copy(textobj);
+ CPDF_TextObject* pCopy = textobj->Clone();
path.m_bStroke = FALSE;
path.m_FillType = FXFILL_WINDING;
path.m_ClipPath.AppendTexts(&pCopy, 1);
diff --git a/core/src/fpdfapi/fpdf_render/render_int.h b/core/src/fpdfapi/fpdf_render/render_int.h
index 5af5909d2e..b7f007dd5d 100644
--- a/core/src/fpdfapi/fpdf_render/render_int.h
+++ b/core/src/fpdfapi/fpdf_render/render_int.h
@@ -340,7 +340,7 @@ class CPDF_ImageRenderer : public IPDF_ObjectRenderer {
protected:
CPDF_RenderStatus* m_pRenderStatus;
- CPDF_ImageObject* m_pImageObject;
+ const CPDF_ImageObject* m_pImageObject;
int m_Status;
const CFX_Matrix* m_pObj2Device;
CFX_Matrix m_ImageMatrix;