merge the formfield patch from ooo-build
[ooovba.git] / sw / source / filter / xml / xmlfonte.cxx
blob8ee621903f80018d3aa0dc014a7aa5e10398ba61
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlfonte.cxx,v $
10 * $Revision: 1.9 $
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_sw.hxx"
35 #include "hintids.hxx"
36 #include <com/sun/star/text/XTextDocument.hpp>
37 #include <xmloff/XMLFontAutoStylePool.hxx>
38 #include <svx/fontitem.hxx>
39 #include <unoobj.hxx>
40 #include <doc.hxx>
41 #include <xmlexp.hxx>
43 using namespace ::com::sun::star::uno;
44 using namespace ::com::sun::star::lang;
45 using namespace ::com::sun::star::text;
47 class SwXMLFontAutoStylePool_Impl: public XMLFontAutoStylePool
49 public:
51 SwXMLFontAutoStylePool_Impl( SwXMLExport& rExport );
55 SwXMLFontAutoStylePool_Impl::SwXMLFontAutoStylePool_Impl(
56 SwXMLExport& _rExport ) :
57 XMLFontAutoStylePool( _rExport )
59 sal_uInt16 aWhichIds[3] = { RES_CHRATR_FONT, RES_CHRATR_CJK_FONT,
60 RES_CHRATR_CTL_FONT };
62 Reference < XTextDocument > xTextDoc( _rExport.GetModel(), UNO_QUERY );
63 Reference < XText > xText = xTextDoc->getText();
64 Reference<XUnoTunnel> xTextTunnel( xText, UNO_QUERY);
65 ASSERT( xTextTunnel.is(), "missing XUnoTunnel for Cursor" );
66 if( !xTextTunnel.is() )
67 return;
69 SwXText *pText = reinterpret_cast< SwXText *>(
70 sal::static_int_cast< sal_IntPtr >( xTextTunnel->getSomething( SwXText::getUnoTunnelId() )));
71 ASSERT( pText, "SwXText missing" );
72 if( !pText )
73 return;
75 const SfxItemPool& rPool = pText->GetDoc()->GetAttrPool();
76 const SfxPoolItem* pItem;
77 for( sal_uInt16 i=0; i<3; i++ )
79 sal_uInt16 nWhichId = aWhichIds[i];
81 const SvxFontItem& rFont =
82 (const SvxFontItem&)rPool.GetDefaultItem( nWhichId );
83 Add( rFont.GetFamilyName(), rFont.GetStyleName(),
84 static_cast< sal_uInt16 >(rFont.GetFamily()), static_cast< sal_uInt16 >(rFont.GetPitch()),
85 rFont.GetCharSet() );
86 sal_uInt16 nItems = rPool.GetItemCount( nWhichId );
87 for( sal_uInt16 j = 0; j < nItems; ++j )
89 if( 0 != (pItem = rPool.GetItem( nWhichId, j ) ) )
91 const SvxFontItem *pFont =
92 (const SvxFontItem *)pItem;
93 Add( pFont->GetFamilyName(), pFont->GetStyleName(),
94 static_cast< sal_uInt16 >(pFont->GetFamily()), static_cast< sal_uInt16 >(pFont->GetPitch()),
95 pFont->GetCharSet() );
102 XMLFontAutoStylePool* SwXMLExport::CreateFontAutoStylePool()
104 return new SwXMLFontAutoStylePool_Impl( *this );