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

Side by Side Diff: core/src/reflow/reflowedpage.cpp

Issue 453133004: clang-format all code (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "../../include/reflow/reflowengine.h" 7 #include "../../include/reflow/reflowengine.h"
8 #include "reflowedpage.h" 8 #include "reflowedpage.h"
9 CPDF_ProgressiveReflowPageParser::CPDF_ProgressiveReflowPageParser() 9 CPDF_ProgressiveReflowPageParser::CPDF_ProgressiveReflowPageParser() {
10 { 10 m_nObjProcessed = 0;
11 m_nObjProcessed = 0; 11 m_pReflowEngine = NULL;
12 m_pReflowEngine = NULL; 12 m_pProvider = NULL;
13 }
14 CPDF_ProgressiveReflowPageParser::~CPDF_ProgressiveReflowPageParser() {
15 if (m_pProvider) {
16 delete m_pProvider;
17 }
18 m_pProvider = NULL;
19 if (m_pReflowEngine) {
20 delete m_pReflowEngine;
21 }
22 m_pReflowEngine = NULL;
23 }
24 void CPDF_ProgressiveReflowPageParser::Init() {
25 m_Status = Ready;
26 }
27 CPDF_ReflowedPage::CPDF_ReflowedPage(CFX_GrowOnlyPool* pMemoryPool) {
28 m_PageWidth = 0;
29 m_PageHeight = 0;
30 m_bWaiting = TRUE;
31 if (pMemoryPool) {
32 m_pMemoryPool = pMemoryPool;
33 m_bCreateMemoryPool = FALSE;
34 } else {
35 m_pMemoryPool = FX_NEW CFX_GrowOnlyPool;
36 m_bCreateMemoryPool = TRUE;
37 }
38 m_pCharState = FX_NEW CRF_CharStateArray(10);
39 m_pReflowed = FX_NEW CRF_DataPtrArray(500);
40 m_pPageInfos = NULL;
41 }
42 CPDF_ReflowedPage::~CPDF_ReflowedPage() {
43 if (m_pReflowed) {
44 for (int i = 0; i < m_pReflowed->GetSize(); i++) {
45 CRF_Data* pData = (*m_pReflowed)[i];
46 if (pData->m_Type == CRF_Data::Image) {
47 delete ((CRF_ImageData*)pData)->m_pBitmap;
48 }
49 }
50 m_pReflowed->RemoveAll();
51 delete m_pReflowed;
52 }
53 m_pReflowed = NULL;
54 if (m_pCharState) {
55 m_pCharState->RemoveAll();
56 delete m_pCharState;
57 }
58 m_pCharState = NULL;
59 if (m_bCreateMemoryPool && m_pMemoryPool) {
60 m_pMemoryPool->FreeAll();
61 }
62 if (m_pMemoryPool) {
63 delete m_pMemoryPool;
64 }
65 m_pMemoryPool = NULL;
66 m_pPDFPage = NULL;
67 if (m_pPageInfos) {
68 ReleasePageObjsMemberShip();
69 }
70 }
71 FX_BOOL CPDF_ReflowedPage::RetainPageObjsMemberShip() {
72 if (NULL == m_pPDFPage) {
73 return FALSE;
74 }
75 if (NULL == m_pPageInfos) {
76 m_pPageInfos = FX_NEW CFX_MapPtrToPtr();
77 } else {
78 return TRUE;
79 }
80 FX_POSITION pos = m_pPDFPage->GetFirstObjectPosition();
81 if (!pos) {
82 return FALSE;
83 }
84 CPDF_PageObject* pPageObj = NULL;
85 while (pos) {
86 pPageObj = m_pPDFPage->GetNextObject(pos);
87 MarkPageObjMemberShip(pPageObj, NULL);
88 pPageObj = NULL;
89 }
90 return TRUE;
91 }
92 void CPDF_ReflowedPage::MarkPageObjMemberShip(CPDF_PageObject* pObj,
93 CRF_PageInfo* pParent) {
94 if (NULL == m_pPageInfos) {
95 return;
96 }
97 CRF_PageInfo* pPageInfo = FX_NEW CRF_PageInfo(pObj, pParent);
98 if (NULL == pPageInfo) {
99 return;
100 }
101 m_pPageInfos->SetAt(pObj, pPageInfo);
102 if (PDFPAGE_FORM != pObj->m_Type) {
103 return;
104 }
105 CPDF_FormObject* pFormObj = (CPDF_FormObject*)pObj;
106 FX_POSITION pos;
107 pos = pFormObj->m_pForm->GetFirstObjectPosition();
108 if (!pos) {
109 return;
110 }
111 CPDF_PageObject* pPageObj = NULL;
112 while (pos) {
113 pPageObj = pFormObj->m_pForm->GetNextObject(pos);
114 MarkPageObjMemberShip(pPageObj, pPageInfo);
115 pPageObj = NULL;
116 }
117 }
118 void CPDF_ReflowedPage::ReleasePageObjsMemberShip() {
119 if (NULL == m_pPageInfos) {
120 return;
121 }
122 CPDF_PageObject* pPageObj = NULL;
123 CRF_PageInfo* pPageInfo = NULL;
124 FX_POSITION pos = m_pPageInfos->GetStartPosition();
125 while (pos) {
126 m_pPageInfos->GetNextAssoc(pos, (void*&)pPageObj, (void*&)pPageInfo);
127 delete pPageInfo;
128 }
129 m_pPageInfos->RemoveAll();
130 delete m_pPageInfos;
131 m_pPageInfos = NULL;
132 }
133 CPDF_Dictionary* CPDF_ReflowedPage::GetFormResDict(CPDF_PageObject* pObj) {
134 if (NULL == m_pPageInfos) {
135 return NULL;
136 }
137 if (FALSE == RetainPageObjsMemberShip()) {
138 return NULL;
139 }
140 CRF_PageInfo* pPageInfo = (CRF_PageInfo*)m_pPageInfos->GetValueAt(pObj);
141 if (NULL == pPageInfo) {
142 return NULL;
143 }
144 return pPageInfo->GetFormDict();
145 }
146 void CPDF_ReflowedPage::GetDisplayMatrix(CFX_AffineMatrix& matrix,
147 FX_INT32 xPos,
148 FX_INT32 yPos,
149 FX_INT32 xSize,
150 FX_INT32 ySize,
151 FX_INT32 iRotate,
152 const CFX_AffineMatrix* pPageMatrix) {
153 CFX_AffineMatrix display_matrix;
154 if (m_PageHeight == 0) {
155 matrix.Set(1, 0, 0, -1, 0, 0);
156 return;
157 }
158 FX_INT32 x0, y0, x1, y1, x2, y2;
159 iRotate %= 4;
160 switch (iRotate) {
161 case 0:
162 x0 = xPos;
163 y0 = yPos;
164 x1 = xPos;
165 y1 = yPos + ySize;
166 x2 = xPos + xSize;
167 y2 = yPos;
168 break;
169 case 3:
170 x0 = xPos;
171 y0 = ySize + yPos;
172 x1 = xPos + xSize;
173 y1 = yPos + ySize;
174 x2 = xPos;
175 y2 = yPos;
176 break;
177 case 2:
178 x0 = xSize + xPos;
179 y0 = ySize + yPos;
180 x1 = xSize + xPos;
181 y1 = yPos;
182 x2 = xPos;
183 y2 = ySize + yPos;
184 break;
185 case 1:
186 x0 = xPos + xSize;
187 y0 = yPos;
188 x1 = xPos;
189 y1 = yPos;
190 x2 = xPos + xSize;
191 y2 = yPos + ySize;
192 break;
193 }
194 display_matrix.Set(FXSYS_Div((FX_FLOAT)(x2 - x0), m_PageWidth),
195 FXSYS_Div((FX_FLOAT)(y2 - y0), m_PageWidth),
196 FXSYS_Div((FX_FLOAT)(x1 - x0), m_PageHeight),
197 FXSYS_Div((FX_FLOAT)(y1 - y0), m_PageHeight),
198 (FX_FLOAT)(x0),
199 (FX_FLOAT)(y0));
200 matrix.Set(1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f);
201 matrix.Concat(display_matrix);
202 return;
203 }
204 FX_FLOAT CPDF_ReflowedPage::GetPageHeight() {
205 return m_PageHeight;
206 }
207 void CPDF_ReflowedPage::FocusGetData(const CFX_AffineMatrix matrix,
208 FX_INT32 x,
209 FX_INT32 y,
210 CFX_ByteString& str) {
211 if (NULL == m_pReflowed) {
212 return;
213 }
214 CFX_AffineMatrix revMatrix;
215 revMatrix.SetReverse(matrix);
216 FX_FLOAT x1, y1;
217 revMatrix.Transform((float)x, (float)y, x1, y1);
218 int count = m_pReflowed->GetSize();
219 FX_FLOAT dx = 1000, dy = 1000;
220 FX_INT32 pos = 0;
221 FX_INT32 i;
222 for (i = 0; i < count; i++) {
223 CRF_Data* pData = (*m_pReflowed)[i];
224 FX_FLOAT tempdy = FXSYS_fabs(pData->m_PosY - y1);
225 if (FXSYS_fabs(tempdy - dy) < 1) {
226 continue;
227 }
228 CFX_FloatRect rect(
229 0, pData->m_PosY + pData->m_Height, this->m_PageWidth, pData->m_PosY);
230 if (rect.Contains(x1, y1)) {
231 pos = i;
232 dx = 0;
233 dy = 0;
234 break;
235 } else if (tempdy < dy) {
236 dy = tempdy;
237 dx = FXSYS_fabs(pData->m_PosX - x1);
238 pos = i;
239 } else if (tempdy == dy) {
240 FX_FLOAT tempdx = FXSYS_fabs(pData->m_PosX - x1);
241 if (tempdx < dx) {
242 dx = tempdx;
243 pos = i;
244 }
245 } else if (tempdy > dy) {
246 break;
247 }
248 }
249 if (dx != 0 || dy != 0) {
250 count = count < (pos + 10) ? count : (pos + 10);
251 for (i = 0 > (pos - 10) ? 0 : (pos - 10); i < count; i++) {
252 CRF_Data* pData = (*m_pReflowed)[i];
253 FX_FLOAT tempdy = FXSYS_fabs(pData->m_PosY - y1);
254 if (tempdy < dy) {
255 dy = tempdy;
256 dx = FXSYS_fabs(pData->m_PosX - x1);
257 pos = i;
258 } else if (tempdy == dy) {
259 FX_FLOAT tempdx = FXSYS_fabs(pData->m_PosX - x1);
260 if (tempdx < dx) {
261 dx = tempdx;
262 pos = i;
263 }
264 }
265 }
266 }
267 str.Format("%d", pos);
268 }
269 FX_BOOL CPDF_ReflowedPage::FocusGetPosition(const CFX_AffineMatrix matrix,
270 CFX_ByteString str,
271 FX_INT32& x,
272 FX_INT32& y) {
273 if (NULL == m_pReflowed) {
274 return FALSE;
275 }
276 FX_INT32 pos = FXSYS_atoi(str);
277 if (pos < 0 || pos >= m_pReflowed->GetSize()) {
278 return FALSE;
279 }
280 CRF_Data* pData = (*m_pReflowed)[pos];
281 FX_FLOAT x1, y1;
282 matrix.Transform(pData->m_PosX, pData->m_PosY + pData->m_Height, x1, y1);
283 x = (int)x1;
284 y = (int)y1;
285 return TRUE;
286 }
287 int CPDF_ProgressiveReflowPageParser::GetPosition() {
288 if (!m_pProvider) {
289 return 0;
290 }
291 if (!m_pReflowEngine) {
292 return m_pProvider->GetPosition() / 2;
293 }
294 return m_pProvider->GetPosition() / 2 + m_pReflowEngine->GetPosition() / 2;
295 }
296 void CPDF_ProgressiveReflowPageParser::Continue(IFX_Pause* pPause) {
297 if (NULL == m_pReflowPage) {
298 return;
299 }
300 if (m_Status != ToBeContinued) {
301 return;
302 }
303 m_pPause = pPause;
304 if (m_pReflowEngine) {
305 if (m_pReflowEngine->Continue() != LayoutToBeContinued) {
306 m_Status = Done;
307 }
308 } else {
309 if (m_pProvider->Continue() == LayoutFinished) {
310 m_pReflowEngine = IPDF_LayoutProcessor::Create_LayoutProcessor_Reflow(
311 m_TopIndent,
312 m_ReflowedWidth,
313 m_fScreenHeight,
314 m_pReflowPage,
315 m_flags,
316 m_ParseStyle.m_LineSpace);
317 CFX_AffineMatrix matrix;
318 m_pPDFPage->GetDisplayMatrix(matrix,
319 0,
320 0,
321 (int)(m_pPDFPage->GetPageWidth()),
322 (int)(m_pPDFPage->GetPageHeight()),
323 0);
324 if (m_pReflowEngine->StartProcess(m_pProvider->GetRoot(),
325 m_pPause,
326 &matrix) != LayoutToBeContinued) {
327 m_Status = Done;
328 }
329 }
330 }
331 if (m_TopIndent && m_Status == Done) {
332 m_pReflowPage->m_PageHeight -= m_TopIndent;
333 }
334 }
335 void CPDF_ProgressiveReflowPageParser::Clear() {
336 this->Init();
337 return;
338 }
339 FX_BOOL IPDF_ProgressiveReflowPageParser::IsTaggedPage(
340 CPDF_PageObjects* pPage) {
341 if (!pPage) {
342 return FALSE;
343 }
344 CPDF_StructTree* pPageTree =
345 CPDF_StructTree::LoadPage(pPage->m_pDocument, pPage->m_pFormDict);
346 if (pPageTree) {
347 int count = pPageTree->CountTopElements();
348 if (count) {
349 for (int i = 0; i < count; i++) {
350 CPDF_StructElement* pElm = pPageTree->GetTopElement(i);
351 if (pElm) {
352 delete pPageTree;
353 pPageTree = NULL;
354 return TRUE;
355 }
356 }
357 }
358 delete pPageTree;
359 pPageTree = NULL;
360 return FALSE;
361 }
362 return FALSE;
363 }
364 void CPDF_ProgressiveReflowPageParser::Start(IPDF_ReflowedPage* pReflowPage,
365 CPDF_Page* pPage,
366 FX_FLOAT topIndent,
367 FX_FLOAT fWidth,
368 FX_FLOAT fHeight,
369 IFX_Pause* pPause,
370 int flags) {
371 if (NULL == pReflowPage) {
372 m_Status = Failed;
373 return;
374 }
375 m_flags = flags;
376 m_pReflowPage = (CPDF_ReflowedPage*)pReflowPage;
377 m_pReflowPage->m_pPDFPage = pPage;
378 m_pReflowPage->ReleasePageObjsMemberShip();
379 m_pPDFPage = pPage;
380 m_TopIndent = topIndent;
381 m_pPause = pPause;
382 m_fScreenHeight = fHeight;
383 m_ReflowedWidth = fWidth;
384 m_pProvider =
385 IPDF_LayoutProvider::Create_LayoutProvider_TaggedPDF(m_pPDFPage);
386 LayoutStatus status = m_pProvider->StartLoad(pPause);
387 if (status == LayoutError) {
388 delete m_pProvider;
389 m_pProvider = IPDF_LayoutProvider::Create_LayoutProvider_AutoReflow(
390 m_pPDFPage, m_flags & RF_PARSER_READERORDER);
391 if (NULL == m_pProvider) {
392 m_Status = Failed;
393 return;
394 }
395 status = m_pProvider->StartLoad(pPause);
396 }
397 if (status == LayoutError) {
398 delete m_pProvider;
13 m_pProvider = NULL; 399 m_pProvider = NULL;
14 } 400 m_Status = Failed;
15 CPDF_ProgressiveReflowPageParser::~CPDF_ProgressiveReflowPageParser() 401 return;
16 { 402 }
17 if(m_pProvider) { 403 if (status == LayoutToBeContinued) {
18 delete m_pProvider; 404 m_Status = ToBeContinued;
19 } 405 } else if (status == LayoutFinished) {
406 m_pReflowEngine = IPDF_LayoutProcessor::Create_LayoutProcessor_Reflow(
407 topIndent,
408 fWidth,
409 fHeight,
410 pReflowPage,
411 m_flags,
412 m_ParseStyle.m_LineSpace);
413 if (NULL == m_pReflowEngine) {
414 delete m_pProvider;
415 m_pProvider = NULL;
416 m_Status = Failed;
417 return;
418 }
419 CFX_AffineMatrix matrix;
420 pPage->GetDisplayMatrix(matrix,
421 0,
422 0,
423 (int)(pPage->GetPageWidth()),
424 (int)(pPage->GetPageHeight()),
425 0);
426 CFX_AffineMatrix matrix1 = pPage->GetPageMatrix();
427 if ((status = m_pReflowEngine->StartProcess(
428 m_pProvider->GetRoot(), pPause, &matrix)) != LayoutToBeContinued) {
429 delete m_pReflowEngine;
430 m_pReflowEngine = NULL;
431 m_Status = Done;
432 } else {
433 m_Status = ToBeContinued;
434 }
435 }
436 if (status != LayoutToBeContinued) {
437 delete m_pProvider;
20 m_pProvider = NULL; 438 m_pProvider = NULL;
21 if(m_pReflowEngine) { 439 }
22 delete m_pReflowEngine; 440 if (m_TopIndent && m_Status == Done) {
23 } 441 m_pReflowPage->m_PageHeight -= m_TopIndent;
24 m_pReflowEngine = NULL; 442 }
25 } 443 return;
26 void CPDF_ProgressiveReflowPageParser::Init() 444 }
27 { 445 CPDF_ProgressiveReflowPageRender::~CPDF_ProgressiveReflowPageRender() {
28 m_Status = Ready; 446 if (m_pDisplayMatrix) {
29 } 447 delete m_pDisplayMatrix;
30 CPDF_ReflowedPage::CPDF_ReflowedPage(CFX_GrowOnlyPool*» pMemoryPool) 448 }
31 { 449 m_pDisplayMatrix = NULL;
32 m_PageWidth = 0; 450 }
33 m_PageHeight = 0; 451 CPDF_ProgressiveReflowPageRender::CPDF_ProgressiveReflowPageRender() {
34 m_bWaiting = TRUE; 452 m_Status = Ready;
35 if(pMemoryPool) { 453 m_pReflowPage = NULL;
36 m_pMemoryPool = pMemoryPool; 454 m_pDisplayMatrix = NULL;
37 m_bCreateMemoryPool = FALSE; 455 m_CurrNum = 0;
38 } else { 456 m_pFontEncoding = NULL;
39 m_pMemoryPool = FX_NEW CFX_GrowOnlyPool; 457 m_DisplayColor = -1;
40 m_bCreateMemoryPool = TRUE; 458 }
41 } 459 static FX_FLOAT _CIDTransformToFloat(FX_BYTE ch) {
42 m_pCharState = FX_NEW CRF_CharStateArray(10); 460 if (ch < 128) {
43 m_pReflowed = FX_NEW CRF_DataPtrArray(500); 461 return ch * 1.0f / 127;
44 m_pPageInfos = NULL; 462 }
45 } 463 return (-255 + ch) * 1.0f / 127;
46 CPDF_ReflowedPage::~CPDF_ReflowedPage() 464 }
47 { 465 int CPDF_ProgressiveReflowPageRender::GetPosition() {
48 if (m_pReflowed) { 466 if (m_CurrNum == 0 || NULL == m_pReflowPage) {
49 for(int i = 0; i < m_pReflowed->GetSize(); i++) { 467 return 0;
50 CRF_Data* pData = (*m_pReflowed)[i]; 468 }
51 if(pData->m_Type == CRF_Data::Image) { 469 int size = m_pReflowPage->m_pReflowed->GetSize();
52 delete ((CRF_ImageData*)pData)->m_pBitmap; 470 if (size == 0 || m_CurrNum >= size) {
53 } 471 return 100;
472 }
473 return (int)(m_CurrNum * 100 / size);
474 }
475 void CPDF_ProgressiveReflowPageRender::Display(IFX_Pause* pPause) {
476 if (NULL == m_pReflowPage) {
477 m_Status = Done;
478 return;
479 }
480 FX_RECT clipBox = m_pFXDevice->GetClipBox();
481 int size = m_pReflowPage->m_pReflowed->GetSize();
482 if (size < 1 || NULL == m_pDisplayMatrix) {
483 m_Status = Done;
484 return;
485 }
486 for (int i = m_CurrNum; i < size; i++) {
487 CRF_Data* pData = (*m_pReflowPage->m_pReflowed)[i];
488 if (!pData) {
489 continue;
490 }
491 CFX_FloatRect rect(pData->m_PosX,
492 pData->m_PosY + pData->m_Height,
493 pData->m_PosX + pData->m_Width,
494 pData->m_PosY);
495 m_pDisplayMatrix->TransformRect(rect);
496 if (rect.left > clipBox.right || rect.right < clipBox.left ||
497 rect.bottom > clipBox.bottom || rect.top < clipBox.top) {
498 continue;
499 }
500 if (pData->GetType() == CRF_Data::Text) {
501 CRF_CharData* pCharData = (CRF_CharData*)pData;
502 CPDF_Font* pPDFFont = pCharData->m_pCharState->m_pFont;
503 if (pPDFFont->GetFontType() == PDFFONT_TYPE3) {
504 continue;
505 }
506 FX_FLOAT x = pData->m_PosX,
507 y = pData->m_PosY - pCharData->m_pCharState->m_fDescent;
508 FXTEXT_CHARPOS charpos;
509 charpos.m_GlyphIndex = pPDFFont->GlyphFromCharCode(pCharData->m_CharCode);
510 charpos.m_FontCharWidth =
511 pPDFFont->m_Font.GetGlyphWidth(charpos.m_GlyphIndex);
512 charpos.m_OriginX = x;
513 charpos.m_OriginY = y;
514 FX_FLOAT charW = pData->m_Width * 1000 / pData->m_Height;
515 if (charW != charpos.m_FontCharWidth) {
516 charpos.m_bGlyphAdjust = TRUE;
517 charpos.m_AdjustMatrix[0] = charW / charpos.m_FontCharWidth;
518 charpos.m_AdjustMatrix[1] = 0;
519 charpos.m_AdjustMatrix[2] = 0;
520 charpos.m_AdjustMatrix[3] = 1;
521 } else {
522 charpos.m_bGlyphAdjust = FALSE;
523 }
524 FX_BOOL bRet = FALSE;
525 if (m_DisplayColor == -1)
526 bRet = m_pFXDevice->DrawNormalText(
527 1,
528 &charpos,
529 &(pPDFFont->m_Font),
530 NULL,
531 pCharData->m_pCharState->m_fFontSize,
532 m_pDisplayMatrix,
533 pCharData->m_pCharState->m_Color + 0xff000000,
534 FXTEXT_CLEARTYPE);
535 else
536 bRet = m_pFXDevice->DrawNormalText(1,
537 &charpos,
538 &(pPDFFont->m_Font),
539 NULL,
540 pCharData->m_pCharState->m_fFontSize,
541 m_pDisplayMatrix,
542 m_DisplayColor,
543 FXTEXT_CLEARTYPE);
544 } else if (pData->GetType() == CRF_Data::Image) {
545 CRF_ImageData* pImageData = (CRF_ImageData*)pData;
546 if (!pImageData->m_pBitmap) {
547 continue;
548 }
549 int left = 0, top = 0;
550 CFX_DIBitmap* pDiBmp = NULL;
551 CFX_DIBSource* pDispSource = pImageData->m_pBitmap;
552 if (pImageData->m_Matrix.d < 0) {
553 CFX_AffineMatrix matrix(
554 pImageData->m_Matrix.a, 0, 0, -pImageData->m_Matrix.d, 0, 0);
555 int left, top;
556 pDiBmp = pImageData->m_pBitmap->TransformTo(&matrix, left, top);
557 pDispSource = pDiBmp;
558 }
559 if (NULL == pDispSource) {
560 continue;
561 }
562 if (pDispSource->GetFormat() == FXDIB_1bppMask ||
563 pDispSource->GetFormat() == FXDIB_8bppMask) {
564 m_pFXDevice->StretchBitMask(pDispSource,
565 (int)(rect.left + 0.5),
566 (int)(rect.bottom + 0.5),
567 (int)(rect.Width() + 0.5),
568 (int)(rect.Height() + 0.5),
569 0xff000000);
570 } else {
571 m_pFXDevice->StretchDIBits(pDispSource,
572 (int)(rect.left + 0.5),
573 (int)(rect.bottom + 0.5),
574 (int)(rect.Width() + 0.5),
575 (int)(rect.Height() + 0.5));
576 }
577 if (m_pFXDevice->GetBitmap() &&
578 m_pFXDevice->GetBitmap()->GetFormat() == FXDIB_8bppRgb &&
579 m_pFXDevice->GetBitmap()->GetPalette() == NULL) {
580 int nPalette = 0;
581 switch (m_DitherBits) {
582 case 0:
583 nPalette = 0;
584 break;
585 case 1:
586 nPalette = 2;
587 break;
588 case 2:
589 nPalette = 4;
590 break;
591 case 3:
592 nPalette = 8;
593 break;
594 case 4:
595 nPalette = 16;
596 break;
597 case 5:
598 nPalette = 32;
599 break;
600 case 6:
601 nPalette = 64;
602 break;
603 case 7:
604 nPalette = 128;
605 break;
606 default:
607 nPalette = 256;
608 break;
54 } 609 }
55 m_pReflowed->RemoveAll(); 610 if (nPalette >= 2) {
56 delete m_pReflowed; 611 FX_ARGB* palette = FX_Alloc(FX_ARGB, nPalette);
57 } 612 nPalette--;
58 m_pReflowed = NULL; 613 palette[0] = 0;
59 if (m_pCharState) { 614 palette[nPalette] = 255;
60 m_pCharState->RemoveAll(); 615 FX_FLOAT Dither = (FX_FLOAT)255 / (nPalette);
61 delete m_pCharState; 616 for (int i = 1; i < nPalette; i++) {
62 } 617 palette[i] = (FX_ARGB)(Dither * i + 0.5);
63 m_pCharState = NULL; 618 }
64 if(m_bCreateMemoryPool && m_pMemoryPool) { 619 FX_RECT tmpRect = rect.GetOutterRect();
65 m_pMemoryPool->FreeAll(); 620 m_pFXDevice->GetBitmap()->DitherFS(palette, nPalette + 1, &tmpRect);
66 } 621 FX_Free(palette);
67 if (m_pMemoryPool) { 622 }
68 delete m_pMemoryPool; 623 }
69 } 624 if (pDiBmp) {
70 m_pMemoryPool = NULL; 625 delete pDiBmp;
71 m_pPDFPage = NULL; 626 }
72 if (m_pPageInfos) { 627 } else if (pData->GetType() == CRF_Data::Path) {
73 ReleasePageObjsMemberShip(); 628 }
74 } 629 if (!(i % 10)) {
75 } 630 if (pPause && pPause->NeedToPauseNow()) {
76 FX_BOOL CPDF_ReflowedPage::RetainPageObjsMemberShip() 631 i++;
77 { 632 m_CurrNum = i;
78 if (NULL == m_pPDFPage) { 633 m_Status = ToBeContinued;
79 return FALSE;
80 }
81 if (NULL == m_pPageInfos) {
82 m_pPageInfos = FX_NEW CFX_MapPtrToPtr();
83 } else {
84 return TRUE;
85 }
86 FX_POSITION»pos = m_pPDFPage->GetFirstObjectPosition();
87 if (!pos)» {
88 return FALSE;
89 }
90 CPDF_PageObject* pPageObj = NULL;
91 while (pos) {
92 pPageObj = m_pPDFPage->GetNextObject(pos);
93 MarkPageObjMemberShip(pPageObj, NULL);
94 pPageObj = NULL;
95 }
96 return TRUE;
97 }
98 void CPDF_ReflowedPage::MarkPageObjMemberShip(CPDF_PageObject* pObj, CRF_PageInf o* pParent)
99 {
100 if (NULL == m_pPageInfos) {
101 return; 634 return;
102 } 635 }
103 CRF_PageInfo* pPageInfo = FX_NEW CRF_PageInfo(pObj, pParent); 636 }
104 if (NULL == pPageInfo) { 637 }
105 return; 638 m_CurrNum = size;
106 } 639 m_Status = Done;
107 m_pPageInfos->SetAt(pObj, pPageInfo); 640 }
108 if (PDFPAGE_FORM != pObj->m_Type) { 641 void CPDF_ProgressiveReflowPageRender::Start(IPDF_ReflowedPage* pReflowPage,
109 return; 642 CFX_RenderDevice* pDevice,
110 } 643 const CFX_AffineMatrix* pMatrix,
111 CPDF_FormObject* pFormObj = (CPDF_FormObject*)pObj; 644 IFX_Pause* pPause,
112 FX_POSITION pos; 645 int DitherBits) {
113 pos = pFormObj->m_pForm->GetFirstObjectPosition(); 646 if (!pReflowPage || !pDevice || !pMatrix) {
114 if (!pos) { 647 m_Status = Failed;
115 return; 648 return;
116 } 649 }
117 CPDF_PageObject* pPageObj = NULL; 650 m_DitherBits = DitherBits;
118 while (pos) { 651 m_Status = Ready;
119 pPageObj = pFormObj->m_pForm->GetNextObject(pos); 652 m_CurrNum = 0;
120 MarkPageObjMemberShip(pPageObj, pPageInfo); 653 m_pReflowPage = (CPDF_ReflowedPage*)pReflowPage;
121 pPageObj = NULL; 654 m_pFXDevice = pDevice;
122 } 655 if (NULL == m_pDisplayMatrix) {
123 } 656 m_pDisplayMatrix = FX_NEW CFX_AffineMatrix;
124 void CPDF_ReflowedPage::ReleasePageObjsMemberShip() 657 }
125 { 658 if (m_pDisplayMatrix) {
126 if (NULL == m_pPageInfos) { 659 m_pDisplayMatrix->Copy(*pMatrix);
127 return; 660 }
128 } 661 m_Status = ToBeContinued;
129 CPDF_PageObject* pPageObj = NULL; 662 Display(pPause);
130 CRF_PageInfo* pPageInfo = NULL; 663 }
131 FX_POSITION pos = m_pPageInfos->GetStartPosition(); 664 void CPDF_ProgressiveReflowPageRender::Continue(IFX_Pause* pPause) {
132 while (pos) { 665 Display(pPause);
133 m_pPageInfos->GetNextAssoc(pos, (void*&)pPageObj, (void*&)pPageInfo); 666 }
134 delete pPageInfo; 667 void CPDF_ProgressiveReflowPageRender::SetDisplayColor(FX_COLORREF color) {
135 } 668 m_DisplayColor = color;
136 m_pPageInfos->RemoveAll(); 669 }
137 delete m_pPageInfos; 670 void CPDF_ProgressiveReflowPageRender::Clear() {
138 m_pPageInfos = NULL; 671 if (m_pDisplayMatrix) {
139 } 672 delete m_pDisplayMatrix;
140 CPDF_Dictionary* CPDF_ReflowedPage::GetFormResDict(CPDF_PageObject* pObj) 673 }
141 { 674 m_pDisplayMatrix = NULL;
142 if (NULL == m_pPageInfos) { 675 m_pReflowPage = NULL;
143 return NULL; 676 m_pFXDevice = NULL;
144 } 677 m_CurrNum = 0;
145 if (FALSE == RetainPageObjsMemberShip()) { 678 m_Status = Ready;
146 return NULL; 679 }
147 }
148 CRF_PageInfo* pPageInfo = (CRF_PageInfo*)m_pPageInfos->GetValueAt(pObj);
149 if (NULL == pPageInfo) {
150 return NULL;
151 }
152 return pPageInfo->GetFormDict();
153 }
154 void CPDF_ReflowedPage::GetDisplayMatrix(CFX_AffineMatrix& matrix, FX_INT32 xPos , FX_INT32 yPos, FX_INT32 xSize, FX_INT32 ySize, FX_INT32 iRotate, const CFX_Aff ineMatrix* pPageMatrix)
155 {
156 CFX_AffineMatrix display_matrix;
157 if(m_PageHeight == 0) {
158 matrix.Set(1, 0, 0, -1, 0, 0);
159 return;
160 }
161 FX_INT32 x0, y0, x1, y1, x2, y2;
162 iRotate %= 4;
163 switch (iRotate) {
164 case 0:
165 x0 = xPos;
166 y0 = yPos;
167 x1 = xPos;
168 y1 = yPos + ySize;
169 x2 = xPos + xSize;
170 y2 = yPos;
171 break;
172 case 3:
173 x0 = xPos;
174 y0 = ySize + yPos;
175 x1 = xPos + xSize;
176 y1 = yPos + ySize;
177 x2 = xPos;
178 y2 = yPos;
179 break;
180 case 2:
181 x0 = xSize + xPos;
182 y0 = ySize + yPos;
183 x1 = xSize + xPos ;
184 y1 = yPos;
185 x2 = xPos;
186 y2 = ySize + yPos;
187 break;
188 case 1:
189 x0 = xPos + xSize;
190 y0 = yPos;
191 x1 = xPos;
192 y1 = yPos;
193 x2 = xPos + xSize;
194 y2 = yPos + ySize;
195 break;
196 }
197 display_matrix.Set(FXSYS_Div((FX_FLOAT)(x2 - x0), m_PageWidth),
198 FXSYS_Div((FX_FLOAT)(y2 - y0), m_PageWidth),
199 FXSYS_Div((FX_FLOAT)(x1 - x0), m_PageHeight),
200 FXSYS_Div((FX_FLOAT)(y1 - y0), m_PageHeight),
201 (FX_FLOAT)(x0), (FX_FLOAT)(y0));
202 matrix.Set(1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f);
203 matrix.Concat(display_matrix);
204 return;
205 }
206 FX_FLOAT CPDF_ReflowedPage::GetPageHeight()
207 {
208 return m_PageHeight;
209 }
210 void CPDF_ReflowedPage::FocusGetData(const CFX_AffineMatrix matrix, FX_INT32 x, FX_INT32 y, CFX_ByteString& str)
211 {
212 if (NULL == m_pReflowed) {
213 return;
214 }
215 CFX_AffineMatrix revMatrix;
216 revMatrix.SetReverse(matrix);
217 FX_FLOAT x1, y1;
218 revMatrix.Transform((float)x, (float)y, x1, y1);
219 int count = m_pReflowed->GetSize();
220 FX_FLOAT dx = 1000, dy = 1000;
221 FX_INT32 pos = 0;
222 FX_INT32 i;
223 for(i = 0; i < count; i++) {
224 CRF_Data* pData = (*m_pReflowed)[i];
225 FX_FLOAT tempdy = FXSYS_fabs(pData->m_PosY - y1);
226 if(FXSYS_fabs(tempdy - dy) < 1) {
227 continue;
228 }
229 CFX_FloatRect rect (0, pData->m_PosY + pData->m_Height, this->m_PageWidt h, pData->m_PosY);
230 if(rect.Contains(x1, y1)) {
231 pos = i;
232 dx = 0;
233 dy = 0;
234 break;
235 } else if(tempdy < dy) {
236 dy = tempdy;
237 dx = FXSYS_fabs(pData->m_PosX - x1);
238 pos = i;
239 } else if (tempdy == dy) {
240 FX_FLOAT tempdx = FXSYS_fabs(pData->m_PosX - x1);
241 if(tempdx < dx) {
242 dx = tempdx;
243 pos = i;
244 }
245 } else if (tempdy > dy) {
246 break;
247 }
248 }
249 if(dx != 0 || dy != 0) {
250 count = count < (pos + 10) ? count : (pos + 10);
251 for(i = 0 > (pos - 10) ? 0 : (pos - 10); i < count; i++) {
252 CRF_Data* pData = (*m_pReflowed)[i];
253 FX_FLOAT tempdy = FXSYS_fabs(pData->m_PosY - y1);
254 if(tempdy < dy) {
255 dy = tempdy;
256 dx = FXSYS_fabs(pData->m_PosX - x1);
257 pos = i;
258 } else if (tempdy == dy) {
259 FX_FLOAT tempdx = FXSYS_fabs(pData->m_PosX - x1);
260 if(tempdx < dx) {
261 dx = tempdx;
262 pos = i;
263 }
264 }
265 }
266 }
267 str.Format("%d", pos);
268 }
269 FX_BOOL CPDF_ReflowedPage::FocusGetPosition(const CFX_AffineMatrix matrix, CFX_B yteString str, FX_INT32& x, FX_INT32& y)
270 {
271 if (NULL == m_pReflowed) {
272 return FALSE;
273 }
274 FX_INT32 pos = FXSYS_atoi(str);
275 if(pos < 0 || pos >= m_pReflowed->GetSize()) {
276 return FALSE;
277 }
278 CRF_Data* pData = (*m_pReflowed)[pos];
279 FX_FLOAT x1, y1;
280 matrix.Transform(pData->m_PosX, pData->m_PosY + pData->m_Height, x1, y1);
281 x = (int)x1;
282 y = (int)y1;
283 return TRUE;
284 }
285 int CPDF_ProgressiveReflowPageParser::GetPosition()
286 {
287 if(!m_pProvider) {
288 return 0;
289 }
290 if(!m_pReflowEngine) {
291 return m_pProvider->GetPosition() / 2;
292 }
293 return m_pProvider->GetPosition() / 2 + m_pReflowEngine->GetPosition() / 2;
294 }
295 void CPDF_ProgressiveReflowPageParser::Continue(IFX_Pause* pPause)
296 {
297 if (NULL == m_pReflowPage) {
298 return;
299 }
300 if(m_Status != ToBeContinued) {
301 return;
302 }
303 m_pPause = pPause;
304 if(m_pReflowEngine) {
305 if(m_pReflowEngine->Continue() != LayoutToBeContinued) {
306 m_Status = Done;
307 }
308 } else {
309 if(m_pProvider->Continue() == LayoutFinished) {
310 m_pReflowEngine = IPDF_LayoutProcessor::Create_LayoutProcessor_Reflo w(m_TopIndent, m_ReflowedWidth, m_fScreenHeight, m_pReflowPage, m_flags, m_Parse Style.m_LineSpace);
311 CFX_AffineMatrix matrix;
312 m_pPDFPage->GetDisplayMatrix(matrix, 0, 0, (int)(m_pPDFPage->GetPage Width()), (int)(m_pPDFPage->GetPageHeight()), 0);
313 if(m_pReflowEngine->StartProcess(m_pProvider->GetRoot(), m_pPause, & matrix) != LayoutToBeContinued) {
314 m_Status = Done;
315 }
316 }
317 }
318 if(m_TopIndent && m_Status == Done) {
319 m_pReflowPage->m_PageHeight -= m_TopIndent;
320 }
321 }
322 void CPDF_ProgressiveReflowPageParser::Clear()
323 {
324 this->Init();
325 return;
326 }
327 FX_BOOL IPDF_ProgressiveReflowPageParser::IsTaggedPage(CPDF_PageObjects*pPage)
328 {
329 if(!pPage) {
330 return FALSE;
331 }
332 CPDF_StructTree* pPageTree = CPDF_StructTree::LoadPage(pPage->m_pDocument, p Page->m_pFormDict);
333 if(pPageTree) {
334 int count = pPageTree->CountTopElements();
335 if(count) {
336 for(int i = 0; i < count; i++) {
337 CPDF_StructElement* pElm = pPageTree->GetTopElement(i);
338 if(pElm) {
339 delete pPageTree;
340 pPageTree = NULL;
341 return TRUE;
342 }
343 }
344 }
345 delete pPageTree;
346 pPageTree = NULL;
347 return FALSE;
348 }
349 return FALSE;
350 }
351 void CPDF_ProgressiveReflowPageParser::Start(IPDF_ReflowedPage* pReflowPage, CPD F_Page* pPage, FX_FLOAT topIndent, FX_FLOAT fWidth, FX_FLOAT fHeight, IFX_Pause* pPause, int flags)
352 {
353 if (NULL == pReflowPage) {
354 m_Status = Failed;
355 return;
356 }
357 m_flags = flags;
358 m_pReflowPage = (CPDF_ReflowedPage*)pReflowPage;
359 m_pReflowPage->m_pPDFPage = pPage;
360 m_pReflowPage->ReleasePageObjsMemberShip();
361 m_pPDFPage = pPage;
362 m_TopIndent = topIndent;
363 m_pPause = pPause;
364 m_fScreenHeight = fHeight;
365 m_ReflowedWidth = fWidth;
366 m_pProvider = IPDF_LayoutProvider::Create_LayoutProvider_TaggedPDF(m_pPDFPag e);
367 LayoutStatus status = m_pProvider->StartLoad(pPause);
368 if(status == LayoutError) {
369 delete m_pProvider;
370 m_pProvider = IPDF_LayoutProvider::Create_LayoutProvider_AutoReflow(m_pP DFPage, m_flags & RF_PARSER_READERORDER);
371 if (NULL == m_pProvider) {
372 m_Status = Failed;
373 return;
374 }
375 status = m_pProvider->StartLoad(pPause);
376 }
377 if(status == LayoutError) {
378 delete m_pProvider;
379 m_pProvider = NULL;
380 m_Status = Failed;
381 return;
382 }
383 if(status == LayoutToBeContinued) {
384 m_Status = ToBeContinued;
385 } else if (status == LayoutFinished) {
386 m_pReflowEngine = IPDF_LayoutProcessor::Create_LayoutProcessor_Reflow(to pIndent, fWidth, fHeight, pReflowPage, m_flags, m_ParseStyle.m_LineSpace);
387 if(NULL == m_pReflowEngine) {
388 delete m_pProvider;
389 m_pProvider = NULL;
390 m_Status = Failed;
391 return;
392 }
393 CFX_AffineMatrix matrix;
394 pPage->GetDisplayMatrix(matrix, 0, 0, (int)(pPage->GetPageWidth()), (int )(pPage->GetPageHeight()), 0);
395 CFX_AffineMatrix matrix1 = pPage->GetPageMatrix();
396 if((status = m_pReflowEngine->StartProcess(m_pProvider->GetRoot(), pPaus e, &matrix)) != LayoutToBeContinued) {
397 delete m_pReflowEngine;
398 m_pReflowEngine = NULL;
399 m_Status = Done;
400 } else {
401 m_Status = ToBeContinued;
402 }
403 }
404 if(status != LayoutToBeContinued) {
405 delete m_pProvider;
406 m_pProvider = NULL;
407 }
408 if(m_TopIndent && m_Status == Done) {
409 m_pReflowPage->m_PageHeight -= m_TopIndent;
410 }
411 return;
412 }
413 CPDF_ProgressiveReflowPageRender::~CPDF_ProgressiveReflowPageRender()
414 {
415 if(m_pDisplayMatrix) {
416 delete m_pDisplayMatrix;
417 }
418 m_pDisplayMatrix = NULL;
419 }
420 CPDF_ProgressiveReflowPageRender::CPDF_ProgressiveReflowPageRender()
421 {
422 m_Status = Ready;
423 m_pReflowPage = NULL;
424 m_pDisplayMatrix = NULL;
425 m_CurrNum = 0;
426 m_pFontEncoding = NULL;
427 m_DisplayColor = -1;
428 }
429 static FX_FLOAT _CIDTransformToFloat(FX_BYTE ch)
430 {
431 if (ch < 128) {
432 return ch * 1.0f / 127;
433 }
434 return (-255 + ch) * 1.0f / 127;
435 }
436 int CPDF_ProgressiveReflowPageRender::GetPosition()
437 {
438 if(m_CurrNum == 0 || NULL == m_pReflowPage) {
439 return 0;
440 }
441 int size = m_pReflowPage->m_pReflowed->GetSize();
442 if(size == 0 || m_CurrNum >= size) {
443 return 100;
444 }
445 return (int)(m_CurrNum * 100 / size);
446 }
447 void CPDF_ProgressiveReflowPageRender::Display(IFX_Pause* pPause)
448 {
449 if (NULL == m_pReflowPage) {
450 m_Status = Done;
451 return;
452 }
453 FX_RECT clipBox = m_pFXDevice->GetClipBox();
454 int size = m_pReflowPage->m_pReflowed->GetSize();
455 if (size < 1 || NULL == m_pDisplayMatrix) {
456 m_Status = Done;
457 return;
458 }
459 for(int i = m_CurrNum; i < size; i++) {
460 CRF_Data* pData = (*m_pReflowPage->m_pReflowed)[i];
461 if(!pData) {
462 continue;
463 }
464 CFX_FloatRect rect (pData->m_PosX, pData->m_PosY + pData->m_Height, pDat a->m_PosX + pData->m_Width, pData->m_PosY);
465 m_pDisplayMatrix->TransformRect(rect);
466 if(rect.left > clipBox.right || rect.right < clipBox.left || rect.bottom > clipBox.bottom || rect.top < clipBox.top) {
467 continue;
468 }
469 if(pData->GetType() == CRF_Data::Text) {
470 CRF_CharData* pCharData = (CRF_CharData*)pData;
471 CPDF_Font* pPDFFont = pCharData->m_pCharState->m_pFont;
472 if(pPDFFont->GetFontType() == PDFFONT_TYPE3) {
473 continue;
474 }
475 FX_FLOAT x = pData->m_PosX, y = pData->m_PosY - pCharData->m_pCharSt ate->m_fDescent;
476 FXTEXT_CHARPOS charpos ;
477 charpos.m_GlyphIndex = pPDFFont->GlyphFromCharCode(pCharData->m_Char Code);
478 charpos.m_FontCharWidth = pPDFFont->m_Font.GetGlyphWidth(charpos.m_G lyphIndex);
479 charpos.m_OriginX = x;
480 charpos.m_OriginY = y;
481 FX_FLOAT charW = pData->m_Width * 1000 / pData->m_Height;
482 if(charW != charpos.m_FontCharWidth) {
483 charpos.m_bGlyphAdjust = TRUE;
484 charpos.m_AdjustMatrix[0] = charW / charpos.m_FontCharWidth;
485 charpos.m_AdjustMatrix[1] = 0;
486 charpos.m_AdjustMatrix[2] = 0;
487 charpos.m_AdjustMatrix[3] = 1;
488 } else {
489 charpos.m_bGlyphAdjust = FALSE;
490 }
491 FX_BOOL bRet = FALSE;
492 if(m_DisplayColor == -1)
493 bRet = m_pFXDevice->DrawNormalText(1, &charpos, &(pPDFFont->m_Fo nt),
494 NULL, pCharData->m_pCharState ->m_fFontSize,
495 m_pDisplayMatrix, pCharData-> m_pCharState->m_Color + 0xff000000, FXTEXT_CLEARTYPE);
496 else
497 bRet = m_pFXDevice->DrawNormalText(1, &charpos, &(pPDFFont->m_Fo nt),
498 NULL, pCharData->m_pCharState ->m_fFontSize, m_pDisplayMatrix, m_DisplayColor, FXTEXT_CLEARTYPE);
499 } else if(pData->GetType() == CRF_Data::Image) {
500 CRF_ImageData* pImageData = (CRF_ImageData*)pData;
501 if(!pImageData->m_pBitmap) {
502 continue;
503 }
504 int left = 0, top = 0;
505 CFX_DIBitmap* pDiBmp = NULL;
506 CFX_DIBSource* pDispSource = pImageData->m_pBitmap;
507 if(pImageData->m_Matrix.d < 0) {
508 CFX_AffineMatrix matrix(pImageData->m_Matrix.a, 0, 0, -pImageDat a->m_Matrix.d, 0, 0);
509 int left, top;
510 pDiBmp = pImageData->m_pBitmap->TransformTo(&matrix, left, top);
511 pDispSource = pDiBmp;
512 }
513 if (NULL == pDispSource) {
514 continue;
515 }
516 if (pDispSource->GetFormat() == FXDIB_1bppMask || pDispSource->GetFo rmat() == FXDIB_8bppMask) {
517 m_pFXDevice->StretchBitMask(pDispSource, (int)(rect.left + 0.5), (int)(rect.bottom + 0.5), (int)(rect.Width() + 0.5), (int)(rect.Height() + 0.5) , 0xff000000);
518 } else {
519 m_pFXDevice->StretchDIBits(pDispSource, (int)(rect.left + 0.5), (int)(rect.bottom + 0.5), (int)(rect.Width() + 0.5), (int)(rect.Height() + 0.5)) ;
520 }
521 if(m_pFXDevice->GetBitmap() && m_pFXDevice->GetBitmap()->GetFormat() == FXDIB_8bppRgb &&
522 m_pFXDevice->GetBitmap()->GetPalette() == NULL) {
523 int nPalette = 0;
524 switch(m_DitherBits) {
525 case 0:
526 nPalette = 0;
527 break;
528 case 1:
529 nPalette = 2;
530 break;
531 case 2:
532 nPalette = 4;
533 break;
534 case 3:
535 nPalette = 8;
536 break;
537 case 4:
538 nPalette = 16;
539 break;
540 case 5:
541 nPalette = 32;
542 break;
543 case 6:
544 nPalette = 64;
545 break;
546 case 7:
547 nPalette = 128;
548 break;
549 default:
550 nPalette = 256;
551 break;
552 }
553 if(nPalette >= 2) {
554 FX_ARGB * palette = FX_Alloc(FX_ARGB, nPalette);
555 nPalette --;
556 palette[0] = 0;
557 palette[nPalette] = 255;
558 FX_FLOAT Dither = (FX_FLOAT)255 / (nPalette);
559 for(int i = 1; i < nPalette; i++) {
560 palette[i] = (FX_ARGB)(Dither * i + 0.5);
561 }
562 FX_RECT tmpRect = rect.GetOutterRect();
563 m_pFXDevice->GetBitmap()->DitherFS(palette, nPalette + 1, &t mpRect);
564 FX_Free (palette);
565 }
566 }
567 if(pDiBmp) {
568 delete pDiBmp;
569 }
570 } else if(pData->GetType() == CRF_Data::Path) {
571 }
572 if(!(i % 10)) {
573 if(pPause && pPause->NeedToPauseNow()) {
574 i++;
575 m_CurrNum = i;
576 m_Status = ToBeContinued;
577 return;
578 }
579 }
580 }
581 m_CurrNum = size;
582 m_Status = Done;
583 }
584 void CPDF_ProgressiveReflowPageRender::Start(IPDF_ReflowedPage* pReflowPage, CFX _RenderDevice* pDevice, const CFX_AffineMatrix* pMatrix, IFX_Pause* pPause, int DitherBits)
585 {
586 if(!pReflowPage || !pDevice || !pMatrix) {
587 m_Status = Failed;
588 return;
589 }
590 m_DitherBits = DitherBits;
591 m_Status = Ready;
592 m_CurrNum = 0;
593 m_pReflowPage = (CPDF_ReflowedPage*)pReflowPage;
594 m_pFXDevice = pDevice;
595 if(NULL == m_pDisplayMatrix) {
596 m_pDisplayMatrix = FX_NEW CFX_AffineMatrix;
597 }
598 if (m_pDisplayMatrix) {
599 m_pDisplayMatrix->Copy(*pMatrix);
600 }
601 m_Status = ToBeContinued;
602 Display(pPause);
603 }
604 void CPDF_ProgressiveReflowPageRender::Continue(IFX_Pause* pPause)
605 {
606 Display(pPause);
607 }
608 void CPDF_ProgressiveReflowPageRender::SetDisplayColor(FX_COLORREF color)
609 {
610 m_DisplayColor = color;
611 }
612 void CPDF_ProgressiveReflowPageRender::Clear()
613 {
614 if (m_pDisplayMatrix) {
615 delete m_pDisplayMatrix;
616 }
617 m_pDisplayMatrix = NULL;
618 m_pReflowPage = NULL;
619 m_pFXDevice = NULL;
620 m_CurrNum = 0;
621 m_Status = Ready;
622 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698