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

Side by Side Diff: xfa/fgas/layout/fgas_rtfbreak.h

Issue 2650773003: Use std::vector for fx_ucd.h arrays. (Closed)
Patch Set: even slightly more saner 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 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 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 #ifndef XFA_FGAS_LAYOUT_FGAS_RTFBREAK_H_ 7 #ifndef XFA_FGAS_LAYOUT_FGAS_RTFBREAK_H_
8 #define XFA_FGAS_LAYOUT_FGAS_RTFBREAK_H_ 8 #define XFA_FGAS_LAYOUT_FGAS_RTFBREAK_H_
9 9
10 #include <vector> 10 #include <vector>
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 int32_t iVerticalScale; 82 int32_t iVerticalScale;
83 }; 83 };
84 84
85 class CFX_RTFPiece { 85 class CFX_RTFPiece {
86 public: 86 public:
87 CFX_RTFPiece(); 87 CFX_RTFPiece();
88 ~CFX_RTFPiece(); 88 ~CFX_RTFPiece();
89 89
90 void AppendChar(const CFX_RTFChar& tc) { 90 void AppendChar(const CFX_RTFChar& tc) {
91 ASSERT(m_pChars); 91 ASSERT(m_pChars);
92 m_pChars->Add(tc); 92 m_pChars->push_back(tc);
93 if (m_iWidth < 0) { 93 if (m_iWidth < 0) {
94 m_iWidth = tc.m_iCharWidth; 94 m_iWidth = tc.m_iCharWidth;
95 } else { 95 } else {
96 m_iWidth += tc.m_iCharWidth; 96 m_iWidth += tc.m_iCharWidth;
97 } 97 }
98 m_iChars++; 98 m_iChars++;
99 } 99 }
100
100 int32_t GetEndPos() const { 101 int32_t GetEndPos() const {
101 return m_iWidth < 0 ? m_iStartPos : m_iStartPos + m_iWidth; 102 return m_iWidth < 0 ? m_iStartPos : m_iStartPos + m_iWidth;
102 } 103 }
104
103 int32_t GetLength() const { return m_iChars; } 105 int32_t GetLength() const { return m_iChars; }
104 int32_t GetEndChar() const { return m_iStartChar + m_iChars; } 106 int32_t GetEndChar() const { return m_iStartChar + m_iChars; }
107
105 CFX_RTFChar& GetChar(int32_t index) { 108 CFX_RTFChar& GetChar(int32_t index) {
106 ASSERT(index > -1 && index < m_iChars && m_pChars); 109 ASSERT(index > -1 && index < m_iChars && m_pChars);
107 return *m_pChars->GetDataPtr(m_iStartChar + index); 110 return (*m_pChars)[m_iStartChar + index];
108 } 111 }
112
109 CFX_RTFChar* GetCharPtr(int32_t index) const { 113 CFX_RTFChar* GetCharPtr(int32_t index) const {
110 ASSERT(index > -1 && index < m_iChars && m_pChars); 114 ASSERT(index > -1 && index < m_iChars && m_pChars);
111 return m_pChars->GetDataPtr(m_iStartChar + index); 115 return &(*m_pChars)[m_iStartChar + index];
112 } 116 }
117
113 void GetString(FX_WCHAR* pText) const { 118 void GetString(FX_WCHAR* pText) const {
114 ASSERT(pText); 119 ASSERT(pText);
115 int32_t iEndChar = m_iStartChar + m_iChars; 120 int32_t iEndChar = m_iStartChar + m_iChars;
116 CFX_RTFChar* pChar; 121 for (int32_t i = m_iStartChar; i < iEndChar; i++)
117 for (int32_t i = m_iStartChar; i < iEndChar; i++) { 122 *pText++ = (FX_WCHAR)(*m_pChars)[i].m_wCharCode;
dsinclair 2017/01/24 18:43:58 nit: static_cast?
Tom Sepez 2017/01/24 19:16:12 Done.
118 pChar = m_pChars->GetDataPtr(i);
119 *pText++ = (FX_WCHAR)pChar->m_wCharCode;
120 }
121 } 123 }
124
122 void GetString(CFX_WideString& wsText) const { 125 void GetString(CFX_WideString& wsText) const {
123 FX_WCHAR* pText = wsText.GetBuffer(m_iChars); 126 FX_WCHAR* pText = wsText.GetBuffer(m_iChars);
124 GetString(pText); 127 GetString(pText);
125 wsText.ReleaseBuffer(m_iChars); 128 wsText.ReleaseBuffer(m_iChars);
126 } 129 }
130
127 void GetWidths(int32_t* pWidths) const { 131 void GetWidths(int32_t* pWidths) const {
128 ASSERT(pWidths); 132 ASSERT(pWidths);
129 int32_t iEndChar = m_iStartChar + m_iChars; 133 int32_t iEndChar = m_iStartChar + m_iChars;
130 CFX_RTFChar* pChar; 134 for (int32_t i = m_iStartChar; i < iEndChar; i++)
131 for (int32_t i = m_iStartChar; i < iEndChar; i++) { 135 *pWidths++ = (*m_pChars)[i].m_iCharWidth;
132 pChar = m_pChars->GetDataPtr(i);
133 *pWidths++ = pChar->m_iCharWidth;
134 }
135 } 136 }
137
136 void Reset() { 138 void Reset() {
137 m_dwStatus = FX_RTFBREAK_PieceBreak; 139 m_dwStatus = FX_RTFBREAK_PieceBreak;
138 if (m_iWidth > -1) { 140 if (m_iWidth > -1) {
139 m_iStartPos += m_iWidth; 141 m_iStartPos += m_iWidth;
140 } 142 }
141 m_iWidth = -1; 143 m_iWidth = -1;
142 m_iStartChar += m_iChars; 144 m_iStartChar += m_iChars;
143 m_iChars = 0; 145 m_iChars = 0;
144 m_iBidiLevel = 0; 146 m_iBidiLevel = 0;
145 m_iBidiPos = 0; 147 m_iBidiPos = 0;
146 m_iHorizontalScale = 100; 148 m_iHorizontalScale = 100;
147 m_iVerticalScale = 100; 149 m_iVerticalScale = 100;
148 } 150 }
149 151
150 uint32_t m_dwStatus; 152 uint32_t m_dwStatus;
151 int32_t m_iStartPos; 153 int32_t m_iStartPos;
152 int32_t m_iWidth; 154 int32_t m_iWidth;
153 int32_t m_iStartChar; 155 int32_t m_iStartChar;
154 int32_t m_iChars; 156 int32_t m_iChars;
155 int32_t m_iBidiLevel; 157 int32_t m_iBidiLevel;
156 int32_t m_iBidiPos; 158 int32_t m_iBidiPos;
157 int32_t m_iFontSize; 159 int32_t m_iFontSize;
158 int32_t m_iFontHeight; 160 int32_t m_iFontHeight;
159 int32_t m_iHorizontalScale; 161 int32_t m_iHorizontalScale;
160 int32_t m_iVerticalScale; 162 int32_t m_iVerticalScale;
161 uint32_t m_dwLayoutStyles; 163 uint32_t m_dwLayoutStyles;
162 uint32_t m_dwIdentity; 164 uint32_t m_dwIdentity;
163 CFX_RTFCharArray* m_pChars; 165 std::vector<CFX_RTFChar>* m_pChars;
dsinclair 2017/01/24 18:43:58 I gather this is set by .... something else and un
Tom Sepez 2017/01/24 19:16:12 Yup, its a pointer to someone else's vector. Adde
164 IFX_Retainable* m_pUserData; 166 IFX_Retainable* m_pUserData;
165 }; 167 };
166 168
167 typedef CFX_BaseArrayTemplate<CFX_RTFPiece> CFX_RTFPieceArray; 169 typedef CFX_BaseArrayTemplate<CFX_RTFPiece> CFX_RTFPieceArray;
168 170
169 class CFX_RTFLine { 171 class CFX_RTFLine {
170 public: 172 public:
171 CFX_RTFLine(); 173 CFX_RTFLine();
172 ~CFX_RTFLine(); 174 ~CFX_RTFLine();
173 175
174 int32_t CountChars() const { return m_LineChars.GetSize(); } 176 int32_t CountChars() const {
177 return pdfium::CollectionSize<int32_t>(m_LineChars);
178 }
175 CFX_RTFChar& GetChar(int32_t index) { 179 CFX_RTFChar& GetChar(int32_t index) {
176 ASSERT(index > -1 && index < m_LineChars.GetSize()); 180 ASSERT(index >= 0 && index < pdfium::CollectionSize<int32_t>(m_LineChars));
177 return *m_LineChars.GetDataPtr(index); 181 return m_LineChars[index];
178 } 182 }
179 CFX_RTFChar* GetCharPtr(int32_t index) { 183 CFX_RTFChar* GetCharPtr(int32_t index) {
180 ASSERT(index > -1 && index < m_LineChars.GetSize()); 184 ASSERT(index > -1 && index < pdfium::CollectionSize<int32_t>(m_LineChars));
181 return m_LineChars.GetDataPtr(index); 185 return &m_LineChars[index];
182 } 186 }
183 int32_t CountPieces() const { return m_LinePieces.GetSize(); } 187 int32_t CountPieces() const { return m_LinePieces.GetSize(); }
184 CFX_RTFPiece& GetPiece(int32_t index) const { 188 CFX_RTFPiece& GetPiece(int32_t index) const {
185 ASSERT(index > -1 && index < m_LinePieces.GetSize()); 189 ASSERT(index > -1 && index < m_LinePieces.GetSize());
186 return m_LinePieces.GetAt(index); 190 return m_LinePieces.GetAt(index);
187 } 191 }
188 CFX_RTFPiece* GetPiecePtr(int32_t index) const { 192 CFX_RTFPiece* GetPiecePtr(int32_t index) const {
189 ASSERT(index > -1 && index < m_LinePieces.GetSize()); 193 ASSERT(index > -1 && index < m_LinePieces.GetSize());
190 return m_LinePieces.GetPtrAt(index); 194 return m_LinePieces.GetPtrAt(index);
191 } 195 }
192 int32_t GetLineEnd() const { return m_iStart + m_iWidth; } 196 int32_t GetLineEnd() const { return m_iStart + m_iWidth; }
193 void RemoveAll(bool bLeaveMemory = false) { 197 void RemoveAll(bool bLeaveMemory = false) {
194 CFX_RTFChar* pChar; 198 int32_t iCount = pdfium::CollectionSize<int32_t>(m_LineChars);
195 int32_t iCount = m_LineChars.GetSize();
196 for (int32_t i = 0; i < iCount; i++) { 199 for (int32_t i = 0; i < iCount; i++) {
197 pChar = m_LineChars.GetDataPtr(i); 200 CFX_RTFChar* pChar = &m_LineChars[i];
198 if (pChar->m_pUserData) 201 if (pChar->m_pUserData)
199 pChar->m_pUserData->Release(); 202 pChar->m_pUserData->Release();
200 } 203 }
201 m_LineChars.RemoveAll(); 204 m_LineChars.clear();
202 m_LinePieces.RemoveAll(bLeaveMemory); 205 m_LinePieces.RemoveAll(bLeaveMemory);
203 m_iWidth = 0; 206 m_iWidth = 0;
204 m_iArabicChars = 0; 207 m_iArabicChars = 0;
205 m_iMBCSChars = 0; 208 m_iMBCSChars = 0;
206 } 209 }
207 210
208 CFX_RTFCharArray m_LineChars; 211 std::vector<CFX_RTFChar> m_LineChars;
209 CFX_RTFPieceArray m_LinePieces; 212 CFX_RTFPieceArray m_LinePieces;
210 int32_t m_iStart; 213 int32_t m_iStart;
211 int32_t m_iWidth; 214 int32_t m_iWidth;
212 int32_t m_iArabicChars; 215 int32_t m_iArabicChars;
213 int32_t m_iMBCSChars; 216 int32_t m_iMBCSChars;
214 }; 217 };
215 218
216 class CFX_RTFBreak { 219 class CFX_RTFBreak {
217 public: 220 public:
218 explicit CFX_RTFBreak(uint32_t dwPolicies); 221 explicit CFX_RTFBreak(uint32_t dwPolicies);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 protected: 267 protected:
265 int32_t GetLineRotation(uint32_t dwStyles) const; 268 int32_t GetLineRotation(uint32_t dwStyles) const;
266 void SetBreakStatus(); 269 void SetBreakStatus();
267 CFX_RTFChar* GetLastChar(int32_t index) const; 270 CFX_RTFChar* GetLastChar(int32_t index) const;
268 CFX_RTFLine* GetRTFLine(bool bReady) const; 271 CFX_RTFLine* GetRTFLine(bool bReady) const;
269 CFX_RTFPieceArray* GetRTFPieces(bool bReady) const; 272 CFX_RTFPieceArray* GetRTFPieces(bool bReady) const;
270 FX_CHARTYPE GetUnifiedCharType(FX_CHARTYPE chartype) const; 273 FX_CHARTYPE GetUnifiedCharType(FX_CHARTYPE chartype) const;
271 int32_t GetLastPositionedTab() const; 274 int32_t GetLastPositionedTab() const;
272 bool GetPositionedTab(int32_t& iTabPos) const; 275 bool GetPositionedTab(int32_t& iTabPos) const;
273 276
274 int32_t GetBreakPos(CFX_RTFCharArray& tca, 277 int32_t GetBreakPos(std::vector<CFX_RTFChar>& tca,
275 int32_t& iEndPos, 278 int32_t& iEndPos,
276 bool bAllChars = false, 279 bool bAllChars = false,
277 bool bOnlyBrk = false); 280 bool bOnlyBrk = false);
278 void SplitTextLine(CFX_RTFLine* pCurLine, 281 void SplitTextLine(CFX_RTFLine* pCurLine,
279 CFX_RTFLine* pNextLine, 282 CFX_RTFLine* pNextLine,
280 bool bAllChars = false); 283 bool bAllChars = false);
281 bool EndBreak_SplitLine(CFX_RTFLine* pNextLine, 284 bool EndBreak_SplitLine(CFX_RTFLine* pNextLine,
282 bool bAllChars, 285 bool bAllChars,
283 uint32_t dwStatus); 286 uint32_t dwStatus);
284 void EndBreak_BidiLine(CFX_TPOArray& tpos, uint32_t dwStatus); 287 void EndBreak_BidiLine(CFX_TPOArray& tpos, uint32_t dwStatus);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 FX_CHARTYPE m_eCharType; 320 FX_CHARTYPE m_eCharType;
318 uint32_t m_dwIdentity; 321 uint32_t m_dwIdentity;
319 CFX_RTFLine m_RTFLine1; 322 CFX_RTFLine m_RTFLine1;
320 CFX_RTFLine m_RTFLine2; 323 CFX_RTFLine m_RTFLine2;
321 CFX_RTFLine* m_pCurLine; 324 CFX_RTFLine* m_pCurLine;
322 int32_t m_iReady; 325 int32_t m_iReady;
323 int32_t m_iTolerance; 326 int32_t m_iTolerance;
324 }; 327 };
325 328
326 #endif // XFA_FGAS_LAYOUT_FGAS_RTFBREAK_H_ 329 #endif // XFA_FGAS_LAYOUT_FGAS_RTFBREAK_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698