nss: upgrade to release 3.73
[LibreOffice.git] / xmloff / source / style / chrhghdl.cxx
blob5417800c6d18590a15e10159043521c131cc8e50
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;
35 XMLCharHeightHdl::~XMLCharHeightHdl()
37 // nothing to do
40 bool XMLCharHeightHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
42 if( rStrImpValue.indexOf( '%' ) == -1 )
44 double fSize;
45 sal_Int16 const eSrcUnit = ::sax::Converter::GetUnitFromString(
46 rStrImpValue, util::MeasureUnit::POINT );
47 if (::sax::Converter::convertDouble(fSize, rStrImpValue,
48 eSrcUnit, util::MeasureUnit::POINT))
50 fSize = ::std::max<double>(fSize, 1.0); // fdo#49876: 0pt is invalid
51 rValue <<= static_cast<float>(fSize);
52 return true;
56 return false;
59 bool XMLCharHeightHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
61 OUStringBuffer aOut;
63 float fSize = 0;
64 if( rValue >>= fSize )
66 fSize = ::std::max<float>(fSize, 1.0f); // fdo#49876: 0pt is invalid
67 ::sax::Converter::convertDouble(aOut, static_cast<double>(fSize), true,
68 util::MeasureUnit::POINT, util::MeasureUnit::POINT);
69 aOut.append( 'p');
70 aOut.append( 't');
73 rStrExpValue = aOut.makeStringAndClear();
74 return !rStrExpValue.isEmpty();
80 XMLCharHeightPropHdl::~XMLCharHeightPropHdl()
82 // nothing to do
85 bool XMLCharHeightPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
87 if( rStrImpValue.indexOf( '%' ) != -1 )
89 sal_Int32 nPrc = 100;
90 if (::sax::Converter::convertPercent( nPrc, rStrImpValue ))
92 rValue <<= static_cast<sal_Int16>(nPrc);
93 return true;
97 return false;
100 bool XMLCharHeightPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
102 OUStringBuffer aOut( rStrExpValue );
104 sal_Int16 nValue = sal_Int16();
105 if( rValue >>= nValue )
107 ::sax::Converter::convertPercent( aOut, nValue );
110 rStrExpValue = aOut.makeStringAndClear();
111 return !rStrExpValue.isEmpty();
117 XMLCharHeightDiffHdl::~XMLCharHeightDiffHdl()
119 // nothing to do
122 bool XMLCharHeightDiffHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
124 sal_Int32 nRel = 0;
126 if (::sax::Converter::convertMeasure( nRel, rStrImpValue,
127 util::MeasureUnit::POINT ))
129 rValue <<= static_cast<float>(nRel);
130 return true;
133 return false;
136 bool XMLCharHeightDiffHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
138 float nRel = 0;
139 if( (rValue >>= nRel) && (nRel != 0) )
141 OUStringBuffer aOut;
142 ::sax::Converter::convertMeasure( aOut, static_cast<sal_Int32>(nRel),
143 util::MeasureUnit::POINT, util::MeasureUnit::POINT );
144 rStrExpValue = aOut.makeStringAndClear();
147 return !rStrExpValue.isEmpty();
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */