7#include "xfa/fxfa/cxfa_textlayout.h"
14#include "core/fxcrt/css/cfx_csscomputedstyle.h"
15#include "core/fxcrt/css/cfx_cssstyleselector.h"
16#include "core/fxcrt/stl_util.h"
17#include "core/fxcrt/xml/cfx_xmlelement.h"
18#include "core/fxcrt/xml/cfx_xmlnode.h"
19#include "core/fxcrt/xml/cfx_xmltext.h"
20#include "core/fxge/cfx_fillrenderoptions.h"
21#include "core/fxge/cfx_graphstatedata.h"
22#include "core/fxge/cfx_path.h"
23#include "core/fxge/cfx_renderdevice.h"
24#include "core/fxge/text_char_pos.h"
25#include "fxjs/xfa/cjx_object.h"
26#include "third_party/base/check.h"
27#include "third_party/base/notreached.h"
28#include "xfa/fde/cfde_textout.h"
29#include "xfa/fgas/font/cfgas_gefont.h"
30#include "xfa/fgas/layout/cfgas_linkuserdata.h"
31#include "xfa/fgas/layout/cfgas_rtfbreak.h"
32#include "xfa/fgas/layout/cfgas_textuserdata.h"
33#include "xfa/fxfa/cxfa_ffdoc.h"
34#include "xfa/fxfa/cxfa_textparser.h"
35#include "xfa/fxfa/cxfa_textprovider.h"
36#include "xfa/fxfa/cxfa_texttabstopscontext.h"
37#include "xfa/fxfa/parser/cxfa_font.h"
38#include "xfa/fxfa/parser/cxfa_node.h"
39#include "xfa/fxfa/parser/cxfa_para.h"
43constexpr float kHeightTolerance = 0.001f;
45void ProcessText(WideString* pText) {
46 size_t iLen = pText->GetLength();
53 pdfium::span<
wchar_t> psz = pText->GetBuffer(iLen);
55 for (size_t i = 0; i < iLen; i++) {
59 if (wch == 0x20 && wPrev == 0x20)
63 psz[iTrimLeft++] = wch;
66 pText->ReleaseBuffer(iTrimLeft);
71CXFA_TextLayout::TextPiece::TextPiece() =
default;
73CXFA_TextLayout::TextPiece::~TextPiece() =
default;
75CXFA_TextLayout::PieceLine::PieceLine() =
default;
77CXFA_TextLayout::PieceLine::~PieceLine() =
default;
79CXFA_TextLayout::LoaderContext::LoaderContext() =
default;
81CXFA_TextLayout::LoaderContext::~LoaderContext() =
default;
83void CXFA_TextLayout::LoaderContext::Trace(
cppgc::Visitor* visitor)
const {
84 visitor->Trace(pNode);
87CXFA_TextLayout::CXFA_TextLayout(
CXFA_FFDoc* doc,
90 m_pTextProvider(pTextProvider),
91 m_pTextParser(cppgc::MakeGarbageCollected<CXFA_TextParser>(
92 doc->GetHeap()->GetAllocationHandle())) {
93 DCHECK(m_pTextProvider);
98void CXFA_TextLayout::Trace(
cppgc::Visitor* visitor)
const {
99 visitor->Trace(m_pDoc);
100 visitor->Trace(m_pTextProvider);
101 visitor->Trace(m_pTextDataNode);
102 visitor->Trace(m_pTextParser);
103 visitor->Trace(m_pLoader);
107 m_pieceLines.clear();
112 for (
const auto& pPieceLine : m_pieceLines) {
113 for (
const auto& pPiece : pPieceLine->m_textPieces) {
114 if (pPiece->pLinkData && pPiece->rtPiece.Contains(point))
115 return pPiece->pLinkData->GetLinkURL();
121void CXFA_TextLayout::GetTextDataNode() {
122 CXFA_Node* pNode = m_pTextProvider->GetTextNode(&m_bRichText);
123 if (pNode && m_bRichText)
124 m_pTextParser->Reset();
126 m_pTextDataNode = pNode;
129CFX_XMLNode* CXFA_TextLayout::GetXMLContainerNode() {
133 CFX_XMLNode* pXMLRoot = m_pTextDataNode->GetXMLMappingNode();
137 for (
CFX_XMLNode* pXMLChild = pXMLRoot->GetFirstChild(); pXMLChild;
138 pXMLChild = pXMLChild->GetNextSibling()) {
149std::unique_ptr<CFGAS_RTFBreak> CXFA_TextLayout::CreateBreak(
bool bDefault) {
154 auto pBreak =
std::make_unique<CFGAS_RTFBreak>(dwStyle);
155 pBreak->SetLineBreakTolerance(1);
157 m_pTextParser->GetFont(m_pDoc.Get(), m_pTextProvider,
nullptr));
158 pBreak->SetFontSize(m_pTextParser->GetFontSize(m_pTextProvider,
nullptr));
162void CXFA_TextLayout::InitBreak(
float fLineWidth) {
163 CXFA_Para* para = m_pTextProvider->GetParaIfExists();
185 NOTREACHED_NORETURN();
187 m_pBreak->SetAlignment(iAlign);
190 if (m_pTextProvider->IsCheckButtonAndAutoWidth()) {
202 fStartPos += fIndent;
205 m_pBreak->SetLineBoundary(fStart, fLineWidth);
206 m_pBreak->SetLineStartPos(fStartPos);
208 CXFA_Font* font = m_pTextProvider->GetFontIfExists();
210 m_pBreak->SetHorizontalScale(
211 static_cast<int32_t>(font->GetHorizontalScale()));
212 m_pBreak->SetVerticalScale(
static_cast<int32_t>(font->GetVerticalScale()));
213 m_pBreak->SetCharSpace(font->GetLetterSpacing());
216 float fFontSize = m_pTextParser->GetFontSize(m_pTextProvider,
nullptr);
217 m_pBreak->SetFontSize(fFontSize);
219 m_pTextParser->GetFont(m_pDoc.Get(), m_pTextProvider,
nullptr));
220 m_pBreak->SetLineBreakTolerance(fFontSize * 0.2f);
223void CXFA_TextLayout::InitBreak(CFX_CSSComputedStyle* pStyle,
227 CFX_CSSComputedStyle* pParentStyle) {
229 InitBreak(fLineWidth);
252 m_pBreak->SetAlignment(iAlign);
270 if (pParPaddingRect) {
283 m_pBreak->SetLineBoundary(fStart, fLineWidth);
288 m_pBreak->SetLineStartPos(fStart);
289 m_pBreak->SetTabWidth(m_pTextParser->GetTabInterval(pStyle));
290 if (!m_pTabstopContext)
291 m_pTabstopContext = std::make_unique<CXFA_TextTabstopsContext>();
292 m_pTextParser->GetTabstops(pStyle, m_pTabstopContext.get());
293 for (
const auto& stop : m_pTabstopContext->m_tabstops)
294 m_pBreak->AddPositionedTab(stop.fTabstops);
296 float fFontSize = m_pTextParser->GetFontSize(m_pTextProvider, pStyle);
297 m_pBreak->SetFontSize(fFontSize);
298 m_pBreak->SetLineBreakTolerance(fFontSize * 0.2f);
300 m_pTextParser->GetFont(m_pDoc.Get(), m_pTextProvider, pStyle));
301 m_pBreak->SetHorizontalScale(
302 m_pTextParser->GetHorScale(m_pTextProvider, pStyle, pXMLNode));
303 m_pBreak->SetVerticalScale(
304 m_pTextParser->GetVerScale(m_pTextProvider, pStyle));
305 m_pBreak->SetCharSpace(pStyle->GetLetterSpacing().GetValue());
312 if (m_pLoader->lineHeights.empty() && m_pLoader->fWidth > 0) {
313 CFX_SizeF szMax(m_pLoader->fWidth, m_pLoader->fHeight);
314 m_pLoader->bSaveLineHeight =
true;
315 m_pLoader->fLastPos = 0;
316 CFX_SizeF szDef = CalcSize(szMax, szMax);
317 m_pLoader->bSaveLineHeight =
false;
321 float fHeight = m_pLoader->fHeight;
322 if (fHeight < 0.1f) {
324 for (
float value : m_pLoader->lineHeights)
332 m_pLoader = cppgc::MakeGarbageCollected<LoaderContext>(
333 m_pDoc->GetHeap()->GetAllocationHandle());
336 (m_pLoader->fWidth > -1 && fabs(fWidth - m_pLoader->fWidth) > 0)) {
337 m_pLoader->lineHeights.clear();
340 m_pLoader->fStartLineOffset = 0;
342 m_pLoader->fWidth = fWidth;
349 m_pLoader->bSaveLineHeight =
true;
350 m_pLoader->fLastPos = 0;
351 CFX_SizeF szDef = CalcSize(szMax, szMax);
352 m_pLoader->bSaveLineHeight =
false;
356float CXFA_TextLayout::
DoLayout(
float fTextHeight) {
360 UpdateLoaderHeight(fTextHeight);
370 UpdateLoaderHeight(fTextHeight);
376 if (m_Blocks.empty() && m_pLoader->fHeight > 0) {
384 m_pLoader->fStartLineOffset = fHeight;
388 float fLinePos = m_pLoader->fStartLineOffset;
389 size_t szLineIndex = 0;
390 if (!m_Blocks.empty()) {
391 if (szBlockIndex < m_Blocks.size())
392 szLineIndex = m_Blocks[szBlockIndex].szIndex;
394 szLineIndex = GetNextIndexFromLastBlockData();
396 i < std::min(szBlockIndex, m_pLoader->blockHeights.size()); ++i) {
397 fLinePos -= m_pLoader->blockHeights[i].fHeight;
401 if (szLineIndex >= m_pLoader->lineHeights.size())
404 if (m_pLoader->lineHeights[szLineIndex] - fCalcHeight > kHeightTolerance)
407 for (size_t i = szLineIndex; i < m_pLoader->lineHeights.size(); ++i) {
408 float fLineHeight = m_pLoader->lineHeights[i];
409 if (fLinePos + fLineHeight - fCalcHeight <= kHeightTolerance) {
410 fLinePos += fLineHeight;
414 if (szBlockIndex < m_Blocks.size())
415 m_Blocks[szBlockIndex] = {szLineIndex, i - szLineIndex};
417 m_Blocks.push_back({szLineIndex, i - szLineIndex});
419 if (i != szLineIndex)
422 if (fCalcHeight > fLinePos)
425 if (szBlockIndex < m_pLoader->blockHeights.size() &&
426 m_pLoader->blockHeights[szBlockIndex].szBlockIndex == szBlockIndex) {
427 m_pLoader->blockHeights[szBlockIndex].fHeight = fCalcHeight;
429 m_pLoader->blockHeights.push_back({szBlockIndex, fCalcHeight});
436size_t CXFA_TextLayout::CountBlocks()
const {
437 size_t szCount = m_Blocks.size();
438 return szCount > 0 ? szCount : 1;
441size_t CXFA_TextLayout::GetNextIndexFromLastBlockData()
const {
442 return m_Blocks.back().szIndex + m_Blocks.back().szLength;
445void CXFA_TextLayout::UpdateLoaderHeight(
float fTextHeight) {
446 m_pLoader->fHeight = fTextHeight;
447 if (m_pLoader->fHeight < 0)
448 m_pLoader->fHeight = GetLayoutHeight();
451CFX_SizeF CXFA_TextLayout::
CalcSize(
const CFX_SizeF& minSize,
452 const CFX_SizeF& maxSize) {
453 float width = maxSize.width;
457 m_pBreak = CreateBreak(
false);
461 Loader(width, &fLinePos,
false);
463 fLinePos = m_pTextParser->GetFontSize(m_pTextProvider,
nullptr);
465 m_pTabstopContext.reset();
466 return CFX_SizeF(m_fMaxWidth, fLinePos);
469float CXFA_TextLayout::
Layout(
const CFX_SizeF& size) {
474 m_pBreak = CreateBreak(
true);
476 m_pLoader->iTotalLines = -1;
477 m_pLoader->nCharIdx = 0;
482 Loader(size.width, &fLinePos,
true);
483 UpdateAlign(size.height, fLinePos);
484 m_pTabstopContext.reset();
488bool CXFA_TextLayout::LayoutInternal(size_t szBlockIndex) {
489 DCHECK(szBlockIndex < CountBlocks());
491 if (!m_pLoader || m_pLoader->fWidth < 1)
494 m_pLoader->iTotalLines = -1;
498 CFX_SizeF szText(m_pLoader->fWidth, m_pLoader->fHeight);
499 if (szBlockIndex < m_pLoader->blockHeights.size())
501 if (szBlockIndex == m_pLoader->blockHeights.size()) {
503 m_pBreak = CreateBreak(
true);
504 fLinePos = m_pLoader->fStartLineOffset;
505 for (size_t i = 0; i < m_pLoader->blockHeights.size(); ++i)
506 fLinePos -= m_pLoader->blockHeights[i].fHeight;
508 m_pLoader->nCharIdx = 0;
509 if (!m_Blocks.empty()) {
510 m_pLoader->iTotalLines =
511 pdfium::base::checked_cast<int32_t>(m_Blocks[szBlockIndex].szLength);
513 Loader(szText.width, &fLinePos,
true);
514 if (m_Blocks.empty() && m_pLoader->fStartLineOffset < 0.1f)
515 UpdateAlign(szText.height, fLinePos);
516 }
else if (m_pTextDataNode) {
517 if (!m_Blocks.empty() && szBlockIndex < m_Blocks.size() - 1) {
518 m_pLoader->iTotalLines =
519 pdfium::base::checked_cast<int32_t>(m_Blocks[szBlockIndex].szLength);
523 CFX_XMLNode* pContainerNode = GetXMLContainerNode();
532 for (; pXMLNode; pXMLNode = pXMLNode->GetNextSibling()) {
533 if (!LoadRichText(pXMLNode, szText.width, &fLinePos,
534 m_pLoader->pParentStyle,
true,
nullptr,
true,
false,
540 pXMLNode = pSaveXMLNode->GetParent();
541 if (pXMLNode == pContainerNode)
543 if (!LoadRichText(pXMLNode, szText.width, &fLinePos,
544 m_pLoader->pParentStyle,
true,
nullptr,
false,
false,
548 pSaveXMLNode = pXMLNode;
549 pXMLNode = pXMLNode->GetNextSibling();
552 for (; pXMLNode; pXMLNode = pXMLNode->GetNextSibling()) {
553 if (!LoadRichText(pXMLNode, szText.width, &fLinePos,
554 m_pLoader->pParentStyle,
true,
nullptr,
true,
false,
561 pNode = m_pLoader->pNode.Get();
564 LoadText(pNode, szText.width, &fLinePos,
true);
574 if (m_pLoader->lineHeights.empty())
577 float fLinePos = m_pLoader->fStartLineOffset;
578 size_t szLineIndex = 0;
579 if (szBlockIndex > 0) {
580 if (szBlockIndex <= m_pLoader->blockHeights.size()) {
581 for (size_t i = 0; i < szBlockIndex; ++i)
582 fLinePos -= m_pLoader->blockHeights[i].fHeight;
586 szLineIndex = GetNextIndexFromLastBlockData();
590 for (i = szLineIndex; i < m_pLoader->lineHeights.size(); ++i) {
591 float fLineHeight = m_pLoader->lineHeights[i];
592 if (fLinePos + fLineHeight - rtText
.height > kHeightTolerance) {
593 m_Blocks.push_back({szLineIndex, i - szLineIndex});
596 fLinePos += fLineHeight;
599 m_Blocks.push_back({szLineIndex, i - szLineIndex});
605 size_t szBlockIndex) {
612 if (m_pieceLines.empty()) {
613 size_t szBlockCount = CountBlocks();
614 for (size_t i = 0; i < szBlockCount; ++i)
616 m_pTabstopContext.reset();
620 std::vector<TextCharPos> char_pos(1);
621 size_t szLineStart = 0;
622 size_t szPieceLines = m_pieceLines.size();
623 if (!m_Blocks.empty()) {
624 if (szBlockIndex < m_Blocks.size()) {
625 szLineStart = m_Blocks[szBlockIndex].szIndex;
626 szPieceLines = m_Blocks[szBlockIndex].szLength;
632 for (size_t i = 0; i < szPieceLines; ++i) {
633 if (i + szLineStart >= m_pieceLines.size())
636 PieceLine* pPieceLine = m_pieceLines[i + szLineStart].get();
637 for (size_t j = 0; j < pPieceLine->m_textPieces.size(); ++j) {
638 const TextPiece* pPiece = pPieceLine->m_textPieces[j].get();
640 if (
fxcrt::CollectionSize<int32_t>(char_pos) < iChars)
641 char_pos.resize(iChars);
642 RenderString(pFxDevice, pPieceLine, j, &char_pos, mtDoc2Device);
644 for (size_t j = 0; j < pPieceLine->m_textPieces.size(); ++j)
645 RenderPath(pFxDevice, pPieceLine, j, &char_pos, mtDoc2Device);
648 return szPieceLines > 0;
651void CXFA_TextLayout::UpdateAlign(
float fHeight,
float fBottom) {
656 switch (m_pTextParser->GetVAlign(m_pTextProvider)) {
657 case XFA_AttributeValue::Middle:
660 case XFA_AttributeValue::Bottom:
666 for (
const auto& pPieceLine : m_pieceLines) {
667 for (
const auto& pPiece : pPieceLine->m_textPieces)
668 pPiece->rtPiece.top += fHeight;
672void CXFA_TextLayout::Loader(
float textWidth,
676 if (!m_pTextDataNode)
680 LoadText(m_pTextDataNode, textWidth, pLinePos, bSavePieces);
684 const CFX_XMLNode* pXMLContainer = GetXMLContainerNode();
688 if (!m_pTextParser->IsParsed())
689 m_pTextParser->DoParse(pXMLContainer, m_pTextProvider);
691 auto pRootStyle = m_pTextParser->CreateRootStyle(m_pTextProvider);
692 LoadRichText(pXMLContainer, textWidth, pLinePos,
std::move(pRootStyle),
693 bSavePieces,
nullptr,
true,
false, 0);
696void CXFA_TextLayout::LoadText(
CXFA_Node* pNode,
700 InitBreak(textWidth);
702 CXFA_Para* para = m_pTextProvider->GetParaIfExists();
703 float fSpaceAbove = 0;
706 if (fSpaceAbove < 0.1f)
713 *pLinePos += fSpaceAbove;
717 NOTREACHED_NORETURN();
721 WideString wsText = pNode->JSObject()->GetContent(
false);
722 wsText.TrimRight(L" ");
723 bool bRet = AppendChar(wsText, pLinePos, fSpaceAbove, bSavePieces);
724 if (bRet && m_pLoader)
725 m_pLoader->pNode = pNode;
730bool CXFA_TextLayout::LoadRichText(
const CFX_XMLNode* pXMLNode,
733 RetainPtr<CFX_CSSComputedStyle> pParentStyle,
743 m_pTextParser->GetParseContextFromMap(pXMLNode);
745 bool bContentNode =
false;
746 float fSpaceBelow = 0;
752 const CFX_XMLElement* pElement =
nullptr;
757 pElement =
static_cast<
const CFX_XMLElement*>(pXMLNode);
772 pStyle = m_pTextParser->ComputeStyle(pXMLNode, pParentStyle);
773 InitBreak(bContentNode ? pParentStyle.Get() : pStyle.Get(), eDisplay,
774 textWidth, pXMLNode, pParentStyle.Get());
781 const CFX_CSSRect* pRect = pStyle->GetMarginWidth();
791 pLinkData = pdfium::MakeRetain<CFGAS_LinkUserData>(wsLinkContent);
794 int32_t iTabCount = m_pTextParser->CountTabs(
795 bContentNode ? pParentStyle.Get() : pStyle.Get());
796 bool bSpaceRun = m_pTextParser->IsSpaceRun(
797 bContentNode ? pParentStyle.Get() : pStyle.Get());
799 if (bContentNode && iTabCount == 0) {
802 wsText
= WideString
(L'\n'
);
808 wsText = 0x00B7 + WideStringView(L" ", 1);
809 }
else if (!bContentNode) {
811 while (iTabCount-- > 0)
814 absl::optional<WideString> obj =
815 m_pTextParser->GetEmbeddedObj(m_pTextProvider, pXMLNode);
817 wsText = obj.value();
821 if (!wsText
.IsEmpty() && bContentNode && !bSpaceRun)
822 ProcessText(&wsText);
825 if (wsText.GetLength() > 0 && m_pLoader->bFilterSpace) {
826 wsText.TrimLeft(L" ");
829 m_pLoader->bFilterSpace =
true;
830 }
else if (CFX_CSSDisplay::Inline == eDisplay &&
831 m_pLoader->bFilterSpace) {
832 m_pLoader->bFilterSpace =
false;
833 }
else if (wsText.GetLength() > 0 && wsText
.Back() == 0x20) {
834 m_pLoader->bFilterSpace =
true;
835 }
else if (wsText.GetLength() != 0) {
836 m_pLoader->bFilterSpace =
false;
840 if (wsText.GetLength() > 0) {
841 if (!m_pLoader || m_pLoader->nCharIdx == 0) {
842 auto pUserData = pdfium::MakeRetain<CFGAS_TextUserData>(
843 bContentNode ? pParentStyle : pStyle, pLinkData);
844 m_pBreak->SetUserData(pUserData);
847 if (AppendChar(wsText, pLinePos, 0, bSavePieces)) {
849 m_pLoader->bFilterSpace =
false;
850 if (!IsEnd(bSavePieces))
852 if (m_pLoader && m_pLoader->iTotalLines > -1) {
853 m_pLoader->pXMLNode = pXMLNode;
854 m_pLoader->pParentStyle = pParentStyle;
861 for (
CFX_XMLNode* pChildNode = pXMLNode->GetFirstChild(); pChildNode;
862 pChildNode = pChildNode->GetNextSibling()) {
866 if (!LoadRichText(pChildNode, textWidth, pLinePos,
867 pContext ? pStyle : pParentStyle, bSavePieces,
868 pLinkData,
true, bIsOl, iLiCount))
873 if (CFX_CSSDisplay::Block == eDisplay)
874 m_pLoader->bFilterSpace =
true;
883 if (!pContext || bContentNode)
889 EndBreak(dwStatus, pLinePos, bSavePieces);
891 *pLinePos += fSpaceBelow;
892 if (m_pTabstopContext)
893 m_pTabstopContext->RemoveAll();
895 if (!IsEnd(bSavePieces))
898 if (m_pLoader && m_pLoader->iTotalLines > -1) {
899 m_pLoader->pXMLNode = pXMLNode->GetNextSibling();
900 m_pLoader->pParentStyle = pParentStyle;
905bool CXFA_TextLayout::AppendChar(
const WideString& wsText,
910 size_t iChar = m_pLoader ? m_pLoader->nCharIdx : 0;
911 size_t iLength = wsText.GetLength();
912 for (size_t i = iChar; i < iLength; i++) {
913 wchar_t wch = wsText[i];
917 dwStatus = m_pBreak->AppendChar(wch);
920 AppendTextLine(dwStatus, pLinePos, bSavePieces,
false);
921 if (IsEnd(bSavePieces)) {
923 m_pLoader->nCharIdx = i;
927 *pLinePos += fSpaceAbove;
931 m_pLoader->nCharIdx = 0;
936bool CXFA_TextLayout::IsEnd(
bool bSavePieces) {
939 if (m_pLoader && m_pLoader->iTotalLines > 0)
940 return m_iLines >= m_pLoader->iTotalLines;
947 dwStatus = m_pBreak->EndBreak(dwStatus);
950 AppendTextLine(dwStatus, pLinePos, bSavePieces,
true);
953void CXFA_TextLayout::DoTabstops(CFX_CSSComputedStyle* pStyle,
954 PieceLine* pPieceLine) {
955 if (!pStyle || !pPieceLine)
958 if (!m_pTabstopContext || m_pTabstopContext->m_tabstops.empty())
961 int32_t iPieces =
fxcrt::CollectionSize<int32_t>(pPieceLine->m_textPieces);
965 TextPiece* pPiece = pPieceLine->m_textPieces[iPieces - 1].get();
966 int32_t& iTabstopsIndex = m_pTabstopContext->m_iTabIndex;
967 int32_t iCount = m_pTextParser->CountTabs(pStyle);
968 if (!fxcrt::IndexInBounds(m_pTabstopContext->m_tabstops, iTabstopsIndex))
973 m_pTabstopContext->m_bHasTabstops =
true;
976 const TextPiece* p = pPieceLine->m_textPieces[iPieces - 2].get();
979 m_pTabstopContext->m_fTabWidth =
980 pPiece->rtPiece.width + pPiece->rtPiece.left - fRight;
981 }
else if (iTabstopsIndex > -1) {
983 if (m_pTabstopContext->m_bHasTabstops) {
984 uint32_t dwAlign = m_pTabstopContext->m_tabstops[iTabstopsIndex].dwAlign;
985 if (dwAlign == FX_HashCode_GetW(L"center")) {
987 }
else if (dwAlign == FX_HashCode_GetW(L"right") ||
988 dwAlign == FX_HashCode_GetW(L"before")) {
990 }
else if (dwAlign == FX_HashCode_GetW(L"decimal")) {
992 for (int32_t i = 0; i < iChars; i++) {
993 if (pPiece->szText[i] == L'.')
996 fLeft += pPiece->Widths[i] / 20000.0f;
999 m_pTabstopContext->m_fLeft =
1000 std::min(fLeft, m_pTabstopContext->m_fTabWidth);
1001 m_pTabstopContext->m_bHasTabstops =
false;
1002 m_pTabstopContext->m_fTabWidth = 0;
1004 pPiece->rtPiece.left -= m_pTabstopContext->m_fLeft;
1012 int32_t iPieces = m_pBreak->CountBreakPieces();
1018 auto pNew =
std::make_unique<PieceLine>();
1019 PieceLine* pPieceLine = pNew.get();
1020 m_pieceLines.push_back(std::move(pNew));
1021 if (m_pTabstopContext)
1022 m_pTabstopContext->Reset();
1024 float fLineStep = 0;
1025 float fBaseLine = 0;
1027 for (i = 0; i < iPieces; i++) {
1031 pStyle = pUserData->m_pStyle;
1034 auto pTP =
std::make_unique<TextPiece>();
1037 pTP->Widths = pPiece->GetWidths();
1042 m_pTextParser->GetUnderline(m_pTextProvider, pStyle.Get());
1044 m_pTextParser->GetUnderlinePeriod(m_pTextProvider, pStyle.Get());
1046 m_pTextParser->GetLinethrough(m_pTextProvider, pStyle.Get());
1047 pTP->dwColor = m_pTextParser->GetColor(m_pTextProvider, pStyle.Get());
1049 m_pTextParser->GetFont(m_pDoc.Get(), m_pTextProvider, pStyle.Get());
1051 m_pTextParser->GetFontSize(m_pTextProvider, pStyle.Get());
1054 pTP->rtPiece.height =
1056 float fBaseLineTemp =
1057 m_pTextParser->GetBaseline(m_pTextProvider, pStyle.Get());
1058 pTP->rtPiece.top = fBaseLineTemp;
1060 float fLineHeight = m_pTextParser->GetLineHeight(
1061 m_pTextProvider, pStyle.Get(), m_iLines == 0, fVerScale);
1062 if (fBaseLineTemp > 0) {
1063 float fLineHeightTmp = fBaseLineTemp + pTP->rtPiece.height;
1064 if (fLineHeight < fLineHeightTmp)
1065 fLineHeight = fLineHeightTmp;
1067 fLineStep =
std::max(fLineStep, fLineHeight);
1068 pTP->pLinkData = pUserData ? pUserData->m_pLinkData :
nullptr;
1069 pPieceLine->m_textPieces.push_back(
std::move(pTP));
1070 DoTabstops(pStyle.Get(), pPieceLine);
1072 for (
const auto& pTP : pPieceLine->m_textPieces) {
1073 float& fTop = pTP->rtPiece.top;
1074 float fBaseLineTemp = fTop;
1075 fTop = *pLinePos + fLineStep - pTP->rtPiece.height - fBaseLineTemp;
1076 fTop = std::max(0.0f, fTop);
1078 *pLinePos += fLineStep + fBaseLine;
1080 float fLineStep = 0;
1081 float fLineWidth = 0;
1082 for (int32_t i = 0; i < iPieces; i++) {
1086 pStyle = pUserData->m_pStyle;
1089 m_pTextParser->GetBaseline(m_pTextProvider, pStyle.Get());
1090 float fLineHeight = m_pTextParser->GetLineHeight(
1091 m_pTextProvider, pStyle.Get(), m_iLines == 0, fVerScale);
1092 if (fBaseLine > 0) {
1093 float fLineHeightTmp =
1096 if (fLineHeight < fLineHeightTmp) {
1097 fLineHeight = fLineHeightTmp;
1100 fLineStep =
std::max(fLineStep, fLineHeight);
1103 *pLinePos += fLineStep;
1104 m_fMaxWidth =
std::max(m_fMaxWidth, fLineWidth);
1105 if (m_pLoader && m_pLoader->bSaveLineHeight) {
1106 float fHeight = *pLinePos - m_pLoader->fLastPos;
1107 m_pLoader->fLastPos = *pLinePos;
1108 m_pLoader->lineHeights.push_back(fHeight);
1112 m_pBreak->ClearBreakPieces();
1115 if (!pStyle && bEndBreak) {
1116 CXFA_Para* para = m_pTextProvider->GetParaIfExists();
1121 fStartPos += fIndent;
1124 if (fSpaceBelow < 0.1f)
1127 m_pBreak->SetLineStartPos(fStartPos);
1128 *pLinePos += fSpaceBelow;
1135 const CFX_CSSRect* pRect = pStyle->GetMarginWidth();
1139 float fTextIndent = pStyle->GetTextIndent().GetValue();
1140 if (fTextIndent < 0)
1141 fStart -= fTextIndent;
1143 m_pBreak->SetLineStartPos(fStart);
1149 PieceLine* pPieceLine,
1151 std::vector<TextCharPos>* pCharPos,
1153 const TextPiece* pPiece = pPieceLine->m_textPieces[szPiece].get();
1154 size_t szCount = GetDisplayPos(pPiece, pCharPos);
1156 auto span = pdfium::make_span(pCharPos->data(), szCount);
1160 pPieceLine->m_charCounts.push_back(szCount);
1164 const PieceLine* pPieceLine,
1166 std::vector<TextCharPos>* pCharPos,
1168 const TextPiece* pPiece = pPieceLine->m_textPieces[szPiece].get();
1169 bool bNoUnderline = pPiece->iUnderline < 1 || pPiece->iUnderline > 2;
1170 bool bNoLineThrough = pPiece->iLineThrough < 1 || pPiece->iLineThrough > 2;
1171 if (bNoUnderline && bNoLineThrough)
1175 size_t szChars = GetDisplayPos(pPiece, pCharPos);
1179 float fEndY = (*pCharPos)[0].m_Origin.y + 1.05f;
1181 for (int32_t i = 0; i < pPiece->iUnderline; i++) {
1182 for (size_t j = 0; j < szChars; j++) {
1183 pt1.x = (*pCharPos)[j].m_Origin.x;
1185 (*pCharPos)[j].m_FontCharWidth * pPiece
->fFontSize / 1000.0f;
1186 pt1.y = pt2.y = fEndY;
1192 pt1.x = (*pCharPos)[0].m_Origin.x;
1193 pt2.x = (*pCharPos)[szChars - 1].m_Origin.x +
1194 (*pCharPos)[szChars - 1].m_FontCharWidth * pPiece
->fFontSize /
1196 for (int32_t i = 0; i < pPiece->iUnderline; i++) {
1197 pt1.y = pt2.y = fEndY;
1203 pt1.x = (*pCharPos)[0].m_Origin.x;
1205 (*pCharPos)[szChars - 1].m_Origin.x +
1206 (*pCharPos)[szChars - 1].m_FontCharWidth * pPiece
->fFontSize / 1000.0f;
1207 for (int32_t i = 0; i < pPiece->iLineThrough; i++) {
1208 pt1.y = pt2.y = fEndY;
1213 if (bNoLineThrough &&
1217 bool bHasCount =
false;
1218 size_t szPiecePrev = szPiece;
1219 size_t szPieceNext = szPiece;
1220 while (szPiecePrev > 0) {
1222 if (pPieceLine->m_charCounts[szPiecePrev] > 0) {
1231 while (szPieceNext + 1 < pPieceLine->m_textPieces.size()) {
1233 if (pPieceLine->m_charCounts[szPieceNext] > 0) {
1243 pPiece = pPieceLine->m_textPieces[szPiecePrev].get();
1244 szChars = GetDisplayPos(pPiece, pCharPos);
1249 (*pCharPos)[szChars - 1].m_Origin.x +
1250 (*pCharPos)[szChars - 1].m_FontCharWidth * pPiece
->fFontSize / 1000.0f;
1251 pPiece = pPieceLine->m_textPieces[szPieceNext].get();
1252 szChars = GetDisplayPos(pPiece, pCharPos);
1256 fEndX = (*pCharPos)[0].m_Origin.x;
1261 float fEndY = (*pCharPos)[0].m_Origin.y + 1.05f;
1262 for (int32_t i = 0; i < pPiece->iUnderline; i++) {
1269 for (int32_t i = 0; i < pPiece->iLineThrough; i++) {
1287size_t CXFA_TextLayout::GetDisplayPos(
const TextPiece* pPiece,
1288 std::vector<TextCharPos>* pCharPos) {
1291 return m_pBreak->GetDisplayPos(pPiece, pCharPos);
CFX_XMLElement * ToXMLElement(CFX_XMLNode *pNode)
const CFX_XMLText * ToXMLText(const CFX_XMLNode *pNode)
static bool DrawString(CFX_RenderDevice *device, FX_ARGB color, const RetainPtr< CFGAS_GEFont > &pFont, pdfium::span< TextCharPos > pCharPos, float fFontSize, const CFX_Matrix &matrix)
int32_t GetHorizontalScale() const
int32_t GetFontSize() const
int32_t GetCharCount() const
int32_t GetStartPos() const
const CFGAS_TextUserData * GetUserData() const
int32_t GetVerticalScale() const
int32_t GetBidiLevel() const
WideString GetString() const
void SetMarginWidth(const CFX_CSSRect &rect)
const CFX_CSSLength & GetTextIndent() const
const CFX_CSSRect * GetMarginWidth() const
CFX_CSSTextAlign GetTextAlign() const
const CFX_CSSRect * GetPaddingWidth() const
CFX_CSSLength & Set(CFX_CSSLengthUnit eUnit, float fValue)
void AppendLine(const CFX_PointF &pt1, const CFX_PointF &pt2)
FX_RECT GetOuterRect() const
bool SetClip_Rect(const FX_RECT &pRect)
bool DrawPath(const CFX_Path &path, const CFX_Matrix *pObject2Device, const CFX_GraphStateData *pGraphState, uint32_t fill_color, uint32_t stroke_color, const CFX_FillRenderOptions &fill_options)
void RestoreState(bool bKeepSaved)
WideString GetLocalTagName() const
WideString GetAttribute(const WideString &name) const
virtual Type GetType() const =0
const WideString & GetText() const
XFA_AttributeValue GetHorizontalAlign()
XFA_AttributeValue GetVerticalAlign()
float StartLayout(float fWidth)
WideString GetLinkURLAtPoint(const CFX_PointF &point)
CFX_SizeF CalcSize(const CFX_SizeF &minSize, const CFX_SizeF &maxSize)
bool DrawString(CFX_RenderDevice *pFxDevice, const CFX_Matrix &mtDoc2Device, const CFX_RectF &rtClip, size_t szBlockIndex)
float DoLayout(float fTextHeight)
float DoSplitLayout(size_t szBlockIndex, float fCalcHeight, float fTextHeight)
float Layout(const CFX_SizeF &size)
void ItemBlocks(const CFX_RectF &rtText, size_t szBlockIndex)
CFX_CSSDisplay GetDisplay() const
static WideString Format(const wchar_t *pFormat,...)
WideString & operator=(WideString &&that) noexcept
WideString & operator+=(wchar_t ch)
WideString & operator=(const WideString &that)
bool EqualsASCII(ByteStringView that) const
constexpr CFX_FillRenderOptions()