summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/vcl/embeddedfontshelper.hxx19
-rw-r--r--oox/source/export/drawingml.cxx5
-rw-r--r--sd/qa/unit/FontEmbeddingTest.cxx4
-rw-r--r--sd/qa/unit/data/TestEmbeddedFonts_DejaVu.odpbin0 -> 12974 bytes
-rw-r--r--sd/source/filter/eppt/pptx-epptooxml.cxx9
-rw-r--r--vcl/source/gdi/embeddedfontshelper.cxx26
6 files changed, 51 insertions, 12 deletions
diff --git a/include/vcl/embeddedfontshelper.hxx b/include/vcl/embeddedfontshelper.hxx
index 404afac13ec1..6082144a3c30 100644
--- a/include/vcl/embeddedfontshelper.hxx
+++ b/include/vcl/embeddedfontshelper.hxx
@@ -22,10 +22,7 @@
namespace com::sun::star::io { class XInputStream; }
namespace com::sun::star::uno { template <typename > class Reference; }
-/**
- Helper functions for handling embedded fonts in documents.
-
-*/
+/** Helper functions for handling embedded fonts in documents. */
class VCL_DLLPUBLIC EmbeddedFontsHelper
{
private:
@@ -100,6 +97,20 @@ public:
*/
static void clearTemporaryFontFiles();
+ /** True if the font is common and doesn't need to be embedded
+ *
+ * A font is common is a font that is available or can be substituted
+ * for a metric compatible font on common platforms and editors. Not
+ * embedding such a font should not cause any issues with the document
+ * format and rendering.
+ *
+ * For example "Liberation Serif" is a common font because it's available
+ * in any typical LibreOffice installation or is substituted for the
+ * "Times New Roman" metric compatible font for compatibility with other
+ * editors.
+ */
+ static bool isCommonFont(std::u16string_view aFontName);
+
~EmbeddedFontsHelper() COVERITY_NOEXCEPT_FALSE
{
activateFonts();
diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx
index a711c9079b98..a6739f35cf00 100644
--- a/oox/source/export/drawingml.cxx
+++ b/oox/source/export/drawingml.cxx
@@ -118,6 +118,7 @@
#include <unotools/fontdefs.hxx>
#include <vcl/cvtgrf.hxx>
#include <vcl/svapp.hxx>
+#include <vcl/embeddedfontshelper.hxx>
#include <rtl/strbuf.hxx>
#include <filter/msfilter/escherex.hxx>
#include <filter/msfilter/util.hxx>
@@ -2836,7 +2837,7 @@ void DrawingML::WriteRunProperties( const Reference< XPropertySet >& rRun, bool
mAny >>= usTypeface;
- if (!mbEmbedFonts)
+ if (!mbEmbedFonts || EmbeddedFontsHelper::isCommonFont(usTypeface))
{
OUString aSubstName( GetSubsFontName( usTypeface, SubsFontFlags::ONLYONE | SubsFontFlags::MS ) );
if (!aSubstName.isEmpty())
@@ -2861,7 +2862,7 @@ void DrawingML::WriteRunProperties( const Reference< XPropertySet >& rRun, bool
OUString usTypeface;
mAny >>= usTypeface;
- if (!mbEmbedFonts)
+ if (!mbEmbedFonts || EmbeddedFontsHelper::isCommonFont(usTypeface))
{
OUString aSubstName( GetSubsFontName( usTypeface, SubsFontFlags::ONLYONE | SubsFontFlags::MS ) );
if (!aSubstName.isEmpty())
diff --git a/sd/qa/unit/FontEmbeddingTest.cxx b/sd/qa/unit/FontEmbeddingTest.cxx
index 09eb657d5ba6..44cc47d838df 100644
--- a/sd/qa/unit/FontEmbeddingTest.cxx
+++ b/sd/qa/unit/FontEmbeddingTest.cxx
@@ -103,7 +103,7 @@ CPPUNIT_TEST_FIXTURE(FontEmbeddingTest, testExportEmbeddedFontsPPTX)
{
#if HAVE_MORE_FONTS
- createSdImpressDoc();
+ createSdImpressDoc("TestEmbeddedFonts_DejaVu.odp");
uno::Reference<lang::XMultiServiceFactory> xFactory(mxComponent, uno::UNO_QUERY_THROW);
uno::Reference<beans::XPropertySet> xProps(
@@ -130,7 +130,7 @@ CPPUNIT_TEST_FIXTURE(FontEmbeddingTest, testExportEmbeddedFontsPPTX)
{
xmlDocUniquePtr pXmlDoc = parseExport(u"ppt/presentation.xml"_ustr);
assertXPath(pXmlDoc, xPath_Presentation, "embedTrueTypeFonts", u"1");
- assertXPath(pXmlDoc, xPath_EmbeddedFont + "[@typeface='Liberation Sans']");
+ assertXPath(pXmlDoc, xPath_EmbeddedFont + "[@typeface='DejaVu Sans']");
}
// Check the relationships to the embedded fonts
diff --git a/sd/qa/unit/data/TestEmbeddedFonts_DejaVu.odp b/sd/qa/unit/data/TestEmbeddedFonts_DejaVu.odp
new file mode 100644
index 000000000000..df90920bf3f7
--- /dev/null
+++ b/sd/qa/unit/data/TestEmbeddedFonts_DejaVu.odp
Binary files differ
diff --git a/sd/source/filter/eppt/pptx-epptooxml.cxx b/sd/source/filter/eppt/pptx-epptooxml.cxx
index ec7e718f3b82..d04a6db9020b 100644
--- a/sd/source/filter/eppt/pptx-epptooxml.cxx
+++ b/sd/source/filter/eppt/pptx-epptooxml.cxx
@@ -765,6 +765,9 @@ void PowerPointExport::WriteEmbeddedFontList()
aAnySeq[nSeqIndex++] >>= ePitch;
aAnySeq[nSeqIndex++] >>= eCharSet;
+ if (EmbeddedFontsHelper::isCommonFont(sFamilyName))
+ continue;
+
if (mbEmbedUsedOnly && !aUsedFonts.contains(sFamilyName))
continue;
@@ -811,7 +814,7 @@ void PowerPointExport::WriteEmbeddedFontList()
if (aFile.isEndOfFile(&eof) != osl::File::E_None)
{
- SAL_WARN("sw.ww8", "Error reading font file " << sFontUrl);
+ SAL_WARN("sd.eppt", "Error reading font file " << sFontUrl);
break;
}
if (eof)
@@ -819,7 +822,7 @@ void PowerPointExport::WriteEmbeddedFontList()
if (aFile.read(buffer.data(), 4096, readSize) != osl::File::E_None)
{
- SAL_WARN("sw.ww8", "Error reading font file " << sFontUrl);
+ SAL_WARN("sd.eppt", "Error reading font file " << sFontUrl);
break;
}
@@ -830,7 +833,7 @@ void PowerPointExport::WriteEmbeddedFontList()
aHashCalc.update(reinterpret_cast<const unsigned char*>(buffer.data()), readSize);
}
- std::string aHash = comphelper::hashToString(aHashCalc.finalize());
+ std::string aHash = comphelper::hashToString(aHashCalc.finalize());
auto iterator = aFontDeduplicationMap.find(aHash);
if (iterator == aFontDeduplicationMap.end())
{
diff --git a/vcl/source/gdi/embeddedfontshelper.cxx b/vcl/source/gdi/embeddedfontshelper.cxx
index 8053d80bc455..e30244ce0a33 100644
--- a/vcl/source/gdi/embeddedfontshelper.cxx
+++ b/vcl/source/gdi/embeddedfontshelper.cxx
@@ -10,6 +10,9 @@
#include <sal/config.h>
#include <memory>
+#include <frozen/bits/defines.h>
+#include <frozen/bits/elsa_std.h>
+#include <frozen/unordered_set.h>
#include <config_folders.h>
#include <config_eot.h>
@@ -26,7 +29,6 @@
#include <salgdi.hxx>
#include <sft.hxx>
-
#if ENABLE_EOT
extern "C"
{
@@ -400,4 +402,26 @@ OUString EmbeddedFontsHelper::fontFileUrl( std::u16string_view familyName, FontF
return ok ? url : u""_ustr;
}
+bool EmbeddedFontsHelper::isCommonFont(std::u16string_view aFontName)
+{
+ static constexpr auto aCommonFontsList = frozen::make_unordered_set<std::u16string_view>({
+ // LO Common
+ u"Liberation Sans",
+ u"Liberation Serif",
+ u"Liberation Sans Narrow",
+ u"Liberation Mono",
+ u"Caladea",
+ u"Carlito",
+ // MSO
+ u"Times New Roman",
+ u"Arial",
+ u"Arial Narrow",
+ u"Courier New",
+ u"Cambria",
+ u"Calibri",
+ });
+
+ return aCommonFontsList.contains(aFontName);
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */