summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
Diffstat (limited to 'core/src')
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp7
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp137
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp43
-rw-r--r--core/src/fpdfapi/fpdf_page/pageint.h112
4 files changed, 162 insertions, 137 deletions
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 70d0743f58..b4d030e679 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp
@@ -8,8 +8,9 @@
#include "../../../include/fpdfapi/fpdf_pageobj.h"
#include "../../../include/fpdfapi/fpdf_module.h"
#include "../../../include/fpdfapi/fpdf_render.h"
-#include "pageint.h"
#include "../fpdf_render/render_int.h"
+#include "pageint.h"
+
void CPDF_GraphicStates::DefaultStates()
{
m_ColorState.New()->Default();
@@ -544,14 +545,14 @@ void CPDF_AllStates::ProcessExtGS(CPDF_Dictionary* pGS, CPDF_StreamContentParser
}
pGeneralState->SetBlendMode(mode);
if (pGeneralState->m_BlendType > FXDIB_BLEND_MULTIPLY) {
- pParser->m_pObjectList->m_bBackgroundAlphaNeeded = TRUE;
+ pParser->GetObjectList()->m_bBackgroundAlphaNeeded = TRUE;
}
break;
}
case FXBSTR_ID('S', 'M', 'a', 's'):
if (pObject && pObject->GetType() == PDFOBJ_DICTIONARY) {
pGeneralState->m_pSoftMask = pObject;
- FXSYS_memcpy(pGeneralState->m_SMaskMatrix, &pParser->m_pCurStates->m_CTM, sizeof(CPDF_Matrix));
+ FXSYS_memcpy(pGeneralState->m_SMaskMatrix, &pParser->GetCurStates()->m_CTM, sizeof(CPDF_Matrix));
} else {
pGeneralState->m_pSoftMask = NULL;
}
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp
index fdc4a27989..5b5703b868 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp
@@ -8,80 +8,60 @@
#include "../../../include/fpdfapi/fpdf_module.h"
#include "../../../include/fpdfapi/fpdf_serial.h"
#include "pageint.h"
+
#define REQUIRE_PARAMS(count) if (m_ParamCount != count) { m_bAbort = TRUE; return; }
-CPDF_StreamContentParser::CPDF_StreamContentParser()
-{
- m_DefFontSize = 0;
- m_pCurStates = NULL;
- m_pLastTextObject = NULL;
- m_pPathPoints = NULL;
- m_PathClipType = 0;
- m_PathPointCount = m_PathAllocSize = 0;
- m_PathCurrentX = m_PathCurrentY = 0.0f;
- m_bResourceMissing = FALSE;
- m_bColored = FALSE;
- FXSYS_memset(m_Type3Data, 0, sizeof(FX_FLOAT) * 6);
- m_ParamCount = 0;
- m_ParamStartPos = 0;
- m_bAbort = FALSE;
- m_pLastImageDict = NULL;
- m_pLastCloneImageDict = NULL;
- m_pLastImage = NULL;
- m_bReleaseLastDict = TRUE;
- m_pParentResources = NULL;
-}
-FX_BOOL CPDF_StreamContentParser::Initialize()
-{
- return TRUE;
-}
-CPDF_StreamContentParser::~CPDF_StreamContentParser()
-{
- ClearAllParams();
- int i = 0;
- for (i = 0; i < m_StateStack.GetSize(); i ++) {
- delete (CPDF_AllStates*)m_StateStack[i];
- }
- if (m_pPathPoints) {
- FX_Free(m_pPathPoints);
- }
- delete m_pCurStates;
- if (m_pLastImageDict) {
- m_pLastImageDict->Release();
- }
- if (m_pLastCloneImageDict) {
- m_pLastCloneImageDict->Release();
- }
-}
-void CPDF_StreamContentParser::PrepareParse(CPDF_Document* pDocument,
- CPDF_Dictionary* pPageResources, CPDF_Dictionary* pParentResources, CFX_AffineMatrix* pmtContentToUser, CPDF_PageObjects* pObjList,
- CPDF_Dictionary* pResources, CPDF_Rect* pBBox, CPDF_ParseOptions* pOptions,
- CPDF_AllStates* pStates, int level)
+
+CPDF_StreamContentParser::CPDF_StreamContentParser(
+ CPDF_Document* pDocument,
+ CPDF_Dictionary* pPageResources,
+ CPDF_Dictionary* pParentResources,
+ CFX_AffineMatrix* pmtContentToUser,
+ CPDF_PageObjects* pObjList,
+ CPDF_Dictionary* pResources,
+ CPDF_Rect* pBBox,
+ CPDF_ParseOptions* pOptions,
+ CPDF_AllStates* pStates,
+ int level)
+ : m_pDocument(pDocument),
+ m_pPageResources(pPageResources),
+ m_pParentResources(pParentResources),
+ m_pResources(pResources),
+ m_pObjectList(pObjList),
+ m_Level(level),
+ m_ParamStartPos(0),
+ m_ParamCount(0),
+ m_bAbort(FALSE),
+ m_pCurStates(new CPDF_AllStates),
+ m_pLastTextObject(nullptr),
+ m_DefFontSize(0),
+ m_pPathPoints(nullptr),
+ m_PathPointCount(0),
+ m_PathAllocSize(0),
+ m_PathCurrentX(0.0f),
+ m_PathCurrentY(0.0f),
+ m_PathClipType(0),
+ m_pLastImage(nullptr),
+ m_pLastImageDict(nullptr),
+ m_pLastCloneImageDict(nullptr),
+ m_bReleaseLastDict(TRUE),
+ m_bColored(FALSE),
+ m_bResourceMissing(FALSE)
{
- for (int i = 0; i < 6; i ++) {
- m_Type3Data[i] = 0;
- }
- m_pDocument = pDocument;
- m_pPageResources = pPageResources;
- m_pParentResources = pParentResources;
if (pmtContentToUser) {
m_mtContentToUser = *pmtContentToUser;
}
if (pOptions) {
m_Options = *pOptions;
}
- m_pObjectList = pObjList;
- m_pResources = pResources;
- if (pResources == NULL) {
+ if (!m_pResources) {
m_pResources = m_pParentResources;
}
- if (m_pResources == NULL) {
- m_pResources = pPageResources;
+ if (!m_pResources) {
+ m_pResources = m_pPageResources;
}
if (pBBox) {
m_BBox = *pBBox;
}
- m_Level = level;
- m_pCurStates = new CPDF_AllStates;
if (pStates) {
m_pCurStates->Copy(*pStates);
} else {
@@ -90,6 +70,26 @@ void CPDF_StreamContentParser::PrepareParse(CPDF_Document* pDocument,
m_pCurStates->m_TextState.New();
m_pCurStates->m_ColorState.New();
}
+ for (int i = 0; i < FX_ArraySize(m_Type3Data); ++i) {
+ m_Type3Data[i] = 0.0;
+ }
+}
+
+CPDF_StreamContentParser::~CPDF_StreamContentParser()
+{
+ ClearAllParams();
+ for (int i = 0; i < m_StateStack.GetSize(); ++i) {
+ delete (CPDF_AllStates*)m_StateStack[i];
+ }
+ if (m_pPathPoints) {
+ FX_Free(m_pPathPoints);
+ }
+ if (m_pLastImageDict) {
+ m_pLastImageDict->Release();
+ }
+ if (m_pLastCloneImageDict) {
+ m_pLastCloneImageDict->Release();
+ }
}
int CPDF_StreamContentParser::GetNextParamPos()
{
@@ -241,10 +241,9 @@ void CPDF_StreamContentParser::SetGraphicStates(CPDF_PageObject* pObj, FX_BOOL b
pObj->m_TextState = m_pCurStates->m_TextState;
}
}
-const struct _OpCode {
- FX_DWORD m_OpId;
- void (CPDF_StreamContentParser::*m_OpHandler)();
-} g_OpCodes[] = {
+
+const CPDF_StreamContentParser::OpCode CPDF_StreamContentParser::g_OpCodes[] =
+{
{FXBSTR_ID('"', 0, 0, 0), &CPDF_StreamContentParser::Handle_NextLineShowText_Space},
{FXBSTR_ID('\'', 0, 0, 0), &CPDF_StreamContentParser::Handle_NextLineShowText},
{FXBSTR_ID('B', 0, 0, 0), &CPDF_StreamContentParser::Handle_FillStrokePath},
@@ -331,7 +330,7 @@ FX_BOOL CPDF_StreamContentParser::OnOperator(const FX_CHAR* op)
opid <<= 8;
i ++;
};
- int low = 0, high = sizeof g_OpCodes / sizeof(struct _OpCode) - 1;
+ int low = 0, high = sizeof g_OpCodes / sizeof(OpCode) - 1;
while (low <= high) {
int middle = (low + high) / 2;
int compare = opid - g_OpCodes[middle].m_OpId;
@@ -713,10 +712,10 @@ void CPDF_StreamContentParser::AddForm(CPDF_Stream* pStream)
ClipPath.Transform(&form_matrix);
form_bbox.Transform(&form_matrix);
}
- CPDF_StreamContentParser parser;
- parser.Initialize();
- parser.PrepareParse(m_pDocument, m_pPageResources, m_pResources, &m_mtContentToUser,
- m_pObjectList, pResources, &form_bbox, &m_Options, m_pCurStates, m_Level + 1);
+ CPDF_StreamContentParser parser(
+ m_pDocument, m_pPageResources, m_pResources, &m_mtContentToUser,
+ m_pObjectList, pResources, &form_bbox, &m_Options,
+ m_pCurStates.get(), m_Level + 1);
parser.m_pCurStates->m_CTM = form_matrix;
if (ClipPath.NotNull()) {
parser.m_pCurStates->m_ClipPath.AppendPath(ClipPath, FXFILL_WINDING, TRUE);
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 3d12ee9c82..ebd4d83310 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp
@@ -997,17 +997,18 @@ void CPDF_ContentParser::Start(CPDF_Form* pForm, CPDF_AllStates* pGraphicStates,
}
}
CPDF_Dictionary* pResources = pForm->m_pFormDict->GetDict(FX_BSTRC("Resources"));
- m_pParser = new CPDF_StreamContentParser;
- m_pParser->Initialize();
- m_pParser->PrepareParse(pForm->m_pDocument, pForm->m_pPageResources, pForm->m_pResources, pParentMatrix, pForm,
- pResources, &form_bbox, pOptions, pGraphicStates, level);
- m_pParser->m_pCurStates->m_CTM = form_matrix;
- m_pParser->m_pCurStates->m_ParentMatrix = form_matrix;
+ m_pParser = new CPDF_StreamContentParser(
+ pForm->m_pDocument, pForm->m_pPageResources, pForm->m_pResources,
+ pParentMatrix, pForm, pResources, &form_bbox, pOptions, pGraphicStates,
+ level);
+
+ m_pParser->GetCurStates()->m_CTM = form_matrix;
+ m_pParser->GetCurStates()->m_ParentMatrix = form_matrix;
if (ClipPath.NotNull()) {
- m_pParser->m_pCurStates->m_ClipPath.AppendPath(ClipPath, FXFILL_WINDING, TRUE);
+ m_pParser->GetCurStates()->m_ClipPath.AppendPath(ClipPath, FXFILL_WINDING, TRUE);
}
if (pForm->m_Transparency & PDFTRANS_GROUP) {
- CPDF_GeneralStateData* pData = m_pParser->m_pCurStates->m_GeneralState.GetModify();
+ CPDF_GeneralStateData* pData = m_pParser->GetCurStates()->m_GeneralState.GetModify();
pData->m_BlendType = FXDIB_BLEND_NORMAL;
pData->m_StrokeAlpha = 1.0f;
pData->m_FillAlpha = 1.0f;
@@ -1068,18 +1069,18 @@ void CPDF_ContentParser::Continue(IFX_Pause* pPause)
}
}
if (m_InternalStage == PAGEPARSE_STAGE_PARSE) {
- if (m_pParser == NULL) {
- m_pParser = new CPDF_StreamContentParser;
- m_pParser->Initialize();
- m_pParser->PrepareParse(m_pObjects->m_pDocument, m_pObjects->m_pPageResources, NULL, NULL, m_pObjects,
- m_pObjects->m_pResources, &m_pObjects->m_BBox, &m_Options, NULL, 0);
- m_pParser->m_pCurStates->m_ColorState.GetModify()->Default();
+ if (!m_pParser) {
+ m_pParser = new CPDF_StreamContentParser(
+ m_pObjects->m_pDocument, m_pObjects->m_pPageResources,
+ nullptr, nullptr, m_pObjects, m_pObjects->m_pResources,
+ &m_pObjects->m_BBox, &m_Options, nullptr, 0);
+ m_pParser->GetCurStates()->m_ColorState.GetModify()->Default();
}
if (m_CurrentOffset >= m_Size) {
m_InternalStage = PAGEPARSE_STAGE_CHECKCLIP;
} else {
m_CurrentOffset += m_pParser->Parse(m_pData + m_CurrentOffset, m_Size - m_CurrentOffset, PARSE_STEP_LIMIT);
- if (m_pParser->m_bAbort) {
+ if (m_pParser->ShouldAbort()) {
m_InternalStage = PAGEPARSE_STAGE_CHECKCLIP;
continue;
}
@@ -1087,12 +1088,12 @@ void CPDF_ContentParser::Continue(IFX_Pause* pPause)
}
if (m_InternalStage == PAGEPARSE_STAGE_CHECKCLIP) {
if (m_pType3Char) {
- m_pType3Char->m_bColored = m_pParser->m_bColored;
- m_pType3Char->m_Width = FXSYS_round(m_pParser->m_Type3Data[0] * 1000);
- m_pType3Char->m_BBox.left = FXSYS_round(m_pParser->m_Type3Data[2] * 1000);
- m_pType3Char->m_BBox.bottom = FXSYS_round(m_pParser->m_Type3Data[3] * 1000);
- m_pType3Char->m_BBox.right = FXSYS_round(m_pParser->m_Type3Data[4] * 1000);
- m_pType3Char->m_BBox.top = FXSYS_round(m_pParser->m_Type3Data[5] * 1000);
+ m_pType3Char->m_bColored = m_pParser->IsColored();
+ m_pType3Char->m_Width = FXSYS_round(m_pParser->GetType3Data()[0] * 1000);
+ m_pType3Char->m_BBox.left = FXSYS_round(m_pParser->GetType3Data()[2] * 1000);
+ m_pType3Char->m_BBox.bottom = FXSYS_round(m_pParser->GetType3Data()[3] * 1000);
+ m_pType3Char->m_BBox.right = FXSYS_round(m_pParser->GetType3Data()[4] * 1000);
+ m_pType3Char->m_BBox.top = FXSYS_round(m_pParser->GetType3Data()[5] * 1000);
}
FX_POSITION pos = m_pObjects->m_ObjectList.GetHeadPosition();
while (pos) {
diff --git a/core/src/fpdfapi/fpdf_page/pageint.h b/core/src/fpdfapi/fpdf_page/pageint.h
index 95e16cb8cf..cf1fe47c0d 100644
--- a/core/src/fpdfapi/fpdf_page/pageint.h
+++ b/core/src/fpdfapi/fpdf_page/pageint.h
@@ -9,6 +9,7 @@
#include <map>
+#include "../../../../third_party/base/nonstd_unique_ptr.h"
#include "../../../include/fpdfapi/fpdf_pageobj.h"
#define PARSE_STEP_LIMIT 100
@@ -123,26 +124,25 @@ typedef struct {
class CPDF_StreamContentParser
{
public:
- CPDF_StreamContentParser();
+ CPDF_StreamContentParser(
+ CPDF_Document* pDoc,
+ CPDF_Dictionary* pPageResources,
+ CPDF_Dictionary* pParentResources,
+ CFX_AffineMatrix* pmtContentToUser,
+ CPDF_PageObjects* pObjList,
+ CPDF_Dictionary* pResources,
+ CFX_FloatRect* pBBox,
+ CPDF_ParseOptions* pOptions,
+ CPDF_AllStates* pAllStates,
+ int level);
~CPDF_StreamContentParser();
- FX_BOOL Initialize();
- void PrepareParse(CPDF_Document* pDoc, CPDF_Dictionary* pPageResources, CPDF_Dictionary* pParentResources,
- CFX_AffineMatrix* pmtContentToUser,
- CPDF_PageObjects* pObjList, CPDF_Dictionary* pResources,
- CFX_FloatRect* pBBox, CPDF_ParseOptions* pOptions,
- CPDF_AllStates* pAllStates, int level);
- CPDF_Document* m_pDocument;
- CPDF_Dictionary* m_pPageResources;
- CPDF_Dictionary* m_pParentResources;
- CPDF_PageObjects* m_pObjectList;
- CPDF_Dictionary* m_pResources;
- int m_Level;
- CFX_AffineMatrix m_mtContentToUser;
- CFX_FloatRect m_BBox;
- CPDF_ParseOptions m_Options;
- _ContentParam m_ParamBuf1[PARAM_BUF_SIZE];
- FX_DWORD m_ParamStartPos;
- FX_DWORD m_ParamCount;
+
+ FX_BOOL ShouldAbort() const { return m_bAbort; }
+ CPDF_PageObjects* GetObjectList() const { return m_pObjectList; }
+ CPDF_AllStates* GetCurStates() const { return m_pCurStates.get(); }
+ FX_BOOL IsColored() const { return m_bColored; }
+ const FX_FLOAT* GetType3Data() const { return m_Type3Data; }
+
void AddNumberParam(const FX_CHAR* str, int len);
void AddObjectParam(CPDF_Object* pObj);
void AddNameParam(const FX_CHAR* name, int size);
@@ -158,17 +158,10 @@ public:
}
FX_BOOL OnOperator(const FX_CHAR* op);
void BigCaseCaller(int index);
- FX_BOOL m_bAbort;
- CPDF_StreamParser* m_pSyntax;
FX_DWORD GetParsePos()
{
return m_pSyntax->GetPos();
}
- CPDF_AllStates* m_pCurStates;
- CPDF_ContentMark m_CurContentMark;
- CFX_PtrArray m_ClipTextList;
- CPDF_TextObject* m_pLastTextObject;
- FX_FLOAT m_DefFontSize;
void AddTextObject(CFX_ByteString* pText, FX_FLOAT fInitKerning, FX_FLOAT* pKerning, int count);
void ConvertUserSpace(FX_FLOAT& x, FX_FLOAT& y);
@@ -176,37 +169,27 @@ public:
void OnChangeTextMatrix();
FX_DWORD Parse(const uint8_t* pData, FX_DWORD dwSize, FX_DWORD max_cost);
void ParsePathObject();
- int m_CompatCount;
- FX_PATHPOINT* m_pPathPoints;
- int m_PathPointCount;
- int m_PathAllocSize;
- FX_FLOAT m_PathStartX, m_PathStartY;
- FX_FLOAT m_PathCurrentX, m_PathCurrentY;
- int m_PathClipType;
void AddPathPoint(FX_FLOAT x, FX_FLOAT y, int flag);
void AddPathRect(FX_FLOAT x, FX_FLOAT y, FX_FLOAT w, FX_FLOAT h);
void AddPathObject(int FillType, FX_BOOL bStroke);
CPDF_ImageObject* AddImage(CPDF_Stream* pStream, CPDF_Image* pImage, FX_BOOL bInline);
void AddDuplicateImage();
void AddForm(CPDF_Stream*);
- CFX_ByteString m_LastImageName;
- CPDF_Image* m_pLastImage;
- CFX_BinaryBuf m_LastImageDict, m_LastImageData;
- CPDF_Dictionary* m_pLastImageDict;
- CPDF_Dictionary* m_pLastCloneImageDict;
- FX_BOOL m_bReleaseLastDict;
- FX_BOOL m_bSameLastDict;
void SetGraphicStates(CPDF_PageObject* pObj, FX_BOOL bColor, FX_BOOL bText, FX_BOOL bGraph);
- FX_BOOL m_bColored;
- FX_FLOAT m_Type3Data[6];
- FX_BOOL m_bResourceMissing;
- CFX_PtrArray m_StateStack;
void SaveStates(CPDF_AllStates*);
void RestoreStates(CPDF_AllStates*);
CPDF_Font* FindFont(const CFX_ByteString& name);
CPDF_ColorSpace* FindColorSpace(const CFX_ByteString& name);
CPDF_Pattern* FindPattern(const CFX_ByteString& name, FX_BOOL bShading);
CPDF_Object* FindResourceObj(const CFX_ByteStringC& type, const CFX_ByteString& name);
+
+protected:
+ struct OpCode {
+ FX_DWORD m_OpId;
+ void (CPDF_StreamContentParser::*m_OpHandler)();
+ };
+ static const OpCode g_OpCodes[];
+
void Handle_CloseFillStrokePath();
void Handle_FillStrokePath();
void Handle_CloseEOFillStrokePath();
@@ -281,6 +264,47 @@ public:
void Handle_NextLineShowText();
void Handle_NextLineShowText_Space();
void Handle_Invalid();
+
+ CPDF_Document* const m_pDocument;
+ CPDF_Dictionary* m_pPageResources;
+ CPDF_Dictionary* m_pParentResources;
+ CPDF_Dictionary* m_pResources;
+ CPDF_PageObjects* m_pObjectList;
+ int m_Level;
+ CFX_AffineMatrix m_mtContentToUser;
+ CFX_FloatRect m_BBox;
+ CPDF_ParseOptions m_Options;
+ _ContentParam m_ParamBuf1[PARAM_BUF_SIZE];
+ FX_DWORD m_ParamStartPos;
+ FX_DWORD m_ParamCount;
+ FX_BOOL m_bAbort;
+ CPDF_StreamParser* m_pSyntax;
+ nonstd::unique_ptr<CPDF_AllStates> m_pCurStates;
+ CPDF_ContentMark m_CurContentMark;
+ CFX_PtrArray m_ClipTextList;
+ CPDF_TextObject* m_pLastTextObject;
+ FX_FLOAT m_DefFontSize;
+ int m_CompatCount;
+ FX_PATHPOINT* m_pPathPoints;
+ int m_PathPointCount;
+ int m_PathAllocSize;
+ FX_FLOAT m_PathStartX;
+ FX_FLOAT m_PathStartY;
+ FX_FLOAT m_PathCurrentX;
+ FX_FLOAT m_PathCurrentY;
+ int m_PathClipType;
+ CFX_ByteString m_LastImageName;
+ CPDF_Image* m_pLastImage;
+ CFX_BinaryBuf m_LastImageDict;
+ CFX_BinaryBuf m_LastImageData;
+ CPDF_Dictionary* m_pLastImageDict;
+ CPDF_Dictionary* m_pLastCloneImageDict;
+ FX_BOOL m_bReleaseLastDict;
+ FX_BOOL m_bSameLastDict;
+ FX_BOOL m_bColored;
+ FX_FLOAT m_Type3Data[6];
+ FX_BOOL m_bResourceMissing;
+ CFX_PtrArray m_StateStack;
};
class CPDF_ContentParser
{