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

Side by Side Diff: xfa/fxfa/app/cxfa_textlayout.cpp

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

Powered by Google App Engine
This is Rietveld 408576698