From d06de2e049761b7b9e8a95f17557d309812f7acc Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Fri, 19 Jul 2024 16:11:33 +0200 Subject: Related: tdf#162072 DOCX import: handle font family for characters Open the bugdoc, the first paragraph is meant to be sans and the second paragraph is meant to be serif, but both of them are serif. The bugdoc uses the fonts 'IBM Plex Sans' and 'IBM Plex Serif', which is not something we bundle, so the font fallback is expected, but the fallback should have a matching font family (roman vs swiss). Fix the problem by implementing support for in the DOCX import, which was just ignored previously. Now the DOCX import result in on par with the ODT import result. Change-Id: I321b9fc6f63126ca5ad61af57af8a5bc7456d5b4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170772 Tested-by: Jenkins Reviewed-by: Miklos Vajna --- sw/qa/writerfilter/dmapper/FontTable.cxx | 36 +++++++++++++++++++++++ sw/qa/writerfilter/dmapper/data/font-family.docx | Bin 0 -> 12207 bytes 2 files changed, 36 insertions(+) create mode 100644 sw/qa/writerfilter/dmapper/data/font-family.docx (limited to 'sw/qa') diff --git a/sw/qa/writerfilter/dmapper/FontTable.cxx b/sw/qa/writerfilter/dmapper/FontTable.cxx index 2fe3dced2e1f..2d5a80ca0476 100644 --- a/sw/qa/writerfilter/dmapper/FontTable.cxx +++ b/sw/qa/writerfilter/dmapper/FontTable.cxx @@ -9,6 +9,10 @@ #include +#include +#include +#include + #include using namespace com::sun::star; @@ -57,6 +61,38 @@ CPPUNIT_TEST_FIXTURE(Test, testSubsettedFullEmbeddedFont) CPPUNIT_ASSERT(!aUrl.isEmpty()); #endif } + +CPPUNIT_TEST_FIXTURE(Test, testFontFamily) +{ + // Given a document with 2 paragraphs, first is sans, second is serif: + // When loading that document: + loadFromFile(u"font-family.docx"); + + // Then make sure we import : + uno::Reference xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference xParaEnumAccess(xTextDocument->getText(), + uno::UNO_QUERY); + uno::Reference xParaEnum = xParaEnumAccess->createEnumeration(); + // First paragraph: sans. + uno::Reference xPortionEnumAccess(xParaEnum->nextElement(), + uno::UNO_QUERY); + uno::Reference xPortionEnum = xPortionEnumAccess->createEnumeration(); + uno::Reference xPortion(xPortionEnum->nextElement(), uno::UNO_QUERY); + sal_Int16 nFontFamily = awt::FontFamily::DONTKNOW; + xPortion->getPropertyValue(u"CharFontFamily"_ustr) >>= nFontFamily; + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 5 (SWISS) + // - Actual : 3 (ROMAN) + // i.e. the font family was not imported, all font family was roman. + CPPUNIT_ASSERT_EQUAL(awt::FontFamily::SWISS, nFontFamily); + // Second paragraph: serif. + xPortionEnumAccess.set(xParaEnum->nextElement(), uno::UNO_QUERY); + xPortionEnum = xPortionEnumAccess->createEnumeration(); + xPortion.set(xPortionEnum->nextElement(), uno::UNO_QUERY); + nFontFamily = awt::FontFamily::DONTKNOW; + xPortion->getPropertyValue(u"CharFontFamily"_ustr) >>= nFontFamily; + CPPUNIT_ASSERT_EQUAL(awt::FontFamily::ROMAN, nFontFamily); +} } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/writerfilter/dmapper/data/font-family.docx b/sw/qa/writerfilter/dmapper/data/font-family.docx new file mode 100644 index 000000000000..15bda10374ea Binary files /dev/null and b/sw/qa/writerfilter/dmapper/data/font-family.docx differ -- cgit