| OLD | NEW |
| 1 // Copyright 2017 PDFium Authors. All rights reserved. | 1 // Copyright 2017 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 "xfa/fxfa/app/cxfa_textlayout.h" | 7 #include "xfa/fxfa/app/cxfa_textlayout.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <utility> |
| 10 | 11 |
| 11 #include "third_party/base/ptr_util.h" | 12 #include "third_party/base/ptr_util.h" |
| 12 #include "third_party/base/stl_util.h" | 13 #include "third_party/base/stl_util.h" |
| 13 #include "xfa/fde/cfde_path.h" | 14 #include "xfa/fde/cfde_path.h" |
| 14 #include "xfa/fde/css/fde_cssstyleselector.h" | 15 #include "xfa/fde/css/fde_cssstyleselector.h" |
| 15 #include "xfa/fde/fde_gedevice.h" | 16 #include "xfa/fde/fde_gedevice.h" |
| 16 #include "xfa/fde/fde_object.h" | 17 #include "xfa/fde/fde_object.h" |
| 17 #include "xfa/fde/xml/fde_xml_imp.h" | 18 #include "xfa/fde/xml/fde_xml_imp.h" |
| 18 #include "xfa/fxfa/app/cxfa_linkuserdata.h" | 19 #include "xfa/fxfa/app/cxfa_linkuserdata.h" |
| 19 #include "xfa/fxfa/app/cxfa_loadercontext.h" | 20 #include "xfa/fxfa/app/cxfa_loadercontext.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 39 m_bBlockContinue(true) { | 40 m_bBlockContinue(true) { |
| 40 ASSERT(m_pTextProvider); | 41 ASSERT(m_pTextProvider); |
| 41 } | 42 } |
| 42 | 43 |
| 43 CXFA_TextLayout::~CXFA_TextLayout() { | 44 CXFA_TextLayout::~CXFA_TextLayout() { |
| 44 m_textParser.Reset(); | 45 m_textParser.Reset(); |
| 45 Unload(); | 46 Unload(); |
| 46 } | 47 } |
| 47 | 48 |
| 48 void CXFA_TextLayout::Unload() { | 49 void CXFA_TextLayout::Unload() { |
| 49 for (int32_t i = 0; i < m_pieceLines.GetSize(); i++) { | 50 m_pieceLines.clear(); |
| 50 CXFA_PieceLine* pLine = m_pieceLines.GetAt(i); | |
| 51 for (int32_t i = 0; i < pLine->m_textPieces.GetSize(); i++) { | |
| 52 XFA_TextPiece* pPiece = pLine->m_textPieces.GetAt(i); | |
| 53 // Release text and widths in a text piece. | |
| 54 delete pPiece->pszText; | |
| 55 delete pPiece->pWidths; | |
| 56 // Release text piece. | |
| 57 delete pPiece; | |
| 58 } | |
| 59 pLine->m_textPieces.RemoveAll(); | |
| 60 // Release line. | |
| 61 delete pLine; | |
| 62 } | |
| 63 m_pieceLines.RemoveAll(); | |
| 64 m_pBreak.reset(); | 51 m_pBreak.reset(); |
| 65 } | 52 } |
| 66 | 53 |
| 67 const CFX_ArrayTemplate<CXFA_PieceLine*>* CXFA_TextLayout::GetPieceLines() { | |
| 68 return &m_pieceLines; | |
| 69 } | |
| 70 | |
| 71 void CXFA_TextLayout::GetTextDataNode() { | 54 void CXFA_TextLayout::GetTextDataNode() { |
| 72 if (!m_pTextProvider) | 55 if (!m_pTextProvider) |
| 73 return; | 56 return; |
| 74 | 57 |
| 75 CXFA_Node* pNode = m_pTextProvider->GetTextNode(m_bRichText); | 58 CXFA_Node* pNode = m_pTextProvider->GetTextNode(m_bRichText); |
| 76 if (pNode && m_bRichText) | 59 if (pNode && m_bRichText) |
| 77 m_textParser.Reset(); | 60 m_textParser.Reset(); |
| 78 | 61 |
| 79 m_pTextDataNode = pNode; | 62 m_pTextDataNode = pNode; |
| 80 } | 63 } |
| (...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 if (!pFxDevice) | 562 if (!pFxDevice) |
| 580 return false; | 563 return false; |
| 581 | 564 |
| 582 std::unique_ptr<CFDE_RenderDevice> pDevice( | 565 std::unique_ptr<CFDE_RenderDevice> pDevice( |
| 583 new CFDE_RenderDevice(pFxDevice, false)); | 566 new CFDE_RenderDevice(pFxDevice, false)); |
| 584 pDevice->SaveState(); | 567 pDevice->SaveState(); |
| 585 pDevice->SetClipRect(rtClip); | 568 pDevice->SetClipRect(rtClip); |
| 586 | 569 |
| 587 auto pSolidBrush = pdfium::MakeUnique<CFDE_Brush>(); | 570 auto pSolidBrush = pdfium::MakeUnique<CFDE_Brush>(); |
| 588 auto pPen = pdfium::MakeUnique<CFDE_Pen>(); | 571 auto pPen = pdfium::MakeUnique<CFDE_Pen>(); |
| 589 if (m_pieceLines.GetSize() == 0) { | 572 if (m_pieceLines.empty()) { |
| 590 int32_t iBlockCount = CountBlocks(); | 573 int32_t iBlockCount = CountBlocks(); |
| 591 for (int32_t i = 0; i < iBlockCount; i++) | 574 for (int32_t i = 0; i < iBlockCount; i++) |
| 592 Layout(i); | 575 Layout(i); |
| 593 } | 576 } |
| 594 | 577 |
| 595 FXTEXT_CHARPOS* pCharPos = nullptr; | 578 FXTEXT_CHARPOS* pCharPos = nullptr; |
| 596 int32_t iCharCount = 0; | 579 int32_t iCharCount = 0; |
| 597 int32_t iLineStart = 0; | 580 int32_t iLineStart = 0; |
| 598 int32_t iPieceLines = m_pieceLines.GetSize(); | 581 int32_t iPieceLines = pdfium::CollectionSize<int32_t>(m_pieceLines); |
| 599 int32_t iCount = m_Blocks.GetSize(); | 582 int32_t iCount = m_Blocks.GetSize(); |
| 600 if (iCount > 0) { | 583 if (iCount > 0) { |
| 601 iBlock *= 2; | 584 iBlock *= 2; |
| 602 if (iBlock < iCount) { | 585 if (iBlock < iCount) { |
| 603 iLineStart = m_Blocks.ElementAt(iBlock); | 586 iLineStart = m_Blocks.ElementAt(iBlock); |
| 604 iPieceLines = m_Blocks.ElementAt(iBlock + 1); | 587 iPieceLines = m_Blocks.ElementAt(iBlock + 1); |
| 605 } else { | 588 } else { |
| 606 iPieceLines = 0; | 589 iPieceLines = 0; |
| 607 } | 590 } |
| 608 } | 591 } |
| 609 | 592 |
| 610 for (int32_t i = 0; i < iPieceLines; i++) { | 593 for (int32_t i = 0; i < iPieceLines; i++) { |
| 611 if (i + iLineStart >= m_pieceLines.GetSize()) | 594 if (i + iLineStart >= pdfium::CollectionSize<int32_t>(m_pieceLines)) |
| 612 break; | 595 break; |
| 613 | 596 |
| 614 CXFA_PieceLine* pPieceLine = m_pieceLines.GetAt(i + iLineStart); | 597 CXFA_PieceLine* pPieceLine = m_pieceLines[i + iLineStart].get(); |
| 615 int32_t iPieces = pPieceLine->m_textPieces.GetSize(); | 598 int32_t iPieces = pdfium::CollectionSize<int32_t>(pPieceLine->m_textPieces); |
| 616 int32_t j = 0; | 599 int32_t j = 0; |
| 617 for (j = 0; j < iPieces; j++) { | 600 for (j = 0; j < iPieces; j++) { |
| 618 const XFA_TextPiece* pPiece = pPieceLine->m_textPieces.GetAt(j); | 601 const XFA_TextPiece* pPiece = pPieceLine->m_textPieces[j].get(); |
| 619 int32_t iChars = pPiece->iChars; | 602 int32_t iChars = pPiece->iChars; |
| 620 if (iCharCount < iChars) { | 603 if (iCharCount < iChars) { |
| 621 FX_Free(pCharPos); | 604 FX_Free(pCharPos); |
| 622 pCharPos = FX_Alloc(FXTEXT_CHARPOS, iChars); | 605 pCharPos = FX_Alloc(FXTEXT_CHARPOS, iChars); |
| 623 iCharCount = iChars; | 606 iCharCount = iChars; |
| 624 } | 607 } |
| 625 FXSYS_memset(pCharPos, 0, iCharCount * sizeof(FXTEXT_CHARPOS)); | 608 FXSYS_memset(pCharPos, 0, iCharCount * sizeof(FXTEXT_CHARPOS)); |
| 626 RenderString(pDevice.get(), pSolidBrush.get(), pPieceLine, j, pCharPos, | 609 RenderString(pDevice.get(), pSolidBrush.get(), pPieceLine, j, pCharPos, |
| 627 tmDoc2Device); | 610 tmDoc2Device); |
| 628 } | 611 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 644 switch (m_textParser.GetVAlign(m_pTextProvider)) { | 627 switch (m_textParser.GetVAlign(m_pTextProvider)) { |
| 645 case XFA_ATTRIBUTEENUM_Middle: | 628 case XFA_ATTRIBUTEENUM_Middle: |
| 646 fHeight /= 2.0f; | 629 fHeight /= 2.0f; |
| 647 break; | 630 break; |
| 648 case XFA_ATTRIBUTEENUM_Bottom: | 631 case XFA_ATTRIBUTEENUM_Bottom: |
| 649 break; | 632 break; |
| 650 default: | 633 default: |
| 651 return; | 634 return; |
| 652 } | 635 } |
| 653 | 636 |
| 654 int32_t iCount = m_pieceLines.GetSize(); | 637 for (const auto& pPieceLine : m_pieceLines) { |
| 655 for (int32_t i = 0; i < iCount; i++) { | 638 for (const auto& pPiece : pPieceLine->m_textPieces) |
| 656 CXFA_PieceLine* pPieceLine = m_pieceLines.GetAt(i); | 639 pPiece->rtPiece.top += fHeight; |
| 657 int32_t iPieces = pPieceLine->m_textPieces.GetSize(); | |
| 658 for (int32_t j = 0; j < iPieces; j++) { | |
| 659 XFA_TextPiece* pPiece = pPieceLine->m_textPieces.GetAt(j); | |
| 660 CFX_RectF& rect = pPiece->rtPiece; | |
| 661 rect.top += fHeight; | |
| 662 } | |
| 663 } | 640 } |
| 664 } | 641 } |
| 665 | 642 |
| 666 bool CXFA_TextLayout::Loader(const CFX_SizeF& szText, | 643 bool CXFA_TextLayout::Loader(const CFX_SizeF& szText, |
| 667 FX_FLOAT& fLinePos, | 644 FX_FLOAT& fLinePos, |
| 668 bool bSavePieces) { | 645 bool bSavePieces) { |
| 669 GetTextDataNode(); | 646 GetTextDataNode(); |
| 670 if (!m_pTextDataNode) | 647 if (!m_pTextDataNode) |
| 671 return true; | 648 return true; |
| 672 | 649 |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 997 AppendTextLine(dwStatus, fLinePos, bSavePieces, true); | 974 AppendTextLine(dwStatus, fLinePos, bSavePieces, true); |
| 998 } | 975 } |
| 999 | 976 |
| 1000 void CXFA_TextLayout::DoTabstops(CFDE_CSSComputedStyle* pStyle, | 977 void CXFA_TextLayout::DoTabstops(CFDE_CSSComputedStyle* pStyle, |
| 1001 CXFA_PieceLine* pPieceLine) { | 978 CXFA_PieceLine* pPieceLine) { |
| 1002 if (!m_pTabstopContext || m_pTabstopContext->m_iTabCount == 0) | 979 if (!m_pTabstopContext || m_pTabstopContext->m_iTabCount == 0) |
| 1003 return; | 980 return; |
| 1004 if (!pStyle || !pPieceLine) | 981 if (!pStyle || !pPieceLine) |
| 1005 return; | 982 return; |
| 1006 | 983 |
| 1007 int32_t iPieces = pPieceLine->m_textPieces.GetSize(); | 984 int32_t iPieces = pdfium::CollectionSize<int32_t>(pPieceLine->m_textPieces); |
| 1008 if (iPieces == 0) | 985 if (iPieces == 0) |
| 1009 return; | 986 return; |
| 1010 | 987 |
| 1011 XFA_TextPiece* pPiece = pPieceLine->m_textPieces.GetAt(iPieces - 1); | 988 XFA_TextPiece* pPiece = pPieceLine->m_textPieces[iPieces - 1].get(); |
| 1012 int32_t& iTabstopsIndex = m_pTabstopContext->m_iTabIndex; | 989 int32_t& iTabstopsIndex = m_pTabstopContext->m_iTabIndex; |
| 1013 int32_t iCount = m_textParser.CountTabs(pStyle); | 990 int32_t iCount = m_textParser.CountTabs(pStyle); |
| 1014 if (iTabstopsIndex > m_pTabstopContext->m_iTabCount - 1) | 991 if (iTabstopsIndex > m_pTabstopContext->m_iTabCount - 1) |
| 1015 return; | 992 return; |
| 1016 | 993 |
| 1017 if (iCount > 0) { | 994 if (iCount > 0) { |
| 1018 iTabstopsIndex++; | 995 iTabstopsIndex++; |
| 1019 m_pTabstopContext->m_bTabstops = true; | 996 m_pTabstopContext->m_bTabstops = true; |
| 1020 FX_FLOAT fRight = 0; | 997 FX_FLOAT fRight = 0; |
| 1021 if (iPieces > 1) { | 998 if (iPieces > 1) { |
| 1022 XFA_TextPiece* p = pPieceLine->m_textPieces.GetAt(iPieces - 2); | 999 XFA_TextPiece* p = pPieceLine->m_textPieces[iPieces - 2].get(); |
| 1023 fRight = p->rtPiece.right(); | 1000 fRight = p->rtPiece.right(); |
| 1024 } | 1001 } |
| 1025 m_pTabstopContext->m_fTabWidth = | 1002 m_pTabstopContext->m_fTabWidth = |
| 1026 pPiece->rtPiece.width + pPiece->rtPiece.left - fRight; | 1003 pPiece->rtPiece.width + pPiece->rtPiece.left - fRight; |
| 1027 } else if (iTabstopsIndex > -1) { | 1004 } else if (iTabstopsIndex > -1) { |
| 1028 FX_FLOAT fLeft = 0; | 1005 FX_FLOAT fLeft = 0; |
| 1029 if (m_pTabstopContext->m_bTabstops) { | 1006 if (m_pTabstopContext->m_bTabstops) { |
| 1030 XFA_TABSTOPS* pTabstops = | 1007 XFA_TABSTOPS* pTabstops = |
| 1031 m_pTabstopContext->m_tabstops.GetDataPtr(iTabstopsIndex); | 1008 m_pTabstopContext->m_tabstops.GetDataPtr(iTabstopsIndex); |
| 1032 uint32_t dwAlign = pTabstops->dwAlign; | 1009 uint32_t dwAlign = pTabstops->dwAlign; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1056 void CXFA_TextLayout::AppendTextLine(uint32_t dwStatus, | 1033 void CXFA_TextLayout::AppendTextLine(uint32_t dwStatus, |
| 1057 FX_FLOAT& fLinePos, | 1034 FX_FLOAT& fLinePos, |
| 1058 bool bSavePieces, | 1035 bool bSavePieces, |
| 1059 bool bEndBreak) { | 1036 bool bEndBreak) { |
| 1060 int32_t iPieces = m_pBreak->CountBreakPieces(); | 1037 int32_t iPieces = m_pBreak->CountBreakPieces(); |
| 1061 if (iPieces < 1) | 1038 if (iPieces < 1) |
| 1062 return; | 1039 return; |
| 1063 | 1040 |
| 1064 CFDE_CSSComputedStyle* pStyle = nullptr; | 1041 CFDE_CSSComputedStyle* pStyle = nullptr; |
| 1065 if (bSavePieces) { | 1042 if (bSavePieces) { |
| 1066 CXFA_PieceLine* pPieceLine = new CXFA_PieceLine; | 1043 auto pNew = pdfium::MakeUnique<CXFA_PieceLine>(); |
| 1067 m_pieceLines.Add(pPieceLine); | 1044 CXFA_PieceLine* pPieceLine = pNew.get(); |
| 1045 m_pieceLines.push_back(std::move(pNew)); |
| 1068 if (m_pTabstopContext) | 1046 if (m_pTabstopContext) |
| 1069 m_pTabstopContext->Reset(); | 1047 m_pTabstopContext->Reset(); |
| 1070 | 1048 |
| 1071 FX_FLOAT fLineStep = 0, fBaseLine = 0; | 1049 FX_FLOAT fLineStep = 0, fBaseLine = 0; |
| 1072 int32_t i = 0; | 1050 int32_t i = 0; |
| 1073 for (i = 0; i < iPieces; i++) { | 1051 for (i = 0; i < iPieces; i++) { |
| 1074 const CFX_RTFPiece* pPiece = m_pBreak->GetBreakPiece(i); | 1052 const CFX_RTFPiece* pPiece = m_pBreak->GetBreakPiece(i); |
| 1075 CXFA_TextUserData* pUserData = (CXFA_TextUserData*)pPiece->m_pUserData; | 1053 CXFA_TextUserData* pUserData = (CXFA_TextUserData*)pPiece->m_pUserData; |
| 1076 if (pUserData) | 1054 if (pUserData) |
| 1077 pStyle = pUserData->m_pStyle; | 1055 pStyle = pUserData->m_pStyle; |
| 1078 FX_FLOAT fVerScale = pPiece->m_iVerticalScale / 100.0f; | 1056 FX_FLOAT fVerScale = pPiece->m_iVerticalScale / 100.0f; |
| 1079 | 1057 |
| 1080 XFA_TextPiece* pTP = new XFA_TextPiece(); | 1058 auto pTP = pdfium::MakeUnique<XFA_TextPiece>(); |
| 1081 pTP->pszText = | 1059 pTP->pszText = FX_Alloc(FX_WCHAR, pPiece->m_iChars); |
| 1082 (FX_WCHAR*)FX_Alloc(uint8_t, pPiece->m_iChars * sizeof(FX_WCHAR)); | 1060 pTP->pWidths = FX_Alloc(int32_t, pPiece->m_iChars); |
| 1083 pTP->pWidths = | |
| 1084 (int32_t*)FX_Alloc(uint8_t, pPiece->m_iChars * sizeof(int32_t)); | |
| 1085 pTP->iChars = pPiece->m_iChars; | 1061 pTP->iChars = pPiece->m_iChars; |
| 1086 pPiece->GetString(pTP->pszText); | 1062 pPiece->GetString(pTP->pszText); |
| 1087 pPiece->GetWidths(pTP->pWidths); | 1063 pPiece->GetWidths(pTP->pWidths); |
| 1088 pTP->iBidiLevel = pPiece->m_iBidiLevel; | 1064 pTP->iBidiLevel = pPiece->m_iBidiLevel; |
| 1089 pTP->iHorScale = pPiece->m_iHorizontalScale; | 1065 pTP->iHorScale = pPiece->m_iHorizontalScale; |
| 1090 pTP->iVerScale = pPiece->m_iVerticalScale; | 1066 pTP->iVerScale = pPiece->m_iVerticalScale; |
| 1091 m_textParser.GetUnderline(m_pTextProvider, pStyle, pTP->iUnderline, | 1067 m_textParser.GetUnderline(m_pTextProvider, pStyle, pTP->iUnderline, |
| 1092 pTP->iPeriod); | 1068 pTP->iPeriod); |
| 1093 m_textParser.GetLinethrough(m_pTextProvider, pStyle, pTP->iLineThrough); | 1069 m_textParser.GetLinethrough(m_pTextProvider, pStyle, pTP->iLineThrough); |
| 1094 pTP->dwColor = m_textParser.GetColor(m_pTextProvider, pStyle); | 1070 pTP->dwColor = m_textParser.GetColor(m_pTextProvider, pStyle); |
| 1095 pTP->pFont = m_textParser.GetFont(m_pTextProvider, pStyle); | 1071 pTP->pFont = m_textParser.GetFont(m_pTextProvider, pStyle); |
| 1096 pTP->fFontSize = m_textParser.GetFontSize(m_pTextProvider, pStyle); | 1072 pTP->fFontSize = m_textParser.GetFontSize(m_pTextProvider, pStyle); |
| 1097 pTP->rtPiece.left = pPiece->m_iStartPos / 20000.0f; | 1073 pTP->rtPiece.left = pPiece->m_iStartPos / 20000.0f; |
| 1098 pTP->rtPiece.width = pPiece->m_iWidth / 20000.0f; | 1074 pTP->rtPiece.width = pPiece->m_iWidth / 20000.0f; |
| 1099 pTP->rtPiece.height = (FX_FLOAT)pPiece->m_iFontSize * fVerScale / 20.0f; | 1075 pTP->rtPiece.height = (FX_FLOAT)pPiece->m_iFontSize * fVerScale / 20.0f; |
| 1100 FX_FLOAT fBaseLineTemp = | 1076 FX_FLOAT fBaseLineTemp = |
| 1101 m_textParser.GetBaseline(m_pTextProvider, pStyle); | 1077 m_textParser.GetBaseline(m_pTextProvider, pStyle); |
| 1102 pTP->rtPiece.top = fBaseLineTemp; | 1078 pTP->rtPiece.top = fBaseLineTemp; |
| 1103 pPieceLine->m_textPieces.Add(pTP); | |
| 1104 | 1079 |
| 1105 FX_FLOAT fLineHeight = m_textParser.GetLineHeight( | 1080 FX_FLOAT fLineHeight = m_textParser.GetLineHeight( |
| 1106 m_pTextProvider, pStyle, m_iLines == 0, fVerScale); | 1081 m_pTextProvider, pStyle, m_iLines == 0, fVerScale); |
| 1107 if (fBaseLineTemp > 0) { | 1082 if (fBaseLineTemp > 0) { |
| 1108 FX_FLOAT fLineHeightTmp = fBaseLineTemp + pTP->rtPiece.height; | 1083 FX_FLOAT fLineHeightTmp = fBaseLineTemp + pTP->rtPiece.height; |
| 1109 if (fLineHeight < fLineHeightTmp) | 1084 if (fLineHeight < fLineHeightTmp) |
| 1110 fLineHeight = fLineHeightTmp; | 1085 fLineHeight = fLineHeightTmp; |
| 1111 else | 1086 else |
| 1112 fBaseLineTemp = 0; | 1087 fBaseLineTemp = 0; |
| 1113 } else if (fBaseLine < -fBaseLineTemp) { | 1088 } else if (fBaseLine < -fBaseLineTemp) { |
| 1114 fBaseLine = -fBaseLineTemp; | 1089 fBaseLine = -fBaseLineTemp; |
| 1115 } | 1090 } |
| 1116 fLineStep = std::max(fLineStep, fLineHeight); | 1091 fLineStep = std::max(fLineStep, fLineHeight); |
| 1117 if (pUserData && pUserData->m_pLinkData) { | 1092 if (pUserData && pUserData->m_pLinkData) { |
| 1118 pUserData->m_pLinkData->Retain(); | 1093 pUserData->m_pLinkData->Retain(); |
| 1119 pTP->pLinkData = pUserData->m_pLinkData; | 1094 pTP->pLinkData = pUserData->m_pLinkData; |
| 1120 } else { | 1095 } else { |
| 1121 pTP->pLinkData = nullptr; | 1096 pTP->pLinkData = nullptr; |
| 1122 } | 1097 } |
| 1098 pPieceLine->m_textPieces.push_back(std::move(pTP)); |
| 1123 DoTabstops(pStyle, pPieceLine); | 1099 DoTabstops(pStyle, pPieceLine); |
| 1124 } | 1100 } |
| 1125 for (i = 0; i < iPieces; i++) { | 1101 for (const auto& pTP : pPieceLine->m_textPieces) { |
| 1126 XFA_TextPiece* pTP = pPieceLine->m_textPieces.GetAt(i); | |
| 1127 FX_FLOAT& fTop = pTP->rtPiece.top; | 1102 FX_FLOAT& fTop = pTP->rtPiece.top; |
| 1128 FX_FLOAT fBaseLineTemp = fTop; | 1103 FX_FLOAT fBaseLineTemp = fTop; |
| 1129 fTop = fLinePos + fLineStep - pTP->rtPiece.height - fBaseLineTemp; | 1104 fTop = fLinePos + fLineStep - pTP->rtPiece.height - fBaseLineTemp; |
| 1130 fTop = std::max(0.0f, fTop); | 1105 fTop = std::max(0.0f, fTop); |
| 1131 } | 1106 } |
| 1132 fLinePos += fLineStep + fBaseLine; | 1107 fLinePos += fLineStep + fBaseLine; |
| 1133 } else { | 1108 } else { |
| 1134 FX_FLOAT fLineStep = 0; | 1109 FX_FLOAT fLineStep = 0; |
| 1135 FX_FLOAT fLineWidth = 0; | 1110 FX_FLOAT fLineWidth = 0; |
| 1136 for (int32_t i = 0; i < iPieces; i++) { | 1111 for (int32_t i = 0; i < iPieces; i++) { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1199 } | 1174 } |
| 1200 m_iLines++; | 1175 m_iLines++; |
| 1201 } | 1176 } |
| 1202 | 1177 |
| 1203 void CXFA_TextLayout::RenderString(CFDE_RenderDevice* pDevice, | 1178 void CXFA_TextLayout::RenderString(CFDE_RenderDevice* pDevice, |
| 1204 CFDE_Brush* pBrush, | 1179 CFDE_Brush* pBrush, |
| 1205 CXFA_PieceLine* pPieceLine, | 1180 CXFA_PieceLine* pPieceLine, |
| 1206 int32_t iPiece, | 1181 int32_t iPiece, |
| 1207 FXTEXT_CHARPOS* pCharPos, | 1182 FXTEXT_CHARPOS* pCharPos, |
| 1208 const CFX_Matrix& tmDoc2Device) { | 1183 const CFX_Matrix& tmDoc2Device) { |
| 1209 const XFA_TextPiece* pPiece = pPieceLine->m_textPieces.GetAt(iPiece); | 1184 const XFA_TextPiece* pPiece = pPieceLine->m_textPieces[iPiece].get(); |
| 1210 int32_t iCount = GetDisplayPos(pPiece, pCharPos); | 1185 int32_t iCount = GetDisplayPos(pPiece, pCharPos); |
| 1211 if (iCount > 0) { | 1186 if (iCount > 0) { |
| 1212 pBrush->SetColor(pPiece->dwColor); | 1187 pBrush->SetColor(pPiece->dwColor); |
| 1213 pDevice->DrawString(pBrush, pPiece->pFont, pCharPos, iCount, | 1188 pDevice->DrawString(pBrush, pPiece->pFont, pCharPos, iCount, |
| 1214 pPiece->fFontSize, &tmDoc2Device); | 1189 pPiece->fFontSize, &tmDoc2Device); |
| 1215 } | 1190 } |
| 1216 pPieceLine->m_charCounts.Add(iCount); | 1191 pPieceLine->m_charCounts.Add(iCount); |
| 1217 } | 1192 } |
| 1218 | 1193 |
| 1219 void CXFA_TextLayout::RenderPath(CFDE_RenderDevice* pDevice, | 1194 void CXFA_TextLayout::RenderPath(CFDE_RenderDevice* pDevice, |
| 1220 CFDE_Pen* pPen, | 1195 CFDE_Pen* pPen, |
| 1221 CXFA_PieceLine* pPieceLine, | 1196 CXFA_PieceLine* pPieceLine, |
| 1222 int32_t iPiece, | 1197 int32_t iPiece, |
| 1223 FXTEXT_CHARPOS* pCharPos, | 1198 FXTEXT_CHARPOS* pCharPos, |
| 1224 const CFX_Matrix& tmDoc2Device) { | 1199 const CFX_Matrix& tmDoc2Device) { |
| 1225 XFA_TextPiece* pPiece = pPieceLine->m_textPieces.GetAt(iPiece); | 1200 XFA_TextPiece* pPiece = pPieceLine->m_textPieces[iPiece].get(); |
| 1226 bool bNoUnderline = pPiece->iUnderline < 1 || pPiece->iUnderline > 2; | 1201 bool bNoUnderline = pPiece->iUnderline < 1 || pPiece->iUnderline > 2; |
| 1227 bool bNoLineThrough = pPiece->iLineThrough < 1 || pPiece->iLineThrough > 2; | 1202 bool bNoLineThrough = pPiece->iLineThrough < 1 || pPiece->iLineThrough > 2; |
| 1228 if (bNoUnderline && bNoLineThrough) | 1203 if (bNoUnderline && bNoLineThrough) |
| 1229 return; | 1204 return; |
| 1230 | 1205 |
| 1231 pPen->SetColor(pPiece->dwColor); | 1206 pPen->SetColor(pPiece->dwColor); |
| 1232 std::unique_ptr<CFDE_Path> pPath(new CFDE_Path); | 1207 std::unique_ptr<CFDE_Path> pPath(new CFDE_Path); |
| 1233 int32_t iChars = GetDisplayPos(pPiece, pCharPos); | 1208 int32_t iChars = GetDisplayPos(pPiece, pCharPos); |
| 1234 if (iChars > 0) { | 1209 if (iChars > 0) { |
| 1235 CFX_PointF pt1, pt2; | 1210 CFX_PointF pt1, pt2; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1275 while (iPiecePrev > 0) { | 1250 while (iPiecePrev > 0) { |
| 1276 iPiecePrev--; | 1251 iPiecePrev--; |
| 1277 iCharsTmp = pPieceLine->m_charCounts.GetAt(iPiecePrev); | 1252 iCharsTmp = pPieceLine->m_charCounts.GetAt(iPiecePrev); |
| 1278 if (iCharsTmp > 0) | 1253 if (iCharsTmp > 0) |
| 1279 break; | 1254 break; |
| 1280 } | 1255 } |
| 1281 if (iCharsTmp == 0) | 1256 if (iCharsTmp == 0) |
| 1282 return; | 1257 return; |
| 1283 | 1258 |
| 1284 iCharsTmp = 0; | 1259 iCharsTmp = 0; |
| 1285 int32_t iPieces = pPieceLine->m_textPieces.GetSize(); | 1260 int32_t iPieces = pdfium::CollectionSize<int32_t>(pPieceLine->m_textPieces); |
| 1286 while (iPieceNext < iPieces - 1) { | 1261 while (iPieceNext < iPieces - 1) { |
| 1287 iPieceNext++; | 1262 iPieceNext++; |
| 1288 iCharsTmp = pPieceLine->m_charCounts.GetAt(iPieceNext); | 1263 iCharsTmp = pPieceLine->m_charCounts.GetAt(iPieceNext); |
| 1289 if (iCharsTmp > 0) | 1264 if (iCharsTmp > 0) |
| 1290 break; | 1265 break; |
| 1291 } | 1266 } |
| 1292 if (iCharsTmp == 0) | 1267 if (iCharsTmp == 0) |
| 1293 return; | 1268 return; |
| 1294 | 1269 |
| 1295 FX_FLOAT fOrgX = 0.0f; | 1270 FX_FLOAT fOrgX = 0.0f; |
| 1296 FX_FLOAT fEndX = 0.0f; | 1271 FX_FLOAT fEndX = 0.0f; |
| 1297 pPiece = pPieceLine->m_textPieces.GetAt(iPiecePrev); | 1272 pPiece = pPieceLine->m_textPieces[iPiecePrev].get(); |
| 1298 iChars = GetDisplayPos(pPiece, pCharPos); | 1273 iChars = GetDisplayPos(pPiece, pCharPos); |
| 1299 if (iChars < 1) | 1274 if (iChars < 1) |
| 1300 return; | 1275 return; |
| 1301 | 1276 |
| 1302 fOrgX = pCharPos[iChars - 1].m_OriginX + | 1277 fOrgX = pCharPos[iChars - 1].m_OriginX + |
| 1303 pCharPos[iChars - 1].m_FontCharWidth * pPiece->fFontSize / 1000.0f; | 1278 pCharPos[iChars - 1].m_FontCharWidth * pPiece->fFontSize / 1000.0f; |
| 1304 pPiece = pPieceLine->m_textPieces.GetAt(iPieceNext); | 1279 pPiece = pPieceLine->m_textPieces[iPieceNext].get(); |
| 1305 iChars = GetDisplayPos(pPiece, pCharPos); | 1280 iChars = GetDisplayPos(pPiece, pCharPos); |
| 1306 if (iChars < 1) | 1281 if (iChars < 1) |
| 1307 return; | 1282 return; |
| 1308 | 1283 |
| 1309 fEndX = pCharPos[0].m_OriginX; | 1284 fEndX = pCharPos[0].m_OriginX; |
| 1310 CFX_PointF pt1, pt2; | 1285 CFX_PointF pt1, pt2; |
| 1311 pt1.x = fOrgX, pt2.x = fEndX; | 1286 pt1.x = fOrgX, pt2.x = fEndX; |
| 1312 FX_FLOAT fEndY = pCharPos[0].m_OriginY + 1.05f; | 1287 FX_FLOAT fEndY = pCharPos[0].m_OriginY + 1.05f; |
| 1313 for (int32_t i = 0; i < pPiece->iUnderline; i++) { | 1288 for (int32_t i = 0; i < pPiece->iUnderline; i++) { |
| 1314 pt1.y = pt2.y = fEndY; | 1289 pt1.y = pt2.y = fEndY; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1325 pDevice->DrawPath(pPen, 1, pPath.get(), &tmDoc2Device); | 1300 pDevice->DrawPath(pPen, 1, pPath.get(), &tmDoc2Device); |
| 1326 } | 1301 } |
| 1327 | 1302 |
| 1328 int32_t CXFA_TextLayout::GetDisplayPos(const XFA_TextPiece* pPiece, | 1303 int32_t CXFA_TextLayout::GetDisplayPos(const XFA_TextPiece* pPiece, |
| 1329 FXTEXT_CHARPOS* pCharPos, | 1304 FXTEXT_CHARPOS* pCharPos, |
| 1330 bool bCharCode) { | 1305 bool bCharCode) { |
| 1331 if (!pPiece) | 1306 if (!pPiece) |
| 1332 return 0; | 1307 return 0; |
| 1333 | 1308 |
| 1334 FX_RTFTEXTOBJ tr; | 1309 FX_RTFTEXTOBJ tr; |
| 1335 if (!ToRun(pPiece, tr)) | 1310 if (!ToRun(pPiece, &tr)) |
| 1336 return 0; | 1311 return 0; |
| 1337 return m_pBreak->GetDisplayPos(&tr, pCharPos, bCharCode); | 1312 return m_pBreak->GetDisplayPos(&tr, pCharPos, bCharCode); |
| 1338 } | 1313 } |
| 1339 | 1314 |
| 1340 bool CXFA_TextLayout::ToRun(const XFA_TextPiece* pPiece, FX_RTFTEXTOBJ& tr) { | 1315 bool CXFA_TextLayout::ToRun(const XFA_TextPiece* pPiece, FX_RTFTEXTOBJ* tr) { |
| 1341 int32_t iLength = pPiece->iChars; | 1316 int32_t iLength = pPiece->iChars; |
| 1342 if (iLength < 1) | 1317 if (iLength < 1) |
| 1343 return false; | 1318 return false; |
| 1344 | 1319 |
| 1345 tr.pStr = pPiece->pszText; | 1320 tr->pStr = pPiece->pszText; |
| 1346 tr.pFont = pPiece->pFont; | 1321 tr->pFont = pPiece->pFont; |
| 1347 tr.pRect = &pPiece->rtPiece; | 1322 tr->pRect = &pPiece->rtPiece; |
| 1348 tr.pWidths = pPiece->pWidths; | 1323 tr->pWidths = pPiece->pWidths; |
| 1349 tr.iLength = iLength; | 1324 tr->iLength = iLength; |
| 1350 tr.fFontSize = pPiece->fFontSize; | 1325 tr->fFontSize = pPiece->fFontSize; |
| 1351 tr.iBidiLevel = pPiece->iBidiLevel; | 1326 tr->iBidiLevel = pPiece->iBidiLevel; |
| 1352 tr.iCharRotation = 0; | 1327 tr->iCharRotation = 0; |
| 1353 tr.wLineBreakChar = L'\n'; | 1328 tr->wLineBreakChar = L'\n'; |
| 1354 tr.iVerticalScale = pPiece->iVerScale; | 1329 tr->iVerticalScale = pPiece->iVerScale; |
| 1355 tr.dwLayoutStyles = FX_RTFLAYOUTSTYLE_ExpandTab; | 1330 tr->dwLayoutStyles = FX_RTFLAYOUTSTYLE_ExpandTab; |
| 1356 tr.iHorizontalScale = pPiece->iHorScale; | 1331 tr->iHorizontalScale = pPiece->iHorScale; |
| 1357 return true; | 1332 return true; |
| 1358 } | 1333 } |
| OLD | NEW |