summaryrefslogtreecommitdiff
path: root/core/fpdfapi/fpdf_page
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2016-03-21 09:15:45 -0400
committerDan Sinclair <dsinclair@chromium.org>2016-03-21 09:15:45 -0400
commit584b1e679f41a580e2b38d5534f126355c78043b (patch)
treeca3f78bc30673b9c4650433168efe574920c60f1 /core/fpdfapi/fpdf_page
parentedbb319d3143692befdbb0603089b7e265cf89aa (diff)
downloadpdfium-584b1e679f41a580e2b38d5534f126355c78043b.tar.xz
Move core/include/fpdfapi/fpdf_pageobj.h into core/fpdfapi.
This CL splits the file into individual classes and moves them into core/fpdfapi/fpdf_page as needed. R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1811053002 .
Diffstat (limited to 'core/fpdfapi/fpdf_page')
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_allstates.cpp185
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_allstates.h39
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_clippath.cpp131
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_clippathdata.cpp77
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_clippathdata.h30
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_colorstate.cpp70
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_colorstate.h41
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_colorstatedata.cpp20
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_colorstatedata.h26
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_contentmark.cpp38
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_contentmark.h23
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_contentmarkdata.cpp51
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_contentmarkdata.h38
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_contentmarkitem.cpp36
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_contentmarkitem.h39
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_form.cpp1
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_formobject.cpp38
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_generalstate.cpp29
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_generalstatedata.cpp95
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_graphicstates.cpp19
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_graphicstates.h28
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_graphstate.h14
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_imageobject.cpp44
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_page.cpp185
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_pageobject.cpp43
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_pageobjectholder.cpp1
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_pageobjectlist.cpp1
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_pathobject.cpp (renamed from core/fpdfapi/fpdf_page/fpdf_page_path.cpp)6
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_shadingobject.cpp54
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_textobject.cpp (renamed from core/fpdfapi/fpdf_page/fpdf_page.cpp)295
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_textstate.cpp47
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_textstate.h28
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_textstatedata.cpp43
-rw-r--r--core/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp694
-rw-r--r--core/fpdfapi/fpdf_page/fpdf_page_image.cpp33
-rw-r--r--core/fpdfapi/fpdf_page/fpdf_page_parser.cpp7
-rw-r--r--core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp3
-rw-r--r--core/fpdfapi/fpdf_page/include/cpdf_clippath.h34
-rw-r--r--core/fpdfapi/fpdf_page/include/cpdf_formobject.h34
-rw-r--r--core/fpdfapi/fpdf_page/include/cpdf_generalstate.h29
-rw-r--r--core/fpdfapi/fpdf_page/include/cpdf_generalstatedata.h49
-rw-r--r--core/fpdfapi/fpdf_page/include/cpdf_imageobject.h34
-rw-r--r--core/fpdfapi/fpdf_page/include/cpdf_page.h3
-rw-r--r--core/fpdfapi/fpdf_page/include/cpdf_pageobject.h71
-rw-r--r--core/fpdfapi/fpdf_page/include/cpdf_path.h50
-rw-r--r--core/fpdfapi/fpdf_page/include/cpdf_pathobject.h36
-rw-r--r--core/fpdfapi/fpdf_page/include/cpdf_shadingobject.h34
-rw-r--r--core/fpdfapi/fpdf_page/include/cpdf_textobject.h69
-rw-r--r--core/fpdfapi/fpdf_page/include/cpdf_textstatedata.h31
-rw-r--r--core/fpdfapi/fpdf_page/pageint.h27
50 files changed, 2015 insertions, 1038 deletions
diff --git a/core/fpdfapi/fpdf_page/cpdf_allstates.cpp b/core/fpdfapi/fpdf_page/cpdf_allstates.cpp
new file mode 100644
index 0000000000..96ccc77f81
--- /dev/null
+++ b/core/fpdfapi/fpdf_page/cpdf_allstates.cpp
@@ -0,0 +1,185 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "core/fpdfapi/fpdf_page/cpdf_allstates.h"
+
+#include "core/fpdfapi/fpdf_page/pageint.h"
+#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
+
+namespace {
+
+FX_FLOAT ClipFloat(FX_FLOAT f) {
+ return std::max(0.0f, std::min(1.0f, f));
+}
+
+} // namespace
+
+CPDF_AllStates::CPDF_AllStates() {
+ m_TextX = m_TextY = m_TextLineX = m_TextLineY = 0;
+ m_TextLeading = 0;
+ m_TextRise = 0;
+ m_TextHorzScale = 1.0f;
+}
+
+CPDF_AllStates::~CPDF_AllStates() {}
+
+void CPDF_AllStates::Copy(const CPDF_AllStates& src) {
+ CopyStates(src);
+ m_TextMatrix.Copy(src.m_TextMatrix);
+ m_ParentMatrix.Copy(src.m_ParentMatrix);
+ m_CTM.Copy(src.m_CTM);
+ m_TextX = src.m_TextX;
+ m_TextY = src.m_TextY;
+ m_TextLineX = src.m_TextLineX;
+ m_TextLineY = src.m_TextLineY;
+ m_TextLeading = src.m_TextLeading;
+ m_TextRise = src.m_TextRise;
+ m_TextHorzScale = src.m_TextHorzScale;
+}
+
+void CPDF_AllStates::SetLineDash(CPDF_Array* pArray,
+ FX_FLOAT phase,
+ FX_FLOAT scale) {
+ CFX_GraphStateData* pData = m_GraphState.GetModify();
+ pData->m_DashPhase = phase * scale;
+ pData->SetDashCount(pArray->GetCount());
+ for (FX_DWORD i = 0; i < pArray->GetCount(); i++) {
+ pData->m_DashArray[i] = pArray->GetNumberAt(i) * scale;
+ }
+}
+
+void CPDF_AllStates::ProcessExtGS(CPDF_Dictionary* pGS,
+ CPDF_StreamContentParser* pParser) {
+ CPDF_GeneralStateData* pGeneralState = m_GeneralState.GetModify();
+ for (const auto& it : *pGS) {
+ const CFX_ByteString& key_str = it.first;
+ CPDF_Object* pElement = it.second;
+ CPDF_Object* pObject = pElement ? pElement->GetDirect() : nullptr;
+ if (!pObject)
+ continue;
+
+ FX_DWORD key = key_str.GetID();
+ switch (key) {
+ case FXBSTR_ID('L', 'W', 0, 0):
+ m_GraphState.GetModify()->m_LineWidth = pObject->GetNumber();
+ break;
+ case FXBSTR_ID('L', 'C', 0, 0):
+ m_GraphState.GetModify()->m_LineCap =
+ (CFX_GraphStateData::LineCap)pObject->GetInteger();
+ break;
+ case FXBSTR_ID('L', 'J', 0, 0):
+ m_GraphState.GetModify()->m_LineJoin =
+ (CFX_GraphStateData::LineJoin)pObject->GetInteger();
+ break;
+ case FXBSTR_ID('M', 'L', 0, 0):
+ m_GraphState.GetModify()->m_MiterLimit = pObject->GetNumber();
+ break;
+ case FXBSTR_ID('D', 0, 0, 0): {
+ CPDF_Array* pDash = pObject->AsArray();
+ if (!pDash)
+ break;
+
+ CPDF_Array* pArray = pDash->GetArrayAt(0);
+ if (!pArray)
+ break;
+
+ SetLineDash(pArray, pDash->GetNumberAt(1), 1.0f);
+ break;
+ }
+ case FXBSTR_ID('R', 'I', 0, 0):
+ m_GeneralState.SetRenderIntent(pObject->GetString());
+ break;
+ case FXBSTR_ID('F', 'o', 'n', 't'): {
+ CPDF_Array* pFont = pObject->AsArray();
+ if (!pFont)
+ break;
+
+ m_TextState.GetModify()->m_FontSize = pFont->GetNumberAt(1);
+ m_TextState.SetFont(pParser->FindFont(pFont->GetStringAt(0)));
+ break;
+ }
+ case FXBSTR_ID('T', 'R', 0, 0):
+ if (pGS->KeyExist("TR2")) {
+ continue;
+ }
+ case FXBSTR_ID('T', 'R', '2', 0):
+ pGeneralState->m_pTR =
+ (pObject && !pObject->IsName()) ? pObject : nullptr;
+ break;
+ case FXBSTR_ID('B', 'M', 0, 0): {
+ CPDF_Array* pArray = pObject->AsArray();
+ CFX_ByteString mode =
+ pArray ? pArray->GetStringAt(0) : pObject->GetString();
+
+ pGeneralState->SetBlendMode(mode);
+ if (pGeneralState->m_BlendType > FXDIB_BLEND_MULTIPLY) {
+ pParser->GetPageObjectHolder()->SetBackgroundAlphaNeeded(TRUE);
+ }
+ break;
+ }
+ case FXBSTR_ID('S', 'M', 'a', 's'):
+ if (ToDictionary(pObject)) {
+ pGeneralState->m_pSoftMask = pObject;
+ FXSYS_memcpy(pGeneralState->m_SMaskMatrix,
+ &pParser->GetCurStates()->m_CTM, sizeof(CFX_Matrix));
+ } else {
+ pGeneralState->m_pSoftMask = NULL;
+ }
+ break;
+ case FXBSTR_ID('C', 'A', 0, 0):
+ pGeneralState->m_StrokeAlpha = ClipFloat(pObject->GetNumber());
+ break;
+ case FXBSTR_ID('c', 'a', 0, 0):
+ pGeneralState->m_FillAlpha = ClipFloat(pObject->GetNumber());
+ break;
+ case FXBSTR_ID('O', 'P', 0, 0):
+ pGeneralState->m_StrokeOP = pObject->GetInteger();
+ if (!pGS->KeyExist("op")) {
+ pGeneralState->m_FillOP = pObject->GetInteger();
+ }
+ break;
+ case FXBSTR_ID('o', 'p', 0, 0):
+ pGeneralState->m_FillOP = pObject->GetInteger();
+ break;
+ case FXBSTR_ID('O', 'P', 'M', 0):
+ pGeneralState->m_OPMode = pObject->GetInteger();
+ break;
+ case FXBSTR_ID('B', 'G', 0, 0):
+ if (pGS->KeyExist("BG2")) {
+ continue;
+ }
+ case FXBSTR_ID('B', 'G', '2', 0):
+ pGeneralState->m_pBG = pObject;
+ break;
+ case FXBSTR_ID('U', 'C', 'R', 0):
+ if (pGS->KeyExist("UCR2")) {
+ continue;
+ }
+ case FXBSTR_ID('U', 'C', 'R', '2'):
+ pGeneralState->m_pUCR = pObject;
+ break;
+ case FXBSTR_ID('H', 'T', 0, 0):
+ pGeneralState->m_pHT = pObject;
+ break;
+ case FXBSTR_ID('F', 'L', 0, 0):
+ pGeneralState->m_Flatness = pObject->GetNumber();
+ break;
+ case FXBSTR_ID('S', 'M', 0, 0):
+ pGeneralState->m_Smoothness = pObject->GetNumber();
+ break;
+ case FXBSTR_ID('S', 'A', 0, 0):
+ pGeneralState->m_StrokeAdjust = pObject->GetInteger();
+ break;
+ case FXBSTR_ID('A', 'I', 'S', 0):
+ pGeneralState->m_AlphaSource = pObject->GetInteger();
+ break;
+ case FXBSTR_ID('T', 'K', 0, 0):
+ pGeneralState->m_TextKnockout = pObject->GetInteger();
+ break;
+ }
+ }
+ pGeneralState->m_Matrix = m_CTM;
+}
diff --git a/core/fpdfapi/fpdf_page/cpdf_allstates.h b/core/fpdfapi/fpdf_page/cpdf_allstates.h
new file mode 100644
index 0000000000..700072f26c
--- /dev/null
+++ b/core/fpdfapi/fpdf_page/cpdf_allstates.h
@@ -0,0 +1,39 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef CORE_FPDFAPI_FPDF_PAGE_CPDF_ALLSTATES_H_
+#define CORE_FPDFAPI_FPDF_PAGE_CPDF_ALLSTATES_H_
+
+#include "core/fpdfapi/fpdf_page/cpdf_graphicstates.h"
+#include "core/include/fxcrt/fx_coordinates.h"
+#include "core/include/fxcrt/fx_system.h"
+
+class CPDF_Array;
+class CPDF_Dictionary;
+class CPDF_StreamContentParser;
+
+class CPDF_AllStates : public CPDF_GraphicStates {
+ public:
+ CPDF_AllStates();
+ ~CPDF_AllStates();
+
+ void Copy(const CPDF_AllStates& src);
+ void ProcessExtGS(CPDF_Dictionary* pGS, CPDF_StreamContentParser* pParser);
+ void SetLineDash(CPDF_Array*, FX_FLOAT, FX_FLOAT scale);
+
+ CFX_Matrix m_TextMatrix;
+ CFX_Matrix m_CTM;
+ CFX_Matrix m_ParentMatrix;
+ FX_FLOAT m_TextX;
+ FX_FLOAT m_TextY;
+ FX_FLOAT m_TextLineX;
+ FX_FLOAT m_TextLineY;
+ FX_FLOAT m_TextLeading;
+ FX_FLOAT m_TextRise;
+ FX_FLOAT m_TextHorzScale;
+};
+
+#endif // CORE_FPDFAPI_FPDF_PAGE_CPDF_ALLSTATES_H_
diff --git a/core/fpdfapi/fpdf_page/cpdf_clippath.cpp b/core/fpdfapi/fpdf_page/cpdf_clippath.cpp
new file mode 100644
index 0000000000..3a3300ae2f
--- /dev/null
+++ b/core/fpdfapi/fpdf_page/cpdf_clippath.cpp
@@ -0,0 +1,131 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "core/fpdfapi/fpdf_page/include/cpdf_clippath.h"
+
+#include "core/fpdfapi/fpdf_page/include/cpdf_textobject.h"
+
+#define FPDF_CLIPPATH_MAX_TEXTS 1024
+
+CFX_FloatRect CPDF_ClipPath::GetClipBox() const {
+ CFX_FloatRect rect;
+ FX_BOOL bStarted = FALSE;
+ int count = GetPathCount();
+ if (count) {
+ rect = GetPath(0).GetBoundingBox();
+ for (int i = 1; i < count; i++) {
+ CFX_FloatRect path_rect = GetPath(i).GetBoundingBox();
+ rect.Intersect(path_rect);
+ }
+ bStarted = TRUE;
+ }
+ count = GetTextCount();
+ if (count) {
+ CFX_FloatRect layer_rect;
+ FX_BOOL bLayerStarted = FALSE;
+ for (int i = 0; i < count; i++) {
+ CPDF_TextObject* pTextObj = GetText(i);
+ if (!pTextObj) {
+ if (!bStarted) {
+ rect = layer_rect;
+ bStarted = TRUE;
+ } else {
+ rect.Intersect(layer_rect);
+ }
+ bLayerStarted = FALSE;
+ } else {
+ if (!bLayerStarted) {
+ layer_rect = CFX_FloatRect(pTextObj->GetBBox(nullptr));
+ bLayerStarted = TRUE;
+ } else {
+ layer_rect.Union(CFX_FloatRect(pTextObj->GetBBox(nullptr)));
+ }
+ }
+ }
+ }
+ return rect;
+}
+
+void CPDF_ClipPath::AppendPath(CPDF_Path path, int type, FX_BOOL bAutoMerge) {
+ CPDF_ClipPathData* pData = GetModify();
+ if (pData->m_PathCount && bAutoMerge) {
+ CPDF_Path old_path = pData->m_pPathList[pData->m_PathCount - 1];
+ if (old_path.IsRect()) {
+ CFX_FloatRect old_rect(old_path.GetPointX(0), old_path.GetPointY(0),
+ old_path.GetPointX(2), old_path.GetPointY(2));
+ CFX_FloatRect new_rect = path.GetBoundingBox();
+ if (old_rect.Contains(new_rect)) {
+ pData->m_PathCount--;
+ pData->m_pPathList[pData->m_PathCount].SetNull();
+ }
+ }
+ }
+ if (pData->m_PathCount % 8 == 0) {
+ CPDF_Path* pNewPath = new CPDF_Path[pData->m_PathCount + 8];
+ for (int i = 0; i < pData->m_PathCount; i++) {
+ pNewPath[i] = pData->m_pPathList[i];
+ }
+ delete[] pData->m_pPathList;
+ uint8_t* pNewType = FX_Alloc(uint8_t, pData->m_PathCount + 8);
+ FXSYS_memcpy(pNewType, pData->m_pTypeList, pData->m_PathCount);
+ FX_Free(pData->m_pTypeList);
+ pData->m_pPathList = pNewPath;
+ pData->m_pTypeList = pNewType;
+ }
+ pData->m_pPathList[pData->m_PathCount] = path;
+ pData->m_pTypeList[pData->m_PathCount] = (uint8_t)type;
+ pData->m_PathCount++;
+}
+
+void CPDF_ClipPath::DeletePath(int index) {
+ CPDF_ClipPathData* pData = GetModify();
+ if (index >= pData->m_PathCount) {
+ return;
+ }
+ pData->m_pPathList[index].SetNull();
+ for (int i = index; i < pData->m_PathCount - 1; i++) {
+ pData->m_pPathList[i] = pData->m_pPathList[i + 1];
+ }
+ pData->m_pPathList[pData->m_PathCount - 1].SetNull();
+ FXSYS_memmove(pData->m_pTypeList + index, pData->m_pTypeList + index + 1,
+ pData->m_PathCount - index - 1);
+ pData->m_PathCount--;
+}
+
+void CPDF_ClipPath::AppendTexts(CPDF_TextObject** pTexts, int count) {
+ CPDF_ClipPathData* pData = GetModify();
+ if (pData->m_TextCount + count > FPDF_CLIPPATH_MAX_TEXTS) {
+ for (int i = 0; i < count; i++) {
+ delete pTexts[i];
+ }
+ return;
+ }
+ CPDF_TextObject** pNewList =
+ FX_Alloc(CPDF_TextObject*, pData->m_TextCount + count + 1);
+ if (pData->m_pTextList) {
+ FXSYS_memcpy(pNewList, pData->m_pTextList,
+ pData->m_TextCount * sizeof(CPDF_TextObject*));
+ FX_Free(pData->m_pTextList);
+ }
+ pData->m_pTextList = pNewList;
+ for (int i = 0; i < count; i++) {
+ pData->m_pTextList[pData->m_TextCount + i] = pTexts[i];
+ }
+ pData->m_pTextList[pData->m_TextCount + count] = NULL;
+ pData->m_TextCount += count + 1;
+}
+
+void CPDF_ClipPath::Transform(const CFX_Matrix& matrix) {
+ CPDF_ClipPathData* pData = GetModify();
+ int i;
+ for (i = 0; i < pData->m_PathCount; i++) {
+ pData->m_pPathList[i].Transform(&matrix);
+ }
+ for (i = 0; i < pData->m_TextCount; i++)
+ if (pData->m_pTextList[i]) {
+ pData->m_pTextList[i]->Transform(matrix);
+ }
+}
diff --git a/core/fpdfapi/fpdf_page/cpdf_clippathdata.cpp b/core/fpdfapi/fpdf_page/cpdf_clippathdata.cpp
new file mode 100644
index 0000000000..e6a5227269
--- /dev/null
+++ b/core/fpdfapi/fpdf_page/cpdf_clippathdata.cpp
@@ -0,0 +1,77 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "core/fpdfapi/fpdf_page/cpdf_clippathdata.h"
+
+#include "core/fpdfapi/fpdf_page/include/cpdf_path.h"
+#include "core/fpdfapi/fpdf_page/include/cpdf_textobject.h"
+
+CPDF_ClipPathData::CPDF_ClipPathData()
+ : m_PathCount(0),
+ m_pPathList(nullptr),
+ m_pTypeList(nullptr),
+ m_TextCount(0),
+ m_pTextList(nullptr) {}
+
+CPDF_ClipPathData::~CPDF_ClipPathData() {
+ delete[] m_pPathList;
+ FX_Free(m_pTypeList);
+
+ for (int i = m_TextCount - 1; i > -1; i--)
+ delete m_pTextList[i];
+ FX_Free(m_pTextList);
+}
+
+CPDF_ClipPathData::CPDF_ClipPathData(const CPDF_ClipPathData& src) {
+ m_pPathList = nullptr;
+ m_pPathList = nullptr;
+ m_pTextList = nullptr;
+
+ m_PathCount = src.m_PathCount;
+ if (m_PathCount) {
+ int alloc_size = m_PathCount;
+ if (alloc_size % 8)
+ alloc_size += 8 - (alloc_size % 8);
+
+ m_pPathList = new CPDF_Path[alloc_size];
+ for (int i = 0; i < m_PathCount; i++)
+ m_pPathList[i] = src.m_pPathList[i];
+
+ m_pTypeList = FX_Alloc(uint8_t, alloc_size);
+ FXSYS_memcpy(m_pTypeList, src.m_pTypeList, m_PathCount);
+ } else {
+ m_pPathList = nullptr;
+ m_pTypeList = nullptr;
+ }
+
+ m_TextCount = src.m_TextCount;
+ if (m_TextCount) {
+ m_pTextList = FX_Alloc(CPDF_TextObject*, m_TextCount);
+ for (int i = 0; i < m_TextCount; i++) {
+ if (src.m_pTextList[i])
+ m_pTextList[i] = src.m_pTextList[i]->Clone();
+ else
+ m_pTextList[i] = nullptr;
+ }
+ } else {
+ m_pTextList = nullptr;
+ }
+}
+
+void CPDF_ClipPathData::SetCount(int path_count, int text_count) {
+ ASSERT(m_TextCount == 0 && m_PathCount == 0);
+ if (path_count) {
+ m_PathCount = path_count;
+ int alloc_size = (path_count + 7) / 8 * 8;
+ m_pPathList = new CPDF_Path[alloc_size];
+ m_pTypeList = FX_Alloc(uint8_t, alloc_size);
+ }
+
+ if (text_count) {
+ m_TextCount = text_count;
+ m_pTextList = FX_Alloc(CPDF_TextObject*, text_count);
+ }
+}
diff --git a/core/fpdfapi/fpdf_page/cpdf_clippathdata.h b/core/fpdfapi/fpdf_page/cpdf_clippathdata.h
new file mode 100644
index 0000000000..05a247f753
--- /dev/null
+++ b/core/fpdfapi/fpdf_page/cpdf_clippathdata.h
@@ -0,0 +1,30 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef CORE_FPDFAPI_FPDF_PAGE_CPDF_CLIPPATHDATA_H_
+#define CORE_FPDFAPI_FPDF_PAGE_CPDF_CLIPPATHDATA_H_
+
+#include <stdint.h>
+
+class CPDF_Path;
+class CPDF_TextObject;
+
+class CPDF_ClipPathData {
+ public:
+ CPDF_ClipPathData();
+ CPDF_ClipPathData(const CPDF_ClipPathData&);
+ ~CPDF_ClipPathData();
+
+ void SetCount(int path_count, int text_count);
+
+ int m_PathCount;
+ CPDF_Path* m_pPathList;
+ uint8_t* m_pTypeList;
+ int m_TextCount;
+ CPDF_TextObject** m_pTextList;
+};
+
+#endif // CORE_FPDFAPI_FPDF_PAGE_CPDF_CLIPPATHDATA_H_
diff --git a/core/fpdfapi/fpdf_page/cpdf_colorstate.cpp b/core/fpdfapi/fpdf_page/cpdf_colorstate.cpp
new file mode 100644
index 0000000000..02999c9d13
--- /dev/null
+++ b/core/fpdfapi/fpdf_page/cpdf_colorstate.cpp
@@ -0,0 +1,70 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "core/fpdfapi/fpdf_page/cpdf_colorstate.h"
+
+void CPDF_ColorState::SetFillColor(CPDF_ColorSpace* pCS,
+ FX_FLOAT* pValue,
+ int nValues) {
+ CPDF_ColorStateData* pData = GetModify();
+ SetColor(pData->m_FillColor, pData->m_FillRGB, pCS, pValue, nValues);
+}
+
+void CPDF_ColorState::SetStrokeColor(CPDF_ColorSpace* pCS,
+ FX_FLOAT* pValue,
+ int nValues) {
+ CPDF_ColorStateData* pData = GetModify();
+ SetColor(pData->m_StrokeColor, pData->m_StrokeRGB, pCS, pValue, nValues);
+}
+
+void CPDF_ColorState::SetColor(CPDF_Color& color,
+ FX_DWORD& rgb,
+ CPDF_ColorSpace* pCS,
+ FX_FLOAT* pValue,
+ int nValues) {
+ if (pCS) {
+ color.SetColorSpace(pCS);
+ } else if (color.IsNull()) {
+ color.SetColorSpace(CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY));
+ }
+ if (color.m_pCS->CountComponents() > nValues) {
+ return;
+ }
+ color.SetValue(pValue);
+ int R, G, B;
+ rgb = color.GetRGB(R, G, B) ? FXSYS_RGB(R, G, B) : (FX_DWORD)-1;
+}
+
+void CPDF_ColorState::SetFillPattern(CPDF_Pattern* pPattern,
+ FX_FLOAT* pValue,
+ int nValues) {
+ CPDF_ColorStateData* pData = GetModify();
+ pData->m_FillColor.SetValue(pPattern, pValue, nValues);
+ int R, G, B;
+ FX_BOOL ret = pData->m_FillColor.GetRGB(R, G, B);
+ if (pPattern->m_PatternType == 1 &&
+ ((CPDF_TilingPattern*)pPattern)->m_bColored && !ret) {
+ pData->m_FillRGB = 0x00BFBFBF;
+ return;
+ }
+ pData->m_FillRGB = ret ? FXSYS_RGB(R, G, B) : (FX_DWORD)-1;
+}
+
+void CPDF_ColorState::SetStrokePattern(CPDF_Pattern* pPattern,
+ FX_FLOAT* pValue,
+ int nValues) {
+ CPDF_ColorStateData* pData = GetModify();
+ pData->m_StrokeColor.SetValue(pPattern, pValue, nValues);
+ int R, G, B;
+ FX_BOOL ret = pData->m_StrokeColor.GetRGB(R, G, B);
+ if (pPattern->m_PatternType == 1 &&
+ ((CPDF_TilingPattern*)pPattern)->m_bColored && !ret) {
+ pData->m_StrokeRGB = 0x00BFBFBF;
+ return;
+ }
+ pData->m_StrokeRGB =
+ pData->m_StrokeColor.GetRGB(R, G, B) ? FXSYS_RGB(R, G, B) : (FX_DWORD)-1;
+}
diff --git a/core/fpdfapi/fpdf_page/cpdf_colorstate.h b/core/fpdfapi/fpdf_page/cpdf_colorstate.h
new file mode 100644
index 0000000000..77a506e1b4
--- /dev/null
+++ b/core/fpdfapi/fpdf_page/cpdf_colorstate.h
@@ -0,0 +1,41 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef CORE_FPDFAPI_FPDF_PAGE_CPDF_COLORSTATE_H_
+#define CORE_FPDFAPI_FPDF_PAGE_CPDF_COLORSTATE_H_
+
+#include "core/fpdfapi/fpdf_page/cpdf_colorstatedata.h"
+#include "core/include/fxcrt/fx_basic.h"
+#include "core/include/fxcrt/fx_system.h"
+
+class CPDF_Color;
+class CPDF_ColorSpace;
+class CPDF_Pattern;
+
+class CPDF_ColorState : public CFX_CountRef<CPDF_ColorStateData> {
+ public:
+ CPDF_Color* GetFillColor() const {
+ return m_pObject ? &m_pObject->m_FillColor : nullptr;
+ }
+
+ CPDF_Color* GetStrokeColor() const {
+ return m_pObject ? &m_pObject->m_StrokeColor : nullptr;
+ }
+
+ void SetFillColor(CPDF_ColorSpace* pCS, FX_FLOAT* pValue, int nValues);
+ void SetStrokeColor(CPDF_ColorSpace* pCS, FX_FLOAT* pValue, int nValues);
+ void SetFillPattern(CPDF_Pattern* pattern, FX_FLOAT* pValue, int nValues);
+ void SetStrokePattern(CPDF_Pattern* pattern, FX_FLOAT* pValue, int nValues);
+
+ private:
+ void SetColor(CPDF_Color& color,
+ FX_DWORD& rgb,
+ CPDF_ColorSpace* pCS,
+ FX_FLOAT* pValue,
+ int nValues);
+};
+
+#endif // CORE_FPDFAPI_FPDF_PAGE_CPDF_COLORSTATE_H_
diff --git a/core/fpdfapi/fpdf_page/cpdf_colorstatedata.cpp b/core/fpdfapi/fpdf_page/cpdf_colorstatedata.cpp
new file mode 100644
index 0000000000..9dbcdec267
--- /dev/null
+++ b/core/fpdfapi/fpdf_page/cpdf_colorstatedata.cpp
@@ -0,0 +1,20 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "core/fpdfapi/fpdf_page/cpdf_colorstatedata.h"
+
+CPDF_ColorStateData::CPDF_ColorStateData(const CPDF_ColorStateData& src) {
+ m_FillColor.Copy(&src.m_FillColor);
+ m_FillRGB = src.m_FillRGB;
+ m_StrokeColor.Copy(&src.m_StrokeColor);
+ m_StrokeRGB = src.m_StrokeRGB;
+}
+
+void CPDF_ColorStateData::Default() {
+ m_FillRGB = m_StrokeRGB = 0;
+ m_FillColor.SetColorSpace(CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY));
+ m_StrokeColor.SetColorSpace(CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY));
+}
diff --git a/core/fpdfapi/fpdf_page/cpdf_colorstatedata.h b/core/fpdfapi/fpdf_page/cpdf_colorstatedata.h
new file mode 100644
index 0000000000..304410b553
--- /dev/null
+++ b/core/fpdfapi/fpdf_page/cpdf_colorstatedata.h
@@ -0,0 +1,26 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef CORE_FPDFAPI_FPDF_PAGE_CPDF_COLORSTATEDATA_H_
+#define CORE_FPDFAPI_FPDF_PAGE_CPDF_COLORSTATEDATA_H_
+
+#include "core/include/fpdfapi/fpdf_resource.h"
+#include "core/include/fxcrt/fx_system.h"
+
+class CPDF_ColorStateData {
+ public:
+ CPDF_ColorStateData() : m_FillRGB(0), m_StrokeRGB(0) {}
+ CPDF_ColorStateData(const CPDF_ColorStateData& src);
+
+ void Default();
+
+ CPDF_Color m_FillColor;
+ FX_DWORD m_FillRGB;
+ CPDF_Color m_StrokeColor;
+ FX_DWORD m_StrokeRGB;
+};
+
+#endif // CORE_FPDFAPI_FPDF_PAGE_CPDF_COLORSTATEDATA_H_
diff --git a/core/fpdfapi/fpdf_page/cpdf_contentmark.cpp b/core/fpdfapi/fpdf_page/cpdf_contentmark.cpp
new file mode 100644
index 0000000000..6e85d2940f
--- /dev/null
+++ b/core/fpdfapi/fpdf_page/cpdf_contentmark.cpp
@@ -0,0 +1,38 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "core/fpdfapi/fpdf_page/cpdf_contentmark.h"
+
+FX_BOOL CPDF_ContentMark::HasMark(const CFX_ByteStringC& mark) const {
+ if (!m_pObject)
+ return FALSE;
+
+ for (int i = 0; i < m_pObject->CountItems(); i++) {
+ CPDF_ContentMarkItem& item = m_pObject->GetItem(i);
+ if (item.GetName() == mark)
+ return TRUE;
+ }
+ return FALSE;
+}
+
+FX_BOOL CPDF_ContentMark::LookupMark(const CFX_ByteStringC& mark,
+ CPDF_Dictionary*& pDict) const {
+ if (!m_pObject)
+ return FALSE;
+
+ for (int i = 0; i < m_pObject->CountItems(); i++) {
+ CPDF_ContentMarkItem& item = m_pObject->GetItem(i);
+ if (item.GetName() == mark) {
+ pDict = nullptr;
+ if (item.GetParamType() == CPDF_ContentMarkItem::PropertiesDict ||
+ item.GetParamType() == CPDF_ContentMarkItem::DirectDict) {
+ pDict = item.GetParam();
+ }
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
diff --git a/core/fpdfapi/fpdf_page/cpdf_contentmark.h b/core/fpdfapi/fpdf_page/cpdf_contentmark.h
new file mode 100644
index 0000000000..35e4a9664b
--- /dev/null
+++ b/core/fpdfapi/fpdf_page/cpdf_contentmark.h
@@ -0,0 +1,23 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef CORE_FPDFAPI_FPDF_PAGE_CPDF_CONTENTMARK_H_
+#define CORE_FPDFAPI_FPDF_PAGE_CPDF_CONTENTMARK_H_
+
+#include "core/fpdfapi/fpdf_page/cpdf_contentmarkdata.h"
+#include "core/include/fxcrt/fx_basic.h"
+
+class CPDF_ContentMark : public CFX_CountRef<CPDF_ContentMarkData> {
+ public:
+ int GetMCID() const { return m_pObject ? m_pObject->GetMCID() : -1; }
+
+ FX_BOOL HasMark(const CFX_ByteStringC& mark) const;
+
+ FX_BOOL LookupMark(const CFX_ByteStringC& mark,
+ CPDF_Dictionary*& pDict) const;
+};
+
+#endif // CORE_FPDFAPI_FPDF_PAGE_CPDF_CONTENTMARK_H_
diff --git a/core/fpdfapi/fpdf_page/cpdf_contentmarkdata.cpp b/core/fpdfapi/fpdf_page/cpdf_contentmarkdata.cpp
new file mode 100644
index 0000000000..076e8ac521
--- /dev/null
+++ b/core/fpdfapi/fpdf_page/cpdf_contentmarkdata.cpp
@@ -0,0 +1,51 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "core/fpdfapi/fpdf_page/cpdf_contentmarkdata.h"
+
+#include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h"
+#include "third_party/base/stl_util.h"
+
+CPDF_ContentMarkData::CPDF_ContentMarkData(const CPDF_ContentMarkData& src)
+ : m_Marks(src.m_Marks) {}
+
+int CPDF_ContentMarkData::CountItems() const {
+ return pdfium::CollectionSize<int>(m_Marks);
+}
+
+int CPDF_ContentMarkData::GetMCID() const {
+ for (const auto& mark : m_Marks) {
+ CPDF_ContentMarkItem::ParamType type = mark.GetParamType();
+ if (type == CPDF_ContentMarkItem::PropertiesDict ||
+ type == CPDF_ContentMarkItem::DirectDict) {
+ CPDF_Dictionary* pDict = mark.GetParam();
+ if (pDict->KeyExist("MCID"))
+ return pDict->GetIntegerBy("MCID");
+ }
+ }
+ return -1;
+}
+
+void CPDF_ContentMarkData::AddMark(const CFX_ByteString& name,
+ CPDF_Dictionary* pDict,
+ FX_BOOL bDirect) {
+ CPDF_ContentMarkItem item;
+ item.SetName(name);
+ if (pDict) {
+ if (bDirect) {
+ item.SetParam(CPDF_ContentMarkItem::DirectDict,
+ ToDictionary(pDict->Clone()));
+ } else {
+ item.SetParam(CPDF_ContentMarkItem::PropertiesDict, pDict);
+ }
+ }
+ m_Marks.push_back(item);
+}
+
+void CPDF_ContentMarkData::DeleteLastMark() {
+ if (!m_Marks.empty())
+ m_Marks.pop_back();
+}
diff --git a/core/fpdfapi/fpdf_page/cpdf_contentmarkdata.h b/core/fpdfapi/fpdf_page/cpdf_contentmarkdata.h
new file mode 100644
index 0000000000..4cf859fda9
--- /dev/null
+++ b/core/fpdfapi/fpdf_page/cpdf_contentmarkdata.h
@@ -0,0 +1,38 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef CORE_FPDFAPI_FPDF_PAGE_CPDF_CONTENTMARKDATA_H_
+#define CORE_FPDFAPI_FPDF_PAGE_CPDF_CONTENTMARKDATA_H_
+
+#include <vector>
+
+#include "core/fpdfapi/fpdf_page/cpdf_contentmarkitem.h"
+#include "core/include/fxcrt/fx_system.h"
+
+class CPDF_Dictionary;
+
+class CPDF_ContentMarkData {
+ public:
+ CPDF_ContentMarkData() {}
+ CPDF_ContentMarkData(const CPDF_ContentMarkData& src);
+
+ int CountItems() const;
+ CPDF_ContentMarkItem& GetItem(int index) { return m_Marks[index]; }
+ const CPDF_ContentMarkItem& GetItem(int index) const {
+ return m_Marks[index];
+ }
+
+ int GetMCID() const;
+ void AddMark(const CFX_ByteString& name,
+ CPDF_Dictionary* pDict,
+ FX_BOOL bDictNeedClone);
+ void DeleteLastMark();
+
+ private:
+ std::vector<CPDF_ContentMarkItem> m_Marks;
+};
+
+#endif // CORE_FPDFAPI_FPDF_PAGE_CPDF_CONTENTMARKDATA_H_
diff --git a/core/fpdfapi/fpdf_page/cpdf_contentmarkitem.cpp b/core/fpdfapi/fpdf_page/cpdf_contentmarkitem.cpp
new file mode 100644
index 0000000000..3b7a60c059
--- /dev/null
+++ b/core/fpdfapi/fpdf_page/cpdf_contentmarkitem.cpp
@@ -0,0 +1,36 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "core/fpdfapi/fpdf_page/cpdf_contentmarkitem.h"
+
+#include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h"
+
+CPDF_ContentMarkItem::CPDF_ContentMarkItem() {
+ m_ParamType = None;
+}
+
+CPDF_ContentMarkItem::CPDF_ContentMarkItem(const CPDF_ContentMarkItem& src) {
+ m_MarkName = src.m_MarkName;
+ m_ParamType = src.m_ParamType;
+ if (m_ParamType == DirectDict) {
+ m_pParam = ToDictionary(src.m_pParam->Clone());
+ } else {
+ m_pParam = src.m_pParam;
+ }
+}
+
+CPDF_ContentMarkItem::~CPDF_ContentMarkItem() {
+ if (m_ParamType == DirectDict && m_pParam)
+ m_pParam->Release();
+}
+
+FX_BOOL CPDF_ContentMarkItem::HasMCID() const {
+ if (m_pParam &&
+ (m_ParamType == DirectDict || m_ParamType == PropertiesDict)) {
+ return m_pParam->KeyExist("MCID");
+ }
+ return FALSE;
+}
diff --git a/core/fpdfapi/fpdf_page/cpdf_contentmarkitem.h b/core/fpdfapi/fpdf_page/cpdf_contentmarkitem.h
new file mode 100644
index 0000000000..0a9ca1a04b
--- /dev/null
+++ b/core/fpdfapi/fpdf_page/cpdf_contentmarkitem.h
@@ -0,0 +1,39 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef CORE_FPDFAPI_FPDF_PAGE_CPDF_CONTENTMARKITEM_H_
+#define CORE_FPDFAPI_FPDF_PAGE_CPDF_CONTENTMARKITEM_H_
+
+#include "core/include/fxcrt/fx_string.h"
+#include "core/include/fxcrt/fx_system.h"
+
+class CPDF_Dictionary;
+
+class CPDF_ContentMarkItem {
+ public:
+ enum ParamType { None, PropertiesDict, DirectDict };
+
+ CPDF_ContentMarkItem();
+ CPDF_ContentMarkItem(const CPDF_ContentMarkItem& src);
+ ~CPDF_ContentMarkItem();
+
+ const CFX_ByteString& GetName() const { return m_MarkName; }
+ ParamType GetParamType() const { return m_ParamType; }
+ CPDF_Dictionary* GetParam() const { return m_pParam; }
+ FX_BOOL HasMCID() const;
+ void SetName(const CFX_ByteString& name) { m_MarkName = name; }
+ void SetParam(ParamType type, CPDF_Dictionary* param) {
+ m_ParamType = type;
+ m_pParam = param;
+ }
+
+ private:
+ CFX_ByteString m_MarkName;
+ ParamType m_ParamType;
+ CPDF_Dictionary* m_pParam;
+};
+
+#endif // CORE_FPDFAPI_FPDF_PAGE_CPDF_CONTENTMARKITEM_H_
diff --git a/core/fpdfapi/fpdf_page/cpdf_form.cpp b/core/fpdfapi/fpdf_page/cpdf_form.cpp
index a1160397fc..403baa2482 100644
--- a/core/fpdfapi/fpdf_page/cpdf_form.cpp
+++ b/core/fpdfapi/fpdf_page/cpdf_form.cpp
@@ -6,6 +6,7 @@
#include "core/fpdfapi/fpdf_page/include/cpdf_form.h"
+#include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h"
#include "core/fpdfapi/fpdf_page/include/cpdf_pageobjectholder.h"
#include "core/fpdfapi/fpdf_page/pageint.h"
#include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h"
diff --git a/core/fpdfapi/fpdf_page/cpdf_formobject.cpp b/core/fpdfapi/fpdf_page/cpdf_formobject.cpp
new file mode 100644
index 0000000000..d85ff7dbb3
--- /dev/null
+++ b/core/fpdfapi/fpdf_page/cpdf_formobject.cpp
@@ -0,0 +1,38 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "core/fpdfapi/fpdf_page/include/cpdf_formobject.h"
+
+#include "core/fpdfapi/fpdf_page/include/cpdf_form.h"
+
+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();
+}
+
+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);
+ m_Left = form_rect.left;
+ m_Bottom = form_rect.bottom;
+ m_Right = form_rect.right;
+ m_Top = form_rect.top;
+}
diff --git a/core/fpdfapi/fpdf_page/cpdf_generalstate.cpp b/core/fpdfapi/fpdf_page/cpdf_generalstate.cpp
new file mode 100644
index 0000000000..11c4dc7701
--- /dev/null
+++ b/core/fpdfapi/fpdf_page/cpdf_generalstate.cpp
@@ -0,0 +1,29 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "core/fpdfapi/fpdf_page/include/cpdf_generalstate.h"
+
+namespace {
+
+int RI_StringToId(const CFX_ByteString& ri) {
+ FX_DWORD id = ri.GetID();
+ if (id == FXBSTR_ID('A', 'b', 's', 'o'))
+ return 1;
+
+ if (id == FXBSTR_ID('S', 'a', 't', 'u'))
+ return 2;
+
+ if (id == FXBSTR_ID('P', 'e', 'r', 'c'))
+ return 3;
+
+ return 0;
+}
+
+} // namespace
+
+void CPDF_GeneralState::SetRenderIntent(const CFX_ByteString& ri) {
+ GetModify()->m_RenderIntent = RI_StringToId(ri);
+}
diff --git a/core/fpdfapi/fpdf_page/cpdf_generalstatedata.cpp b/core/fpdfapi/fpdf_page/cpdf_generalstatedata.cpp
new file mode 100644
index 0000000000..2e4b5e4dff
--- /dev/null
+++ b/core/fpdfapi/fpdf_page/cpdf_generalstatedata.cpp
@@ -0,0 +1,95 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "core/fpdfapi/fpdf_page/include/cpdf_generalstatedata.h"
+
+#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
+#include "core/fpdfapi/fpdf_render/render_int.h"
+
+namespace {
+
+static int GetBlendTypeInternal(const CFX_ByteStringC& mode) {
+ switch (mode.GetID()) {
+ case FXBSTR_ID('N', 'o', 'r', 'm'):
+ case FXBSTR_ID('C', 'o', 'm', 'p'):
+ return FXDIB_BLEND_NORMAL;
+ case FXBSTR_ID('M', 'u', 'l', 't'):
+ return FXDIB_BLEND_MULTIPLY;
+ case FXBSTR_ID('S', 'c', 'r', 'e'):
+ return FXDIB_BLEND_SCREEN;
+ case FXBSTR_ID('O', 'v', 'e', 'r'):
+ return FXDIB_BLEND_OVERLAY;
+ case FXBSTR_ID('D', 'a', 'r', 'k'):
+ return FXDIB_BLEND_DARKEN;
+ case FXBSTR_ID('L', 'i', 'g', 'h'):
+ return FXDIB_BLEND_LIGHTEN;
+ case FXBSTR_ID('C', 'o', 'l', 'o'):
+ if (mode.GetLength() == 10)
+ return FXDIB_BLEND_COLORDODGE;
+
+ if (mode.GetLength() == 9)
+ return FXDIB_BLEND_COLORBURN;
+
+ return FXDIB_BLEND_COLOR;
+ case FXBSTR_ID('H', 'a', 'r', 'd'):
+ return FXDIB_BLEND_HARDLIGHT;
+ case FXBSTR_ID('S', 'o', 'f', 't'):
+ return FXDIB_BLEND_SOFTLIGHT;
+ case FXBSTR_ID('D', 'i', 'f', 'f'):
+ return FXDIB_BLEND_DIFFERENCE;
+ case FXBSTR_ID('E', 'x', 'c', 'l'):
+ return FXDIB_BLEND_EXCLUSION;
+ case FXBSTR_ID('H', 'u', 'e', 0):
+ return FXDIB_BLEND_HUE;
+ case FXBSTR_ID('S', 'a', 't', 'u'):
+ return FXDIB_BLEND_SATURATION;
+ case FXBSTR_ID('L', 'u', 'm', 'i'):
+ return FXDIB_BLEND_LUMINOSITY;
+ }
+ return FXDIB_BLEND_NORMAL;
+}
+
+} // namespace
+
+CPDF_GeneralStateData::CPDF_GeneralStateData() {
+ FXSYS_memset(this, 0, sizeof(CPDF_GeneralStateData));
+ FXSYS_strcpy((FX_CHAR*)m_BlendMode, "Normal");
+ m_StrokeAlpha = 1.0f;
+ m_FillAlpha = 1.0f;
+ m_Flatness = 1.0f;
+ m_Matrix.SetIdentity();
+}
+
+CPDF_GeneralStateData::CPDF_GeneralStateData(const CPDF_GeneralStateData& src) {
+ FXSYS_memcpy(this, &src, sizeof(CPDF_GeneralStateData));
+ if (src.m_pTransferFunc && src.m_pTransferFunc->m_pPDFDoc) {
+ CPDF_DocRenderData* pDocCache =
+ src.m_pTransferFunc->m_pPDFDoc->GetRenderData();
+ if (!pDocCache)
+ return;
+
+ m_pTransferFunc = pDocCache->GetTransferFunc(m_pTR);
+ }
+}
+
+CPDF_GeneralStateData::~CPDF_GeneralStateData() {
+ if (m_pTransferFunc && m_pTransferFunc->m_pPDFDoc) {
+ CPDF_DocRenderData* pDocCache = m_pTransferFunc->m_pPDFDoc->GetRenderData();
+ if (!pDocCache)
+ return;
+
+ pDocCache->ReleaseTransferFunc(m_pTR);
+ }
+}
+
+void CPDF_GeneralStateData::SetBlendMode(const CFX_ByteStringC& blend_mode) {
+ if (blend_mode.GetLength() > 15) {
+ return;
+ }
+ FXSYS_memcpy(m_BlendMode, blend_mode.GetPtr(), blend_mode.GetLength());
+ m_BlendMode[blend_mode.GetLength()] = 0;
+ m_BlendType = GetBlendTypeInternal(blend_mode);
+}
diff --git a/core/fpdfapi/fpdf_page/cpdf_graphicstates.cpp b/core/fpdfapi/fpdf_page/cpdf_graphicstates.cpp
new file mode 100644
index 0000000000..9c540941ce
--- /dev/null
+++ b/core/fpdfapi/fpdf_page/cpdf_graphicstates.cpp
@@ -0,0 +1,19 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "core/fpdfapi/fpdf_page/cpdf_graphicstates.h"
+
+void CPDF_GraphicStates::DefaultStates() {
+ m_ColorState.New()->Default();
+}
+
+void CPDF_GraphicStates::CopyStates(const CPDF_GraphicStates& src) {
+ m_ClipPath = src.m_ClipPath;
+ m_GraphState = src.m_GraphState;
+ m_ColorState = src.m_ColorState;
+ m_TextState = src.m_TextState;
+ m_GeneralState = src.m_GeneralState;
+}
diff --git a/core/fpdfapi/fpdf_page/cpdf_graphicstates.h b/core/fpdfapi/fpdf_page/cpdf_graphicstates.h
new file mode 100644
index 0000000000..0add18c910
--- /dev/null
+++ b/core/fpdfapi/fpdf_page/cpdf_graphicstates.h
@@ -0,0 +1,28 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef CORE_FPDFAPI_FPDF_PAGE_CPDF_GRAPHICSTATES_H_
+#define CORE_FPDFAPI_FPDF_PAGE_CPDF_GRAPHICSTATES_H_
+
+#include "core/fpdfapi/fpdf_page/cpdf_colorstate.h"
+#include "core/fpdfapi/fpdf_page/cpdf_graphstate.h"
+#include "core/fpdfapi/fpdf_page/cpdf_textstate.h"
+#include "core/fpdfapi/fpdf_page/include/cpdf_clippath.h"
+#include "core/fpdfapi/fpdf_page/include/cpdf_generalstate.h"
+
+class CPDF_GraphicStates {
+ public:
+ void CopyStates(const CPDF_GraphicStates& src);
+ void DefaultStates();
+
+ CPDF_ClipPath m_ClipPath;
+ CPDF_GraphState m_GraphState;
+ CPDF_ColorState m_ColorState;
+ CPDF_TextState m_TextState;
+ CPDF_GeneralState m_GeneralState;
+};
+
+#endif // CORE_FPDFAPI_FPDF_PAGE_CPDF_GRAPHICSTATES_H_
diff --git a/core/fpdfapi/fpdf_page/cpdf_graphstate.h b/core/fpdfapi/fpdf_page/cpdf_graphstate.h
new file mode 100644
index 0000000000..d44d32d31c
--- /dev/null
+++ b/core/fpdfapi/fpdf_page/cpdf_graphstate.h
@@ -0,0 +1,14 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef CORE_FPDFAPI_FPDF_PAGE_CPDF_GRAPHSTATE_H_
+#define CORE_FPDFAPI_FPDF_PAGE_CPDF_GRAPHSTATE_H_
+
+#include "core/include/fxge/fx_ge.h"
+
+class CPDF_GraphState : public CFX_CountRef<CFX_GraphStateData> {};
+
+#endif // CORE_FPDFAPI_FPDF_PAGE_CPDF_GRAPHSTATE_H_
diff --git a/core/fpdfapi/fpdf_page/cpdf_imageobject.cpp b/core/fpdfapi/fpdf_page/cpdf_imageobject.cpp
new file mode 100644
index 0000000000..f339935ecb
--- /dev/null
+++ b/core/fpdfapi/fpdf_page/cpdf_imageobject.cpp
@@ -0,0 +1,44 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "core/fpdfapi/fpdf_page/include/cpdf_imageobject.h"
+
+#include "core/fpdfapi/fpdf_page/pageint.h"
+#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
+
+CPDF_ImageObject::CPDF_ImageObject() : m_pImage(nullptr) {}
+
+CPDF_ImageObject::~CPDF_ImageObject() {
+ if (!m_pImage) {
+ return;
+ }
+ if (m_pImage->IsInline() ||
+ (m_pImage->GetStream() && m_pImage->GetStream()->GetObjNum() == 0)) {
+ delete m_pImage;
+ } else {
+ m_pImage->GetDocument()->GetPageData()->ReleaseImage(m_pImage->GetStream());
+ }
+}
+
+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();
+}
+
+void CPDF_ImageObject::CalcBoundingBox() {
+ m_Left = m_Bottom = 0;
+ m_Right = m_Top = 1.0f;
+ m_Matrix.TransformRect(m_Left, m_Right, m_Top, m_Bottom);
+}
diff --git a/core/fpdfapi/fpdf_page/cpdf_page.cpp b/core/fpdfapi/fpdf_page/cpdf_page.cpp
new file mode 100644
index 0000000000..0da5452969
--- /dev/null
+++ b/core/fpdfapi/fpdf_page/cpdf_page.cpp
@@ -0,0 +1,185 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "core/fpdfapi/fpdf_page/include/cpdf_page.h"
+
+#include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h"
+#include "core/fpdfapi/fpdf_page/pageint.h"
+#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
+#include "core/fpdfapi/fpdf_parser/include/cpdf_object.h"
+#include "core/fpdfapi/include/cpdf_modulemgr.h"
+#include "core/fpdfapi/ipdf_rendermodule.h"
+
+CPDF_Object* FPDFAPI_GetPageAttr(CPDF_Dictionary* pPageDict,
+ const CFX_ByteStringC& name) {
+ int level = 0;
+ while (1) {
+ CPDF_Object* pObj = pPageDict->GetElementValue(name);
+ if (pObj) {
+ return pObj;
+ }
+ CPDF_Dictionary* pParent = pPageDict->GetDictBy("Parent");
+ if (!pParent || pParent == pPageDict) {
+ return NULL;
+ }
+ pPageDict = pParent;
+ level++;
+ if (level == 1000) {
+ return NULL;
+ }
+ }
+}
+
+CPDF_Page::CPDF_Page() : m_pPageRender(nullptr) {}
+
+CPDF_Page::~CPDF_Page() {
+ if (m_pPageRender) {
+ IPDF_RenderModule* pModule = CPDF_ModuleMgr::Get()->GetRenderModule();
+ pModule->DestroyPageCache(m_pPageRender);
+ }
+}
+
+void CPDF_Page::Load(CPDF_Document* pDocument,
+ CPDF_Dictionary* pPageDict,
+ FX_BOOL bPageCache) {
+ m_pDocument = (CPDF_Document*)pDocument;
+ m_pFormDict = pPageDict;
+ if (bPageCache) {
+ m_pPageRender =
+ CPDF_ModuleMgr::Get()->GetRenderModule()->CreatePageCache(this);
+ }
+ if (!pPageDict) {
+ m_PageWidth = m_PageHeight = 100 * 1.0f;
+ m_pPageResources = m_pResources = NULL;
+ return;
+ }
+ CPDF_Object* pageAttr = GetPageAttr("Resources");
+ m_pResources = pageAttr ? pageAttr->GetDict() : NULL;
+ m_pPageResources = m_pResources;
+ CPDF_Object* pRotate = GetPageAttr("Rotate");
+ int rotate = 0;
+ if (pRotate) {
+ rotate = pRotate->GetInteger() / 90 % 4;
+ }
+ if (rotate < 0) {
+ rotate += 4;
+ }
+ CPDF_Array* pMediaBox = ToArray(GetPageAttr("MediaBox"));
+ CFX_FloatRect mediabox;
+ if (pMediaBox) {
+ mediabox = pMediaBox->GetRect();
+ mediabox.Normalize();
+ }
+ if (mediabox.IsEmpty()) {
+ mediabox = CFX_FloatRect(0, 0, 612, 792);
+ }
+
+ CPDF_Array* pCropBox = ToArray(GetPageAttr("CropBox"));
+ if (pCropBox) {
+ m_BBox = pCropBox->GetRect();
+ m_BBox.Normalize();
+ }
+ if (m_BBox.IsEmpty()) {
+ m_BBox = mediabox;
+ } else {
+ m_BBox.Intersect(mediabox);
+ }
+ if (rotate % 2) {
+ m_PageHeight = m_BBox.right - m_BBox.left;
+ m_PageWidth = m_BBox.top - m_BBox.bottom;
+ } else {
+ m_PageWidth = m_BBox.right - m_BBox.left;
+ m_PageHeight = m_BBox.top - m_BBox.bottom;
+ }
+ switch (rotate) {
+ case 0:
+ m_PageMatrix.Set(1.0f, 0, 0, 1.0f, -m_BBox.left, -m_BBox.bottom);
+ break;
+ case 1:
+ m_PageMatrix.Set(0, -1.0f, 1.0f, 0, -m_BBox.bottom, m_BBox.right);
+ break;
+ case 2:
+ m_PageMatrix.Set(-1.0f, 0, 0, -1.0f, m_BBox.right, m_BBox.top);
+ break;
+ case 3:
+ m_PageMatrix.Set(0, 1.0f, -1.0f, 0, m_BBox.top, -m_BBox.left);
+ break;
+ }
+ m_Transparency = PDFTRANS_ISOLATED;
+ LoadTransInfo();
+}
+
+void CPDF_Page::StartParse(CPDF_ParseOptions* pOptions) {
+ if (m_ParseState == CONTENT_PARSED || m_ParseState == CONTENT_PARSING) {
+ return;
+ }
+ m_pParser.reset(new CPDF_ContentParser);
+ m_pParser->Start(this, pOptions);
+ m_ParseState = CONTENT_PARSING;
+}
+
+void CPDF_Page::ParseContent(CPDF_ParseOptions* pOptions) {
+ StartParse(pOptions);
+ ContinueParse(nullptr);
+}
+
+CPDF_Object* CPDF_Page::GetPageAttr(const CFX_ByteStringC& name) const {
+ return FPDFAPI_GetPageAttr(m_pFormDict, name);
+}
+
+void CPDF_Page::GetDisplayMatrix(CFX_Matrix& matrix,
+ int xPos,
+ int yPos,
+ int xSize,
+ int ySize,
+ int iRotate) const {
+ if (m_PageWidth == 0 || m_PageHeight == 0) {
+ return;
+ }
+ CFX_Matrix display_matrix;
+ int x0, y0, x1, y1, x2, y2;
+ iRotate %= 4;
+ switch (iRotate) {
+ case 0:
+ x0 = xPos;
+ y0 = yPos + ySize;
+ x1 = xPos;
+ y1 = yPos;
+ x2 = xPos + xSize;
+ y2 = yPos + ySize;
+ break;
+ case 1:
+ x0 = xPos;
+ y0 = yPos;
+ x1 = xPos + xSize;
+ y1 = yPos;
+ x2 = xPos;
+ y2 = yPos + ySize;
+ break;
+ case 2:
+ x0 = xPos + xSize;
+ y0 = yPos;
+ x1 = xPos + xSize;
+ y1 = yPos + ySize;
+ x2 = xPos;
+ y2 = yPos;
+ break;
+ case 3:
+ x0 = xPos + xSize;
+ y0 = yPos + ySize;
+ x1 = xPos;
+ y1 = yPos + ySize;
+ x2 = xPos + xSize;
+ y2 = yPos;
+ break;
+ }
+ display_matrix.Set(
+ ((FX_FLOAT)(x2 - x0)) / m_PageWidth, ((FX_FLOAT)(y2 - y0)) / m_PageWidth,
+ ((FX_FLOAT)(x1 - x0)) / m_PageHeight,
+ ((FX_FLOAT)(y1 - y0)) / m_PageHeight, (FX_FLOAT)x0, (FX_FLOAT)y0);
+ matrix = m_PageMatrix;
+ matrix.Concat(display_matrix);
+}
diff --git a/core/fpdfapi/fpdf_page/cpdf_pageobject.cpp b/core/fpdfapi/fpdf_page/cpdf_pageobject.cpp
new file mode 100644
index 0000000000..ee6615e2e7
--- /dev/null
+++ b/core/fpdfapi/fpdf_page/cpdf_pageobject.cpp
@@ -0,0 +1,43 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h"
+
+CPDF_PageObject::CPDF_PageObject() {}
+
+CPDF_PageObject::~CPDF_PageObject() {}
+
+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::TransformClipPath(CFX_Matrix& matrix) {
+ if (m_ClipPath.IsNull()) {
+ return;
+ }
+ m_ClipPath.GetModify();
+ m_ClipPath.Transform(matrix);
+}
+
+void CPDF_PageObject::TransformGeneralState(CFX_Matrix& matrix) {
+ if (m_GeneralState.IsNull()) {
+ return;
+ }
+ 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) {
+ pMatrix->TransformRect(rect);
+ }
+ return rect.GetOutterRect();
+}
diff --git a/core/fpdfapi/fpdf_page/cpdf_pageobjectholder.cpp b/core/fpdfapi/fpdf_page/cpdf_pageobjectholder.cpp
index a1392f647e..fa6347e5bc 100644
--- a/core/fpdfapi/fpdf_page/cpdf_pageobjectholder.cpp
+++ b/core/fpdfapi/fpdf_page/cpdf_pageobjectholder.cpp
@@ -6,6 +6,7 @@
#include "core/fpdfapi/fpdf_page/include/cpdf_pageobjectholder.h"
+#include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h"
#include "core/fpdfapi/fpdf_page/pageint.h"
CPDF_PageObjectHolder::CPDF_PageObjectHolder()
diff --git a/core/fpdfapi/fpdf_page/cpdf_pageobjectlist.cpp b/core/fpdfapi/fpdf_page/cpdf_pageobjectlist.cpp
index 36fb672849..e433431551 100644
--- a/core/fpdfapi/fpdf_page/cpdf_pageobjectlist.cpp
+++ b/core/fpdfapi/fpdf_page/cpdf_pageobjectlist.cpp
@@ -7,7 +7,6 @@
#include "core/fpdfapi/fpdf_page/cpdf_pageobjectlist.h"
#include "core/fpdfapi/fpdf_page/pageint.h"
-#include "core/include/fpdfapi/fpdf_pageobj.h"
#include "third_party/base/stl_util.h"
CPDF_PageObject* CPDF_PageObjectList::GetPageObjectByIndex(int index) {
diff --git a/core/fpdfapi/fpdf_page/fpdf_page_path.cpp b/core/fpdfapi/fpdf_page/cpdf_pathobject.cpp
index 286dfdfb1c..cfe7b48c8b 100644
--- a/core/fpdfapi/fpdf_page/fpdf_page_path.cpp
+++ b/core/fpdfapi/fpdf_page/cpdf_pathobject.cpp
@@ -1,12 +1,10 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2016 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-#include "core/fpdfapi/fpdf_page/pageint.h"
-
-#include "core/include/fpdfapi/fpdf_pageobj.h"
+#include "core/fpdfapi/fpdf_page/include/cpdf_pathobject.h"
CPDF_PathObject::CPDF_PathObject() {}
diff --git a/core/fpdfapi/fpdf_page/cpdf_shadingobject.cpp b/core/fpdfapi/fpdf_page/cpdf_shadingobject.cpp
new file mode 100644
index 0000000000..16287fe692
--- /dev/null
+++ b/core/fpdfapi/fpdf_page/cpdf_shadingobject.cpp
@@ -0,0 +1,54 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "core/fpdfapi/fpdf_page/include/cpdf_shadingobject.h"
+
+#include "core/fpdfapi/fpdf_page/pageint.h"
+#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
+
+CPDF_ShadingObject::CPDF_ShadingObject() : m_pShading(nullptr) {}
+
+CPDF_ShadingObject::~CPDF_ShadingObject() {}
+
+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);
+ }
+ obj->m_Matrix = m_Matrix;
+ return obj;
+}
+
+void CPDF_ShadingObject::Transform(const CFX_Matrix& matrix) {
+ if (!m_ClipPath.IsNull()) {
+ m_ClipPath.GetModify();
+ m_ClipPath.Transform(matrix);
+ }
+ m_Matrix.Concat(matrix);
+ if (!m_ClipPath.IsNull()) {
+ CalcBoundingBox();
+ } else {
+ matrix.TransformRect(m_Left, m_Right, m_Top, m_Bottom);
+ }
+}
+
+void CPDF_ShadingObject::CalcBoundingBox() {
+ if (m_ClipPath.IsNull()) {
+ return;
+ }
+ CFX_FloatRect rect = m_ClipPath.GetClipBox();
+ m_Left = rect.left;
+ m_Bottom = rect.bottom;
+ m_Right = rect.right;
+ m_Top = rect.top;
+}
diff --git a/core/fpdfapi/fpdf_page/fpdf_page.cpp b/core/fpdfapi/fpdf_page/cpdf_textobject.cpp
index ad54e320bc..b4161f320e 100644
--- a/core/fpdfapi/fpdf_page/fpdf_page.cpp
+++ b/core/fpdfapi/fpdf_page/cpdf_textobject.cpp
@@ -1,57 +1,10 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2016 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-#include "core/fpdfapi/fpdf_page/pageint.h"
-
-#include <algorithm>
-
-#include "core/fpdfapi/fpdf_page/include/cpdf_form.h"
-#include "core/fpdfapi/fpdf_page/include/cpdf_page.h"
-#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
-#include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h"
-#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
-#include "core/fpdfapi/include/cpdf_modulemgr.h"
-#include "core/fpdfapi/ipdf_rendermodule.h"
-#include "third_party/base/stl_util.h"
-
-CPDF_PageObject::CPDF_PageObject() {}
-
-CPDF_PageObject::~CPDF_PageObject() {}
-
-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::TransformClipPath(CFX_Matrix& matrix) {
- if (m_ClipPath.IsNull()) {
- return;
- }
- m_ClipPath.GetModify();
- m_ClipPath.Transform(matrix);
-}
-
-void CPDF_PageObject::TransformGeneralState(CFX_Matrix& matrix) {
- if (m_GeneralState.IsNull()) {
- return;
- }
- 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) {
- pMatrix->TransformRect(rect);
- }
- return rect.GetOutterRect();
-}
+#include "core/fpdfapi/fpdf_page/include/cpdf_textobject.h"
CPDF_TextObject::CPDF_TextObject()
: m_PosX(0),
@@ -390,247 +343,3 @@ void CPDF_TextObject::SetPosition(FX_FLOAT x, FX_FLOAT y) {
m_Top += dy;
m_Bottom += dy;
}
-
-CPDF_ShadingObject::CPDF_ShadingObject() : m_pShading(nullptr) {}
-
-CPDF_ShadingObject::~CPDF_ShadingObject() {}
-
-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);
- }
- obj->m_Matrix = m_Matrix;
- return obj;
-}
-
-void CPDF_ShadingObject::Transform(const CFX_Matrix& matrix) {
- if (!m_ClipPath.IsNull()) {
- m_ClipPath.GetModify();
- m_ClipPath.Transform(matrix);
- }
- m_Matrix.Concat(matrix);
- if (!m_ClipPath.IsNull()) {
- CalcBoundingBox();
- } else {
- matrix.TransformRect(m_Left, m_Right, m_Top, m_Bottom);
- }
-}
-
-void CPDF_ShadingObject::CalcBoundingBox() {
- if (m_ClipPath.IsNull()) {
- return;
- }
- CFX_FloatRect rect = m_ClipPath.GetClipBox();
- m_Left = rect.left;
- m_Bottom = rect.bottom;
- m_Right = rect.right;
- 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();
-}
-
-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);
- m_Left = form_rect.left;
- m_Bottom = form_rect.bottom;
- m_Right = form_rect.right;
- m_Top = form_rect.top;
-}
-
-CPDF_Page::CPDF_Page() : m_pPageRender(nullptr) {}
-
-void CPDF_Page::Load(CPDF_Document* pDocument,
- CPDF_Dictionary* pPageDict,
- FX_BOOL bPageCache) {
- m_pDocument = (CPDF_Document*)pDocument;
- m_pFormDict = pPageDict;
- if (bPageCache) {
- m_pPageRender =
- CPDF_ModuleMgr::Get()->GetRenderModule()->CreatePageCache(this);
- }
- if (!pPageDict) {
- m_PageWidth = m_PageHeight = 100 * 1.0f;
- m_pPageResources = m_pResources = NULL;
- return;
- }
- CPDF_Object* pageAttr = GetPageAttr("Resources");
- m_pResources = pageAttr ? pageAttr->GetDict() : NULL;
- m_pPageResources = m_pResources;
- CPDF_Object* pRotate = GetPageAttr("Rotate");
- int rotate = 0;
- if (pRotate) {
- rotate = pRotate->GetInteger() / 90 % 4;
- }
- if (rotate < 0) {
- rotate += 4;
- }
- CPDF_Array* pMediaBox = ToArray(GetPageAttr("MediaBox"));
- CFX_FloatRect mediabox;
- if (pMediaBox) {
- mediabox = pMediaBox->GetRect();
- mediabox.Normalize();
- }
- if (mediabox.IsEmpty()) {
- mediabox = CFX_FloatRect(0, 0, 612, 792);
- }
-
- CPDF_Array* pCropBox = ToArray(GetPageAttr("CropBox"));
- if (pCropBox) {
- m_BBox = pCropBox->GetRect();
- m_BBox.Normalize();
- }
- if (m_BBox.IsEmpty()) {
- m_BBox = mediabox;
- } else {
- m_BBox.Intersect(mediabox);
- }
- if (rotate % 2) {
- m_PageHeight = m_BBox.right - m_BBox.left;
- m_PageWidth = m_BBox.top - m_BBox.bottom;
- } else {
- m_PageWidth = m_BBox.right - m_BBox.left;
- m_PageHeight = m_BBox.top - m_BBox.bottom;
- }
- switch (rotate) {
- case 0:
- m_PageMatrix.Set(1.0f, 0, 0, 1.0f, -m_BBox.left, -m_BBox.bottom);
- break;
- case 1:
- m_PageMatrix.Set(0, -1.0f, 1.0f, 0, -m_BBox.bottom, m_BBox.right);
- break;
- case 2:
- m_PageMatrix.Set(-1.0f, 0, 0, -1.0f, m_BBox.right, m_BBox.top);
- break;
- case 3:
- m_PageMatrix.Set(0, 1.0f, -1.0f, 0, m_BBox.top, -m_BBox.left);
- break;
- }
- m_Transparency = PDFTRANS_ISOLATED;
- LoadTransInfo();
-}
-
-void CPDF_Page::StartParse(CPDF_ParseOptions* pOptions) {
- if (m_ParseState == CONTENT_PARSED || m_ParseState == CONTENT_PARSING) {
- return;
- }
- m_pParser.reset(new CPDF_ContentParser);
- 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;
- while (1) {
- CPDF_Object* pObj = pPageDict->GetElementValue(name);
- if (pObj) {
- return pObj;
- }
- CPDF_Dictionary* pParent = pPageDict->GetDictBy("Parent");
- if (!pParent || pParent == pPageDict) {
- return NULL;
- }
- pPageDict = pParent;
- level++;
- if (level == 1000) {
- return NULL;
- }
- }
-}
-
-CPDF_Object* CPDF_Page::GetPageAttr(const CFX_ByteStringC& name) const {
- return FPDFAPI_GetPageAttr(m_pFormDict, name);
-}
-
-void CPDF_Page::GetDisplayMatrix(CFX_Matrix& matrix,
- int xPos,
- int yPos,
- int xSize,
- int ySize,
- int iRotate) const {
- if (m_PageWidth == 0 || m_PageHeight == 0) {
- return;
- }
- CFX_Matrix display_matrix;
- int x0, y0, x1, y1, x2, y2;
- iRotate %= 4;
- switch (iRotate) {
- case 0:
- x0 = xPos;
- y0 = yPos + ySize;
- x1 = xPos;
- y1 = yPos;
- x2 = xPos + xSize;
- y2 = yPos + ySize;
- break;
- case 1:
- x0 = xPos;
- y0 = yPos;
- x1 = xPos + xSize;
- y1 = yPos;
- x2 = xPos;
- y2 = yPos + ySize;
- break;
- case 2:
- x0 = xPos + xSize;
- y0 = yPos;
- x1 = xPos + xSize;
- y1 = yPos + ySize;
- x2 = xPos;
- y2 = yPos;
- break;
- case 3:
- x0 = xPos + xSize;
- y0 = yPos + ySize;
- x1 = xPos;
- y1 = yPos + ySize;
- x2 = xPos + xSize;
- y2 = yPos;
- break;
- }
- display_matrix.Set(
- ((FX_FLOAT)(x2 - x0)) / m_PageWidth, ((FX_FLOAT)(y2 - y0)) / m_PageWidth,
- ((FX_FLOAT)(x1 - x0)) / m_PageHeight,
- ((FX_FLOAT)(y1 - y0)) / m_PageHeight, (FX_FLOAT)x0, (FX_FLOAT)y0);
- matrix = m_PageMatrix;
- matrix.Concat(display_matrix);
-}
diff --git a/core/fpdfapi/fpdf_page/cpdf_textstate.cpp b/core/fpdfapi/fpdf_page/cpdf_textstate.cpp
new file mode 100644
index 0000000000..f56d58ed0a
--- /dev/null
+++ b/core/fpdfapi/fpdf_page/cpdf_textstate.cpp
@@ -0,0 +1,47 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "core/fpdfapi/fpdf_page/cpdf_textstate.h"
+#include "core/fpdfapi/fpdf_page/pageint.h"
+#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
+
+void CPDF_TextState::SetFont(CPDF_Font* pFont) {
+ CPDF_TextStateData* pStateData = GetModify();
+ if (pStateData) {
+ CPDF_Document* pDoc = pStateData->m_pDocument;
+ CPDF_DocPageData* pPageData = pDoc ? pDoc->GetPageData() : NULL;
+ if (pPageData && pStateData->m_pFont && !pPageData->IsForceClear()) {
+ pPageData->ReleaseFont(pStateData->m_pFont->GetFontDict());
+ }
+ pStateData->m_pDocument = pFont ? pFont->m_pDocument : NULL;
+ pStateData->m_pFont = pFont;
+ }
+}
+
+FX_FLOAT CPDF_TextState::GetFontSizeV() const {
+ FX_FLOAT* pMatrix = GetMatrix();
+ FX_FLOAT unit = FXSYS_sqrt2(pMatrix[1], pMatrix[3]);
+ FX_FLOAT size = unit * GetFontSize();
+ return (FX_FLOAT)FXSYS_fabs(size);
+}
+
+FX_FLOAT CPDF_TextState::GetFontSizeH() const {
+ FX_FLOAT* pMatrix = GetMatrix();
+ FX_FLOAT unit = FXSYS_sqrt2(pMatrix[0], pMatrix[2]);
+ FX_FLOAT size = unit * GetFontSize();
+ return (FX_FLOAT)FXSYS_fabs(size);
+}
+
+FX_FLOAT CPDF_TextState::GetBaselineAngle() const {
+ FX_FLOAT* m_Matrix = GetMatrix();
+ return FXSYS_atan2(m_Matrix[2], m_Matrix[0]);
+}
+
+FX_FLOAT CPDF_TextState::GetShearAngle() const {
+ FX_FLOAT* m_Matrix = GetMatrix();
+ FX_FLOAT shear_angle = FXSYS_atan2(m_Matrix[1], m_Matrix[3]);
+ return GetBaselineAngle() + shear_angle;
+}
diff --git a/core/fpdfapi/fpdf_page/cpdf_textstate.h b/core/fpdfapi/fpdf_page/cpdf_textstate.h
new file mode 100644
index 0000000000..8530322aeb
--- /dev/null
+++ b/core/fpdfapi/fpdf_page/cpdf_textstate.h
@@ -0,0 +1,28 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef CORE_FPDFAPI_FPDF_PAGE_CPDF_TEXTSTATE_H_
+#define CORE_FPDFAPI_FPDF_PAGE_CPDF_TEXTSTATE_H_
+
+#include "core/fpdfapi/fpdf_page/include/cpdf_textstatedata.h"
+#include "core/include/fxcrt/fx_basic.h"
+
+class CPDF_Font;
+
+class CPDF_TextState : public CFX_CountRef<CPDF_TextStateData> {
+ public:
+ CPDF_Font* GetFont() const { return m_pObject->m_pFont; }
+ void SetFont(CPDF_Font* pFont);
+
+ FX_FLOAT GetFontSize() const { return m_pObject->m_FontSize; }
+ FX_FLOAT* GetMatrix() const { return m_pObject->m_Matrix; }
+ FX_FLOAT GetFontSizeV() const;
+ FX_FLOAT GetFontSizeH() const;
+ FX_FLOAT GetBaselineAngle() const;
+ FX_FLOAT GetShearAngle() const;
+};
+
+#endif // CORE_FPDFAPI_FPDF_PAGE_CPDF_TEXTSTATE_H_
diff --git a/core/fpdfapi/fpdf_page/cpdf_textstatedata.cpp b/core/fpdfapi/fpdf_page/cpdf_textstatedata.cpp
new file mode 100644
index 0000000000..af65fb530a
--- /dev/null
+++ b/core/fpdfapi/fpdf_page/cpdf_textstatedata.cpp
@@ -0,0 +1,43 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "core/fpdfapi/fpdf_page/include/cpdf_textstatedata.h"
+
+#include "core/fpdfapi/fpdf_page/pageint.h"
+#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
+#include "core/include/fpdfapi/fpdf_resource.h"
+
+CPDF_TextStateData::CPDF_TextStateData()
+ : m_pFont(nullptr),
+ m_pDocument(nullptr),
+ m_FontSize(1.0f),
+ m_CharSpace(0),
+ m_WordSpace(0),
+ m_TextMode(0) {
+ m_Matrix[0] = m_Matrix[3] = 1.0f;
+ m_Matrix[1] = m_Matrix[2] = 0;
+ m_CTM[0] = m_CTM[3] = 1.0f;
+ m_CTM[1] = m_CTM[2] = 0;
+}
+
+CPDF_TextStateData::CPDF_TextStateData(const CPDF_TextStateData& src) {
+ if (this == &src)
+ return;
+
+ FXSYS_memcpy(this, &src, sizeof(CPDF_TextStateData));
+ if (m_pDocument && m_pFont) {
+ m_pFont =
+ m_pDocument->GetPageData()->GetFont(m_pFont->GetFontDict(), FALSE);
+ }
+}
+
+CPDF_TextStateData::~CPDF_TextStateData() {
+ if (m_pDocument && m_pFont) {
+ CPDF_DocPageData* pPageData = m_pDocument->GetPageData();
+ if (pPageData && !pPageData->IsForceClear())
+ pPageData->ReleaseFont(m_pFont->GetFontDict());
+ }
+}
diff --git a/core/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp b/core/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp
deleted file mode 100644
index cd81b97112..0000000000
--- a/core/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp
+++ /dev/null
@@ -1,694 +0,0 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "core/fpdfapi/fpdf_page/pageint.h"
-
-#include <algorithm>
-
-#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
-#include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h"
-#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
-#include "core/fpdfapi/fpdf_render/render_int.h"
-#include "core/include/fpdfapi/fpdf_pageobj.h"
-#include "third_party/base/stl_util.h"
-
-namespace {
-
-FX_FLOAT ClipFloat(FX_FLOAT f) {
- return std::max(0.0f, std::min(1.0f, f));
-}
-
-} // namespace
-
-void CPDF_GraphicStates::DefaultStates() {
- m_ColorState.New()->Default();
-}
-void CPDF_GraphicStates::CopyStates(const CPDF_GraphicStates& src) {
- m_ClipPath = src.m_ClipPath;
- m_GraphState = src.m_GraphState;
- m_ColorState = src.m_ColorState;
- m_TextState = src.m_TextState;
- m_GeneralState = src.m_GeneralState;
-}
-CPDF_ClipPathData::CPDF_ClipPathData() {
- m_PathCount = 0;
- m_pPathList = NULL;
- m_pTypeList = NULL;
- m_TextCount = 0;
- m_pTextList = NULL;
-}
-CPDF_ClipPathData::~CPDF_ClipPathData() {
- int i;
- delete[] m_pPathList;
- FX_Free(m_pTypeList);
- for (i = m_TextCount - 1; i > -1; i--)
- delete m_pTextList[i];
- FX_Free(m_pTextList);
-}
-CPDF_ClipPathData::CPDF_ClipPathData(const CPDF_ClipPathData& src) {
- m_pPathList = NULL;
- m_pPathList = NULL;
- m_pTextList = NULL;
- m_PathCount = src.m_PathCount;
- if (m_PathCount) {
- int alloc_size = m_PathCount;
- if (alloc_size % 8) {
- alloc_size += 8 - (alloc_size % 8);
- }
- m_pPathList = new CPDF_Path[alloc_size];
- for (int i = 0; i < m_PathCount; i++) {
- m_pPathList[i] = src.m_pPathList[i];
- }
- m_pTypeList = FX_Alloc(uint8_t, alloc_size);
- FXSYS_memcpy(m_pTypeList, src.m_pTypeList, m_PathCount);
- } else {
- m_pPathList = NULL;
- m_pTypeList = NULL;
- }
- m_TextCount = src.m_TextCount;
- if (m_TextCount) {
- m_pTextList = FX_Alloc(CPDF_TextObject*, m_TextCount);
- for (int i = 0; i < m_TextCount; i++) {
- if (src.m_pTextList[i]) {
- m_pTextList[i] = src.m_pTextList[i]->Clone();
- } else {
- m_pTextList[i] = NULL;
- }
- }
- } else {
- m_pTextList = NULL;
- }
-}
-void CPDF_ClipPathData::SetCount(int path_count, int text_count) {
- ASSERT(m_TextCount == 0 && m_PathCount == 0);
- if (path_count) {
- m_PathCount = path_count;
- int alloc_size = (path_count + 7) / 8 * 8;
- m_pPathList = new CPDF_Path[alloc_size];
- m_pTypeList = FX_Alloc(uint8_t, alloc_size);
- }
- if (text_count) {
- m_TextCount = text_count;
- m_pTextList = FX_Alloc(CPDF_TextObject*, text_count);
- }
-}
-CFX_FloatRect CPDF_ClipPath::GetClipBox() const {
- CFX_FloatRect rect;
- FX_BOOL bStarted = FALSE;
- int count = GetPathCount();
- if (count) {
- rect = GetPath(0).GetBoundingBox();
- for (int i = 1; i < count; i++) {
- CFX_FloatRect path_rect = GetPath(i).GetBoundingBox();
- rect.Intersect(path_rect);
- }
- bStarted = TRUE;
- }
- count = GetTextCount();
- if (count) {
- CFX_FloatRect layer_rect;
- FX_BOOL bLayerStarted = FALSE;
- for (int i = 0; i < count; i++) {
- CPDF_TextObject* pTextObj = GetText(i);
- if (!pTextObj) {
- if (!bStarted) {
- rect = layer_rect;
- bStarted = TRUE;
- } else {
- rect.Intersect(layer_rect);
- }
- bLayerStarted = FALSE;
- } else {
- if (!bLayerStarted) {
- layer_rect = CFX_FloatRect(pTextObj->GetBBox(nullptr));
- bLayerStarted = TRUE;
- } else {
- layer_rect.Union(CFX_FloatRect(pTextObj->GetBBox(nullptr)));
- }
- }
- }
- }
- return rect;
-}
-void CPDF_ClipPath::AppendPath(CPDF_Path path, int type, FX_BOOL bAutoMerge) {
- CPDF_ClipPathData* pData = GetModify();
- if (pData->m_PathCount && bAutoMerge) {
- CPDF_Path old_path = pData->m_pPathList[pData->m_PathCount - 1];
- if (old_path.IsRect()) {
- CFX_FloatRect old_rect(old_path.GetPointX(0), old_path.GetPointY(0),
- old_path.GetPointX(2), old_path.GetPointY(2));
- CFX_FloatRect new_rect = path.GetBoundingBox();
- if (old_rect.Contains(new_rect)) {
- pData->m_PathCount--;
- pData->m_pPathList[pData->m_PathCount].SetNull();
- }
- }
- }
- if (pData->m_PathCount % 8 == 0) {
- CPDF_Path* pNewPath = new CPDF_Path[pData->m_PathCount + 8];
- for (int i = 0; i < pData->m_PathCount; i++) {
- pNewPath[i] = pData->m_pPathList[i];
- }
- delete[] pData->m_pPathList;
- uint8_t* pNewType = FX_Alloc(uint8_t, pData->m_PathCount + 8);
- FXSYS_memcpy(pNewType, pData->m_pTypeList, pData->m_PathCount);
- FX_Free(pData->m_pTypeList);
- pData->m_pPathList = pNewPath;
- pData->m_pTypeList = pNewType;
- }
- pData->m_pPathList[pData->m_PathCount] = path;
- pData->m_pTypeList[pData->m_PathCount] = (uint8_t)type;
- pData->m_PathCount++;
-}
-void CPDF_ClipPath::DeletePath(int index) {
- CPDF_ClipPathData* pData = GetModify();
- if (index >= pData->m_PathCount) {
- return;
- }
- pData->m_pPathList[index].SetNull();
- for (int i = index; i < pData->m_PathCount - 1; i++) {
- pData->m_pPathList[i] = pData->m_pPathList[i + 1];
- }
- pData->m_pPathList[pData->m_PathCount - 1].SetNull();
- FXSYS_memmove(pData->m_pTypeList + index, pData->m_pTypeList + index + 1,
- pData->m_PathCount - index - 1);
- pData->m_PathCount--;
-}
-#define FPDF_CLIPPATH_MAX_TEXTS 1024
-void CPDF_ClipPath::AppendTexts(CPDF_TextObject** pTexts, int count) {
- CPDF_ClipPathData* pData = GetModify();
- if (pData->m_TextCount + count > FPDF_CLIPPATH_MAX_TEXTS) {
- for (int i = 0; i < count; i++) {
- delete pTexts[i];
- }
- return;
- }
- CPDF_TextObject** pNewList =
- FX_Alloc(CPDF_TextObject*, pData->m_TextCount + count + 1);
- if (pData->m_pTextList) {
- FXSYS_memcpy(pNewList, pData->m_pTextList,
- pData->m_TextCount * sizeof(CPDF_TextObject*));
- FX_Free(pData->m_pTextList);
- }
- pData->m_pTextList = pNewList;
- for (int i = 0; i < count; i++) {
- pData->m_pTextList[pData->m_TextCount + i] = pTexts[i];
- }
- pData->m_pTextList[pData->m_TextCount + count] = NULL;
- pData->m_TextCount += count + 1;
-}
-void CPDF_ClipPath::Transform(const CFX_Matrix& matrix) {
- CPDF_ClipPathData* pData = GetModify();
- int i;
- for (i = 0; i < pData->m_PathCount; i++) {
- pData->m_pPathList[i].Transform(&matrix);
- }
- for (i = 0; i < pData->m_TextCount; i++)
- if (pData->m_pTextList[i]) {
- pData->m_pTextList[i]->Transform(matrix);
- }
-}
-CPDF_ColorStateData::CPDF_ColorStateData(const CPDF_ColorStateData& src) {
- m_FillColor.Copy(&src.m_FillColor);
- m_FillRGB = src.m_FillRGB;
- m_StrokeColor.Copy(&src.m_StrokeColor);
- m_StrokeRGB = src.m_StrokeRGB;
-}
-void CPDF_ColorStateData::Default() {
- m_FillRGB = m_StrokeRGB = 0;
- m_FillColor.SetColorSpace(CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY));
- m_StrokeColor.SetColorSpace(CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY));
-}
-void CPDF_ColorState::SetFillColor(CPDF_ColorSpace* pCS,
- FX_FLOAT* pValue,
- int nValues) {
- CPDF_ColorStateData* pData = GetModify();
- SetColor(pData->m_FillColor, pData->m_FillRGB, pCS, pValue, nValues);
-}
-void CPDF_ColorState::SetStrokeColor(CPDF_ColorSpace* pCS,
- FX_FLOAT* pValue,
- int nValues) {
- CPDF_ColorStateData* pData = GetModify();
- SetColor(pData->m_StrokeColor, pData->m_StrokeRGB, pCS, pValue, nValues);
-}
-void CPDF_ColorState::SetColor(CPDF_Color& color,
- FX_DWORD& rgb,
- CPDF_ColorSpace* pCS,
- FX_FLOAT* pValue,
- int nValues) {
- if (pCS) {
- color.SetColorSpace(pCS);
- } else if (color.IsNull()) {
- color.SetColorSpace(CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY));
- }
- if (color.m_pCS->CountComponents() > nValues) {
- return;
- }
- color.SetValue(pValue);
- int R, G, B;
- rgb = color.GetRGB(R, G, B) ? FXSYS_RGB(R, G, B) : (FX_DWORD)-1;
-}
-void CPDF_ColorState::SetFillPattern(CPDF_Pattern* pPattern,
- FX_FLOAT* pValue,
- int nValues) {
- CPDF_ColorStateData* pData = GetModify();
- pData->m_FillColor.SetValue(pPattern, pValue, nValues);
- int R, G, B;
- FX_BOOL ret = pData->m_FillColor.GetRGB(R, G, B);
- if (pPattern->m_PatternType == 1 &&
- ((CPDF_TilingPattern*)pPattern)->m_bColored && !ret) {
- pData->m_FillRGB = 0x00BFBFBF;
- return;
- }
- pData->m_FillRGB = ret ? FXSYS_RGB(R, G, B) : (FX_DWORD)-1;
-}
-void CPDF_ColorState::SetStrokePattern(CPDF_Pattern* pPattern,
- FX_FLOAT* pValue,
- int nValues) {
- CPDF_ColorStateData* pData = GetModify();
- pData->m_StrokeColor.SetValue(pPattern, pValue, nValues);
- int R, G, B;
- FX_BOOL ret = pData->m_StrokeColor.GetRGB(R, G, B);
- if (pPattern->m_PatternType == 1 &&
- ((CPDF_TilingPattern*)pPattern)->m_bColored && !ret) {
- pData->m_StrokeRGB = 0x00BFBFBF;
- return;
- }
- pData->m_StrokeRGB =
- pData->m_StrokeColor.GetRGB(R, G, B) ? FXSYS_RGB(R, G, B) : (FX_DWORD)-1;
-}
-CPDF_TextStateData::CPDF_TextStateData() {
- m_pFont = NULL;
- m_pDocument = NULL;
- m_FontSize = 1.0f;
- m_WordSpace = 0;
- m_CharSpace = 0;
- m_TextMode = 0;
- m_Matrix[0] = m_Matrix[3] = 1.0f;
- m_Matrix[1] = m_Matrix[2] = 0;
- m_CTM[0] = m_CTM[3] = 1.0f;
- m_CTM[1] = m_CTM[2] = 0;
-}
-CPDF_TextStateData::CPDF_TextStateData(const CPDF_TextStateData& src) {
- if (this == &src) {
- return;
- }
- FXSYS_memcpy(this, &src, sizeof(CPDF_TextStateData));
- if (m_pDocument && m_pFont) {
- m_pFont =
- m_pDocument->GetPageData()->GetFont(m_pFont->GetFontDict(), FALSE);
- }
-}
-CPDF_TextStateData::~CPDF_TextStateData() {
- if (m_pDocument && m_pFont) {
- CPDF_DocPageData* pPageData = m_pDocument->GetPageData();
- if (pPageData && !pPageData->IsForceClear()) {
- pPageData->ReleaseFont(m_pFont->GetFontDict());
- }
- }
-}
-void CPDF_TextState::SetFont(CPDF_Font* pFont) {
- CPDF_TextStateData* pStateData = GetModify();
- if (pStateData) {
- CPDF_Document* pDoc = pStateData->m_pDocument;
- CPDF_DocPageData* pPageData = pDoc ? pDoc->GetPageData() : NULL;
- if (pPageData && pStateData->m_pFont && !pPageData->IsForceClear()) {
- pPageData->ReleaseFont(pStateData->m_pFont->GetFontDict());
- }
- pStateData->m_pDocument = pFont ? pFont->m_pDocument : NULL;
- pStateData->m_pFont = pFont;
- }
-}
-FX_FLOAT CPDF_TextState::GetFontSizeV() const {
- FX_FLOAT* pMatrix = GetMatrix();
- FX_FLOAT unit = FXSYS_sqrt2(pMatrix[1], pMatrix[3]);
- FX_FLOAT size = unit * GetFontSize();
- return (FX_FLOAT)FXSYS_fabs(size);
-}
-FX_FLOAT CPDF_TextState::GetFontSizeH() const {
- FX_FLOAT* pMatrix = GetMatrix();
- FX_FLOAT unit = FXSYS_sqrt2(pMatrix[0], pMatrix[2]);
- FX_FLOAT size = unit * GetFontSize();
- return (FX_FLOAT)FXSYS_fabs(size);
-}
-FX_FLOAT CPDF_TextState::GetBaselineAngle() const {
- FX_FLOAT* m_Matrix = GetMatrix();
- return FXSYS_atan2(m_Matrix[2], m_Matrix[0]);
-}
-FX_FLOAT CPDF_TextState::GetShearAngle() const {
- FX_FLOAT* m_Matrix = GetMatrix();
- FX_FLOAT shear_angle = FXSYS_atan2(m_Matrix[1], m_Matrix[3]);
- return GetBaselineAngle() + shear_angle;
-}
-CPDF_GeneralStateData::CPDF_GeneralStateData() {
- FXSYS_memset(this, 0, sizeof(CPDF_GeneralStateData));
- FXSYS_strcpy((FX_CHAR*)m_BlendMode, "Normal");
- m_StrokeAlpha = 1.0f;
- m_FillAlpha = 1.0f;
- m_Flatness = 1.0f;
- m_Matrix.SetIdentity();
-}
-CPDF_GeneralStateData::CPDF_GeneralStateData(const CPDF_GeneralStateData& src) {
- FXSYS_memcpy(this, &src, sizeof(CPDF_GeneralStateData));
- if (src.m_pTransferFunc && src.m_pTransferFunc->m_pPDFDoc) {
- CPDF_DocRenderData* pDocCache =
- src.m_pTransferFunc->m_pPDFDoc->GetRenderData();
- if (!pDocCache) {
- return;
- }
- m_pTransferFunc = pDocCache->GetTransferFunc(m_pTR);
- }
-}
-CPDF_GeneralStateData::~CPDF_GeneralStateData() {
- if (m_pTransferFunc && m_pTransferFunc->m_pPDFDoc) {
- CPDF_DocRenderData* pDocCache = m_pTransferFunc->m_pPDFDoc->GetRenderData();
- if (!pDocCache) {
- return;
- }
- pDocCache->ReleaseTransferFunc(m_pTR);
- }
-}
-static int GetBlendType(const CFX_ByteStringC& mode) {
- switch (mode.GetID()) {
- case FXBSTR_ID('N', 'o', 'r', 'm'):
- case FXBSTR_ID('C', 'o', 'm', 'p'):
- return FXDIB_BLEND_NORMAL;
- case FXBSTR_ID('M', 'u', 'l', 't'):
- return FXDIB_BLEND_MULTIPLY;
- case FXBSTR_ID('S', 'c', 'r', 'e'):
- return FXDIB_BLEND_SCREEN;
- case FXBSTR_ID('O', 'v', 'e', 'r'):
- return FXDIB_BLEND_OVERLAY;
- case FXBSTR_ID('D', 'a', 'r', 'k'):
- return FXDIB_BLEND_DARKEN;
- case FXBSTR_ID('L', 'i', 'g', 'h'):
- return FXDIB_BLEND_LIGHTEN;
- case FXBSTR_ID('C', 'o', 'l', 'o'):
- if (mode.GetLength() == 10) {
- return FXDIB_BLEND_COLORDODGE;
- }
- if (mode.GetLength() == 9) {
- return FXDIB_BLEND_COLORBURN;
- }
- return FXDIB_BLEND_COLOR;
- case FXBSTR_ID('H', 'a', 'r', 'd'):
- return FXDIB_BLEND_HARDLIGHT;
- case FXBSTR_ID('S', 'o', 'f', 't'):
- return FXDIB_BLEND_SOFTLIGHT;
- case FXBSTR_ID('D', 'i', 'f', 'f'):
- return FXDIB_BLEND_DIFFERENCE;
- case FXBSTR_ID('E', 'x', 'c', 'l'):
- return FXDIB_BLEND_EXCLUSION;
- case FXBSTR_ID('H', 'u', 'e', 0):
- return FXDIB_BLEND_HUE;
- case FXBSTR_ID('S', 'a', 't', 'u'):
- return FXDIB_BLEND_SATURATION;
- case FXBSTR_ID('L', 'u', 'm', 'i'):
- return FXDIB_BLEND_LUMINOSITY;
- }
- return FXDIB_BLEND_NORMAL;
-}
-void CPDF_GeneralStateData::SetBlendMode(const CFX_ByteStringC& blend_mode) {
- if (blend_mode.GetLength() > 15) {
- return;
- }
- FXSYS_memcpy(m_BlendMode, blend_mode.GetPtr(), blend_mode.GetLength());
- m_BlendMode[blend_mode.GetLength()] = 0;
- m_BlendType = ::GetBlendType(blend_mode);
-}
-int RI_StringToId(const CFX_ByteString& ri) {
- FX_DWORD id = ri.GetID();
- if (id == FXBSTR_ID('A', 'b', 's', 'o')) {
- return 1;
- }
- if (id == FXBSTR_ID('S', 'a', 't', 'u')) {
- return 2;
- }
- if (id == FXBSTR_ID('P', 'e', 'r', 'c')) {
- return 3;
- }
- return 0;
-}
-void CPDF_GeneralState::SetRenderIntent(const CFX_ByteString& ri) {
- GetModify()->m_RenderIntent = RI_StringToId(ri);
-}
-CPDF_AllStates::CPDF_AllStates() {
- m_TextX = m_TextY = m_TextLineX = m_TextLineY = 0;
- m_TextLeading = 0;
- m_TextRise = 0;
- m_TextHorzScale = 1.0f;
-}
-CPDF_AllStates::~CPDF_AllStates() {}
-void CPDF_AllStates::Copy(const CPDF_AllStates& src) {
- CopyStates(src);
- m_TextMatrix.Copy(src.m_TextMatrix);
- m_ParentMatrix.Copy(src.m_ParentMatrix);
- m_CTM.Copy(src.m_CTM);
- m_TextX = src.m_TextX;
- m_TextY = src.m_TextY;
- m_TextLineX = src.m_TextLineX;
- m_TextLineY = src.m_TextLineY;
- m_TextLeading = src.m_TextLeading;
- m_TextRise = src.m_TextRise;
- m_TextHorzScale = src.m_TextHorzScale;
-}
-void CPDF_AllStates::SetLineDash(CPDF_Array* pArray,
- FX_FLOAT phase,
- FX_FLOAT scale) {
- CFX_GraphStateData* pData = m_GraphState.GetModify();
- pData->m_DashPhase = phase * scale;
- pData->SetDashCount(pArray->GetCount());
- for (FX_DWORD i = 0; i < pArray->GetCount(); i++) {
- pData->m_DashArray[i] = pArray->GetNumberAt(i) * scale;
- }
-}
-void CPDF_AllStates::ProcessExtGS(CPDF_Dictionary* pGS,
- CPDF_StreamContentParser* pParser) {
- CPDF_GeneralStateData* pGeneralState = m_GeneralState.GetModify();
- for (const auto& it : *pGS) {
- const CFX_ByteString& key_str = it.first;
- CPDF_Object* pElement = it.second;
- CPDF_Object* pObject = pElement ? pElement->GetDirect() : nullptr;
- if (!pObject)
- continue;
-
- FX_DWORD key = key_str.GetID();
- switch (key) {
- case FXBSTR_ID('L', 'W', 0, 0):
- m_GraphState.GetModify()->m_LineWidth = pObject->GetNumber();
- break;
- case FXBSTR_ID('L', 'C', 0, 0):
- m_GraphState.GetModify()->m_LineCap =
- (CFX_GraphStateData::LineCap)pObject->GetInteger();
- break;
- case FXBSTR_ID('L', 'J', 0, 0):
- m_GraphState.GetModify()->m_LineJoin =
- (CFX_GraphStateData::LineJoin)pObject->GetInteger();
- break;
- case FXBSTR_ID('M', 'L', 0, 0):
- m_GraphState.GetModify()->m_MiterLimit = pObject->GetNumber();
- break;
- case FXBSTR_ID('D', 0, 0, 0): {
- CPDF_Array* pDash = pObject->AsArray();
- if (!pDash)
- break;
-
- CPDF_Array* pArray = pDash->GetArrayAt(0);
- if (!pArray)
- break;
-
- SetLineDash(pArray, pDash->GetNumberAt(1), 1.0f);
- break;
- }
- case FXBSTR_ID('R', 'I', 0, 0):
- m_GeneralState.SetRenderIntent(pObject->GetString());
- break;
- case FXBSTR_ID('F', 'o', 'n', 't'): {
- CPDF_Array* pFont = pObject->AsArray();
- if (!pFont)
- break;
-
- m_TextState.GetModify()->m_FontSize = pFont->GetNumberAt(1);
- m_TextState.SetFont(pParser->FindFont(pFont->GetStringAt(0)));
- break;
- }
- case FXBSTR_ID('T', 'R', 0, 0):
- if (pGS->KeyExist("TR2")) {
- continue;
- }
- case FXBSTR_ID('T', 'R', '2', 0):
- pGeneralState->m_pTR =
- (pObject && !pObject->IsName()) ? pObject : nullptr;
- break;
- case FXBSTR_ID('B', 'M', 0, 0): {
- CPDF_Array* pArray = pObject->AsArray();
- CFX_ByteString mode =
- pArray ? pArray->GetStringAt(0) : pObject->GetString();
-
- pGeneralState->SetBlendMode(mode);
- if (pGeneralState->m_BlendType > FXDIB_BLEND_MULTIPLY) {
- pParser->GetPageObjectHolder()->SetBackgroundAlphaNeeded(TRUE);
- }
- break;
- }
- case FXBSTR_ID('S', 'M', 'a', 's'):
- if (ToDictionary(pObject)) {
- pGeneralState->m_pSoftMask = pObject;
- FXSYS_memcpy(pGeneralState->m_SMaskMatrix,
- &pParser->GetCurStates()->m_CTM, sizeof(CFX_Matrix));
- } else {
- pGeneralState->m_pSoftMask = NULL;
- }
- break;
- case FXBSTR_ID('C', 'A', 0, 0):
- pGeneralState->m_StrokeAlpha = ClipFloat(pObject->GetNumber());
- break;
- case FXBSTR_ID('c', 'a', 0, 0):
- pGeneralState->m_FillAlpha = ClipFloat(pObject->GetNumber());
- break;
- case FXBSTR_ID('O', 'P', 0, 0):
- pGeneralState->m_StrokeOP = pObject->GetInteger();
- if (!pGS->KeyExist("op")) {
- pGeneralState->m_FillOP = pObject->GetInteger();
- }
- break;
- case FXBSTR_ID('o', 'p', 0, 0):
- pGeneralState->m_FillOP = pObject->GetInteger();
- break;
- case FXBSTR_ID('O', 'P', 'M', 0):
- pGeneralState->m_OPMode = pObject->GetInteger();
- break;
- case FXBSTR_ID('B', 'G', 0, 0):
- if (pGS->KeyExist("BG2")) {
- continue;
- }
- case FXBSTR_ID('B', 'G', '2', 0):
- pGeneralState->m_pBG = pObject;
- break;
- case FXBSTR_ID('U', 'C', 'R', 0):
- if (pGS->KeyExist("UCR2")) {
- continue;
- }
- case FXBSTR_ID('U', 'C', 'R', '2'):
- pGeneralState->m_pUCR = pObject;
- break;
- case FXBSTR_ID('H', 'T', 0, 0):
- pGeneralState->m_pHT = pObject;
- break;
- case FXBSTR_ID('F', 'L', 0, 0):
- pGeneralState->m_Flatness = pObject->GetNumber();
- break;
- case FXBSTR_ID('S', 'M', 0, 0):
- pGeneralState->m_Smoothness = pObject->GetNumber();
- break;
- case FXBSTR_ID('S', 'A', 0, 0):
- pGeneralState->m_StrokeAdjust = pObject->GetInteger();
- break;
- case FXBSTR_ID('A', 'I', 'S', 0):
- pGeneralState->m_AlphaSource = pObject->GetInteger();
- break;
- case FXBSTR_ID('T', 'K', 0, 0):
- pGeneralState->m_TextKnockout = pObject->GetInteger();
- break;
- }
- }
- pGeneralState->m_Matrix = m_CTM;
-}
-CPDF_ContentMarkItem::CPDF_ContentMarkItem() {
- m_ParamType = None;
-}
-CPDF_ContentMarkItem::CPDF_ContentMarkItem(const CPDF_ContentMarkItem& src) {
- m_MarkName = src.m_MarkName;
- m_ParamType = src.m_ParamType;
- if (m_ParamType == DirectDict) {
- m_pParam = ToDictionary(src.m_pParam->Clone());
- } else {
- m_pParam = src.m_pParam;
- }
-}
-CPDF_ContentMarkItem::~CPDF_ContentMarkItem() {
- if (m_ParamType == DirectDict && m_pParam)
- m_pParam->Release();
-}
-FX_BOOL CPDF_ContentMarkItem::HasMCID() const {
- if (m_pParam &&
- (m_ParamType == DirectDict || m_ParamType == PropertiesDict)) {
- return m_pParam->KeyExist("MCID");
- }
- return FALSE;
-}
-
-CPDF_ContentMarkData::CPDF_ContentMarkData(const CPDF_ContentMarkData& src)
- : m_Marks(src.m_Marks) {}
-
-int CPDF_ContentMarkData::CountItems() const {
- return pdfium::CollectionSize<int>(m_Marks);
-}
-
-int CPDF_ContentMarkData::GetMCID() const {
- for (const auto& mark : m_Marks) {
- CPDF_ContentMarkItem::ParamType type = mark.GetParamType();
- if (type == CPDF_ContentMarkItem::PropertiesDict ||
- type == CPDF_ContentMarkItem::DirectDict) {
- CPDF_Dictionary* pDict = mark.GetParam();
- if (pDict->KeyExist("MCID"))
- return pDict->GetIntegerBy("MCID");
- }
- }
- return -1;
-}
-
-void CPDF_ContentMarkData::AddMark(const CFX_ByteString& name,
- CPDF_Dictionary* pDict,
- FX_BOOL bDirect) {
- CPDF_ContentMarkItem item;
- item.SetName(name);
- if (pDict) {
- if (bDirect) {
- item.SetParam(CPDF_ContentMarkItem::DirectDict,
- ToDictionary(pDict->Clone()));
- } else {
- item.SetParam(CPDF_ContentMarkItem::PropertiesDict, pDict);
- }
- }
- m_Marks.push_back(item);
-}
-
-void CPDF_ContentMarkData::DeleteLastMark() {
- if (!m_Marks.empty())
- m_Marks.pop_back();
-}
-
-FX_BOOL CPDF_ContentMark::HasMark(const CFX_ByteStringC& mark) const {
- if (!m_pObject) {
- return FALSE;
- }
- for (int i = 0; i < m_pObject->CountItems(); i++) {
- CPDF_ContentMarkItem& item = m_pObject->GetItem(i);
- if (item.GetName() == mark) {
- return TRUE;
- }
- }
- return FALSE;
-}
-FX_BOOL CPDF_ContentMark::LookupMark(const CFX_ByteStringC& mark,
- CPDF_Dictionary*& pDict) const {
- if (!m_pObject) {
- return FALSE;
- }
- for (int i = 0; i < m_pObject->CountItems(); i++) {
- CPDF_ContentMarkItem& item = m_pObject->GetItem(i);
- if (item.GetName() == mark) {
- pDict = NULL;
- if (item.GetParamType() == CPDF_ContentMarkItem::PropertiesDict ||
- item.GetParamType() == CPDF_ContentMarkItem::DirectDict) {
- pDict = item.GetParam();
- }
- return TRUE;
- }
- }
- return FALSE;
-}
diff --git a/core/fpdfapi/fpdf_page/fpdf_page_image.cpp b/core/fpdfapi/fpdf_page/fpdf_page_image.cpp
index 247b0b9703..f66823657f 100644
--- a/core/fpdfapi/fpdf_page/fpdf_page_image.cpp
+++ b/core/fpdfapi/fpdf_page/fpdf_page_image.cpp
@@ -8,40 +8,7 @@
#include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h"
#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
-#include "core/include/fpdfapi/fpdf_pageobj.h"
-CPDF_ImageObject::CPDF_ImageObject() : m_pImage(nullptr) {}
-
-CPDF_ImageObject::~CPDF_ImageObject() {
- if (!m_pImage) {
- return;
- }
- if (m_pImage->IsInline() ||
- (m_pImage->GetStream() && m_pImage->GetStream()->GetObjNum() == 0)) {
- delete m_pImage;
- } else {
- m_pImage->GetDocument()->GetPageData()->ReleaseImage(m_pImage->GetStream());
- }
-}
-
-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();
-}
-void CPDF_ImageObject::CalcBoundingBox() {
- m_Left = m_Bottom = 0;
- m_Right = m_Top = 1.0f;
- m_Matrix.TransformRect(m_Left, m_Right, m_Top, m_Bottom);
-}
void CPDF_Image::Release() {
if (m_bInline || (m_pStream && m_pStream->GetObjNum() == 0)) {
delete this;
diff --git a/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp b/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp
index b62579813a..700103ed41 100644
--- a/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp
+++ b/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp
@@ -9,7 +9,14 @@
#include <vector>
#include "core/fpdfapi/fpdf_edit/include/cpdf_creator.h"
+#include "core/fpdfapi/fpdf_page/cpdf_allstates.h"
#include "core/fpdfapi/fpdf_page/include/cpdf_form.h"
+#include "core/fpdfapi/fpdf_page/include/cpdf_formobject.h"
+#include "core/fpdfapi/fpdf_page/include/cpdf_imageobject.h"
+#include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h"
+#include "core/fpdfapi/fpdf_page/include/cpdf_pathobject.h"
+#include "core/fpdfapi/fpdf_page/include/cpdf_shadingobject.h"
+#include "core/fpdfapi/fpdf_page/include/cpdf_textobject.h"
#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
#include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h"
#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
diff --git a/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp b/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp
index c1bb70ff80..c9f05ac5ab 100644
--- a/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp
+++ b/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp
@@ -8,8 +8,11 @@
#include <limits.h>
+#include "core/fpdfapi/fpdf_page/cpdf_allstates.h"
#include "core/fpdfapi/fpdf_page/include/cpdf_form.h"
#include "core/fpdfapi/fpdf_page/include/cpdf_page.h"
+#include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h"
+#include "core/fpdfapi/fpdf_page/include/cpdf_path.h"
#include "core/fpdfapi/fpdf_parser/cpdf_boolean.h"
#include "core/fpdfapi/fpdf_parser/cpdf_null.h"
#include "core/fpdfapi/fpdf_parser/fpdf_parser_utility.h"
diff --git a/core/fpdfapi/fpdf_page/include/cpdf_clippath.h b/core/fpdfapi/fpdf_page/include/cpdf_clippath.h
new file mode 100644
index 0000000000..4631e8266a
--- /dev/null
+++ b/core/fpdfapi/fpdf_page/include/cpdf_clippath.h
@@ -0,0 +1,34 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_CLIPPATH_H_
+#define CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_CLIPPATH_H_
+
+#include "core/fpdfapi/fpdf_page/cpdf_clippathdata.h"
+#include "core/fpdfapi/fpdf_page/include/cpdf_path.h"
+#include "core/include/fxcrt/fx_basic.h"
+#include "core/include/fxcrt/fx_coordinates.h"
+#include "core/include/fxcrt/fx_system.h"
+
+class CPDF_TextObject;
+
+class CPDF_ClipPath : public CFX_CountRef<CPDF_ClipPathData> {
+ public:
+ FX_DWORD GetPathCount() const { return m_pObject->m_PathCount; }
+ CPDF_Path GetPath(int i) const { return m_pObject->m_pPathList[i]; }
+ int GetClipType(int i) const { return m_pObject->m_pTypeList[i]; }
+ FX_DWORD GetTextCount() const { return m_pObject->m_TextCount; }
+ CPDF_TextObject* GetText(int i) const { return m_pObject->m_pTextList[i]; }
+ CFX_FloatRect GetClipBox() const;
+
+ void AppendPath(CPDF_Path path, int type, FX_BOOL bAutoMerge);
+ void DeletePath(int layer_index);
+
+ void AppendTexts(CPDF_TextObject** pTexts, int count);
+ void Transform(const CFX_Matrix& matrix);
+};
+
+#endif // CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_CLIPPATH_H_
diff --git a/core/fpdfapi/fpdf_page/include/cpdf_formobject.h b/core/fpdfapi/fpdf_page/include/cpdf_formobject.h
new file mode 100644
index 0000000000..47d40e0e8b
--- /dev/null
+++ b/core/fpdfapi/fpdf_page/include/cpdf_formobject.h
@@ -0,0 +1,34 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_FORMOBJECT_H_
+#define CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_FORMOBJECT_H_
+
+#include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h"
+#include "core/include/fxcrt/fx_coordinates.h"
+
+class Form;
+
+class CPDF_FormObject : public CPDF_PageObject {
+ public:
+ 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; };
+ CPDF_FormObject* AsForm() override { return this; };
+ const CPDF_FormObject* AsForm() const override { return this; };
+
+ void CalcBoundingBox();
+
+ CPDF_Form* m_pForm;
+ CFX_Matrix m_FormMatrix;
+};
+
+#endif // CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_FORMOBJECT_H_
diff --git a/core/fpdfapi/fpdf_page/include/cpdf_generalstate.h b/core/fpdfapi/fpdf_page/include/cpdf_generalstate.h
new file mode 100644
index 0000000000..3495b6c3ff
--- /dev/null
+++ b/core/fpdfapi/fpdf_page/include/cpdf_generalstate.h
@@ -0,0 +1,29 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_GENERALSTATE_H_
+#define CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_GENERALSTATE_H_
+
+#include "core/fpdfapi/fpdf_page/include/cpdf_generalstatedata.h"
+#include "core/include/fxcrt/fx_basic.h"
+
+class CPDF_GeneralState : public CFX_CountRef<CPDF_GeneralStateData> {
+ public:
+ void SetRenderIntent(const CFX_ByteString& ri);
+
+ int GetBlendType() const {
+ return m_pObject ? m_pObject->m_BlendType : FXDIB_BLEND_NORMAL;
+ }
+
+ int GetAlpha(FX_BOOL bStroke) const {
+ if (!m_pObject)
+ return 255;
+ return FXSYS_round(
+ (bStroke ? m_pObject->m_StrokeAlpha : m_pObject->m_FillAlpha) * 255);
+ }
+};
+
+#endif // CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_GENERALSTATE_H_
diff --git a/core/fpdfapi/fpdf_page/include/cpdf_generalstatedata.h b/core/fpdfapi/fpdf_page/include/cpdf_generalstatedata.h
new file mode 100644
index 0000000000..f2e5510ccc
--- /dev/null
+++ b/core/fpdfapi/fpdf_page/include/cpdf_generalstatedata.h
@@ -0,0 +1,49 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_GENERALSTATEDATA_H_
+#define CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_GENERALSTATEDATA_H_
+
+#include "core/include/fxcrt/fx_coordinates.h"
+#include "core/include/fxcrt/fx_string.h"
+#include "core/include/fxcrt/fx_system.h"
+#include "core/include/fxge/fx_dib.h"
+
+class CPDF_TransferFunc;
+class CPDF_Object;
+
+class CPDF_GeneralStateData {
+ public:
+ CPDF_GeneralStateData();
+ CPDF_GeneralStateData(const CPDF_GeneralStateData& src);
+ ~CPDF_GeneralStateData();
+
+ void SetBlendMode(const CFX_ByteStringC& blend_mode);
+
+ char m_BlendMode[16];
+ int m_BlendType;
+ CPDF_Object* m_pSoftMask;
+ FX_FLOAT m_SMaskMatrix[6];
+ FX_FLOAT m_StrokeAlpha;
+ FX_FLOAT m_FillAlpha;
+ CPDF_Object* m_pTR;
+ CPDF_TransferFunc* m_pTransferFunc;
+ CFX_Matrix m_Matrix;
+ int m_RenderIntent;
+ FX_BOOL m_StrokeAdjust;
+ FX_BOOL m_AlphaSource;
+ FX_BOOL m_TextKnockout;
+ FX_BOOL m_StrokeOP;
+ FX_BOOL m_FillOP;
+ int m_OPMode;
+ CPDF_Object* m_pBG;
+ CPDF_Object* m_pUCR;
+ CPDF_Object* m_pHT;
+ FX_FLOAT m_Flatness;
+ FX_FLOAT m_Smoothness;
+};
+
+#endif // CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_GENERALSTATEDATA_H_
diff --git a/core/fpdfapi/fpdf_page/include/cpdf_imageobject.h b/core/fpdfapi/fpdf_page/include/cpdf_imageobject.h
new file mode 100644
index 0000000000..dec60c9d9b
--- /dev/null
+++ b/core/fpdfapi/fpdf_page/include/cpdf_imageobject.h
@@ -0,0 +1,34 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_IMAGEOBJECT_H_
+#define CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_IMAGEOBJECT_H_
+
+#include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h"
+#include "core/include/fxcrt/fx_coordinates.h"
+
+class CPDF_Image;
+
+class CPDF_ImageObject : public CPDF_PageObject {
+ public:
+ CPDF_ImageObject();
+ ~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; };
+
+ void CalcBoundingBox();
+
+ CPDF_Image* m_pImage;
+ CFX_Matrix m_Matrix;
+};
+
+#endif // CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_IMAGEOBJECT_H_
diff --git a/core/fpdfapi/fpdf_page/include/cpdf_page.h b/core/fpdfapi/fpdf_page/include/cpdf_page.h
index 82c88d1c37..5e27ba2ec7 100644
--- a/core/fpdfapi/fpdf_page/include/cpdf_page.h
+++ b/core/fpdfapi/fpdf_page/include/cpdf_page.h
@@ -18,6 +18,9 @@ class CPDF_Object;
class CPDF_PageRenderCache;
class CPDF_ParseOptions;
+CPDF_Object* FPDFAPI_GetPageAttr(CPDF_Dictionary* pPageDict,
+ const CFX_ByteStringC& name);
+
class CPDF_Page : public CPDF_PageObjectHolder, public CFX_PrivateData {
public:
CPDF_Page();
diff --git a/core/fpdfapi/fpdf_page/include/cpdf_pageobject.h b/core/fpdfapi/fpdf_page/include/cpdf_pageobject.h
new file mode 100644
index 0000000000..2f55547b47
--- /dev/null
+++ b/core/fpdfapi/fpdf_page/include/cpdf_pageobject.h
@@ -0,0 +1,71 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_PAGEOBJECT_H_
+#define CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_PAGEOBJECT_H_
+
+#include "core/fpdfapi/fpdf_page/cpdf_contentmark.h"
+#include "core/fpdfapi/fpdf_page/cpdf_graphicstates.h"
+#include "core/include/fxcrt/fx_coordinates.h"
+#include "core/include/fxcrt/fx_system.h"
+
+class CPDF_TextObject;
+class CPDF_PathObject;
+class CPDF_ImageObject;
+class CPDF_ShadingObject;
+class CPDF_FormObject;
+
+class CPDF_PageObject : public CPDF_GraphicStates {
+ public:
+ enum Type {
+ TEXT = 1,
+ PATH,
+ IMAGE,
+ SHADING,
+ FORM,
+ };
+
+ CPDF_PageObject();
+ virtual ~CPDF_PageObject();
+
+ 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; }
+ virtual bool IsPath() const { return false; }
+ virtual bool IsImage() const { return false; }
+ virtual bool IsShading() const { return false; }
+ virtual bool IsForm() const { return false; }
+ virtual CPDF_TextObject* AsText() { return nullptr; }
+ virtual const CPDF_TextObject* AsText() const { return nullptr; }
+ virtual CPDF_PathObject* AsPath() { return nullptr; }
+ virtual const CPDF_PathObject* AsPath() const { return nullptr; }
+ virtual CPDF_ImageObject* AsImage() { return nullptr; }
+ virtual const CPDF_ImageObject* AsImage() const { return nullptr; }
+ virtual CPDF_ShadingObject* AsShading() { return nullptr; }
+ virtual const CPDF_ShadingObject* AsShading() const { return nullptr; }
+ virtual CPDF_FormObject* AsForm() { return nullptr; }
+ virtual const CPDF_FormObject* AsForm() const { return nullptr; }
+
+ void TransformClipPath(CFX_Matrix& matrix);
+ void TransformGeneralState(CFX_Matrix& matrix);
+ FX_RECT GetBBox(const CFX_Matrix* pMatrix) const;
+
+ FX_FLOAT m_Left;
+ FX_FLOAT m_Right;
+ FX_FLOAT m_Top;
+ FX_FLOAT m_Bottom;
+ CPDF_ContentMark m_ContentMark;
+
+ protected:
+ void CopyData(const CPDF_PageObject* pSrcObject);
+
+ private:
+ CPDF_PageObject(const CPDF_PageObject& src) = delete;
+ void operator=(const CPDF_PageObject& src) = delete;
+};
+
+#endif // CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_PAGEOBJECT_H_
diff --git a/core/fpdfapi/fpdf_page/include/cpdf_path.h b/core/fpdfapi/fpdf_page/include/cpdf_path.h
new file mode 100644
index 0000000000..a90115486a
--- /dev/null
+++ b/core/fpdfapi/fpdf_page/include/cpdf_path.h
@@ -0,0 +1,50 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_PATH_H_
+#define CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_PATH_H_
+
+#include "core/include/fxcrt/fx_system.h"
+#include "core/include/fxge/fx_ge.h"
+
+class CPDF_Path : public CFX_CountRef<CFX_PathData> {
+ public:
+ int GetPointCount() const { return m_pObject->m_PointCount; }
+ int GetFlag(int index) const { return m_pObject->m_pPoints[index].m_Flag; }
+
+ FX_FLOAT GetPointX(int index) const {
+ return m_pObject->m_pPoints[index].m_PointX;
+ }
+
+ FX_FLOAT GetPointY(int index) const {
+ return m_pObject->m_pPoints[index].m_PointY;
+ }
+
+ FX_PATHPOINT* GetPoints() const { return m_pObject->m_pPoints; }
+ CFX_FloatRect GetBoundingBox() const { return m_pObject->GetBoundingBox(); }
+
+ CFX_FloatRect GetBoundingBox(FX_FLOAT line_width,
+ FX_FLOAT miter_limit) const {
+ return m_pObject->GetBoundingBox(line_width, miter_limit);
+ }
+
+ FX_BOOL IsRect() const { return m_pObject->IsRect(); }
+
+ void Transform(const CFX_Matrix* pMatrix) { GetModify()->Transform(pMatrix); }
+
+ void Append(CPDF_Path src, const CFX_Matrix* pMatrix) {
+ m_pObject->Append(src.m_pObject, pMatrix);
+ }
+
+ void AppendRect(FX_FLOAT left,
+ FX_FLOAT bottom,
+ FX_FLOAT right,
+ FX_FLOAT top) {
+ m_pObject->AppendRect(left, bottom, right, top);
+ }
+};
+
+#endif // CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_PATH_H_
diff --git a/core/fpdfapi/fpdf_page/include/cpdf_pathobject.h b/core/fpdfapi/fpdf_page/include/cpdf_pathobject.h
new file mode 100644
index 0000000000..30df0c2937
--- /dev/null
+++ b/core/fpdfapi/fpdf_page/include/cpdf_pathobject.h
@@ -0,0 +1,36 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_PATHOBJECT_H_
+#define CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_PATHOBJECT_H_
+
+#include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h"
+#include "core/fpdfapi/fpdf_page/include/cpdf_path.h"
+#include "core/include/fxcrt/fx_coordinates.h"
+#include "core/include/fxcrt/fx_system.h"
+
+class CPDF_PathObject : public CPDF_PageObject {
+ public:
+ 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 CalcBoundingBox();
+
+ CPDF_Path m_Path;
+ int m_FillType;
+ FX_BOOL m_bStroke;
+ CFX_Matrix m_Matrix;
+};
+
+#endif // CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_PATHOBJECT_H_
diff --git a/core/fpdfapi/fpdf_page/include/cpdf_shadingobject.h b/core/fpdfapi/fpdf_page/include/cpdf_shadingobject.h
new file mode 100644
index 0000000000..f43a1e3a4f
--- /dev/null
+++ b/core/fpdfapi/fpdf_page/include/cpdf_shadingobject.h
@@ -0,0 +1,34 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_SHADINGOBJECT_H_
+#define CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_SHADINGOBJECT_H_
+
+#include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h"
+#include "core/include/fxcrt/fx_coordinates.h"
+
+class CPDF_ShadingPattern;
+
+class CPDF_ShadingObject : public CPDF_PageObject {
+ public:
+ CPDF_ShadingObject();
+ ~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; };
+ CPDF_ShadingObject* AsShading() override { return this; };
+ const CPDF_ShadingObject* AsShading() const override { return this; };
+
+ void CalcBoundingBox();
+
+ CPDF_ShadingPattern* m_pShading;
+ CFX_Matrix m_Matrix;
+};
+
+#endif // CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_SHADINGOBJECT_H_
diff --git a/core/fpdfapi/fpdf_page/include/cpdf_textobject.h b/core/fpdfapi/fpdf_page/include/cpdf_textobject.h
new file mode 100644
index 0000000000..9aaa2f0160
--- /dev/null
+++ b/core/fpdfapi/fpdf_page/include/cpdf_textobject.h
@@ -0,0 +1,69 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_TEXTOBJECT_H_
+#define CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_TEXTOBJECT_H_
+
+#include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h"
+#include "core/include/fxcrt/fx_string.h"
+#include "core/include/fxcrt/fx_system.h"
+
+struct CPDF_TextObjectItem {
+ FX_DWORD m_CharCode;
+ FX_FLOAT m_OriginX;
+ FX_FLOAT m_OriginY;
+};
+
+class CPDF_TextObject : public CPDF_PageObject {
+ public:
+ CPDF_TextObject();
+ ~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; };
+ CPDF_TextObject* AsText() override { return this; };
+ 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;
+ FX_FLOAT GetCharWidth(FX_DWORD charcode) 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 SetText(const CFX_ByteString& text);
+ void SetPosition(FX_FLOAT x, FX_FLOAT y);
+
+ void RecalcPositionData() { CalcPositionData(nullptr, nullptr, 1); }
+
+ protected:
+ friend class CPDF_RenderStatus;
+ friend class CPDF_StreamContentParser;
+ friend class CPDF_TextRenderer;
+
+ void SetSegments(const CFX_ByteString* pStrs, FX_FLOAT* pKerning, int nSegs);
+
+ void CalcPositionData(FX_FLOAT* pTextAdvanceX,
+ FX_FLOAT* pTextAdvanceY,
+ FX_FLOAT horz_scale,
+ int level = 0);
+
+ FX_FLOAT m_PosX;
+ FX_FLOAT m_PosY;
+ int m_nChars;
+ FX_DWORD* m_pCharCodes;
+ FX_FLOAT* m_pCharPos;
+};
+
+#endif // CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_TEXTOBJECT_H_
diff --git a/core/fpdfapi/fpdf_page/include/cpdf_textstatedata.h b/core/fpdfapi/fpdf_page/include/cpdf_textstatedata.h
new file mode 100644
index 0000000000..1fcc1fe8c2
--- /dev/null
+++ b/core/fpdfapi/fpdf_page/include/cpdf_textstatedata.h
@@ -0,0 +1,31 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_TEXTSTATEDATA_H_
+#define CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_TEXTSTATEDATA_H_
+
+#include "core/include/fxcrt/fx_system.h"
+
+class CPDF_Font;
+class CPDF_Document;
+
+class CPDF_TextStateData {
+ public:
+ CPDF_TextStateData();
+ CPDF_TextStateData(const CPDF_TextStateData& src);
+ ~CPDF_TextStateData();
+
+ CPDF_Font* m_pFont;
+ CPDF_Document* m_pDocument;
+ FX_FLOAT m_FontSize;
+ FX_FLOAT m_CharSpace;
+ FX_FLOAT m_WordSpace;
+ FX_FLOAT m_Matrix[4];
+ int m_TextMode;
+ FX_FLOAT m_CTM[4];
+};
+
+#endif // CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_TEXTSTATEDATA_H_
diff --git a/core/fpdfapi/fpdf_page/pageint.h b/core/fpdfapi/fpdf_page/pageint.h
index eab3d42b2b..e6a150072e 100644
--- a/core/fpdfapi/fpdf_page/pageint.h
+++ b/core/fpdfapi/fpdf_page/pageint.h
@@ -12,13 +12,25 @@
#include <unordered_map>
#include <vector>
+#include "core/fpdfapi/fpdf_page/cpdf_contentmark.h"
#include "core/fpdfapi/fpdf_page/cpdf_parseoptions.h"
#include "core/fpdfapi/fpdf_page/include/cpdf_pageobjectholder.h"
-#include "core/include/fpdfapi/fpdf_pageobj.h"
+#include "core/include/fpdfapi/fpdf_resource.h"
+#include "core/include/fxge/fx_ge.h"
class CPDF_AllStates;
-class CPDF_ParseOptions;
+class CPDF_ColorSpace;
+class CPDF_Font;
+class CPDF_FontEncoding;
+class CPDF_Form;
class CPDF_IccProfile;
+class CPDF_Image;
+class CPDF_ImageObject;
+class CPDF_ParseOptions;
+class CPDF_Pattern;
+class CPDF_StreamAcc;
+class CPDF_TextObject;
+class CPDF_Type3Char;
#define PARSE_STEP_LIMIT 100
@@ -308,17 +320,6 @@ class CPDF_ContentParser {
FX_DWORD m_CurrentOffset;
std::unique_ptr<CPDF_StreamContentParser> m_pParser;
};
-class CPDF_AllStates : public CPDF_GraphicStates {
- public:
- CPDF_AllStates();
- ~CPDF_AllStates();
- void Copy(const CPDF_AllStates& src);
- void ProcessExtGS(CPDF_Dictionary* pGS, CPDF_StreamContentParser* pParser);
- void SetLineDash(CPDF_Array*, FX_FLOAT, FX_FLOAT scale);
- CFX_Matrix m_TextMatrix, m_CTM, m_ParentMatrix;
- FX_FLOAT m_TextX, m_TextY, m_TextLineX, m_TextLineY;
- FX_FLOAT m_TextLeading, m_TextRise, m_TextHorzScale;
-};
class CPDF_DocPageData {
public: