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