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 <jonathan@libreoffice.org> Tested-by: Jenkins
This commit is contained in:
@@ -190,6 +190,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();
|
||||
|
||||
@@ -716,6 +716,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 );
|
||||
|
||||
Reference in New Issue
Block a user