diff options
-rw-r--r-- | include/xmloff/AutoStyleEntry.hxx | 32 | ||||
-rw-r--r-- | include/xmloff/XMLFontAutoStylePool.hxx | 4 | ||||
-rw-r--r-- | include/xmloff/txtparae.hxx | 2 | ||||
-rw-r--r-- | include/xmloff/xmlaustp.hxx | 3 | ||||
-rw-r--r-- | xmloff/source/style/XMLFontAutoStylePool.cxx | 124 | ||||
-rw-r--r-- | xmloff/source/style/impastpl.cxx | 31 | ||||
-rw-r--r-- | xmloff/source/style/impastpl.hxx | 3 | ||||
-rw-r--r-- | xmloff/source/style/xmlaustp.cxx | 5 | ||||
-rw-r--r-- | xmloff/source/text/txtparae.cxx | 5 |
9 files changed, 196 insertions, 13 deletions
diff --git a/include/xmloff/AutoStyleEntry.hxx b/include/xmloff/AutoStyleEntry.hxx new file mode 100644 index 000000000000..c313aac15313 --- /dev/null +++ b/include/xmloff/AutoStyleEntry.hxx @@ -0,0 +1,32 @@ +/* -*- 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/. + * + */ + +#ifndef INCLUDED_XMLOFF_AUTOSTYLEENTRY_HXX +#define INCLUDED_XMLOFF_AUTOSTYLEENTRY_HXX + +#include <sal/config.h> +#include <xmloff/dllapi.h> +#include <memory> + +namespace xmloff +{ +struct XMLOFF_DLLPUBLIC AutoStyleEntry +{ + sal_Int32 m_nFamily; + OUString m_aParentName; + OUString m_aName; + std::vector<std::pair<OUString, css::uno::Any>> m_aXmlProperties; +}; + +} // end xmloff + +#endif // INCLUDED_XMLOFF_AUTOSTYLEENTRY_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/xmloff/XMLFontAutoStylePool.hxx b/include/xmloff/XMLFontAutoStylePool.hxx index 3380fc96d532..2354bcf8ce7d 100644 --- a/include/xmloff/XMLFontAutoStylePool.hxx +++ b/include/xmloff/XMLFontAutoStylePool.hxx @@ -26,6 +26,7 @@ #include <tools/fontenum.hxx> #include <salhelper/simplereferenceobject.hxx> #include <set> +#include <unordered_set> #include <unordered_map> #include <memory> @@ -44,6 +45,8 @@ private: OUString embedFontFile(OUString const & rFileUrl, OUString const & rFamilyName); + std::unordered_set<OUString> getUsedFontList(); + protected: bool m_bEmbedUsedOnly; bool m_bEmbedLatinScript; @@ -53,7 +56,6 @@ protected: SvXMLExport& GetExport() { return rExport; } public: - XMLFontAutoStylePool( SvXMLExport& rExport, bool tryToEmbedFonts = false ); virtual ~XMLFontAutoStylePool() override; diff --git a/include/xmloff/txtparae.hxx b/include/xmloff/txtparae.hxx index d06a335f1f83..7bf35536156f 100644 --- a/include/xmloff/txtparae.hxx +++ b/include/xmloff/txtparae.hxx @@ -111,6 +111,8 @@ class XMLOFF_DLLPUBLIC XMLTextParagraphExport : public XMLStyleExport XMLTextListsHelper* mpTextListsHelper; ::std::vector< std::unique_ptr<XMLTextListsHelper> > maTextListsHelperStack; + bool mbCollected; + enum class FrameType { Text, Graphic, Embedded, Shape }; public: diff --git a/include/xmloff/xmlaustp.hxx b/include/xmloff/xmlaustp.hxx index 7b270ce09724..1d708ad12806 100644 --- a/include/xmloff/xmlaustp.hxx +++ b/include/xmloff/xmlaustp.hxx @@ -24,6 +24,7 @@ #include <xmloff/dllapi.h> #include <com/sun/star/xml/sax/XDocumentHandler.hpp> #include <xmloff/xmlprmap.hxx> +#include <xmloff/AutoStyleEntry.hxx> #include <salhelper/simplereferenceobject.hxx> #include <memory> @@ -116,6 +117,8 @@ public: void exportXML( sal_Int32 nFamily ) const; void ClearEntries(); + + std::vector<xmloff::AutoStyleEntry> GetAutoStyleEntries() const; }; #endif // INCLUDED_XMLOFF_XMLAUSTP_HXX diff --git a/xmloff/source/style/XMLFontAutoStylePool.cxx b/xmloff/source/style/XMLFontAutoStylePool.cxx index c410624ee9ce..56bb2211e990 100644 --- a/xmloff/source/style/XMLFontAutoStylePool.cxx +++ b/xmloff/source/style/XMLFontAutoStylePool.cxx @@ -32,8 +32,12 @@ #include <com/sun/star/embed/XTransactedObject.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/ucb/SimpleFileAccess.hpp> +#include <com/sun/star/style/XStyleFamiliesSupplier.hpp> +#include <com/sun/star/style/XStyle.hpp> +#include <com/sun/star/container/XNameAccess.hpp> #include <XMLBase64Export.hxx> +#include <xmloff/AutoStyleEntry.hxx> #include <comphelper/hash.hxx> using namespace ::com::sun::star; @@ -290,6 +294,93 @@ OUString FontItalicToString(FontItalic eWeight) } +std::unordered_set<OUString> XMLFontAutoStylePool::getUsedFontList() +{ + std::unordered_set<OUString> aReturnSet; + + uno::Reference<style::XStyleFamiliesSupplier> xFamiliesSupp(GetExport().GetModel(), UNO_QUERY); + if (!xFamiliesSupp.is()) + return aReturnSet; + + // Check styles first + uno::Reference<container::XNameAccess> xFamilies(xFamiliesSupp->getStyleFamilies()); + if (xFamilies.is()) + { + for (OUString const & sFamilyName : xFamilies->getElementNames()) + { + uno::Reference<container::XNameAccess> xStyleContainer; + xFamilies->getByName(sFamilyName) >>= xStyleContainer; + + if (xStyleContainer.is()) + { + for (OUString const & rName : xStyleContainer->getElementNames()) + { + uno::Reference<style::XStyle> xStyle; + xStyleContainer->getByName(rName) >>= xStyle; + if (xStyle->isInUse()) + { + uno::Reference<beans::XPropertySet> xPropertySet(xStyle, UNO_QUERY); + if (xPropertySet.is()) + { + uno::Reference<beans::XPropertySetInfo> xInfo(xPropertySet->getPropertySetInfo()); + if (m_bEmbedLatinScript && xInfo->hasPropertyByName("CharFontName")) + { + OUString sCharFontName; + Any aFontAny = xPropertySet->getPropertyValue("CharFontName"); + aFontAny >>= sCharFontName; + if (!sCharFontName.isEmpty()) + aReturnSet.insert(sCharFontName); + } + if (m_bEmbedAsianScript && xInfo->hasPropertyByName("CharFontNameAsian")) + { + OUString sCharFontNameAsian; + Any aFontAny = xPropertySet->getPropertyValue("CharFontNameAsian"); + aFontAny >>= sCharFontNameAsian; + if (!sCharFontNameAsian.isEmpty()) + aReturnSet.insert(sCharFontNameAsian); + } + if (m_bEmbedComplexScript && xInfo->hasPropertyByName("CharFontNameComplex")) + { + OUString sCharFontNameComplex; + Any aFontAny = xPropertySet->getPropertyValue("CharFontNameComplex"); + aFontAny >>= sCharFontNameComplex; + if (!sCharFontNameComplex.isEmpty()) + aReturnSet.insert(sCharFontNameComplex); + } + } + } + } + } + } + } + + // make sure auto-styles are collected + GetExport().GetTextParagraphExport()->collectTextAutoStylesOptimized(false); + + // Check auto-styles for fonts + std::vector<xmloff::AutoStyleEntry> aAutoStyleEntries; + aAutoStyleEntries = GetExport().GetAutoStylePool()->GetAutoStyleEntries(); + for (auto const & rAutoStyleEntry : aAutoStyleEntries) + { + for (auto const & rPair : rAutoStyleEntry.m_aXmlProperties) + { + if (rPair.first == "font-name" || + rPair.first == "font-weight-asian" || + rPair.first == "font-weight-complex") + { + if (rPair.second.has<OUString>()) + { + OUString sFontName = rPair.second.get<OUString>(); + if (!sFontName.isEmpty()) + aReturnSet.insert(sFontName); + } + } + } + } + + return aReturnSet; +} + void XMLFontAutoStylePool::exportXML() { SvXMLElementExport aElem(GetExport(), XML_NAMESPACE_OFFICE, @@ -306,6 +397,10 @@ void XMLFontAutoStylePool::exportXML() std::map<OUString, OUString> fontFilesMap; // our url to document url sal_uInt32 nCount = m_pFontAutoStylePool->size(); + std::unordered_set<OUString> aUsedFontNames; + if (m_bEmbedUsedOnly) + aUsedFontNames = getUsedFontList(); + for (sal_uInt32 i = 0; i < nCount; i++) { const XMLFontAutoStylePoolEntry_Impl* pEntry = (*m_pFontAutoStylePool)[i]; @@ -369,20 +464,25 @@ void XMLFontAutoStylePool::exportXML() if (sFileUrl.isEmpty()) continue; - if (!fontFilesMap.count(sFileUrl)) + // When embeded only is not set or font is used + if (!m_bEmbedUsedOnly || + aUsedFontNames.find(pEntry->GetFamilyName()) != aUsedFontNames.end()) { - const OUString docUrl = bExportFlat ? - lcl_checkFontFile(sFileUrl) : embedFontFile(sFileUrl, pEntry->GetFamilyName()); - if (!docUrl.isEmpty()) - fontFilesMap[sFileUrl] = docUrl; - else - continue; // --> failed to embed + if (!fontFilesMap.count(sFileUrl)) + { + const OUString docUrl = bExportFlat ? + lcl_checkFontFile(sFileUrl) : embedFontFile(sFileUrl, pEntry->GetFamilyName()); + if (!docUrl.isEmpty()) + fontFilesMap[sFileUrl] = docUrl; + else + continue; // --> failed to embed + } + EmbeddedFontInfo aEmbeddedFont; + aEmbeddedFont.aURL = sFileUrl; + aEmbeddedFont.eWeight = aCombinationPair.first; + aEmbeddedFont.eItalic = aCombinationPair.second; + aEmbeddedFonts.push_back(aEmbeddedFont); } - EmbeddedFontInfo aEmbeddedFont; - aEmbeddedFont.aURL = sFileUrl; - aEmbeddedFont.eWeight = aCombinationPair.first; - aEmbeddedFont.eItalic = aCombinationPair.second; - aEmbeddedFonts.push_back(aEmbeddedFont); } if (!aEmbeddedFonts.empty()) { diff --git a/xmloff/source/style/impastpl.cxx b/xmloff/source/style/impastpl.cxx index 69ad5d3e05ce..ed5f0e32eecb 100644 --- a/xmloff/source/style/impastpl.cxx +++ b/xmloff/source/style/impastpl.cxx @@ -591,6 +591,37 @@ OUString SvXMLAutoStylePoolP_Impl::Find( sal_Int32 nFamily, return sName; } +std::vector<xmloff::AutoStyleEntry> SvXMLAutoStylePoolP_Impl::GetAutoStyleEntries() const +{ + std::vector<xmloff::AutoStyleEntry> rReturnVector; + + for (std::unique_ptr<XMLAutoStyleFamily> const & rFamily : m_FamilySet) + { + rtl::Reference<XMLPropertySetMapper> aPropertyMapper = rFamily->mxMapper->getPropertySetMapper(); + sal_Int32 nFamily = rFamily->mnFamily; + for (auto const & rParent : rFamily->m_ParentSet) + { + for (auto const & rProperty : rParent->GetPropertiesList()) + { + rReturnVector.emplace_back(); + xmloff::AutoStyleEntry & rEntry = rReturnVector.back(); + rEntry.m_nFamily = nFamily; + rEntry.m_aParentName = rParent->GetParent(); + rEntry.m_aName = rProperty->GetName(); + for (XMLPropertyState const & rPropertyState : rProperty->GetProperties()) + { + if (rPropertyState.mnIndex >= 0) + { + OUString sXmlName = aPropertyMapper->GetEntryXMLName(rPropertyState.mnIndex); + rEntry.m_aXmlProperties.emplace_back(sXmlName, rPropertyState.maValue); + } + } + } + } + } + return rReturnVector; +} + namespace { struct AutoStylePoolExport diff --git a/xmloff/source/style/impastpl.hxx b/xmloff/source/style/impastpl.hxx index eec145cd19c9..49a93fc2a742 100644 --- a/xmloff/source/style/impastpl.hxx +++ b/xmloff/source/style/impastpl.hxx @@ -33,6 +33,7 @@ #include <xmloff/maptype.hxx> #include <xmloff/xmlexppr.hxx> +#include <xmloff/AutoStyleEntry.hxx> class SvXMLAutoStylePoolP; class XMLAutoStylePoolParent; @@ -174,6 +175,8 @@ public: const SvXMLAutoStylePoolP *pAntiImpl) const; void ClearEntries(); + + std::vector<xmloff::AutoStyleEntry> GetAutoStyleEntries() const; }; #endif diff --git a/xmloff/source/style/xmlaustp.cxx b/xmloff/source/style/xmlaustp.cxx index 863f740b24b8..c5256a49f12b 100644 --- a/xmloff/source/style/xmlaustp.cxx +++ b/xmloff/source/style/xmlaustp.cxx @@ -382,4 +382,9 @@ void SvXMLAutoStylePoolP::ClearEntries() pImpl->ClearEntries(); } +std::vector<xmloff::AutoStyleEntry> SvXMLAutoStylePoolP::GetAutoStyleEntries() const +{ + return pImpl->GetAutoStyleEntries(); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/text/txtparae.cxx b/xmloff/source/text/txtparae.cxx index d039682eb856..cd9eba5f801b 100644 --- a/xmloff/source/text/txtparae.cxx +++ b/xmloff/source/text/txtparae.cxx @@ -1173,6 +1173,7 @@ XMLTextParagraphExport::XMLTextParagraphExport( bOpenRuby( false ), mpTextListsHelper( nullptr ), maTextListsHelperStack(), + mbCollected(false), // Implement Title/Description Elements UI (#i73249#) sTitle("Title"), sDescription("Description"), @@ -1432,6 +1433,9 @@ void XMLTextParagraphExport::collectTextAutoStylesOptimized( bool bIsProgress ) { GetExport().GetShapeExport(); // make sure the graphics styles family is added + if (mbCollected) + return; + const bool bAutoStyles = true; const bool bExportContent = false; @@ -1630,6 +1634,7 @@ void XMLTextParagraphExport::collectTextAutoStylesOptimized( bool bIsProgress ) } } } + mbCollected = true; } void XMLTextParagraphExport::exportText( |