OLD | NEW |
| (Empty) |
1 // Copyright 2014 PDFium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | |
6 | |
7 #include "core/fpdfapi/fpdf_page/pageint.h" | |
8 | |
9 #include <algorithm> | |
10 | |
11 #include "core/fpdfapi/fpdf_page/include/cpdf_form.h" | |
12 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" | |
13 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" | |
14 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" | |
15 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | |
16 #include "core/fpdfapi/include/cpdf_modulemgr.h" | |
17 #include "core/fpdfapi/ipdf_rendermodule.h" | |
18 #include "third_party/base/stl_util.h" | |
19 | |
20 CPDF_PageObject::CPDF_PageObject() {} | |
21 | |
22 CPDF_PageObject::~CPDF_PageObject() {} | |
23 | |
24 void CPDF_PageObject::CopyData(const CPDF_PageObject* pSrc) { | |
25 CopyStates(*pSrc); | |
26 m_Left = pSrc->m_Left; | |
27 m_Right = pSrc->m_Right; | |
28 m_Top = pSrc->m_Top; | |
29 m_Bottom = pSrc->m_Bottom; | |
30 } | |
31 | |
32 void CPDF_PageObject::TransformClipPath(CFX_Matrix& matrix) { | |
33 if (m_ClipPath.IsNull()) { | |
34 return; | |
35 } | |
36 m_ClipPath.GetModify(); | |
37 m_ClipPath.Transform(matrix); | |
38 } | |
39 | |
40 void CPDF_PageObject::TransformGeneralState(CFX_Matrix& matrix) { | |
41 if (m_GeneralState.IsNull()) { | |
42 return; | |
43 } | |
44 CPDF_GeneralStateData* pGS = m_GeneralState.GetModify(); | |
45 pGS->m_Matrix.Concat(matrix); | |
46 } | |
47 | |
48 FX_RECT CPDF_PageObject::GetBBox(const CFX_Matrix* pMatrix) const { | |
49 CFX_FloatRect rect(m_Left, m_Bottom, m_Right, m_Top); | |
50 if (pMatrix) { | |
51 pMatrix->TransformRect(rect); | |
52 } | |
53 return rect.GetOutterRect(); | |
54 } | |
55 | |
56 CPDF_TextObject::CPDF_TextObject() | |
57 : m_PosX(0), | |
58 m_PosY(0), | |
59 m_nChars(0), | |
60 m_pCharCodes(nullptr), | |
61 m_pCharPos(nullptr) {} | |
62 | |
63 CPDF_TextObject::~CPDF_TextObject() { | |
64 if (m_nChars > 1) { | |
65 FX_Free(m_pCharCodes); | |
66 } | |
67 FX_Free(m_pCharPos); | |
68 } | |
69 | |
70 void CPDF_TextObject::GetItemInfo(int index, CPDF_TextObjectItem* pInfo) const { | |
71 pInfo->m_CharCode = | |
72 m_nChars == 1 ? (FX_DWORD)(uintptr_t)m_pCharCodes : m_pCharCodes[index]; | |
73 pInfo->m_OriginX = index ? m_pCharPos[index - 1] : 0; | |
74 pInfo->m_OriginY = 0; | |
75 if (pInfo->m_CharCode == -1) { | |
76 return; | |
77 } | |
78 CPDF_Font* pFont = m_TextState.GetFont(); | |
79 if (!pFont->IsCIDFont()) { | |
80 return; | |
81 } | |
82 if (!pFont->AsCIDFont()->IsVertWriting()) { | |
83 return; | |
84 } | |
85 FX_WORD CID = pFont->AsCIDFont()->CIDFromCharCode(pInfo->m_CharCode); | |
86 pInfo->m_OriginY = pInfo->m_OriginX; | |
87 pInfo->m_OriginX = 0; | |
88 short vx, vy; | |
89 pFont->AsCIDFont()->GetVertOrigin(CID, vx, vy); | |
90 FX_FLOAT fontsize = m_TextState.GetFontSize(); | |
91 pInfo->m_OriginX -= fontsize * vx / 1000; | |
92 pInfo->m_OriginY -= fontsize * vy / 1000; | |
93 } | |
94 | |
95 int CPDF_TextObject::CountChars() const { | |
96 if (m_nChars == 1) { | |
97 return 1; | |
98 } | |
99 int count = 0; | |
100 for (int i = 0; i < m_nChars; ++i) | |
101 if (m_pCharCodes[i] != (FX_DWORD)-1) { | |
102 ++count; | |
103 } | |
104 return count; | |
105 } | |
106 | |
107 void CPDF_TextObject::GetCharInfo(int index, | |
108 FX_DWORD& charcode, | |
109 FX_FLOAT& kerning) const { | |
110 if (m_nChars == 1) { | |
111 charcode = (FX_DWORD)(uintptr_t)m_pCharCodes; | |
112 kerning = 0; | |
113 return; | |
114 } | |
115 int count = 0; | |
116 for (int i = 0; i < m_nChars; ++i) { | |
117 if (m_pCharCodes[i] != (FX_DWORD)-1) { | |
118 if (count == index) { | |
119 charcode = m_pCharCodes[i]; | |
120 if (i == m_nChars - 1 || m_pCharCodes[i + 1] != (FX_DWORD)-1) { | |
121 kerning = 0; | |
122 } else { | |
123 kerning = m_pCharPos[i]; | |
124 } | |
125 return; | |
126 } | |
127 ++count; | |
128 } | |
129 } | |
130 } | |
131 | |
132 void CPDF_TextObject::GetCharInfo(int index, CPDF_TextObjectItem* pInfo) const { | |
133 if (m_nChars == 1) { | |
134 GetItemInfo(0, pInfo); | |
135 return; | |
136 } | |
137 int count = 0; | |
138 for (int i = 0; i < m_nChars; ++i) { | |
139 FX_DWORD charcode = m_pCharCodes[i]; | |
140 if (charcode == (FX_DWORD)-1) { | |
141 continue; | |
142 } | |
143 if (count == index) { | |
144 GetItemInfo(i, pInfo); | |
145 break; | |
146 } | |
147 ++count; | |
148 } | |
149 } | |
150 | |
151 CPDF_TextObject* CPDF_TextObject::Clone() const { | |
152 CPDF_TextObject* obj = new CPDF_TextObject; | |
153 obj->CopyData(this); | |
154 | |
155 obj->m_nChars = m_nChars; | |
156 if (m_nChars > 1) { | |
157 obj->m_pCharCodes = FX_Alloc(FX_DWORD, m_nChars); | |
158 FXSYS_memcpy(obj->m_pCharCodes, m_pCharCodes, m_nChars * sizeof(FX_DWORD)); | |
159 obj->m_pCharPos = FX_Alloc(FX_FLOAT, m_nChars - 1); | |
160 FXSYS_memcpy(obj->m_pCharPos, m_pCharPos, | |
161 (m_nChars - 1) * sizeof(FX_FLOAT)); | |
162 } else { | |
163 obj->m_pCharCodes = m_pCharCodes; | |
164 } | |
165 obj->m_PosX = m_PosX; | |
166 obj->m_PosY = m_PosY; | |
167 return obj; | |
168 } | |
169 | |
170 void CPDF_TextObject::GetTextMatrix(CFX_Matrix* pMatrix) const { | |
171 FX_FLOAT* pTextMatrix = m_TextState.GetMatrix(); | |
172 pMatrix->Set(pTextMatrix[0], pTextMatrix[2], pTextMatrix[1], pTextMatrix[3], | |
173 m_PosX, m_PosY); | |
174 } | |
175 | |
176 void CPDF_TextObject::SetSegments(const CFX_ByteString* pStrs, | |
177 FX_FLOAT* pKerning, | |
178 int nsegs) { | |
179 if (m_nChars > 1) { | |
180 FX_Free(m_pCharCodes); | |
181 m_pCharCodes = nullptr; | |
182 } | |
183 FX_Free(m_pCharPos); | |
184 m_pCharPos = nullptr; | |
185 CPDF_Font* pFont = m_TextState.GetFont(); | |
186 m_nChars = 0; | |
187 for (int i = 0; i < nsegs; ++i) { | |
188 m_nChars += pFont->CountChar(pStrs[i], pStrs[i].GetLength()); | |
189 } | |
190 m_nChars += nsegs - 1; | |
191 if (m_nChars > 1) { | |
192 m_pCharCodes = FX_Alloc(FX_DWORD, m_nChars); | |
193 m_pCharPos = FX_Alloc(FX_FLOAT, m_nChars - 1); | |
194 int index = 0; | |
195 for (int i = 0; i < nsegs; ++i) { | |
196 const FX_CHAR* segment = pStrs[i]; | |
197 int offset = 0, len = pStrs[i].GetLength(); | |
198 while (offset < len) { | |
199 m_pCharCodes[index++] = pFont->GetNextChar(segment, len, offset); | |
200 } | |
201 if (i != nsegs - 1) { | |
202 m_pCharPos[index - 1] = pKerning[i]; | |
203 m_pCharCodes[index++] = (FX_DWORD)-1; | |
204 } | |
205 } | |
206 } else { | |
207 int offset = 0; | |
208 m_pCharCodes = (FX_DWORD*)(uintptr_t)pFont->GetNextChar( | |
209 pStrs[0], pStrs[0].GetLength(), offset); | |
210 } | |
211 } | |
212 | |
213 void CPDF_TextObject::SetText(const CFX_ByteString& str) { | |
214 SetSegments(&str, nullptr, 1); | |
215 RecalcPositionData(); | |
216 } | |
217 | |
218 FX_FLOAT CPDF_TextObject::GetCharWidth(FX_DWORD charcode) const { | |
219 FX_FLOAT fontsize = m_TextState.GetFontSize() / 1000; | |
220 CPDF_Font* pFont = m_TextState.GetFont(); | |
221 FX_BOOL bVertWriting = FALSE; | |
222 CPDF_CIDFont* pCIDFont = pFont->AsCIDFont(); | |
223 if (pCIDFont) { | |
224 bVertWriting = pCIDFont->IsVertWriting(); | |
225 } | |
226 if (!bVertWriting) | |
227 return pFont->GetCharWidthF(charcode, 0) * fontsize; | |
228 | |
229 FX_WORD CID = pCIDFont->CIDFromCharCode(charcode); | |
230 return pCIDFont->GetVertWidth(CID) * fontsize; | |
231 } | |
232 | |
233 void CPDF_TextObject::CalcPositionData(FX_FLOAT* pTextAdvanceX, | |
234 FX_FLOAT* pTextAdvanceY, | |
235 FX_FLOAT horz_scale, | |
236 int level) { | |
237 FX_FLOAT curpos = 0; | |
238 FX_FLOAT min_x = 10000 * 1.0f; | |
239 FX_FLOAT max_x = -10000 * 1.0f; | |
240 FX_FLOAT min_y = 10000 * 1.0f; | |
241 FX_FLOAT max_y = -10000 * 1.0f; | |
242 CPDF_Font* pFont = m_TextState.GetFont(); | |
243 FX_BOOL bVertWriting = FALSE; | |
244 CPDF_CIDFont* pCIDFont = pFont->AsCIDFont(); | |
245 if (pCIDFont) { | |
246 bVertWriting = pCIDFont->IsVertWriting(); | |
247 } | |
248 FX_FLOAT fontsize = m_TextState.GetFontSize(); | |
249 for (int i = 0; i < m_nChars; ++i) { | |
250 FX_DWORD charcode = | |
251 m_nChars == 1 ? (FX_DWORD)(uintptr_t)m_pCharCodes : m_pCharCodes[i]; | |
252 if (i > 0) { | |
253 if (charcode == (FX_DWORD)-1) { | |
254 curpos -= (m_pCharPos[i - 1] * fontsize) / 1000; | |
255 continue; | |
256 } | |
257 m_pCharPos[i - 1] = curpos; | |
258 } | |
259 FX_RECT char_rect = pFont->GetCharBBox(charcode, level); | |
260 FX_FLOAT charwidth; | |
261 if (!bVertWriting) { | |
262 if (min_y > char_rect.top) { | |
263 min_y = (FX_FLOAT)char_rect.top; | |
264 } | |
265 if (max_y < char_rect.top) { | |
266 max_y = (FX_FLOAT)char_rect.top; | |
267 } | |
268 if (min_y > char_rect.bottom) { | |
269 min_y = (FX_FLOAT)char_rect.bottom; | |
270 } | |
271 if (max_y < char_rect.bottom) { | |
272 max_y = (FX_FLOAT)char_rect.bottom; | |
273 } | |
274 FX_FLOAT char_left = curpos + char_rect.left * fontsize / 1000; | |
275 FX_FLOAT char_right = curpos + char_rect.right * fontsize / 1000; | |
276 if (min_x > char_left) { | |
277 min_x = char_left; | |
278 } | |
279 if (max_x < char_left) { | |
280 max_x = char_left; | |
281 } | |
282 if (min_x > char_right) { | |
283 min_x = char_right; | |
284 } | |
285 if (max_x < char_right) { | |
286 max_x = char_right; | |
287 } | |
288 charwidth = pFont->GetCharWidthF(charcode, level) * fontsize / 1000; | |
289 } else { | |
290 FX_WORD CID = pCIDFont->CIDFromCharCode(charcode); | |
291 short vx; | |
292 short vy; | |
293 pCIDFont->GetVertOrigin(CID, vx, vy); | |
294 char_rect.left -= vx; | |
295 char_rect.right -= vx; | |
296 char_rect.top -= vy; | |
297 char_rect.bottom -= vy; | |
298 if (min_x > char_rect.left) { | |
299 min_x = (FX_FLOAT)char_rect.left; | |
300 } | |
301 if (max_x < char_rect.left) { | |
302 max_x = (FX_FLOAT)char_rect.left; | |
303 } | |
304 if (min_x > char_rect.right) { | |
305 min_x = (FX_FLOAT)char_rect.right; | |
306 } | |
307 if (max_x < char_rect.right) { | |
308 max_x = (FX_FLOAT)char_rect.right; | |
309 } | |
310 FX_FLOAT char_top = curpos + char_rect.top * fontsize / 1000; | |
311 FX_FLOAT char_bottom = curpos + char_rect.bottom * fontsize / 1000; | |
312 if (min_y > char_top) { | |
313 min_y = char_top; | |
314 } | |
315 if (max_y < char_top) { | |
316 max_y = char_top; | |
317 } | |
318 if (min_y > char_bottom) { | |
319 min_y = char_bottom; | |
320 } | |
321 if (max_y < char_bottom) { | |
322 max_y = char_bottom; | |
323 } | |
324 charwidth = pCIDFont->GetVertWidth(CID) * fontsize / 1000; | |
325 } | |
326 curpos += charwidth; | |
327 if (charcode == ' ' && (!pCIDFont || pCIDFont->GetCharSize(32) == 1)) { | |
328 curpos += m_TextState.GetObject()->m_WordSpace; | |
329 } | |
330 curpos += m_TextState.GetObject()->m_CharSpace; | |
331 } | |
332 if (bVertWriting) { | |
333 if (pTextAdvanceX) { | |
334 *pTextAdvanceX = 0; | |
335 } | |
336 if (pTextAdvanceY) { | |
337 *pTextAdvanceY = curpos; | |
338 } | |
339 min_x = min_x * fontsize / 1000; | |
340 max_x = max_x * fontsize / 1000; | |
341 } else { | |
342 if (pTextAdvanceX) { | |
343 *pTextAdvanceX = curpos * horz_scale; | |
344 } | |
345 if (pTextAdvanceY) { | |
346 *pTextAdvanceY = 0; | |
347 } | |
348 min_y = min_y * fontsize / 1000; | |
349 max_y = max_y * fontsize / 1000; | |
350 } | |
351 CFX_Matrix matrix; | |
352 GetTextMatrix(&matrix); | |
353 m_Left = min_x; | |
354 m_Right = max_x; | |
355 m_Bottom = min_y; | |
356 m_Top = max_y; | |
357 matrix.TransformRect(m_Left, m_Right, m_Top, m_Bottom); | |
358 int textmode = m_TextState.GetObject()->m_TextMode; | |
359 if (textmode == 1 || textmode == 2 || textmode == 5 || textmode == 6) { | |
360 FX_FLOAT half_width = m_GraphState.GetObject()->m_LineWidth / 2; | |
361 m_Left -= half_width; | |
362 m_Right += half_width; | |
363 m_Top += half_width; | |
364 m_Bottom -= half_width; | |
365 } | |
366 } | |
367 | |
368 void CPDF_TextObject::Transform(const CFX_Matrix& matrix) { | |
369 m_TextState.GetModify(); | |
370 CFX_Matrix text_matrix; | |
371 GetTextMatrix(&text_matrix); | |
372 text_matrix.Concat(matrix); | |
373 FX_FLOAT* pTextMatrix = m_TextState.GetMatrix(); | |
374 pTextMatrix[0] = text_matrix.GetA(); | |
375 pTextMatrix[1] = text_matrix.GetC(); | |
376 pTextMatrix[2] = text_matrix.GetB(); | |
377 pTextMatrix[3] = text_matrix.GetD(); | |
378 m_PosX = text_matrix.GetE(); | |
379 m_PosY = text_matrix.GetF(); | |
380 CalcPositionData(nullptr, nullptr, 0); | |
381 } | |
382 | |
383 void CPDF_TextObject::SetPosition(FX_FLOAT x, FX_FLOAT y) { | |
384 FX_FLOAT dx = x - m_PosX; | |
385 FX_FLOAT dy = y - m_PosY; | |
386 m_PosX = x; | |
387 m_PosY = y; | |
388 m_Left += dx; | |
389 m_Right += dx; | |
390 m_Top += dy; | |
391 m_Bottom += dy; | |
392 } | |
393 | |
394 CPDF_ShadingObject::CPDF_ShadingObject() : m_pShading(nullptr) {} | |
395 | |
396 CPDF_ShadingObject::~CPDF_ShadingObject() {} | |
397 | |
398 CPDF_ShadingObject* CPDF_ShadingObject::Clone() const { | |
399 CPDF_ShadingObject* obj = new CPDF_ShadingObject; | |
400 obj->CopyData(this); | |
401 | |
402 obj->m_pShading = m_pShading; | |
403 if (obj->m_pShading && obj->m_pShading->m_pDocument) { | |
404 CPDF_DocPageData* pDocPageData = | |
405 obj->m_pShading->m_pDocument->GetPageData(); | |
406 obj->m_pShading = (CPDF_ShadingPattern*)pDocPageData->GetPattern( | |
407 obj->m_pShading->m_pShadingObj, m_pShading->m_bShadingObj, | |
408 &obj->m_pShading->m_ParentMatrix); | |
409 } | |
410 obj->m_Matrix = m_Matrix; | |
411 return obj; | |
412 } | |
413 | |
414 void CPDF_ShadingObject::Transform(const CFX_Matrix& matrix) { | |
415 if (!m_ClipPath.IsNull()) { | |
416 m_ClipPath.GetModify(); | |
417 m_ClipPath.Transform(matrix); | |
418 } | |
419 m_Matrix.Concat(matrix); | |
420 if (!m_ClipPath.IsNull()) { | |
421 CalcBoundingBox(); | |
422 } else { | |
423 matrix.TransformRect(m_Left, m_Right, m_Top, m_Bottom); | |
424 } | |
425 } | |
426 | |
427 void CPDF_ShadingObject::CalcBoundingBox() { | |
428 if (m_ClipPath.IsNull()) { | |
429 return; | |
430 } | |
431 CFX_FloatRect rect = m_ClipPath.GetClipBox(); | |
432 m_Left = rect.left; | |
433 m_Bottom = rect.bottom; | |
434 m_Right = rect.right; | |
435 m_Top = rect.top; | |
436 } | |
437 | |
438 CPDF_FormObject::CPDF_FormObject() : m_pForm(nullptr) {} | |
439 | |
440 CPDF_FormObject::~CPDF_FormObject() { | |
441 delete m_pForm; | |
442 } | |
443 | |
444 void CPDF_FormObject::Transform(const CFX_Matrix& matrix) { | |
445 m_FormMatrix.Concat(matrix); | |
446 CalcBoundingBox(); | |
447 } | |
448 | |
449 CPDF_FormObject* CPDF_FormObject::Clone() const { | |
450 CPDF_FormObject* obj = new CPDF_FormObject; | |
451 obj->CopyData(this); | |
452 | |
453 obj->m_pForm = m_pForm->Clone(); | |
454 obj->m_FormMatrix = m_FormMatrix; | |
455 return obj; | |
456 } | |
457 | |
458 void CPDF_FormObject::CalcBoundingBox() { | |
459 CFX_FloatRect form_rect = m_pForm->CalcBoundingBox(); | |
460 form_rect.Transform(&m_FormMatrix); | |
461 m_Left = form_rect.left; | |
462 m_Bottom = form_rect.bottom; | |
463 m_Right = form_rect.right; | |
464 m_Top = form_rect.top; | |
465 } | |
466 | |
467 CPDF_Page::CPDF_Page() : m_pPageRender(nullptr) {} | |
468 | |
469 void CPDF_Page::Load(CPDF_Document* pDocument, | |
470 CPDF_Dictionary* pPageDict, | |
471 FX_BOOL bPageCache) { | |
472 m_pDocument = (CPDF_Document*)pDocument; | |
473 m_pFormDict = pPageDict; | |
474 if (bPageCache) { | |
475 m_pPageRender = | |
476 CPDF_ModuleMgr::Get()->GetRenderModule()->CreatePageCache(this); | |
477 } | |
478 if (!pPageDict) { | |
479 m_PageWidth = m_PageHeight = 100 * 1.0f; | |
480 m_pPageResources = m_pResources = NULL; | |
481 return; | |
482 } | |
483 CPDF_Object* pageAttr = GetPageAttr("Resources"); | |
484 m_pResources = pageAttr ? pageAttr->GetDict() : NULL; | |
485 m_pPageResources = m_pResources; | |
486 CPDF_Object* pRotate = GetPageAttr("Rotate"); | |
487 int rotate = 0; | |
488 if (pRotate) { | |
489 rotate = pRotate->GetInteger() / 90 % 4; | |
490 } | |
491 if (rotate < 0) { | |
492 rotate += 4; | |
493 } | |
494 CPDF_Array* pMediaBox = ToArray(GetPageAttr("MediaBox")); | |
495 CFX_FloatRect mediabox; | |
496 if (pMediaBox) { | |
497 mediabox = pMediaBox->GetRect(); | |
498 mediabox.Normalize(); | |
499 } | |
500 if (mediabox.IsEmpty()) { | |
501 mediabox = CFX_FloatRect(0, 0, 612, 792); | |
502 } | |
503 | |
504 CPDF_Array* pCropBox = ToArray(GetPageAttr("CropBox")); | |
505 if (pCropBox) { | |
506 m_BBox = pCropBox->GetRect(); | |
507 m_BBox.Normalize(); | |
508 } | |
509 if (m_BBox.IsEmpty()) { | |
510 m_BBox = mediabox; | |
511 } else { | |
512 m_BBox.Intersect(mediabox); | |
513 } | |
514 if (rotate % 2) { | |
515 m_PageHeight = m_BBox.right - m_BBox.left; | |
516 m_PageWidth = m_BBox.top - m_BBox.bottom; | |
517 } else { | |
518 m_PageWidth = m_BBox.right - m_BBox.left; | |
519 m_PageHeight = m_BBox.top - m_BBox.bottom; | |
520 } | |
521 switch (rotate) { | |
522 case 0: | |
523 m_PageMatrix.Set(1.0f, 0, 0, 1.0f, -m_BBox.left, -m_BBox.bottom); | |
524 break; | |
525 case 1: | |
526 m_PageMatrix.Set(0, -1.0f, 1.0f, 0, -m_BBox.bottom, m_BBox.right); | |
527 break; | |
528 case 2: | |
529 m_PageMatrix.Set(-1.0f, 0, 0, -1.0f, m_BBox.right, m_BBox.top); | |
530 break; | |
531 case 3: | |
532 m_PageMatrix.Set(0, 1.0f, -1.0f, 0, m_BBox.top, -m_BBox.left); | |
533 break; | |
534 } | |
535 m_Transparency = PDFTRANS_ISOLATED; | |
536 LoadTransInfo(); | |
537 } | |
538 | |
539 void CPDF_Page::StartParse(CPDF_ParseOptions* pOptions) { | |
540 if (m_ParseState == CONTENT_PARSED || m_ParseState == CONTENT_PARSING) { | |
541 return; | |
542 } | |
543 m_pParser.reset(new CPDF_ContentParser); | |
544 m_pParser->Start(this, pOptions); | |
545 m_ParseState = CONTENT_PARSING; | |
546 } | |
547 | |
548 void CPDF_Page::ParseContent(CPDF_ParseOptions* pOptions) { | |
549 StartParse(pOptions); | |
550 ContinueParse(nullptr); | |
551 } | |
552 | |
553 CPDF_Page::~CPDF_Page() { | |
554 if (m_pPageRender) { | |
555 IPDF_RenderModule* pModule = CPDF_ModuleMgr::Get()->GetRenderModule(); | |
556 pModule->DestroyPageCache(m_pPageRender); | |
557 } | |
558 } | |
559 | |
560 CPDF_Object* FPDFAPI_GetPageAttr(CPDF_Dictionary* pPageDict, | |
561 const CFX_ByteStringC& name) { | |
562 int level = 0; | |
563 while (1) { | |
564 CPDF_Object* pObj = pPageDict->GetElementValue(name); | |
565 if (pObj) { | |
566 return pObj; | |
567 } | |
568 CPDF_Dictionary* pParent = pPageDict->GetDictBy("Parent"); | |
569 if (!pParent || pParent == pPageDict) { | |
570 return NULL; | |
571 } | |
572 pPageDict = pParent; | |
573 level++; | |
574 if (level == 1000) { | |
575 return NULL; | |
576 } | |
577 } | |
578 } | |
579 | |
580 CPDF_Object* CPDF_Page::GetPageAttr(const CFX_ByteStringC& name) const { | |
581 return FPDFAPI_GetPageAttr(m_pFormDict, name); | |
582 } | |
583 | |
584 void CPDF_Page::GetDisplayMatrix(CFX_Matrix& matrix, | |
585 int xPos, | |
586 int yPos, | |
587 int xSize, | |
588 int ySize, | |
589 int iRotate) const { | |
590 if (m_PageWidth == 0 || m_PageHeight == 0) { | |
591 return; | |
592 } | |
593 CFX_Matrix display_matrix; | |
594 int x0, y0, x1, y1, x2, y2; | |
595 iRotate %= 4; | |
596 switch (iRotate) { | |
597 case 0: | |
598 x0 = xPos; | |
599 y0 = yPos + ySize; | |
600 x1 = xPos; | |
601 y1 = yPos; | |
602 x2 = xPos + xSize; | |
603 y2 = yPos + ySize; | |
604 break; | |
605 case 1: | |
606 x0 = xPos; | |
607 y0 = yPos; | |
608 x1 = xPos + xSize; | |
609 y1 = yPos; | |
610 x2 = xPos; | |
611 y2 = yPos + ySize; | |
612 break; | |
613 case 2: | |
614 x0 = xPos + xSize; | |
615 y0 = yPos; | |
616 x1 = xPos + xSize; | |
617 y1 = yPos + ySize; | |
618 x2 = xPos; | |
619 y2 = yPos; | |
620 break; | |
621 case 3: | |
622 x0 = xPos + xSize; | |
623 y0 = yPos + ySize; | |
624 x1 = xPos; | |
625 y1 = yPos + ySize; | |
626 x2 = xPos + xSize; | |
627 y2 = yPos; | |
628 break; | |
629 } | |
630 display_matrix.Set( | |
631 ((FX_FLOAT)(x2 - x0)) / m_PageWidth, ((FX_FLOAT)(y2 - y0)) / m_PageWidth, | |
632 ((FX_FLOAT)(x1 - x0)) / m_PageHeight, | |
633 ((FX_FLOAT)(y1 - y0)) / m_PageHeight, (FX_FLOAT)x0, (FX_FLOAT)y0); | |
634 matrix = m_PageMatrix; | |
635 matrix.Concat(display_matrix); | |
636 } | |
OLD | NEW |