1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26
27 #include "hintids.hxx"
28 #include <com/sun/star/text/XTextDocument.hpp>
29 #include <xmloff/XMLFontAutoStylePool.hxx>
30 #include <editeng/fontitem.hxx>
31 #include <unotext.hxx>
32 #include <doc.hxx>
33 #include <xmlexp.hxx>
34
35
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::lang;
38 using namespace ::com::sun::star::text;
39
40 class SwXMLFontAutoStylePool_Impl: public XMLFontAutoStylePool
41 {
42 public:
43
44 SwXMLFontAutoStylePool_Impl( SwXMLExport& rExport );
45
46 };
47
SwXMLFontAutoStylePool_Impl(SwXMLExport & _rExport)48 SwXMLFontAutoStylePool_Impl::SwXMLFontAutoStylePool_Impl(
49 SwXMLExport& _rExport ) :
50 XMLFontAutoStylePool( _rExport )
51 {
52 sal_uInt16 aWhichIds[3] = { RES_CHRATR_FONT, RES_CHRATR_CJK_FONT,
53 RES_CHRATR_CTL_FONT };
54
55 Reference < XTextDocument > xTextDoc( _rExport.GetModel(), UNO_QUERY );
56 Reference < XText > xText = xTextDoc->getText();
57 Reference<XUnoTunnel> xTextTunnel( xText, UNO_QUERY);
58 ASSERT( xTextTunnel.is(), "missing XUnoTunnel for Cursor" );
59 if( !xTextTunnel.is() )
60 return;
61
62 SwXText *pText = reinterpret_cast< SwXText *>(
63 sal::static_int_cast< sal_IntPtr >( xTextTunnel->getSomething( SwXText::getUnoTunnelId() )));
64 ASSERT( pText, "SwXText missing" );
65 if( !pText )
66 return;
67
68 const SfxItemPool& rPool = pText->GetDoc()->GetAttrPool();
69 const SfxPoolItem* pItem;
70 for( sal_uInt16 i=0; i<3; i++ )
71 {
72 sal_uInt16 nWhichId = aWhichIds[i];
73
74 const SvxFontItem& rFont =
75 (const SvxFontItem&)rPool.GetDefaultItem( nWhichId );
76 Add( rFont.GetFamilyName(), rFont.GetStyleName(),
77 static_cast< sal_uInt16 >(rFont.GetFamily()), static_cast< sal_uInt16 >(rFont.GetPitch()),
78 rFont.GetCharSet() );
79 sal_uInt32 nItems = rPool.GetItemCount2( nWhichId );
80 for( sal_uInt32 j = 0; j < nItems; ++j )
81 {
82 if( 0 != (pItem = rPool.GetItem2( nWhichId, j ) ) )
83 {
84 const SvxFontItem *pFont =
85 (const SvxFontItem *)pItem;
86 Add( pFont->GetFamilyName(), pFont->GetStyleName(),
87 static_cast< sal_uInt16 >(pFont->GetFamily()), static_cast< sal_uInt16 >(pFont->GetPitch()),
88 pFont->GetCharSet() );
89 }
90 }
91 }
92 }
93
94
CreateFontAutoStylePool()95 XMLFontAutoStylePool* SwXMLExport::CreateFontAutoStylePool()
96 {
97 return new SwXMLFontAutoStylePool_Impl( *this );
98 }
99