diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2022-05-23 11:26:43 +0200 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2022-05-24 13:25:23 +0200 |
commit | b3bdb10195cca95b632d0489a16a675b4717754d (patch) | |
tree | 34d3d5406d1748cdaebc72e0f2b440be9ac5b38e /vcl | |
parent | b4ae96a261ccb7bbaaa2f7bc844a6a0e973755d5 (diff) |
do not use ubidi_setLine() for text runs
As far as I understand this, the setLine() is meant to be called for
every line in the paragraph set by setPara(), but
- our text layout API does not say this in any way, it may be kind of
assumed that a substring is a line in a paragraph, but it's not a given,
as we call layout functions also e.g. for underlined parts of the text
- as I understand it after looking at the source of that function,
it really just changes processing to work on a subset of the paragraph,
so all it seems to do is to prepare the whole text once with setPara()
and then reuse that with repeated calls to setLine(), so it's basically
just an optimization, but here using setPara() on the entire string
actually should make it slower by processing parts of the string that
are not used
- if the substring contains some control characters that may be
interpreted as going to the next paragraph (#moz147714-1 does this with
0x1e record-separator character), then setLine() will fail because
it will not consider the substring to be in just one paragraph and there
will be no run detected
Change-Id: Ided1d777f086f7905732b408e845405db0163e49
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134763
Tested-by: Luboš Luňák <l.lunak@collabora.com>
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/source/text/ImplLayoutArgs.cxx | 21 |
1 files changed, 5 insertions, 16 deletions
diff --git a/vcl/source/text/ImplLayoutArgs.cxx b/vcl/source/text/ImplLayoutArgs.cxx index 0638473f4168..dbdc6e18f5a0 100644 --- a/vcl/source/text/ImplLayoutArgs.cxx +++ b/vcl/source/text/ImplLayoutArgs.cxx @@ -59,28 +59,19 @@ ImplLayoutArgs::ImplLayoutArgs(const OUString& rStr, int nMinCharPos, int nEndCh // prepare substring for BiDi analysis // TODO: reuse allocated pParaBidi UErrorCode rcI18n = U_ZERO_ERROR; - const int nLength = mrStr.getLength(); + const int nLength = mnEndCharPos - mnMinCharPos; UBiDi* pParaBidi = ubidi_openSized(nLength, 0, &rcI18n); if (!pParaBidi) return; - ubidi_setPara(pParaBidi, reinterpret_cast<const UChar*>(mrStr.getStr()), nLength, nLevel, - nullptr, &rcI18n); - - UBiDi* pLineBidi = pParaBidi; - int nSubLength = mnEndCharPos - mnMinCharPos; - if (nSubLength != nLength) - { - pLineBidi = ubidi_openSized(nSubLength, 0, &rcI18n); - ubidi_setLine(pParaBidi, mnMinCharPos, mnEndCharPos, pLineBidi, &rcI18n); - } + ubidi_setPara(pParaBidi, reinterpret_cast<const UChar*>(mrStr.getStr()) + mnMinCharPos, + nLength, nLevel, nullptr, &rcI18n); // run BiDi algorithm - const int nRunCount = ubidi_countRuns(pLineBidi, &rcI18n); - //maRuns.resize( 2 * nRunCount ); + const int nRunCount = ubidi_countRuns(pParaBidi, &rcI18n); for (int i = 0; i < nRunCount; ++i) { int32_t nMinPos, nRunLength; - const UBiDiDirection nDir = ubidi_getVisualRun(pLineBidi, i, &nMinPos, &nRunLength); + const UBiDiDirection nDir = ubidi_getVisualRun(pParaBidi, i, &nMinPos, &nRunLength); const int nPos0 = nMinPos + mnMinCharPos; const int nPos1 = nPos0 + nRunLength; @@ -89,8 +80,6 @@ ImplLayoutArgs::ImplLayoutArgs(const OUString& rStr, int nMinCharPos, int nEndCh } // cleanup BiDi engine - if (pLineBidi != pParaBidi) - ubidi_close(pLineBidi); ubidi_close(pParaBidi); } |