1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlfonte.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 #include "filt_pch.hxx"
38 #include "scitems.hxx"
40 #include <svx/eeitem.hxx>
43 #include <xmloff/XMLFontAutoStylePool.hxx>
44 #include <svx/fontitem.hxx>
45 #include <svx/eeitem.hxx>
46 #include <svx/editeng.hxx>
47 #include "document.hxx"
48 #include "docpool.hxx"
49 #include "xmlexprt.hxx"
50 #include "stlpool.hxx"
53 class ScXMLFontAutoStylePool_Impl
: public XMLFontAutoStylePool
55 void AddFontItems(sal_uInt16
* pWhichIds
, sal_uInt8 nIdCount
, const SfxItemPool
* pItemPool
, const sal_Bool bExportDefaults
);
58 ScXMLFontAutoStylePool_Impl( ScXMLExport
& rExport
);
62 void ScXMLFontAutoStylePool_Impl::AddFontItems(sal_uInt16
* pWhichIds
, sal_uInt8 nIdCount
, const SfxItemPool
* pItemPool
, const sal_Bool bExportDefaults
)
64 const SfxPoolItem
* pItem
;
65 for( sal_uInt16 i
=0; i
< nIdCount
; ++i
)
67 sal_uInt16
nWhichId(pWhichIds
[i
]);
68 if (bExportDefaults
&& (0 != (pItem
= &pItemPool
->GetDefaultItem(nWhichId
))))
70 const SvxFontItem
*pFont((const SvxFontItem
*)pItem
);
71 Add( pFont
->GetFamilyName(), pFont
->GetStyleName(),
72 sal::static_int_cast
<sal_Int16
>(pFont
->GetFamily()),
73 sal::static_int_cast
<sal_Int16
>(pFont
->GetPitch()),
74 pFont
->GetCharSet() );
76 sal_uInt16
nItems(pItemPool
->GetItemCount( nWhichId
));
77 for( sal_uInt16 j
= 0; j
< nItems
; ++j
)
79 if( 0 != (pItem
= pItemPool
->GetItem( nWhichId
, j
) ) )
81 const SvxFontItem
*pFont((const SvxFontItem
*)pItem
);
82 Add( pFont
->GetFamilyName(), pFont
->GetStyleName(),
83 sal::static_int_cast
<sal_Int16
>(pFont
->GetFamily()),
84 sal::static_int_cast
<sal_Int16
>(pFont
->GetPitch()),
85 pFont
->GetCharSet() );
91 ScXMLFontAutoStylePool_Impl::ScXMLFontAutoStylePool_Impl(
92 ScXMLExport
& rExportP
) :
93 XMLFontAutoStylePool( rExportP
)
95 sal_uInt16 aWhichIds
[3] = { ATTR_FONT
, ATTR_CJK_FONT
,
97 sal_uInt16 aEditWhichIds
[3] = { EE_CHAR_FONTINFO
, EE_CHAR_FONTINFO_CJK
,
98 EE_CHAR_FONTINFO_CTL
};
99 sal_uInt16 aPageWhichIds
[4] = { ATTR_PAGE_HEADERLEFT
, ATTR_PAGE_FOOTERLEFT
,
100 ATTR_PAGE_HEADERRIGHT
, ATTR_PAGE_FOOTERRIGHT
};
102 const SfxItemPool
* pItemPool(rExportP
.GetDocument() ? rExportP
.GetDocument()->GetPool() : NULL
);
103 AddFontItems(aWhichIds
, 3, pItemPool
, sal_True
);
104 const SfxItemPool
* pEditPool(rExportP
.GetDocument()->GetEditPool());
105 AddFontItems(aEditWhichIds
, 3, pEditPool
, sal_False
);
107 SfxStyleSheetIterator
* pItr(rExportP
.GetDocument() ? rExportP
.GetDocument()->GetStyleSheetPool()->CreateIterator(SFX_STYLE_FAMILY_PAGE
, 0xFFFF) : NULL
);
110 SfxStyleSheetBase
* pStyle(pItr
->First());
111 SfxItemPool
* pPageEditPool(EditEngine::CreatePool());
112 EditEngine
aEditEngine(pPageEditPool
);
115 const SfxItemPool
& rPagePool(pStyle
->GetPool().GetPool());
116 for (sal_uInt8 j
= 0; j
< 4; ++j
)
118 sal_uInt16
nPageWhichId(aPageWhichIds
[j
]);
119 sal_uInt16
nPageHFItems(rPagePool
.GetItemCount(nPageWhichId
));
120 const ScPageHFItem
* pPageItem
;
121 for (sal_uInt16 k
= 0; k
< nPageHFItems
; ++k
)
123 if (0 != (pPageItem
= static_cast<const ScPageHFItem
*>(rPagePool
.GetItem(nPageWhichId
, k
))))
125 const EditTextObject
* pLeftArea(pPageItem
->GetLeftArea());
128 aEditEngine
.SetText(*pLeftArea
);
129 AddFontItems(aEditWhichIds
, 3, pPageEditPool
, sal_False
);
131 const EditTextObject
* pCenterArea(pPageItem
->GetCenterArea());
134 aEditEngine
.SetText(*pCenterArea
);
135 AddFontItems(aEditWhichIds
, 3, pPageEditPool
, sal_False
);
137 const EditTextObject
* pRightArea(pPageItem
->GetRightArea());
140 aEditEngine
.SetText(*pRightArea
);
141 AddFontItems(aEditWhichIds
, 3, pPageEditPool
, sal_False
);
146 pStyle
= pItr
->Next();
152 XMLFontAutoStylePool
* ScXMLExport::CreateFontAutoStylePool()
154 return new ScXMLFontAutoStylePool_Impl( *this );