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/reflow/reflowengine.h" | 7 #include "../../include/reflow/reflowengine.h" |
8 #include "reflowedpage.h" | 8 #include "reflowedpage.h" |
9 #include "layoutprovider_taggedpdf.h" | 9 #include "layoutprovider_taggedpdf.h" |
10 IPDF_LayoutProcessor* IPDF_LayoutProcessor::Create_LayoutProcessor_Reflow(FX_FLO
AT TopIndent, FX_FLOAT fWidth, FX_FLOAT fHeight, void* pReflowedPage, int flags,
FX_FLOAT lineSpace ) | 10 IPDF_LayoutProcessor* IPDF_LayoutProcessor::Create_LayoutProcessor_Reflow(FX_FLO
AT TopIndent, FX_FLOAT fWidth, FX_FLOAT fHeight, void* pReflowedPage, int flags,
FX_FLOAT lineSpace ) |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 if(!GetIntersection(Rect1.left, Rect1.right, Rect2.left, Rect2.right, in
ter_left, inter_right)) { | 400 if(!GetIntersection(Rect1.left, Rect1.right, Rect2.left, Rect2.right, in
ter_left, inter_right)) { |
401 return FALSE; | 401 return FALSE; |
402 } | 402 } |
403 FX_FLOAT inter_w = inter_right - inter_left; | 403 FX_FLOAT inter_w = inter_right - inter_left; |
404 if (inter_w < (Rect1.right - Rect1.left) / 2 && inter_w < (Rect2.right -
Rect2.left) / 2) { | 404 if (inter_w < (Rect1.right - Rect1.left) / 2 && inter_w < (Rect2.right -
Rect2.left) / 2) { |
405 return FALSE; | 405 return FALSE; |
406 } | 406 } |
407 } | 407 } |
408 return TRUE; | 408 return TRUE; |
409 } | 409 } |
410 FX_INT32 IsCanMergeParagraph(IPDF_LayoutElement* pPrevElement, IPDF_LayoutElemen
t* pNextElement) | 410 int32_t IsCanMergeParagraph(IPDF_LayoutElement* pPrevElement, IPDF_LayoutElement
* pNextElement) |
411 { | 411 { |
412 FX_INT32 analogial = 100; | 412 int32_t analogial = 100; |
413 FX_INT32 nPrevObj = pPrevElement->CountObjects(), i; | 413 int32_t nPrevObj = pPrevElement->CountObjects(), i; |
414 CPDF_PageObject* pPrevObj = NULL; | 414 CPDF_PageObject* pPrevObj = NULL; |
415 CFX_FloatRect prevRect, rect; | 415 CFX_FloatRect prevRect, rect; |
416 CFX_PtrArray prevLine, line; | 416 CFX_PtrArray prevLine, line; |
417 FX_BOOL bParagraphStart = FALSE; | 417 FX_BOOL bParagraphStart = FALSE; |
418 for(i = 0; i < nPrevObj; i++) { | 418 for(i = 0; i < nPrevObj; i++) { |
419 CPDF_PageObject* pObj = pPrevElement->GetObject(i); | 419 CPDF_PageObject* pObj = pPrevElement->GetObject(i); |
420 if(!pPrevObj) { | 420 if(!pPrevObj) { |
421 pPrevObj = pObj; | 421 pPrevObj = pObj; |
422 rect = CFX_FloatRect(pObj->m_Left, pObj->m_Bottom, pObj->m_Right, pO
bj->m_Top); | 422 rect = CFX_FloatRect(pObj->m_Left, pObj->m_Bottom, pObj->m_Right, pO
bj->m_Top); |
423 line.Add(pObj); | 423 line.Add(pObj); |
(...skipping 18 matching lines...) Expand all Loading... |
442 } | 442 } |
443 } | 443 } |
444 if(prevLine.GetSize()) { | 444 if(prevLine.GetSize()) { |
445 if(FXSYS_fabs(rect.right - prevRect.right) > rect.Height()) { | 445 if(FXSYS_fabs(rect.right - prevRect.right) > rect.Height()) { |
446 analogial -= 50; | 446 analogial -= 50; |
447 } | 447 } |
448 } | 448 } |
449 CPDF_PageObject* pObj = pPrevElement->GetObject(nPrevObj - 1); | 449 CPDF_PageObject* pObj = pPrevElement->GetObject(nPrevObj - 1); |
450 if(pObj->m_Type == PDFPAGE_TEXT) { | 450 if(pObj->m_Type == PDFPAGE_TEXT) { |
451 CPDF_TextObject* pText = (CPDF_TextObject*)pObj; | 451 CPDF_TextObject* pText = (CPDF_TextObject*)pObj; |
452 FX_INT32 nItem = pText->CountItems(); | 452 int32_t nItem = pText->CountItems(); |
453 CPDF_TextObjectItem item; | 453 CPDF_TextObjectItem item; |
454 pText->GetItemInfo(nItem - 1, &item); | 454 pText->GetItemInfo(nItem - 1, &item); |
455 CFX_WideString wStr = pText->GetFont()->UnicodeFromCharCode(item.m_CharC
ode); | 455 CFX_WideString wStr = pText->GetFont()->UnicodeFromCharCode(item.m_CharC
ode); |
456 if(wStr.IsEmpty()) { | 456 if(wStr.IsEmpty()) { |
457 wStr = (FX_WCHAR)item.m_CharCode; | 457 wStr = (FX_WCHAR)item.m_CharCode; |
458 } | 458 } |
459 FX_WCHAR wch = wStr.GetAt(wStr.GetLength() - 1); | 459 FX_WCHAR wch = wStr.GetAt(wStr.GetLength() - 1); |
460 switch(wch) { | 460 switch(wch) { |
461 case '.': | 461 case '.': |
462 case 12290: | 462 case 12290: |
463 case 65311: | 463 case 65311: |
464 case 63: | 464 case 63: |
465 case 33: | 465 case 33: |
466 case 65281: | 466 case 65281: |
467 analogial -= 50; | 467 analogial -= 50; |
468 break; | 468 break; |
469 } | 469 } |
470 } | 470 } |
471 prevLine.RemoveAll(); | 471 prevLine.RemoveAll(); |
472 prevLine.Append(line); | 472 prevLine.Append(line); |
473 line.RemoveAll(); | 473 line.RemoveAll(); |
474 FX_INT32 nNextObj = pNextElement->CountObjects(); | 474 int32_t nNextObj = pNextElement->CountObjects(); |
475 pPrevObj = NULL; | 475 pPrevObj = NULL; |
476 FX_BOOL bFirst = TRUE; | 476 FX_BOOL bFirst = TRUE; |
477 for(i = 0; i < nNextObj; i++) { | 477 for(i = 0; i < nNextObj; i++) { |
478 CPDF_PageObject* pObj = pNextElement->GetObject(i); | 478 CPDF_PageObject* pObj = pNextElement->GetObject(i); |
479 if(!pPrevObj) { | 479 if(!pPrevObj) { |
480 pPrevObj = pObj; | 480 pPrevObj = pObj; |
481 rect = CFX_FloatRect(pObj->m_Left, pObj->m_Bottom, pObj->m_Right, pO
bj->m_Top); | 481 rect = CFX_FloatRect(pObj->m_Left, pObj->m_Bottom, pObj->m_Right, pO
bj->m_Top); |
482 line.Add(pObj); | 482 line.Add(pObj); |
483 continue; | 483 continue; |
484 } | 484 } |
(...skipping 30 matching lines...) Expand all Loading... |
515 } | 515 } |
516 return analogial; | 516 return analogial; |
517 } | 517 } |
518 void CPDF_LayoutProcessor_Reflow::ProcessElement(IPDF_LayoutElement* pElement, F
X_FLOAT reflowWidth) | 518 void CPDF_LayoutProcessor_Reflow::ProcessElement(IPDF_LayoutElement* pElement, F
X_FLOAT reflowWidth) |
519 { | 519 { |
520 if(pElement == NULL) { | 520 if(pElement == NULL) { |
521 return; | 521 return; |
522 } | 522 } |
523 if(m_Status == LayoutReady) { | 523 if(m_Status == LayoutReady) { |
524 LayoutType layoutType = pElement->GetType(); | 524 LayoutType layoutType = pElement->GetType(); |
525 FX_INT32 ElementType = GetElementTypes(layoutType); | 525 int32_t ElementType = GetElementTypes(layoutType); |
526 switch(ElementType) { | 526 switch(ElementType) { |
527 case SST_IE: | 527 case SST_IE: |
528 m_bIllustration = TRUE; | 528 m_bIllustration = TRUE; |
529 break; | 529 break; |
530 case SST_BLSE: | 530 case SST_BLSE: |
531 FinishedCurrLine(); | 531 FinishedCurrLine(); |
532 FX_FLOAT StartIndent = 0; | 532 FX_FLOAT StartIndent = 0; |
533 if(IPDF_LayoutElement* pParent = pElement->GetParent()) { | 533 if(IPDF_LayoutElement* pParent = pElement->GetParent()) { |
534 StartIndent = pParent->GetNumberAttr(LayoutStartIndent); | 534 StartIndent = pParent->GetNumberAttr(LayoutStartIndent); |
535 } | 535 } |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 return ; | 638 return ; |
639 } | 639 } |
640 } | 640 } |
641 if(m_Status == LayoutToBeContinued && m_pLayoutElement == pChildElement)
{ | 641 if(m_Status == LayoutToBeContinued && m_pLayoutElement == pChildElement)
{ |
642 m_Status = LayoutReady; | 642 m_Status = LayoutReady; |
643 } | 643 } |
644 } | 644 } |
645 if(m_Status == LayoutReady) { | 645 if(m_Status == LayoutReady) { |
646 FX_FLOAT dx = 0; | 646 FX_FLOAT dx = 0; |
647 LayoutType layoutType = pElement->GetType(); | 647 LayoutType layoutType = pElement->GetType(); |
648 FX_INT32 ElementType = GetElementTypes(layoutType); | 648 int32_t ElementType = GetElementTypes(layoutType); |
649 switch(ElementType) { | 649 switch(ElementType) { |
650 case SST_IE: | 650 case SST_IE: |
651 m_bIllustration = FALSE; | 651 m_bIllustration = FALSE; |
652 FinishedCurrLine(); | 652 FinishedCurrLine(); |
653 break; | 653 break; |
654 case SST_BLSE: | 654 case SST_BLSE: |
655 FinishedCurrLine(); | 655 FinishedCurrLine(); |
656 FX_FLOAT StartIndent = 0; | 656 FX_FLOAT StartIndent = 0; |
657 if(IPDF_LayoutElement* pParent = pElement->GetParent()) { | 657 if(IPDF_LayoutElement* pParent = pElement->GetParent()) { |
658 StartIndent = pParent->GetNumberAttr(LayoutStartIndent); | 658 StartIndent = pParent->GetNumberAttr(LayoutStartIndent); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
704 CFX_AffineMatrix matrix(1, 0, 0, 1, dx, 0); | 704 CFX_AffineMatrix matrix(1, 0, 0, 1, dx, 0); |
705 int ReflowedSize = m_pReflowedPage->m_pReflowed->GetSize(); | 705 int ReflowedSize = m_pReflowedPage->m_pReflowed->GetSize(); |
706 Transform(&matrix, m_pReflowedPage->m_pReflowed, ReflowedSiz
e, m_pReflowedPage->m_pReflowed->GetSize() - ReflowedSize); | 706 Transform(&matrix, m_pReflowedPage->m_pReflowed, ReflowedSiz
e, m_pReflowedPage->m_pReflowed->GetSize() - ReflowedSize); |
707 } | 707 } |
708 } | 708 } |
709 } | 709 } |
710 if(m_pRootElement == pElement) { | 710 if(m_pRootElement == pElement) { |
711 m_PausePosition = 100; | 711 m_PausePosition = 100; |
712 } | 712 } |
713 } | 713 } |
714 FX_INT32 CPDF_LayoutProcessor_Reflow::GetElementTypes(LayoutType layoutType) | 714 int32_t CPDF_LayoutProcessor_Reflow::GetElementTypes(LayoutType layoutType) |
715 { | 715 { |
716 switch(layoutType) { | 716 switch(layoutType) { |
717 case LayoutParagraph: | 717 case LayoutParagraph: |
718 case LayoutHeading: | 718 case LayoutHeading: |
719 case LayoutHeading1: | 719 case LayoutHeading1: |
720 case LayoutHeading2: | 720 case LayoutHeading2: |
721 case LayoutHeading3: | 721 case LayoutHeading3: |
722 case LayoutHeading4: | 722 case LayoutHeading4: |
723 case LayoutHeading5: | 723 case LayoutHeading5: |
724 case LayoutHeading6: | 724 case LayoutHeading6: |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1203 if (preChar != L' ') { | 1203 if (preChar != L' ') { |
1204 return 1; | 1204 return 1; |
1205 } | 1205 } |
1206 return 2; | 1206 return 2; |
1207 } | 1207 } |
1208 if ((x - last_pos - last_width) > threshold && curChar != L' ' && preChar !=
L' ') { | 1208 if ((x - last_pos - last_width) > threshold && curChar != L' ' && preChar !=
L' ') { |
1209 return 1; | 1209 return 1; |
1210 } | 1210 } |
1211 return 0; | 1211 return 0; |
1212 } | 1212 } |
1213 FX_INT32 CPDF_LayoutProcessor_Reflow::LogicPreObj(CPDF_TextObject* pObj) | 1213 int32_t CPDF_LayoutProcessor_Reflow::LogicPreObj(CPDF_TextObject* pObj) |
1214 { | 1214 { |
1215 CPDF_TextObject* pPreObj = m_pPreObj; | 1215 CPDF_TextObject* pPreObj = m_pPreObj; |
1216 m_pPreObj = pObj; | 1216 m_pPreObj = pObj; |
1217 if(!pObj || !pPreObj) { | 1217 if(!pObj || !pPreObj) { |
1218 return 0; | 1218 return 0; |
1219 } | 1219 } |
1220 CPDF_TextObjectItem item; | 1220 CPDF_TextObjectItem item; |
1221 pPreObj->GetItemInfo(pPreObj->CountItems() - 1, &item); | 1221 pPreObj->GetItemInfo(pPreObj->CountItems() - 1, &item); |
1222 FX_FLOAT last_pos = item.m_OriginX; | 1222 FX_FLOAT last_pos = item.m_OriginX; |
1223 FX_FLOAT last_width = pPreObj->GetFont()->GetCharWidthF(item.m_CharCode) * p
PreObj->GetFontSize() / 1000; | 1223 FX_FLOAT last_width = pPreObj->GetFont()->GetCharWidthF(item.m_CharCode) * p
PreObj->GetFontSize() / 1000; |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1340 } | 1340 } |
1341 void CPDF_LayoutProcessor_Reflow::ProcessTextObject(CPDF_TextObject *pTextObj, F
X_FLOAT reflowWidth, CFX_AffineMatrix objMatrix) | 1341 void CPDF_LayoutProcessor_Reflow::ProcessTextObject(CPDF_TextObject *pTextObj, F
X_FLOAT reflowWidth, CFX_AffineMatrix objMatrix) |
1342 { | 1342 { |
1343 if(reflowWidth < 0 || !m_pCurrLine || !m_pTempLine) { | 1343 if(reflowWidth < 0 || !m_pCurrLine || !m_pTempLine) { |
1344 return; | 1344 return; |
1345 } | 1345 } |
1346 if(IsSameTextObject(pTextObj, m_pPreObj)) { | 1346 if(IsSameTextObject(pTextObj, m_pPreObj)) { |
1347 return; | 1347 return; |
1348 } | 1348 } |
1349 CPDF_PageObject* pPreObj = m_pPreObj; | 1349 CPDF_PageObject* pPreObj = m_pPreObj; |
1350 FX_INT32 logic = ProcessInsertObject(pTextObj, objMatrix); | 1350 int32_t logic = ProcessInsertObject(pTextObj, objMatrix); |
1351 m_pPreObj = pTextObj; | 1351 m_pPreObj = pTextObj; |
1352 m_perMatrix.Copy(objMatrix); | 1352 m_perMatrix.Copy(objMatrix); |
1353 int size = m_pTempLine->GetSize(); | 1353 int size = m_pTempLine->GetSize(); |
1354 int curs = m_pCurrLine->GetSize(); | 1354 int curs = m_pCurrLine->GetSize(); |
1355 CreateRFData(pTextObj); | 1355 CreateRFData(pTextObj); |
1356 size = m_pTempLine->GetSize(); | 1356 size = m_pTempLine->GetSize(); |
1357 int reds = m_pReflowedPage->m_pReflowed->GetSize(); | 1357 int reds = m_pReflowedPage->m_pReflowed->GetSize(); |
1358 if(size == 0) { | 1358 if(size == 0) { |
1359 return; | 1359 return; |
1360 } | 1360 } |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1535 FinishedCurrLine(); | 1535 FinishedCurrLine(); |
1536 FX_FLOAT f = reflowWidth / ObjWidth ; | 1536 FX_FLOAT f = reflowWidth / ObjWidth ; |
1537 matrix.Set(f, 0, 0, f, 0, 0); | 1537 matrix.Set(f, 0, 0, f, 0, 0); |
1538 } | 1538 } |
1539 CFX_AffineMatrix tempMatrix = matrix; | 1539 CFX_AffineMatrix tempMatrix = matrix; |
1540 matrix.Concat(objMatrix); | 1540 matrix.Concat(objMatrix); |
1541 FX_POSITION pos = pObjs->GetFirstObjectPosition(); | 1541 FX_POSITION pos = pObjs->GetFirstObjectPosition(); |
1542 while(pos) { | 1542 while(pos) { |
1543 CPDF_PageObject* pObj = pObjs->GetNextObject(pos); | 1543 CPDF_PageObject* pObj = pObjs->GetNextObject(pos); |
1544 if(pObj->m_Type == PDFPAGE_TEXT) { | 1544 if(pObj->m_Type == PDFPAGE_TEXT) { |
1545 FX_INT32 ret = LogicPreObj((CPDF_TextObject*)pObj); | 1545 int32_t ret = LogicPreObj((CPDF_TextObject*)pObj); |
1546 if(ret == 1 || ret == 2) { | 1546 if(ret == 1 || ret == 2) { |
1547 continue; | 1547 continue; |
1548 } | 1548 } |
1549 } | 1549 } |
1550 CreateRFData(pObj, &matrix); | 1550 CreateRFData(pObj, &matrix); |
1551 } | 1551 } |
1552 if (m_pTempLine) { | 1552 if (m_pTempLine) { |
1553 Transform(&tempMatrix, m_pTempLine, 0, m_pTempLine->GetSize()); | 1553 Transform(&tempMatrix, m_pTempLine, 0, m_pTempLine->GetSize()); |
1554 AddTemp2CurrLine(0, m_pTempLine->GetSize()); | 1554 AddTemp2CurrLine(0, m_pTempLine->GetSize()); |
1555 m_pTempLine->RemoveAll(); | 1555 m_pTempLine->RemoveAll(); |
1556 } | 1556 } |
1557 } | 1557 } |
1558 void CPDF_LayoutProcessor_Reflow::ProcessPathObject(CPDF_PathObject *pObj, FX_FL
OAT reflowWidth) | 1558 void CPDF_LayoutProcessor_Reflow::ProcessPathObject(CPDF_PathObject *pObj, FX_FL
OAT reflowWidth) |
1559 { | 1559 { |
1560 } | 1560 } |
OLD | NEW |