android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / source / filter / xml / xmlfonte.cxx
blobb8c0f7730d5745ee713ee4064f1320254e6e453a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <hintids.hxx>
21 #include <xmloff/XMLFontAutoStylePool.hxx>
22 #include <editeng/fontitem.hxx>
23 #include <doc.hxx>
24 #include "xmlexp.hxx"
25 #include "xmlimp.hxx"
26 #include <IDocumentSettingAccess.hxx>
28 using namespace ::com::sun::star::uno;
29 using namespace ::com::sun::star::lang;
30 using namespace ::com::sun::star::text;
32 namespace {
34 class SwXMLFontAutoStylePool_Impl: public XMLFontAutoStylePool
36 public:
37 SwXMLFontAutoStylePool_Impl(SwXMLExport& rExport, bool bFontEmbedding);
42 SwXMLFontAutoStylePool_Impl::SwXMLFontAutoStylePool_Impl(SwXMLExport& _rExport, bool bFontEmbedding)
43 : XMLFontAutoStylePool(_rExport, bFontEmbedding)
45 sal_uInt16 const aWhichIds[3] = { RES_CHRATR_FONT, RES_CHRATR_CJK_FONT,
46 RES_CHRATR_CTL_FONT };
48 const SfxItemPool& rPool = _rExport.getDoc()->GetAttrPool();
49 std::vector<const SvxFontItem *> aFonts;
50 for(sal_uInt16 nWhichId : aWhichIds)
52 const SvxFontItem& rFont =
53 static_cast<const SvxFontItem&>(rPool.GetDefaultItem( nWhichId ));
54 aFonts.push_back(&rFont);
55 for (const SfxPoolItem* pItem : rPool.GetItemSurrogates(nWhichId))
57 auto pFont = static_cast<const SvxFontItem *>(pItem);
58 aFonts.push_back(pFont);
62 std::sort(aFonts.begin(), aFonts.end(),
63 [](const SvxFontItem* pA, const SvxFontItem* pB) -> bool { return *pA < *pB; });
64 for (const auto& pFont : aFonts)
66 Add(pFont->GetFamilyName(), pFont->GetStyleName(), pFont->GetFamily(), pFont->GetPitch(),
67 pFont->GetCharSet());
70 auto const & pDocument = _rExport.getDoc();
72 m_bEmbedUsedOnly = pDocument->getIDocumentSettingAccess().get(DocumentSettingId::EMBED_USED_FONTS);
73 m_bEmbedLatinScript = pDocument->getIDocumentSettingAccess().get(DocumentSettingId::EMBED_LATIN_SCRIPT_FONTS);
74 m_bEmbedAsianScript = pDocument->getIDocumentSettingAccess().get(DocumentSettingId::EMBED_ASIAN_SCRIPT_FONTS);
75 m_bEmbedComplexScript = pDocument->getIDocumentSettingAccess().get(DocumentSettingId::EMBED_COMPLEX_SCRIPT_FONTS);
79 XMLFontAutoStylePool* SwXMLExport::CreateFontAutoStylePool()
81 bool blockFontEmbedding = false;
82 // We write font info to both content.xml and styles.xml, but they are both
83 // written by different SwXMLExport instance, and would therefore write each
84 // font file twice without complicated checking for duplicates, so handle
85 // the embedding only in one of them.
86 if( !( getExportFlags() & SvXMLExportFlags::CONTENT) )
87 blockFontEmbedding = true;
88 if( !getDoc()->getIDocumentSettingAccess().get( DocumentSettingId::EMBED_FONTS ))
89 blockFontEmbedding = true;
90 return new SwXMLFontAutoStylePool_Impl( *this, !blockFontEmbedding );
93 void SwXMLImport::NotifyContainsEmbeddedFont()
95 getDoc()->getIDocumentSettingAccess().set( DocumentSettingId::EMBED_FONTS, true );
98 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */