Make CFDE_TextOut::CalcLogicSize() take a WideStringView Fixes a longstanding TODO() about avoiding copying. Change-Id: Ia8eb94c272f79d300fc8b1856a3a69a263620ae5 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/61811 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/xfa/fde/cfde_texteditengine.cpp b/xfa/fde/cfde_texteditengine.cpp index ca40913..21b365b 100644 --- a/xfa/fde/cfde_texteditengine.cpp +++ b/xfa/fde/cfde_texteditengine.cpp
@@ -247,18 +247,16 @@ size_t chars_exceeding_size = 0; // TODO(dsinclair): Can this get changed to a binary search? for (size_t i = 0; i < num_to_check; i++) { - // This does a lot of string copying .... - // TODO(dsinclair): make CalcLogicSize take a WideStringC instead. - text_out->CalcLogicSize(WideString(temp), &text_rect); - + text_out->CalcLogicSize(temp, &text_rect); if (limit_horizontal_area_ && text_rect.width <= available_width_) break; if (limit_vertical_area_ && text_rect.height <= vertical_height) break; - --length; - temp = temp.Mid(0, length); ++chars_exceeding_size; + + --length; + temp = temp.Left(length); } return chars_exceeding_size;
diff --git a/xfa/fde/cfde_textout.cpp b/xfa/fde/cfde_textout.cpp index e10f3f8..cd419bd 100644 --- a/xfa/fde/cfde_textout.cpp +++ b/xfa/fde/cfde_textout.cpp
@@ -183,13 +183,13 @@ m_pTxtBreak->SetLineBreakTolerance(m_fTolerance); } -void CFDE_TextOut::CalcLogicSize(const WideString& str, CFX_SizeF* pSize) { +void CFDE_TextOut::CalcLogicSize(WideStringView str, CFX_SizeF* pSize) { CFX_RectF rtText(0.0f, 0.0f, pSize->width, pSize->height); CalcLogicSize(str, &rtText); *pSize = rtText.Size(); } -void CFDE_TextOut::CalcLogicSize(const WideString& str, CFX_RectF* pRect) { +void CFDE_TextOut::CalcLogicSize(WideStringView str, CFX_RectF* pRect) { if (str.IsEmpty()) { pRect->width = 0.0f; pRect->height = 0.0f;
diff --git a/xfa/fde/cfde_textout.h b/xfa/fde/cfde_textout.h index 473f5bc..bb65d28 100644 --- a/xfa/fde/cfde_textout.h +++ b/xfa/fde/cfde_textout.h
@@ -54,8 +54,8 @@ void SetMatrix(const CFX_Matrix& matrix) { m_Matrix = matrix; } void SetLineBreakTolerance(float fTolerance); - void CalcLogicSize(const WideString& str, CFX_SizeF* pSize); - void CalcLogicSize(const WideString& str, CFX_RectF* pRect); + void CalcLogicSize(WideStringView str, CFX_SizeF* pSize); + void CalcLogicSize(WideStringView str, CFX_RectF* pRect); void DrawLogicText(CFX_RenderDevice* device, WideStringView str, const CFX_RectF& rect);
diff --git a/xfa/fxfa/cxfa_fwltheme.cpp b/xfa/fxfa/cxfa_fwltheme.cpp index 5312525..fd798b9 100644 --- a/xfa/fxfa/cxfa_fwltheme.cpp +++ b/xfa/fxfa/cxfa_fwltheme.cpp
@@ -236,7 +236,7 @@ m_pTextOut->SetTextColor(FWLTHEME_CAPACITY_TextColor); m_pTextOut->SetAlignment(pParams.m_iTTOAlign); m_pTextOut->SetStyles(pParams.m_dwTTOStyles); - m_pTextOut->CalcLogicSize(pParams.m_wsText, pRect); + m_pTextOut->CalcLogicSize(pParams.m_wsText.AsStringView(), pRect); return; } @@ -246,7 +246,7 @@ m_pTextOut->SetTextColor(pNode->GetTextColor()); m_pTextOut->SetAlignment(pParams.m_iTTOAlign); m_pTextOut->SetStyles(pParams.m_dwTTOStyles); - m_pTextOut->CalcLogicSize(pParams.m_wsText, pRect); + m_pTextOut->CalcLogicSize(pParams.m_wsText.AsStringView(), pRect); } CFWL_WidgetTP* CXFA_FWLTheme::GetTheme(CFWL_Widget* pWidget) const {
diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp index 5daccc4..c324006 100644 --- a/xfa/fxfa/parser/cxfa_node.cpp +++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -3246,7 +3246,7 @@ pTextOut->SetStyles(dwStyles); } - layoutData->m_pTextOut->CalcLogicSize(wsText, pSize); + layoutData->m_pTextOut->CalcLogicSize(wsText.AsStringView(), pSize); } bool CXFA_Node::CalculateTextEditAutoSize(CXFA_FFDoc* doc, CFX_SizeF* pSize) {