1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
33 class ScXMLFontAutoStylePool_Impl
: public XMLFontAutoStylePool
36 // #i120077# remember owned pool
37 SfxItemPool
* mpEditEnginePool
;
39 void AddFontItems(const sal_uInt16
* pWhichIds
, sal_uInt8 nIdCount
, const SfxItemPool
* pItemPool
, const bool bExportDefaults
);
42 ScXMLFontAutoStylePool_Impl( ScXMLExport
& rExport
, bool bEmbedFonts
);
43 virtual ~ScXMLFontAutoStylePool_Impl() override
;
46 void ScXMLFontAutoStylePool_Impl::AddFontItems(const sal_uInt16
* pWhichIds
, sal_uInt8 nIdCount
, const SfxItemPool
* pItemPool
, const bool bExportDefaults
)
48 for( sal_uInt16 i
=0; i
< nIdCount
; ++i
)
50 sal_uInt16
nWhichId(pWhichIds
[i
]);
53 const SfxPoolItem
* pItem
= &pItemPool
->GetDefaultItem(nWhichId
);
54 const SvxFontItem
*pFont(static_cast<const SvxFontItem
*>(pItem
));
55 Add( pFont
->GetFamilyName(), pFont
->GetStyleName(),
56 pFont
->GetFamily(), pFont
->GetPitch(),
57 pFont
->GetCharSet() );
59 for (const SfxPoolItem
* pItem
: pItemPool
->GetItemSurrogates( nWhichId
))
61 const SvxFontItem
*pFont(static_cast<const SvxFontItem
*>(pItem
));
62 Add( pFont
->GetFamilyName(), pFont
->GetStyleName(),
63 pFont
->GetFamily(), pFont
->GetPitch(),
64 pFont
->GetCharSet() );
69 ScXMLFontAutoStylePool_Impl::ScXMLFontAutoStylePool_Impl(ScXMLExport
& rExportP
, bool bEmbedFonts
)
70 : XMLFontAutoStylePool(rExportP
, bEmbedFonts
)
71 , mpEditEnginePool(nullptr)
73 sal_uInt16
const aWhichIds
[] { ATTR_FONT
, ATTR_CJK_FONT
,
75 sal_uInt16
const aEditWhichIds
[] { EE_CHAR_FONTINFO
, EE_CHAR_FONTINFO_CJK
,
76 EE_CHAR_FONTINFO_CTL
};
77 sal_uInt16
const aPageWhichIds
[] { ATTR_PAGE_HEADERLEFT
, ATTR_PAGE_FOOTERLEFT
,
78 ATTR_PAGE_HEADERRIGHT
, ATTR_PAGE_FOOTERRIGHT
};
80 const SfxItemPool
* pItemPool(rExportP
.GetDocument()->GetPool());
81 AddFontItems(aWhichIds
, 3, pItemPool
, true);
82 const SfxItemPool
* pEditPool(rExportP
.GetDocument()->GetEditPool());
83 AddFontItems(aEditWhichIds
, 3, pEditPool
, false);
85 std::unique_ptr
<SfxStyleSheetIterator
> pItr
= rExportP
.GetDocument()->GetStyleSheetPool()->CreateIterator(SfxStyleFamily::Page
, SfxStyleSearchBits::All
);
87 m_bEmbedUsedOnly
= rExportP
.GetDocument()->IsEmbedUsedFontsOnly();
88 m_bEmbedLatinScript
= rExportP
.GetDocument()->IsEmbedFontScriptLatin();
89 m_bEmbedAsianScript
= rExportP
.GetDocument()->IsEmbedFontScriptAsian();
90 m_bEmbedComplexScript
= rExportP
.GetDocument()->IsEmbedFontScriptComplex();
94 SfxStyleSheetBase
* pStyle(pItr
->First());
98 // #i120077# remember the SfxItemPool in member variable before usage. The
99 // local EditEngine will not take over ownership of the pool.
100 mpEditEnginePool
= EditEngine::CreatePool();
101 EditEngine
aEditEngine(mpEditEnginePool
);
105 const SfxItemPool
& rPagePool(pStyle
->GetPool()->GetPool());
107 for (sal_uInt16 nPageWhichId
: aPageWhichIds
)
109 for (const SfxPoolItem
* pItem
: rPagePool
.GetItemSurrogates( nPageWhichId
))
111 const ScPageHFItem
* pPageItem
= static_cast<const ScPageHFItem
*>(pItem
);
112 const EditTextObject
* pLeftArea(pPageItem
->GetLeftArea());
115 aEditEngine
.SetText(*pLeftArea
);
116 AddFontItems(aEditWhichIds
, 3, mpEditEnginePool
, false);
118 const EditTextObject
* pCenterArea(pPageItem
->GetCenterArea());
121 aEditEngine
.SetText(*pCenterArea
);
122 AddFontItems(aEditWhichIds
, 3, mpEditEnginePool
, false);
124 const EditTextObject
* pRightArea(pPageItem
->GetRightArea());
127 aEditEngine
.SetText(*pRightArea
);
128 AddFontItems(aEditWhichIds
, 3, mpEditEnginePool
, false);
133 pStyle
= pItr
->Next();
139 ScXMLFontAutoStylePool_Impl::~ScXMLFontAutoStylePool_Impl()
143 // memory leak #i120077#
144 SfxItemPool::Free(mpEditEnginePool
);
148 XMLFontAutoStylePool
* ScXMLExport::CreateFontAutoStylePool()
150 bool blockFontEmbedding
= false;
151 // We write font info to both content.xml and styles.xml, but they are both
152 // written by different ScXMLExport instance, and would therefore write each
153 // font file twice without complicated checking for duplicates, so handle
154 // the embedding only in one of them.
155 if(!( getExportFlags() & SvXMLExportFlags::CONTENT
))
156 blockFontEmbedding
= true;
157 if (!GetDocument()->IsEmbedFonts())
158 blockFontEmbedding
= true;
159 return new ScXMLFontAutoStylePool_Impl( *this, !blockFontEmbedding
);
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */