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

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

Issue 1219683007: Make ContentStreamParser members private, fix constructor (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Whitespace and line break nits. Created 5 years, 5 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 #include "../../../include/fpdfapi/fpdf_page.h" 7 #include "../../../include/fpdfapi/fpdf_page.h"
8 #include "../../../include/fpdfapi/fpdf_module.h" 8 #include "../../../include/fpdfapi/fpdf_module.h"
9 #include "../../../include/fpdfapi/fpdf_serial.h" 9 #include "../../../include/fpdfapi/fpdf_serial.h"
10 #include "pageint.h" 10 #include "pageint.h"
11
11 #define REQUIRE_PARAMS(count) if (m_ParamCount != count) { m_bAbort = TRUE; retu rn; } 12 #define REQUIRE_PARAMS(count) if (m_ParamCount != count) { m_bAbort = TRUE; retu rn; }
12 CPDF_StreamContentParser::CPDF_StreamContentParser() 13
14 CPDF_StreamContentParser::CPDF_StreamContentParser(
15 CPDF_Document* pDocument,
16 CPDF_Dictionary* pPageResources,
17 CPDF_Dictionary* pParentResources,
18 CFX_AffineMatrix* pmtContentToUser,
19 CPDF_PageObjects* pObjList,
20 CPDF_Dictionary* pResources,
21 CPDF_Rect* pBBox,
22 CPDF_ParseOptions* pOptions,
23 CPDF_AllStates* pStates,
24 int level)
25 : m_pDocument(pDocument),
26 m_pPageResources(pPageResources),
27 m_pParentResources(pParentResources),
28 m_pResources(pResources),
29 m_pObjectList(pObjList),
30 m_Level(level),
31 m_ParamStartPos(0),
32 m_ParamCount(0),
33 m_bAbort(FALSE),
34 m_pCurStates(new CPDF_AllStates),
35 m_pLastTextObject(nullptr),
36 m_DefFontSize(0),
37 m_pPathPoints(nullptr),
38 m_PathPointCount(0),
39 m_PathAllocSize(0),
40 m_PathCurrentX(0.0f),
41 m_PathCurrentY(0.0f),
42 m_PathClipType(0),
43 m_pLastImage(nullptr),
44 m_pLastImageDict(nullptr),
45 m_pLastCloneImageDict(nullptr),
46 m_bReleaseLastDict(TRUE),
47 m_bColored(FALSE),
48 m_bResourceMissing(FALSE)
13 { 49 {
14 m_DefFontSize = 0;
15 m_pCurStates = NULL;
16 m_pLastTextObject = NULL;
17 m_pPathPoints = NULL;
18 m_PathClipType = 0;
19 m_PathPointCount = m_PathAllocSize = 0;
20 m_PathCurrentX = m_PathCurrentY = 0.0f;
21 m_bResourceMissing = FALSE;
22 m_bColored = FALSE;
23 FXSYS_memset(m_Type3Data, 0, sizeof(FX_FLOAT) * 6);
24 m_ParamCount = 0;
25 m_ParamStartPos = 0;
26 m_bAbort = FALSE;
27 m_pLastImageDict = NULL;
28 m_pLastCloneImageDict = NULL;
29 m_pLastImage = NULL;
30 m_bReleaseLastDict = TRUE;
31 m_pParentResources = NULL;
32 }
33 FX_BOOL CPDF_StreamContentParser::Initialize()
34 {
35 return TRUE;
36 }
37 CPDF_StreamContentParser::~CPDF_StreamContentParser()
38 {
39 ClearAllParams();
40 int i = 0;
41 for (i = 0; i < m_StateStack.GetSize(); i ++) {
42 delete (CPDF_AllStates*)m_StateStack[i];
43 }
44 if (m_pPathPoints) {
45 FX_Free(m_pPathPoints);
46 }
47 delete m_pCurStates;
48 if (m_pLastImageDict) {
49 m_pLastImageDict->Release();
50 }
51 if (m_pLastCloneImageDict) {
52 m_pLastCloneImageDict->Release();
53 }
54 }
55 void CPDF_StreamContentParser::PrepareParse(CPDF_Document* pDocument,
56 CPDF_Dictionary* pPageResources, CPDF_Dictionary* pParentResources, CFX_ AffineMatrix* pmtContentToUser, CPDF_PageObjects* pObjList,
57 CPDF_Dictionary* pResources, CPDF_Rect* pBBox, CPDF_ParseOptions* pOptio ns,
58 CPDF_AllStates* pStates, int level)
59 {
60 for (int i = 0; i < 6; i ++) {
61 m_Type3Data[i] = 0;
62 }
63 m_pDocument = pDocument;
64 m_pPageResources = pPageResources;
65 m_pParentResources = pParentResources;
66 if (pmtContentToUser) { 50 if (pmtContentToUser) {
67 m_mtContentToUser = *pmtContentToUser; 51 m_mtContentToUser = *pmtContentToUser;
68 } 52 }
69 if (pOptions) { 53 if (pOptions) {
70 m_Options = *pOptions; 54 m_Options = *pOptions;
71 } 55 }
72 m_pObjectList = pObjList; 56 if (!m_pResources) {
73 m_pResources = pResources;
74 if (pResources == NULL) {
75 m_pResources = m_pParentResources; 57 m_pResources = m_pParentResources;
76 } 58 }
77 if (m_pResources == NULL) { 59 if (!m_pResources) {
78 m_pResources = pPageResources; 60 m_pResources = m_pPageResources;
79 } 61 }
80 if (pBBox) { 62 if (pBBox) {
81 m_BBox = *pBBox; 63 m_BBox = *pBBox;
82 } 64 }
83 m_Level = level;
84 m_pCurStates = new CPDF_AllStates;
85 if (pStates) { 65 if (pStates) {
86 m_pCurStates->Copy(*pStates); 66 m_pCurStates->Copy(*pStates);
87 } else { 67 } else {
88 m_pCurStates->m_GeneralState.New(); 68 m_pCurStates->m_GeneralState.New();
89 m_pCurStates->m_GraphState.New(); 69 m_pCurStates->m_GraphState.New();
90 m_pCurStates->m_TextState.New(); 70 m_pCurStates->m_TextState.New();
91 m_pCurStates->m_ColorState.New(); 71 m_pCurStates->m_ColorState.New();
92 } 72 }
73 for (int i = 0; i < FX_ArraySize(m_Type3Data); ++i) {
74 m_Type3Data[i] = 0.0;
75 }
76 }
77
78 CPDF_StreamContentParser::~CPDF_StreamContentParser()
79 {
80 ClearAllParams();
81 for (int i = 0; i < m_StateStack.GetSize(); ++i) {
82 delete (CPDF_AllStates*)m_StateStack[i];
83 }
84 if (m_pPathPoints) {
85 FX_Free(m_pPathPoints);
86 }
87 if (m_pLastImageDict) {
88 m_pLastImageDict->Release();
89 }
90 if (m_pLastCloneImageDict) {
91 m_pLastCloneImageDict->Release();
92 }
93 } 93 }
94 int CPDF_StreamContentParser::GetNextParamPos() 94 int CPDF_StreamContentParser::GetNextParamPos()
95 { 95 {
96 if (m_ParamCount == PARAM_BUF_SIZE) { 96 if (m_ParamCount == PARAM_BUF_SIZE) {
97 m_ParamStartPos ++; 97 m_ParamStartPos ++;
98 if (m_ParamStartPos == PARAM_BUF_SIZE) { 98 if (m_ParamStartPos == PARAM_BUF_SIZE) {
99 m_ParamStartPos = 0; 99 m_ParamStartPos = 0;
100 } 100 }
101 if (m_ParamBuf1[m_ParamStartPos].m_Type == 0) { 101 if (m_ParamBuf1[m_ParamStartPos].m_Type == 0) {
102 if (CPDF_Object* pObject = m_ParamBuf1[m_ParamStartPos].m_pObject) 102 if (CPDF_Object* pObject = m_ParamBuf1[m_ParamStartPos].m_pObject)
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 if (bColor) { 234 if (bColor) {
235 pObj->m_ColorState = m_pCurStates->m_ColorState; 235 pObj->m_ColorState = m_pCurStates->m_ColorState;
236 } 236 }
237 if (bGraph) { 237 if (bGraph) {
238 pObj->m_GraphState = m_pCurStates->m_GraphState; 238 pObj->m_GraphState = m_pCurStates->m_GraphState;
239 } 239 }
240 if (bText) { 240 if (bText) {
241 pObj->m_TextState = m_pCurStates->m_TextState; 241 pObj->m_TextState = m_pCurStates->m_TextState;
242 } 242 }
243 } 243 }
244 const struct _OpCode { 244
245 FX_DWORD» m_OpId; 245 const CPDF_StreamContentParser::OpCode CPDF_StreamContentParser::g_OpCodes[] =
246 void (CPDF_StreamContentParser::*m_OpHandler)(); 246 {
247 } g_OpCodes[] = {
248 {FXBSTR_ID('"', 0, 0, 0), &CPDF_StreamContentParser::Handle_NextLi neShowText_Space}, 247 {FXBSTR_ID('"', 0, 0, 0), &CPDF_StreamContentParser::Handle_NextLi neShowText_Space},
249 {FXBSTR_ID('\'', 0, 0, 0), &CPDF_StreamContentParser::Handle_NextLi neShowText}, 248 {FXBSTR_ID('\'', 0, 0, 0), &CPDF_StreamContentParser::Handle_NextLi neShowText},
250 {FXBSTR_ID('B', 0, 0, 0), &CPDF_StreamContentParser::Handle_FillSt rokePath}, 249 {FXBSTR_ID('B', 0, 0, 0), &CPDF_StreamContentParser::Handle_FillSt rokePath},
251 {FXBSTR_ID('B', '*', 0, 0), &CPDF_StreamContentParser::Handle_EOFillStrokePa th}, 250 {FXBSTR_ID('B', '*', 0, 0), &CPDF_StreamContentParser::Handle_EOFillStrokePa th},
252 {FXBSTR_ID('B', 'D', 'C', 0), &CPDF_StreamContentParser::Handle_BeginM arkedContent_Dictionary}, 251 {FXBSTR_ID('B', 'D', 'C', 0), &CPDF_StreamContentParser::Handle_BeginM arkedContent_Dictionary},
253 {FXBSTR_ID('B', 'I', 0, 0), &CPDF_StreamContentParser::Handle_BeginImage}, 252 {FXBSTR_ID('B', 'I', 0, 0), &CPDF_StreamContentParser::Handle_BeginImage},
254 {FXBSTR_ID('B', 'M', 'C', 0), &CPDF_StreamContentParser::Handle_BeginM arkedContent}, 253 {FXBSTR_ID('B', 'M', 'C', 0), &CPDF_StreamContentParser::Handle_BeginM arkedContent},
255 {FXBSTR_ID('B', 'T', 0, 0), &CPDF_StreamContentParser::Handle_BeginText}, 254 {FXBSTR_ID('B', 'T', 0, 0), &CPDF_StreamContentParser::Handle_BeginText},
256 {FXBSTR_ID('B', 'X', 0, 0), &CPDF_StreamContentParser::Handle_BeginSectionUn defined}, 255 {FXBSTR_ID('B', 'X', 0, 0), &CPDF_StreamContentParser::Handle_BeginSectionUn defined},
257 {FXBSTR_ID('C', 'S', 0, 0), &CPDF_StreamContentParser::Handle_SetColorSpace_ Stroke}, 256 {FXBSTR_ID('C', 'S', 0, 0), &CPDF_StreamContentParser::Handle_SetColorSpace_ Stroke},
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 int i = 0; 323 int i = 0;
325 FX_DWORD opid = 0; 324 FX_DWORD opid = 0;
326 while (i < 4 && op[i]) { 325 while (i < 4 && op[i]) {
327 opid = (opid << 8) + op[i]; 326 opid = (opid << 8) + op[i];
328 i ++; 327 i ++;
329 } 328 }
330 while (i < 4) { 329 while (i < 4) {
331 opid <<= 8; 330 opid <<= 8;
332 i ++; 331 i ++;
333 }; 332 };
334 int low = 0, high = sizeof g_OpCodes / sizeof(struct _OpCode) - 1; 333 int low = 0, high = sizeof g_OpCodes / sizeof(OpCode) - 1;
335 while (low <= high) { 334 while (low <= high) {
336 int middle = (low + high) / 2; 335 int middle = (low + high) / 2;
337 int compare = opid - g_OpCodes[middle].m_OpId; 336 int compare = opid - g_OpCodes[middle].m_OpId;
338 if (compare == 0) { 337 if (compare == 0) {
339 (this->*g_OpCodes[middle].m_OpHandler)(); 338 (this->*g_OpCodes[middle].m_OpHandler)();
340 return TRUE; 339 return TRUE;
341 } else if (compare < 0) { 340 } else if (compare < 0) {
342 high = middle - 1; 341 high = middle - 1;
343 } else { 342 } else {
344 low = middle + 1; 343 low = middle + 1;
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 CPDF_Array* pBBox = pStream->GetDict()->GetArray(FX_BSTRC("BBox")); 705 CPDF_Array* pBBox = pStream->GetDict()->GetArray(FX_BSTRC("BBox"));
707 CFX_FloatRect form_bbox; 706 CFX_FloatRect form_bbox;
708 CPDF_Path ClipPath; 707 CPDF_Path ClipPath;
709 if (pBBox) { 708 if (pBBox) {
710 form_bbox = pStream->GetDict()->GetRect(FX_BSTRC("BBox")); 709 form_bbox = pStream->GetDict()->GetRect(FX_BSTRC("BBox"));
711 ClipPath.New(); 710 ClipPath.New();
712 ClipPath.AppendRect(form_bbox.left, form_bbox.bottom, form_bbox.righ t, form_bbox.top); 711 ClipPath.AppendRect(form_bbox.left, form_bbox.bottom, form_bbox.righ t, form_bbox.top);
713 ClipPath.Transform(&form_matrix); 712 ClipPath.Transform(&form_matrix);
714 form_bbox.Transform(&form_matrix); 713 form_bbox.Transform(&form_matrix);
715 } 714 }
716 CPDF_StreamContentParser parser; 715 CPDF_StreamContentParser parser(
717 parser.Initialize(); 716 m_pDocument, m_pPageResources, m_pResources, &m_mtContentToUser,
718 parser.PrepareParse(m_pDocument, m_pPageResources, m_pResources, &m_mtCo ntentToUser, 717 m_pObjectList, pResources, &form_bbox, &m_Options,
719 m_pObjectList, pResources, &form_bbox, &m_Options, m _pCurStates, m_Level + 1); 718 m_pCurStates.get(), m_Level + 1);
720 parser.m_pCurStates->m_CTM = form_matrix; 719 parser.m_pCurStates->m_CTM = form_matrix;
721 if (ClipPath.NotNull()) { 720 if (ClipPath.NotNull()) {
722 parser.m_pCurStates->m_ClipPath.AppendPath(ClipPath, FXFILL_WINDING, TRUE); 721 parser.m_pCurStates->m_ClipPath.AppendPath(ClipPath, FXFILL_WINDING, TRUE);
723 } 722 }
724 CPDF_StreamAcc stream; 723 CPDF_StreamAcc stream;
725 stream.LoadAllData(pStream, FALSE); 724 stream.LoadAllData(pStream, FALSE);
726 if (stream.GetSize() == 0) { 725 if (stream.GetSize() == 0) {
727 return; 726 return;
728 } 727 }
729 parser.Parse(stream.GetData(), stream.GetSize(), 0); 728 parser.Parse(stream.GetData(), stream.GetSize(), 0);
(...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after
1574 buf.AppendChar((char)code); 1573 buf.AppendChar((char)code);
1575 } 1574 }
1576 bFirst = !bFirst; 1575 bFirst = !bFirst;
1577 } 1576 }
1578 } 1577 }
1579 if (!bFirst) { 1578 if (!bFirst) {
1580 buf.AppendChar((char)code); 1579 buf.AppendChar((char)code);
1581 } 1580 }
1582 return buf.GetByteString(); 1581 return buf.GetByteString();
1583 } 1582 }
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp ('k') | core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698