Line data Source code
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 :
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"
32 :
33 : class ScXMLFontAutoStylePool_Impl: public XMLFontAutoStylePool
34 : {
35 : private:
36 : // #i120077# remember owned pool
37 : SfxItemPool* mpEditEnginePool;
38 :
39 : void AddFontItems(sal_uInt16* pWhichIds, sal_uInt8 nIdCount, const SfxItemPool* pItemPool, const sal_Bool bExportDefaults);
40 :
41 : public:
42 : ScXMLFontAutoStylePool_Impl( ScXMLExport& rExport, bool bBlockFontEmbedding );
43 : virtual ~ScXMLFontAutoStylePool_Impl();
44 : };
45 :
46 1368 : void ScXMLFontAutoStylePool_Impl::AddFontItems(sal_uInt16* pWhichIds, sal_uInt8 nIdCount, const SfxItemPool* pItemPool, const sal_Bool bExportDefaults)
47 : {
48 : const SfxPoolItem* pItem;
49 5472 : for( sal_uInt16 i=0; i < nIdCount; ++i )
50 : {
51 4104 : sal_uInt16 nWhichId(pWhichIds[i]);
52 4104 : if (bExportDefaults && (0 != (pItem = &pItemPool->GetDefaultItem(nWhichId))))
53 : {
54 108 : const SvxFontItem *pFont((const SvxFontItem *)pItem);
55 108 : Add( pFont->GetFamilyName(), pFont->GetStyleName(),
56 : pFont->GetFamily(), pFont->GetPitch(),
57 216 : pFont->GetCharSet() );
58 : }
59 4104 : sal_uInt32 nItems(pItemPool->GetItemCount2( nWhichId ));
60 7148 : for( sal_uInt32 j = 0; j < nItems; ++j )
61 : {
62 3044 : if( 0 != (pItem = pItemPool->GetItem2( nWhichId, j ) ) )
63 : {
64 2982 : const SvxFontItem *pFont((const SvxFontItem *)pItem);
65 2982 : Add( pFont->GetFamilyName(), pFont->GetStyleName(),
66 : pFont->GetFamily(), pFont->GetPitch(),
67 5964 : pFont->GetCharSet() );
68 : }
69 : }
70 : }
71 1368 : }
72 :
73 36 : ScXMLFontAutoStylePool_Impl::ScXMLFontAutoStylePool_Impl(ScXMLExport& rExportP, bool bBlockFontEmbedding)
74 : : XMLFontAutoStylePool(rExportP, bBlockFontEmbedding)
75 36 : , mpEditEnginePool(NULL)
76 : {
77 : sal_uInt16 aWhichIds[3] = { ATTR_FONT, ATTR_CJK_FONT,
78 36 : ATTR_CTL_FONT };
79 : sal_uInt16 aEditWhichIds[3] = { EE_CHAR_FONTINFO, EE_CHAR_FONTINFO_CJK,
80 36 : EE_CHAR_FONTINFO_CTL };
81 : sal_uInt16 aPageWhichIds[4] = { ATTR_PAGE_HEADERLEFT, ATTR_PAGE_FOOTERLEFT,
82 36 : ATTR_PAGE_HEADERRIGHT, ATTR_PAGE_FOOTERRIGHT };
83 :
84 36 : const SfxItemPool* pItemPool(rExportP.GetDocument() ? rExportP.GetDocument()->GetPool() : NULL);
85 36 : AddFontItems(aWhichIds, 3, pItemPool, sal_True);
86 36 : const SfxItemPool* pEditPool(rExportP.GetDocument()->GetEditPool());
87 36 : AddFontItems(aEditWhichIds, 3, pEditPool, false);
88 :
89 36 : SfxStyleSheetIteratorPtr pItr;
90 :
91 36 : if(rExportP.GetDocument())
92 : {
93 36 : pItr = rExportP.GetDocument()->GetStyleSheetPool()->CreateIterator(SFX_STYLE_FAMILY_PAGE, 0xFFFF);
94 : }
95 :
96 36 : if(pItr)
97 : {
98 36 : SfxStyleSheetBase* pStyle(pItr->First());
99 :
100 36 : if(pStyle)
101 : {
102 : // #i120077# remember the SfxItemPool in member variable before usage. The
103 : // local EditEngine will not take over ownership of the pool.
104 36 : mpEditEnginePool = EditEngine::CreatePool();
105 36 : EditEngine aEditEngine(mpEditEnginePool);
106 :
107 146 : while (pStyle)
108 : {
109 74 : const SfxItemPool& rPagePool(pStyle->GetPool().GetPool());
110 :
111 370 : for (sal_uInt8 j = 0; j < 4; ++j)
112 : {
113 296 : sal_uInt16 nPageWhichId(aPageWhichIds[j]);
114 296 : sal_uInt32 nPageHFItems(rPagePool.GetItemCount2(nPageWhichId));
115 : const ScPageHFItem* pPageItem;
116 988 : for (sal_uInt32 k = 0; k < nPageHFItems; ++k)
117 : {
118 692 : if (0 != (pPageItem = static_cast<const ScPageHFItem*>(rPagePool.GetItem2(nPageWhichId, k))))
119 : {
120 432 : const EditTextObject* pLeftArea(pPageItem->GetLeftArea());
121 432 : if (pLeftArea)
122 : {
123 432 : aEditEngine.SetText(*pLeftArea);
124 432 : AddFontItems(aEditWhichIds, 3, mpEditEnginePool, false);
125 : }
126 432 : const EditTextObject* pCenterArea(pPageItem->GetCenterArea());
127 432 : if (pCenterArea)
128 : {
129 432 : aEditEngine.SetText(*pCenterArea);
130 432 : AddFontItems(aEditWhichIds, 3, mpEditEnginePool, false);
131 : }
132 432 : const EditTextObject* pRightArea(pPageItem->GetRightArea());
133 432 : if (pRightArea)
134 : {
135 432 : aEditEngine.SetText(*pRightArea);
136 432 : AddFontItems(aEditWhichIds, 3, mpEditEnginePool, false);
137 : }
138 : }
139 : }
140 : }
141 :
142 74 : pStyle = pItr->Next();
143 36 : }
144 : }
145 36 : }
146 36 : }
147 :
148 108 : ScXMLFontAutoStylePool_Impl::~ScXMLFontAutoStylePool_Impl()
149 : {
150 36 : if(mpEditEnginePool)
151 : {
152 : // memory leak #i120077#
153 36 : SfxItemPool::Free(mpEditEnginePool);
154 : }
155 72 : }
156 :
157 36 : XMLFontAutoStylePool* ScXMLExport::CreateFontAutoStylePool()
158 : {
159 36 : bool blockFontEmbedding = false;
160 : // We write font info to both content.xml and styles.xml, but they are both
161 : // written by different ScXMLExport instance, and would therefore write each
162 : // font file twice without complicated checking for duplicates, so handle
163 : // the embedding only in one of them.
164 36 : if(( getExportFlags() & EXPORT_CONTENT ) == 0 )
165 18 : blockFontEmbedding = true;
166 36 : if( !GetDocument()->IsUsingEmbededFonts())
167 36 : blockFontEmbedding = true;
168 36 : return new ScXMLFontAutoStylePool_Impl( *this, !blockFontEmbedding );
169 : }
170 :
171 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|