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 31*cdf0e10cSrcweir #include <fonthdl.hxx> 32*cdf0e10cSrcweir #include <xmloff/xmltoken.hxx> 33*cdf0e10cSrcweir #include <xmloff/xmluconv.hxx> 34*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 35*cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx> 36*cdf0e10cSrcweir #include <tools/fontenum.hxx> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir #include <tools/string.hxx> 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir using ::rtl::OUString; 41*cdf0e10cSrcweir using ::rtl::OUStringBuffer; 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir using namespace ::com::sun::star; 44*cdf0e10cSrcweir using namespace ::xmloff::token; 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir const SvXMLEnumMapEntry* lcl_getFontFamilyGenericMapping() 47*cdf0e10cSrcweir { 48*cdf0e10cSrcweir static SvXMLEnumMapEntry __READONLY_DATA aFontFamilyGenericMapping[] = 49*cdf0e10cSrcweir { 50*cdf0e10cSrcweir { XML_DECORATIVE, FAMILY_DECORATIVE }, 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir { XML_MODERN, FAMILY_MODERN }, 53*cdf0e10cSrcweir { XML_ROMAN, FAMILY_ROMAN }, 54*cdf0e10cSrcweir { XML_SCRIPT, FAMILY_SCRIPT }, 55*cdf0e10cSrcweir { XML_SWISS, FAMILY_SWISS }, 56*cdf0e10cSrcweir { XML_SYSTEM, FAMILY_SYSTEM }, 57*cdf0e10cSrcweir { XML_TOKEN_INVALID, 0 } 58*cdf0e10cSrcweir }; 59*cdf0e10cSrcweir return aFontFamilyGenericMapping; 60*cdf0e10cSrcweir } 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir static SvXMLEnumMapEntry __READONLY_DATA aFontPitchMapping[] = 63*cdf0e10cSrcweir { 64*cdf0e10cSrcweir { XML_FIXED, PITCH_FIXED }, 65*cdf0e10cSrcweir { XML_VARIABLE, PITCH_VARIABLE }, 66*cdf0e10cSrcweir { XML_TOKEN_INVALID, 0 } 67*cdf0e10cSrcweir }; 68*cdf0e10cSrcweir /////////////////////////////////////////////////////////////////////////////// 69*cdf0e10cSrcweir // 70*cdf0e10cSrcweir // class XMLFontFamilyNamePropHdl 71*cdf0e10cSrcweir // 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir XMLFontFamilyNamePropHdl::~XMLFontFamilyNamePropHdl() 74*cdf0e10cSrcweir { 75*cdf0e10cSrcweir // Nothing to do 76*cdf0e10cSrcweir } 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir sal_Bool XMLFontFamilyNamePropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const 79*cdf0e10cSrcweir { 80*cdf0e10cSrcweir sal_Bool bRet = sal_False; 81*cdf0e10cSrcweir String sValue; 82*cdf0e10cSrcweir sal_Int32 nPos = 0; 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir do 85*cdf0e10cSrcweir { 86*cdf0e10cSrcweir sal_Int32 nFirst = nPos; 87*cdf0e10cSrcweir nPos = SvXMLUnitConverter::indexOfComma( rStrImpValue, nPos ); 88*cdf0e10cSrcweir sal_Int32 nLast = (-1 == nPos ? rStrImpValue.getLength() : nPos); 89*cdf0e10cSrcweir if( nLast > 0 ) 90*cdf0e10cSrcweir nLast--; 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir // skip trailing blanks 93*cdf0e10cSrcweir while( sal_Unicode(' ') == rStrImpValue[nLast] && nLast > nFirst ) 94*cdf0e10cSrcweir nLast--; 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir // skip leading blanks 97*cdf0e10cSrcweir while( sal_Unicode(' ') == rStrImpValue[nFirst] && nFirst <= nLast ) 98*cdf0e10cSrcweir nFirst++; 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir // remove quotes 101*cdf0e10cSrcweir sal_Unicode c = rStrImpValue[nFirst]; 102*cdf0e10cSrcweir if( nFirst < nLast && (sal_Unicode('\'') == c || sal_Unicode('\"') == c) && rStrImpValue[nLast] == c ) 103*cdf0e10cSrcweir { 104*cdf0e10cSrcweir nFirst++; 105*cdf0e10cSrcweir nLast--; 106*cdf0e10cSrcweir } 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir if( nFirst <= nLast ) 109*cdf0e10cSrcweir { 110*cdf0e10cSrcweir if( sValue.Len() != 0 ) 111*cdf0e10cSrcweir sValue += sal_Unicode(';'); 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir OUString sTemp = rStrImpValue.copy( nFirst, nLast-nFirst+1 ); 114*cdf0e10cSrcweir sValue += sTemp.getStr(); 115*cdf0e10cSrcweir } 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir if( -1 != nPos ) 118*cdf0e10cSrcweir nPos++; 119*cdf0e10cSrcweir } 120*cdf0e10cSrcweir while( -1 != nPos ); 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir if( sValue.Len() ) 123*cdf0e10cSrcweir { 124*cdf0e10cSrcweir rValue <<= OUString(sValue.GetBuffer()); 125*cdf0e10cSrcweir bRet = sal_True; 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir return bRet; 129*cdf0e10cSrcweir } 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir sal_Bool XMLFontFamilyNamePropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const 132*cdf0e10cSrcweir { 133*cdf0e10cSrcweir sal_Bool bRet = sal_False; 134*cdf0e10cSrcweir OUString aStrFamilyName; 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir if( rValue >>= aStrFamilyName ) 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir OUStringBuffer sValue( aStrFamilyName.getLength() + 2L ); 139*cdf0e10cSrcweir sal_Int32 nPos = 0; 140*cdf0e10cSrcweir do 141*cdf0e10cSrcweir { 142*cdf0e10cSrcweir sal_Int32 nFirst = nPos; 143*cdf0e10cSrcweir nPos = aStrFamilyName.indexOf( sal_Unicode(';'), nPos ); 144*cdf0e10cSrcweir sal_Int32 nLast = (-1 == nPos ? aStrFamilyName.getLength() : nPos); 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir // Set position to the character behind the ';', so we won't 147*cdf0e10cSrcweir // forget this. 148*cdf0e10cSrcweir if( -1L != nPos ) 149*cdf0e10cSrcweir nPos++; 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir // If the property value was empty, we stop now. 152*cdf0e10cSrcweir // If there is a ';' at the first position, the empty name 153*cdf0e10cSrcweir // at the start will be removed. 154*cdf0e10cSrcweir if( 0L == nLast ) 155*cdf0e10cSrcweir continue; 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir // nFirst and nLast now denote the first and last character of 158*cdf0e10cSrcweir // one font name. 159*cdf0e10cSrcweir nLast--; 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir // skip trailing blanks 162*cdf0e10cSrcweir while( sal_Unicode(' ') == aStrFamilyName[nLast] && nLast > nFirst ) 163*cdf0e10cSrcweir nLast--; 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir // skip leading blanks 166*cdf0e10cSrcweir while( sal_Unicode(' ') == aStrFamilyName[nFirst] && nFirst <= nLast ) 167*cdf0e10cSrcweir nFirst++; 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir if( nFirst <= nLast ) 170*cdf0e10cSrcweir { 171*cdf0e10cSrcweir if( sValue.getLength() != 0L ) 172*cdf0e10cSrcweir { 173*cdf0e10cSrcweir sValue.append( sal_Unicode( ',' ) ); 174*cdf0e10cSrcweir sValue.append( sal_Unicode( ' ' )); 175*cdf0e10cSrcweir } 176*cdf0e10cSrcweir sal_Int32 nLen = nLast-nFirst+1; 177*cdf0e10cSrcweir OUString sFamily( aStrFamilyName.copy( nFirst, nLen ) ); 178*cdf0e10cSrcweir sal_Bool bQuote = sal_False; 179*cdf0e10cSrcweir for( sal_Int32 i=0; i < nLen; i++ ) 180*cdf0e10cSrcweir { 181*cdf0e10cSrcweir sal_Unicode c = sFamily[i]; 182*cdf0e10cSrcweir if( sal_Unicode(' ') == c || sal_Unicode(',') == c ) 183*cdf0e10cSrcweir { 184*cdf0e10cSrcweir bQuote = sal_True; 185*cdf0e10cSrcweir break; 186*cdf0e10cSrcweir } 187*cdf0e10cSrcweir } 188*cdf0e10cSrcweir if( bQuote ) 189*cdf0e10cSrcweir sValue.append( sal_Unicode('\'') ); 190*cdf0e10cSrcweir sValue.append( sFamily ); 191*cdf0e10cSrcweir if( bQuote ) 192*cdf0e10cSrcweir sValue.append( sal_Unicode('\'') ); 193*cdf0e10cSrcweir } 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir while( -1L != nPos ); 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir rStrExpValue = sValue.makeStringAndClear(); 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir bRet = sal_True; 200*cdf0e10cSrcweir } 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir return bRet; 203*cdf0e10cSrcweir } 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir /////////////////////////////////////////////////////////////////////////////// 206*cdf0e10cSrcweir // 207*cdf0e10cSrcweir // class XMLFontFamilyPropHdl 208*cdf0e10cSrcweir // 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir XMLFontFamilyPropHdl::~XMLFontFamilyPropHdl() 211*cdf0e10cSrcweir { 212*cdf0e10cSrcweir // Nothing to do 213*cdf0e10cSrcweir } 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir sal_Bool XMLFontFamilyPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const 216*cdf0e10cSrcweir { 217*cdf0e10cSrcweir sal_uInt16 eNewFamily; 218*cdf0e10cSrcweir sal_Bool bRet = SvXMLUnitConverter::convertEnum( eNewFamily, rStrImpValue, lcl_getFontFamilyGenericMapping() ); 219*cdf0e10cSrcweir if( bRet ) 220*cdf0e10cSrcweir rValue <<= (sal_Int16)eNewFamily; 221*cdf0e10cSrcweir 222*cdf0e10cSrcweir return bRet; 223*cdf0e10cSrcweir } 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir sal_Bool XMLFontFamilyPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const 226*cdf0e10cSrcweir { 227*cdf0e10cSrcweir sal_Bool bRet = sal_False; 228*cdf0e10cSrcweir OUStringBuffer aOut; 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir sal_Int16 nFamily = sal_Int16(); 231*cdf0e10cSrcweir if( rValue >>= nFamily ) 232*cdf0e10cSrcweir { 233*cdf0e10cSrcweir FontFamily eFamily = (FontFamily)nFamily; 234*cdf0e10cSrcweir if( eFamily != FAMILY_DONTKNOW ) 235*cdf0e10cSrcweir bRet = SvXMLUnitConverter::convertEnum( aOut, eFamily, lcl_getFontFamilyGenericMapping() ); 236*cdf0e10cSrcweir } 237*cdf0e10cSrcweir 238*cdf0e10cSrcweir rStrExpValue = aOut.makeStringAndClear(); 239*cdf0e10cSrcweir 240*cdf0e10cSrcweir return bRet; 241*cdf0e10cSrcweir } 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir /////////////////////////////////////////////////////////////////////////////// 244*cdf0e10cSrcweir // 245*cdf0e10cSrcweir // class XMLFontEncodingPropHdl 246*cdf0e10cSrcweir // 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir XMLFontEncodingPropHdl::~XMLFontEncodingPropHdl() 249*cdf0e10cSrcweir { 250*cdf0e10cSrcweir // Nothing to do 251*cdf0e10cSrcweir } 252*cdf0e10cSrcweir 253*cdf0e10cSrcweir sal_Bool XMLFontEncodingPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const 254*cdf0e10cSrcweir { 255*cdf0e10cSrcweir sal_Bool bRet = sal_True; 256*cdf0e10cSrcweir 257*cdf0e10cSrcweir if( IsXMLToken( rStrImpValue, XML_X_SYMBOL ) ) 258*cdf0e10cSrcweir rValue <<= (sal_Int16) RTL_TEXTENCODING_SYMBOL; 259*cdf0e10cSrcweir 260*cdf0e10cSrcweir return bRet; 261*cdf0e10cSrcweir } 262*cdf0e10cSrcweir 263*cdf0e10cSrcweir sal_Bool XMLFontEncodingPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const 264*cdf0e10cSrcweir { 265*cdf0e10cSrcweir sal_Bool bRet = sal_False; 266*cdf0e10cSrcweir OUStringBuffer aOut; 267*cdf0e10cSrcweir sal_Int16 nSet = sal_Int16(); 268*cdf0e10cSrcweir 269*cdf0e10cSrcweir if( rValue >>= nSet ) 270*cdf0e10cSrcweir { 271*cdf0e10cSrcweir if( (rtl_TextEncoding)nSet == RTL_TEXTENCODING_SYMBOL ) 272*cdf0e10cSrcweir { 273*cdf0e10cSrcweir aOut.append( GetXMLToken(XML_X_SYMBOL) ); 274*cdf0e10cSrcweir rStrExpValue = aOut.makeStringAndClear(); 275*cdf0e10cSrcweir bRet = sal_True; 276*cdf0e10cSrcweir } 277*cdf0e10cSrcweir } 278*cdf0e10cSrcweir 279*cdf0e10cSrcweir return bRet; 280*cdf0e10cSrcweir } 281*cdf0e10cSrcweir 282*cdf0e10cSrcweir /////////////////////////////////////////////////////////////////////////////// 283*cdf0e10cSrcweir // 284*cdf0e10cSrcweir // class XMLFontPitchPropHdl 285*cdf0e10cSrcweir // 286*cdf0e10cSrcweir 287*cdf0e10cSrcweir XMLFontPitchPropHdl::~XMLFontPitchPropHdl() 288*cdf0e10cSrcweir { 289*cdf0e10cSrcweir // Nothing to do 290*cdf0e10cSrcweir } 291*cdf0e10cSrcweir 292*cdf0e10cSrcweir sal_Bool XMLFontPitchPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const 293*cdf0e10cSrcweir { 294*cdf0e10cSrcweir sal_uInt16 eNewPitch; 295*cdf0e10cSrcweir sal_Bool bRet = SvXMLUnitConverter::convertEnum( eNewPitch, rStrImpValue, aFontPitchMapping ); 296*cdf0e10cSrcweir if( bRet ) 297*cdf0e10cSrcweir rValue <<= (sal_Int16)eNewPitch; 298*cdf0e10cSrcweir 299*cdf0e10cSrcweir return bRet; 300*cdf0e10cSrcweir } 301*cdf0e10cSrcweir 302*cdf0e10cSrcweir sal_Bool XMLFontPitchPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const 303*cdf0e10cSrcweir { 304*cdf0e10cSrcweir sal_Bool bRet = sal_False; 305*cdf0e10cSrcweir sal_Int16 nPitch = sal_Int16(); 306*cdf0e10cSrcweir OUStringBuffer aOut; 307*cdf0e10cSrcweir 308*cdf0e10cSrcweir FontPitch ePitch = PITCH_DONTKNOW; 309*cdf0e10cSrcweir if( rValue >>= nPitch ) 310*cdf0e10cSrcweir ePitch = (FontPitch)nPitch; 311*cdf0e10cSrcweir 312*cdf0e10cSrcweir if( PITCH_DONTKNOW != ePitch ) 313*cdf0e10cSrcweir { 314*cdf0e10cSrcweir bRet = SvXMLUnitConverter::convertEnum( aOut, ePitch, aFontPitchMapping, XML_FIXED ); 315*cdf0e10cSrcweir rStrExpValue = aOut.makeStringAndClear(); 316*cdf0e10cSrcweir } 317*cdf0e10cSrcweir 318*cdf0e10cSrcweir return bRet; 319*cdf0e10cSrcweir } 320