include/oox/ppt/presentationfragmenthandler.hxx |    2 
 oox/Library_oox.mk                              |    1 
 oox/source/ppt/EmbeddedFontListContext.cxx      |  129 ++++++++++++++++++++++++
 oox/source/ppt/EmbeddedFontListContext.hxx      |   62 +++++++++++
 oox/source/ppt/presentationfragmenthandler.cxx  |    9 +
 5 files changed, 203 insertions(+)

New commits:
commit 248b826786e29c32ebdd2553d68adf240903977b
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Mon Apr 21 16:33:22 2025 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Mon Apr 28 14:52:28 2025 +0200

    oox: read embedTrueTypeFonts and set doc. setting "EmbedFonts"
    
    Embed fonts depending if the attribute "embedTrueTypeFonts "on
    "presentation" element is set to true. If true, set the doc.
    setting "EmbedFonts" and start proceed with font embedding code
    path.
    
    Change-Id: Iba2552ab58c07cfa41afca4e1883ae706eb8c678
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184403
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/include/oox/ppt/presentationfragmenthandler.hxx 
b/include/oox/ppt/presentationfragmenthandler.hxx
index 0e46d86a7399..254bb50eebff 100644
--- a/include/oox/ppt/presentationfragmenthandler.hxx
+++ b/include/oox/ppt/presentationfragmenthandler.hxx
@@ -72,6 +72,8 @@ private:
 
     CommentAuthorList           maAuthorList;
     bool                        mbCommentAuthorsRead; // read 
commentAuthors.xml only once
+
+    bool mbEmbedTrueTypeFonts = false;
 };
 
 }
diff --git a/oox/source/ppt/EmbeddedFontListContext.cxx 
b/oox/source/ppt/EmbeddedFontListContext.cxx
index c60a257fbcf3..792387e34556 100644
--- a/oox/source/ppt/EmbeddedFontListContext.cxx
+++ b/oox/source/ppt/EmbeddedFontListContext.cxx
@@ -20,8 +20,12 @@ using namespace css;
 
 namespace oox::ppt
 {
-EmbeddedFontListContext::EmbeddedFontListContext(FragmentHandler2 const& 
rParent)
+EmbeddedFontListContext::EmbeddedFontListContext(
+    FragmentHandler2 const& rParent, bool bEmbedTrueType,
+    css::uno::Reference<css::beans::XPropertySet> const& rxDocSettings)
     : FragmentHandler2(rParent)
+    , mbEmbedTrueType(bEmbedTrueType)
+    , mxDocSettings(rxDocSettings)
 {
 }
 
@@ -77,9 +81,14 @@ void EmbeddedFontListContext::onEndElement()
     if (!isCurrentElement(PPT_TOKEN(embeddedFont)))
         return;
 
-    if (!moCurrentFont)
+    if (!mbEmbedTrueType || !moCurrentFont)
         return;
 
+    if (mxDocSettings.is())
+    {
+        mxDocSettings->setPropertyValue(u"EmbedFonts"_ustr, uno::Any(true));
+    }
+
     if (!moCurrentFont->aRegularID.isEmpty())
     {
         OUString aFragmentPath = 
getFragmentPathFromRelId(moCurrentFont->aRegularID);
diff --git a/oox/source/ppt/EmbeddedFontListContext.hxx 
b/oox/source/ppt/EmbeddedFontListContext.hxx
index 35a15b24c62a..4c9dd4075fe6 100644
--- a/oox/source/ppt/EmbeddedFontListContext.hxx
+++ b/oox/source/ppt/EmbeddedFontListContext.hxx
@@ -45,9 +45,12 @@ class EmbeddedFontListContext final : public 
::oox::core::FragmentHandler2
 {
     std::optional<EmbeddedFont> moCurrentFont;
     EmbeddedFontsHelper maEmbeddedFontHelper;
+    bool mbEmbedTrueType = false;
+    css::uno::Reference<css::beans::XPropertySet> mxDocSettings;
 
 public:
-    EmbeddedFontListContext(oox::core::FragmentHandler2 const& rParent);
+    EmbeddedFontListContext(oox::core::FragmentHandler2 const& rParent, bool 
bEmbedTrueType,
+                            css::uno::Reference<css::beans::XPropertySet> 
const& rxDocSettings);
     ~EmbeddedFontListContext() override;
 
     oox::core::ContextHandlerRef onCreateContext(sal_Int32 aElementToken,
diff --git a/oox/source/ppt/presentationfragmenthandler.cxx 
b/oox/source/ppt/presentationfragmenthandler.cxx
index f5b8842fff7b..aee89e1c4dce 100644
--- a/oox/source/ppt/presentationfragmenthandler.cxx
+++ b/oox/source/ppt/presentationfragmenthandler.cxx
@@ -683,6 +683,8 @@ void PresentationFragmentHandler::finalizeImport()
     switch( aElementToken )
     {
     case PPT_TOKEN( presentation ):
+        mbEmbedTrueTypeFonts = rAttribs.getBool(XML_embedTrueTypeFonts, false);
+        return this;
     case PPT_TOKEN( sldMasterIdLst ):
     case PPT_TOKEN( notesMasterIdLst ):
     case PPT_TOKEN( sldIdLst ):
@@ -707,7 +709,10 @@ void PresentationFragmentHandler::finalizeImport()
     case PPT_TOKEN( defaultTextStyle ):
         return new TextListStyleContext( *this, *mpTextListStyle );
     case PPT_TOKEN(embeddedFontLst):
-        return new EmbeddedFontListContext(*this);
+    {
+        uno::Reference<beans::XPropertySet> 
xDocSettings(getFilter().getModelFactory()->createInstance(u"com.sun.star.document.Settings"_ustr),
 uno::UNO_QUERY);
+        return new EmbeddedFontListContext(*this, mbEmbedTrueTypeFonts, 
xDocSettings);
+    }
     case PPT_TOKEN( modifyVerifier ):
         OUString sAlgorithmClass = 
rAttribs.getStringDefaulted(XML_cryptAlgorithmClass);
         OUString sAlgorithmType = 
rAttribs.getStringDefaulted(XML_cryptAlgorithmType);
commit faf45f80e1963534d72a60636836b816f6d27442
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Mon Feb 24 14:34:01 2025 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Mon Apr 28 14:52:20 2025 +0200

    oox: import embedded font if it exists in impress
    
    The fonts are usually EOT fonts so this needs libEOT to work. The
    EmbeddedFontHelper takes care the conversion and make the font
    available in LibreOffice (which is then used automatically in the
    document).
    
    Change-Id: I96a9b968aaba4b8ee08fe67fb8551d34d55dd9d3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184287
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>
    Tested-by: Jenkins

diff --git a/oox/Library_oox.mk b/oox/Library_oox.mk
index df8e484f7303..d1f9933605db 100644
--- a/oox/Library_oox.mk
+++ b/oox/Library_oox.mk
@@ -280,6 +280,7 @@ $(eval $(call gb_Library_add_exception_objects,oox,\
     oox/source/ppt/commontimenodecontext \
     oox/source/ppt/conditioncontext \
     oox/source/ppt/customshowlistcontext \
+    oox/source/ppt/EmbeddedFontListContext \
     oox/source/ppt/headerfootercontext \
     oox/source/ppt/layoutfragmenthandler \
     oox/source/ppt/pptfilterhelpers \
diff --git a/oox/source/ppt/EmbeddedFontListContext.cxx 
b/oox/source/ppt/EmbeddedFontListContext.cxx
new file mode 100644
index 000000000000..c60a257fbcf3
--- /dev/null
+++ b/oox/source/ppt/EmbeddedFontListContext.cxx
@@ -0,0 +1,120 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "EmbeddedFontListContext.hxx"
+
+#include <oox/helper/attributelist.hxx>
+#include <oox/token/namespaces.hxx>
+#include <oox/token/tokens.hxx>
+#include <oox/helper/binaryinputstream.hxx>
+#include <oox/core/xmlfilterbase.hxx>
+#include <sax/fshelper.hxx>
+
+using namespace css;
+
+namespace oox::ppt
+{
+EmbeddedFontListContext::EmbeddedFontListContext(FragmentHandler2 const& 
rParent)
+    : FragmentHandler2(rParent)
+{
+}
+
+EmbeddedFontListContext::~EmbeddedFontListContext() = default;
+
+oox::core::ContextHandlerRef
+EmbeddedFontListContext::onCreateContext(sal_Int32 aElementToken, const 
AttributeList& rAttributes)
+{
+    switch (aElementToken)
+    {
+        case PPT_TOKEN(embeddedFont):
+        {
+            moCurrentFont = EmbeddedFont();
+            return this;
+        }
+        case PPT_TOKEN(font):
+        {
+            moCurrentFont->aTypeface = 
rAttributes.getStringDefaulted(XML_typeface);
+            moCurrentFont->aPanose = 
rAttributes.getStringDefaulted(XML_panose);
+            moCurrentFont->nPitchFamily = 
rAttributes.getUnsigned(XML_pitchFamily, 0);
+            moCurrentFont->nCharset = rAttributes.getUnsigned(XML_charset, 0);
+            return this;
+        }
+        case PPT_TOKEN(regular):
+        {
+            moCurrentFont->aRegularID = 
rAttributes.getStringDefaulted(R_TOKEN(id));
+            return this;
+        }
+        case PPT_TOKEN(bold):
+        {
+            moCurrentFont->aBoldID = 
rAttributes.getStringDefaulted(R_TOKEN(id));
+            return this;
+        }
+        case PPT_TOKEN(italic):
+        {
+            moCurrentFont->aItalicID = 
rAttributes.getStringDefaulted(R_TOKEN(id));
+            return this;
+        }
+        case PPT_TOKEN(boldItalic):
+        {
+            moCurrentFont->aBoldItalicID = 
rAttributes.getStringDefaulted(R_TOKEN(id));
+            return this;
+        }
+        default:
+            break;
+    }
+
+    return this;
+}
+
+void EmbeddedFontListContext::onEndElement()
+{
+    if (!isCurrentElement(PPT_TOKEN(embeddedFont)))
+        return;
+
+    if (!moCurrentFont)
+        return;
+
+    if (!moCurrentFont->aRegularID.isEmpty())
+    {
+        OUString aFragmentPath = 
getFragmentPathFromRelId(moCurrentFont->aRegularID);
+        uno::Reference<io::XInputStream> xInputStream = 
getFilter().openInputStream(aFragmentPath);
+        maEmbeddedFontHelper.addEmbeddedFont(xInputStream, 
moCurrentFont->aTypeface, u"",
+                                             std::vector<unsigned char>(), 
true, false);
+    }
+
+    if (!moCurrentFont->aBoldID.isEmpty())
+    {
+        OUString aFragmentPath = 
getFragmentPathFromRelId(moCurrentFont->aBoldID);
+        uno::Reference<io::XInputStream> xInputStream = 
getFilter().openInputStream(aFragmentPath);
+        maEmbeddedFontHelper.addEmbeddedFont(xInputStream, 
moCurrentFont->aTypeface, u"b",
+                                             std::vector<unsigned char>(), 
true, false);
+    }
+
+    if (!moCurrentFont->aItalicID.isEmpty())
+    {
+        OUString aFragmentPath = 
getFragmentPathFromRelId(moCurrentFont->aItalicID);
+        uno::Reference<io::XInputStream> xInputStream = 
getFilter().openInputStream(aFragmentPath);
+        maEmbeddedFontHelper.addEmbeddedFont(xInputStream, 
moCurrentFont->aTypeface, u"i",
+                                             std::vector<unsigned char>(), 
true, false);
+    }
+
+    if (!moCurrentFont->aBoldItalicID.isEmpty())
+    {
+        OUString aFragmentPath = 
getFragmentPathFromRelId(moCurrentFont->aBoldItalicID);
+        uno::Reference<io::XInputStream> xInputStream = 
getFilter().openInputStream(aFragmentPath);
+        maEmbeddedFontHelper.addEmbeddedFont(xInputStream, 
moCurrentFont->aTypeface, u"bi",
+                                             std::vector<unsigned char>(), 
true, false);
+    }
+
+    moCurrentFont = std::nullopt;
+}
+
+} // end oox::ppt
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/oox/source/ppt/EmbeddedFontListContext.hxx 
b/oox/source/ppt/EmbeddedFontListContext.hxx
new file mode 100644
index 000000000000..35a15b24c62a
--- /dev/null
+++ b/oox/source/ppt/EmbeddedFontListContext.hxx
@@ -0,0 +1,59 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#pragma once
+
+#include <vector>
+
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <oox/core/contexthandler.hxx>
+#include <oox/core/fragmenthandler2.hxx>
+#include <vcl/embeddedfontshelper.hxx>
+#include <rtl/ustring.hxx>
+#include <sal/types.h>
+#include <optional>
+
+namespace oox
+{
+class AttributeList;
+}
+
+namespace oox::ppt
+{
+/** Imported embedded font information */
+struct EmbeddedFont
+{
+    OUString aTypeface;
+    OUString aPanose;
+    sal_Int32 nPitchFamily = -1;
+    sal_Int32 nCharset = -1;
+
+    OUString aRegularID;
+    OUString aBoldID;
+    OUString aItalicID;
+    OUString aBoldItalicID;
+};
+
+/** Import context handling the embedded font list (p:embeddedFontLst) */
+class EmbeddedFontListContext final : public ::oox::core::FragmentHandler2
+{
+    std::optional<EmbeddedFont> moCurrentFont;
+    EmbeddedFontsHelper maEmbeddedFontHelper;
+
+public:
+    EmbeddedFontListContext(oox::core::FragmentHandler2 const& rParent);
+    ~EmbeddedFontListContext() override;
+
+    oox::core::ContextHandlerRef onCreateContext(sal_Int32 aElementToken,
+                                                 const AttributeList& 
rAttribs) override;
+    void onEndElement() override;
+};
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/oox/source/ppt/presentationfragmenthandler.cxx 
b/oox/source/ppt/presentationfragmenthandler.cxx
index 180cd7128867..f5b8842fff7b 100644
--- a/oox/source/ppt/presentationfragmenthandler.cxx
+++ b/oox/source/ppt/presentationfragmenthandler.cxx
@@ -69,6 +69,8 @@
 #include <ooxresid.hxx>
 #include <strings.hrc>
 
+#include "EmbeddedFontListContext.hxx"
+
 using namespace ::com::sun::star;
 using namespace ::oox::core;
 using namespace ::oox::drawingml;
@@ -704,6 +706,8 @@ void PresentationFragmentHandler::finalizeImport()
         return new CustomShowListContext( *this, maCustomShowList );
     case PPT_TOKEN( defaultTextStyle ):
         return new TextListStyleContext( *this, *mpTextListStyle );
+    case PPT_TOKEN(embeddedFontLst):
+        return new EmbeddedFontListContext(*this);
     case PPT_TOKEN( modifyVerifier ):
         OUString sAlgorithmClass = 
rAttribs.getStringDefaulted(XML_cryptAlgorithmClass);
         OUString sAlgorithmType = 
rAttribs.getStringDefaulted(XML_cryptAlgorithmType);

Reply via email to