sd: PPTX embedded fonts - skip common fonts

Skip embedding common fonts that are considered to be always
available or are substituted for a metric compatible fonts in a
LO or MSO.

Change-Id: Ic970e25e464517fa44f446492c1fdfce29379c77
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185761
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
(cherry picked from commit 21a5a743f3663392798c16943a40c431af4f2dd1)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186166
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
This commit is contained in:
Tomaž Vajngerl
2025-06-04 16:58:54 +02:00
committed by Tomaž Vajngerl
parent cc2babfa0a
commit 0e9091b6db
6 changed files with 51 additions and 12 deletions
+15 -4
View File
@@ -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();
+3 -2
View File
@@ -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())
+2 -2
View File
@@ -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
Binary file not shown.
+6 -3
View File
@@ -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())
{
+25 -1
View File
@@ -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: */