nss: upgrade to release 3.73
[LibreOffice.git] / sc / source / filter / xml / xmlfonte.cxx
blob1120ed9cfd090d67b54be06d4c9b27d44c2021cc
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 <scitems.hxx>
22 #include <editeng/eeitem.hxx>
24 #include <xmloff/XMLFontAutoStylePool.hxx>
25 #include <editeng/fontitem.hxx>
26 #include <editeng/editeng.hxx>
27 #include <document.hxx>
28 #include <docpool.hxx>
29 #include "xmlexprt.hxx"
30 #include <stlpool.hxx>
31 #include <attrib.hxx>
33 namespace {
35 class ScXMLFontAutoStylePool_Impl: public XMLFontAutoStylePool
37 private:
38 // #i120077# remember owned pool
39 SfxItemPool* mpEditEnginePool;
41 void AddFontItems(const sal_uInt16* pWhichIds, sal_uInt8 nIdCount, const SfxItemPool* pItemPool, const bool bExportDefaults);
43 public:
44 ScXMLFontAutoStylePool_Impl( ScXMLExport& rExport, bool bEmbedFonts);
45 virtual ~ScXMLFontAutoStylePool_Impl() override;
50 void ScXMLFontAutoStylePool_Impl::AddFontItems(const sal_uInt16* pWhichIds, sal_uInt8 nIdCount, const SfxItemPool* pItemPool, const bool bExportDefaults)
52 for( sal_uInt16 i=0; i < nIdCount; ++i )
54 sal_uInt16 nWhichId(pWhichIds[i]);
55 if (bExportDefaults)
57 const SfxPoolItem* pItem = &pItemPool->GetDefaultItem(nWhichId);
58 const SvxFontItem *pFont(static_cast<const SvxFontItem *>(pItem));
59 Add( pFont->GetFamilyName(), pFont->GetStyleName(),
60 pFont->GetFamily(), pFont->GetPitch(),
61 pFont->GetCharSet() );
63 for (const SfxPoolItem* pItem : pItemPool->GetItemSurrogates( nWhichId ))
65 const SvxFontItem *pFont(static_cast<const SvxFontItem *>(pItem));
66 Add( pFont->GetFamilyName(), pFont->GetStyleName(),
67 pFont->GetFamily(), pFont->GetPitch(),
68 pFont->GetCharSet() );
73 ScXMLFontAutoStylePool_Impl::ScXMLFontAutoStylePool_Impl(ScXMLExport& rExportP, bool bEmbedFonts)
74 : XMLFontAutoStylePool(rExportP, bEmbedFonts)
75 , mpEditEnginePool(nullptr)
77 sal_uInt16 const aWhichIds[] { ATTR_FONT, ATTR_CJK_FONT,
78 ATTR_CTL_FONT };
79 sal_uInt16 const aEditWhichIds[] { EE_CHAR_FONTINFO, EE_CHAR_FONTINFO_CJK,
80 EE_CHAR_FONTINFO_CTL };
81 sal_uInt16 const aPageWhichIds[] { ATTR_PAGE_HEADERLEFT, ATTR_PAGE_FOOTERLEFT,
82 ATTR_PAGE_HEADERRIGHT, ATTR_PAGE_FOOTERRIGHT };
84 const SfxItemPool* pItemPool(rExportP.GetDocument()->GetPool());
85 AddFontItems(aWhichIds, 3, pItemPool, true);
86 const SfxItemPool* pEditPool(rExportP.GetDocument()->GetEditPool());
87 AddFontItems(aEditWhichIds, 3, pEditPool, false);
89 std::unique_ptr<SfxStyleSheetIterator> pItr = rExportP.GetDocument()->GetStyleSheetPool()->CreateIterator(SfxStyleFamily::Page);
91 m_bEmbedUsedOnly = rExportP.GetDocument()->IsEmbedUsedFontsOnly();
92 m_bEmbedLatinScript = rExportP.GetDocument()->IsEmbedFontScriptLatin();
93 m_bEmbedAsianScript = rExportP.GetDocument()->IsEmbedFontScriptAsian();
94 m_bEmbedComplexScript = rExportP.GetDocument()->IsEmbedFontScriptComplex();
96 if(!pItr)
97 return;
99 SfxStyleSheetBase* pStyle(pItr->First());
101 if(!pStyle)
102 return;
104 // #i120077# remember the SfxItemPool in member variable before usage. The
105 // local EditEngine will not take over ownership of the pool.
106 mpEditEnginePool = EditEngine::CreatePool();
107 EditEngine aEditEngine(mpEditEnginePool);
109 while (pStyle)
111 const SfxItemPool& rPagePool(pStyle->GetPool()->GetPool());
113 for (sal_uInt16 nPageWhichId : aPageWhichIds)
115 for (const SfxPoolItem* pItem : rPagePool.GetItemSurrogates( nPageWhichId ))
117 const ScPageHFItem* pPageItem = static_cast<const ScPageHFItem*>(pItem);
118 const EditTextObject* pLeftArea(pPageItem->GetLeftArea());
119 if (pLeftArea)
121 aEditEngine.SetText(*pLeftArea);
122 AddFontItems(aEditWhichIds, 3, mpEditEnginePool, false);
124 const EditTextObject* pCenterArea(pPageItem->GetCenterArea());
125 if (pCenterArea)
127 aEditEngine.SetText(*pCenterArea);
128 AddFontItems(aEditWhichIds, 3, mpEditEnginePool, false);
130 const EditTextObject* pRightArea(pPageItem->GetRightArea());
131 if (pRightArea)
133 aEditEngine.SetText(*pRightArea);
134 AddFontItems(aEditWhichIds, 3, mpEditEnginePool, false);
139 pStyle = pItr->Next();
143 ScXMLFontAutoStylePool_Impl::~ScXMLFontAutoStylePool_Impl()
145 if(mpEditEnginePool)
147 // memory leak #i120077#
148 SfxItemPool::Free(mpEditEnginePool);
152 XMLFontAutoStylePool* ScXMLExport::CreateFontAutoStylePool()
154 bool blockFontEmbedding = false;
155 // We write font info to both content.xml and styles.xml, but they are both
156 // written by different ScXMLExport instance, and would therefore write each
157 // font file twice without complicated checking for duplicates, so handle
158 // the embedding only in one of them.
159 if(!( getExportFlags() & SvXMLExportFlags::CONTENT ))
160 blockFontEmbedding = true;
161 if (!GetDocument()->IsEmbedFonts())
162 blockFontEmbedding = true;
163 return new ScXMLFontAutoStylePool_Impl( *this, !blockFontEmbedding );
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */