oox/Library_oox.mk | 1 oox/source/ppt/EmbeddedFontListContext.cxx | 120 +++++++++++++++++++++++++ oox/source/ppt/EmbeddedFontListContext.hxx | 59 ++++++++++++ oox/source/ppt/presentationfragmenthandler.cxx | 4 4 files changed, 184 insertions(+)
New commits: commit 6647520ca68c882027b6845f88baaaae3a04bf86 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Mon Feb 24 14:34:01 2025 +0900 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Wed Apr 30 15:57:43 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 (cherry picked from commit faf45f80e1963534d72a60636836b816f6d27442) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184813 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> 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 941fa68b6e16..be5c9f19749d 100644 --- a/oox/source/ppt/presentationfragmenthandler.cxx +++ b/oox/source/ppt/presentationfragmenthandler.cxx @@ -68,6 +68,8 @@ #include <ooxresid.hxx> #include <strings.hrc> +#include "EmbeddedFontListContext.hxx" + using namespace ::com::sun::star; using namespace ::oox::core; using namespace ::oox::drawingml; @@ -703,6 +705,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);