1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_xmloff.hxx" 30 31 32 #include <escphdl.hxx> 33 #include <xmloff/xmltoken.hxx> 34 #include <xmloff/xmluconv.hxx> 35 #include <rtl/ustrbuf.hxx> 36 #include <com/sun/star/uno/Any.hxx> 37 38 using ::rtl::OUString; 39 using ::rtl::OUStringBuffer; 40 41 using namespace ::com::sun::star; 42 using namespace ::xmloff::token; 43 44 // this is a copy of defines in svx/inc/escpitem.hxx 45 #define DFLT_ESC_PROP 58 46 #define DFLT_ESC_AUTO_SUPER 101 47 #define DFLT_ESC_AUTO_SUB -101 48 49 /////////////////////////////////////////////////////////////////////////////// 50 // 51 // class XMLEscapementPropHdl 52 // 53 54 XMLEscapementPropHdl::~XMLEscapementPropHdl() 55 { 56 // nothing to do 57 } 58 59 sal_Bool XMLEscapementPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const 60 { 61 sal_Int16 nVal; 62 63 SvXMLTokenEnumerator aTokens( rStrImpValue ); 64 65 OUString aToken; 66 if( ! aTokens.getNextToken( aToken ) ) 67 return sal_False; 68 69 if( IsXMLToken( aToken, XML_ESCAPEMENT_SUB ) ) 70 { 71 nVal = DFLT_ESC_AUTO_SUB; 72 } 73 else if( IsXMLToken( aToken, XML_ESCAPEMENT_SUPER ) ) 74 { 75 nVal = DFLT_ESC_AUTO_SUPER; 76 } 77 else 78 { 79 sal_Int32 nNewEsc; 80 if( !SvXMLUnitConverter::convertPercent( nNewEsc, aToken ) ) 81 return sal_False; 82 83 nVal = (sal_Int16) nNewEsc; 84 } 85 86 rValue <<= nVal; 87 return sal_True; 88 } 89 90 sal_Bool XMLEscapementPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const 91 { 92 sal_Int32 nValue = 0; 93 OUStringBuffer aOut; 94 95 if( rValue >>= nValue ) 96 { 97 if( nValue == DFLT_ESC_AUTO_SUPER ) 98 { 99 aOut.append( GetXMLToken(XML_ESCAPEMENT_SUPER) ); 100 } 101 else if( nValue == DFLT_ESC_AUTO_SUB ) 102 { 103 aOut.append( GetXMLToken(XML_ESCAPEMENT_SUB) ); 104 } 105 else 106 { 107 SvXMLUnitConverter::convertPercent( aOut, nValue ); 108 } 109 } 110 111 rStrExpValue = aOut.makeStringAndClear(); 112 return sal_True; 113 } 114 115 /////////////////////////////////////////////////////////////////////////////// 116 // 117 // class XMLEscapementHeightPropHdl 118 // 119 120 XMLEscapementHeightPropHdl::~XMLEscapementHeightPropHdl() 121 { 122 // nothing to do 123 } 124 125 sal_Bool XMLEscapementHeightPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const 126 { 127 if( IsXMLToken( rStrImpValue, XML_CASEMAP_SMALL_CAPS ) ) 128 return sal_False; 129 130 SvXMLTokenEnumerator aTokens( rStrImpValue ); 131 132 OUString aToken; 133 if( ! aTokens.getNextToken( aToken ) ) 134 return sal_False; 135 136 sal_Int8 nProp; 137 if( aTokens.getNextToken( aToken ) ) 138 { 139 sal_Int32 nNewProp; 140 if( !SvXMLUnitConverter::convertPercent( nNewProp, aToken ) ) 141 return sal_False; 142 nProp = (sal_Int8)nNewProp; 143 } 144 else 145 { 146 sal_Int32 nEscapementPosition=0; 147 if( SvXMLUnitConverter::convertPercent( nEscapementPosition, aToken ) && nEscapementPosition==0 ) 148 nProp = 100; //if escapement position is zero and no escapement height is given the default height should be 100percent and not something smaller (#i91800#) 149 else 150 nProp = (sal_Int8) DFLT_ESC_PROP; 151 } 152 153 rValue <<= nProp; 154 return sal_True; 155 } 156 157 sal_Bool XMLEscapementHeightPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const 158 { 159 OUStringBuffer aOut( rStrExpValue ); 160 161 sal_Int32 nValue = 0; 162 if( rValue >>= nValue ) 163 { 164 if( rStrExpValue.getLength() ) 165 aOut.append( sal_Unicode(' ')); 166 167 SvXMLUnitConverter::convertPercent( aOut, nValue ); 168 } 169 170 rStrExpValue = aOut.makeStringAndClear(); 171 return rStrExpValue.getLength() != 0; 172 } 173