diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2024-07-16 14:49:23 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2024-07-16 17:21:05 +0200 |
commit | 09da7fd9cec9b36f2e09c1105a9263b83e2c66e4 (patch) | |
tree | 77cea4021eaab38787e3064bb145fd50bdf8d7cb /sw | |
parent | 828b26bdc22743974655d64dada69e154159435a (diff) |
tdf#162002 DOCX import, font embed: only discard subset fonts with few glyphs
Commit a9f3c11375525a7708378dd3648febc40db1ad20 (tdf#162002 DOCX import:
ignore subsetted embedded fonts for editing, 2024-07-12) decided to
ignore all subsetted fonts for editing, improve this a little so we only
ignore subsetted fonts when they can't even provide an English alphabet
in any form (lowercase, uppercase).
This avoids the possible problem that a font is marked as subsetted but
it's good enough in practice and we would still throw it away for
editing.
Change-Id: I0bc0e14ffc0c039f029220991bd16d9e3254f059
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170570
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/writerfilter/dmapper/FontTable.cxx | 18 | ||||
-rw-r--r-- | sw/qa/writerfilter/dmapper/data/subsetted-full-embedded-font.docx | bin | 0 -> 85639 bytes | |||
-rw-r--r-- | sw/source/writerfilter/dmapper/FontTable.cxx | 15 | ||||
-rw-r--r-- | sw/source/writerfilter/dmapper/FontTable.hxx | 3 |
4 files changed, 27 insertions, 9 deletions
diff --git a/sw/qa/writerfilter/dmapper/FontTable.cxx b/sw/qa/writerfilter/dmapper/FontTable.cxx index 798d68d0a193..2fe3dced2e1f 100644 --- a/sw/qa/writerfilter/dmapper/FontTable.cxx +++ b/sw/qa/writerfilter/dmapper/FontTable.cxx @@ -39,6 +39,24 @@ CPPUNIT_TEST_FIXTURE(Test, testSubsettedEmbeddedFont) // during editing may be missing from the subsetted font: CPPUNIT_ASSERT(aUrl.isEmpty()); } + +CPPUNIT_TEST_FIXTURE(Test, testSubsettedFullEmbeddedFont) +{ +#if !defined(MACOSX) // FIXME fails on macOS + // Given a document with an embedded font (marked as subsetted, but otherwise full in practice), + // loaded for editing: + loadFromFile(u"subsetted-full-embedded-font.docx"); + + // When checking if the font is available: + OUString aUrl = EmbeddedFontsHelper::fontFileUrl( + u"IBM Plex Serif Light", FAMILY_ROMAN, ITALIC_NONE, WEIGHT_NORMAL, PITCH_VARIABLE, + EmbeddedFontsHelper::FontRights::ViewingAllowed); + + // Then make sure the subsetted font is available, given that it has the reasonable amount of + // glyphs: + CPPUNIT_ASSERT(!aUrl.isEmpty()); +#endif +} } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/writerfilter/dmapper/data/subsetted-full-embedded-font.docx b/sw/qa/writerfilter/dmapper/data/subsetted-full-embedded-font.docx Binary files differnew file mode 100644 index 000000000000..7cdbaf271d6b --- /dev/null +++ b/sw/qa/writerfilter/dmapper/data/subsetted-full-embedded-font.docx diff --git a/sw/source/writerfilter/dmapper/FontTable.cxx b/sw/source/writerfilter/dmapper/FontTable.cxx index 3262d732e2fb..7cc8a39b3ef1 100644 --- a/sw/source/writerfilter/dmapper/FontTable.cxx +++ b/sw/source/writerfilter/dmapper/FontTable.cxx @@ -236,11 +236,13 @@ bool FontTable::IsReadOnly() const void FontTable::addEmbeddedFont(const css::uno::Reference<css::io::XInputStream>& stream, const OUString& fontName, std::u16string_view extra, - std::vector<unsigned char> const & key) + std::vector<unsigned char> const & key, + bool bSubsetted) { if (!m_pImpl->xEmbeddedFontHelper) m_pImpl->xEmbeddedFontHelper.reset(new EmbeddedFontsHelper); - m_pImpl->xEmbeddedFontHelper->addEmbeddedFont(stream, fontName, extra, key); + m_pImpl->xEmbeddedFontHelper->addEmbeddedFont(stream, fontName, extra, key, + /*eot=*/false, bSubsetted); } EmbeddedFontHandler::EmbeddedFontHandler(FontTable& rFontTable, OUString _fontName, std::u16string_view style ) @@ -256,11 +258,6 @@ EmbeddedFontHandler::~EmbeddedFontHandler() if( !m_inputStream.is()) return; - if (m_bSubsetted && !m_fontTable.IsReadOnly()) - { - return; - } - std::vector< unsigned char > key( 32 ); if( !m_fontKey.isEmpty()) { // key for unobfuscating @@ -280,7 +277,9 @@ EmbeddedFontHandler::~EmbeddedFontHandler() key[ i + 16 ] = val; } } - m_fontTable.addEmbeddedFont( m_inputStream, m_fontName, m_style, key ); + // Ignore the "subsetted" flag if we're not editing anyway. + bool bSubsetted = m_bSubsetted && !m_fontTable.IsReadOnly(); + m_fontTable.addEmbeddedFont( m_inputStream, m_fontName, m_style, key, bSubsetted ); m_inputStream->closeInput(); } diff --git a/sw/source/writerfilter/dmapper/FontTable.hxx b/sw/source/writerfilter/dmapper/FontTable.hxx index 9ad092befe79..babb43d8aebb 100644 --- a/sw/source/writerfilter/dmapper/FontTable.hxx +++ b/sw/source/writerfilter/dmapper/FontTable.hxx @@ -53,7 +53,8 @@ class FontTable : public LoggedProperties, public LoggedTable void addEmbeddedFont(const css::uno::Reference<css::io::XInputStream>& stream, const OUString& fontName, std::u16string_view extra, - std::vector<unsigned char> const & key); + std::vector<unsigned char> const & key, + bool bSubsetted); bool IsReadOnly() const; private: |