bump product version to 4.1.6.2
[LibreOffice.git] / xmloff / source / style / lspachdl.cxx
bloba6fd84667e6ea768f741d0e2008eb6fed1c318f2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <lspachdl.hxx>
21 #include <xmloff/xmltoken.hxx>
22 #include <xmloff/xmluconv.hxx>
23 #include <sax/tools/converter.hxx>
24 #include <rtl/ustrbuf.hxx>
25 #include <com/sun/star/uno/Any.hxx>
26 #include <com/sun/star/style/LineSpacing.hpp>
27 #include <com/sun/star/style/LineSpacingMode.hpp>
30 using namespace ::com::sun::star;
31 using ::xmloff::token::IsXMLToken;
32 using ::xmloff::token::XML_CASEMAP_NORMAL;
34 ///////////////////////////////////////////////////////////////////////////////
36 // class XMLEscapementPropHdl
39 XMLLineHeightHdl::~XMLLineHeightHdl()
41 // nothing to do
44 sal_Bool XMLLineHeightHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
46 style::LineSpacing aLSp;
47 sal_Int32 nTemp = 0;
49 if( -1 != rStrImpValue.indexOf( sal_Unicode( '%' ) ) )
51 aLSp.Mode = style::LineSpacingMode::PROP;
52 if (!::sax::Converter::convertPercent( nTemp, rStrImpValue ))
53 return sal_False;
54 aLSp.Height = sal::static_int_cast< sal_Int16 >(nTemp);
56 else if( IsXMLToken( rStrImpValue, XML_CASEMAP_NORMAL) )
58 aLSp.Mode = style::LineSpacingMode::PROP;
59 aLSp.Height = 100;
61 else
63 aLSp.Mode = style::LineSpacingMode::FIX;
64 if (!rUnitConverter.convertMeasureToCore(
65 nTemp, rStrImpValue, 0x0000, 0xffff))
66 return sal_False;
67 aLSp.Height = sal::static_int_cast< sal_Int16 >(nTemp);
70 rValue <<= aLSp;
71 return sal_True;
74 sal_Bool XMLLineHeightHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
76 OUStringBuffer aOut;
78 style::LineSpacing aLSp;
79 if(!(rValue >>= aLSp))
80 return sal_False;
82 if( style::LineSpacingMode::PROP != aLSp.Mode && style::LineSpacingMode::FIX != aLSp.Mode )
83 return sal_False;
85 if( style::LineSpacingMode::PROP == aLSp.Mode )
87 ::sax::Converter::convertPercent( aOut, aLSp.Height );
89 else
91 rUnitConverter.convertMeasureToXML( aOut, aLSp.Height );
94 rStrExpValue = aOut.makeStringAndClear();
95 return !rStrExpValue.isEmpty();
98 ///////////////////////////////////////////////////////////////////////////////
100 // class XMLLineHeightAtLeastHdl
103 XMLLineHeightAtLeastHdl::~XMLLineHeightAtLeastHdl()
105 // nothing to do
108 sal_Bool XMLLineHeightAtLeastHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
110 style::LineSpacing aLSp;
112 sal_Int32 nTemp;
113 aLSp.Mode = style::LineSpacingMode::MINIMUM;
114 if (!rUnitConverter.convertMeasureToCore( nTemp, rStrImpValue, 0, 0xffff))
115 return sal_False;
116 aLSp.Height = sal::static_int_cast< sal_Int16 >(nTemp);
118 rValue <<= aLSp;
119 return sal_True;
122 sal_Bool XMLLineHeightAtLeastHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
124 OUStringBuffer aOut;
126 style::LineSpacing aLSp;
127 if(!(rValue >>= aLSp))
128 return sal_False;
130 if( style::LineSpacingMode::MINIMUM != aLSp.Mode )
131 return sal_False;
133 rUnitConverter.convertMeasureToXML( aOut, aLSp.Height );
135 rStrExpValue = aOut.makeStringAndClear();
136 return !rStrExpValue.isEmpty();
139 ///////////////////////////////////////////////////////////////////////////////
141 // class XMLLineSpacingHdl
144 XMLLineSpacingHdl::~XMLLineSpacingHdl()
146 // nothing to do
149 sal_Bool XMLLineSpacingHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
151 style::LineSpacing aLSp;
152 sal_Int32 nTemp;
154 aLSp.Mode = style::LineSpacingMode::LEADING;
155 if (!rUnitConverter.convertMeasureToCore( nTemp, rStrImpValue, 0, 0xffff))
156 return sal_False;
157 aLSp.Height = sal::static_int_cast< sal_Int16 >(nTemp);
159 rValue <<= aLSp;
160 return sal_True;
163 sal_Bool XMLLineSpacingHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
165 OUStringBuffer aOut;
167 style::LineSpacing aLSp;
168 if(!(rValue >>= aLSp))
169 return sal_False;
171 if( style::LineSpacingMode::LEADING != aLSp.Mode )
172 return sal_False;
174 rUnitConverter.convertMeasureToXML( aOut, aLSp.Height );
176 rStrExpValue = aOut.makeStringAndClear();
177 return !rStrExpValue.isEmpty();
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */