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