tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / xmloff / source / style / chrhghdl.cxx
blob53048812726bb299c8f4883a0c341bf24c086b9d
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( "pt" );
72 rStrExpValue = aOut.makeStringAndClear();
73 return !rStrExpValue.isEmpty();
79 XMLCharHeightPropHdl::~XMLCharHeightPropHdl()
81 // nothing to do
84 bool XMLCharHeightPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
86 if( rStrImpValue.indexOf( '%' ) != -1 )
88 sal_Int32 nPrc = 100;
89 if (::sax::Converter::convertPercent( nPrc, rStrImpValue ))
91 rValue <<= static_cast<sal_Int16>(nPrc);
92 return true;
96 return false;
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()
118 // nothing to do
121 bool XMLCharHeightDiffHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
123 sal_Int32 nRel = 0;
125 if (::sax::Converter::convertMeasure( nRel, rStrImpValue,
126 util::MeasureUnit::POINT ))
128 rValue <<= static_cast<float>(nRel);
129 return true;
132 return false;
135 bool XMLCharHeightDiffHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
137 float nRel = 0;
138 if( (rValue >>= nRel) && (nRel != 0) )
140 OUStringBuffer aOut;
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: */