Skip to content

Commit

Permalink
Fix surrogate pairs handling when tweaking script info
Browse files Browse the repository at this point in the history
Followup to:

commit 3af30ba
Author: Khaled Hosny <[email protected]>
Date:   Thu Jul 27 19:03:28 2023 +0300

    sw: Handle surrogate pairs when tweaking script info

and:

commit d6efe8c
Author: Khaled Hosny <[email protected]>
Date:   Thu Jul 27 20:39:22 2023 +0300

    tdf#112594: Group NNBSP with the Mongolian characters after it

Change-Id: Ie273c457e4f3ed31a3372bc8eb0eb0055c1b97b1
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155053
Tested-by: Jenkins
Reviewed-by: Michael Stahl <[email protected]>
  • Loading branch information
khaledhosny authored and mistmist committed Jul 31, 2023
1 parent 74963f6 commit 5526c52
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
3 changes: 1 addition & 2 deletions editeng/source/editeng/impedit2.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1742,8 +1742,7 @@ void ImpEditEngine::InitScriptTypes( sal_Int32 nPara )
(nPrevChar == 0x202F /* NNBSP, tdf#112594 */ &&
u_getIntPropertyValue(nChar, UCHAR_SCRIPT) == USCRIPT_MONGOLIAN))
{
--nPos;
rTypes.back().nEndPos--;
rTypes.back().nEndPos = nPos = nPrevPos;
break;
}
}
Expand Down
1 change: 1 addition & 0 deletions sw/qa/core/text/data/scriptinfo-surrogate-pairs.fodt
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@
<text:sequence-decl text:display-outline-level="0" text:name="Figure"/>
</text:sequence-decls>
<text:p text:style-name="Standard">11◌𐻽</text:p>
<text:p text:style-name="Standard">11𝐀َ</text:p>
</office:text>
</office:body>
</office:document>
13 changes: 11 additions & 2 deletions sw/qa/core/text/text.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1475,9 +1475,18 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testScriptinfosurrogatePairs)
// Without the fix it fails with:
// - Expected: 11
// - Actual : 11◌
assertXPath(pXmlDoc, "//SwParaPortion/SwLineLayout/SwLinePortion[1]", "portion", u"11");
assertXPath(pXmlDoc, "//SwParaPortion/SwLineLayout/SwLinePortion[2]", "portion",
assertXPath(pXmlDoc, "//txt[1]/SwParaPortion/SwLineLayout/SwLinePortion[1]", "portion", u"11");
assertXPath(pXmlDoc, "//txt[1]/SwParaPortion/SwLineLayout/SwLinePortion[2]", "portion",
u"\u25CC\U00010EFD");

// Without the fix this would crash because we got a lone surrogate that
// can’t be converted to UTF-8, but if it were not for that it might fail
// with something like:
// - Expected: 11
// - Actual : 11𝐀
assertXPath(pXmlDoc, "//txt[2]/SwParaPortion/SwLineLayout/SwLinePortion[1]", "portion", u"11");
assertXPath(pXmlDoc, "//txt[2]/SwParaPortion/SwLineLayout/SwLinePortion[2]", "portion",
u"\U0001D400\u064E");
}

CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testTdf112594)
Expand Down
2 changes: 1 addition & 1 deletion sw/source/core/text/porlay.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1457,7 +1457,7 @@ void SwScriptInfo::InitScriptInfo(const SwTextNode& rNode,
(nPrevChar == CHAR_NNBSP &&
u_getIntPropertyValue(nChar, UCHAR_SCRIPT) == USCRIPT_MONGOLIAN))
{
--nPos;
nPos = nPrevPos;
}
}
m_ScriptChanges.emplace_back(TextFrameIndex(nPos), nScript);
Expand Down

0 comments on commit 5526c52

Please sign in to comment.