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 .
21 #include <chrhghdl.hxx>
23 #include <rtl/ustrbuf.hxx>
25 #include <com/sun/star/uno/Any.hxx>
27 #include <sax/tools/converter.hxx>
29 #include <xmloff/xmluconv.hxx>
32 using namespace ::com::sun::star
;
34 ///////////////////////////////////////////////////////////////////////////////
36 // class XMLEscapementPropHdl
39 XMLCharHeightHdl::~XMLCharHeightHdl()
44 sal_Bool
XMLCharHeightHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
46 if( rStrImpValue
.indexOf( sal_Unicode('%') ) == -1 )
49 sal_Int16
const eSrcUnit
= ::sax::Converter::GetUnitFromString(
50 rStrImpValue
, util::MeasureUnit::POINT
);
51 if (::sax::Converter::convertDouble(fSize
, rStrImpValue
,
52 eSrcUnit
, util::MeasureUnit::POINT
))
54 fSize
= ::std::max
<double>(fSize
, 1.0); // fdo#49876: 0pt is invalid
55 rValue
<<= (float)fSize
;
63 sal_Bool
XMLCharHeightHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
68 if( rValue
>>= fSize
)
70 fSize
= ::std::max
<float>(fSize
, 1.0f
); // fdo#49876: 0pt is invalid
71 ::sax::Converter::convertDouble(aOut
, (double)fSize
, true,
72 util::MeasureUnit::POINT
, util::MeasureUnit::POINT
);
73 aOut
.append( sal_Unicode('p'));
74 aOut
.append( sal_Unicode('t'));
77 rStrExpValue
= aOut
.makeStringAndClear();
78 return !rStrExpValue
.isEmpty();
81 ///////////////////////////////////////////////////////////////////////////////
83 // class XMLEscapementHeightPropHdl
86 XMLCharHeightPropHdl::~XMLCharHeightPropHdl()
91 sal_Bool
XMLCharHeightPropHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
93 if( rStrImpValue
.indexOf( sal_Unicode('%') ) != -1 )
96 if (::sax::Converter::convertPercent( nPrc
, rStrImpValue
))
98 rValue
<<= (sal_Int16
)nPrc
;
106 sal_Bool
XMLCharHeightPropHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
108 OUStringBuffer
aOut( rStrExpValue
);
110 sal_Int16 nValue
= sal_Int16();
111 if( rValue
>>= nValue
)
113 ::sax::Converter::convertPercent( aOut
, nValue
);
116 rStrExpValue
= aOut
.makeStringAndClear();
117 return !rStrExpValue
.isEmpty();
120 ///////////////////////////////////////////////////////////////////////////////
122 // class XMLEscapementPropHdl
125 XMLCharHeightDiffHdl::~XMLCharHeightDiffHdl()
130 sal_Bool
XMLCharHeightDiffHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
134 if (::sax::Converter::convertMeasure( nRel
, rStrImpValue
,
135 util::MeasureUnit::POINT
))
137 rValue
<<= (float)nRel
;
144 sal_Bool
XMLCharHeightDiffHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
149 if( (rValue
>>= nRel
) && (nRel
!= 0) )
151 ::sax::Converter::convertMeasure( aOut
, static_cast<sal_Int32
>(nRel
),
152 util::MeasureUnit::POINT
, util::MeasureUnit::POINT
);
153 rStrExpValue
= aOut
.makeStringAndClear();
156 return !rStrExpValue
.isEmpty();
159 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */