tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / filter / xml / xmlfonte.cxx
blob46bf1f159bdb12b31f2664d03c1b4e1fc9a5662d
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 rtl::Reference<SfxItemPool> mpEditEnginePool;
41 void AddFontItems(const sal_uInt16* pWhichIds, sal_uInt8 nIdCount, const SfxItemPool* pItemPool, const bool bExportDefaults);
43 public:
44 ScXMLFontAutoStylePool_Impl(ScDocument* pDoc, ScXMLExport& rExport, bool bEmbedFonts);
49 void ScXMLFontAutoStylePool_Impl::AddFontItems(const sal_uInt16* pWhichIds, sal_uInt8 nIdCount, const SfxItemPool* pItemPool, const bool bExportDefaults)
51 for( sal_uInt16 i=0; i < nIdCount; ++i )
53 sal_uInt16 nWhichId(pWhichIds[i]);
54 if (bExportDefaults)
56 const SfxPoolItem* pItem = &pItemPool->GetUserOrPoolDefaultItem(nWhichId);
57 const SvxFontItem *pFont(static_cast<const SvxFontItem *>(pItem));
58 Add( pFont->GetFamilyName(), pFont->GetStyleName(),
59 pFont->GetFamily(), pFont->GetPitch(),
60 pFont->GetCharSet() );
62 ItemSurrogates aSurrogates;
63 pItemPool->GetItemSurrogates( aSurrogates, nWhichId );
64 for (const SfxPoolItem* pItem : aSurrogates)
66 const SvxFontItem *pFont(static_cast<const SvxFontItem *>(pItem));
67 Add( pFont->GetFamilyName(), pFont->GetStyleName(),
68 pFont->GetFamily(), pFont->GetPitch(),
69 pFont->GetCharSet() );
74 ScXMLFontAutoStylePool_Impl::ScXMLFontAutoStylePool_Impl(ScDocument* pDoc, ScXMLExport& rExportP, bool bEmbedFonts)
75 : XMLFontAutoStylePool(rExportP, bEmbedFonts)
77 if (!pDoc)
78 return;
80 sal_uInt16 const aWhichIds[] { ATTR_FONT, ATTR_CJK_FONT,
81 ATTR_CTL_FONT };
82 sal_uInt16 const aEditWhichIds[] { EE_CHAR_FONTINFO, EE_CHAR_FONTINFO_CJK,
83 EE_CHAR_FONTINFO_CTL };
84 sal_uInt16 const aPageWhichIds[] { ATTR_PAGE_HEADERLEFT, ATTR_PAGE_FOOTERLEFT,
85 ATTR_PAGE_HEADERRIGHT, ATTR_PAGE_FOOTERRIGHT,
86 ATTR_PAGE_HEADERFIRST, ATTR_PAGE_FOOTERFIRST };
88 const SfxItemPool* pItemPool(pDoc->GetPool());
89 AddFontItems(aWhichIds, 3, pItemPool, true);
90 const SfxItemPool* pEditPool(pDoc->GetEditPool());
91 AddFontItems(aEditWhichIds, 3, pEditPool, false);
93 std::unique_ptr<SfxStyleSheetIterator> pItr = pDoc->GetStyleSheetPool()->CreateIterator(SfxStyleFamily::Page);
95 m_bEmbedUsedOnly = pDoc->IsEmbedUsedFontsOnly();
96 m_bEmbedLatinScript = pDoc->IsEmbedFontScriptLatin();
97 m_bEmbedAsianScript = pDoc->IsEmbedFontScriptAsian();
98 m_bEmbedComplexScript = pDoc->IsEmbedFontScriptComplex();
100 if(!pItr)
101 return;
103 SfxStyleSheetBase* pStyle(pItr->First());
105 if(!pStyle)
106 return;
108 // #i120077# remember the SfxItemPool in member variable before usage. The
109 // local EditEngine will not take over ownership of the pool.
110 mpEditEnginePool = EditEngine::CreatePool();
111 EditEngine aEditEngine(mpEditEnginePool.get());
113 while (pStyle)
115 const SfxItemPool& rPagePool(pStyle->GetPool()->GetPool());
117 for (sal_uInt16 nPageWhichId : aPageWhichIds)
119 ItemSurrogates aSurrogates;
120 rPagePool.GetItemSurrogates( aSurrogates, nPageWhichId );
121 for (const SfxPoolItem* pItem : aSurrogates)
123 const ScPageHFItem* pPageItem = static_cast<const ScPageHFItem*>(pItem);
124 const EditTextObject* pLeftArea(pPageItem->GetLeftArea());
125 if (pLeftArea)
127 aEditEngine.SetText(*pLeftArea);
128 AddFontItems(aEditWhichIds, 3, mpEditEnginePool.get(), false);
130 const EditTextObject* pCenterArea(pPageItem->GetCenterArea());
131 if (pCenterArea)
133 aEditEngine.SetText(*pCenterArea);
134 AddFontItems(aEditWhichIds, 3, mpEditEnginePool.get(), false);
136 const EditTextObject* pRightArea(pPageItem->GetRightArea());
137 if (pRightArea)
139 aEditEngine.SetText(*pRightArea);
140 AddFontItems(aEditWhichIds, 3, mpEditEnginePool.get(), false);
145 pStyle = pItr->Next();
149 XMLFontAutoStylePool* ScXMLExport::CreateFontAutoStylePool()
151 bool blockFontEmbedding = false;
152 // We write font info to both content.xml and styles.xml, but they are both
153 // written by different ScXMLExport instance, and would therefore write each
154 // font file twice without complicated checking for duplicates, so handle
155 // the embedding only in one of them.
156 if(!( getExportFlags() & SvXMLExportFlags::CONTENT ))
157 blockFontEmbedding = true;
158 ScDocument* pDoc = GetDocument();
159 if (pDoc && !pDoc->IsEmbedFonts())
160 blockFontEmbedding = true;
161 return new ScXMLFontAutoStylePool_Impl(pDoc, *this, !blockFontEmbedding);
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */