Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(253)

Side by Side Diff: xfa/fxfa/parser/cxfa_box.cpp

Issue 2648773003: Replace CXFA_StrokeArray and CXFA_WidgetArray with std::vector (Closed)
Patch Set: pass by pointer Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "xfa/fxfa/parser/cxfa_box.h" 7 #include "xfa/fxfa/parser/cxfa_box.h"
8 8
9 #include "xfa/fxfa/parser/cxfa_corner.h" 9 #include "xfa/fxfa/parser/cxfa_corner.h"
10 #include "xfa/fxfa/parser/cxfa_measurement.h" 10 #include "xfa/fxfa/parser/cxfa_measurement.h"
11 #include "xfa/fxfa/parser/xfa_object.h" 11 #include "xfa/fxfa/parser/xfa_object.h"
12 12
13 namespace { 13 namespace {
14 14
15 void GetStrokesInternal(CXFA_Node* pNode, 15 void GetStrokesInternal(CXFA_Node* pNode,
16 CXFA_StrokeArray& strokes, 16 std::vector<CXFA_Stroke>* strokes,
17 bool bNull) { 17 bool bNull) {
18 strokes.RemoveAll(); 18 strokes->clear();
19 if (!pNode) 19 if (!pNode)
20 return; 20 return;
21 21
22 strokes.SetSize(8); 22 strokes->resize(8);
23 int32_t i, j; 23 int32_t i, j;
24 for (i = 0, j = 0; i < 4; i++) { 24 for (i = 0, j = 0; i < 4; i++) {
25 CXFA_Corner corner = 25 CXFA_Corner corner =
26 CXFA_Corner(pNode->GetProperty(i, XFA_Element::Corner, i == 0)); 26 CXFA_Corner(pNode->GetProperty(i, XFA_Element::Corner, i == 0));
27 if (corner || i == 0) 27 if (corner || i == 0)
28 strokes.SetAt(j, corner); 28 (*strokes)[j] = corner;
29 else if (bNull) 29 else if (bNull)
30 strokes.SetAt(j, CXFA_Stroke(nullptr)); 30 (*strokes)[j] = CXFA_Stroke(nullptr);
npm 2017/01/23 14:49:50 Now this can be CXFA_Stroke(), right?
Tom Sepez 2017/01/23 18:36:51 Actually, now that I added the default ctor, the r
npm 2017/01/23 18:51:51 Acknowledged.
31 else if (i == 1) 31 else if (i == 1 || i == 2)
32 strokes.SetAt(j, strokes[0]); 32 (*strokes)[j] = (*strokes)[0];
33 else if (i == 2)
34 strokes.SetAt(j, strokes[0]);
35 else 33 else
36 strokes.SetAt(j, strokes[2]); 34 (*strokes)[j] = (*strokes)[2];
37 35
38 j++; 36 j++;
39 CXFA_Edge edge = 37 CXFA_Edge edge =
40 CXFA_Edge(pNode->GetProperty(i, XFA_Element::Edge, i == 0)); 38 CXFA_Edge(pNode->GetProperty(i, XFA_Element::Edge, i == 0));
41 if (edge || i == 0) 39 if (edge || i == 0)
42 strokes.SetAt(j, edge); 40 (*strokes)[j] = edge;
43 else if (bNull) 41 else if (bNull)
44 strokes.SetAt(j, CXFA_Stroke(nullptr)); 42 (*strokes)[j] = CXFA_Stroke(nullptr);
npm 2017/01/23 14:49:50 ditto
Tom Sepez 2017/01/23 18:36:51 ditto
npm 2017/01/23 18:51:51 Acknowledged.
45 else if (i == 1) 43 else if (i == 1 || i == 2)
46 strokes.SetAt(j, strokes[1]); 44 (*strokes)[j] = (*strokes)[1];
47 else if (i == 2)
48 strokes.SetAt(j, strokes[1]);
49 else 45 else
50 strokes.SetAt(j, strokes[3]); 46 (*strokes)[j] = (*strokes)[3];
51 47
52 j++; 48 j++;
53 } 49 }
54 } 50 }
55 51
56 static int32_t Style3D(const CXFA_StrokeArray& strokes, CXFA_Stroke& stroke) { 52 static int32_t Style3D(const std::vector<CXFA_Stroke>& strokes,
57 int32_t iCount = strokes.GetSize(); 53 CXFA_Stroke& stroke) {
58 if (iCount < 1) 54 if (strokes.empty())
59 return 0; 55 return 0;
60 56
61 stroke = strokes[0]; 57 stroke = strokes[0];
62 for (int32_t i = 1; i < iCount; i++) { 58 for (size_t i = 1; i < strokes.size(); i++) {
63 CXFA_Stroke find = strokes[i]; 59 CXFA_Stroke find = strokes[i];
64 if (!find) 60 if (!find)
65 continue; 61 continue;
66 62
67 if (!stroke) 63 if (!stroke)
68 stroke = find; 64 stroke = find;
69 else if (stroke.GetStrokeType() != find.GetStrokeType()) 65 else if (stroke.GetStrokeType() != find.GetStrokeType())
70 stroke = find; 66 stroke = find;
71 break; 67 break;
72 } 68 }
(...skipping 25 matching lines...) Expand all
98 return 0; 94 return 0;
99 return m_pNode->CountChildren(XFA_Element::Edge); 95 return m_pNode->CountChildren(XFA_Element::Edge);
100 } 96 }
101 97
102 CXFA_Edge CXFA_Box::GetEdge(int32_t nIndex) const { 98 CXFA_Edge CXFA_Box::GetEdge(int32_t nIndex) const {
103 return CXFA_Edge( 99 return CXFA_Edge(
104 m_pNode ? m_pNode->GetProperty(nIndex, XFA_Element::Edge, nIndex == 0) 100 m_pNode ? m_pNode->GetProperty(nIndex, XFA_Element::Edge, nIndex == 0)
105 : nullptr); 101 : nullptr);
106 } 102 }
107 103
108 void CXFA_Box::GetStrokes(CXFA_StrokeArray& strokes) const { 104 void CXFA_Box::GetStrokes(std::vector<CXFA_Stroke>* strokes) const {
109 GetStrokesInternal(m_pNode, strokes, false); 105 GetStrokesInternal(m_pNode, strokes, false);
110 } 106 }
111 107
112 bool CXFA_Box::IsCircular() const { 108 bool CXFA_Box::IsCircular() const {
113 if (!m_pNode) 109 if (!m_pNode)
114 return false; 110 return false;
115 return m_pNode->GetBoolean(XFA_ATTRIBUTE_Circular); 111 return m_pNode->GetBoolean(XFA_ATTRIBUTE_Circular);
116 } 112 }
117 113
118 bool CXFA_Box::GetStartAngle(FX_FLOAT& fStartAngle) const { 114 bool CXFA_Box::GetStartAngle(FX_FLOAT& fStartAngle) const {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 147
152 CXFA_Margin CXFA_Box::GetMargin() const { 148 CXFA_Margin CXFA_Box::GetMargin() const {
153 return CXFA_Margin(m_pNode ? m_pNode->GetChild(0, XFA_Element::Margin) 149 return CXFA_Margin(m_pNode ? m_pNode->GetChild(0, XFA_Element::Margin)
154 : nullptr); 150 : nullptr);
155 } 151 }
156 152
157 int32_t CXFA_Box::Get3DStyle(bool& bVisible, FX_FLOAT& fThickness) const { 153 int32_t CXFA_Box::Get3DStyle(bool& bVisible, FX_FLOAT& fThickness) const {
158 if (IsArc()) 154 if (IsArc())
159 return 0; 155 return 0;
160 156
161 CXFA_StrokeArray strokes; 157 std::vector<CXFA_Stroke> strokes;
162 GetStrokesInternal(m_pNode, strokes, true); 158 GetStrokesInternal(m_pNode, &strokes, true);
163 CXFA_Stroke stroke(nullptr); 159 CXFA_Stroke stroke(nullptr);
164 int32_t iType = Style3D(strokes, stroke); 160 int32_t iType = Style3D(strokes, stroke);
165 if (iType) { 161 if (iType) {
166 bVisible = stroke.IsVisible(); 162 bVisible = stroke.IsVisible();
167 fThickness = stroke.GetThickness(); 163 fThickness = stroke.GetThickness();
168 } 164 }
169 return iType; 165 return iType;
170 } 166 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698