editeng/qa/editeng/editeng.cxx | 22 ++++++++++++++++++++++ editeng/source/editeng/impedit4.cxx | 6 ++++++ 2 files changed, 28 insertions(+)
New commits: commit bbff30981d91716efab7d3c8d106bb1238927e69 Author: Jonathan Clark <[email protected]> AuthorDate: Tue Jun 17 04:06:49 2025 -0600 Commit: Andras Timar <[email protected]> CommitDate: Wed Oct 15 16:57:21 2025 +0200 tdf#119192 editeng: Fix for copy-and-paste using font from wrong script To minimize the size of the output RTF, Edit Engine only emits font attributes when either the font changes or when the script type changes. In the latter case, Edit Engine was previously writing font attributes inside a child scope, rather than the paragraph scope. Font changes related to a language change would thus apply only to the first run of characters in that language, while following runs would appear to use an arbitrary language. Change-Id: Iff38299bffaf3045cef5c6e71b8cab441ba0be39 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186612 Reviewed-by: Jonathan Clark <[email protected]> Tested-by: Jenkins (cherry picked from commit c28307fa99dae0322a3dca7ce0010d87c93ec85a) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186636 Reviewed-by: Xisco Fauli <[email protected]> (cherry picked from commit a64df17b7a922d8d9f1cd2358c9f2f78bc6fd6e8) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/192442 Reviewed-by: Andras Timar <[email protected]> Tested-by: Jenkins CollaboraOffice <[email protected]> diff --git a/editeng/qa/editeng/editeng.cxx b/editeng/qa/editeng/editeng.cxx index 811ff31c2a12..a5bf51442eb3 100644 --- a/editeng/qa/editeng/editeng.cxx +++ b/editeng/qa/editeng/editeng.cxx @@ -193,6 +193,28 @@ CPPUNIT_TEST_FIXTURE(Test, testRTFStyleExportFollowRecursive) SvMemoryStream& rStream = pData->GetRTFStream(); CPPUNIT_ASSERT_GREATER(static_cast<sal_uInt64>(0), rStream.remainingSize()); } + +CPPUNIT_TEST_FIXTURE(Test, testTdf119192) +{ + // Tests that font changes due to a script type change are placed in paragraph scope + EditEngine aEditEngine(mpItemPool.get()); + + OUString aText = u"mytest"_ustr; + aEditEngine.SetText(aText); + + uno::Reference<datatransfer::XTransferable> xData + = aEditEngine.CreateTransferable(ESelection(0, 0, 0, aText.getLength())); + + auto pData = dynamic_cast<EditDataObject*>(xData.get()); + SvMemoryStream& rStream = pData->GetRTFStream(); + + std::string aCnt{ static_cast<const char*>(rStream.GetData()), + static_cast<size_t>(rStream.GetSize()) }; + + // Without the fix, the RTF text will include font attributes inside the curly braces. + bool bContains = (aCnt.find("{mytest}") != std::string::npos); + CPPUNIT_ASSERT(bContains); +} } CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/editeng/source/editeng/impedit4.cxx b/editeng/source/editeng/impedit4.cxx index 6d37fed5fe88..4922ad17e07a 100644 --- a/editeng/source/editeng/impedit4.cxx +++ b/editeng/source/editeng/impedit4.cxx @@ -686,6 +686,12 @@ ErrCode ImpEditEngine::WriteRTF( SvStream& rOutput, EditSelection aSel, bool bCl aAttribItems.Insert( &aAttribs.Get( GetScriptItemId( EE_CHAR_WEIGHT, nScriptType ) ) ); aAttribItems.Insert( &aAttribs.Get( GetScriptItemId( EE_CHAR_ITALIC, nScriptType ) ) ); aAttribItems.Insert( &aAttribs.Get( GetScriptItemId( EE_CHAR_LANGUAGE, nScriptType ) ) ); + + // tdf#119192: Write these font attributes at paragraph scope, so they can be + // reused across multiple runs. + WriteItemListAsRTF(aAttribItems, rOutput, nNode, nIndex, aFontTable, + aColorList); + aAttribItems.Clear(); } // Insert hard attribs AFTER CJK attribs... lcl_FindValidAttribs( aAttribItems, pNode, nIndex, nScriptTypeI18N );
