xref: /aoo41x/main/xmloff/source/style/chrhghdl.cxx (revision 63bba73c)
1*63bba73cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*63bba73cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*63bba73cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*63bba73cSAndrew Rist  * distributed with this work for additional information
6*63bba73cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*63bba73cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*63bba73cSAndrew Rist  * "License"); you may not use this file except in compliance
9*63bba73cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*63bba73cSAndrew Rist  *
11*63bba73cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*63bba73cSAndrew Rist  *
13*63bba73cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*63bba73cSAndrew Rist  * software distributed under the License is distributed on an
15*63bba73cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*63bba73cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*63bba73cSAndrew Rist  * specific language governing permissions and limitations
18*63bba73cSAndrew Rist  * under the License.
19*63bba73cSAndrew Rist  *
20*63bba73cSAndrew Rist  *************************************************************/
21*63bba73cSAndrew Rist 
22*63bba73cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <chrhghdl.hxx>
29cdf0e10cSrcweir #include <xmloff/xmluconv.hxx>
30cdf0e10cSrcweir #include "xmlehelp.hxx"
31cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
32cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir using ::rtl::OUString;
35cdf0e10cSrcweir using ::rtl::OUStringBuffer;
36cdf0e10cSrcweir 
37cdf0e10cSrcweir using namespace ::com::sun::star;
38cdf0e10cSrcweir 
39cdf0e10cSrcweir // this is a copy of defines in svx/inc/escpitem.hxx
40cdf0e10cSrcweir #define DFLT_ESC_PROP	 58
41cdf0e10cSrcweir #define DFLT_ESC_AUTO_SUPER	101
42cdf0e10cSrcweir #define DFLT_ESC_AUTO_SUB  -101
43cdf0e10cSrcweir 
44cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////////
45cdf0e10cSrcweir //
46cdf0e10cSrcweir // class XMLEscapementPropHdl
47cdf0e10cSrcweir //
48cdf0e10cSrcweir 
~XMLCharHeightHdl()49cdf0e10cSrcweir XMLCharHeightHdl::~XMLCharHeightHdl()
50cdf0e10cSrcweir {
51cdf0e10cSrcweir 	// nothing to do
52cdf0e10cSrcweir }
53cdf0e10cSrcweir 
importXML(const OUString & rStrImpValue,uno::Any & rValue,const SvXMLUnitConverter &) const54cdf0e10cSrcweir sal_Bool XMLCharHeightHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
55cdf0e10cSrcweir {
56cdf0e10cSrcweir     double fSize;
57cdf0e10cSrcweir 
58cdf0e10cSrcweir 	if( rStrImpValue.indexOf( sal_Unicode('%') ) == -1 )
59cdf0e10cSrcweir 	{
60cdf0e10cSrcweir 		MapUnit eSrcUnit = SvXMLExportHelper::GetUnitFromString( rStrImpValue, MAP_POINT );
61cdf0e10cSrcweir         if( SvXMLUnitConverter::convertDouble( fSize, rStrImpValue, eSrcUnit, MAP_POINT ))
62cdf0e10cSrcweir 		{
63cdf0e10cSrcweir 			rValue <<= (float)fSize;
64cdf0e10cSrcweir 			return sal_True;
65cdf0e10cSrcweir 		}
66cdf0e10cSrcweir 	}
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 	return sal_False;
69cdf0e10cSrcweir }
70cdf0e10cSrcweir 
exportXML(OUString & rStrExpValue,const uno::Any & rValue,const SvXMLUnitConverter &) const71cdf0e10cSrcweir sal_Bool XMLCharHeightHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
72cdf0e10cSrcweir {
73cdf0e10cSrcweir 	OUStringBuffer aOut;
74cdf0e10cSrcweir 
75cdf0e10cSrcweir 	float fSize = 0;
76cdf0e10cSrcweir 	if( rValue >>= fSize )
77cdf0e10cSrcweir 	{
78cdf0e10cSrcweir         SvXMLUnitConverter::convertDouble( aOut, (double)fSize, sal_True, MAP_POINT, MAP_POINT );
79cdf0e10cSrcweir         aOut.append( sal_Unicode('p'));
80cdf0e10cSrcweir         aOut.append( sal_Unicode('t'));
81cdf0e10cSrcweir 	}
82cdf0e10cSrcweir 
83cdf0e10cSrcweir 	rStrExpValue = aOut.makeStringAndClear();
84cdf0e10cSrcweir 	return rStrExpValue.getLength() != 0;
85cdf0e10cSrcweir }
86cdf0e10cSrcweir 
87cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////////
88cdf0e10cSrcweir //
89cdf0e10cSrcweir // class XMLEscapementHeightPropHdl
90cdf0e10cSrcweir //
91cdf0e10cSrcweir 
~XMLCharHeightPropHdl()92cdf0e10cSrcweir XMLCharHeightPropHdl::~XMLCharHeightPropHdl()
93cdf0e10cSrcweir {
94cdf0e10cSrcweir 	// nothing to do
95cdf0e10cSrcweir }
96cdf0e10cSrcweir 
importXML(const OUString & rStrImpValue,uno::Any & rValue,const SvXMLUnitConverter &) const97cdf0e10cSrcweir sal_Bool XMLCharHeightPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
98cdf0e10cSrcweir {
99cdf0e10cSrcweir 	sal_Int32 nPrc = 100;
100cdf0e10cSrcweir 
101cdf0e10cSrcweir 	if( rStrImpValue.indexOf( sal_Unicode('%') ) != -1 )
102cdf0e10cSrcweir 	{
103cdf0e10cSrcweir 		if( SvXMLUnitConverter::convertPercent( nPrc, rStrImpValue ) )
104cdf0e10cSrcweir 		{
105cdf0e10cSrcweir 			rValue <<= (sal_Int16)nPrc;
106cdf0e10cSrcweir 			return sal_True;
107cdf0e10cSrcweir 		}
108cdf0e10cSrcweir 	}
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 	return sal_False;
111cdf0e10cSrcweir }
112cdf0e10cSrcweir 
exportXML(OUString & rStrExpValue,const uno::Any & rValue,const SvXMLUnitConverter &) const113cdf0e10cSrcweir sal_Bool XMLCharHeightPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
114cdf0e10cSrcweir {
115cdf0e10cSrcweir 	OUStringBuffer aOut( rStrExpValue );
116cdf0e10cSrcweir 
117cdf0e10cSrcweir 	sal_Int16 nValue = sal_Int16();
118cdf0e10cSrcweir 	if( rValue >>= nValue )
119cdf0e10cSrcweir 	{
120cdf0e10cSrcweir 		SvXMLUnitConverter::convertPercent( aOut, nValue );
121cdf0e10cSrcweir 	}
122cdf0e10cSrcweir 
123cdf0e10cSrcweir 	rStrExpValue = aOut.makeStringAndClear();
124cdf0e10cSrcweir 	return rStrExpValue.getLength() != 0;
125cdf0e10cSrcweir }
126cdf0e10cSrcweir 
127cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////////
128cdf0e10cSrcweir //
129cdf0e10cSrcweir // class XMLEscapementPropHdl
130cdf0e10cSrcweir //
131cdf0e10cSrcweir 
~XMLCharHeightDiffHdl()132cdf0e10cSrcweir XMLCharHeightDiffHdl::~XMLCharHeightDiffHdl()
133cdf0e10cSrcweir {
134cdf0e10cSrcweir 	// nothing to do
135cdf0e10cSrcweir }
136cdf0e10cSrcweir 
importXML(const OUString & rStrImpValue,uno::Any & rValue,const SvXMLUnitConverter &) const137cdf0e10cSrcweir sal_Bool XMLCharHeightDiffHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
138cdf0e10cSrcweir {
139cdf0e10cSrcweir 	sal_Int32 nRel = 0;
140cdf0e10cSrcweir 
141cdf0e10cSrcweir 	if( SvXMLUnitConverter::convertMeasure( nRel, rStrImpValue, MAP_POINT ) )
142cdf0e10cSrcweir 	{
143cdf0e10cSrcweir 		rValue <<= (float)nRel;
144cdf0e10cSrcweir 		return sal_True;
145cdf0e10cSrcweir 	}
146cdf0e10cSrcweir 
147cdf0e10cSrcweir 	return sal_False;
148cdf0e10cSrcweir }
149cdf0e10cSrcweir 
exportXML(OUString & rStrExpValue,const uno::Any & rValue,const SvXMLUnitConverter &) const150cdf0e10cSrcweir sal_Bool XMLCharHeightDiffHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
151cdf0e10cSrcweir {
152cdf0e10cSrcweir 	OUStringBuffer aOut;
153cdf0e10cSrcweir 
154cdf0e10cSrcweir 	float nRel = 0;
155cdf0e10cSrcweir 	if( (rValue >>= nRel) && (nRel != 0) )
156cdf0e10cSrcweir 	{
157cdf0e10cSrcweir 		SvXMLUnitConverter::convertMeasure( aOut, (sal_Int32)nRel, MAP_POINT, MAP_POINT );
158cdf0e10cSrcweir 		rStrExpValue = aOut.makeStringAndClear();
159cdf0e10cSrcweir 	}
160cdf0e10cSrcweir 
161cdf0e10cSrcweir 	return rStrExpValue.getLength() != 0;
162cdf0e10cSrcweir }
163cdf0e10cSrcweir 
164