xref: /trunk/main/xmloff/source/style/lspachdl.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 <lspachdl.hxx>
29cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
30cdf0e10cSrcweir #include <xmloff/xmluconv.hxx>
31cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
32cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx>
33cdf0e10cSrcweir #include <com/sun/star/style/LineSpacing.hpp>
34cdf0e10cSrcweir #include <com/sun/star/style/LineSpacingMode.hpp>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir using ::rtl::OUString;
37cdf0e10cSrcweir using ::rtl::OUStringBuffer;
38cdf0e10cSrcweir 
39cdf0e10cSrcweir using namespace ::com::sun::star;
40cdf0e10cSrcweir using ::xmloff::token::IsXMLToken;
41cdf0e10cSrcweir using ::xmloff::token::XML_CASEMAP_NORMAL;
42cdf0e10cSrcweir 
43cdf0e10cSrcweir // this is a copy of defines in svx/inc/escpitem.hxx
44cdf0e10cSrcweir #define DFLT_ESC_PROP	 58
45cdf0e10cSrcweir #define DFLT_ESC_AUTO_SUPER	101
46cdf0e10cSrcweir #define DFLT_ESC_AUTO_SUB  -101
47cdf0e10cSrcweir 
48cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////////
49cdf0e10cSrcweir //
50cdf0e10cSrcweir // class XMLEscapementPropHdl
51cdf0e10cSrcweir //
52cdf0e10cSrcweir 
~XMLLineHeightHdl()53cdf0e10cSrcweir XMLLineHeightHdl::~XMLLineHeightHdl()
54cdf0e10cSrcweir {
55cdf0e10cSrcweir 	// nothing to do
56cdf0e10cSrcweir }
57cdf0e10cSrcweir 
importXML(const OUString & rStrImpValue,uno::Any & rValue,const SvXMLUnitConverter & rUnitConverter) const58cdf0e10cSrcweir sal_Bool XMLLineHeightHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
59cdf0e10cSrcweir {
60cdf0e10cSrcweir 	style::LineSpacing aLSp;
61cdf0e10cSrcweir 	sal_Int32 nTemp = 0;
62cdf0e10cSrcweir 
63cdf0e10cSrcweir 	if( -1 != rStrImpValue.indexOf( sal_Unicode( '%' ) ) )
64cdf0e10cSrcweir 	{
65cdf0e10cSrcweir 		aLSp.Mode = style::LineSpacingMode::PROP;
66cdf0e10cSrcweir 		if(!rUnitConverter.convertPercent( nTemp, rStrImpValue ))
67cdf0e10cSrcweir 			return sal_False;
68cdf0e10cSrcweir 		aLSp.Height = sal::static_int_cast< sal_Int16 >(nTemp);
69cdf0e10cSrcweir 	}
70cdf0e10cSrcweir 	else if( IsXMLToken( rStrImpValue, XML_CASEMAP_NORMAL) )
71cdf0e10cSrcweir 	{
72cdf0e10cSrcweir 		aLSp.Mode = style::LineSpacingMode::PROP;
73cdf0e10cSrcweir 		aLSp.Height = 100;
74cdf0e10cSrcweir 	}
75cdf0e10cSrcweir 	else
76cdf0e10cSrcweir 	{
77cdf0e10cSrcweir 		aLSp.Mode = style::LineSpacingMode::FIX;
78cdf0e10cSrcweir 		if(!rUnitConverter.convertMeasure( nTemp, rStrImpValue, 0x0000, 0xffff ))
79cdf0e10cSrcweir 			return sal_False;
80cdf0e10cSrcweir 		aLSp.Height = sal::static_int_cast< sal_Int16 >(nTemp);
81cdf0e10cSrcweir 	}
82cdf0e10cSrcweir 
83cdf0e10cSrcweir 	rValue <<= aLSp;
84cdf0e10cSrcweir 	return sal_True;
85cdf0e10cSrcweir }
86cdf0e10cSrcweir 
exportXML(OUString & rStrExpValue,const uno::Any & rValue,const SvXMLUnitConverter & rUnitConverter) const87cdf0e10cSrcweir sal_Bool XMLLineHeightHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
88cdf0e10cSrcweir {
89cdf0e10cSrcweir 	OUStringBuffer aOut;
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 	style::LineSpacing aLSp;
92cdf0e10cSrcweir 	if(!(rValue >>= aLSp))
93cdf0e10cSrcweir 		return sal_False;
94cdf0e10cSrcweir 
95cdf0e10cSrcweir 	if( style::LineSpacingMode::PROP != aLSp.Mode && style::LineSpacingMode::FIX  != aLSp.Mode )
96cdf0e10cSrcweir 		return sal_False;
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 	if( style::LineSpacingMode::PROP == aLSp.Mode )
99cdf0e10cSrcweir 	{
100cdf0e10cSrcweir 		rUnitConverter.convertPercent( aOut, aLSp.Height );
101cdf0e10cSrcweir 	}
102cdf0e10cSrcweir 	else
103cdf0e10cSrcweir 	{
104cdf0e10cSrcweir 		rUnitConverter.convertMeasure( aOut, aLSp.Height );
105cdf0e10cSrcweir 	}
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 	rStrExpValue = aOut.makeStringAndClear();
108cdf0e10cSrcweir 	return rStrExpValue.getLength() != 0;
109cdf0e10cSrcweir }
110cdf0e10cSrcweir 
111cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////////
112cdf0e10cSrcweir //
113cdf0e10cSrcweir // class XMLLineHeightAtLeastHdl
114cdf0e10cSrcweir //
115cdf0e10cSrcweir 
~XMLLineHeightAtLeastHdl()116cdf0e10cSrcweir XMLLineHeightAtLeastHdl::~XMLLineHeightAtLeastHdl()
117cdf0e10cSrcweir {
118cdf0e10cSrcweir 	// nothing to do
119cdf0e10cSrcweir }
120cdf0e10cSrcweir 
importXML(const OUString & rStrImpValue,uno::Any & rValue,const SvXMLUnitConverter & rUnitConverter) const121cdf0e10cSrcweir sal_Bool XMLLineHeightAtLeastHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
122cdf0e10cSrcweir {
123cdf0e10cSrcweir 	style::LineSpacing aLSp;
124cdf0e10cSrcweir 
125cdf0e10cSrcweir 	sal_Int32 nTemp;
126cdf0e10cSrcweir 	aLSp.Mode = style::LineSpacingMode::MINIMUM;
127cdf0e10cSrcweir 	if(!rUnitConverter.convertMeasure( nTemp, rStrImpValue, 0x0000, 0xffff ))
128cdf0e10cSrcweir 		return sal_False;
129cdf0e10cSrcweir 	aLSp.Height = sal::static_int_cast< sal_Int16 >(nTemp);
130cdf0e10cSrcweir 
131cdf0e10cSrcweir 	rValue <<= aLSp;
132cdf0e10cSrcweir 	return sal_True;
133cdf0e10cSrcweir }
134cdf0e10cSrcweir 
exportXML(OUString & rStrExpValue,const uno::Any & rValue,const SvXMLUnitConverter & rUnitConverter) const135cdf0e10cSrcweir sal_Bool XMLLineHeightAtLeastHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
136cdf0e10cSrcweir {
137cdf0e10cSrcweir 	OUStringBuffer aOut;
138cdf0e10cSrcweir 
139cdf0e10cSrcweir 	style::LineSpacing aLSp;
140cdf0e10cSrcweir 	if(!(rValue >>= aLSp))
141cdf0e10cSrcweir 		return sal_False;
142cdf0e10cSrcweir 
143cdf0e10cSrcweir 	if( style::LineSpacingMode::MINIMUM != aLSp.Mode )
144cdf0e10cSrcweir 		return sal_False;
145cdf0e10cSrcweir 
146cdf0e10cSrcweir 	rUnitConverter.convertMeasure( aOut, aLSp.Height );
147cdf0e10cSrcweir 
148cdf0e10cSrcweir 	rStrExpValue = aOut.makeStringAndClear();
149cdf0e10cSrcweir 	return rStrExpValue.getLength() != 0;
150cdf0e10cSrcweir }
151cdf0e10cSrcweir 
152cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////////
153cdf0e10cSrcweir //
154cdf0e10cSrcweir // class XMLLineSpacingHdl
155cdf0e10cSrcweir //
156cdf0e10cSrcweir 
~XMLLineSpacingHdl()157cdf0e10cSrcweir XMLLineSpacingHdl::~XMLLineSpacingHdl()
158cdf0e10cSrcweir {
159cdf0e10cSrcweir 	// nothing to do
160cdf0e10cSrcweir }
161cdf0e10cSrcweir 
importXML(const OUString & rStrImpValue,uno::Any & rValue,const SvXMLUnitConverter & rUnitConverter) const162cdf0e10cSrcweir sal_Bool XMLLineSpacingHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
163cdf0e10cSrcweir {
164cdf0e10cSrcweir 	style::LineSpacing aLSp;
165cdf0e10cSrcweir 	sal_Int32 nTemp;
166cdf0e10cSrcweir 
167cdf0e10cSrcweir 	aLSp.Mode = style::LineSpacingMode::LEADING;
168cdf0e10cSrcweir 	if(!rUnitConverter.convertMeasure( nTemp, rStrImpValue, 0x0000, 0xffff ))
169cdf0e10cSrcweir 		return sal_False;
170cdf0e10cSrcweir 	aLSp.Height = sal::static_int_cast< sal_Int16 >(nTemp);
171cdf0e10cSrcweir 
172cdf0e10cSrcweir 	rValue <<= aLSp;
173cdf0e10cSrcweir 	return sal_True;
174cdf0e10cSrcweir }
175cdf0e10cSrcweir 
exportXML(OUString & rStrExpValue,const uno::Any & rValue,const SvXMLUnitConverter & rUnitConverter) const176cdf0e10cSrcweir sal_Bool XMLLineSpacingHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
177cdf0e10cSrcweir {
178cdf0e10cSrcweir 	OUStringBuffer aOut;
179cdf0e10cSrcweir 
180cdf0e10cSrcweir 	style::LineSpacing aLSp;
181cdf0e10cSrcweir 	if(!(rValue >>= aLSp))
182cdf0e10cSrcweir 		return sal_False;
183cdf0e10cSrcweir 
184cdf0e10cSrcweir 	if( style::LineSpacingMode::LEADING != aLSp.Mode )
185cdf0e10cSrcweir 		return sal_False;
186cdf0e10cSrcweir 
187cdf0e10cSrcweir 	rUnitConverter.convertMeasure( aOut, aLSp.Height );
188cdf0e10cSrcweir 
189cdf0e10cSrcweir 	rStrExpValue = aOut.makeStringAndClear();
190cdf0e10cSrcweir 	return rStrExpValue.getLength() != 0;
191cdf0e10cSrcweir }
192