From ad5dddb689337398a54200e83f9e694e9d70f5d3 Mon Sep 17 00:00:00 2001 From: Jaume Pujantell Date: Tue, 31 Mar 2026 16:17:51 +0200 Subject: [PATCH] sc: copy put font height in RTF export When copying a range of cell the font height was not exported in the RTF format string copied to the clipboard. Change-Id: Ib26df4775df506584da43538653fd209329def47 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/203068 Reviewed-by: Miklos Vajna Tested-by: Jenkins CollaboraOffice Signed-off-by: Xisco Fauli Reviewed-on: https://gerrit.libreoffice.org/c/core/+/204056 Tested-by: Jenkins --- sc/CppunitTest_sc_copypaste.mk | 1 + sc/qa/unit/copy_paste_test.cxx | 30 ++++++++++++++++++++++++++++++ sc/source/filter/rtf/rtfexp.cxx | 8 ++++++++ 3 files changed, 39 insertions(+) diff --git a/sc/CppunitTest_sc_copypaste.mk b/sc/CppunitTest_sc_copypaste.mk index 3beac9a67222..d83e2fe45965 100644 --- a/sc/CppunitTest_sc_copypaste.mk +++ b/sc/CppunitTest_sc_copypaste.mk @@ -23,6 +23,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sc_copypaste, \ comphelper \ cppu \ cppuhelper \ + editeng \ i18nlangtag \ sal \ sc \ diff --git a/sc/qa/unit/copy_paste_test.cxx b/sc/qa/unit/copy_paste_test.cxx index 759f65f71f9d..13be698fb1c9 100644 --- a/sc/qa/unit/copy_paste_test.cxx +++ b/sc/qa/unit/copy_paste_test.cxx @@ -21,6 +21,7 @@ #include #include #include +#include using namespace ::com::sun::star; using namespace ::com::sun::star::uno; @@ -46,6 +47,7 @@ public: void tdf137625_autofillMergedUserlist(); void tdf137624_autofillMergedMixed(); void tdf122716_rtf_portion_encoding(); + void testRTFFontHeight(); CPPUNIT_TEST_SUITE(ScCopyPasteTest); CPPUNIT_TEST(testCopyPasteXLS); @@ -64,6 +66,7 @@ public: CPPUNIT_TEST(tdf137625_autofillMergedUserlist); CPPUNIT_TEST(tdf137624_autofillMergedMixed); CPPUNIT_TEST(tdf122716_rtf_portion_encoding); + CPPUNIT_TEST(testRTFFontHeight); CPPUNIT_TEST_SUITE_END(); private: @@ -802,6 +805,33 @@ void ScCopyPasteTest::tdf122716_rtf_portion_encoding() CPPUNIT_ASSERT(rtf_string.indexOf("\\u352\\'3famp\\u363\\'3fnas") >= 0); } +void ScCopyPasteTest::testRTFFontHeight() +{ + createScDoc(); + ScDocument* pDoc = getScDoc(); + ScTabViewShell* pViewShell = getViewShell(); + pDoc->SetString(ScAddress(0, 0, 0), u"Text"_ustr); + sal_uInt32 nHeightPt = 8; + pDoc->ApplyAttr(0, 0, 0, SvxFontHeightItem(nHeightPt * 20, 100, ATTR_FONT_HEIGHT)); + + // Select a range containing A1: + ScRange aRange(0, 0, 0, 1, 0, 0); + pViewShell->GetViewData().GetMarkData().SetMarkArea(aRange); + + // Obtain a transferable, similar to what happens on copy to clipboard: + ScModelObj* pModelObj = comphelper::getFromUnoTunnel(mxComponent); + auto xTransferable = pModelObj->getSelection(); + // Get the RTF data: + auto aRTF + = xTransferable->getTransferData({ u"text/rtf"_ustr, {}, cppu::UnoType::get() }); + OUString sRTF; + CPPUNIT_ASSERT(aRTF >>= sRTF); + + // Check that the font height was exported (in Half-point units) + OUString sText = "\\fs" + OUString::number(nHeightPt * 2); + CPPUNIT_ASSERT(sRTF.indexOf(sText) >= 0); +} + ScCopyPasteTest::ScCopyPasteTest() : ScModelTestBase(u"/sc/qa/unit/data/"_ustr) { diff --git a/sc/source/filter/rtf/rtfexp.cxx b/sc/source/filter/rtf/rtfexp.cxx index 586d0ee35597..cace80fcdcc1 100644 --- a/sc/source/filter/rtf/rtfexp.cxx +++ b/sc/source/filter/rtf/rtfexp.cxx @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -260,6 +261,7 @@ void ScRTFExport::WriteCell( SCTAB nTab, SCROW nRow, SCCOL nCol ) bool bResetAttr(false); const SvxFontItem& rFontItem = pAttr->GetItem( ATTR_FONT ); + const SvxFontHeightItem& rFontHeightItem = pAttr->GetItem(ATTR_FONT_HEIGHT); const SvxHorJustifyItem& rHorJustifyItem = pAttr->GetItem( ATTR_HOR_JUSTIFY ); const SvxWeightItem& rWeightItem = pAttr->GetItem( ATTR_FONT_WEIGHT ); const SvxPostureItem& rPostureItem = pAttr->GetItem( ATTR_FONT_POSTURE ); @@ -268,6 +270,12 @@ void ScRTFExport::WriteCell( SCTAB nTab, SCROW nRow, SCCOL nCol ) m_aDocStrm.WriteOString( OOO_STRING_SVTOOLS_RTF_F ) .WriteOString( OString::number(AddFont(rFontItem)) ); + m_aDocStrm.WriteOString(OOO_STRING_SVTOOLS_RTF_FS); + sal_Int32 nHeight = rFontHeightItem.GetHeight(); + // Twips => HalfPoints + nHeight /= 10; + m_aDocStrm.WriteNumberAsString(nHeight); + const char* pChar; switch( rHorJustifyItem.GetValue() )