diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2024-07-19 16:11:33 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2024-07-19 22:38:42 +0200 |
commit | d06de2e049761b7b9e8a95f17557d309812f7acc (patch) | |
tree | 8cf44ef775670837639b6eef4b7c05089486b47e /sw/qa | |
parent | 6fd88230b543e98ff6981472cc075fd7bd2f6d9b (diff) |
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 <w:family w:val="..."> 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 <vmiklos@collabora.com>
Diffstat (limited to 'sw/qa')
-rw-r--r-- | sw/qa/writerfilter/dmapper/FontTable.cxx | 36 | ||||
-rw-r--r-- | sw/qa/writerfilter/dmapper/data/font-family.docx | bin | 0 -> 12207 bytes |
2 files changed, 36 insertions, 0 deletions
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 <test/unoapi_test.hxx> +#include <com/sun/star/awt/FontFamily.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/text/XTextDocument.hpp> + #include <vcl/embeddedfontshelper.hxx> 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 <w:family w:val="...">: + 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(); + // First paragraph: sans. + uno::Reference<container::XEnumerationAccess> xPortionEnumAccess(xParaEnum->nextElement(), + uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xPortionEnum = xPortionEnumAccess->createEnumeration(); + uno::Reference<beans::XPropertySet> 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 Binary files differnew file mode 100644 index 000000000000..15bda10374ea --- /dev/null +++ b/sw/qa/writerfilter/dmapper/data/font-family.docx |