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

Side by Side Diff: core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp

Issue 1635173003: Move struct ContentParam off of CPDF_Object's enums (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 10 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
« no previous file with comments | « no previous file | core/src/fpdfapi/fpdf_page/pageint.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "core/src/fpdfapi/fpdf_page/pageint.h" 7 #include "core/src/fpdfapi/fpdf_page/pageint.h"
8 8
9 #include "core/include/fpdfapi/fpdf_module.h" 9 #include "core/include/fpdfapi/fpdf_module.h"
10 #include "core/include/fpdfapi/fpdf_page.h" 10 #include "core/include/fpdfapi/fpdf_page.h"
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 m_pLastCloneImageDict->Release(); 181 m_pLastCloneImageDict->Release();
182 } 182 }
183 } 183 }
184 184
185 int CPDF_StreamContentParser::GetNextParamPos() { 185 int CPDF_StreamContentParser::GetNextParamPos() {
186 if (m_ParamCount == PARAM_BUF_SIZE) { 186 if (m_ParamCount == PARAM_BUF_SIZE) {
187 m_ParamStartPos++; 187 m_ParamStartPos++;
188 if (m_ParamStartPos == PARAM_BUF_SIZE) { 188 if (m_ParamStartPos == PARAM_BUF_SIZE) {
189 m_ParamStartPos = 0; 189 m_ParamStartPos = 0;
190 } 190 }
191 if (m_ParamBuf1[m_ParamStartPos].m_Type == 0) { 191 if (m_ParamBuf[m_ParamStartPos].m_Type == 0) {
192 if (CPDF_Object* pObject = m_ParamBuf1[m_ParamStartPos].m_pObject) 192 if (CPDF_Object* pObject = m_ParamBuf[m_ParamStartPos].m_pObject)
193 pObject->Release(); 193 pObject->Release();
194 } 194 }
195 return m_ParamStartPos; 195 return m_ParamStartPos;
196 } 196 }
197 int index = m_ParamStartPos + m_ParamCount; 197 int index = m_ParamStartPos + m_ParamCount;
198 if (index >= PARAM_BUF_SIZE) { 198 if (index >= PARAM_BUF_SIZE) {
199 index -= PARAM_BUF_SIZE; 199 index -= PARAM_BUF_SIZE;
200 } 200 }
201 m_ParamCount++; 201 m_ParamCount++;
202 return index; 202 return index;
203 } 203 }
204 204
205 void CPDF_StreamContentParser::AddNameParam(const FX_CHAR* name, int len) { 205 void CPDF_StreamContentParser::AddNameParam(const FX_CHAR* name, int len) {
206 int index = GetNextParamPos(); 206 int index = GetNextParamPos();
207 if (len > 32) { 207 if (len > 32) {
208 m_ParamBuf1[index].m_Type = 0; 208 m_ParamBuf[index].m_Type = ContentParam::OBJECT;
209 m_ParamBuf1[index].m_pObject = 209 m_ParamBuf[index].m_pObject =
210 new CPDF_Name(PDF_NameDecode(CFX_ByteStringC(name, len))); 210 new CPDF_Name(PDF_NameDecode(CFX_ByteStringC(name, len)));
211 } else { 211 } else {
212 m_ParamBuf1[index].m_Type = CPDF_Object::NAME; 212 m_ParamBuf[index].m_Type = ContentParam::NAME;
213 if (!FXSYS_memchr(name, '#', len)) { 213 if (!FXSYS_memchr(name, '#', len)) {
214 FXSYS_memcpy(m_ParamBuf1[index].m_Name.m_Buffer, name, len); 214 FXSYS_memcpy(m_ParamBuf[index].m_Name.m_Buffer, name, len);
215 m_ParamBuf1[index].m_Name.m_Len = len; 215 m_ParamBuf[index].m_Name.m_Len = len;
216 } else { 216 } else {
217 CFX_ByteString str = PDF_NameDecode(CFX_ByteStringC(name, len)); 217 CFX_ByteString str = PDF_NameDecode(CFX_ByteStringC(name, len));
218 FXSYS_memcpy(m_ParamBuf1[index].m_Name.m_Buffer, str.c_str(), 218 FXSYS_memcpy(m_ParamBuf[index].m_Name.m_Buffer, str.c_str(),
219 str.GetLength()); 219 str.GetLength());
220 m_ParamBuf1[index].m_Name.m_Len = str.GetLength(); 220 m_ParamBuf[index].m_Name.m_Len = str.GetLength();
221 } 221 }
222 } 222 }
223 } 223 }
224 224
225 void CPDF_StreamContentParser::AddNumberParam(const FX_CHAR* str, int len) { 225 void CPDF_StreamContentParser::AddNumberParam(const FX_CHAR* str, int len) {
226 int index = GetNextParamPos(); 226 int index = GetNextParamPos();
227 m_ParamBuf1[index].m_Type = CPDF_Object::NUMBER; 227 m_ParamBuf[index].m_Type = ContentParam::NUMBER;
228 FX_atonum(CFX_ByteStringC(str, len), m_ParamBuf1[index].m_Number.m_bInteger, 228 FX_atonum(CFX_ByteStringC(str, len), m_ParamBuf[index].m_Number.m_bInteger,
229 &m_ParamBuf1[index].m_Number.m_Integer); 229 &m_ParamBuf[index].m_Number.m_Integer);
230 } 230 }
231 void CPDF_StreamContentParser::AddObjectParam(CPDF_Object* pObj) { 231 void CPDF_StreamContentParser::AddObjectParam(CPDF_Object* pObj) {
232 int index = GetNextParamPos(); 232 int index = GetNextParamPos();
233 m_ParamBuf1[index].m_Type = 0; 233 m_ParamBuf[index].m_Type = ContentParam::OBJECT;
234 m_ParamBuf1[index].m_pObject = pObj; 234 m_ParamBuf[index].m_pObject = pObj;
235 } 235 }
236 void CPDF_StreamContentParser::ClearAllParams() { 236 void CPDF_StreamContentParser::ClearAllParams() {
237 FX_DWORD index = m_ParamStartPos; 237 FX_DWORD index = m_ParamStartPos;
238 for (FX_DWORD i = 0; i < m_ParamCount; i++) { 238 for (FX_DWORD i = 0; i < m_ParamCount; i++) {
239 if (m_ParamBuf1[index].m_Type == 0) { 239 if (m_ParamBuf[index].m_Type == 0) {
240 if (CPDF_Object* pObject = m_ParamBuf1[index].m_pObject) 240 if (CPDF_Object* pObject = m_ParamBuf[index].m_pObject)
241 pObject->Release(); 241 pObject->Release();
242 } 242 }
243 index++; 243 index++;
244 if (index == PARAM_BUF_SIZE) { 244 if (index == PARAM_BUF_SIZE) {
245 index = 0; 245 index = 0;
246 } 246 }
247 } 247 }
248 m_ParamStartPos = 0; 248 m_ParamStartPos = 0;
249 m_ParamCount = 0; 249 m_ParamCount = 0;
250 } 250 }
251 251
252 CPDF_Object* CPDF_StreamContentParser::GetObject(FX_DWORD index) { 252 CPDF_Object* CPDF_StreamContentParser::GetObject(FX_DWORD index) {
253 if (index >= m_ParamCount) { 253 if (index >= m_ParamCount) {
254 return NULL; 254 return NULL;
255 } 255 }
256 int real_index = m_ParamStartPos + m_ParamCount - index - 1; 256 int real_index = m_ParamStartPos + m_ParamCount - index - 1;
257 if (real_index >= PARAM_BUF_SIZE) { 257 if (real_index >= PARAM_BUF_SIZE) {
258 real_index -= PARAM_BUF_SIZE; 258 real_index -= PARAM_BUF_SIZE;
259 } 259 }
260 ContentParam& param = m_ParamBuf1[real_index]; 260 ContentParam& param = m_ParamBuf[real_index];
261 if (param.m_Type == CPDF_Object::NUMBER) { 261 if (param.m_Type == ContentParam::NUMBER) {
262 CPDF_Number* pNumber = param.m_Number.m_bInteger 262 CPDF_Number* pNumber = param.m_Number.m_bInteger
263 ? new CPDF_Number(param.m_Number.m_Integer) 263 ? new CPDF_Number(param.m_Number.m_Integer)
264 : new CPDF_Number(param.m_Number.m_Float); 264 : new CPDF_Number(param.m_Number.m_Float);
265 265
266 param.m_Type = 0; 266 param.m_Type = ContentParam::OBJECT;
267 param.m_pObject = pNumber; 267 param.m_pObject = pNumber;
268 return pNumber; 268 return pNumber;
269 } 269 }
270 if (param.m_Type == CPDF_Object::NAME) { 270 if (param.m_Type == ContentParam::NAME) {
271 CPDF_Name* pName = new CPDF_Name( 271 CPDF_Name* pName = new CPDF_Name(
272 CFX_ByteString(param.m_Name.m_Buffer, param.m_Name.m_Len)); 272 CFX_ByteString(param.m_Name.m_Buffer, param.m_Name.m_Len));
273 param.m_Type = 0; 273 param.m_Type = ContentParam::OBJECT;
274 param.m_pObject = pName; 274 param.m_pObject = pName;
275 return pName; 275 return pName;
276 } 276 }
277 if (param.m_Type == 0) { 277 if (param.m_Type == ContentParam::OBJECT) {
278 return param.m_pObject; 278 return param.m_pObject;
279 } 279 }
280 ASSERT(FALSE); 280 ASSERT(FALSE);
281 return NULL; 281 return NULL;
282 } 282 }
283 283
284 CFX_ByteString CPDF_StreamContentParser::GetString(FX_DWORD index) { 284 CFX_ByteString CPDF_StreamContentParser::GetString(FX_DWORD index) {
285 if (index >= m_ParamCount) { 285 if (index >= m_ParamCount) {
286 return CFX_ByteString(); 286 return CFX_ByteString();
287 } 287 }
288 int real_index = m_ParamStartPos + m_ParamCount - index - 1; 288 int real_index = m_ParamStartPos + m_ParamCount - index - 1;
289 if (real_index >= PARAM_BUF_SIZE) { 289 if (real_index >= PARAM_BUF_SIZE) {
290 real_index -= PARAM_BUF_SIZE; 290 real_index -= PARAM_BUF_SIZE;
291 } 291 }
292 ContentParam& param = m_ParamBuf1[real_index]; 292 ContentParam& param = m_ParamBuf[real_index];
293 if (param.m_Type == CPDF_Object::NAME) { 293 if (param.m_Type == ContentParam::NAME) {
294 return CFX_ByteString(param.m_Name.m_Buffer, param.m_Name.m_Len); 294 return CFX_ByteString(param.m_Name.m_Buffer, param.m_Name.m_Len);
295 } 295 }
296 if (param.m_Type == 0 && param.m_pObject) { 296 if (param.m_Type == 0 && param.m_pObject) {
297 return param.m_pObject->GetString(); 297 return param.m_pObject->GetString();
298 } 298 }
299 return CFX_ByteString(); 299 return CFX_ByteString();
300 } 300 }
301 301
302 FX_FLOAT CPDF_StreamContentParser::GetNumber(FX_DWORD index) { 302 FX_FLOAT CPDF_StreamContentParser::GetNumber(FX_DWORD index) {
303 if (index >= m_ParamCount) { 303 if (index >= m_ParamCount) {
304 return 0; 304 return 0;
305 } 305 }
306 int real_index = m_ParamStartPos + m_ParamCount - index - 1; 306 int real_index = m_ParamStartPos + m_ParamCount - index - 1;
307 if (real_index >= PARAM_BUF_SIZE) { 307 if (real_index >= PARAM_BUF_SIZE) {
308 real_index -= PARAM_BUF_SIZE; 308 real_index -= PARAM_BUF_SIZE;
309 } 309 }
310 ContentParam& param = m_ParamBuf1[real_index]; 310 ContentParam& param = m_ParamBuf[real_index];
311 if (param.m_Type == CPDF_Object::NUMBER) { 311 if (param.m_Type == ContentParam::NUMBER) {
312 return param.m_Number.m_bInteger ? (FX_FLOAT)param.m_Number.m_Integer 312 return param.m_Number.m_bInteger ? (FX_FLOAT)param.m_Number.m_Integer
313 : param.m_Number.m_Float; 313 : param.m_Number.m_Float;
314 } 314 }
315 if (param.m_Type == 0 && param.m_pObject) { 315 if (param.m_Type == 0 && param.m_pObject) {
316 return param.m_pObject->GetNumber(); 316 return param.m_pObject->GetNumber();
317 } 317 }
318 return 0; 318 return 0;
319 } 319 }
320 320
321 FX_FLOAT CPDF_StreamContentParser::GetNumber16(FX_DWORD index) { 321 FX_FLOAT CPDF_StreamContentParser::GetNumber16(FX_DWORD index) {
(...skipping 1491 matching lines...) Expand 10 before | Expand all | Expand 10 after
1813 } else { 1813 } else {
1814 PDF_ReplaceAbbr(pElement); 1814 PDF_ReplaceAbbr(pElement);
1815 } 1815 }
1816 } 1816 }
1817 break; 1817 break;
1818 } 1818 }
1819 default: 1819 default:
1820 break; 1820 break;
1821 } 1821 }
1822 } 1822 }
OLDNEW
« no previous file with comments | « no previous file | core/src/fpdfapi/fpdf_page/pageint.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698