LibreOffice Module sc (master) 1
xmlfonte.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <scitems.hxx>
21
22#include <editeng/eeitem.hxx>
23
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>
32
33namespace {
34
35class ScXMLFontAutoStylePool_Impl: public XMLFontAutoStylePool
36{
37private:
38 // #i120077# remember owned pool
39 rtl::Reference<SfxItemPool> mpEditEnginePool;
40
41 void AddFontItems(const sal_uInt16* pWhichIds, sal_uInt8 nIdCount, const SfxItemPool* pItemPool, const bool bExportDefaults);
42
43public:
44 ScXMLFontAutoStylePool_Impl( ScXMLExport& rExport, bool bEmbedFonts);
45};
46
47}
48
49void ScXMLFontAutoStylePool_Impl::AddFontItems(const sal_uInt16* pWhichIds, sal_uInt8 nIdCount, const SfxItemPool* pItemPool, const bool bExportDefaults)
50{
51 for( sal_uInt16 i=0; i < nIdCount; ++i )
52 {
53 sal_uInt16 nWhichId(pWhichIds[i]);
54 if (bExportDefaults)
55 {
56 const SfxPoolItem* pItem = &pItemPool->GetDefaultItem(nWhichId);
57 const SvxFontItem *pFont(static_cast<const SvxFontItem *>(pItem));
58 Add( pFont->GetFamilyName(), pFont->GetStyleName(),
59 pFont->GetFamily(), pFont->GetPitch(),
60 pFont->GetCharSet() );
61 }
62 for (const SfxPoolItem* pItem : pItemPool->GetItemSurrogates( nWhichId ))
63 {
64 const SvxFontItem *pFont(static_cast<const SvxFontItem *>(pItem));
65 Add( pFont->GetFamilyName(), pFont->GetStyleName(),
66 pFont->GetFamily(), pFont->GetPitch(),
67 pFont->GetCharSet() );
68 }
69 }
70}
71
72ScXMLFontAutoStylePool_Impl::ScXMLFontAutoStylePool_Impl(ScXMLExport& rExportP, bool bEmbedFonts)
73 : XMLFontAutoStylePool(rExportP, bEmbedFonts)
74{
75 sal_uInt16 const aWhichIds[] { ATTR_FONT, ATTR_CJK_FONT,
77 sal_uInt16 const aEditWhichIds[] { EE_CHAR_FONTINFO, EE_CHAR_FONTINFO_CJK,
79 sal_uInt16 const aPageWhichIds[] { ATTR_PAGE_HEADERLEFT, ATTR_PAGE_FOOTERLEFT,
82
83 const SfxItemPool* pItemPool(rExportP.GetDocument()->GetPool());
84 AddFontItems(aWhichIds, 3, pItemPool, true);
85 const SfxItemPool* pEditPool(rExportP.GetDocument()->GetEditPool());
86 AddFontItems(aEditWhichIds, 3, pEditPool, false);
87
88 std::unique_ptr<SfxStyleSheetIterator> pItr = rExportP.GetDocument()->GetStyleSheetPool()->CreateIterator(SfxStyleFamily::Page);
89
90 m_bEmbedUsedOnly = rExportP.GetDocument()->IsEmbedUsedFontsOnly();
91 m_bEmbedLatinScript = rExportP.GetDocument()->IsEmbedFontScriptLatin();
92 m_bEmbedAsianScript = rExportP.GetDocument()->IsEmbedFontScriptAsian();
93 m_bEmbedComplexScript = rExportP.GetDocument()->IsEmbedFontScriptComplex();
94
95 if(!pItr)
96 return;
97
98 SfxStyleSheetBase* pStyle(pItr->First());
99
100 if(!pStyle)
101 return;
102
103 // #i120077# remember the SfxItemPool in member variable before usage. The
104 // local EditEngine will not take over ownership of the pool.
105 mpEditEnginePool = EditEngine::CreatePool();
106 EditEngine aEditEngine(mpEditEnginePool.get());
107
108 while (pStyle)
109 {
110 const SfxItemPool& rPagePool(pStyle->GetPool()->GetPool());
111
112 for (sal_uInt16 nPageWhichId : aPageWhichIds)
113 {
114 for (const SfxPoolItem* pItem : rPagePool.GetItemSurrogates( nPageWhichId ))
115 {
116 const ScPageHFItem* pPageItem = static_cast<const ScPageHFItem*>(pItem);
117 const EditTextObject* pLeftArea(pPageItem->GetLeftArea());
118 if (pLeftArea)
119 {
120 aEditEngine.SetText(*pLeftArea);
121 AddFontItems(aEditWhichIds, 3, mpEditEnginePool.get(), false);
122 }
123 const EditTextObject* pCenterArea(pPageItem->GetCenterArea());
124 if (pCenterArea)
125 {
126 aEditEngine.SetText(*pCenterArea);
127 AddFontItems(aEditWhichIds, 3, mpEditEnginePool.get(), false);
128 }
129 const EditTextObject* pRightArea(pPageItem->GetRightArea());
130 if (pRightArea)
131 {
132 aEditEngine.SetText(*pRightArea);
133 AddFontItems(aEditWhichIds, 3, mpEditEnginePool.get(), false);
134 }
135 }
136 }
137
138 pStyle = pItr->Next();
139 }
140}
141
143{
144 bool blockFontEmbedding = false;
145 // We write font info to both content.xml and styles.xml, but they are both
146 // written by different ScXMLExport instance, and would therefore write each
147 // font file twice without complicated checking for duplicates, so handle
148 // the embedding only in one of them.
149 if(!( getExportFlags() & SvXMLExportFlags::CONTENT ))
150 blockFontEmbedding = true;
151 if (!GetDocument()->IsEmbedFonts())
152 blockFontEmbedding = true;
153 return new ScXMLFontAutoStylePool_Impl( *this, !blockFontEmbedding );
154}
155
156/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static rtl::Reference< SfxItemPool > CreatePool()
bool IsEmbedUsedFontsOnly() const
Definition: document.hxx:584
SC_DLLPUBLIC ScDocumentPool * GetPool()
Definition: document.cxx:6050
bool IsEmbedFontScriptComplex() const
Definition: document.hxx:587
SC_DLLPUBLIC SfxItemPool * GetEditPool() const
Definition: documen2.cxx:473
bool IsEmbedFontScriptLatin() const
Definition: document.hxx:585
bool IsEmbedFontScriptAsian() const
Definition: document.hxx:586
SC_DLLPUBLIC ScStyleSheetPool * GetStyleSheetPool() const
Definition: document.cxx:6055
const EditTextObject * GetCenterArea() const
Definition: attrib.hxx:191
const EditTextObject * GetLeftArea() const
Definition: attrib.hxx:190
const EditTextObject * GetRightArea() const
Definition: attrib.hxx:192
ScDocument * GetDocument()
Definition: xmlexprt.hxx:240
virtual XMLFontAutoStylePool * CreateFontAutoStylePool() override
Definition: xmlfonte.cxx:142
Item2Range GetItemSurrogates(sal_uInt16 nWhich) const
const SfxPoolItem & GetDefaultItem(sal_uInt16 nWhich) const
virtual std::unique_ptr< SfxStyleSheetIterator > CreateIterator(SfxStyleFamily, SfxStyleSearchBits nMask=SfxStyleSearchBits::All)
SvXMLExportFlags getExportFlags() const
constexpr TypedWhichId< SvxFontItem > EE_CHAR_FONTINFO_CJK(EE_CHAR_START+17)
constexpr TypedWhichId< SvxFontItem > EE_CHAR_FONTINFO_CTL(EE_CHAR_START+18)
constexpr TypedWhichId< SvxFontItem > EE_CHAR_FONTINFO(EE_CHAR_START+1)
int i
constexpr TypedWhichId< ScPageHFItem > ATTR_PAGE_FOOTERLEFT(179)
constexpr TypedWhichId< ScPageHFItem > ATTR_PAGE_HEADERLEFT(178)
constexpr TypedWhichId< SvxFontItem > ATTR_CJK_FONT(111)
constexpr TypedWhichId< SvxFontItem > ATTR_CTL_FONT(116)
constexpr TypedWhichId< ScPageHFItem > ATTR_PAGE_FOOTERRIGHT(181)
constexpr TypedWhichId< ScPageHFItem > ATTR_PAGE_HEADERRIGHT(180)
constexpr TypedWhichId< ScPageHFItem > ATTR_PAGE_HEADERFIRST(182)
constexpr TypedWhichId< ScPageHFItem > ATTR_PAGE_FOOTERFIRST(183)
constexpr TypedWhichId< SvxFontItem > ATTR_FONT(100)
unsigned char sal_uInt8