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