summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2016-02-17 16:58:49 -0800
committerTom Sepez <tsepez@chromium.org>2016-02-17 16:58:49 -0800
commitdee2d7ba656cdf8111f879485146e0900630826a (patch)
tree3ea64c42d591456fedcf3e3cdd9d4f12dcdf1e18 /core
parent1e1d3b0f2bc6b6c185b37e0aa6b8663e901dc8bf (diff)
downloadpdfium-dee2d7ba656cdf8111f879485146e0900630826a.tar.xz
Banish CFX_ObjectArray to the XFA side.
Tidy whitespace, add missing consts in a few places. Remove a few pointless typedefs. R=thestig@chromium.org Review URL: https://codereview.chromium.org/1707953002 .
Diffstat (limited to 'core')
-rw-r--r--core/include/fpdfapi/fpdf_pageobj.h135
-rw-r--r--core/include/fxcrt/fx_basic.h2
-rw-r--r--core/include/fxcrt/fx_xml.h11
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp47
-rw-r--r--core/src/fpdfapi/fpdf_render/fpdf_render.cpp2
-rw-r--r--core/src/fpdfdoc/doc_annot.cpp4
-rw-r--r--core/src/fxcrt/fx_xml_parser.cpp70
7 files changed, 94 insertions, 177 deletions
diff --git a/core/include/fpdfapi/fpdf_pageobj.h b/core/include/fpdfapi/fpdf_pageobj.h
index 42248c7dd1..9190fd9270 100644
--- a/core/include/fpdfapi/fpdf_pageobj.h
+++ b/core/include/fpdfapi/fpdf_pageobj.h
@@ -7,6 +7,8 @@
#ifndef CORE_INCLUDE_FPDFAPI_FPDF_PAGEOBJ_H_
#define CORE_INCLUDE_FPDFAPI_FPDF_PAGEOBJ_H_
+#include <vector>
+
#include "core/include/fpdfapi/fpdf_resource.h"
#include "core/include/fxge/fx_ge.h"
@@ -31,42 +33,36 @@ class CPDF_TextState;
class CPDF_TextStateData;
class CPDF_TransferFunc;
-typedef CFX_PathData CPDF_PathData;
-
class CPDF_Path : public CFX_CountRef<CFX_PathData> {
public:
- int GetPointCount() { return m_pObject->m_PointCount; }
-
- int GetFlag(int index) { return m_pObject->m_pPoints[index].m_Flag; }
-
- FX_FLOAT GetPointX(int index) { return m_pObject->m_pPoints[index].m_PointX; }
-
- FX_FLOAT GetPointY(int index) { return m_pObject->m_pPoints[index].m_PointY; }
-
- FX_PATHPOINT* GetPoints() { return m_pObject->m_pPoints; }
-
+ 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);
}
-
- FX_BOOL IsRect() const { return m_pObject->IsRect(); }
};
+
class CPDF_ClipPathData {
public:
CPDF_ClipPathData();
@@ -75,72 +71,53 @@ class CPDF_ClipPathData {
void SetCount(int path_count, int text_count);
- public:
int m_PathCount;
-
CPDF_Path* m_pPathList;
-
uint8_t* m_pTypeList;
-
int m_TextCount;
-
CPDF_TextObject** m_pTextList;
};
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);
};
+
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;
};
+
class CPDF_ColorState : public CFX_CountRef<CPDF_ColorStateData> {
public:
CPDF_Color* GetFillColor() const {
- return m_pObject ? &m_pObject->m_FillColor : NULL;
+ return m_pObject ? &m_pObject->m_FillColor : nullptr;
}
CPDF_Color* GetStrokeColor() const {
- return m_pObject ? &m_pObject->m_StrokeColor : NULL;
+ 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:
@@ -150,104 +127,69 @@ class CPDF_ColorState : public CFX_CountRef<CPDF_ColorStateData> {
FX_FLOAT* pValue,
int nValues);
};
-typedef CFX_GraphStateData CPDF_GraphStateData;
+
class CPDF_GraphState : public CFX_CountRef<CFX_GraphStateData> {
- public:
};
+
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];
};
+
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;
};
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;
};
+
class CPDF_GeneralState : public CFX_CountRef<CPDF_GeneralStateData> {
public:
void SetRenderIntent(const CFX_ByteString& ri);
@@ -263,61 +205,52 @@ class CPDF_GeneralState : public CFX_CountRef<CPDF_GeneralStateData> {
: 255;
}
};
+
class CPDF_ContentMarkItem {
public:
enum ParamType { None, PropertiesDict, DirectDict };
CPDF_ContentMarkItem();
-
CPDF_ContentMarkItem(const CPDF_ContentMarkItem& src);
-
~CPDF_ContentMarkItem();
- inline const CFX_ByteString& GetName() const { return m_MarkName; }
-
- inline ParamType GetParamType() const { return m_ParamType; }
-
- inline CPDF_Dictionary* GetParam() const { return m_pParam; }
-
- inline FX_BOOL HasMCID() const;
-
- inline void SetName(const CFX_ByteString& name) { m_MarkName = name; }
-
- inline void SetParam(ParamType type, CPDF_Dictionary* param) {
+ 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;
};
+
class CPDF_ContentMarkData {
public:
CPDF_ContentMarkData() {}
-
CPDF_ContentMarkData(const CPDF_ContentMarkData& src);
- inline int CountItems() const { return m_Marks.GetSize(); }
-
- inline CPDF_ContentMarkItem& GetItem(int index) const {
+ 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:
- CFX_ObjectArray<CPDF_ContentMarkItem> m_Marks;
+ std::vector<CPDF_ContentMarkItem> m_Marks;
};
+
class CPDF_ContentMark : public CFX_CountRef<CPDF_ContentMarkData> {
public:
int GetMCID() const { return m_pObject ? m_pObject->GetMCID() : -1; }
diff --git a/core/include/fxcrt/fx_basic.h b/core/include/fxcrt/fx_basic.h
index 3acdda7797..7f47122dea 100644
--- a/core/include/fxcrt/fx_basic.h
+++ b/core/include/fxcrt/fx_basic.h
@@ -444,6 +444,7 @@ typedef CFX_ArrayTemplate<int32_t> CFX_Int32Array;
typedef CFX_ArrayTemplate<void*> CFX_PtrArray;
#endif // PDF_ENABLE_XFA
+#ifdef PDF_ENABLE_XFA
template <class ObjectClass>
class CFX_ObjectArray : public CFX_BasicArray {
public:
@@ -545,7 +546,6 @@ class CFX_ObjectArray : public CFX_BasicArray {
CFX_BasicArray::SetSize(0);
}
};
-#ifdef PDF_ENABLE_XFA
typedef CFX_ObjectArray<CFX_ByteString> CFX_ByteStringArray;
typedef CFX_ObjectArray<CFX_WideString> CFX_WideStringArray;
class CFX_BaseSegmentedArray {
diff --git a/core/include/fxcrt/fx_xml.h b/core/include/fxcrt/fx_xml.h
index e1255c1f30..f18392c6ee 100644
--- a/core/include/fxcrt/fx_xml.h
+++ b/core/include/fxcrt/fx_xml.h
@@ -7,12 +7,15 @@
#ifndef CORE_INCLUDE_FXCRT_FX_XML_H_
#define CORE_INCLUDE_FXCRT_FX_XML_H_
+#include <memory>
#include <vector>
#include "core/include/fxcrt/fx_basic.h"
class CXML_AttrItem {
public:
+ bool Matches(const CFX_ByteStringC& space, const CFX_ByteStringC& name) const;
+
CFX_ByteString m_QSpaceName;
CFX_ByteString m_AttrName;
CFX_WideString m_Value;
@@ -20,18 +23,15 @@ class CXML_AttrItem {
class CXML_AttrMap {
public:
- CXML_AttrMap() { m_pMap = NULL; }
- ~CXML_AttrMap() { RemoveAll(); }
const CFX_WideString* Lookup(const CFX_ByteStringC& space,
const CFX_ByteStringC& name) const;
void SetAt(const CFX_ByteStringC& space,
const CFX_ByteStringC& name,
const CFX_WideStringC& value);
- void RemoveAt(const CFX_ByteStringC& space, const CFX_ByteStringC& name);
- void RemoveAll();
int GetSize() const;
CXML_AttrItem& GetAt(int index) const;
- CFX_ObjectArray<CXML_AttrItem>* m_pMap;
+
+ std::unique_ptr<std::vector<CXML_AttrItem>> m_pMap;
};
class CXML_Content {
@@ -41,6 +41,7 @@ class CXML_Content {
m_bCDATA = bCDATA;
m_Content = content;
}
+
FX_BOOL m_bCDATA;
CFX_WideString m_Content;
};
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp
index a428287e19..818ec8fd2f 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp
@@ -11,6 +11,7 @@
#include "core/include/fpdfapi/fpdf_pageobj.h"
#include "core/include/fpdfapi/fpdf_render.h"
#include "core/src/fpdfapi/fpdf_render/render_int.h"
+#include "third_party/base/stl_util.h"
void CPDF_GraphicStates::DefaultStates() {
m_ColorState.New()->Default();
@@ -610,44 +611,48 @@ FX_BOOL CPDF_ContentMarkItem::HasMCID() const {
}
return FALSE;
}
-CPDF_ContentMarkData::CPDF_ContentMarkData(const CPDF_ContentMarkData& src) {
- for (int i = 0; i < src.m_Marks.GetSize(); i++) {
- m_Marks.Add(src.m_Marks[i]);
- }
+
+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 {
- CPDF_ContentMarkItem::ParamType type = CPDF_ContentMarkItem::None;
- for (int i = 0; i < m_Marks.GetSize(); i++) {
- type = m_Marks[i].GetParamType();
+ for (const auto& mark : m_Marks) {
+ CPDF_ContentMarkItem::ParamType type = mark.GetParamType();
if (type == CPDF_ContentMarkItem::PropertiesDict ||
type == CPDF_ContentMarkItem::DirectDict) {
- CPDF_Dictionary* pDict = m_Marks[i].GetParam();
- if (pDict->KeyExist("MCID")) {
+ 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 = m_Marks.Add();
+ CPDF_ContentMarkItem item;
item.SetName(name);
- if (!pDict) {
- return;
+ if (pDict) {
+ if (bDirect) {
+ item.SetParam(CPDF_ContentMarkItem::DirectDict,
+ ToDictionary(pDict->Clone()));
+ } else {
+ item.SetParam(CPDF_ContentMarkItem::PropertiesDict, pDict);
+ }
}
- item.SetParam(bDirect ? CPDF_ContentMarkItem::DirectDict
- : CPDF_ContentMarkItem::PropertiesDict,
- bDirect ? ToDictionary(pDict->Clone()) : pDict);
+ m_Marks.push_back(item);
}
+
void CPDF_ContentMarkData::DeleteLastMark() {
- int size = m_Marks.GetSize();
- if (size == 0) {
- return;
- }
- m_Marks.RemoveAt(size - 1);
+ if (!m_Marks.empty())
+ m_Marks.pop_back();
}
+
FX_BOOL CPDF_ContentMark::HasMark(const CFX_ByteStringC& mark) const {
if (!m_pObject) {
return FALSE;
diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render.cpp
index 147de51f4d..8e205df281 100644
--- a/core/src/fpdfapi/fpdf_render/fpdf_render.cpp
+++ b/core/src/fpdfapi/fpdf_render/fpdf_render.cpp
@@ -1332,7 +1332,7 @@ FX_BOOL IPDF_OCContext::CheckObjectVisible(const CPDF_PageObject* pObj) {
const CPDF_ContentMarkData* pData = pObj->m_ContentMark;
int nItems = pData->CountItems();
for (int i = 0; i < nItems; i++) {
- CPDF_ContentMarkItem& item = pData->GetItem(i);
+ const CPDF_ContentMarkItem& item = pData->GetItem(i);
if (item.GetName() == "OC" &&
item.GetParamType() == CPDF_ContentMarkItem::PropertiesDict &&
!CheckOCGVisible(item.GetParam())) {
diff --git a/core/src/fpdfdoc/doc_annot.cpp b/core/src/fpdfdoc/doc_annot.cpp
index a73d24410c..4b0b2b54bc 100644
--- a/core/src/fpdfdoc/doc_annot.cpp
+++ b/core/src/fpdfdoc/doc_annot.cpp
@@ -310,7 +310,7 @@ void CPDF_Annot::DrawBorder(CFX_RenderDevice* pDevice,
int B = (int32_t)(pColor->GetNumberAt(2) * 255);
argb = ArgbEncode(0xff, R, G, B);
}
- CPDF_GraphStateData graph_state;
+ CFX_GraphStateData graph_state;
graph_state.m_LineWidth = width;
if (style_char == 'D') {
if (pDashArray) {
@@ -335,7 +335,7 @@ void CPDF_Annot::DrawBorder(CFX_RenderDevice* pDevice,
}
CFX_FloatRect rect;
GetRect(rect);
- CPDF_PathData path;
+ CFX_PathData path;
width /= 2;
path.AppendRect(rect.left + width, rect.bottom + width, rect.right - width,
rect.top - width);
diff --git a/core/src/fxcrt/fx_xml_parser.cpp b/core/src/fxcrt/fx_xml_parser.cpp
index 88789437c9..ab729eebaf 100644
--- a/core/src/fxcrt/fx_xml_parser.cpp
+++ b/core/src/fxcrt/fx_xml_parser.cpp
@@ -8,6 +8,7 @@
#include "core/include/fxcrt/fx_ext.h"
#include "core/include/fxcrt/fx_xml.h"
+#include "third_party/base/stl_util.h"
CXML_Parser::~CXML_Parser() {
if (m_bOwnedStream) {
@@ -748,67 +749,44 @@ FX_DWORD CXML_Element::FindElement(CXML_Element* pChild) const {
}
return (FX_DWORD)-1;
}
+
+bool CXML_AttrItem::Matches(const CFX_ByteStringC& space,
+ const CFX_ByteStringC& name) const {
+ return (space.IsEmpty() || m_QSpaceName == space) && m_AttrName == name;
+}
+
const CFX_WideString* CXML_AttrMap::Lookup(const CFX_ByteStringC& space,
const CFX_ByteStringC& name) const {
- if (!m_pMap) {
- return NULL;
- }
- for (int i = 0; i < m_pMap->GetSize(); i++) {
- CXML_AttrItem& item = GetAt(i);
- if ((space.IsEmpty() || item.m_QSpaceName == space) &&
- item.m_AttrName == name) {
+ if (!m_pMap)
+ return nullptr;
+
+ for (const auto& item : *m_pMap) {
+ if (item.Matches(space, name))
return &item.m_Value;
- }
}
- return NULL;
+ return nullptr;
}
+
void CXML_AttrMap::SetAt(const CFX_ByteStringC& space,
const CFX_ByteStringC& name,
const CFX_WideStringC& value) {
- for (int i = 0; i < GetSize(); i++) {
- CXML_AttrItem& item = GetAt(i);
- if ((space.IsEmpty() || item.m_QSpaceName == space) &&
- item.m_AttrName == name) {
+ if (!m_pMap)
+ m_pMap.reset(new std::vector<CXML_AttrItem>);
+
+ for (CXML_AttrItem& item : *m_pMap) {
+ if (item.Matches(space, name)) {
item.m_Value = value;
return;
}
}
- if (!m_pMap) {
- m_pMap = new CFX_ObjectArray<CXML_AttrItem>;
- }
- CXML_AttrItem* pItem = (CXML_AttrItem*)m_pMap->AddSpace();
- if (!pItem) {
- return;
- }
- pItem->m_QSpaceName = space;
- pItem->m_AttrName = name;
- pItem->m_Value = value;
-}
-void CXML_AttrMap::RemoveAt(const CFX_ByteStringC& space,
- const CFX_ByteStringC& name) {
- if (!m_pMap) {
- return;
- }
- for (int i = 0; i < m_pMap->GetSize(); i++) {
- CXML_AttrItem& item = GetAt(i);
- if ((space.IsEmpty() || item.m_QSpaceName == space) &&
- item.m_AttrName == name) {
- m_pMap->RemoveAt(i);
- return;
- }
- }
+
+ m_pMap->push_back({space, name, value});
}
+
int CXML_AttrMap::GetSize() const {
- return m_pMap ? m_pMap->GetSize() : 0;
+ return m_pMap ? pdfium::CollectionSize<int>(*m_pMap) : 0;
}
+
CXML_AttrItem& CXML_AttrMap::GetAt(int index) const {
return (*m_pMap)[index];
}
-void CXML_AttrMap::RemoveAll() {
- if (!m_pMap) {
- return;
- }
- m_pMap->RemoveAll();
- delete m_pMap;
- m_pMap = NULL;
-}