summaryrefslogtreecommitdiff
path: root/core/src
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/src
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/src')
-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
4 files changed, 53 insertions, 70 deletions
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp
index 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;
-}