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: XMLFontAutoStylePool.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_xmloff.hxx"
33 #include <tools/debug.hxx>
34 #include <svtools/cntnrsrt.hxx>
35 #include <vcl/vclenum.hxx>
36 #include "xmlnmspe.hxx"
37 #include <xmloff/xmltoken.hxx>
38 #include <xmloff/xmluconv.hxx>
39 #ifndef _XMLOFF_PROPERTYHANDLER_FONTTYPES_HXX
40 #include "fonthdl.hxx"
42 #include <xmloff/xmlexp.hxx>
43 #include <xmloff/XMLFontAutoStylePool.hxx>
45 using ::rtl::OUString
;
46 using ::rtl::OUStringBuffer
;
48 using namespace ::com::sun::star::uno
;
49 using namespace ::xmloff::token
;
51 int XMLFontAutoStylePoolNameCmp_Impl( const OUString
& r1
,
54 return (int)r1
.compareTo( r2
);
57 DECLARE_CONTAINER_SORT_DEL( XMLFontAutoStylePoolNames_Impl
,
59 IMPL_CONTAINER_SORT( XMLFontAutoStylePoolNames_Impl
,
61 XMLFontAutoStylePoolNameCmp_Impl
)
63 class XMLFontAutoStylePoolEntry_Impl
70 rtl_TextEncoding eEnc
;
74 inline XMLFontAutoStylePoolEntry_Impl(
75 const ::rtl::OUString
& rName
,
76 const ::rtl::OUString
& rFamilyName
,
77 const ::rtl::OUString
& rStyleName
,
80 rtl_TextEncoding eEnc
);
82 inline XMLFontAutoStylePoolEntry_Impl(
83 const ::rtl::OUString
& rFamilyName
,
84 const ::rtl::OUString
& rStyleName
,
87 rtl_TextEncoding eEnc
);
89 const OUString
& GetName() const { return sName
; }
90 const OUString
& GetFamilyName() const { return sFamilyName
; }
91 const OUString
& GetStyleName() const { return sStyleName
; }
92 sal_Int16
GetFamily() const { return nFamily
; }
93 sal_Int16
GetPitch() const { return nPitch
; }
94 rtl_TextEncoding
GetEncoding() const { return eEnc
; }
98 inline XMLFontAutoStylePoolEntry_Impl::XMLFontAutoStylePoolEntry_Impl(
99 const ::rtl::OUString
& rName
,
100 const ::rtl::OUString
& rFamilyName
,
101 const ::rtl::OUString
& rStyleName
,
104 rtl_TextEncoding eE
) :
106 sFamilyName( rFamilyName
),
107 sStyleName( rStyleName
),
114 inline XMLFontAutoStylePoolEntry_Impl::XMLFontAutoStylePoolEntry_Impl(
115 const ::rtl::OUString
& rFamilyName
,
116 const ::rtl::OUString
& rStyleName
,
119 rtl_TextEncoding eE
) :
120 sFamilyName( rFamilyName
),
121 sStyleName( rStyleName
),
127 int XMLFontAutoStylePoolEntryCmp_Impl(
128 const XMLFontAutoStylePoolEntry_Impl
& r1
,
129 const XMLFontAutoStylePoolEntry_Impl
& r2
)
131 sal_Int8
nEnc1(r1
.GetEncoding() != RTL_TEXTENCODING_SYMBOL
);
132 sal_Int8
nEnc2(r2
.GetEncoding() != RTL_TEXTENCODING_SYMBOL
);
134 return nEnc1
- nEnc2
;
135 else if( r1
.GetPitch() != r2
.GetPitch() )
136 return (int)r1
.GetPitch() - (int)r2
.GetPitch();
137 else if( r1
.GetFamily() != r2
.GetFamily() )
138 return (int)r1
.GetFamily() - (int)r2
.GetFamily();
141 sal_Int32 nCmp
= r1
.GetFamilyName().compareTo( r2
.GetFamilyName() );
143 return (int)r1
.GetStyleName().compareTo( r2
.GetStyleName() );
149 typedef XMLFontAutoStylePoolEntry_Impl
*XMLFontAutoStylePoolEntryPtr
;
150 DECLARE_CONTAINER_SORT_DEL( XMLFontAutoStylePool_Impl
,
151 XMLFontAutoStylePoolEntry_Impl
)
152 IMPL_CONTAINER_SORT( XMLFontAutoStylePool_Impl
,
153 XMLFontAutoStylePoolEntry_Impl
,
154 XMLFontAutoStylePoolEntryCmp_Impl
)
156 XMLFontAutoStylePool::XMLFontAutoStylePool( SvXMLExport
& rExp
) :
158 pPool( new XMLFontAutoStylePool_Impl( 5, 5 ) ),
159 pNames( new XMLFontAutoStylePoolNames_Impl( 5, 5 ) )
163 XMLFontAutoStylePool::~XMLFontAutoStylePool()
169 OUString
XMLFontAutoStylePool::Add(
170 const OUString
& rFamilyName
,
171 const OUString
& rStyleName
,
174 rtl_TextEncoding eEnc
)
177 XMLFontAutoStylePoolEntry_Impl
aTmp( rFamilyName
, rStyleName
, nFamily
,
180 if( pPool
->Seek_Entry( &aTmp
, &nPos
) )
182 sPoolName
= pPool
->GetObject( nPos
)->GetName();
187 sal_Int32 nLen
= rFamilyName
.indexOf( sal_Unicode(';'), 0 );
194 sName
= rFamilyName
.copy( 0, nLen
);
198 if( !sName
.getLength() )
199 sName
= OUString::valueOf( sal_Unicode( 'F' ) );
201 if( pNames
->Seek_Entry( &sName
, 0 ) )
203 sal_Int32 nCount
= 1;
204 OUString
sPrefix( sName
);
205 sName
+= OUString::valueOf( nCount
);
206 while( pNames
->Seek_Entry( &sName
, 0 ) )
209 sName
+= OUString::valueOf( ++nCount
);
213 XMLFontAutoStylePoolEntry_Impl
*pEntry
=
214 new XMLFontAutoStylePoolEntry_Impl( sName
, rFamilyName
, rStyleName
,
215 nFamily
, nPitch
, eEnc
);
216 pPool
->Insert( pEntry
);
217 pNames
->Insert( new OUString( sName
) );
223 ::rtl::OUString
XMLFontAutoStylePool::Find(
224 const OUString
& rFamilyName
,
225 const OUString
& rStyleName
,
228 rtl_TextEncoding eEnc
) const
231 XMLFontAutoStylePoolEntry_Impl
aTmp( rFamilyName
, rStyleName
, nFamily
,
234 if( pPool
->Seek_Entry( &aTmp
, &nPos
) )
236 sName
= pPool
->GetObject( nPos
)->GetName();
243 void XMLFontAutoStylePool::exportXML()
245 SvXMLElementExport
aElem( GetExport(), XML_NAMESPACE_OFFICE
,
247 sal_True
, sal_True
);
250 XMLFontFamilyNamePropHdl aFamilyNameHdl
;
251 XMLFontFamilyPropHdl aFamilyHdl
;
252 XMLFontPitchPropHdl aPitchHdl
;
253 XMLFontEncodingPropHdl aEncHdl
;
254 const SvXMLUnitConverter
& rUnitConv
= GetExport().GetMM100UnitConverter();
256 sal_uInt32 nCount
= pPool
->Count();
257 for( sal_uInt32 i
=0; i
<nCount
; i
++ )
259 const XMLFontAutoStylePoolEntry_Impl
*pEntry
= pPool
->GetObject( i
);
261 GetExport().AddAttribute( XML_NAMESPACE_STYLE
,
262 XML_NAME
, pEntry
->GetName() );
264 aAny
<<= pEntry
->GetFamilyName();
265 if( aFamilyNameHdl
.exportXML( sTmp
, aAny
, rUnitConv
) )
266 GetExport().AddAttribute( XML_NAMESPACE_SVG
,
267 XML_FONT_FAMILY
, sTmp
);
269 const OUString
& rStyleName
= pEntry
->GetStyleName();
270 if( rStyleName
.getLength() )
271 GetExport().AddAttribute( XML_NAMESPACE_STYLE
,
275 aAny
<<= (sal_Int16
)pEntry
->GetFamily();
276 if( aFamilyHdl
.exportXML( sTmp
, aAny
, rUnitConv
) )
277 GetExport().AddAttribute( XML_NAMESPACE_STYLE
,
278 XML_FONT_FAMILY_GENERIC
, sTmp
);
280 aAny
<<= (sal_Int16
)pEntry
->GetPitch();
281 if( aPitchHdl
.exportXML( sTmp
, aAny
, rUnitConv
) )
282 GetExport().AddAttribute( XML_NAMESPACE_STYLE
,
283 XML_FONT_PITCH
, sTmp
);
285 aAny
<<= (sal_Int16
)pEntry
->GetEncoding();
286 if( aEncHdl
.exportXML( sTmp
, aAny
, rUnitConv
) )
287 GetExport().AddAttribute( XML_NAMESPACE_STYLE
,
288 XML_FONT_CHARSET
, sTmp
);
290 SvXMLElementExport
aElement( GetExport(), XML_NAMESPACE_STYLE
,
292 sal_True
, sal_True
);