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 8 : class ScXMLFontAutoStylePool_Impl: public XMLFontAutoStylePool
34 : {
35 : void AddFontItems(sal_uInt16* pWhichIds, sal_uInt8 nIdCount, const SfxItemPool* pItemPool, const sal_Bool bExportDefaults);
36 : public:
37 :
38 : ScXMLFontAutoStylePool_Impl( ScXMLExport& rExport );
39 :
40 : };
41 :
42 104 : void ScXMLFontAutoStylePool_Impl::AddFontItems(sal_uInt16* pWhichIds, sal_uInt8 nIdCount, const SfxItemPool* pItemPool, const sal_Bool bExportDefaults)
43 : {
44 : const SfxPoolItem* pItem;
45 416 : for( sal_uInt16 i=0; i < nIdCount; ++i )
46 : {
47 312 : sal_uInt16 nWhichId(pWhichIds[i]);
48 312 : if (bExportDefaults && (0 != (pItem = &pItemPool->GetDefaultItem(nWhichId))))
49 : {
50 12 : const SvxFontItem *pFont((const SvxFontItem *)pItem);
51 24 : Add( pFont->GetFamilyName(), pFont->GetStyleName(),
52 12 : sal::static_int_cast<sal_Int16>(pFont->GetFamily()),
53 12 : sal::static_int_cast<sal_Int16>(pFont->GetPitch()),
54 60 : pFont->GetCharSet() );
55 : }
56 312 : sal_uInt32 nItems(pItemPool->GetItemCount2( nWhichId ));
57 320 : for( sal_uInt32 j = 0; j < nItems; ++j )
58 : {
59 8 : if( 0 != (pItem = pItemPool->GetItem2( nWhichId, j ) ) )
60 : {
61 8 : const SvxFontItem *pFont((const SvxFontItem *)pItem);
62 16 : Add( pFont->GetFamilyName(), pFont->GetStyleName(),
63 8 : sal::static_int_cast<sal_Int16>(pFont->GetFamily()),
64 8 : sal::static_int_cast<sal_Int16>(pFont->GetPitch()),
65 40 : pFont->GetCharSet() );
66 : }
67 : }
68 : }
69 104 : }
70 :
71 4 : ScXMLFontAutoStylePool_Impl::ScXMLFontAutoStylePool_Impl(
72 : ScXMLExport& rExportP ) :
73 4 : XMLFontAutoStylePool( rExportP )
74 : {
75 : sal_uInt16 aWhichIds[3] = { ATTR_FONT, ATTR_CJK_FONT,
76 4 : ATTR_CTL_FONT };
77 : sal_uInt16 aEditWhichIds[3] = { EE_CHAR_FONTINFO, EE_CHAR_FONTINFO_CJK,
78 4 : EE_CHAR_FONTINFO_CTL };
79 : sal_uInt16 aPageWhichIds[4] = { ATTR_PAGE_HEADERLEFT, ATTR_PAGE_FOOTERLEFT,
80 4 : ATTR_PAGE_HEADERRIGHT, ATTR_PAGE_FOOTERRIGHT };
81 :
82 4 : const SfxItemPool* pItemPool(rExportP.GetDocument() ? rExportP.GetDocument()->GetPool() : NULL);
83 4 : AddFontItems(aWhichIds, 3, pItemPool, sal_True);
84 4 : const SfxItemPool* pEditPool(rExportP.GetDocument()->GetEditPool());
85 4 : AddFontItems(aEditWhichIds, 3, pEditPool, false);
86 :
87 4 : SfxStyleSheetIterator* pItr(rExportP.GetDocument() ? rExportP.GetDocument()->GetStyleSheetPool()->CreateIterator(SFX_STYLE_FAMILY_PAGE, 0xFFFF) : NULL);
88 4 : if(pItr)
89 : {
90 4 : SfxStyleSheetBase* pStyle(pItr->First());
91 4 : SfxItemPool* pPageEditPool(EditEngine::CreatePool());
92 4 : EditEngine aEditEngine(pPageEditPool);
93 16 : while (pStyle)
94 : {
95 8 : const SfxItemPool& rPagePool(pStyle->GetPool().GetPool());
96 40 : for (sal_uInt8 j = 0; j < 4; ++j)
97 : {
98 32 : sal_uInt16 nPageWhichId(aPageWhichIds[j]);
99 32 : sal_uInt32 nPageHFItems(rPagePool.GetItemCount2(nPageWhichId));
100 : const ScPageHFItem* pPageItem;
101 72 : for (sal_uInt32 k = 0; k < nPageHFItems; ++k)
102 : {
103 40 : if (0 != (pPageItem = static_cast<const ScPageHFItem*>(rPagePool.GetItem2(nPageWhichId, k))))
104 : {
105 32 : const EditTextObject* pLeftArea(pPageItem->GetLeftArea());
106 32 : if (pLeftArea)
107 : {
108 32 : aEditEngine.SetText(*pLeftArea);
109 32 : AddFontItems(aEditWhichIds, 3, pPageEditPool, false);
110 : }
111 32 : const EditTextObject* pCenterArea(pPageItem->GetCenterArea());
112 32 : if (pCenterArea)
113 : {
114 32 : aEditEngine.SetText(*pCenterArea);
115 32 : AddFontItems(aEditWhichIds, 3, pPageEditPool, false);
116 : }
117 32 : const EditTextObject* pRightArea(pPageItem->GetRightArea());
118 32 : if (pRightArea)
119 : {
120 32 : aEditEngine.SetText(*pRightArea);
121 32 : AddFontItems(aEditWhichIds, 3, pPageEditPool, false);
122 : }
123 : }
124 : }
125 : }
126 8 : pStyle = pItr->Next();
127 4 : }
128 : }
129 4 : }
130 :
131 :
132 4 : XMLFontAutoStylePool* ScXMLExport::CreateFontAutoStylePool()
133 : {
134 4 : return new ScXMLFontAutoStylePool_Impl( *this );
135 : }
136 :
137 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|