bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / style / chrhghdl.cxx
blob1c28079bf8122851fdd96d61ff492cd0e3fcd7ca
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 <chrhghdl.hxx>
22 #include <rtl/ustrbuf.hxx>
24 #include <com/sun/star/uno/Any.hxx>
26 #include <sax/tools/converter.hxx>
28 #include <xmloff/xmluconv.hxx>
30 using namespace ::com::sun::star;
33 // class XMLEscapementPropHdl
36 XMLCharHeightHdl::~XMLCharHeightHdl()
38 // nothing to do
41 bool XMLCharHeightHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
43 if( rStrImpValue.indexOf( '%' ) == -1 )
45 double fSize;
46 sal_Int16 const eSrcUnit = ::sax::Converter::GetUnitFromString(
47 rStrImpValue, util::MeasureUnit::POINT );
48 if (::sax::Converter::convertDouble(fSize, rStrImpValue,
49 eSrcUnit, util::MeasureUnit::POINT))
51 fSize = ::std::max<double>(fSize, 1.0); // fdo#49876: 0pt is invalid
52 rValue <<= (float)fSize;
53 return true;
57 return false;
60 bool XMLCharHeightHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
62 OUStringBuffer aOut;
64 float fSize = 0;
65 if( rValue >>= fSize )
67 fSize = ::std::max<float>(fSize, 1.0f); // fdo#49876: 0pt is invalid
68 ::sax::Converter::convertDouble(aOut, (double)fSize, true,
69 util::MeasureUnit::POINT, util::MeasureUnit::POINT);
70 aOut.append( 'p');
71 aOut.append( 't');
74 rStrExpValue = aOut.makeStringAndClear();
75 return !rStrExpValue.isEmpty();
79 // class XMLEscapementHeightPropHdl
82 XMLCharHeightPropHdl::~XMLCharHeightPropHdl()
84 // nothing to do
87 bool XMLCharHeightPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
89 if( rStrImpValue.indexOf( '%' ) != -1 )
91 sal_Int32 nPrc = 100;
92 if (::sax::Converter::convertPercent( nPrc, rStrImpValue ))
94 rValue <<= (sal_Int16)nPrc;
95 return true;
99 return false;
102 bool XMLCharHeightPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
104 OUStringBuffer aOut( rStrExpValue );
106 sal_Int16 nValue = sal_Int16();
107 if( rValue >>= nValue )
109 ::sax::Converter::convertPercent( aOut, nValue );
112 rStrExpValue = aOut.makeStringAndClear();
113 return !rStrExpValue.isEmpty();
117 // class XMLEscapementPropHdl
120 XMLCharHeightDiffHdl::~XMLCharHeightDiffHdl()
122 // nothing to do
125 bool XMLCharHeightDiffHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
127 sal_Int32 nRel = 0;
129 if (::sax::Converter::convertMeasure( nRel, rStrImpValue,
130 util::MeasureUnit::POINT ))
132 rValue <<= (float)nRel;
133 return true;
136 return false;
139 bool XMLCharHeightDiffHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
141 OUStringBuffer aOut;
143 float nRel = 0;
144 if( (rValue >>= nRel) && (nRel != 0) )
146 ::sax::Converter::convertMeasure( aOut, static_cast<sal_Int32>(nRel),
147 util::MeasureUnit::POINT, util::MeasureUnit::POINT );
148 rStrExpValue = aOut.makeStringAndClear();
151 return !rStrExpValue.isEmpty();
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */