1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_xmloff.hxx" 30*cdf0e10cSrcweir #include <tools/debug.hxx> 31*cdf0e10cSrcweir #include <svl/cntnrsrt.hxx> 32*cdf0e10cSrcweir #include <tools/fontenum.hxx> 33*cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx" 34*cdf0e10cSrcweir #include <xmloff/xmltoken.hxx> 35*cdf0e10cSrcweir #include <xmloff/xmluconv.hxx> 36*cdf0e10cSrcweir #include "fonthdl.hxx" 37*cdf0e10cSrcweir #include <xmloff/xmlexp.hxx> 38*cdf0e10cSrcweir #include <xmloff/XMLFontAutoStylePool.hxx> 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir using ::rtl::OUString; 42*cdf0e10cSrcweir using ::rtl::OUStringBuffer; 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 45*cdf0e10cSrcweir using namespace ::xmloff::token; 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir int XMLFontAutoStylePoolNameCmp_Impl( const OUString& r1, 48*cdf0e10cSrcweir const OUString& r2 ) 49*cdf0e10cSrcweir { 50*cdf0e10cSrcweir return (int)r1.compareTo( r2 ); 51*cdf0e10cSrcweir } 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir DECLARE_CONTAINER_SORT_DEL( XMLFontAutoStylePoolNames_Impl, 54*cdf0e10cSrcweir OUString ) 55*cdf0e10cSrcweir IMPL_CONTAINER_SORT( XMLFontAutoStylePoolNames_Impl, 56*cdf0e10cSrcweir OUString, 57*cdf0e10cSrcweir XMLFontAutoStylePoolNameCmp_Impl ) 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir class XMLFontAutoStylePoolEntry_Impl 60*cdf0e10cSrcweir { 61*cdf0e10cSrcweir OUString sName; 62*cdf0e10cSrcweir OUString sFamilyName; 63*cdf0e10cSrcweir OUString sStyleName; 64*cdf0e10cSrcweir sal_Int16 nFamily; 65*cdf0e10cSrcweir sal_Int16 nPitch; 66*cdf0e10cSrcweir rtl_TextEncoding eEnc; 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir public: 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir inline XMLFontAutoStylePoolEntry_Impl( 71*cdf0e10cSrcweir const ::rtl::OUString& rName, 72*cdf0e10cSrcweir const ::rtl::OUString& rFamilyName, 73*cdf0e10cSrcweir const ::rtl::OUString& rStyleName, 74*cdf0e10cSrcweir sal_Int16 nFamily, 75*cdf0e10cSrcweir sal_Int16 nPitch, 76*cdf0e10cSrcweir rtl_TextEncoding eEnc ); 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir inline XMLFontAutoStylePoolEntry_Impl( 79*cdf0e10cSrcweir const ::rtl::OUString& rFamilyName, 80*cdf0e10cSrcweir const ::rtl::OUString& rStyleName, 81*cdf0e10cSrcweir sal_Int16 nFamily, 82*cdf0e10cSrcweir sal_Int16 nPitch, 83*cdf0e10cSrcweir rtl_TextEncoding eEnc ); 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir const OUString& GetName() const { return sName; } 86*cdf0e10cSrcweir const OUString& GetFamilyName() const { return sFamilyName; } 87*cdf0e10cSrcweir const OUString& GetStyleName() const { return sStyleName; } 88*cdf0e10cSrcweir sal_Int16 GetFamily() const { return nFamily; } 89*cdf0e10cSrcweir sal_Int16 GetPitch() const { return nPitch; } 90*cdf0e10cSrcweir rtl_TextEncoding GetEncoding() const { return eEnc; } 91*cdf0e10cSrcweir }; 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir inline XMLFontAutoStylePoolEntry_Impl::XMLFontAutoStylePoolEntry_Impl( 95*cdf0e10cSrcweir const ::rtl::OUString& rName, 96*cdf0e10cSrcweir const ::rtl::OUString& rFamilyName, 97*cdf0e10cSrcweir const ::rtl::OUString& rStyleName, 98*cdf0e10cSrcweir sal_Int16 nFam, 99*cdf0e10cSrcweir sal_Int16 nP, 100*cdf0e10cSrcweir rtl_TextEncoding eE ) : 101*cdf0e10cSrcweir sName( rName ), 102*cdf0e10cSrcweir sFamilyName( rFamilyName ), 103*cdf0e10cSrcweir sStyleName( rStyleName ), 104*cdf0e10cSrcweir nFamily( nFam ), 105*cdf0e10cSrcweir nPitch( nP ), 106*cdf0e10cSrcweir eEnc( eE ) 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir inline XMLFontAutoStylePoolEntry_Impl::XMLFontAutoStylePoolEntry_Impl( 111*cdf0e10cSrcweir const ::rtl::OUString& rFamilyName, 112*cdf0e10cSrcweir const ::rtl::OUString& rStyleName, 113*cdf0e10cSrcweir sal_Int16 nFam, 114*cdf0e10cSrcweir sal_Int16 nP, 115*cdf0e10cSrcweir rtl_TextEncoding eE ) : 116*cdf0e10cSrcweir sFamilyName( rFamilyName ), 117*cdf0e10cSrcweir sStyleName( rStyleName ), 118*cdf0e10cSrcweir nFamily( nFam ), 119*cdf0e10cSrcweir nPitch( nP ), 120*cdf0e10cSrcweir eEnc( eE ) 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir } 123*cdf0e10cSrcweir int XMLFontAutoStylePoolEntryCmp_Impl( 124*cdf0e10cSrcweir const XMLFontAutoStylePoolEntry_Impl& r1, 125*cdf0e10cSrcweir const XMLFontAutoStylePoolEntry_Impl& r2 ) 126*cdf0e10cSrcweir { 127*cdf0e10cSrcweir sal_Int8 nEnc1(r1.GetEncoding() != RTL_TEXTENCODING_SYMBOL); 128*cdf0e10cSrcweir sal_Int8 nEnc2(r2.GetEncoding() != RTL_TEXTENCODING_SYMBOL); 129*cdf0e10cSrcweir if( nEnc1 != nEnc2 ) 130*cdf0e10cSrcweir return nEnc1 - nEnc2; 131*cdf0e10cSrcweir else if( r1.GetPitch() != r2.GetPitch() ) 132*cdf0e10cSrcweir return (int)r1.GetPitch() - (int)r2.GetPitch(); 133*cdf0e10cSrcweir else if( r1.GetFamily() != r2.GetFamily() ) 134*cdf0e10cSrcweir return (int)r1.GetFamily() - (int)r2.GetFamily(); 135*cdf0e10cSrcweir else 136*cdf0e10cSrcweir { 137*cdf0e10cSrcweir sal_Int32 nCmp = r1.GetFamilyName().compareTo( r2.GetFamilyName() ); 138*cdf0e10cSrcweir if( 0 == nCmp ) 139*cdf0e10cSrcweir return (int)r1.GetStyleName().compareTo( r2.GetStyleName() ); 140*cdf0e10cSrcweir else 141*cdf0e10cSrcweir return (int)nCmp; 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir typedef XMLFontAutoStylePoolEntry_Impl *XMLFontAutoStylePoolEntryPtr; 146*cdf0e10cSrcweir DECLARE_CONTAINER_SORT_DEL( XMLFontAutoStylePool_Impl, 147*cdf0e10cSrcweir XMLFontAutoStylePoolEntry_Impl ) 148*cdf0e10cSrcweir IMPL_CONTAINER_SORT( XMLFontAutoStylePool_Impl, 149*cdf0e10cSrcweir XMLFontAutoStylePoolEntry_Impl, 150*cdf0e10cSrcweir XMLFontAutoStylePoolEntryCmp_Impl ) 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir XMLFontAutoStylePool::XMLFontAutoStylePool( SvXMLExport& rExp ) : 153*cdf0e10cSrcweir rExport( rExp ), 154*cdf0e10cSrcweir pPool( new XMLFontAutoStylePool_Impl( 5, 5 ) ), 155*cdf0e10cSrcweir pNames( new XMLFontAutoStylePoolNames_Impl( 5, 5 ) ) 156*cdf0e10cSrcweir { 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir XMLFontAutoStylePool::~XMLFontAutoStylePool() 160*cdf0e10cSrcweir { 161*cdf0e10cSrcweir delete pPool; 162*cdf0e10cSrcweir delete pNames; 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir OUString XMLFontAutoStylePool::Add( 166*cdf0e10cSrcweir const OUString& rFamilyName, 167*cdf0e10cSrcweir const OUString& rStyleName, 168*cdf0e10cSrcweir sal_Int16 nFamily, 169*cdf0e10cSrcweir sal_Int16 nPitch, 170*cdf0e10cSrcweir rtl_TextEncoding eEnc ) 171*cdf0e10cSrcweir { 172*cdf0e10cSrcweir OUString sPoolName; 173*cdf0e10cSrcweir XMLFontAutoStylePoolEntry_Impl aTmp( rFamilyName, rStyleName, nFamily, 174*cdf0e10cSrcweir nPitch, eEnc ); 175*cdf0e10cSrcweir sal_uLong nPos; 176*cdf0e10cSrcweir if( pPool->Seek_Entry( &aTmp, &nPos ) ) 177*cdf0e10cSrcweir { 178*cdf0e10cSrcweir sPoolName = pPool->GetObject( nPos )->GetName(); 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir else 181*cdf0e10cSrcweir { 182*cdf0e10cSrcweir OUString sName; 183*cdf0e10cSrcweir sal_Int32 nLen = rFamilyName.indexOf( sal_Unicode(';'), 0 ); 184*cdf0e10cSrcweir if( -1 == nLen ) 185*cdf0e10cSrcweir { 186*cdf0e10cSrcweir sName = rFamilyName; 187*cdf0e10cSrcweir } 188*cdf0e10cSrcweir else if( nLen > 0 ) 189*cdf0e10cSrcweir { 190*cdf0e10cSrcweir sName = rFamilyName.copy( 0, nLen ); 191*cdf0e10cSrcweir sName.trim(); 192*cdf0e10cSrcweir } 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir if( !sName.getLength() ) 195*cdf0e10cSrcweir sName = OUString::valueOf( sal_Unicode( 'F' ) ); 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir if( pNames->Seek_Entry( &sName, 0 ) ) 198*cdf0e10cSrcweir { 199*cdf0e10cSrcweir sal_Int32 nCount = 1; 200*cdf0e10cSrcweir OUString sPrefix( sName ); 201*cdf0e10cSrcweir sName += OUString::valueOf( nCount ); 202*cdf0e10cSrcweir while( pNames->Seek_Entry( &sName, 0 ) ) 203*cdf0e10cSrcweir { 204*cdf0e10cSrcweir sName = sPrefix; 205*cdf0e10cSrcweir sName += OUString::valueOf( ++nCount ); 206*cdf0e10cSrcweir } 207*cdf0e10cSrcweir } 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir XMLFontAutoStylePoolEntry_Impl *pEntry = 210*cdf0e10cSrcweir new XMLFontAutoStylePoolEntry_Impl( sName, rFamilyName, rStyleName, 211*cdf0e10cSrcweir nFamily, nPitch, eEnc ); 212*cdf0e10cSrcweir pPool->Insert( pEntry ); 213*cdf0e10cSrcweir pNames->Insert( new OUString( sName ) ); 214*cdf0e10cSrcweir } 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir return sPoolName; 217*cdf0e10cSrcweir } 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir ::rtl::OUString XMLFontAutoStylePool::Find( 220*cdf0e10cSrcweir const OUString& rFamilyName, 221*cdf0e10cSrcweir const OUString& rStyleName, 222*cdf0e10cSrcweir sal_Int16 nFamily, 223*cdf0e10cSrcweir sal_Int16 nPitch, 224*cdf0e10cSrcweir rtl_TextEncoding eEnc ) const 225*cdf0e10cSrcweir { 226*cdf0e10cSrcweir OUString sName; 227*cdf0e10cSrcweir XMLFontAutoStylePoolEntry_Impl aTmp( rFamilyName, rStyleName, nFamily, 228*cdf0e10cSrcweir nPitch, eEnc ); 229*cdf0e10cSrcweir sal_uLong nPos; 230*cdf0e10cSrcweir if( pPool->Seek_Entry( &aTmp, &nPos ) ) 231*cdf0e10cSrcweir { 232*cdf0e10cSrcweir sName = pPool->GetObject( nPos )->GetName(); 233*cdf0e10cSrcweir } 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir return sName; 236*cdf0e10cSrcweir } 237*cdf0e10cSrcweir 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir void XMLFontAutoStylePool::exportXML() 240*cdf0e10cSrcweir { 241*cdf0e10cSrcweir SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_OFFICE, 242*cdf0e10cSrcweir XML_FONT_FACE_DECLS, 243*cdf0e10cSrcweir sal_True, sal_True ); 244*cdf0e10cSrcweir Any aAny; 245*cdf0e10cSrcweir OUString sTmp; 246*cdf0e10cSrcweir XMLFontFamilyNamePropHdl aFamilyNameHdl; 247*cdf0e10cSrcweir XMLFontFamilyPropHdl aFamilyHdl; 248*cdf0e10cSrcweir XMLFontPitchPropHdl aPitchHdl; 249*cdf0e10cSrcweir XMLFontEncodingPropHdl aEncHdl; 250*cdf0e10cSrcweir const SvXMLUnitConverter& rUnitConv = GetExport().GetMM100UnitConverter(); 251*cdf0e10cSrcweir 252*cdf0e10cSrcweir sal_uInt32 nCount = pPool->Count(); 253*cdf0e10cSrcweir for( sal_uInt32 i=0; i<nCount; i++ ) 254*cdf0e10cSrcweir { 255*cdf0e10cSrcweir const XMLFontAutoStylePoolEntry_Impl *pEntry = pPool->GetObject( i ); 256*cdf0e10cSrcweir 257*cdf0e10cSrcweir GetExport().AddAttribute( XML_NAMESPACE_STYLE, 258*cdf0e10cSrcweir XML_NAME, pEntry->GetName() ); 259*cdf0e10cSrcweir 260*cdf0e10cSrcweir aAny <<= pEntry->GetFamilyName(); 261*cdf0e10cSrcweir if( aFamilyNameHdl.exportXML( sTmp, aAny, rUnitConv ) ) 262*cdf0e10cSrcweir GetExport().AddAttribute( XML_NAMESPACE_SVG, 263*cdf0e10cSrcweir XML_FONT_FAMILY, sTmp ); 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir const OUString& rStyleName = pEntry->GetStyleName(); 266*cdf0e10cSrcweir if( rStyleName.getLength() ) 267*cdf0e10cSrcweir GetExport().AddAttribute( XML_NAMESPACE_STYLE, 268*cdf0e10cSrcweir XML_FONT_ADORNMENTS, 269*cdf0e10cSrcweir rStyleName ); 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir aAny <<= (sal_Int16)pEntry->GetFamily(); 272*cdf0e10cSrcweir if( aFamilyHdl.exportXML( sTmp, aAny, rUnitConv ) ) 273*cdf0e10cSrcweir GetExport().AddAttribute( XML_NAMESPACE_STYLE, 274*cdf0e10cSrcweir XML_FONT_FAMILY_GENERIC, sTmp ); 275*cdf0e10cSrcweir 276*cdf0e10cSrcweir aAny <<= (sal_Int16)pEntry->GetPitch(); 277*cdf0e10cSrcweir if( aPitchHdl.exportXML( sTmp, aAny, rUnitConv ) ) 278*cdf0e10cSrcweir GetExport().AddAttribute( XML_NAMESPACE_STYLE, 279*cdf0e10cSrcweir XML_FONT_PITCH, sTmp ); 280*cdf0e10cSrcweir 281*cdf0e10cSrcweir aAny <<= (sal_Int16)pEntry->GetEncoding(); 282*cdf0e10cSrcweir if( aEncHdl.exportXML( sTmp, aAny, rUnitConv ) ) 283*cdf0e10cSrcweir GetExport().AddAttribute( XML_NAMESPACE_STYLE, 284*cdf0e10cSrcweir XML_FONT_CHARSET, sTmp ); 285*cdf0e10cSrcweir 286*cdf0e10cSrcweir SvXMLElementExport aElement( GetExport(), XML_NAMESPACE_STYLE, 287*cdf0e10cSrcweir XML_FONT_FACE, 288*cdf0e10cSrcweir sal_True, sal_True ); 289*cdf0e10cSrcweir } 290*cdf0e10cSrcweir } 291*cdf0e10cSrcweir 292*cdf0e10cSrcweir 293