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 
26 #include <sax/tools/converter.hxx>
27 
28 #include <xmloff/xmluconv.hxx>
29 
30 using namespace ::com::sun::star;
31 
32 
33 
34 
36 {
37  // nothing to do
38 }
39 
40 bool 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 
59 bool 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( 'p');
70  aOut.append( 't');
71  }
72 
73  rStrExpValue = aOut.makeStringAndClear();
74  return !rStrExpValue.isEmpty();
75 }
76 
77 
78 
79 
81 {
82  // nothing to do
83 }
84 
85 bool XMLCharHeightPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
86 {
87  if( rStrImpValue.indexOf( '%' ) != -1 )
88  {
89  sal_Int32 nPrc = 100;
90  if (::sax::Converter::convertPercent( nPrc, rStrImpValue ))
91  {
92  rValue <<= static_cast<sal_Int16>(nPrc);
93  return true;
94  }
95  }
96 
97  return false;
98 }
99 
100 bool XMLCharHeightPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
101 {
102  OUStringBuffer aOut( rStrExpValue );
103 
104  sal_Int16 nValue = sal_Int16();
105  if( rValue >>= nValue )
106  {
107  ::sax::Converter::convertPercent( aOut, nValue );
108  }
109 
110  rStrExpValue = aOut.makeStringAndClear();
111  return !rStrExpValue.isEmpty();
112 }
113 
114 
115 
116 
118 {
119  // nothing to do
120 }
121 
122 bool XMLCharHeightDiffHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
123 {
124  sal_Int32 nRel = 0;
125 
126  if (::sax::Converter::convertMeasure( nRel, rStrImpValue,
127  util::MeasureUnit::POINT ))
128  {
129  rValue <<= static_cast<float>(nRel);
130  return true;
131  }
132 
133  return false;
134 }
135 
136 bool XMLCharHeightDiffHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
137 {
138  float nRel = 0;
139  if( (rValue >>= nRel) && (nRel != 0) )
140  {
141  OUStringBuffer aOut;
142  ::sax::Converter::convertMeasure( aOut, static_cast<sal_Int32>(nRel),
143  util::MeasureUnit::POINT, util::MeasureUnit::POINT );
144  rStrExpValue = aOut.makeStringAndClear();
145  }
146 
147  return !rStrExpValue.isEmpty();
148 }
149 
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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
static bool convertMeasure(sal_Int32 &rValue, const OUString &rString, sal_Int16 nTargetUnit=css::util::MeasureUnit::MM_100TH, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32)
the SvXMLTypeConverter converts values of various types from their internal representation to the tex...
Definition: xmluconv.hxx:77
static void convertDouble(OUStringBuffer &rBuffer, double fNumber, bool bWriteUnits, sal_Int16 nSourceUnit, sal_Int16 nTargetUnit)
css::uno::Any const & rValue
Definition: ImageStyle.hxx:38
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:100
virtual ~XMLCharHeightDiffHdl() override
Definition: chrhghdl.cxx:117
virtual ~XMLCharHeightPropHdl() override
Definition: chrhghdl.cxx:80
static sal_Int16 GetUnitFromString(const OUString &rString, sal_Int16 nDefaultUnit)
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:122
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:136
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:85
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 ~XMLCharHeightHdl() override
Definition: chrhghdl.cxx:35
sal_Int16 nValue
static bool convertPercent(sal_Int32 &rValue, const OUString &rString)