From c831580e1b4547d5fcbe74864e657c1c4ebffc12 Mon Sep 17 00:00:00 2001 From: Henrique Nakashima Date: Thu, 19 Apr 2018 21:59:33 +0000 Subject: Fix duplicated text in each line in XFA widgets. When calculating the characters to display, the run offset was not added to the offset inside the run, so characters from the first run were always used instead of from the run that the line should display. Bug: chromium:832909 Change-Id: I4d1d284894ce6ac9c7a49976aa6a6d0cf21f1382 Reviewed-on: https://pdfium-review.googlesource.com/30993 Commit-Queue: Henrique Nakashima Reviewed-by: dsinclair --- xfa/fde/cfde_texteditengine.cpp | 2 ++ xfa/fgas/layout/cfx_txtbreak.cpp | 19 ++++++++++++------- xfa/fgas/layout/cfx_txtbreak.h | 1 + 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/xfa/fde/cfde_texteditengine.cpp b/xfa/fde/cfde_texteditengine.cpp index ac66fd7f99..a423ba6eb4 100644 --- a/xfa/fde/cfde_texteditengine.cpp +++ b/xfa/fde/cfde_texteditengine.cpp @@ -953,6 +953,7 @@ std::vector CFDE_TextEditEngine::GetCharRects( FX_TXTRUN tr; tr.pEdtEngine = this; + tr.iStart = piece.nStart; tr.iLength = piece.nCount; tr.pFont = font_; tr.fFontSize = font_size_; @@ -969,6 +970,7 @@ std::vector CFDE_TextEditEngine::GetDisplayPos( FX_TXTRUN tr; tr.pEdtEngine = this; + tr.iStart = piece.nStart; tr.iLength = piece.nCount; tr.pFont = font_; tr.fFontSize = font_size_; diff --git a/xfa/fgas/layout/cfx_txtbreak.cpp b/xfa/fgas/layout/cfx_txtbreak.cpp index c3075b00dc..ccbc6a817a 100644 --- a/xfa/fgas/layout/cfx_txtbreak.cpp +++ b/xfa/fgas/layout/cfx_txtbreak.cpp @@ -686,11 +686,12 @@ int32_t CFX_TxtBreak::GetDisplayPos(const FX_TXTRUN* pTxtRun, bool bShadda = false; bool bLam = false; for (int32_t i = 0; i <= iLength; i++) { + int32_t iAbsolute = i + pTxtRun->iStart; int32_t iWidth; wchar_t wch; if (pEngine) { - wch = pEngine->GetChar(i); - iWidth = pEngine->GetWidthOfChar(i); + wch = pEngine->GetChar(iAbsolute); + iWidth = pEngine->GetWidthOfChar(iAbsolute); } else { wch = *pStr++; iWidth = *pWidths++; @@ -709,7 +710,8 @@ int32_t CFX_TxtBreak::GetDisplayPos(const FX_TXTRUN* pTxtRun, if (pEngine) { iNext = i + 1; while (iNext <= iLength) { - wNext = pEngine->GetChar(iNext); + int32_t iNextAbsolute = iNext + pTxtRun->iStart; + wNext = pEngine->GetChar(iNextAbsolute); dwProps = FX_GetUnicodeProperties(wNext); if ((dwProps & FX_CHARTYPEBITSMASK) != FX_CHARTYPE_Combination) break; @@ -747,8 +749,10 @@ int32_t CFX_TxtBreak::GetDisplayPos(const FX_TXTRUN* pTxtRun, wNext = 0xFEFF; if (pEngine) { iNext = i + 1; - if (iNext <= iLength) - wNext = pEngine->GetChar(iNext); + if (iNext <= iLength) { + int32_t iNextAbsolute = iNext + pTxtRun->iStart; + wNext = pEngine->GetChar(iNextAbsolute); + } } else { if (i < iLength) wNext = *pStr; @@ -930,9 +934,10 @@ std::vector CFX_TxtBreak::GetCharRects(const FX_TXTRUN* pTxtRun, std::vector rtArray(iLength); for (int32_t i = 0; i < iLength; i++) { + int32_t iAbsolute = i + pTxtRun->iStart; if (pEngine) { - wch = pEngine->GetChar(i); - iCharSize = pEngine->GetWidthOfChar(i); + wch = pEngine->GetChar(iAbsolute); + iCharSize = pEngine->GetWidthOfChar(iAbsolute); } else { wch = *pStr++; iCharSize = *pWidths++; diff --git a/xfa/fgas/layout/cfx_txtbreak.h b/xfa/fgas/layout/cfx_txtbreak.h index b43fda0e2f..a0e034280b 100644 --- a/xfa/fgas/layout/cfx_txtbreak.h +++ b/xfa/fgas/layout/cfx_txtbreak.h @@ -42,6 +42,7 @@ struct FX_TXTRUN { CFDE_TextEditEngine* pEdtEngine; WideString wsStr; int32_t* pWidths; + int32_t iStart; int32_t iLength; RetainPtr pFont; float fFontSize; -- cgit v1.2.3