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_xmloff.hxx" 26 27 28 #include <chrhghdl.hxx> 29 #include <xmloff/xmluconv.hxx> 30 #include "xmlehelp.hxx" 31 #include <rtl/ustrbuf.hxx> 32 #include <com/sun/star/uno/Any.hxx> 33 34 using ::rtl::OUString; 35 using ::rtl::OUStringBuffer; 36 37 using namespace ::com::sun::star; 38 39 // this is a copy of defines in svx/inc/escpitem.hxx 40 #define DFLT_ESC_PROP 58 41 #define DFLT_ESC_AUTO_SUPER 101 42 #define DFLT_ESC_AUTO_SUB -101 43 44 /////////////////////////////////////////////////////////////////////////////// 45 // 46 // class XMLEscapementPropHdl 47 // 48 49 XMLCharHeightHdl::~XMLCharHeightHdl() 50 { 51 // nothing to do 52 } 53 54 sal_Bool XMLCharHeightHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const 55 { 56 double fSize; 57 58 if( rStrImpValue.indexOf( sal_Unicode('%') ) == -1 ) 59 { 60 MapUnit eSrcUnit = SvXMLExportHelper::GetUnitFromString( rStrImpValue, MAP_POINT ); 61 if( SvXMLUnitConverter::convertDouble( fSize, rStrImpValue, eSrcUnit, MAP_POINT )) 62 { 63 rValue <<= (float)fSize; 64 return sal_True; 65 } 66 } 67 68 return sal_False; 69 } 70 71 sal_Bool XMLCharHeightHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const 72 { 73 OUStringBuffer aOut; 74 75 float fSize = 0; 76 if( rValue >>= fSize ) 77 { 78 SvXMLUnitConverter::convertDouble( aOut, (double)fSize, sal_True, MAP_POINT, MAP_POINT ); 79 aOut.append( sal_Unicode('p')); 80 aOut.append( sal_Unicode('t')); 81 } 82 83 rStrExpValue = aOut.makeStringAndClear(); 84 return rStrExpValue.getLength() != 0; 85 } 86 87 /////////////////////////////////////////////////////////////////////////////// 88 // 89 // class XMLEscapementHeightPropHdl 90 // 91 92 XMLCharHeightPropHdl::~XMLCharHeightPropHdl() 93 { 94 // nothing to do 95 } 96 97 sal_Bool XMLCharHeightPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const 98 { 99 sal_Int32 nPrc = 100; 100 101 if( rStrImpValue.indexOf( sal_Unicode('%') ) != -1 ) 102 { 103 if( SvXMLUnitConverter::convertPercent( nPrc, rStrImpValue ) ) 104 { 105 rValue <<= (sal_Int16)nPrc; 106 return sal_True; 107 } 108 } 109 110 return sal_False; 111 } 112 113 sal_Bool XMLCharHeightPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const 114 { 115 OUStringBuffer aOut( rStrExpValue ); 116 117 sal_Int16 nValue = sal_Int16(); 118 if( rValue >>= nValue ) 119 { 120 SvXMLUnitConverter::convertPercent( aOut, nValue ); 121 } 122 123 rStrExpValue = aOut.makeStringAndClear(); 124 return rStrExpValue.getLength() != 0; 125 } 126 127 /////////////////////////////////////////////////////////////////////////////// 128 // 129 // class XMLEscapementPropHdl 130 // 131 132 XMLCharHeightDiffHdl::~XMLCharHeightDiffHdl() 133 { 134 // nothing to do 135 } 136 137 sal_Bool XMLCharHeightDiffHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const 138 { 139 sal_Int32 nRel = 0; 140 141 if( SvXMLUnitConverter::convertMeasure( nRel, rStrImpValue, MAP_POINT ) ) 142 { 143 rValue <<= (float)nRel; 144 return sal_True; 145 } 146 147 return sal_False; 148 } 149 150 sal_Bool XMLCharHeightDiffHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const 151 { 152 OUStringBuffer aOut; 153 154 float nRel = 0; 155 if( (rValue >>= nRel) && (nRel != 0) ) 156 { 157 SvXMLUnitConverter::convertMeasure( aOut, (sal_Int32)nRel, MAP_POINT, MAP_POINT ); 158 rStrExpValue = aOut.makeStringAndClear(); 159 } 160 161 return rStrExpValue.getLength() != 0; 162 } 163 164