LibreOffice Module xmloff (master) 1
chrhghdl.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include "chrhghdl.hxx"
21
22#include <rtl/ustrbuf.hxx>
23
24#include <com/sun/star/uno/Any.hxx>
25
27
28#include <xmloff/xmluconv.hxx>
29
30using namespace ::com::sun::star;
31
32
33
34
36{
37 // nothing to do
38}
39
40bool XMLCharHeightHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
41{
42 if( rStrImpValue.indexOf( '%' ) == -1 )
43 {
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))
49 {
50 fSize = ::std::max<double>(fSize, 1.0); // fdo#49876: 0pt is invalid
51 rValue <<= static_cast<float>(fSize);
52 return true;
53 }
54 }
55
56 return false;
57}
58
59bool XMLCharHeightHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
60{
61 OUStringBuffer aOut;
62
63 float fSize = 0;
64 if( rValue >>= fSize )
65 {
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" );
70 }
71
72 rStrExpValue = aOut.makeStringAndClear();
73 return !rStrExpValue.isEmpty();
74}
75
76
77
78
80{
81 // nothing to do
82}
83
84bool XMLCharHeightPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
85{
86 if( rStrImpValue.indexOf( '%' ) != -1 )
87 {
88 sal_Int32 nPrc = 100;
89 if (::sax::Converter::convertPercent( nPrc, rStrImpValue ))
90 {
91 rValue <<= static_cast<sal_Int16>(nPrc);
92 return true;
93 }
94 }
95
96 return false;
97}
98
99bool XMLCharHeightPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
100{
101 OUStringBuffer aOut( rStrExpValue );
102
103 sal_Int16 nValue = sal_Int16();
104 if( rValue >>= nValue )
105 {
107 }
108
109 rStrExpValue = aOut.makeStringAndClear();
110 return !rStrExpValue.isEmpty();
111}
112
113
114
115
117{
118 // nothing to do
119}
120
121bool XMLCharHeightDiffHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
122{
123 sal_Int32 nRel = 0;
124
125 if (::sax::Converter::convertMeasure( nRel, rStrImpValue,
126 util::MeasureUnit::POINT ))
127 {
128 rValue <<= static_cast<float>(nRel);
129 return true;
130 }
131
132 return false;
133}
134
135bool XMLCharHeightDiffHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
136{
137 float nRel = 0;
138 if( (rValue >>= nRel) && (nRel != 0) )
139 {
140 OUStringBuffer aOut;
141 ::sax::Converter::convertMeasure( aOut, static_cast<sal_Int32>(nRel),
142 util::MeasureUnit::POINT, util::MeasureUnit::POINT );
143 rStrExpValue = aOut.makeStringAndClear();
144 }
145
146 return !rStrExpValue.isEmpty();
147}
148
149/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
the SvXMLTypeConverter converts values of various types from their internal representation to the tex...
Definition: xmluconv.hxx:83
virtual bool importXML(const OUString &rStrImpValue, css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Imports the given value according to the XML-data-type corresponding to the derived class.
Definition: chrhghdl.cxx:121
virtual bool exportXML(OUString &rStrExpValue, const css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Exports the given value according to the XML-data-type corresponding to the derived class.
Definition: chrhghdl.cxx:135
virtual ~XMLCharHeightDiffHdl() override
Definition: chrhghdl.cxx:116
virtual ~XMLCharHeightHdl() override
Definition: chrhghdl.cxx:35
virtual bool importXML(const OUString &rStrImpValue, css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Imports the given value according to the XML-data-type corresponding to the derived class.
Definition: chrhghdl.cxx:40
virtual bool exportXML(OUString &rStrExpValue, const css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Exports the given value according to the XML-data-type corresponding to the derived class.
Definition: chrhghdl.cxx:59
virtual ~XMLCharHeightPropHdl() override
Definition: chrhghdl.cxx:79
virtual bool importXML(const OUString &rStrImpValue, css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Imports the given value according to the XML-data-type corresponding to the derived class.
Definition: chrhghdl.cxx:84
virtual bool exportXML(OUString &rStrExpValue, const css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Exports the given value according to the XML-data-type corresponding to the derived class.
Definition: chrhghdl.cxx:99
static void convertDouble(OUStringBuffer &rBuffer, double fNumber, bool bWriteUnits, sal_Int16 nSourceUnit, sal_Int16 nTargetUnit)
static bool convertMeasure(sal_Int32 &rValue, std::u16string_view rString, sal_Int16 nTargetUnit=css::util::MeasureUnit::MM_100TH, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32)
static bool convertPercent(sal_Int32 &rValue, std::u16string_view rString)
static sal_Int16 GetUnitFromString(std::u16string_view rString, sal_Int16 nDefaultUnit)
sal_Int16 nValue