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

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

Issue 1265503005: clang-format all pdfium code. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: sigh Created 5 years, 4 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
12 #define REQUIRE_PARAMS(count) if (m_ParamCount != count) { m_bAbort = TRUE; retu rn; } 12 #define REQUIRE_PARAMS(count) \
13 if (m_ParamCount != count) { \
14 m_bAbort = TRUE; \
15 return; \
16 }
13 17
14 CPDF_StreamContentParser::CPDF_StreamContentParser( 18 CPDF_StreamContentParser::CPDF_StreamContentParser(
15 CPDF_Document* pDocument, 19 CPDF_Document* pDocument,
16 CPDF_Dictionary* pPageResources, 20 CPDF_Dictionary* pPageResources,
17 CPDF_Dictionary* pParentResources, 21 CPDF_Dictionary* pParentResources,
18 CFX_AffineMatrix* pmtContentToUser, 22 CFX_AffineMatrix* pmtContentToUser,
19 CPDF_PageObjects* pObjList, 23 CPDF_PageObjects* pObjList,
20 CPDF_Dictionary* pResources, 24 CPDF_Dictionary* pResources,
21 CPDF_Rect* pBBox, 25 CPDF_Rect* pBBox,
22 CPDF_ParseOptions* pOptions, 26 CPDF_ParseOptions* pOptions,
(...skipping 15 matching lines...) Expand all
38 m_PathPointCount(0), 42 m_PathPointCount(0),
39 m_PathAllocSize(0), 43 m_PathAllocSize(0),
40 m_PathCurrentX(0.0f), 44 m_PathCurrentX(0.0f),
41 m_PathCurrentY(0.0f), 45 m_PathCurrentY(0.0f),
42 m_PathClipType(0), 46 m_PathClipType(0),
43 m_pLastImage(nullptr), 47 m_pLastImage(nullptr),
44 m_pLastImageDict(nullptr), 48 m_pLastImageDict(nullptr),
45 m_pLastCloneImageDict(nullptr), 49 m_pLastCloneImageDict(nullptr),
46 m_bReleaseLastDict(TRUE), 50 m_bReleaseLastDict(TRUE),
47 m_bColored(FALSE), 51 m_bColored(FALSE),
48 m_bResourceMissing(FALSE) 52 m_bResourceMissing(FALSE) {
49 { 53 if (pmtContentToUser) {
50 if (pmtContentToUser) { 54 m_mtContentToUser = *pmtContentToUser;
51 m_mtContentToUser = *pmtContentToUser; 55 }
52 } 56 if (pOptions) {
53 if (pOptions) { 57 m_Options = *pOptions;
54 m_Options = *pOptions; 58 }
55 } 59 if (!m_pResources) {
56 if (!m_pResources) { 60 m_pResources = m_pParentResources;
57 m_pResources = m_pParentResources; 61 }
58 } 62 if (!m_pResources) {
59 if (!m_pResources) { 63 m_pResources = m_pPageResources;
60 m_pResources = m_pPageResources; 64 }
61 } 65 if (pBBox) {
62 if (pBBox) { 66 m_BBox = *pBBox;
63 m_BBox = *pBBox; 67 }
64 } 68 if (pStates) {
65 if (pStates) { 69 m_pCurStates->Copy(*pStates);
66 m_pCurStates->Copy(*pStates); 70 } else {
71 m_pCurStates->m_GeneralState.New();
72 m_pCurStates->m_GraphState.New();
73 m_pCurStates->m_TextState.New();
74 m_pCurStates->m_ColorState.New();
75 }
76 for (int i = 0; i < FX_ArraySize(m_Type3Data); ++i) {
77 m_Type3Data[i] = 0.0;
78 }
79 }
80
81 CPDF_StreamContentParser::~CPDF_StreamContentParser() {
82 ClearAllParams();
83 for (int i = 0; i < m_StateStack.GetSize(); ++i) {
84 delete (CPDF_AllStates*)m_StateStack[i];
85 }
86 if (m_pPathPoints) {
87 FX_Free(m_pPathPoints);
88 }
89 if (m_pLastImageDict) {
90 m_pLastImageDict->Release();
91 }
92 if (m_pLastCloneImageDict) {
93 m_pLastCloneImageDict->Release();
94 }
95 }
96 int CPDF_StreamContentParser::GetNextParamPos() {
97 if (m_ParamCount == PARAM_BUF_SIZE) {
98 m_ParamStartPos++;
99 if (m_ParamStartPos == PARAM_BUF_SIZE) {
100 m_ParamStartPos = 0;
101 }
102 if (m_ParamBuf1[m_ParamStartPos].m_Type == 0) {
103 if (CPDF_Object* pObject = m_ParamBuf1[m_ParamStartPos].m_pObject)
104 pObject->Release();
105 }
106 return m_ParamStartPos;
107 }
108 int index = m_ParamStartPos + m_ParamCount;
109 if (index >= PARAM_BUF_SIZE) {
110 index -= PARAM_BUF_SIZE;
111 }
112 m_ParamCount++;
113 return index;
114 }
115 void CPDF_StreamContentParser::AddNameParam(const FX_CHAR* name, int len) {
116 int index = GetNextParamPos();
117 if (len > 32) {
118 m_ParamBuf1[index].m_Type = 0;
119 m_ParamBuf1[index].m_pObject =
120 CPDF_Name::Create(PDF_NameDecode(CFX_ByteStringC(name, len)));
121 } else {
122 m_ParamBuf1[index].m_Type = PDFOBJ_NAME;
123 if (FXSYS_memchr(name, '#', len) == NULL) {
124 FXSYS_memcpy(m_ParamBuf1[index].m_Name.m_Buffer, name, len);
125 m_ParamBuf1[index].m_Name.m_Len = len;
67 } else { 126 } else {
68 m_pCurStates->m_GeneralState.New(); 127 CFX_ByteString str = PDF_NameDecode(CFX_ByteStringC(name, len));
69 m_pCurStates->m_GraphState.New(); 128 FXSYS_memcpy(m_ParamBuf1[index].m_Name.m_Buffer, str.c_str(),
70 m_pCurStates->m_TextState.New(); 129 str.GetLength());
71 m_pCurStates->m_ColorState.New(); 130 m_ParamBuf1[index].m_Name.m_Len = str.GetLength();
72 } 131 }
73 for (int i = 0; i < FX_ArraySize(m_Type3Data); ++i) { 132 }
74 m_Type3Data[i] = 0.0; 133 }
75 } 134 void CPDF_StreamContentParser::AddNumberParam(const FX_CHAR* str, int len) {
135 int index = GetNextParamPos();
136 m_ParamBuf1[index].m_Type = PDFOBJ_NUMBER;
137 FX_atonum(CFX_ByteStringC(str, len), m_ParamBuf1[index].m_Number.m_bInteger,
138 &m_ParamBuf1[index].m_Number.m_Integer);
139 }
140 void CPDF_StreamContentParser::AddObjectParam(CPDF_Object* pObj) {
141 int index = GetNextParamPos();
142 m_ParamBuf1[index].m_Type = 0;
143 m_ParamBuf1[index].m_pObject = pObj;
144 }
145 void CPDF_StreamContentParser::ClearAllParams() {
146 FX_DWORD index = m_ParamStartPos;
147 for (FX_DWORD i = 0; i < m_ParamCount; i++) {
148 if (m_ParamBuf1[index].m_Type == 0) {
149 if (CPDF_Object* pObject = m_ParamBuf1[index].m_pObject)
150 pObject->Release();
151 }
152 index++;
153 if (index == PARAM_BUF_SIZE) {
154 index = 0;
155 }
156 }
157 m_ParamStartPos = 0;
158 m_ParamCount = 0;
159 }
160 CPDF_Object* CPDF_StreamContentParser::GetObject(FX_DWORD index) {
161 if (index >= m_ParamCount) {
162 return NULL;
163 }
164 int real_index = m_ParamStartPos + m_ParamCount - index - 1;
165 if (real_index >= PARAM_BUF_SIZE) {
166 real_index -= PARAM_BUF_SIZE;
167 }
168 _ContentParam& param = m_ParamBuf1[real_index];
169 if (param.m_Type == PDFOBJ_NUMBER) {
170 CPDF_Number* pNumber = CPDF_Number::Create(param.m_Number.m_bInteger,
171 &param.m_Number.m_Integer);
172 param.m_Type = 0;
173 param.m_pObject = pNumber;
174 return pNumber;
175 }
176 if (param.m_Type == PDFOBJ_NAME) {
177 CPDF_Name* pName = CPDF_Name::Create(
178 CFX_ByteString(param.m_Name.m_Buffer, param.m_Name.m_Len));
179 param.m_Type = 0;
180 param.m_pObject = pName;
181 return pName;
182 }
183 if (param.m_Type == 0) {
184 return param.m_pObject;
185 }
186 ASSERT(FALSE);
187 return NULL;
188 }
189 CFX_ByteString CPDF_StreamContentParser::GetString(FX_DWORD index) {
190 if (index >= m_ParamCount) {
191 return CFX_ByteString();
192 }
193 int real_index = m_ParamStartPos + m_ParamCount - index - 1;
194 if (real_index >= PARAM_BUF_SIZE) {
195 real_index -= PARAM_BUF_SIZE;
196 }
197 _ContentParam& param = m_ParamBuf1[real_index];
198 if (param.m_Type == PDFOBJ_NAME) {
199 return CFX_ByteString(param.m_Name.m_Buffer, param.m_Name.m_Len);
200 }
201 if (param.m_Type == 0 && param.m_pObject) {
202 return param.m_pObject->GetString();
203 }
204 return CFX_ByteString();
205 }
206 FX_FLOAT CPDF_StreamContentParser::GetNumber(FX_DWORD index) {
207 if (index >= m_ParamCount) {
208 return 0;
209 }
210 int real_index = m_ParamStartPos + m_ParamCount - index - 1;
211 if (real_index >= PARAM_BUF_SIZE) {
212 real_index -= PARAM_BUF_SIZE;
213 }
214 _ContentParam& param = m_ParamBuf1[real_index];
215 if (param.m_Type == PDFOBJ_NUMBER) {
216 return param.m_Number.m_bInteger ? (FX_FLOAT)param.m_Number.m_Integer
217 : param.m_Number.m_Float;
218 }
219 if (param.m_Type == 0 && param.m_pObject) {
220 return param.m_pObject->GetNumber();
221 }
222 return 0;
223 }
224 FX_FLOAT CPDF_StreamContentParser::GetNumber16(FX_DWORD index) {
225 return GetNumber(index);
226 }
227 void CPDF_StreamContentParser::SetGraphicStates(CPDF_PageObject* pObj,
228 FX_BOOL bColor,
229 FX_BOOL bText,
230 FX_BOOL bGraph) {
231 pObj->m_GeneralState = m_pCurStates->m_GeneralState;
232 pObj->m_ClipPath = m_pCurStates->m_ClipPath;
233 pObj->m_ContentMark = m_CurContentMark;
234 if (bColor) {
235 pObj->m_ColorState = m_pCurStates->m_ColorState;
236 }
237 if (bGraph) {
238 pObj->m_GraphState = m_pCurStates->m_GraphState;
239 }
240 if (bText) {
241 pObj->m_TextState = m_pCurStates->m_TextState;
242 }
76 } 243 }
77 244
78 CPDF_StreamContentParser::~CPDF_StreamContentParser() 245 const CPDF_StreamContentParser::OpCode CPDF_StreamContentParser::g_OpCodes[] = {
79 { 246 {FXBSTR_ID('"', 0, 0, 0),
80 ClearAllParams(); 247 &CPDF_StreamContentParser::Handle_NextLineShowText_Space},
81 for (int i = 0; i < m_StateStack.GetSize(); ++i) { 248 {FXBSTR_ID('\'', 0, 0, 0),
82 delete (CPDF_AllStates*)m_StateStack[i]; 249 &CPDF_StreamContentParser::Handle_NextLineShowText},
83 } 250 {FXBSTR_ID('B', 0, 0, 0), &CPDF_StreamContentParser::Handle_FillStrokePath},
84 if (m_pPathPoints) { 251 {FXBSTR_ID('B', '*', 0, 0),
85 FX_Free(m_pPathPoints); 252 &CPDF_StreamContentParser::Handle_EOFillStrokePath},
86 } 253 {FXBSTR_ID('B', 'D', 'C', 0),
87 if (m_pLastImageDict) { 254 &CPDF_StreamContentParser::Handle_BeginMarkedContent_Dictionary},
88 m_pLastImageDict->Release(); 255 {FXBSTR_ID('B', 'I', 0, 0), &CPDF_StreamContentParser::Handle_BeginImage},
89 } 256 {FXBSTR_ID('B', 'M', 'C', 0),
90 if (m_pLastCloneImageDict) { 257 &CPDF_StreamContentParser::Handle_BeginMarkedContent},
91 m_pLastCloneImageDict->Release(); 258 {FXBSTR_ID('B', 'T', 0, 0), &CPDF_StreamContentParser::Handle_BeginText},
92 } 259 {FXBSTR_ID('B', 'X', 0, 0),
93 } 260 &CPDF_StreamContentParser::Handle_BeginSectionUndefined},
94 int CPDF_StreamContentParser::GetNextParamPos() 261 {FXBSTR_ID('C', 'S', 0, 0),
95 { 262 &CPDF_StreamContentParser::Handle_SetColorSpace_Stroke},
96 if (m_ParamCount == PARAM_BUF_SIZE) { 263 {FXBSTR_ID('D', 'P', 0, 0),
97 m_ParamStartPos ++; 264 &CPDF_StreamContentParser::Handle_MarkPlace_Dictionary},
98 if (m_ParamStartPos == PARAM_BUF_SIZE) { 265 {FXBSTR_ID('D', 'o', 0, 0),
99 m_ParamStartPos = 0; 266 &CPDF_StreamContentParser::Handle_ExecuteXObject},
100 } 267 {FXBSTR_ID('E', 'I', 0, 0), &CPDF_StreamContentParser::Handle_EndImage},
101 if (m_ParamBuf1[m_ParamStartPos].m_Type == 0) { 268 {FXBSTR_ID('E', 'M', 'C', 0),
102 if (CPDF_Object* pObject = m_ParamBuf1[m_ParamStartPos].m_pObject) 269 &CPDF_StreamContentParser::Handle_EndMarkedContent},
103 pObject->Release(); 270 {FXBSTR_ID('E', 'T', 0, 0), &CPDF_StreamContentParser::Handle_EndText},
104 } 271 {FXBSTR_ID('E', 'X', 0, 0),
105 return m_ParamStartPos; 272 &CPDF_StreamContentParser::Handle_EndSectionUndefined},
106 } 273 {FXBSTR_ID('F', 0, 0, 0), &CPDF_StreamContentParser::Handle_FillPathOld},
107 int index = m_ParamStartPos + m_ParamCount; 274 {FXBSTR_ID('G', 0, 0, 0), &CPDF_StreamContentParser::Handle_SetGray_Stroke},
108 if (index >= PARAM_BUF_SIZE) { 275 {FXBSTR_ID('I', 'D', 0, 0),
109 index -= PARAM_BUF_SIZE; 276 &CPDF_StreamContentParser::Handle_BeginImageData},
110 } 277 {FXBSTR_ID('J', 0, 0, 0), &CPDF_StreamContentParser::Handle_SetLineCap},
111 m_ParamCount ++; 278 {FXBSTR_ID('K', 0, 0, 0),
112 return index; 279 &CPDF_StreamContentParser::Handle_SetCMYKColor_Stroke},
113 } 280 {FXBSTR_ID('M', 0, 0, 0), &CPDF_StreamContentParser::Handle_SetMiterLimit},
114 void CPDF_StreamContentParser::AddNameParam(const FX_CHAR* name, int len) 281 {FXBSTR_ID('M', 'P', 0, 0), &CPDF_StreamContentParser::Handle_MarkPlace},
115 { 282 {FXBSTR_ID('Q', 0, 0, 0),
116 int index = GetNextParamPos(); 283 &CPDF_StreamContentParser::Handle_RestoreGraphState},
117 if (len > 32) { 284 {FXBSTR_ID('R', 'G', 0, 0),
118 m_ParamBuf1[index].m_Type = 0; 285 &CPDF_StreamContentParser::Handle_SetRGBColor_Stroke},
119 m_ParamBuf1[index].m_pObject = CPDF_Name::Create(PDF_NameDecode(CFX_Byte StringC(name, len))); 286 {FXBSTR_ID('S', 0, 0, 0), &CPDF_StreamContentParser::Handle_StrokePath},
287 {FXBSTR_ID('S', 'C', 0, 0),
288 &CPDF_StreamContentParser::Handle_SetColor_Stroke},
289 {FXBSTR_ID('S', 'C', 'N', 0),
290 &CPDF_StreamContentParser::Handle_SetColorPS_Stroke},
291 {FXBSTR_ID('T', '*', 0, 0),
292 &CPDF_StreamContentParser::Handle_MoveToNextLine},
293 {FXBSTR_ID('T', 'D', 0, 0),
294 &CPDF_StreamContentParser::Handle_MoveTextPoint_SetLeading},
295 {FXBSTR_ID('T', 'J', 0, 0),
296 &CPDF_StreamContentParser::Handle_ShowText_Positioning},
297 {FXBSTR_ID('T', 'L', 0, 0),
298 &CPDF_StreamContentParser::Handle_SetTextLeading},
299 {FXBSTR_ID('T', 'c', 0, 0), &CPDF_StreamContentParser::Handle_SetCharSpace},
300 {FXBSTR_ID('T', 'd', 0, 0),
301 &CPDF_StreamContentParser::Handle_MoveTextPoint},
302 {FXBSTR_ID('T', 'f', 0, 0), &CPDF_StreamContentParser::Handle_SetFont},
303 {FXBSTR_ID('T', 'j', 0, 0), &CPDF_StreamContentParser::Handle_ShowText},
304 {FXBSTR_ID('T', 'm', 0, 0),
305 &CPDF_StreamContentParser::Handle_SetTextMatrix},
306 {FXBSTR_ID('T', 'r', 0, 0),
307 &CPDF_StreamContentParser::Handle_SetTextRenderMode},
308 {FXBSTR_ID('T', 's', 0, 0), &CPDF_StreamContentParser::Handle_SetTextRise},
309 {FXBSTR_ID('T', 'w', 0, 0), &CPDF_StreamContentParser::Handle_SetWordSpace},
310 {FXBSTR_ID('T', 'z', 0, 0), &CPDF_StreamContentParser::Handle_SetHorzScale},
311 {FXBSTR_ID('W', 0, 0, 0), &CPDF_StreamContentParser::Handle_Clip},
312 {FXBSTR_ID('W', '*', 0, 0), &CPDF_StreamContentParser::Handle_EOClip},
313 {FXBSTR_ID('b', 0, 0, 0),
314 &CPDF_StreamContentParser::Handle_CloseFillStrokePath},
315 {FXBSTR_ID('b', '*', 0, 0),
316 &CPDF_StreamContentParser::Handle_CloseEOFillStrokePath},
317 {FXBSTR_ID('c', 0, 0, 0), &CPDF_StreamContentParser::Handle_CurveTo_123},
318 {FXBSTR_ID('c', 'm', 0, 0), &CPDF_StreamContentParser::Handle_ConcatMatrix},
319 {FXBSTR_ID('c', 's', 0, 0),
320 &CPDF_StreamContentParser::Handle_SetColorSpace_Fill},
321 {FXBSTR_ID('d', 0, 0, 0), &CPDF_StreamContentParser::Handle_SetDash},
322 {FXBSTR_ID('d', '0', 0, 0), &CPDF_StreamContentParser::Handle_SetCharWidth},
323 {FXBSTR_ID('d', '1', 0, 0),
324 &CPDF_StreamContentParser::Handle_SetCachedDevice},
325 {FXBSTR_ID('f', 0, 0, 0), &CPDF_StreamContentParser::Handle_FillPath},
326 {FXBSTR_ID('f', '*', 0, 0), &CPDF_StreamContentParser::Handle_EOFillPath},
327 {FXBSTR_ID('g', 0, 0, 0), &CPDF_StreamContentParser::Handle_SetGray_Fill},
328 {FXBSTR_ID('g', 's', 0, 0),
329 &CPDF_StreamContentParser::Handle_SetExtendGraphState},
330 {FXBSTR_ID('h', 0, 0, 0), &CPDF_StreamContentParser::Handle_ClosePath},
331 {FXBSTR_ID('i', 0, 0, 0), &CPDF_StreamContentParser::Handle_SetFlat},
332 {FXBSTR_ID('j', 0, 0, 0), &CPDF_StreamContentParser::Handle_SetLineJoin},
333 {FXBSTR_ID('k', 0, 0, 0),
334 &CPDF_StreamContentParser::Handle_SetCMYKColor_Fill},
335 {FXBSTR_ID('l', 0, 0, 0), &CPDF_StreamContentParser::Handle_LineTo},
336 {FXBSTR_ID('m', 0, 0, 0), &CPDF_StreamContentParser::Handle_MoveTo},
337 {FXBSTR_ID('n', 0, 0, 0), &CPDF_StreamContentParser::Handle_EndPath},
338 {FXBSTR_ID('q', 0, 0, 0), &CPDF_StreamContentParser::Handle_SaveGraphState},
339 {FXBSTR_ID('r', 'e', 0, 0), &CPDF_StreamContentParser::Handle_Rectangle},
340 {FXBSTR_ID('r', 'g', 0, 0),
341 &CPDF_StreamContentParser::Handle_SetRGBColor_Fill},
342 {FXBSTR_ID('r', 'i', 0, 0),
343 &CPDF_StreamContentParser::Handle_SetRenderIntent},
344 {FXBSTR_ID('s', 0, 0, 0),
345 &CPDF_StreamContentParser::Handle_CloseStrokePath},
346 {FXBSTR_ID('s', 'c', 0, 0),
347 &CPDF_StreamContentParser::Handle_SetColor_Fill},
348 {FXBSTR_ID('s', 'c', 'n', 0),
349 &CPDF_StreamContentParser::Handle_SetColorPS_Fill},
350 {FXBSTR_ID('s', 'h', 0, 0), &CPDF_StreamContentParser::Handle_ShadeFill},
351 {FXBSTR_ID('v', 0, 0, 0), &CPDF_StreamContentParser::Handle_CurveTo_23},
352 {FXBSTR_ID('w', 0, 0, 0), &CPDF_StreamContentParser::Handle_SetLineWidth},
353 {FXBSTR_ID('y', 0, 0, 0), &CPDF_StreamContentParser::Handle_CurveTo_13},
354 };
355 FX_BOOL CPDF_StreamContentParser::OnOperator(const FX_CHAR* op) {
356 int i = 0;
357 FX_DWORD opid = 0;
358 while (i < 4 && op[i]) {
359 opid = (opid << 8) + op[i];
360 i++;
361 }
362 while (i < 4) {
363 opid <<= 8;
364 i++;
365 };
366 int low = 0, high = sizeof g_OpCodes / sizeof(OpCode) - 1;
367 while (low <= high) {
368 int middle = (low + high) / 2;
369 int compare = opid - g_OpCodes[middle].m_OpId;
370 if (compare == 0) {
371 (this->*g_OpCodes[middle].m_OpHandler)();
372 return TRUE;
373 }
374 if (compare < 0) {
375 high = middle - 1;
120 } else { 376 } else {
121 m_ParamBuf1[index].m_Type = PDFOBJ_NAME; 377 low = middle + 1;
122 if (FXSYS_memchr(name, '#', len) == NULL) { 378 }
123 FXSYS_memcpy(m_ParamBuf1[index].m_Name.m_Buffer, name, len); 379 }
124 m_ParamBuf1[index].m_Name.m_Len = len; 380 return m_CompatCount != 0;
125 } else { 381 }
126 CFX_ByteString str = PDF_NameDecode(CFX_ByteStringC(name, len)); 382 void CPDF_StreamContentParser::Handle_CloseFillStrokePath() {
127 FXSYS_memcpy(m_ParamBuf1[index].m_Name.m_Buffer, str.c_str(), str.Ge tLength()); 383 if (m_Options.m_bTextOnly) {
128 m_ParamBuf1[index].m_Name.m_Len = str.GetLength(); 384 return;
129 } 385 }
130 } 386 Handle_ClosePath();
131 } 387 AddPathObject(FXFILL_WINDING, TRUE);
132 void CPDF_StreamContentParser::AddNumberParam(const FX_CHAR* str, int len) 388 }
133 { 389 void CPDF_StreamContentParser::Handle_FillStrokePath() {
134 int index = GetNextParamPos(); 390 if (m_Options.m_bTextOnly) {
135 m_ParamBuf1[index].m_Type = PDFOBJ_NUMBER; 391 return;
136 FX_atonum(CFX_ByteStringC(str, len), m_ParamBuf1[index].m_Number.m_bInteger, 392 }
137 &m_ParamBuf1[index].m_Number.m_Integer); 393 AddPathObject(FXFILL_WINDING, TRUE);
138 } 394 }
139 void CPDF_StreamContentParser::AddObjectParam(CPDF_Object* pObj) 395 void CPDF_StreamContentParser::Handle_CloseEOFillStrokePath() {
140 { 396 if (m_Options.m_bTextOnly) {
141 int index = GetNextParamPos(); 397 return;
142 m_ParamBuf1[index].m_Type = 0; 398 }
143 m_ParamBuf1[index].m_pObject = pObj; 399 AddPathPoint(m_PathStartX, m_PathStartY, FXPT_LINETO | FXPT_CLOSEFIGURE);
144 } 400 AddPathObject(FXFILL_ALTERNATE, TRUE);
145 void CPDF_StreamContentParser::ClearAllParams() 401 }
146 { 402 void CPDF_StreamContentParser::Handle_EOFillStrokePath() {
147 FX_DWORD index = m_ParamStartPos; 403 if (m_Options.m_bTextOnly) {
148 for (FX_DWORD i = 0; i < m_ParamCount; i ++) { 404 return;
149 if (m_ParamBuf1[index].m_Type == 0) { 405 }
150 if (CPDF_Object* pObject = m_ParamBuf1[index].m_pObject) 406 AddPathObject(FXFILL_ALTERNATE, TRUE);
151 pObject->Release(); 407 }
152 } 408 void CPDF_StreamContentParser::Handle_BeginMarkedContent_Dictionary() {
153 index ++; 409 if (!m_Options.m_bMarkedContent) {
154 if (index == PARAM_BUF_SIZE) { 410 return;
155 index = 0; 411 }
156 } 412 CFX_ByteString tag = GetString(1);
157 } 413 CPDF_Object* pProperty = GetObject(0);
158 m_ParamStartPos = 0; 414 if (pProperty == NULL) {
159 m_ParamCount = 0; 415 return;
160 } 416 }
161 CPDF_Object* CPDF_StreamContentParser::GetObject(FX_DWORD index) 417 FX_BOOL bDirect = TRUE;
162 { 418 if (pProperty->GetType() == PDFOBJ_NAME) {
163 if (index >= m_ParamCount) { 419 pProperty = FindResourceObj(FX_BSTRC("Properties"), pProperty->GetString());
164 return NULL; 420 if (pProperty == NULL) {
165 } 421 return;
166 int real_index = m_ParamStartPos + m_ParamCount - index - 1; 422 }
167 if (real_index >= PARAM_BUF_SIZE) { 423 bDirect = FALSE;
168 real_index -= PARAM_BUF_SIZE; 424 }
169 } 425 if (pProperty->GetType() != PDFOBJ_DICTIONARY) {
170 _ContentParam& param = m_ParamBuf1[real_index]; 426 return;
171 if (param.m_Type == PDFOBJ_NUMBER) { 427 }
172 CPDF_Number* pNumber = CPDF_Number::Create(param.m_Number.m_bInteger, &p aram.m_Number.m_Integer); 428 m_CurContentMark.GetModify()->AddMark(tag, (CPDF_Dictionary*)pProperty,
173 param.m_Type = 0; 429 bDirect);
174 param.m_pObject = pNumber; 430 }
175 return pNumber; 431 void CPDF_StreamContentParser::Handle_BeginMarkedContent() {
176 } 432 if (!m_Options.m_bMarkedContent) {
177 if (param.m_Type == PDFOBJ_NAME) { 433 return;
178 CPDF_Name* pName = CPDF_Name::Create(CFX_ByteString(param.m_Name.m_Buffe r, param.m_Name.m_Len)); 434 }
179 param.m_Type = 0; 435 CFX_ByteString tag = GetString(0);
180 param.m_pObject = pName; 436 m_CurContentMark.GetModify()->AddMark(tag, NULL, FALSE);
181 return pName; 437 }
182 } 438 struct _FX_BSTR {
183 if (param.m_Type == 0) { 439 const FX_CHAR* m_Ptr;
184 return param.m_pObject; 440 int m_Size;
185 }
186 ASSERT(FALSE);
187 return NULL;
188 }
189 CFX_ByteString CPDF_StreamContentParser::GetString(FX_DWORD index)
190 {
191 if (index >= m_ParamCount) {
192 return CFX_ByteString();
193 }
194 int real_index = m_ParamStartPos + m_ParamCount - index - 1;
195 if (real_index >= PARAM_BUF_SIZE) {
196 real_index -= PARAM_BUF_SIZE;
197 }
198 _ContentParam& param = m_ParamBuf1[real_index];
199 if (param.m_Type == PDFOBJ_NAME) {
200 return CFX_ByteString(param.m_Name.m_Buffer, param.m_Name.m_Len);
201 }
202 if (param.m_Type == 0 && param.m_pObject) {
203 return param.m_pObject->GetString();
204 }
205 return CFX_ByteString();
206 }
207 FX_FLOAT CPDF_StreamContentParser::GetNumber(FX_DWORD index)
208 {
209 if (index >= m_ParamCount) {
210 return 0;
211 }
212 int real_index = m_ParamStartPos + m_ParamCount - index - 1;
213 if (real_index >= PARAM_BUF_SIZE) {
214 real_index -= PARAM_BUF_SIZE;
215 }
216 _ContentParam& param = m_ParamBuf1[real_index];
217 if (param.m_Type == PDFOBJ_NUMBER) {
218 return param.m_Number.m_bInteger ? (FX_FLOAT)param.m_Number.m_Integer : param.m_Number.m_Float;
219 }
220 if (param.m_Type == 0 && param.m_pObject) {
221 return param.m_pObject->GetNumber();
222 }
223 return 0;
224 }
225 FX_FLOAT CPDF_StreamContentParser::GetNumber16(FX_DWORD index)
226 {
227 return GetNumber(index);
228 }
229 void CPDF_StreamContentParser::SetGraphicStates(CPDF_PageObject* pObj, FX_BOOL b Color, FX_BOOL bText, FX_BOOL bGraph)
230 {
231 pObj->m_GeneralState = m_pCurStates->m_GeneralState;
232 pObj->m_ClipPath = m_pCurStates->m_ClipPath;
233 pObj->m_ContentMark = m_CurContentMark;
234 if (bColor) {
235 pObj->m_ColorState = m_pCurStates->m_ColorState;
236 }
237 if (bGraph) {
238 pObj->m_GraphState = m_pCurStates->m_GraphState;
239 }
240 if (bText) {
241 pObj->m_TextState = m_pCurStates->m_TextState;
242 }
243 }
244
245 const CPDF_StreamContentParser::OpCode CPDF_StreamContentParser::g_OpCodes[] =
246 {
247 {FXBSTR_ID('"', 0, 0, 0), &CPDF_StreamContentParser::Handle_NextLi neShowText_Space},
248 {FXBSTR_ID('\'', 0, 0, 0), &CPDF_StreamContentParser::Handle_NextLi neShowText},
249 {FXBSTR_ID('B', 0, 0, 0), &CPDF_StreamContentParser::Handle_FillSt rokePath},
250 {FXBSTR_ID('B', '*', 0, 0), &CPDF_StreamContentParser::Handle_EOFillStrokePa th},
251 {FXBSTR_ID('B', 'D', 'C', 0), &CPDF_StreamContentParser::Handle_BeginM arkedContent_Dictionary},
252 {FXBSTR_ID('B', 'I', 0, 0), &CPDF_StreamContentParser::Handle_BeginImage},
253 {FXBSTR_ID('B', 'M', 'C', 0), &CPDF_StreamContentParser::Handle_BeginM arkedContent},
254 {FXBSTR_ID('B', 'T', 0, 0), &CPDF_StreamContentParser::Handle_BeginText},
255 {FXBSTR_ID('B', 'X', 0, 0), &CPDF_StreamContentParser::Handle_BeginSectionUn defined},
256 {FXBSTR_ID('C', 'S', 0, 0), &CPDF_StreamContentParser::Handle_SetColorSpace_ Stroke},
257 {FXBSTR_ID('D', 'P', 0, 0), &CPDF_StreamContentParser::Handle_MarkPlace_Dict ionary},
258 {FXBSTR_ID('D', 'o', 0, 0), &CPDF_StreamContentParser::Handle_ExecuteXObject },
259 {FXBSTR_ID('E', 'I', 0, 0), &CPDF_StreamContentParser::Handle_EndImage},
260 {FXBSTR_ID('E', 'M', 'C', 0), &CPDF_StreamContentParser::Handle_EndMar kedContent},
261 {FXBSTR_ID('E', 'T', 0, 0), &CPDF_StreamContentParser::Handle_EndText},
262 {FXBSTR_ID('E', 'X', 0, 0), &CPDF_StreamContentParser::Handle_EndSectionUnde fined},
263 {FXBSTR_ID('F', 0, 0, 0), &CPDF_StreamContentParser::Handle_FillPa thOld},
264 {FXBSTR_ID('G', 0, 0, 0), &CPDF_StreamContentParser::Handle_SetGra y_Stroke},
265 {FXBSTR_ID('I', 'D', 0, 0), &CPDF_StreamContentParser::Handle_BeginImageData },
266 {FXBSTR_ID('J', 0, 0, 0), &CPDF_StreamContentParser::Handle_SetLin eCap},
267 {FXBSTR_ID('K', 0, 0, 0), &CPDF_StreamContentParser::Handle_SetCMY KColor_Stroke},
268 {FXBSTR_ID('M', 0, 0, 0), &CPDF_StreamContentParser::Handle_SetMit erLimit},
269 {FXBSTR_ID('M', 'P', 0, 0), &CPDF_StreamContentParser::Handle_MarkPlace},
270 {FXBSTR_ID('Q', 0, 0, 0), &CPDF_StreamContentParser::Handle_Restor eGraphState},
271 {FXBSTR_ID('R', 'G', 0, 0), &CPDF_StreamContentParser::Handle_SetRGBColor_St roke},
272 {FXBSTR_ID('S', 0, 0, 0), &CPDF_StreamContentParser::Handle_Stroke Path},
273 {FXBSTR_ID('S', 'C', 0, 0), &CPDF_StreamContentParser::Handle_SetColor_Strok e},
274 {FXBSTR_ID('S', 'C', 'N', 0), &CPDF_StreamContentParser::Handle_SetCol orPS_Stroke},
275 {FXBSTR_ID('T', '*', 0, 0), &CPDF_StreamContentParser::Handle_MoveToNextLine },
276 {FXBSTR_ID('T', 'D', 0, 0), &CPDF_StreamContentParser::Handle_MoveTextPoint_ SetLeading},
277 {FXBSTR_ID('T', 'J', 0, 0), &CPDF_StreamContentParser::Handle_ShowText_Posit ioning},
278 {FXBSTR_ID('T', 'L', 0, 0), &CPDF_StreamContentParser::Handle_SetTextLeading },
279 {FXBSTR_ID('T', 'c', 0, 0), &CPDF_StreamContentParser::Handle_SetCharSpace},
280 {FXBSTR_ID('T', 'd', 0, 0), &CPDF_StreamContentParser::Handle_MoveTextPoint} ,
281 {FXBSTR_ID('T', 'f', 0, 0), &CPDF_StreamContentParser::Handle_SetFont},
282 {FXBSTR_ID('T', 'j', 0, 0), &CPDF_StreamContentParser::Handle_ShowText},
283 {FXBSTR_ID('T', 'm', 0, 0), &CPDF_StreamContentParser::Handle_SetTextMatrix} ,
284 {FXBSTR_ID('T', 'r', 0, 0), &CPDF_StreamContentParser::Handle_SetTextRenderM ode},
285 {FXBSTR_ID('T', 's', 0, 0), &CPDF_StreamContentParser::Handle_SetTextRise},
286 {FXBSTR_ID('T', 'w', 0, 0), &CPDF_StreamContentParser::Handle_SetWordSpace},
287 {FXBSTR_ID('T', 'z', 0, 0), &CPDF_StreamContentParser::Handle_SetHorzScale},
288 {FXBSTR_ID('W', 0, 0, 0), &CPDF_StreamContentParser::Handle_Clip},
289 {FXBSTR_ID('W', '*', 0, 0), &CPDF_StreamContentParser::Handle_EOClip},
290 {FXBSTR_ID('b', 0, 0, 0), &CPDF_StreamContentParser::Handle_CloseF illStrokePath},
291 {FXBSTR_ID('b', '*', 0, 0), &CPDF_StreamContentParser::Handle_CloseEOFillStr okePath},
292 {FXBSTR_ID('c', 0, 0, 0), &CPDF_StreamContentParser::Handle_CurveT o_123},
293 {FXBSTR_ID('c', 'm', 0, 0), &CPDF_StreamContentParser::Handle_ConcatMatrix},
294 {FXBSTR_ID('c', 's', 0, 0), &CPDF_StreamContentParser::Handle_SetColorSpace_ Fill},
295 {FXBSTR_ID('d', 0, 0, 0), &CPDF_StreamContentParser::Handle_SetDas h},
296 {FXBSTR_ID('d', '0', 0, 0), &CPDF_StreamContentParser::Handle_SetCharWidth},
297 {FXBSTR_ID('d', '1', 0, 0), &CPDF_StreamContentParser::Handle_SetCachedDevic e},
298 {FXBSTR_ID('f', 0, 0, 0), &CPDF_StreamContentParser::Handle_FillPa th},
299 {FXBSTR_ID('f', '*', 0, 0), &CPDF_StreamContentParser::Handle_EOFillPath},
300 {FXBSTR_ID('g', 0, 0, 0), &CPDF_StreamContentParser::Handle_SetGra y_Fill},
301 {FXBSTR_ID('g', 's', 0, 0), &CPDF_StreamContentParser::Handle_SetExtendGraph State},
302 {FXBSTR_ID('h', 0, 0, 0), &CPDF_StreamContentParser::Handle_CloseP ath},
303 {FXBSTR_ID('i', 0, 0, 0), &CPDF_StreamContentParser::Handle_SetFla t},
304 {FXBSTR_ID('j', 0, 0, 0), &CPDF_StreamContentParser::Handle_SetLin eJoin},
305 {FXBSTR_ID('k', 0, 0, 0), &CPDF_StreamContentParser::Handle_SetCMY KColor_Fill},
306 {FXBSTR_ID('l', 0, 0, 0), &CPDF_StreamContentParser::Handle_LineTo },
307 {FXBSTR_ID('m', 0, 0, 0), &CPDF_StreamContentParser::Handle_MoveTo },
308 {FXBSTR_ID('n', 0, 0, 0), &CPDF_StreamContentParser::Handle_EndPat h},
309 {FXBSTR_ID('q', 0, 0, 0), &CPDF_StreamContentParser::Handle_SaveGr aphState},
310 {FXBSTR_ID('r', 'e', 0, 0), &CPDF_StreamContentParser::Handle_Rectangle},
311 {FXBSTR_ID('r', 'g', 0, 0), &CPDF_StreamContentParser::Handle_SetRGBColor_Fi ll},
312 {FXBSTR_ID('r', 'i', 0, 0), &CPDF_StreamContentParser::Handle_SetRenderInten t},
313 {FXBSTR_ID('s', 0, 0, 0), &CPDF_StreamContentParser::Handle_CloseS trokePath},
314 {FXBSTR_ID('s', 'c', 0, 0), &CPDF_StreamContentParser::Handle_SetColor_Fill} ,
315 {FXBSTR_ID('s', 'c', 'n', 0), &CPDF_StreamContentParser::Handle_SetCol orPS_Fill},
316 {FXBSTR_ID('s', 'h', 0, 0), &CPDF_StreamContentParser::Handle_ShadeFill},
317 {FXBSTR_ID('v', 0, 0, 0), &CPDF_StreamContentParser::Handle_CurveT o_23},
318 {FXBSTR_ID('w', 0, 0, 0), &CPDF_StreamContentParser::Handle_SetLin eWidth},
319 {FXBSTR_ID('y', 0, 0, 0), &CPDF_StreamContentParser::Handle_CurveT o_13},
320 }; 441 };
321 FX_BOOL CPDF_StreamContentParser::OnOperator(const FX_CHAR* op) 442 #define _FX_BSTRC(str) \
322 { 443 { str, sizeof(str) - 1 }
323 int i = 0;
324 FX_DWORD opid = 0;
325 while (i < 4 && op[i]) {
326 opid = (opid << 8) + op[i];
327 i ++;
328 }
329 while (i < 4) {
330 opid <<= 8;
331 i ++;
332 };
333 int low = 0, high = sizeof g_OpCodes / sizeof(OpCode) - 1;
334 while (low <= high) {
335 int middle = (low + high) / 2;
336 int compare = opid - g_OpCodes[middle].m_OpId;
337 if (compare == 0) {
338 (this->*g_OpCodes[middle].m_OpHandler)();
339 return TRUE;
340 }
341 if (compare < 0) {
342 high = middle - 1;
343 } else {
344 low = middle + 1;
345 }
346 }
347 return m_CompatCount != 0;
348 }
349 void CPDF_StreamContentParser::Handle_CloseFillStrokePath()
350 {
351 if (m_Options.m_bTextOnly) {
352 return;
353 }
354 Handle_ClosePath();
355 AddPathObject(FXFILL_WINDING, TRUE);
356 }
357 void CPDF_StreamContentParser::Handle_FillStrokePath()
358 {
359 if (m_Options.m_bTextOnly) {
360 return;
361 }
362 AddPathObject(FXFILL_WINDING, TRUE);
363 }
364 void CPDF_StreamContentParser::Handle_CloseEOFillStrokePath()
365 {
366 if (m_Options.m_bTextOnly) {
367 return;
368 }
369 AddPathPoint(m_PathStartX, m_PathStartY, FXPT_LINETO | FXPT_CLOSEFIGURE);
370 AddPathObject(FXFILL_ALTERNATE, TRUE);
371 }
372 void CPDF_StreamContentParser::Handle_EOFillStrokePath()
373 {
374 if (m_Options.m_bTextOnly) {
375 return;
376 }
377 AddPathObject(FXFILL_ALTERNATE, TRUE);
378 }
379 void CPDF_StreamContentParser::Handle_BeginMarkedContent_Dictionary()
380 {
381 if (!m_Options.m_bMarkedContent) {
382 return;
383 }
384 CFX_ByteString tag = GetString(1);
385 CPDF_Object* pProperty = GetObject(0);
386 if (pProperty == NULL) {
387 return;
388 }
389 FX_BOOL bDirect = TRUE;
390 if (pProperty->GetType() == PDFOBJ_NAME) {
391 pProperty = FindResourceObj(FX_BSTRC("Properties"), pProperty->GetString ());
392 if (pProperty == NULL) {
393 return;
394 }
395 bDirect = FALSE;
396 }
397 if (pProperty->GetType() != PDFOBJ_DICTIONARY) {
398 return;
399 }
400 m_CurContentMark.GetModify()->AddMark(tag, (CPDF_Dictionary*)pProperty, bDir ect);
401 }
402 void CPDF_StreamContentParser::Handle_BeginMarkedContent()
403 {
404 if (!m_Options.m_bMarkedContent) {
405 return;
406 }
407 CFX_ByteString tag = GetString(0);
408 m_CurContentMark.GetModify()->AddMark(tag, NULL, FALSE);
409 }
410 struct _FX_BSTR {
411 const FX_CHAR*» m_Ptr;
412 int»» » m_Size;
413 };
414 #define _FX_BSTRC(str) {str, sizeof(str)-1}
415 const _FX_BSTR _PDF_InlineKeyAbbr[] = { 444 const _FX_BSTR _PDF_InlineKeyAbbr[] = {
416 _FX_BSTRC("BitsPerComponent"), _FX_BSTRC("BPC"), 445 _FX_BSTRC("BitsPerComponent"),
417 _FX_BSTRC("ColorSpace"), _FX_BSTRC("CS"), 446 _FX_BSTRC("BPC"),
418 _FX_BSTRC("Decode"), _FX_BSTRC("D"), 447 _FX_BSTRC("ColorSpace"),
419 _FX_BSTRC("DecodeParms"), _FX_BSTRC("DP"), 448 _FX_BSTRC("CS"),
420 _FX_BSTRC("Filter"), _FX_BSTRC("F"), 449 _FX_BSTRC("Decode"),
421 _FX_BSTRC("Height"), _FX_BSTRC("H"), 450 _FX_BSTRC("D"),
422 _FX_BSTRC("ImageMask"), _FX_BSTRC("IM"), 451 _FX_BSTRC("DecodeParms"),
423 _FX_BSTRC("Interpolate"), _FX_BSTRC("I"), 452 _FX_BSTRC("DP"),
424 _FX_BSTRC("Width"), _FX_BSTRC("W"), 453 _FX_BSTRC("Filter"),
454 _FX_BSTRC("F"),
455 _FX_BSTRC("Height"),
456 _FX_BSTRC("H"),
457 _FX_BSTRC("ImageMask"),
458 _FX_BSTRC("IM"),
459 _FX_BSTRC("Interpolate"),
460 _FX_BSTRC("I"),
461 _FX_BSTRC("Width"),
462 _FX_BSTRC("W"),
425 }; 463 };
426 const _FX_BSTR _PDF_InlineValueAbbr[] = { 464 const _FX_BSTR _PDF_InlineValueAbbr[] = {
427 _FX_BSTRC("DeviceGray"), _FX_BSTRC("G"), 465 _FX_BSTRC("DeviceGray"), _FX_BSTRC("G"),
428 _FX_BSTRC("DeviceRGB"), _FX_BSTRC("RGB"), 466 _FX_BSTRC("DeviceRGB"), _FX_BSTRC("RGB"),
429 _FX_BSTRC("DeviceCMYK"), _FX_BSTRC("CMYK"), 467 _FX_BSTRC("DeviceCMYK"), _FX_BSTRC("CMYK"),
430 _FX_BSTRC("Indexed"), _FX_BSTRC("I"), 468 _FX_BSTRC("Indexed"), _FX_BSTRC("I"),
431 _FX_BSTRC("ASCIIHexDecode"), _FX_BSTRC("AHx"), 469 _FX_BSTRC("ASCIIHexDecode"), _FX_BSTRC("AHx"),
432 _FX_BSTRC("ASCII85Decode"), _FX_BSTRC("A85"), 470 _FX_BSTRC("ASCII85Decode"), _FX_BSTRC("A85"),
433 _FX_BSTRC("LZWDecode"), _FX_BSTRC("LZW"), 471 _FX_BSTRC("LZWDecode"), _FX_BSTRC("LZW"),
434 _FX_BSTRC("FlateDecode"), _FX_BSTRC("Fl"), 472 _FX_BSTRC("FlateDecode"), _FX_BSTRC("Fl"),
435 _FX_BSTRC("RunLengthDecode"), _FX_BSTRC("RL"), 473 _FX_BSTRC("RunLengthDecode"), _FX_BSTRC("RL"),
436 _FX_BSTRC("CCITTFaxDecode"), _FX_BSTRC("CCF"), 474 _FX_BSTRC("CCITTFaxDecode"), _FX_BSTRC("CCF"),
437 _FX_BSTRC("DCTDecode"), _FX_BSTRC("DCT"), 475 _FX_BSTRC("DCTDecode"), _FX_BSTRC("DCT"),
438 }; 476 };
439 static CFX_ByteStringC _PDF_FindFullName(const _FX_BSTR* table, int count, const CFX_ByteStringC& abbr) 477 static CFX_ByteStringC _PDF_FindFullName(const _FX_BSTR* table,
440 { 478 int count,
441 int i = 0; 479 const CFX_ByteStringC& abbr) {
442 while (i < count) { 480 int i = 0;
443 if (abbr.GetLength() == table[i + 1].m_Size && FXSYS_memcmp(abbr.GetPtr( ), table[i + 1].m_Ptr, abbr.GetLength()) == 0) { 481 while (i < count) {
444 return CFX_ByteStringC(table[i].m_Ptr, table[i].m_Size); 482 if (abbr.GetLength() == table[i + 1].m_Size &&
483 FXSYS_memcmp(abbr.GetPtr(), table[i + 1].m_Ptr, abbr.GetLength()) ==
484 0) {
485 return CFX_ByteStringC(table[i].m_Ptr, table[i].m_Size);
486 }
487 i += 2;
488 }
489 return CFX_ByteStringC();
490 }
491 void _PDF_ReplaceAbbr(CPDF_Object* pObj) {
492 switch (pObj->GetType()) {
493 case PDFOBJ_DICTIONARY: {
494 CPDF_Dictionary* pDict = (CPDF_Dictionary*)pObj;
495 FX_POSITION pos = pDict->GetStartPos();
496 while (pos) {
497 CFX_ByteString key;
498 CPDF_Object* value = pDict->GetNextElement(pos, key);
499 CFX_ByteStringC fullname = _PDF_FindFullName(
500 _PDF_InlineKeyAbbr, sizeof _PDF_InlineKeyAbbr / sizeof(_FX_BSTR),
501 key);
502 if (!fullname.IsEmpty()) {
503 pDict->ReplaceKey(key, fullname);
504 key = fullname;
445 } 505 }
446 i += 2; 506 if (value->GetType() == PDFOBJ_NAME) {
447 } 507 CFX_ByteString name = value->GetString();
448 return CFX_ByteStringC(); 508 fullname = _PDF_FindFullName(
449 } 509 _PDF_InlineValueAbbr,
450 void _PDF_ReplaceAbbr(CPDF_Object* pObj) 510 sizeof _PDF_InlineValueAbbr / sizeof(_FX_BSTR), name);
451 { 511 if (!fullname.IsEmpty()) {
452 switch (pObj->GetType()) { 512 pDict->SetAtName(key, fullname);
453 case PDFOBJ_DICTIONARY: { 513 }
454 CPDF_Dictionary* pDict = (CPDF_Dictionary*)pObj; 514 } else {
455 FX_POSITION pos = pDict->GetStartPos(); 515 _PDF_ReplaceAbbr(value);
456 while (pos) {
457 CFX_ByteString key;
458 CPDF_Object* value = pDict->GetNextElement(pos, key);
459 CFX_ByteStringC fullname = _PDF_FindFullName(_PDF_InlineKeyA bbr,
460 sizeof _PDF_InlineKeyAbbr / sizeo f(_FX_BSTR), key);
461 if (!fullname.IsEmpty()) {
462 pDict->ReplaceKey(key, fullname);
463 key = fullname;
464 }
465 if (value->GetType() == PDFOBJ_NAME) {
466 CFX_ByteString name = value->GetString();
467 fullname = _PDF_FindFullName(_PDF_InlineValueAbbr,
468 sizeof _PDF_InlineValueAbbr / sizeof(_FX_BSTR), name);
469 if (!fullname.IsEmpty()) {
470 pDict->SetAtName(key, fullname);
471 }
472 } else {
473 _PDF_ReplaceAbbr(value);
474 }
475 }
476 break;
477 }
478 case PDFOBJ_ARRAY: {
479 CPDF_Array* pArray = (CPDF_Array*)pObj;
480 for (FX_DWORD i = 0; i < pArray->GetCount(); i ++) {
481 CPDF_Object* pElement = pArray->GetElement(i);
482 if (pElement->GetType() == PDFOBJ_NAME) {
483 CFX_ByteString name = pElement->GetString();
484 CFX_ByteStringC fullname = _PDF_FindFullName(_PDF_Inline ValueAbbr,
485 sizeof _PDF_InlineValueAbbr / sizeof(_FX_BSTR), name);
486 if (!fullname.IsEmpty()) {
487 pArray->SetAt(i, CPDF_Name::Create(fullname));
488 }
489 } else {
490 _PDF_ReplaceAbbr(pElement);
491 }
492 }
493 break;
494 }
495 }
496 }
497 static CFX_ByteStringC _PDF_FindAbbrName(const _FX_BSTR* table, int count, const CFX_ByteStringC& fullName)
498 {
499 int i = 0;
500 while (i < count) {
501 if (fullName.GetLength() == table[i].m_Size && FXSYS_memcmp(fullName.Get Ptr(), table[i].m_Ptr, fullName.GetLength()) == 0) {
502 return CFX_ByteStringC(table[i + 1].m_Ptr, table[i + 1].m_Size);
503 } 516 }
504 i += 2; 517 }
505 } 518 break;
506 return CFX_ByteStringC(); 519 }
507 } 520 case PDFOBJ_ARRAY: {
508 void _PDF_ReplaceFull(CPDF_Object* pObj) 521 CPDF_Array* pArray = (CPDF_Array*)pObj;
509 { 522 for (FX_DWORD i = 0; i < pArray->GetCount(); i++) {
510 switch (pObj->GetType()) { 523 CPDF_Object* pElement = pArray->GetElement(i);
511 case PDFOBJ_DICTIONARY: { 524 if (pElement->GetType() == PDFOBJ_NAME) {
512 CPDF_Dictionary* pDict = (CPDF_Dictionary*)pObj; 525 CFX_ByteString name = pElement->GetString();
513 FX_POSITION pos = pDict->GetStartPos(); 526 CFX_ByteStringC fullname = _PDF_FindFullName(
514 while (pos) { 527 _PDF_InlineValueAbbr,
515 CFX_ByteString key; 528 sizeof _PDF_InlineValueAbbr / sizeof(_FX_BSTR), name);
516 CPDF_Object* value = pDict->GetNextElement(pos, key); 529 if (!fullname.IsEmpty()) {
517 CFX_ByteStringC abbrName = _PDF_FindAbbrName(_PDF_InlineKeyA bbr, 530 pArray->SetAt(i, CPDF_Name::Create(fullname));
518 sizeof(_PDF_InlineKeyAbbr) / size of(_FX_BSTR), key); 531 }
519 if (!abbrName.IsEmpty()) { 532 } else {
520 pDict->ReplaceKey(key, abbrName); 533 _PDF_ReplaceAbbr(pElement);
521 key = abbrName; 534 }
522 } 535 }
523 if (value->GetType() == PDFOBJ_NAME) { 536 break;
524 CFX_ByteString name = value->GetString(); 537 }
525 abbrName = _PDF_FindAbbrName(_PDF_InlineValueAbbr, 538 }
526 sizeof(_PDF_InlineValueAbbr ) / sizeof(_FX_BSTR), name); 539 }
527 if (!abbrName.IsEmpty()) { 540 static CFX_ByteStringC _PDF_FindAbbrName(const _FX_BSTR* table,
528 pDict->SetAtName(key, abbrName); 541 int count,
529 } 542 const CFX_ByteStringC& fullName) {
530 } else { 543 int i = 0;
531 _PDF_ReplaceFull(value); 544 while (i < count) {
532 } 545 if (fullName.GetLength() == table[i].m_Size &&
533 } 546 FXSYS_memcmp(fullName.GetPtr(), table[i].m_Ptr, fullName.GetLength()) ==
534 break; 547 0) {
535 } 548 return CFX_ByteStringC(table[i + 1].m_Ptr, table[i + 1].m_Size);
536 case PDFOBJ_ARRAY: { 549 }
537 CPDF_Array* pArray = (CPDF_Array*)pObj; 550 i += 2;
538 for (FX_DWORD i = 0; i < pArray->GetCount(); i ++) { 551 }
539 CPDF_Object* pElement = pArray->GetElement(i); 552 return CFX_ByteStringC();
540 if (pElement->GetType() == PDFOBJ_NAME) { 553 }
541 CFX_ByteString name = pElement->GetString(); 554 void _PDF_ReplaceFull(CPDF_Object* pObj) {
542 CFX_ByteStringC abbrName = _PDF_FindAbbrName(_PDF_Inline ValueAbbr, 555 switch (pObj->GetType()) {
543 sizeof _PDF_InlineValueAbbr / sizeof(_FX_BSTR), name); 556 case PDFOBJ_DICTIONARY: {
544 if (!abbrName.IsEmpty()) { 557 CPDF_Dictionary* pDict = (CPDF_Dictionary*)pObj;
545 pArray->SetAt(i, CPDF_Name::Create(abbrName)); 558 FX_POSITION pos = pDict->GetStartPos();
546 } 559 while (pos) {
547 } else { 560 CFX_ByteString key;
548 _PDF_ReplaceFull(pElement); 561 CPDF_Object* value = pDict->GetNextElement(pos, key);
549 } 562 CFX_ByteStringC abbrName = _PDF_FindAbbrName(
550 } 563 _PDF_InlineKeyAbbr, sizeof(_PDF_InlineKeyAbbr) / sizeof(_FX_BSTR),
551 break; 564 key);
552 } 565 if (!abbrName.IsEmpty()) {
553 } 566 pDict->ReplaceKey(key, abbrName);
554 } 567 key = abbrName;
555 void CPDF_StreamContentParser::Handle_BeginText() 568 }
556 { 569 if (value->GetType() == PDFOBJ_NAME) {
557 m_pCurStates->m_TextMatrix.Set(1.0f, 0, 0, 1.0f, 0, 0); 570 CFX_ByteString name = value->GetString();
558 OnChangeTextMatrix(); 571 abbrName = _PDF_FindAbbrName(
559 m_pCurStates->m_TextX = 0; 572 _PDF_InlineValueAbbr,
560 m_pCurStates->m_TextY = 0; 573 sizeof(_PDF_InlineValueAbbr) / sizeof(_FX_BSTR), name);
561 m_pCurStates->m_TextLineX = 0; 574 if (!abbrName.IsEmpty()) {
562 m_pCurStates->m_TextLineY = 0; 575 pDict->SetAtName(key, abbrName);
563 } 576 }
564 void CPDF_StreamContentParser::Handle_BeginSectionUndefined() 577 } else {
565 { 578 _PDF_ReplaceFull(value);
566 m_CompatCount ++; 579 }
567 } 580 }
568 void CPDF_StreamContentParser::Handle_CurveTo_123() 581 break;
569 { 582 }
583 case PDFOBJ_ARRAY: {
584 CPDF_Array* pArray = (CPDF_Array*)pObj;
585 for (FX_DWORD i = 0; i < pArray->GetCount(); i++) {
586 CPDF_Object* pElement = pArray->GetElement(i);
587 if (pElement->GetType() == PDFOBJ_NAME) {
588 CFX_ByteString name = pElement->GetString();
589 CFX_ByteStringC abbrName = _PDF_FindAbbrName(
590 _PDF_InlineValueAbbr,
591 sizeof _PDF_InlineValueAbbr / sizeof(_FX_BSTR), name);
592 if (!abbrName.IsEmpty()) {
593 pArray->SetAt(i, CPDF_Name::Create(abbrName));
594 }
595 } else {
596 _PDF_ReplaceFull(pElement);
597 }
598 }
599 break;
600 }
601 }
602 }
603 void CPDF_StreamContentParser::Handle_BeginText() {
604 m_pCurStates->m_TextMatrix.Set(1.0f, 0, 0, 1.0f, 0, 0);
605 OnChangeTextMatrix();
606 m_pCurStates->m_TextX = 0;
607 m_pCurStates->m_TextY = 0;
608 m_pCurStates->m_TextLineX = 0;
609 m_pCurStates->m_TextLineY = 0;
610 }
611 void CPDF_StreamContentParser::Handle_BeginSectionUndefined() {
612 m_CompatCount++;
613 }
614 void CPDF_StreamContentParser::Handle_CurveTo_123() {
615 if (m_Options.m_bTextOnly) {
616 return;
617 }
618 AddPathPoint(GetNumber(5), GetNumber(4), FXPT_BEZIERTO);
619 AddPathPoint(GetNumber(3), GetNumber(2), FXPT_BEZIERTO);
620 AddPathPoint(GetNumber(1), GetNumber(0), FXPT_BEZIERTO);
621 }
622 void CPDF_StreamContentParser::Handle_ConcatMatrix() {
623 FX_FLOAT a2 = GetNumber16(5), b2 = GetNumber16(4), c2 = GetNumber16(3),
624 d2 = GetNumber16(2);
625 FX_FLOAT e2 = GetNumber(1), f2 = GetNumber(0);
626 CFX_AffineMatrix new_matrix(a2, b2, c2, d2, e2, f2);
627 new_matrix.Concat(m_pCurStates->m_CTM);
628 m_pCurStates->m_CTM = new_matrix;
629 OnChangeTextMatrix();
630 }
631 void CPDF_StreamContentParser::Handle_SetColorSpace_Fill() {
632 if (m_Options.m_bTextOnly) {
633 return;
634 }
635 CFX_ByteString csname = GetString(0);
636 CPDF_ColorSpace* pCS = FindColorSpace(csname);
637 if (pCS == NULL) {
638 return;
639 }
640 m_pCurStates->m_ColorState.GetModify()->m_FillColor.SetColorSpace(pCS);
641 }
642 void CPDF_StreamContentParser::Handle_SetColorSpace_Stroke() {
643 if (m_Options.m_bTextOnly) {
644 return;
645 }
646 CFX_ByteString csname = GetString(0);
647 CPDF_ColorSpace* pCS = FindColorSpace(csname);
648 if (pCS == NULL) {
649 return;
650 }
651 m_pCurStates->m_ColorState.GetModify()->m_StrokeColor.SetColorSpace(pCS);
652 }
653 void CPDF_StreamContentParser::Handle_SetDash() {
654 if (m_Options.m_bTextOnly) {
655 return;
656 }
657 CPDF_Array* pArray = GetObject(1) ? GetObject(1)->GetArray() : NULL;
658 if (pArray == NULL) {
659 return;
660 }
661 m_pCurStates->SetLineDash(pArray, GetNumber(0), 1.0f);
662 }
663 void CPDF_StreamContentParser::Handle_SetCharWidth() {
664 m_Type3Data[0] = GetNumber(1);
665 m_Type3Data[1] = GetNumber(0);
666 m_bColored = TRUE;
667 }
668 void CPDF_StreamContentParser::Handle_SetCachedDevice() {
669 for (int i = 0; i < 6; i++) {
670 m_Type3Data[i] = GetNumber(5 - i);
671 }
672 m_bColored = FALSE;
673 }
674 void CPDF_StreamContentParser::Handle_ExecuteXObject() {
675 CFX_ByteString name = GetString(0);
676 if (name == m_LastImageName && m_pLastImage && m_pLastImage->GetStream() &&
677 m_pLastImage->GetStream()->GetObjNum()) {
678 AddImage(NULL, m_pLastImage, FALSE);
679 return;
680 }
681 if (m_Options.m_bTextOnly) {
682 CPDF_Object* pRes = NULL;
683 if (m_pResources == NULL) {
684 return;
685 }
686 if (m_pResources == m_pPageResources) {
687 CPDF_Dictionary* pList = m_pResources->GetDict(FX_BSTRC("XObject"));
688 if (pList == NULL) {
689 return;
690 }
691 pRes = pList->GetElement(name);
692 if (pRes == NULL || pRes->GetType() != PDFOBJ_REFERENCE) {
693 return;
694 }
695 } else {
696 CPDF_Dictionary* pList = m_pResources->GetDict(FX_BSTRC("XObject"));
697 if (pList == NULL) {
698 if (m_pPageResources == NULL) {
699 return;
700 }
701 CPDF_Dictionary* pList = m_pPageResources->GetDict(FX_BSTRC("XObject"));
702 if (pList == NULL) {
703 return;
704 }
705 pRes = pList->GetElement(name);
706 if (pRes == NULL || pRes->GetType() != PDFOBJ_REFERENCE) {
707 return;
708 }
709 } else {
710 pRes = pList->GetElement(name);
711 if (pRes == NULL || pRes->GetType() != PDFOBJ_REFERENCE) {
712 return;
713 }
714 }
715 }
716 FX_BOOL bForm;
717 if (m_pDocument->IsFormStream(((CPDF_Reference*)pRes)->GetRefObjNum(),
718 bForm) &&
719 !bForm) {
720 return;
721 }
722 }
723 CPDF_Stream* pXObject =
724 (CPDF_Stream*)FindResourceObj(FX_BSTRC("XObject"), name);
725 if (pXObject == NULL || pXObject->GetType() != PDFOBJ_STREAM) {
726 m_bResourceMissing = TRUE;
727 return;
728 }
729 CFX_ByteStringC type =
730 pXObject->GetDict()
731 ? pXObject->GetDict()->GetConstString(FX_BSTRC("Subtype"))
732 : CFX_ByteStringC();
733 if (type == FX_BSTRC("Image")) {
570 if (m_Options.m_bTextOnly) { 734 if (m_Options.m_bTextOnly) {
571 return; 735 return;
572 } 736 }
573 AddPathPoint(GetNumber(5), GetNumber(4), FXPT_BEZIERTO); 737 CPDF_ImageObject* pObj = AddImage(pXObject, NULL, FALSE);
574 AddPathPoint(GetNumber(3), GetNumber(2), FXPT_BEZIERTO); 738 m_LastImageName = name;
575 AddPathPoint(GetNumber(1), GetNumber(0), FXPT_BEZIERTO); 739 m_pLastImage = pObj->m_pImage;
576 } 740 } else if (type == FX_BSTRC("Form")) {
577 void CPDF_StreamContentParser::Handle_ConcatMatrix() 741 AddForm(pXObject);
578 { 742 } else {
579 FX_FLOAT a2 = GetNumber16(5), b2 = GetNumber16(4), c2 = GetNumber16(3), d2 = GetNumber16(2); 743 return;
580 FX_FLOAT e2 = GetNumber(1), f2 = GetNumber(0); 744 }
581 CFX_AffineMatrix new_matrix(a2, b2, c2, d2, e2, f2); 745 }
582 new_matrix.Concat(m_pCurStates->m_CTM); 746 void CPDF_StreamContentParser::AddForm(CPDF_Stream* pStream) {
583 m_pCurStates->m_CTM = new_matrix; 747 if (!m_Options.m_bSeparateForm) {
584 OnChangeTextMatrix(); 748 CPDF_Dictionary* pResources =
585 } 749 pStream->GetDict()->GetDict(FX_BSTRC("Resources"));
586 void CPDF_StreamContentParser::Handle_SetColorSpace_Fill() 750 CFX_AffineMatrix form_matrix =
587 { 751 pStream->GetDict()->GetMatrix(FX_BSTRC("Matrix"));
588 if (m_Options.m_bTextOnly) { 752 form_matrix.Concat(m_pCurStates->m_CTM);
589 return; 753 CPDF_Array* pBBox = pStream->GetDict()->GetArray(FX_BSTRC("BBox"));
590 } 754 CFX_FloatRect form_bbox;
591 CFX_ByteString csname = GetString(0); 755 CPDF_Path ClipPath;
592 CPDF_ColorSpace* pCS = FindColorSpace(csname); 756 if (pBBox) {
593 if (pCS == NULL) { 757 form_bbox = pStream->GetDict()->GetRect(FX_BSTRC("BBox"));
594 return; 758 ClipPath.New();
595 } 759 ClipPath.AppendRect(form_bbox.left, form_bbox.bottom, form_bbox.right,
596 m_pCurStates->m_ColorState.GetModify()->m_FillColor.SetColorSpace(pCS); 760 form_bbox.top);
597 } 761 ClipPath.Transform(&form_matrix);
598 void CPDF_StreamContentParser::Handle_SetColorSpace_Stroke() 762 form_bbox.Transform(&form_matrix);
599 { 763 }
600 if (m_Options.m_bTextOnly) { 764 CPDF_StreamContentParser parser(m_pDocument, m_pPageResources, m_pResources,
601 return; 765 &m_mtContentToUser, m_pObjectList,
602 } 766 pResources, &form_bbox, &m_Options,
603 CFX_ByteString csname = GetString(0); 767 m_pCurStates.get(), m_Level + 1);
604 CPDF_ColorSpace* pCS = FindColorSpace(csname); 768 parser.m_pCurStates->m_CTM = form_matrix;
605 if (pCS == NULL) { 769 if (ClipPath.NotNull()) {
606 return; 770 parser.m_pCurStates->m_ClipPath.AppendPath(ClipPath, FXFILL_WINDING,
607 } 771 TRUE);
608 m_pCurStates->m_ColorState.GetModify()->m_StrokeColor.SetColorSpace(pCS); 772 }
609 } 773 CPDF_StreamAcc stream;
610 void CPDF_StreamContentParser::Handle_SetDash() 774 stream.LoadAllData(pStream, FALSE);
611 { 775 if (stream.GetSize() == 0) {
612 if (m_Options.m_bTextOnly) { 776 return;
613 return; 777 }
614 } 778 parser.Parse(stream.GetData(), stream.GetSize(), 0);
615 CPDF_Array* pArray = GetObject(1) ? GetObject(1)->GetArray() : NULL; 779 return;
616 if (pArray == NULL) { 780 }
617 return; 781 CPDF_FormObject* pFormObj = new CPDF_FormObject;
618 } 782 pFormObj->m_pForm =
619 m_pCurStates->SetLineDash(pArray, GetNumber(0), 1.0f); 783 new CPDF_Form(m_pDocument, m_pPageResources, pStream, m_pResources);
620 } 784 pFormObj->m_FormMatrix = m_pCurStates->m_CTM;
621 void CPDF_StreamContentParser::Handle_SetCharWidth() 785 pFormObj->m_FormMatrix.Concat(m_mtContentToUser);
622 { 786 CPDF_AllStates status;
623 m_Type3Data[0] = GetNumber(1); 787 status.m_GeneralState = m_pCurStates->m_GeneralState;
624 m_Type3Data[1] = GetNumber(0); 788 status.m_GraphState = m_pCurStates->m_GraphState;
625 m_bColored = TRUE; 789 status.m_ColorState = m_pCurStates->m_ColorState;
626 } 790 status.m_TextState = m_pCurStates->m_TextState;
627 void CPDF_StreamContentParser::Handle_SetCachedDevice() 791 pFormObj->m_pForm->ParseContent(&status, NULL, NULL, &m_Options, m_Level + 1);
628 { 792 if (!m_pObjectList->m_bBackgroundAlphaNeeded &&
629 for (int i = 0; i < 6; i ++) { 793 pFormObj->m_pForm->m_bBackgroundAlphaNeeded) {
630 m_Type3Data[i] = GetNumber(5 - i); 794 m_pObjectList->m_bBackgroundAlphaNeeded = TRUE;
631 } 795 }
632 m_bColored = FALSE; 796 pFormObj->CalcBoundingBox();
633 } 797 SetGraphicStates(pFormObj, TRUE, TRUE, TRUE);
634 void CPDF_StreamContentParser::Handle_ExecuteXObject() 798 m_pObjectList->m_ObjectList.AddTail(pFormObj);
635 { 799 }
636 CFX_ByteString name = GetString(0); 800 CPDF_ImageObject* CPDF_StreamContentParser::AddImage(CPDF_Stream* pStream,
637 if (name == m_LastImageName && m_pLastImage && m_pLastImage->GetStream() && m_pLastImage->GetStream()->GetObjNum()) { 801 CPDF_Image* pImage,
638 AddImage(NULL, m_pLastImage, FALSE); 802 FX_BOOL bInline) {
639 return; 803 if (pStream == NULL && pImage == NULL) {
640 } 804 return NULL;
641 if (m_Options.m_bTextOnly) { 805 }
642 CPDF_Object* pRes = NULL; 806 CFX_AffineMatrix ImageMatrix;
643 if (m_pResources == NULL) { 807 ImageMatrix.Copy(m_pCurStates->m_CTM);
644 return; 808 ImageMatrix.Concat(m_mtContentToUser);
645 } 809 CPDF_ImageObject* pImageObj = new CPDF_ImageObject;
646 if (m_pResources == m_pPageResources) { 810 if (pImage) {
647 CPDF_Dictionary* pList = m_pResources->GetDict(FX_BSTRC("XObject")); 811 pImageObj->m_pImage =
648 if (pList == NULL) { 812 m_pDocument->GetPageData()->GetImage(pImage->GetStream());
649 return; 813 } else if (pStream->GetObjNum()) {
650 } 814 pImageObj->m_pImage = m_pDocument->LoadImageF(pStream);
651 pRes = pList->GetElement(name); 815 } else {
652 if (pRes == NULL || pRes->GetType() != PDFOBJ_REFERENCE) { 816 pImageObj->m_pImage = new CPDF_Image(m_pDocument);
653 return; 817 pImageObj->m_pImage->LoadImageF(pStream, bInline);
654 } 818 }
655 } else { 819 SetGraphicStates(pImageObj, pImageObj->m_pImage->IsMask(), FALSE, FALSE);
656 CPDF_Dictionary* pList = m_pResources->GetDict(FX_BSTRC("XObject")); 820 pImageObj->m_Matrix = ImageMatrix;
657 if (pList == NULL) { 821 pImageObj->CalcBoundingBox();
658 if (m_pPageResources == NULL) { 822 m_pObjectList->m_ObjectList.AddTail(pImageObj);
659 return; 823 return pImageObj;
660 } 824 }
661 CPDF_Dictionary* pList = m_pPageResources->GetDict(FX_BSTRC("XOb ject")); 825 void CPDF_StreamContentParser::Handle_MarkPlace_Dictionary() {}
662 if (pList == NULL) { 826 void CPDF_StreamContentParser::Handle_EndImage() {}
663 return; 827 void CPDF_StreamContentParser::Handle_EndMarkedContent() {
664 } 828 if (!m_Options.m_bMarkedContent) {
665 pRes = pList->GetElement(name); 829 return;
666 if (pRes == NULL || pRes->GetType() != PDFOBJ_REFERENCE) { 830 }
667 return; 831 if (m_CurContentMark.IsNull()) {
668 } 832 return;
669 } else { 833 }
670 pRes = pList->GetElement(name); 834 int count = m_CurContentMark.GetObject()->CountItems();
671 if (pRes == NULL || pRes->GetType() != PDFOBJ_REFERENCE) { 835 if (count == 1) {
672 return; 836 m_CurContentMark.SetNull();
673 } 837 return;
674 } 838 }
675 } 839 m_CurContentMark.GetModify()->DeleteLastMark();
676 FX_BOOL bForm; 840 }
677 if (m_pDocument->IsFormStream(((CPDF_Reference*)pRes)->GetRefObjNum(), b Form) && !bForm) { 841 void CPDF_StreamContentParser::Handle_EndText() {
678 return; 842 int count = m_ClipTextList.GetSize();
679 } 843 if (count == 0) {
680 } 844 return;
681 CPDF_Stream* pXObject = (CPDF_Stream*)FindResourceObj(FX_BSTRC("XObject"), n ame); 845 }
682 if (pXObject == NULL || pXObject->GetType() != PDFOBJ_STREAM) { 846 if (m_pCurStates->m_TextState.GetObject()->m_TextMode < 4) {
683 m_bResourceMissing = TRUE; 847 for (int i = 0; i < count; i++) {
684 return; 848 CPDF_TextObject* pText = (CPDF_TextObject*)m_ClipTextList.GetAt(i);
685 } 849 delete pText;
686 CFX_ByteStringC type = pXObject->GetDict() ? pXObject->GetDict()->GetConstSt ring(FX_BSTRC("Subtype")) : CFX_ByteStringC(); 850 }
687 if (type == FX_BSTRC("Image")) { 851 } else {
688 if (m_Options.m_bTextOnly) { 852 m_pCurStates->m_ClipPath.AppendTexts(
689 return; 853 (CPDF_TextObject**)m_ClipTextList.GetData(), count);
690 } 854 }
691 CPDF_ImageObject* pObj = AddImage(pXObject, NULL, FALSE); 855 m_ClipTextList.RemoveAll();
692 m_LastImageName = name; 856 }
693 m_pLastImage = pObj->m_pImage; 857 void CPDF_StreamContentParser::Handle_EndSectionUndefined() {
694 } else if (type == FX_BSTRC("Form")) { 858 if (m_CompatCount) {
695 AddForm(pXObject); 859 m_CompatCount--;
696 } else { 860 }
697 return; 861 }
698 } 862 void CPDF_StreamContentParser::Handle_FillPath() {
699 } 863 if (m_Options.m_bTextOnly) {
700 void CPDF_StreamContentParser::AddForm(CPDF_Stream* pStream) 864 return;
701 { 865 }
702 if (!m_Options.m_bSeparateForm) { 866 AddPathObject(FXFILL_WINDING, FALSE);
703 CPDF_Dictionary* pResources = pStream->GetDict()->GetDict(FX_BSTRC("Reso urces")); 867 }
704 CFX_AffineMatrix form_matrix = pStream->GetDict()->GetMatrix(FX_BSTRC("M atrix")); 868 void CPDF_StreamContentParser::Handle_FillPathOld() {
705 form_matrix.Concat(m_pCurStates->m_CTM); 869 if (m_Options.m_bTextOnly) {
706 CPDF_Array* pBBox = pStream->GetDict()->GetArray(FX_BSTRC("BBox")); 870 return;
707 CFX_FloatRect form_bbox; 871 }
708 CPDF_Path ClipPath; 872 AddPathObject(FXFILL_WINDING, FALSE);
709 if (pBBox) { 873 }
710 form_bbox = pStream->GetDict()->GetRect(FX_BSTRC("BBox")); 874 void CPDF_StreamContentParser::Handle_EOFillPath() {
711 ClipPath.New(); 875 if (m_Options.m_bTextOnly) {
712 ClipPath.AppendRect(form_bbox.left, form_bbox.bottom, form_bbox.righ t, form_bbox.top); 876 return;
713 ClipPath.Transform(&form_matrix); 877 }
714 form_bbox.Transform(&form_matrix); 878 AddPathObject(FXFILL_ALTERNATE, FALSE);
715 } 879 }
716 CPDF_StreamContentParser parser( 880 void CPDF_StreamContentParser::Handle_SetGray_Fill() {
717 m_pDocument, m_pPageResources, m_pResources, &m_mtContentToUser, 881 FX_FLOAT value = GetNumber(0);
718 m_pObjectList, pResources, &form_bbox, &m_Options, 882 CPDF_ColorSpace* pCS = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY);
719 m_pCurStates.get(), m_Level + 1); 883 m_pCurStates->m_ColorState.SetFillColor(pCS, &value, 1);
720 parser.m_pCurStates->m_CTM = form_matrix; 884 }
721 if (ClipPath.NotNull()) { 885 void CPDF_StreamContentParser::Handle_SetGray_Stroke() {
722 parser.m_pCurStates->m_ClipPath.AppendPath(ClipPath, FXFILL_WINDING, TRUE); 886 FX_FLOAT value = GetNumber(0);
723 } 887 CPDF_ColorSpace* pCS = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY);
724 CPDF_StreamAcc stream; 888 m_pCurStates->m_ColorState.SetStrokeColor(pCS, &value, 1);
725 stream.LoadAllData(pStream, FALSE); 889 }
726 if (stream.GetSize() == 0) { 890 void CPDF_StreamContentParser::Handle_SetExtendGraphState() {
727 return; 891 CFX_ByteString name = GetString(0);
728 } 892 CPDF_Dictionary* pGS =
729 parser.Parse(stream.GetData(), stream.GetSize(), 0); 893 (CPDF_Dictionary*)FindResourceObj(FX_BSTRC("ExtGState"), name);
730 return; 894 if (pGS == NULL || pGS->GetType() != PDFOBJ_DICTIONARY) {
731 } 895 m_bResourceMissing = TRUE;
732 CPDF_FormObject* pFormObj = new CPDF_FormObject; 896 return;
733 pFormObj->m_pForm = new CPDF_Form(m_pDocument, m_pPageResources, pStream, m_ pResources); 897 }
734 pFormObj->m_FormMatrix = m_pCurStates->m_CTM; 898 m_pCurStates->ProcessExtGS(pGS, this);
735 pFormObj->m_FormMatrix.Concat(m_mtContentToUser); 899 }
736 CPDF_AllStates status; 900 void CPDF_StreamContentParser::Handle_ClosePath() {
737 status.m_GeneralState = m_pCurStates->m_GeneralState; 901 if (m_Options.m_bTextOnly) {
738 status.m_GraphState = m_pCurStates->m_GraphState; 902 return;
739 status.m_ColorState = m_pCurStates->m_ColorState; 903 }
740 status.m_TextState = m_pCurStates->m_TextState; 904 if (m_PathPointCount == 0) {
741 pFormObj->m_pForm->ParseContent(&status, NULL, NULL, &m_Options, m_Level + 1 ); 905 return;
742 if (!m_pObjectList->m_bBackgroundAlphaNeeded && pFormObj->m_pForm->m_bBackgr oundAlphaNeeded) { 906 }
743 m_pObjectList->m_bBackgroundAlphaNeeded = TRUE; 907 if (m_PathStartX != m_PathCurrentX || m_PathStartY != m_PathCurrentY) {
744 } 908 AddPathPoint(m_PathStartX, m_PathStartY, FXPT_LINETO | FXPT_CLOSEFIGURE);
745 pFormObj->CalcBoundingBox(); 909 } else if (m_pPathPoints[m_PathPointCount - 1].m_Flag != FXPT_MOVETO) {
746 SetGraphicStates(pFormObj, TRUE, TRUE, TRUE); 910 m_pPathPoints[m_PathPointCount - 1].m_Flag |= FXPT_CLOSEFIGURE;
747 m_pObjectList->m_ObjectList.AddTail(pFormObj); 911 }
748 } 912 }
749 CPDF_ImageObject* CPDF_StreamContentParser::AddImage(CPDF_Stream* pStream, CPDF_ Image* pImage, FX_BOOL bInline) 913 void CPDF_StreamContentParser::Handle_SetFlat() {
750 { 914 m_pCurStates->m_GeneralState.GetModify()->m_Flatness = GetNumber(0);
751 if (pStream == NULL && pImage == NULL) { 915 }
752 return NULL; 916 void CPDF_StreamContentParser::Handle_BeginImageData() {}
753 } 917 void CPDF_StreamContentParser::Handle_SetLineJoin() {
754 CFX_AffineMatrix ImageMatrix; 918 m_pCurStates->m_GraphState.GetModify()->m_LineJoin =
755 ImageMatrix.Copy(m_pCurStates->m_CTM); 919 (CFX_GraphStateData::LineJoin)GetInteger(0);
756 ImageMatrix.Concat(m_mtContentToUser); 920 }
757 CPDF_ImageObject* pImageObj = new CPDF_ImageObject; 921 void CPDF_StreamContentParser::Handle_SetLineCap() {
758 if (pImage) { 922 m_pCurStates->m_GraphState.GetModify()->m_LineCap =
759 pImageObj->m_pImage = m_pDocument->GetPageData()->GetImage(pImage->GetSt ream()); 923 (CFX_GraphStateData::LineCap)GetInteger(0);
760 } else if (pStream->GetObjNum()) { 924 }
761 pImageObj->m_pImage = m_pDocument->LoadImageF(pStream); 925 void CPDF_StreamContentParser::Handle_SetCMYKColor_Fill() {
762 } else { 926 REQUIRE_PARAMS(4);
763 pImageObj->m_pImage = new CPDF_Image(m_pDocument); 927 FX_FLOAT values[4];
764 pImageObj->m_pImage->LoadImageF(pStream, bInline); 928 for (int i = 0; i < 4; i++) {
765 } 929 values[i] = GetNumber(3 - i);
766 SetGraphicStates(pImageObj, pImageObj->m_pImage->IsMask(), FALSE, FALSE); 930 }
767 pImageObj->m_Matrix = ImageMatrix; 931 CPDF_ColorSpace* pCS = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICECMYK);
768 pImageObj->CalcBoundingBox(); 932 m_pCurStates->m_ColorState.SetFillColor(pCS, values, 4);
769 m_pObjectList->m_ObjectList.AddTail(pImageObj); 933 }
770 return pImageObj; 934 void CPDF_StreamContentParser::Handle_SetCMYKColor_Stroke() {
771 } 935 REQUIRE_PARAMS(4);
772 void CPDF_StreamContentParser::Handle_MarkPlace_Dictionary() 936 FX_FLOAT values[4];
773 { 937 for (int i = 0; i < 4; i++) {
774 } 938 values[i] = GetNumber(3 - i);
775 void CPDF_StreamContentParser::Handle_EndImage() 939 }
776 { 940 CPDF_ColorSpace* pCS = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICECMYK);
777 } 941 m_pCurStates->m_ColorState.SetStrokeColor(pCS, values, 4);
778 void CPDF_StreamContentParser::Handle_EndMarkedContent() 942 }
779 { 943 void CPDF_StreamContentParser::Handle_LineTo() {
780 if (!m_Options.m_bMarkedContent) { 944 REQUIRE_PARAMS(2);
781 return; 945 if (m_Options.m_bTextOnly) {
782 } 946 return;
783 if (m_CurContentMark.IsNull()) { 947 }
784 return; 948 AddPathPoint(GetNumber(1), GetNumber(0), FXPT_LINETO);
785 } 949 }
786 int count = m_CurContentMark.GetObject()->CountItems(); 950 void CPDF_StreamContentParser::Handle_MoveTo() {
787 if (count == 1) { 951 REQUIRE_PARAMS(2);
788 m_CurContentMark.SetNull(); 952 if (m_Options.m_bTextOnly) {
789 return; 953 m_pSyntax->SkipPathObject();
790 } 954 return;
791 m_CurContentMark.GetModify()->DeleteLastMark(); 955 }
792 } 956 AddPathPoint(GetNumber(1), GetNumber(0), FXPT_MOVETO);
793 void CPDF_StreamContentParser::Handle_EndText() 957 ParsePathObject();
794 { 958 }
795 int count = m_ClipTextList.GetSize(); 959 void CPDF_StreamContentParser::Handle_SetMiterLimit() {
796 if (count == 0) { 960 m_pCurStates->m_GraphState.GetModify()->m_MiterLimit = GetNumber(0);
797 return; 961 }
798 } 962 void CPDF_StreamContentParser::Handle_MarkPlace() {}
799 if (m_pCurStates->m_TextState.GetObject()->m_TextMode < 4) { 963 void CPDF_StreamContentParser::Handle_EndPath() {
800 for (int i = 0; i < count; i ++) { 964 if (m_Options.m_bTextOnly) {
801 CPDF_TextObject* pText = (CPDF_TextObject*)m_ClipTextList.GetAt(i); 965 return;
802 delete pText; 966 }
803 } 967 AddPathObject(0, FALSE);
804 } else { 968 }
805 m_pCurStates->m_ClipPath.AppendTexts((CPDF_TextObject**)m_ClipTextList.G etData(), count); 969 void CPDF_StreamContentParser::Handle_SaveGraphState() {
806 } 970 CPDF_AllStates* pStates = new CPDF_AllStates;
807 m_ClipTextList.RemoveAll(); 971 pStates->Copy(*m_pCurStates);
808 } 972 m_StateStack.Add(pStates);
809 void CPDF_StreamContentParser::Handle_EndSectionUndefined() 973 }
810 { 974 void CPDF_StreamContentParser::Handle_RestoreGraphState() {
811 if (m_CompatCount) { 975 int size = m_StateStack.GetSize();
812 m_CompatCount --; 976 if (size == 0) {
813 } 977 return;
814 } 978 }
815 void CPDF_StreamContentParser::Handle_FillPath() 979 CPDF_AllStates* pStates = (CPDF_AllStates*)m_StateStack.GetAt(size - 1);
816 { 980 m_pCurStates->Copy(*pStates);
817 if (m_Options.m_bTextOnly) { 981 delete pStates;
818 return; 982 m_StateStack.RemoveAt(size - 1);
819 } 983 }
820 AddPathObject(FXFILL_WINDING, FALSE); 984 void CPDF_StreamContentParser::Handle_Rectangle() {
821 } 985 if (m_Options.m_bTextOnly) {
822 void CPDF_StreamContentParser::Handle_FillPathOld() 986 return;
823 { 987 }
824 if (m_Options.m_bTextOnly) { 988 FX_FLOAT x = GetNumber(3), y = GetNumber(2);
825 return; 989 FX_FLOAT w = GetNumber(1), h = GetNumber(0);
826 } 990 AddPathRect(x, y, w, h);
827 AddPathObject(FXFILL_WINDING, FALSE); 991 }
828 } 992 void CPDF_StreamContentParser::AddPathRect(FX_FLOAT x,
829 void CPDF_StreamContentParser::Handle_EOFillPath() 993 FX_FLOAT y,
830 { 994 FX_FLOAT w,
831 if (m_Options.m_bTextOnly) { 995 FX_FLOAT h) {
832 return; 996 AddPathPoint(x, y, FXPT_MOVETO);
833 } 997 AddPathPoint(x + w, y, FXPT_LINETO);
834 AddPathObject(FXFILL_ALTERNATE, FALSE); 998 AddPathPoint(x + w, y + h, FXPT_LINETO);
835 } 999 AddPathPoint(x, y + h, FXPT_LINETO);
836 void CPDF_StreamContentParser::Handle_SetGray_Fill() 1000 AddPathPoint(x, y, FXPT_LINETO | FXPT_CLOSEFIGURE);
837 { 1001 }
838 FX_FLOAT value = GetNumber(0); 1002 void CPDF_StreamContentParser::Handle_SetRGBColor_Fill() {
839 CPDF_ColorSpace* pCS = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY); 1003 REQUIRE_PARAMS(3);
840 m_pCurStates->m_ColorState.SetFillColor(pCS, &value, 1); 1004 FX_FLOAT values[3];
841 } 1005 for (int i = 0; i < 3; i++) {
842 void CPDF_StreamContentParser::Handle_SetGray_Stroke() 1006 values[i] = GetNumber(2 - i);
843 { 1007 }
844 FX_FLOAT value = GetNumber(0); 1008 CPDF_ColorSpace* pCS = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB);
845 CPDF_ColorSpace* pCS = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY); 1009 m_pCurStates->m_ColorState.SetFillColor(pCS, values, 3);
846 m_pCurStates->m_ColorState.SetStrokeColor(pCS, &value, 1); 1010 }
847 } 1011 void CPDF_StreamContentParser::Handle_SetRGBColor_Stroke() {
848 void CPDF_StreamContentParser::Handle_SetExtendGraphState() 1012 REQUIRE_PARAMS(3);
849 { 1013 FX_FLOAT values[3];
850 CFX_ByteString name = GetString(0); 1014 for (int i = 0; i < 3; i++) {
851 CPDF_Dictionary* pGS = (CPDF_Dictionary*)FindResourceObj(FX_BSTRC("ExtGState "), name); 1015 values[i] = GetNumber(2 - i);
852 if (pGS == NULL || pGS->GetType() != PDFOBJ_DICTIONARY) { 1016 }
853 m_bResourceMissing = TRUE; 1017 CPDF_ColorSpace* pCS = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB);
854 return; 1018 m_pCurStates->m_ColorState.SetStrokeColor(pCS, values, 3);
855 } 1019 }
856 m_pCurStates->ProcessExtGS(pGS, this); 1020 void CPDF_StreamContentParser::Handle_SetRenderIntent() {}
857 } 1021 void CPDF_StreamContentParser::Handle_CloseStrokePath() {
858 void CPDF_StreamContentParser::Handle_ClosePath() 1022 if (m_Options.m_bTextOnly) {
859 { 1023 return;
860 if (m_Options.m_bTextOnly) { 1024 }
861 return; 1025 Handle_ClosePath();
862 } 1026 AddPathObject(0, TRUE);
863 if (m_PathPointCount == 0) { 1027 }
864 return; 1028 void CPDF_StreamContentParser::Handle_StrokePath() {
865 } 1029 if (m_Options.m_bTextOnly) {
866 if (m_PathStartX != m_PathCurrentX || m_PathStartY != m_PathCurrentY) { 1030 return;
867 AddPathPoint(m_PathStartX, m_PathStartY, FXPT_LINETO | FXPT_CLOSEFIGURE) ; 1031 }
868 } else if (m_pPathPoints[m_PathPointCount - 1].m_Flag != FXPT_MOVETO) { 1032 AddPathObject(0, TRUE);
869 m_pPathPoints[m_PathPointCount - 1].m_Flag |= FXPT_CLOSEFIGURE; 1033 }
870 } 1034 void CPDF_StreamContentParser::Handle_SetColor_Fill() {
871 } 1035 if (m_Options.m_bTextOnly) {
872 void CPDF_StreamContentParser::Handle_SetFlat() 1036 return;
873 { 1037 }
874 m_pCurStates->m_GeneralState.GetModify()->m_Flatness = GetNumber(0); 1038 FX_FLOAT values[4];
875 } 1039 int nargs = m_ParamCount;
876 void CPDF_StreamContentParser::Handle_BeginImageData() 1040 if (nargs > 4) {
877 { 1041 nargs = 4;
878 } 1042 }
879 void CPDF_StreamContentParser::Handle_SetLineJoin() 1043 for (int i = 0; i < nargs; i++) {
880 { 1044 values[i] = GetNumber(nargs - i - 1);
881 m_pCurStates->m_GraphState.GetModify()->m_LineJoin = (CFX_GraphStateData::Li neJoin)GetInteger(0); 1045 }
882 } 1046 m_pCurStates->m_ColorState.SetFillColor(NULL, values, nargs);
883 void CPDF_StreamContentParser::Handle_SetLineCap() 1047 }
884 { 1048 void CPDF_StreamContentParser::Handle_SetColor_Stroke() {
885 m_pCurStates->m_GraphState.GetModify()->m_LineCap = (CFX_GraphStateData::Lin eCap)GetInteger(0); 1049 if (m_Options.m_bTextOnly) {
886 } 1050 return;
887 void CPDF_StreamContentParser::Handle_SetCMYKColor_Fill() 1051 }
888 { 1052 FX_FLOAT values[4];
889 REQUIRE_PARAMS(4); 1053 int nargs = m_ParamCount;
890 FX_FLOAT values[4]; 1054 if (nargs > 4) {
891 for (int i = 0; i < 4; i ++) { 1055 nargs = 4;
892 values[i] = GetNumber(3 - i); 1056 }
893 } 1057 for (int i = 0; i < nargs; i++) {
894 CPDF_ColorSpace* pCS = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICECMYK); 1058 values[i] = GetNumber(nargs - i - 1);
895 m_pCurStates->m_ColorState.SetFillColor(pCS, values, 4); 1059 }
896 } 1060 m_pCurStates->m_ColorState.SetStrokeColor(NULL, values, nargs);
897 void CPDF_StreamContentParser::Handle_SetCMYKColor_Stroke() 1061 }
898 { 1062 void CPDF_StreamContentParser::Handle_SetColorPS_Fill() {
899 REQUIRE_PARAMS(4); 1063 if (m_Options.m_bTextOnly) {
900 FX_FLOAT values[4]; 1064 return;
901 for (int i = 0; i < 4; i ++) { 1065 }
902 values[i] = GetNumber(3 - i); 1066 CPDF_Object* pLastParam = GetObject(0);
903 } 1067 if (pLastParam == NULL) {
904 CPDF_ColorSpace* pCS = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICECMYK); 1068 return;
905 m_pCurStates->m_ColorState.SetStrokeColor(pCS, values, 4); 1069 }
906 } 1070 int nargs = m_ParamCount;
907 void CPDF_StreamContentParser::Handle_LineTo() 1071 int nvalues = nargs;
908 { 1072 if (pLastParam->GetType() == PDFOBJ_NAME) {
909 REQUIRE_PARAMS(2); 1073 nvalues--;
910 if (m_Options.m_bTextOnly) { 1074 }
911 return; 1075 FX_FLOAT* values = NULL;
912 } 1076 if (nvalues) {
913 AddPathPoint(GetNumber(1), GetNumber(0), FXPT_LINETO); 1077 values = FX_Alloc(FX_FLOAT, nvalues);
914 } 1078 for (int i = 0; i < nvalues; i++) {
915 void CPDF_StreamContentParser::Handle_MoveTo() 1079 values[i] = GetNumber(nargs - i - 1);
916 { 1080 }
917 REQUIRE_PARAMS(2); 1081 }
918 if (m_Options.m_bTextOnly) { 1082 if (nvalues != nargs) {
919 m_pSyntax->SkipPathObject(); 1083 CPDF_Pattern* pPattern = FindPattern(GetString(0), FALSE);
920 return; 1084 if (pPattern) {
921 } 1085 m_pCurStates->m_ColorState.SetFillPattern(pPattern, values, nvalues);
922 AddPathPoint(GetNumber(1), GetNumber(0), FXPT_MOVETO); 1086 }
923 ParsePathObject(); 1087 } else {
924 } 1088 m_pCurStates->m_ColorState.SetFillColor(NULL, values, nvalues);
925 void CPDF_StreamContentParser::Handle_SetMiterLimit() 1089 }
926 { 1090 if (values) {
927 m_pCurStates->m_GraphState.GetModify()->m_MiterLimit = GetNumber(0); 1091 FX_Free(values);
928 } 1092 }
929 void CPDF_StreamContentParser::Handle_MarkPlace() 1093 }
930 { 1094 void CPDF_StreamContentParser::Handle_SetColorPS_Stroke() {
931 } 1095 if (m_Options.m_bTextOnly) {
932 void CPDF_StreamContentParser::Handle_EndPath() 1096 return;
933 { 1097 }
934 if (m_Options.m_bTextOnly) { 1098 CPDF_Object* pLastParam = GetObject(0);
935 return; 1099 if (pLastParam == NULL) {
936 } 1100 return;
937 AddPathObject(0, FALSE); 1101 }
938 } 1102 int nargs = m_ParamCount;
939 void CPDF_StreamContentParser::Handle_SaveGraphState() 1103 int nvalues = nargs;
940 { 1104 if (pLastParam->GetType() == PDFOBJ_NAME) {
941 CPDF_AllStates* pStates = new CPDF_AllStates; 1105 nvalues--;
942 pStates->Copy(*m_pCurStates); 1106 }
943 m_StateStack.Add(pStates); 1107 FX_FLOAT* values = NULL;
944 } 1108 if (nvalues) {
945 void CPDF_StreamContentParser::Handle_RestoreGraphState() 1109 values = FX_Alloc(FX_FLOAT, nvalues);
946 { 1110 for (int i = 0; i < nvalues; i++) {
947 int size = m_StateStack.GetSize(); 1111 values[i] = GetNumber(nargs - i - 1);
948 if (size == 0) { 1112 }
949 return; 1113 }
950 } 1114 if (nvalues != nargs) {
951 CPDF_AllStates* pStates = (CPDF_AllStates*)m_StateStack.GetAt(size - 1); 1115 CPDF_Pattern* pPattern = FindPattern(GetString(0), FALSE);
952 m_pCurStates->Copy(*pStates); 1116 if (pPattern) {
953 delete pStates; 1117 m_pCurStates->m_ColorState.SetStrokePattern(pPattern, values, nvalues);
954 m_StateStack.RemoveAt(size - 1); 1118 }
955 } 1119 } else {
956 void CPDF_StreamContentParser::Handle_Rectangle() 1120 m_pCurStates->m_ColorState.SetStrokeColor(NULL, values, nvalues);
957 { 1121 }
958 if (m_Options.m_bTextOnly) { 1122 if (values) {
959 return; 1123 FX_Free(values);
960 } 1124 }
961 FX_FLOAT x = GetNumber(3), y = GetNumber(2); 1125 }
962 FX_FLOAT w = GetNumber(1), h = GetNumber(0); 1126 CFX_FloatRect _GetShadingBBox(CPDF_Stream* pStream,
963 AddPathRect(x, y, w, h); 1127 int type,
964 } 1128 const CFX_AffineMatrix* pMatrix,
965 void CPDF_StreamContentParser::AddPathRect(FX_FLOAT x, FX_FLOAT y, FX_FLOAT w, F X_FLOAT h) 1129 CPDF_Function** pFuncs,
966 { 1130 int nFuncs,
967 AddPathPoint(x, y, FXPT_MOVETO); 1131 CPDF_ColorSpace* pCS);
968 AddPathPoint(x + w, y, FXPT_LINETO); 1132 void CPDF_StreamContentParser::Handle_ShadeFill() {
969 AddPathPoint(x + w, y + h, FXPT_LINETO); 1133 if (m_Options.m_bTextOnly) {
970 AddPathPoint(x, y + h, FXPT_LINETO); 1134 return;
971 AddPathPoint(x, y, FXPT_LINETO | FXPT_CLOSEFIGURE); 1135 }
972 } 1136 CPDF_Pattern* pPattern = FindPattern(GetString(0), TRUE);
973 void CPDF_StreamContentParser::Handle_SetRGBColor_Fill() 1137 if (pPattern == NULL) {
974 { 1138 return;
975 REQUIRE_PARAMS(3); 1139 }
976 FX_FLOAT values[3]; 1140 if (pPattern->m_PatternType != PATTERN_SHADING) {
977 for (int i = 0; i < 3; i ++) { 1141 return;
978 values[i] = GetNumber(2 - i); 1142 }
979 } 1143 CPDF_ShadingPattern* pShading = (CPDF_ShadingPattern*)pPattern;
980 CPDF_ColorSpace* pCS = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB); 1144 if (!pShading->m_bShadingObj) {
981 m_pCurStates->m_ColorState.SetFillColor(pCS, values, 3); 1145 return;
982 } 1146 }
983 void CPDF_StreamContentParser::Handle_SetRGBColor_Stroke() 1147 if (!pShading->Load()) {
984 { 1148 return;
985 REQUIRE_PARAMS(3); 1149 }
986 FX_FLOAT values[3]; 1150 CPDF_ShadingObject* pObj = new CPDF_ShadingObject;
987 for (int i = 0; i < 3; i ++) { 1151 pObj->m_pShading = pShading;
988 values[i] = GetNumber(2 - i); 1152 SetGraphicStates(pObj, FALSE, FALSE, FALSE);
989 } 1153 pObj->m_Matrix = m_pCurStates->m_CTM;
990 CPDF_ColorSpace* pCS = CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB); 1154 pObj->m_Matrix.Concat(m_mtContentToUser);
991 m_pCurStates->m_ColorState.SetStrokeColor(pCS, values, 3); 1155 CFX_FloatRect bbox;
992 } 1156 if (!pObj->m_ClipPath.IsNull()) {
993 void CPDF_StreamContentParser::Handle_SetRenderIntent() 1157 bbox = pObj->m_ClipPath.GetClipBox();
994 { 1158 } else {
995 } 1159 bbox = m_BBox;
996 void CPDF_StreamContentParser::Handle_CloseStrokePath() 1160 }
997 { 1161 if (pShading->m_ShadingType >= 4) {
998 if (m_Options.m_bTextOnly) { 1162 bbox.Intersect(_GetShadingBBox((CPDF_Stream*)pShading->m_pShadingObj,
999 return; 1163 pShading->m_ShadingType, &pObj->m_Matrix,
1000 } 1164 pShading->m_pFunctions, pShading->m_nFuncs,
1001 Handle_ClosePath(); 1165 pShading->m_pCS));
1002 AddPathObject(0, TRUE); 1166 }
1003 } 1167 pObj->m_Left = bbox.left;
1004 void CPDF_StreamContentParser::Handle_StrokePath() 1168 pObj->m_Right = bbox.right;
1005 { 1169 pObj->m_Top = bbox.top;
1006 if (m_Options.m_bTextOnly) { 1170 pObj->m_Bottom = bbox.bottom;
1007 return; 1171 m_pObjectList->m_ObjectList.AddTail(pObj);
1008 } 1172 }
1009 AddPathObject(0, TRUE); 1173 void CPDF_StreamContentParser::Handle_SetCharSpace() {
1010 } 1174 m_pCurStates->m_TextState.GetModify()->m_CharSpace = GetNumber(0);
1011 void CPDF_StreamContentParser::Handle_SetColor_Fill() 1175 }
1012 { 1176 void CPDF_StreamContentParser::Handle_MoveTextPoint() {
1013 if (m_Options.m_bTextOnly) { 1177 m_pCurStates->m_TextLineX += GetNumber(1);
1014 return; 1178 m_pCurStates->m_TextLineY += GetNumber(0);
1015 } 1179 m_pCurStates->m_TextX = m_pCurStates->m_TextLineX;
1016 FX_FLOAT values[4]; 1180 m_pCurStates->m_TextY = m_pCurStates->m_TextLineY;
1017 int nargs = m_ParamCount; 1181 }
1018 if (nargs > 4) { 1182 void CPDF_StreamContentParser::Handle_MoveTextPoint_SetLeading() {
1019 nargs = 4; 1183 Handle_MoveTextPoint();
1020 } 1184 m_pCurStates->m_TextLeading = -GetNumber(0);
1021 for (int i = 0; i < nargs; i ++) { 1185 }
1022 values[i] = GetNumber(nargs - i - 1); 1186 void CPDF_StreamContentParser::Handle_SetFont() {
1023 } 1187 FX_FLOAT fs = GetNumber(0);
1024 m_pCurStates->m_ColorState.SetFillColor(NULL, values, nargs); 1188 if (fs == 0) {
1025 } 1189 fs = m_DefFontSize;
1026 void CPDF_StreamContentParser::Handle_SetColor_Stroke() 1190 }
1027 { 1191 m_pCurStates->m_TextState.GetModify()->m_FontSize = fs;
1028 if (m_Options.m_bTextOnly) { 1192 CPDF_Font* pFont = FindFont(GetString(1));
1029 return; 1193 if (pFont) {
1030 } 1194 m_pCurStates->m_TextState.SetFont(pFont);
1031 FX_FLOAT values[4]; 1195 }
1032 int nargs = m_ParamCount; 1196 }
1033 if (nargs > 4) { 1197 CPDF_Object* CPDF_StreamContentParser::FindResourceObj(
1034 nargs = 4; 1198 const CFX_ByteStringC& type,
1035 } 1199 const CFX_ByteString& name) {
1036 for (int i = 0; i < nargs; i ++) { 1200 if (m_pResources == NULL) {
1037 values[i] = GetNumber(nargs - i - 1); 1201 return NULL;
1038 } 1202 }
1039 m_pCurStates->m_ColorState.SetStrokeColor(NULL, values, nargs); 1203 if (m_pResources == m_pPageResources) {
1040 }
1041 void CPDF_StreamContentParser::Handle_SetColorPS_Fill()
1042 {
1043 if (m_Options.m_bTextOnly) {
1044 return;
1045 }
1046 CPDF_Object* pLastParam = GetObject(0);
1047 if (pLastParam == NULL) {
1048 return;
1049 }
1050 int nargs = m_ParamCount;
1051 int nvalues = nargs;
1052 if (pLastParam->GetType() == PDFOBJ_NAME) {
1053 nvalues --;
1054 }
1055 FX_FLOAT* values = NULL;
1056 if (nvalues) {
1057 values = FX_Alloc(FX_FLOAT, nvalues);
1058 for (int i = 0; i < nvalues; i ++) {
1059 values[i] = GetNumber(nargs - i - 1);
1060 }
1061 }
1062 if (nvalues != nargs) {
1063 CPDF_Pattern* pPattern = FindPattern(GetString(0), FALSE);
1064 if (pPattern) {
1065 m_pCurStates->m_ColorState.SetFillPattern(pPattern, values, nvalues) ;
1066 }
1067 } else {
1068 m_pCurStates->m_ColorState.SetFillColor(NULL, values, nvalues);
1069 }
1070 if (values) {
1071 FX_Free(values);
1072 }
1073 }
1074 void CPDF_StreamContentParser::Handle_SetColorPS_Stroke()
1075 {
1076 if (m_Options.m_bTextOnly) {
1077 return;
1078 }
1079 CPDF_Object* pLastParam = GetObject(0);
1080 if (pLastParam == NULL) {
1081 return;
1082 }
1083 int nargs = m_ParamCount;
1084 int nvalues = nargs;
1085 if (pLastParam->GetType() == PDFOBJ_NAME) {
1086 nvalues --;
1087 }
1088 FX_FLOAT* values = NULL;
1089 if (nvalues) {
1090 values = FX_Alloc(FX_FLOAT, nvalues);
1091 for (int i = 0; i < nvalues; i ++) {
1092 values[i] = GetNumber(nargs - i - 1);
1093 }
1094 }
1095 if (nvalues != nargs) {
1096 CPDF_Pattern* pPattern = FindPattern(GetString(0), FALSE);
1097 if (pPattern) {
1098 m_pCurStates->m_ColorState.SetStrokePattern(pPattern, values, nvalue s);
1099 }
1100 } else {
1101 m_pCurStates->m_ColorState.SetStrokeColor(NULL, values, nvalues);
1102 }
1103 if (values) {
1104 FX_Free(values);
1105 }
1106 }
1107 CFX_FloatRect _GetShadingBBox(CPDF_Stream* pStream, int type, const CFX_AffineMa trix* pMatrix,
1108 CPDF_Function** pFuncs, int nFuncs, CPDF_ColorSpac e* pCS);
1109 void CPDF_StreamContentParser::Handle_ShadeFill()
1110 {
1111 if (m_Options.m_bTextOnly) {
1112 return;
1113 }
1114 CPDF_Pattern* pPattern = FindPattern(GetString(0), TRUE);
1115 if (pPattern == NULL) {
1116 return;
1117 }
1118 if (pPattern->m_PatternType != PATTERN_SHADING) {
1119 return;
1120 }
1121 CPDF_ShadingPattern* pShading = (CPDF_ShadingPattern*)pPattern;
1122 if (!pShading->m_bShadingObj) {
1123 return;
1124 }
1125 if (!pShading->Load()) {
1126 return;
1127 }
1128 CPDF_ShadingObject* pObj = new CPDF_ShadingObject;
1129 pObj->m_pShading = pShading;
1130 SetGraphicStates(pObj, FALSE, FALSE, FALSE);
1131 pObj->m_Matrix = m_pCurStates->m_CTM;
1132 pObj->m_Matrix.Concat(m_mtContentToUser);
1133 CFX_FloatRect bbox;
1134 if (!pObj->m_ClipPath.IsNull()) {
1135 bbox = pObj->m_ClipPath.GetClipBox();
1136 } else {
1137 bbox = m_BBox;
1138 }
1139 if (pShading->m_ShadingType >= 4) {
1140 bbox.Intersect(_GetShadingBBox((CPDF_Stream*)pShading->m_pShadingObj, pS hading->m_ShadingType, &pObj->m_Matrix,
1141 pShading->m_pFunctions, pShading->m_nFunc s, pShading->m_pCS));
1142 }
1143 pObj->m_Left = bbox.left;
1144 pObj->m_Right = bbox.right;
1145 pObj->m_Top = bbox.top;
1146 pObj->m_Bottom = bbox.bottom;
1147 m_pObjectList->m_ObjectList.AddTail(pObj);
1148 }
1149 void CPDF_StreamContentParser::Handle_SetCharSpace()
1150 {
1151 m_pCurStates->m_TextState.GetModify()->m_CharSpace = GetNumber(0);
1152 }
1153 void CPDF_StreamContentParser::Handle_MoveTextPoint()
1154 {
1155 m_pCurStates->m_TextLineX += GetNumber(1);
1156 m_pCurStates->m_TextLineY += GetNumber(0);
1157 m_pCurStates->m_TextX = m_pCurStates->m_TextLineX;
1158 m_pCurStates->m_TextY = m_pCurStates->m_TextLineY;
1159 }
1160 void CPDF_StreamContentParser::Handle_MoveTextPoint_SetLeading()
1161 {
1162 Handle_MoveTextPoint();
1163 m_pCurStates->m_TextLeading = -GetNumber(0);
1164 }
1165 void CPDF_StreamContentParser::Handle_SetFont()
1166 {
1167 FX_FLOAT fs = GetNumber(0);
1168 if (fs == 0) {
1169 fs = m_DefFontSize;
1170 }
1171 m_pCurStates->m_TextState.GetModify()->m_FontSize = fs;
1172 CPDF_Font* pFont = FindFont(GetString(1));
1173 if (pFont) {
1174 m_pCurStates->m_TextState.SetFont(pFont);
1175 }
1176 }
1177 CPDF_Object* CPDF_StreamContentParser::FindResourceObj(const CFX_ByteStringC& ty pe, const CFX_ByteString& name)
1178 {
1179 if (m_pResources == NULL) {
1180 return NULL;
1181 }
1182 if (m_pResources == m_pPageResources) {
1183 CPDF_Dictionary* pList = m_pResources->GetDict(type);
1184 if (pList == NULL) {
1185 return NULL;
1186 }
1187 CPDF_Object* pRes = pList->GetElementValue(name);
1188 return pRes;
1189 }
1190 CPDF_Dictionary* pList = m_pResources->GetDict(type); 1204 CPDF_Dictionary* pList = m_pResources->GetDict(type);
1191 if (pList == NULL) { 1205 if (pList == NULL) {
1192 if (m_pPageResources == NULL) { 1206 return NULL;
1193 return NULL;
1194 }
1195 CPDF_Dictionary* pList = m_pPageResources->GetDict(type);
1196 if (pList == NULL) {
1197 return NULL;
1198 }
1199 CPDF_Object* pRes = pList->GetElementValue(name);
1200 return pRes;
1201 } 1207 }
1202 CPDF_Object* pRes = pList->GetElementValue(name); 1208 CPDF_Object* pRes = pList->GetElementValue(name);
1203 return pRes; 1209 return pRes;
1204 } 1210 }
1205 CPDF_Font* CPDF_StreamContentParser::FindFont(const CFX_ByteString& name) 1211 CPDF_Dictionary* pList = m_pResources->GetDict(type);
1206 { 1212 if (pList == NULL) {
1207 CPDF_Dictionary* pFontDict = (CPDF_Dictionary*)FindResourceObj(FX_BSTRC("Fon t"), name); 1213 if (m_pPageResources == NULL) {
1208 if (pFontDict == NULL || pFontDict->GetType() != PDFOBJ_DICTIONARY) { 1214 return NULL;
1209 m_bResourceMissing = TRUE; 1215 }
1210 return CPDF_Font::GetStockFont(m_pDocument, FX_BSTRC("Helvetica")); 1216 CPDF_Dictionary* pList = m_pPageResources->GetDict(type);
1211 } 1217 if (pList == NULL) {
1212 CPDF_Font* pFont = m_pDocument->LoadFont(pFontDict); 1218 return NULL;
1213 if (pFont && pFont->GetType3Font()) { 1219 }
1214 pFont->GetType3Font()->SetPageResources(m_pResources); 1220 CPDF_Object* pRes = pList->GetElementValue(name);
1215 pFont->GetType3Font()->CheckType3FontMetrics(); 1221 return pRes;
1216 } 1222 }
1217 return pFont; 1223 CPDF_Object* pRes = pList->GetElementValue(name);
1218 } 1224 return pRes;
1219 CPDF_ColorSpace* CPDF_StreamContentParser::FindColorSpace(const CFX_ByteString& name) 1225 }
1220 { 1226 CPDF_Font* CPDF_StreamContentParser::FindFont(const CFX_ByteString& name) {
1221 if (name == FX_BSTRC("Pattern")) { 1227 CPDF_Dictionary* pFontDict =
1222 return CPDF_ColorSpace::GetStockCS(PDFCS_PATTERN); 1228 (CPDF_Dictionary*)FindResourceObj(FX_BSTRC("Font"), name);
1223 } 1229 if (pFontDict == NULL || pFontDict->GetType() != PDFOBJ_DICTIONARY) {
1224 if (name == FX_BSTRC("DeviceGray") || name == FX_BSTRC("DeviceCMYK") || name == FX_BSTRC("DeviceRGB")) { 1230 m_bResourceMissing = TRUE;
1225 CFX_ByteString defname = "Default"; 1231 return CPDF_Font::GetStockFont(m_pDocument, FX_BSTRC("Helvetica"));
1226 defname += name.Mid(7); 1232 }
1227 CPDF_Object* pDefObj = FindResourceObj(FX_BSTRC("ColorSpace"), defname); 1233 CPDF_Font* pFont = m_pDocument->LoadFont(pFontDict);
1228 if (pDefObj == NULL) { 1234 if (pFont && pFont->GetType3Font()) {
1229 if (name == FX_BSTRC("DeviceGray")) { 1235 pFont->GetType3Font()->SetPageResources(m_pResources);
1230 return CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY); 1236 pFont->GetType3Font()->CheckType3FontMetrics();
1231 } 1237 }
1232 if (name == FX_BSTRC("DeviceRGB")) { 1238 return pFont;
1233 return CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB); 1239 }
1234 } 1240 CPDF_ColorSpace* CPDF_StreamContentParser::FindColorSpace(
1235 return CPDF_ColorSpace::GetStockCS(PDFCS_DEVICECMYK); 1241 const CFX_ByteString& name) {
1236 } 1242 if (name == FX_BSTRC("Pattern")) {
1237 return m_pDocument->LoadColorSpace(pDefObj); 1243 return CPDF_ColorSpace::GetStockCS(PDFCS_PATTERN);
1238 } 1244 }
1239 CPDF_Object* pCSObj = FindResourceObj(FX_BSTRC("ColorSpace"), name); 1245 if (name == FX_BSTRC("DeviceGray") || name == FX_BSTRC("DeviceCMYK") ||
1240 if (pCSObj == NULL) { 1246 name == FX_BSTRC("DeviceRGB")) {
1241 m_bResourceMissing = TRUE; 1247 CFX_ByteString defname = "Default";
1242 return NULL; 1248 defname += name.Mid(7);
1243 } 1249 CPDF_Object* pDefObj = FindResourceObj(FX_BSTRC("ColorSpace"), defname);
1244 return m_pDocument->LoadColorSpace(pCSObj); 1250 if (pDefObj == NULL) {
1245 } 1251 if (name == FX_BSTRC("DeviceGray")) {
1246 CPDF_Pattern* CPDF_StreamContentParser::FindPattern(const CFX_ByteString& name, FX_BOOL bShading) 1252 return CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY);
1247 { 1253 }
1248 CPDF_Object* pPattern = FindResourceObj(bShading ? FX_BSTRC("Shading") : FX_ BSTRC("Pattern"), name); 1254 if (name == FX_BSTRC("DeviceRGB")) {
1249 if (pPattern == NULL || (pPattern->GetType() != PDFOBJ_DICTIONARY && 1255 return CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB);
1250 pPattern->GetType() != PDFOBJ_STREAM)) { 1256 }
1251 m_bResourceMissing = TRUE; 1257 return CPDF_ColorSpace::GetStockCS(PDFCS_DEVICECMYK);
1252 return NULL; 1258 }
1253 } 1259 return m_pDocument->LoadColorSpace(pDefObj);
1254 return m_pDocument->LoadPattern(pPattern, bShading, &m_pCurStates->m_ParentM atrix); 1260 }
1255 } 1261 CPDF_Object* pCSObj = FindResourceObj(FX_BSTRC("ColorSpace"), name);
1256 void CPDF_StreamContentParser::ConvertTextSpace(FX_FLOAT& x, FX_FLOAT& y) 1262 if (pCSObj == NULL) {
1257 { 1263 m_bResourceMissing = TRUE;
1258 m_pCurStates->m_TextMatrix.Transform(x, y, x, y); 1264 return NULL;
1259 ConvertUserSpace(x, y); 1265 }
1260 } 1266 return m_pDocument->LoadColorSpace(pCSObj);
1261 void CPDF_StreamContentParser::ConvertUserSpace(FX_FLOAT& x, FX_FLOAT& y) 1267 }
1262 { 1268 CPDF_Pattern* CPDF_StreamContentParser::FindPattern(const CFX_ByteString& name,
1263 m_pCurStates->m_CTM.Transform(x, y, x, y); 1269 FX_BOOL bShading) {
1264 m_mtContentToUser.Transform(x, y, x, y); 1270 CPDF_Object* pPattern = FindResourceObj(
1265 } 1271 bShading ? FX_BSTRC("Shading") : FX_BSTRC("Pattern"), name);
1266 void CPDF_StreamContentParser::AddTextObject(CFX_ByteString* pStrs, FX_FLOAT fIn itKerning, FX_FLOAT* pKerning, int nsegs) 1272 if (pPattern == NULL || (pPattern->GetType() != PDFOBJ_DICTIONARY &&
1267 { 1273 pPattern->GetType() != PDFOBJ_STREAM)) {
1268 CPDF_Font* pFont = m_pCurStates->m_TextState.GetFont(); 1274 m_bResourceMissing = TRUE;
1269 if (pFont == NULL) { 1275 return NULL;
1270 return; 1276 }
1271 } 1277 return m_pDocument->LoadPattern(pPattern, bShading,
1272 if (fInitKerning != 0) { 1278 &m_pCurStates->m_ParentMatrix);
1273 if (!pFont->IsVertWriting()) { 1279 }
1274 m_pCurStates->m_TextX -= FXSYS_Mul(fInitKerning, m_pCurStates->m_Tex tState.GetFontSize()) / 1000; 1280 void CPDF_StreamContentParser::ConvertTextSpace(FX_FLOAT& x, FX_FLOAT& y) {
1275 } else { 1281 m_pCurStates->m_TextMatrix.Transform(x, y, x, y);
1276 m_pCurStates->m_TextY -= FXSYS_Mul(fInitKerning, m_pCurStates->m_Tex tState.GetFontSize()) / 1000; 1282 ConvertUserSpace(x, y);
1277 } 1283 }
1278 } 1284 void CPDF_StreamContentParser::ConvertUserSpace(FX_FLOAT& x, FX_FLOAT& y) {
1279 if (nsegs == 0) { 1285 m_pCurStates->m_CTM.Transform(x, y, x, y);
1280 return; 1286 m_mtContentToUser.Transform(x, y, x, y);
1281 } 1287 }
1282 int textmode; 1288 void CPDF_StreamContentParser::AddTextObject(CFX_ByteString* pStrs,
1283 if (pFont->GetFontType() == PDFFONT_TYPE3) { 1289 FX_FLOAT fInitKerning,
1284 textmode = 0; 1290 FX_FLOAT* pKerning,
1291 int nsegs) {
1292 CPDF_Font* pFont = m_pCurStates->m_TextState.GetFont();
1293 if (pFont == NULL) {
1294 return;
1295 }
1296 if (fInitKerning != 0) {
1297 if (!pFont->IsVertWriting()) {
1298 m_pCurStates->m_TextX -=
1299 FXSYS_Mul(fInitKerning, m_pCurStates->m_TextState.GetFontSize()) /
1300 1000;
1285 } else { 1301 } else {
1286 textmode = m_pCurStates->m_TextState.GetObject()->m_TextMode; 1302 m_pCurStates->m_TextY -=
1287 } 1303 FXSYS_Mul(fInitKerning, m_pCurStates->m_TextState.GetFontSize()) /
1288 CPDF_TextObject* pText = new CPDF_TextObject; 1304 1000;
1289 m_pLastTextObject = pText; 1305 }
1290 SetGraphicStates(pText, TRUE, TRUE, TRUE); 1306 }
1291 if (textmode && textmode != 3 && textmode != 4 && textmode != 7) { 1307 if (nsegs == 0) {
1292 FX_FLOAT* pCTM = pText->m_TextState.GetModify()->m_CTM; 1308 return;
1293 pCTM[0] = m_pCurStates->m_CTM.a; 1309 }
1294 pCTM[1] = m_pCurStates->m_CTM.c; 1310 int textmode;
1295 pCTM[2] = m_pCurStates->m_CTM.b; 1311 if (pFont->GetFontType() == PDFFONT_TYPE3) {
1296 pCTM[3] = m_pCurStates->m_CTM.d; 1312 textmode = 0;
1297 } 1313 } else {
1298 pText->SetSegments(pStrs, pKerning, nsegs); 1314 textmode = m_pCurStates->m_TextState.GetObject()->m_TextMode;
1299 pText->m_PosX = m_pCurStates->m_TextX; 1315 }
1300 pText->m_PosY = m_pCurStates->m_TextY + m_pCurStates->m_TextRise; 1316 CPDF_TextObject* pText = new CPDF_TextObject;
1301 ConvertTextSpace(pText->m_PosX, pText->m_PosY); 1317 m_pLastTextObject = pText;
1302 FX_FLOAT x_advance, y_advance; 1318 SetGraphicStates(pText, TRUE, TRUE, TRUE);
1303 pText->CalcPositionData(&x_advance, &y_advance, m_pCurStates->m_TextHorzScal e, m_Level); 1319 if (textmode && textmode != 3 && textmode != 4 && textmode != 7) {
1304 m_pCurStates->m_TextX += x_advance; 1320 FX_FLOAT* pCTM = pText->m_TextState.GetModify()->m_CTM;
1305 m_pCurStates->m_TextY += y_advance; 1321 pCTM[0] = m_pCurStates->m_CTM.a;
1306 if (textmode > 3) { 1322 pCTM[1] = m_pCurStates->m_CTM.c;
1307 CPDF_TextObject* pCopy = new CPDF_TextObject; 1323 pCTM[2] = m_pCurStates->m_CTM.b;
1308 pCopy->Copy(pText); 1324 pCTM[3] = m_pCurStates->m_CTM.d;
1309 m_ClipTextList.Add(pCopy); 1325 }
1310 } 1326 pText->SetSegments(pStrs, pKerning, nsegs);
1311 m_pObjectList->m_ObjectList.AddTail(pText); 1327 pText->m_PosX = m_pCurStates->m_TextX;
1312 if (pKerning && pKerning[nsegs - 1] != 0) { 1328 pText->m_PosY = m_pCurStates->m_TextY + m_pCurStates->m_TextRise;
1313 if (!pFont->IsVertWriting()) { 1329 ConvertTextSpace(pText->m_PosX, pText->m_PosY);
1314 m_pCurStates->m_TextX -= FXSYS_Mul(pKerning[nsegs - 1], m_pCurStates ->m_TextState.GetFontSize()) / 1000; 1330 FX_FLOAT x_advance, y_advance;
1315 } else { 1331 pText->CalcPositionData(&x_advance, &y_advance, m_pCurStates->m_TextHorzScale,
1316 m_pCurStates->m_TextY -= FXSYS_Mul(pKerning[nsegs - 1], m_pCurStates ->m_TextState.GetFontSize()) / 1000; 1332 m_Level);
1317 } 1333 m_pCurStates->m_TextX += x_advance;
1318 } 1334 m_pCurStates->m_TextY += y_advance;
1319 } 1335 if (textmode > 3) {
1320 void CPDF_StreamContentParser::Handle_ShowText() 1336 CPDF_TextObject* pCopy = new CPDF_TextObject;
1321 { 1337 pCopy->Copy(pText);
1322 CFX_ByteString str = GetString(0); 1338 m_ClipTextList.Add(pCopy);
1323 if (str.IsEmpty()) { 1339 }
1324 return; 1340 m_pObjectList->m_ObjectList.AddTail(pText);
1325 } 1341 if (pKerning && pKerning[nsegs - 1] != 0) {
1326 AddTextObject(&str, 0, NULL, 1); 1342 if (!pFont->IsVertWriting()) {
1327 } 1343 m_pCurStates->m_TextX -=
1328 void CPDF_StreamContentParser::Handle_ShowText_Positioning() 1344 FXSYS_Mul(pKerning[nsegs - 1],
1329 { 1345 m_pCurStates->m_TextState.GetFontSize()) /
1330 CPDF_Array* pArray = GetObject(0) ? GetObject(0)->GetArray() : NULL; 1346 1000;
1331 if (pArray == NULL) { 1347 } else {
1332 return; 1348 m_pCurStates->m_TextY -=
1333 } 1349 FXSYS_Mul(pKerning[nsegs - 1],
1334 int n = pArray->GetCount(), nsegs = 0, i; 1350 m_pCurStates->m_TextState.GetFontSize()) /
1335 for (i = 0; i < n; i ++) { 1351 1000;
1336 CPDF_Object* pObj = pArray->GetElementValue(i); 1352 }
1337 if (pObj->GetType() == PDFOBJ_STRING) { 1353 }
1338 nsegs ++; 1354 }
1339 } 1355 void CPDF_StreamContentParser::Handle_ShowText() {
1340 } 1356 CFX_ByteString str = GetString(0);
1341 if (nsegs == 0) { 1357 if (str.IsEmpty()) {
1342 for (i = 0; i < n; i ++) { 1358 return;
1343 m_pCurStates->m_TextX -= FXSYS_Mul(pArray->GetNumber(i), m_pCurState s->m_TextState.GetFontSize()) / 1000; 1359 }
1344 }; 1360 AddTextObject(&str, 0, NULL, 1);
1345 return; 1361 }
1346 } 1362 void CPDF_StreamContentParser::Handle_ShowText_Positioning() {
1347 CFX_ByteString* pStrs = new CFX_ByteString[nsegs]; 1363 CPDF_Array* pArray = GetObject(0) ? GetObject(0)->GetArray() : NULL;
1348 FX_FLOAT* pKerning = FX_Alloc(FX_FLOAT, nsegs); 1364 if (pArray == NULL) {
1349 int iSegment = 0; 1365 return;
1350 FX_FLOAT fInitKerning = 0; 1366 }
1351 for (i = 0; i < n; i ++) { 1367 int n = pArray->GetCount(), nsegs = 0, i;
1352 CPDF_Object* pObj = pArray->GetElementValue(i); 1368 for (i = 0; i < n; i++) {
1353 if (pObj->GetType() == PDFOBJ_STRING) { 1369 CPDF_Object* pObj = pArray->GetElementValue(i);
1354 CFX_ByteString str = pObj->GetString(); 1370 if (pObj->GetType() == PDFOBJ_STRING) {
1355 if (str.IsEmpty()) { 1371 nsegs++;
1356 continue; 1372 }
1357 } 1373 }
1358 pStrs[iSegment] = str; 1374 if (nsegs == 0) {
1359 pKerning[iSegment ++] = 0; 1375 for (i = 0; i < n; i++) {
1360 } else { 1376 m_pCurStates->m_TextX -=
1361 FX_FLOAT num = pObj ? pObj->GetNumber() : 0; 1377 FXSYS_Mul(pArray->GetNumber(i),
1362 if (iSegment == 0) { 1378 m_pCurStates->m_TextState.GetFontSize()) /
1363 fInitKerning += num; 1379 1000;
1364 } else { 1380 };
1365 pKerning[iSegment - 1] += num; 1381 return;
1366 } 1382 }
1367 } 1383 CFX_ByteString* pStrs = new CFX_ByteString[nsegs];
1368 } 1384 FX_FLOAT* pKerning = FX_Alloc(FX_FLOAT, nsegs);
1369 AddTextObject(pStrs, fInitKerning, pKerning, iSegment); 1385 int iSegment = 0;
1370 delete[] pStrs; 1386 FX_FLOAT fInitKerning = 0;
1371 FX_Free(pKerning); 1387 for (i = 0; i < n; i++) {
1372 } 1388 CPDF_Object* pObj = pArray->GetElementValue(i);
1373 void CPDF_StreamContentParser::Handle_SetTextLeading() 1389 if (pObj->GetType() == PDFOBJ_STRING) {
1374 { 1390 CFX_ByteString str = pObj->GetString();
1375 m_pCurStates->m_TextLeading = GetNumber(0); 1391 if (str.IsEmpty()) {
1376 } 1392 continue;
1377 void CPDF_StreamContentParser::Handle_SetTextMatrix() 1393 }
1378 { 1394 pStrs[iSegment] = str;
1379 m_pCurStates->m_TextMatrix.Set(GetNumber16(5), GetNumber16(4), GetNumber16(3 ), 1395 pKerning[iSegment++] = 0;
1380 GetNumber16(2), GetNumber(1), GetNumber(0)); 1396 } else {
1381 OnChangeTextMatrix(); 1397 FX_FLOAT num = pObj ? pObj->GetNumber() : 0;
1382 m_pCurStates->m_TextX = 0; 1398 if (iSegment == 0) {
1383 m_pCurStates->m_TextY = 0; 1399 fInitKerning += num;
1384 m_pCurStates->m_TextLineX = 0; 1400 } else {
1385 m_pCurStates->m_TextLineY = 0; 1401 pKerning[iSegment - 1] += num;
1386 } 1402 }
1387 void CPDF_StreamContentParser::OnChangeTextMatrix() 1403 }
1388 { 1404 }
1389 CFX_AffineMatrix text_matrix(m_pCurStates->m_TextHorzScale, 0.0f, 0.0f, 1.0f , 0.0f, 0.0f); 1405 AddTextObject(pStrs, fInitKerning, pKerning, iSegment);
1390 text_matrix.Concat(m_pCurStates->m_TextMatrix); 1406 delete[] pStrs;
1391 text_matrix.Concat(m_pCurStates->m_CTM); 1407 FX_Free(pKerning);
1392 text_matrix.Concat(m_mtContentToUser); 1408 }
1393 FX_FLOAT* pTextMatrix = m_pCurStates->m_TextState.GetModify()->m_Matrix; 1409 void CPDF_StreamContentParser::Handle_SetTextLeading() {
1394 pTextMatrix[0] = text_matrix.a; 1410 m_pCurStates->m_TextLeading = GetNumber(0);
1395 pTextMatrix[1] = text_matrix.c; 1411 }
1396 pTextMatrix[2] = text_matrix.b; 1412 void CPDF_StreamContentParser::Handle_SetTextMatrix() {
1397 pTextMatrix[3] = text_matrix.d; 1413 m_pCurStates->m_TextMatrix.Set(GetNumber16(5), GetNumber16(4), GetNumber16(3),
1398 } 1414 GetNumber16(2), GetNumber(1), GetNumber(0));
1399 void CPDF_StreamContentParser::Handle_SetTextRenderMode() 1415 OnChangeTextMatrix();
1400 { 1416 m_pCurStates->m_TextX = 0;
1401 int mode = GetInteger(0); 1417 m_pCurStates->m_TextY = 0;
1402 if (mode < 0 || mode > 7) { 1418 m_pCurStates->m_TextLineX = 0;
1403 return; 1419 m_pCurStates->m_TextLineY = 0;
1404 } 1420 }
1405 m_pCurStates->m_TextState.GetModify()->m_TextMode = mode; 1421 void CPDF_StreamContentParser::OnChangeTextMatrix() {
1406 } 1422 CFX_AffineMatrix text_matrix(m_pCurStates->m_TextHorzScale, 0.0f, 0.0f, 1.0f,
1407 void CPDF_StreamContentParser::Handle_SetTextRise() 1423 0.0f, 0.0f);
1408 { 1424 text_matrix.Concat(m_pCurStates->m_TextMatrix);
1409 m_pCurStates->m_TextRise = GetNumber(0); 1425 text_matrix.Concat(m_pCurStates->m_CTM);
1410 } 1426 text_matrix.Concat(m_mtContentToUser);
1411 void CPDF_StreamContentParser::Handle_SetWordSpace() 1427 FX_FLOAT* pTextMatrix = m_pCurStates->m_TextState.GetModify()->m_Matrix;
1412 { 1428 pTextMatrix[0] = text_matrix.a;
1413 m_pCurStates->m_TextState.GetModify()->m_WordSpace = GetNumber(0); 1429 pTextMatrix[1] = text_matrix.c;
1414 } 1430 pTextMatrix[2] = text_matrix.b;
1415 void CPDF_StreamContentParser::Handle_SetHorzScale() 1431 pTextMatrix[3] = text_matrix.d;
1416 { 1432 }
1417 if (m_ParamCount != 1) { 1433 void CPDF_StreamContentParser::Handle_SetTextRenderMode() {
1418 return; 1434 int mode = GetInteger(0);
1419 } 1435 if (mode < 0 || mode > 7) {
1420 m_pCurStates->m_TextHorzScale = GetNumber(0) / 100; 1436 return;
1421 OnChangeTextMatrix(); 1437 }
1422 } 1438 m_pCurStates->m_TextState.GetModify()->m_TextMode = mode;
1423 void CPDF_StreamContentParser::Handle_MoveToNextLine() 1439 }
1424 { 1440 void CPDF_StreamContentParser::Handle_SetTextRise() {
1425 m_pCurStates->m_TextLineY -= m_pCurStates->m_TextLeading; 1441 m_pCurStates->m_TextRise = GetNumber(0);
1426 m_pCurStates->m_TextX = m_pCurStates->m_TextLineX; 1442 }
1427 m_pCurStates->m_TextY = m_pCurStates->m_TextLineY; 1443 void CPDF_StreamContentParser::Handle_SetWordSpace() {
1428 } 1444 m_pCurStates->m_TextState.GetModify()->m_WordSpace = GetNumber(0);
1429 void CPDF_StreamContentParser::Handle_CurveTo_23() 1445 }
1430 { 1446 void CPDF_StreamContentParser::Handle_SetHorzScale() {
1431 if (m_Options.m_bTextOnly) { 1447 if (m_ParamCount != 1) {
1432 return; 1448 return;
1433 } 1449 }
1434 AddPathPoint(m_PathCurrentX, m_PathCurrentY, FXPT_BEZIERTO); 1450 m_pCurStates->m_TextHorzScale = GetNumber(0) / 100;
1435 AddPathPoint(GetNumber(3), GetNumber(2), FXPT_BEZIERTO); 1451 OnChangeTextMatrix();
1436 AddPathPoint(GetNumber(1), GetNumber(0), FXPT_BEZIERTO); 1452 }
1437 } 1453 void CPDF_StreamContentParser::Handle_MoveToNextLine() {
1438 void CPDF_StreamContentParser::Handle_SetLineWidth() 1454 m_pCurStates->m_TextLineY -= m_pCurStates->m_TextLeading;
1439 { 1455 m_pCurStates->m_TextX = m_pCurStates->m_TextLineX;
1440 FX_FLOAT width = GetNumber(0); 1456 m_pCurStates->m_TextY = m_pCurStates->m_TextLineY;
1441 m_pCurStates->m_GraphState.GetModify()->m_LineWidth = width; 1457 }
1442 } 1458 void CPDF_StreamContentParser::Handle_CurveTo_23() {
1443 void CPDF_StreamContentParser::Handle_Clip() 1459 if (m_Options.m_bTextOnly) {
1444 { 1460 return;
1445 m_PathClipType = FXFILL_WINDING; 1461 }
1446 } 1462 AddPathPoint(m_PathCurrentX, m_PathCurrentY, FXPT_BEZIERTO);
1447 void CPDF_StreamContentParser::Handle_EOClip() 1463 AddPathPoint(GetNumber(3), GetNumber(2), FXPT_BEZIERTO);
1448 { 1464 AddPathPoint(GetNumber(1), GetNumber(0), FXPT_BEZIERTO);
1449 m_PathClipType = FXFILL_ALTERNATE; 1465 }
1450 } 1466 void CPDF_StreamContentParser::Handle_SetLineWidth() {
1451 void CPDF_StreamContentParser::Handle_CurveTo_13() 1467 FX_FLOAT width = GetNumber(0);
1452 { 1468 m_pCurStates->m_GraphState.GetModify()->m_LineWidth = width;
1453 if (m_Options.m_bTextOnly) { 1469 }
1454 return; 1470 void CPDF_StreamContentParser::Handle_Clip() {
1455 } 1471 m_PathClipType = FXFILL_WINDING;
1456 AddPathPoint(GetNumber(3), GetNumber(2), FXPT_BEZIERTO); 1472 }
1457 AddPathPoint(GetNumber(1), GetNumber(0), FXPT_BEZIERTO); 1473 void CPDF_StreamContentParser::Handle_EOClip() {
1458 AddPathPoint(GetNumber(1), GetNumber(0), FXPT_BEZIERTO); 1474 m_PathClipType = FXFILL_ALTERNATE;
1459 } 1475 }
1460 void CPDF_StreamContentParser::Handle_NextLineShowText() 1476 void CPDF_StreamContentParser::Handle_CurveTo_13() {
1461 { 1477 if (m_Options.m_bTextOnly) {
1462 Handle_MoveToNextLine(); 1478 return;
1463 Handle_ShowText(); 1479 }
1464 } 1480 AddPathPoint(GetNumber(3), GetNumber(2), FXPT_BEZIERTO);
1465 void CPDF_StreamContentParser::Handle_NextLineShowText_Space() 1481 AddPathPoint(GetNumber(1), GetNumber(0), FXPT_BEZIERTO);
1466 { 1482 AddPathPoint(GetNumber(1), GetNumber(0), FXPT_BEZIERTO);
1467 m_pCurStates->m_TextState.GetModify()->m_WordSpace = GetNumber(2); 1483 }
1468 m_pCurStates->m_TextState.GetModify()->m_CharSpace = GetNumber(1); 1484 void CPDF_StreamContentParser::Handle_NextLineShowText() {
1469 Handle_NextLineShowText(); 1485 Handle_MoveToNextLine();
1470 } 1486 Handle_ShowText();
1471 void CPDF_StreamContentParser::Handle_Invalid() 1487 }
1472 { 1488 void CPDF_StreamContentParser::Handle_NextLineShowText_Space() {
1473 } 1489 m_pCurStates->m_TextState.GetModify()->m_WordSpace = GetNumber(2);
1474 void CPDF_StreamContentParser::AddPathPoint(FX_FLOAT x, FX_FLOAT y, int flag) 1490 m_pCurStates->m_TextState.GetModify()->m_CharSpace = GetNumber(1);
1475 { 1491 Handle_NextLineShowText();
1476 m_PathCurrentX = x; 1492 }
1477 m_PathCurrentY = y; 1493 void CPDF_StreamContentParser::Handle_Invalid() {}
1478 if (flag == FXPT_MOVETO) { 1494 void CPDF_StreamContentParser::AddPathPoint(FX_FLOAT x, FX_FLOAT y, int flag) {
1479 m_PathStartX = x; 1495 m_PathCurrentX = x;
1480 m_PathStartY = y; 1496 m_PathCurrentY = y;
1481 if (m_PathPointCount && m_pPathPoints[m_PathPointCount - 1].m_Flag == FX PT_MOVETO) { 1497 if (flag == FXPT_MOVETO) {
1482 m_pPathPoints[m_PathPointCount - 1].m_PointX = x; 1498 m_PathStartX = x;
1483 m_pPathPoints[m_PathPointCount - 1].m_PointY = y; 1499 m_PathStartY = y;
1484 return; 1500 if (m_PathPointCount &&
1485 } 1501 m_pPathPoints[m_PathPointCount - 1].m_Flag == FXPT_MOVETO) {
1486 } else if (m_PathPointCount == 0) { 1502 m_pPathPoints[m_PathPointCount - 1].m_PointX = x;
1487 return; 1503 m_pPathPoints[m_PathPointCount - 1].m_PointY = y;
1488 } 1504 return;
1489 m_PathPointCount ++; 1505 }
1490 if (m_PathPointCount > m_PathAllocSize) { 1506 } else if (m_PathPointCount == 0) {
1491 int newsize = m_PathPointCount + 256; 1507 return;
1492 FX_PATHPOINT* pNewPoints = FX_Alloc(FX_PATHPOINT, newsize); 1508 }
1493 if (m_PathAllocSize) { 1509 m_PathPointCount++;
1494 FXSYS_memcpy(pNewPoints, m_pPathPoints, m_PathAllocSize * sizeof(FX_ PATHPOINT)); 1510 if (m_PathPointCount > m_PathAllocSize) {
1495 FX_Free(m_pPathPoints); 1511 int newsize = m_PathPointCount + 256;
1496 } 1512 FX_PATHPOINT* pNewPoints = FX_Alloc(FX_PATHPOINT, newsize);
1497 m_pPathPoints = pNewPoints; 1513 if (m_PathAllocSize) {
1498 m_PathAllocSize = newsize; 1514 FXSYS_memcpy(pNewPoints, m_pPathPoints,
1499 } 1515 m_PathAllocSize * sizeof(FX_PATHPOINT));
1500 m_pPathPoints[m_PathPointCount - 1].m_Flag = flag; 1516 FX_Free(m_pPathPoints);
1501 m_pPathPoints[m_PathPointCount - 1].m_PointX = x; 1517 }
1502 m_pPathPoints[m_PathPointCount - 1].m_PointY = y; 1518 m_pPathPoints = pNewPoints;
1503 } 1519 m_PathAllocSize = newsize;
1504 void CPDF_StreamContentParser::AddPathObject(int FillType, FX_BOOL bStroke) 1520 }
1505 { 1521 m_pPathPoints[m_PathPointCount - 1].m_Flag = flag;
1506 int PathPointCount = m_PathPointCount, PathClipType = m_PathClipType; 1522 m_pPathPoints[m_PathPointCount - 1].m_PointX = x;
1507 m_PathPointCount = 0; 1523 m_pPathPoints[m_PathPointCount - 1].m_PointY = y;
1508 m_PathClipType = 0; 1524 }
1509 if (PathPointCount <= 1) { 1525 void CPDF_StreamContentParser::AddPathObject(int FillType, FX_BOOL bStroke) {
1510 if (PathPointCount && PathClipType) { 1526 int PathPointCount = m_PathPointCount, PathClipType = m_PathClipType;
1511 CPDF_Path path; 1527 m_PathPointCount = 0;
1512 path.New()->AppendRect(0, 0, 0, 0); 1528 m_PathClipType = 0;
1513 m_pCurStates->m_ClipPath.AppendPath(path, FXFILL_WINDING, TRUE); 1529 if (PathPointCount <= 1) {
1514 } 1530 if (PathPointCount && PathClipType) {
1515 return; 1531 CPDF_Path path;
1516 } 1532 path.New()->AppendRect(0, 0, 0, 0);
1517 if (PathPointCount && m_pPathPoints[PathPointCount - 1].m_Flag == FXPT_MOVET O) { 1533 m_pCurStates->m_ClipPath.AppendPath(path, FXFILL_WINDING, TRUE);
1518 PathPointCount --; 1534 }
1519 } 1535 return;
1520 CPDF_Path Path; 1536 }
1521 CFX_PathData* pPathData = Path.New(); 1537 if (PathPointCount &&
1522 pPathData->SetPointCount(PathPointCount); 1538 m_pPathPoints[PathPointCount - 1].m_Flag == FXPT_MOVETO) {
1523 FXSYS_memcpy(pPathData->GetPoints(), m_pPathPoints, sizeof(FX_PATHPOINT) * P athPointCount); 1539 PathPointCount--;
1524 CFX_AffineMatrix matrix = m_pCurStates->m_CTM; 1540 }
1525 matrix.Concat(m_mtContentToUser); 1541 CPDF_Path Path;
1526 if (bStroke || FillType) { 1542 CFX_PathData* pPathData = Path.New();
1527 CPDF_PathObject* pPathObj = new CPDF_PathObject; 1543 pPathData->SetPointCount(PathPointCount);
1528 pPathObj->m_bStroke = bStroke; 1544 FXSYS_memcpy(pPathData->GetPoints(), m_pPathPoints,
1529 pPathObj->m_FillType = FillType; 1545 sizeof(FX_PATHPOINT) * PathPointCount);
1530 pPathObj->m_Path = Path; 1546 CFX_AffineMatrix matrix = m_pCurStates->m_CTM;
1531 pPathObj->m_Matrix = matrix; 1547 matrix.Concat(m_mtContentToUser);
1532 SetGraphicStates(pPathObj, TRUE, FALSE, TRUE); 1548 if (bStroke || FillType) {
1533 pPathObj->CalcBoundingBox(); 1549 CPDF_PathObject* pPathObj = new CPDF_PathObject;
1534 m_pObjectList->m_ObjectList.AddTail(pPathObj); 1550 pPathObj->m_bStroke = bStroke;
1535 } 1551 pPathObj->m_FillType = FillType;
1536 if (PathClipType) { 1552 pPathObj->m_Path = Path;
1537 if (!matrix.IsIdentity()) { 1553 pPathObj->m_Matrix = matrix;
1538 Path.Transform(&matrix); 1554 SetGraphicStates(pPathObj, TRUE, FALSE, TRUE);
1539 matrix.SetIdentity(); 1555 pPathObj->CalcBoundingBox();
1540 } 1556 m_pObjectList->m_ObjectList.AddTail(pPathObj);
1541 m_pCurStates->m_ClipPath.AppendPath(Path, PathClipType, TRUE); 1557 }
1542 } 1558 if (PathClipType) {
1543 } 1559 if (!matrix.IsIdentity()) {
1544 CFX_ByteString _FPDF_ByteStringFromHex(CFX_BinaryBuf& src_buf) 1560 Path.Transform(&matrix);
1545 { 1561 matrix.SetIdentity();
1546 CFX_ByteTextBuf buf; 1562 }
1547 FX_BOOL bFirst = TRUE; 1563 m_pCurStates->m_ClipPath.AppendPath(Path, PathClipType, TRUE);
1548 int code = 0; 1564 }
1549 const uint8_t* str = src_buf.GetBuffer(); 1565 }
1550 FX_DWORD size = src_buf.GetSize(); 1566 CFX_ByteString _FPDF_ByteStringFromHex(CFX_BinaryBuf& src_buf) {
1551 for (FX_DWORD i = 0; i < size; i ++) { 1567 CFX_ByteTextBuf buf;
1552 uint8_t ch = str[i]; 1568 FX_BOOL bFirst = TRUE;
1553 if (ch >= '0' && ch <= '9') { 1569 int code = 0;
1554 if (bFirst) { 1570 const uint8_t* str = src_buf.GetBuffer();
1555 code = (ch - '0') * 16; 1571 FX_DWORD size = src_buf.GetSize();
1556 } else { 1572 for (FX_DWORD i = 0; i < size; i++) {
1557 code += ch - '0'; 1573 uint8_t ch = str[i];
1558 buf.AppendChar((char)code); 1574 if (ch >= '0' && ch <= '9') {
1559 } 1575 if (bFirst) {
1560 bFirst = !bFirst; 1576 code = (ch - '0') * 16;
1561 } else if (ch >= 'A' && ch <= 'F') { 1577 } else {
1562 if (bFirst) { 1578 code += ch - '0';
1563 code = (ch - 'A' + 10) * 16;
1564 } else {
1565 code += ch - 'A' + 10;
1566 buf.AppendChar((char)code);
1567 }
1568 bFirst = !bFirst;
1569 } else if (ch >= 'a' && ch <= 'f') {
1570 if (bFirst) {
1571 code = (ch - 'a' + 10) * 16;
1572 } else {
1573 code += ch - 'a' + 10;
1574 buf.AppendChar((char)code);
1575 }
1576 bFirst = !bFirst;
1577 }
1578 }
1579 if (!bFirst) {
1580 buf.AppendChar((char)code); 1579 buf.AppendChar((char)code);
1581 } 1580 }
1582 return buf.GetByteString(); 1581 bFirst = !bFirst;
1583 } 1582 } else if (ch >= 'A' && ch <= 'F') {
1583 if (bFirst) {
1584 code = (ch - 'A' + 10) * 16;
1585 } else {
1586 code += ch - 'A' + 10;
1587 buf.AppendChar((char)code);
1588 }
1589 bFirst = !bFirst;
1590 } else if (ch >= 'a' && ch <= 'f') {
1591 if (bFirst) {
1592 code = (ch - 'a' + 10) * 16;
1593 } else {
1594 code += ch - 'a' + 10;
1595 buf.AppendChar((char)code);
1596 }
1597 bFirst = !bFirst;
1598 }
1599 }
1600 if (!bFirst) {
1601 buf.AppendChar((char)code);
1602 }
1603 return buf.GetByteString();
1604 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698