sw/qa/writerfilter/dmapper/DomainMapper.cxx | 25 ++++++++++++++++++++++++ sw/qa/writerfilter/dmapper/data/font-family.rtf | 12 +++++++++++ sw/source/writerfilter/dmapper/DomainMapper.cxx | 2 - 3 files changed, 38 insertions(+), 1 deletion(-)
New commits: commit f2191fa91094a951df4a9a717a1c012eab5f9aad Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Thu Jan 30 10:18:46 2025 +0100 Commit: Gabor Kelemen <gabor.kelemen.ext...@allotropia.de> CommitDate: Tue Feb 4 22:36:30 2025 +0100 tdf#164904 RTF import: fix unexpected CharFontFamily Open the RTF in Word, the font fallback is serif, open in Writer, our fallback is sans. roman is not parsed by the RTF import, but the default font family was ROMAN and that worked in the past. Fix the problem by only setting the property in case the tokenizer has a value for it, there is a difference between not setting it vs setting it to "don't know". Regression from commit d06de2e049761b7b9e8a95f17557d309812f7acc (Related: tdf#162072 DOCX import: handle font family for characters, 2024-07-19). Change-Id: I4253ac7e27fab7d3e8e61c43659589b4fc177d6c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180934 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmik...@collabora.com> (cherry picked from commit 7af540ddeb42a3a733f258a77e17c7ebb16d4571) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180936 Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> (cherry picked from commit c2c39d4c46c3ae9416c1772bf4f0a3865b77c817) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181124 Tested-by: allotropia jenkins <jenk...@allotropia.de> Reviewed-by: Gabor Kelemen <gabor.kelemen.ext...@allotropia.de> Tested-by: Gabor Kelemen <gabor.kelemen.ext...@allotropia.de> diff --git a/sw/qa/writerfilter/dmapper/DomainMapper.cxx b/sw/qa/writerfilter/dmapper/DomainMapper.cxx index c33e7e7f29b9..52fe40108a27 100644 --- a/sw/qa/writerfilter/dmapper/DomainMapper.cxx +++ b/sw/qa/writerfilter/dmapper/DomainMapper.cxx @@ -17,6 +17,7 @@ #include <com/sun/star/style/XStyleFamiliesSupplier.hpp> #include <com/sun/star/document/XFilter.hpp> #include <com/sun/star/document/XImporter.hpp> +#include <com/sun/star/awt/FontFamily.hpp> #include <tools/UnitConversion.hxx> #include <unotools/streamwrap.hxx> @@ -225,6 +226,30 @@ CPPUNIT_TEST_FIXTURE(Test, testRTFStylePaste) // was imported, even if no pasted content referenced it. CPPUNIT_ASSERT(!xStyleFamily->hasByName(u"Default Drawing Style"_ustr)); } + +CPPUNIT_TEST_FIXTURE(Test, testRTFFontFamily) +{ + // Given an RTF file with a 'Times New (W1)' font: + loadFromFile(u"font-family.rtf"); + + // When checking the font family: + uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(), + uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration(); + uno::Reference<container::XEnumerationAccess> xPara(xParaEnum->nextElement(), uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xPortionEnum = xPara->createEnumeration(); + uno::Reference<beans::XPropertySet> xPortion(xPortionEnum->nextElement(), uno::UNO_QUERY); + sal_Int16 eFamily{}; + xPortion->getPropertyValue(u"CharFontFamily"_ustr) >>= eFamily; + + // Then make sure it's roman: + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 3 (ROMAN) + // - Actual : 0 (DONTKNOW) + // i.e. the final result was a sans fallback instead of a serif fallback. + CPPUNIT_ASSERT_EQUAL(awt::FontFamily::ROMAN, eFamily); +} } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/writerfilter/dmapper/data/font-family.rtf b/sw/qa/writerfilter/dmapper/data/font-family.rtf new file mode 100644 index 000000000000..b776df8ac5cd --- /dev/null +++ b/sw/qa/writerfilter/dmapper/data/font-family.rtf @@ -0,0 +1,12 @@ +{ tf1 +{onttbl +{42bidi romancharset0prq2 +Times New (W1) +{\*alt Times New Roman} +;} +} +\paperw11906\paperh16838\margl1440\margr1440\margt1440\margb1440 +\pard\plain +42 Lorem ipsum +\par +} diff --git a/sw/source/writerfilter/dmapper/DomainMapper.cxx b/sw/source/writerfilter/dmapper/DomainMapper.cxx index dd01c1b0a06d..b6075e2b3810 100644 --- a/sw/source/writerfilter/dmapper/DomainMapper.cxx +++ b/sw/source/writerfilter/dmapper/DomainMapper.cxx @@ -426,7 +426,7 @@ void DomainMapper::lcl_attribute(Id nName, Value & val) // Set the matching font family if we have one. FontEntry::Pointer_t pFontEntry = m_pImpl->GetFontTable()->getFontEntryByName(sStringValue); - if (pFontEntry) + if (pFontEntry && pFontEntry->m_nFontFamily != awt::FontFamily::DONTKNOW) { m_pImpl->GetTopContext()->Insert(PROP_CHAR_FONT_FAMILY, uno::Any(pFontEntry->m_nFontFamily));