1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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()
40 bool XMLCharHeightHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
42 if( rStrImpValue
.indexOf( '%' ) == -1 )
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
);
59 bool XMLCharHeightHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
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
);
72 rStrExpValue
= aOut
.makeStringAndClear();
73 return !rStrExpValue
.isEmpty();
79 XMLCharHeightPropHdl::~XMLCharHeightPropHdl()
84 bool XMLCharHeightPropHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
86 if( rStrImpValue
.indexOf( '%' ) != -1 )
89 if (::sax::Converter::convertPercent( nPrc
, rStrImpValue
))
91 rValue
<<= static_cast<sal_Int16
>(nPrc
);
99 bool XMLCharHeightPropHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
101 OUStringBuffer
aOut( rStrExpValue
);
103 sal_Int16 nValue
= sal_Int16();
104 if( rValue
>>= nValue
)
106 ::sax::Converter::convertPercent( aOut
, nValue
);
109 rStrExpValue
= aOut
.makeStringAndClear();
110 return !rStrExpValue
.isEmpty();
116 XMLCharHeightDiffHdl::~XMLCharHeightDiffHdl()
121 bool XMLCharHeightDiffHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
125 if (::sax::Converter::convertMeasure( nRel
, rStrImpValue
,
126 util::MeasureUnit::POINT
))
128 rValue
<<= static_cast<float>(nRel
);
135 bool XMLCharHeightDiffHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
138 if( (rValue
>>= nRel
) && (nRel
!= 0) )
141 ::sax::Converter::convertMeasure( aOut
, static_cast<sal_Int32
>(nRel
),
142 util::MeasureUnit::POINT
, util::MeasureUnit::POINT
);
143 rStrExpValue
= aOut
.makeStringAndClear();
146 return !rStrExpValue
.isEmpty();
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */