From dee2d7ba656cdf8111f879485146e0900630826a Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Wed, 17 Feb 2016 16:58:49 -0800 Subject: 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 . --- core/include/fpdfapi/fpdf_pageobj.h | 135 ++++++--------------- core/include/fxcrt/fx_basic.h | 2 +- core/include/fxcrt/fx_xml.h | 11 +- .../fpdfapi/fpdf_page/fpdf_page_graph_state.cpp | 47 +++---- core/src/fpdfapi/fpdf_render/fpdf_render.cpp | 2 +- core/src/fpdfdoc/doc_annot.cpp | 4 +- core/src/fxcrt/fx_xml_parser.cpp | 70 ++++------- fpdfsdk/src/fxedit/fxet_pageobjs.cpp | 2 +- 8 files changed, 95 insertions(+), 178 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 + #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 { 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 { 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 { 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 { FX_FLOAT* pValue, int nValues); }; -typedef CFX_GraphStateData CPDF_GraphStateData; + class CPDF_GraphState : public CFX_CountRef { - 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 { 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 { public: void SetRenderIntent(const CFX_ByteString& ri); @@ -263,61 +205,52 @@ class CPDF_GeneralState : public CFX_CountRef { : 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 m_Marks; + std::vector m_Marks; }; + class CPDF_ContentMark : public CFX_CountRef { 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 CFX_Int32Array; typedef CFX_ArrayTemplate CFX_PtrArray; #endif // PDF_ENABLE_XFA +#ifdef PDF_ENABLE_XFA template 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_ByteStringArray; typedef CFX_ObjectArray 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 #include #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* m_pMap; + + std::unique_ptr> 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(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); + + 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* 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(*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; -} diff --git a/fpdfsdk/src/fxedit/fxet_pageobjs.cpp b/fpdfsdk/src/fxedit/fxet_pageobjs.cpp index c3bd79759b..ed96b96654 100644 --- a/fpdfsdk/src/fxedit/fxet_pageobjs.cpp +++ b/fpdfsdk/src/fxedit/fxet_pageobjs.cpp @@ -413,7 +413,7 @@ static void AddRectToPageObjects(CPDF_PageObjectHolder* pObjectHolder, FX_COLORREF crFill, const CPDF_Rect& rcFill) { std::unique_ptr pPathObj(new CPDF_PathObject); - CPDF_PathData* pPathData = pPathObj->m_Path.GetModify(); + CFX_PathData* pPathData = pPathObj->m_Path.GetModify(); pPathData->AppendRect(rcFill.left, rcFill.bottom, rcFill.right, rcFill.top); FX_FLOAT rgb[3]; -- cgit v1.2.3