Line data Source code
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 :
21 : #include <chrhghdl.hxx>
22 :
23 : #include <rtl/ustrbuf.hxx>
24 :
25 : #include <com/sun/star/uno/Any.hxx>
26 :
27 : #include <sax/tools/converter.hxx>
28 :
29 : #include <xmloff/xmluconv.hxx>
30 :
31 :
32 : using namespace ::com::sun::star;
33 :
34 : ///////////////////////////////////////////////////////////////////////////////
35 : //
36 : // class XMLEscapementPropHdl
37 : //
38 :
39 3928 : XMLCharHeightHdl::~XMLCharHeightHdl()
40 : {
41 : // nothing to do
42 3928 : }
43 :
44 2189 : sal_Bool XMLCharHeightHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
45 : {
46 2189 : if( rStrImpValue.indexOf( sal_Unicode('%') ) == -1 )
47 : {
48 : double fSize;
49 : sal_Int16 const eSrcUnit = ::sax::Converter::GetUnitFromString(
50 2186 : rStrImpValue, util::MeasureUnit::POINT );
51 2186 : if (::sax::Converter::convertDouble(fSize, rStrImpValue,
52 2186 : eSrcUnit, util::MeasureUnit::POINT))
53 : {
54 2186 : fSize = ::std::max<double>(fSize, 1.0); // fdo#49876: 0pt is invalid
55 2186 : rValue <<= (float)fSize;
56 2186 : return sal_True;
57 : }
58 : }
59 :
60 3 : return sal_False;
61 : }
62 :
63 685 : sal_Bool XMLCharHeightHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
64 : {
65 685 : OUStringBuffer aOut;
66 :
67 685 : float fSize = 0;
68 685 : if( rValue >>= fSize )
69 : {
70 685 : fSize = ::std::max<float>(fSize, 1.0f); // fdo#49876: 0pt is invalid
71 : ::sax::Converter::convertDouble(aOut, (double)fSize, true,
72 685 : util::MeasureUnit::POINT, util::MeasureUnit::POINT);
73 685 : aOut.append( sal_Unicode('p'));
74 685 : aOut.append( sal_Unicode('t'));
75 : }
76 :
77 685 : rStrExpValue = aOut.makeStringAndClear();
78 685 : return !rStrExpValue.isEmpty();
79 : }
80 :
81 : ///////////////////////////////////////////////////////////////////////////////
82 : //
83 : // class XMLEscapementHeightPropHdl
84 : //
85 :
86 3862 : XMLCharHeightPropHdl::~XMLCharHeightPropHdl()
87 : {
88 : // nothing to do
89 3862 : }
90 :
91 2189 : sal_Bool XMLCharHeightPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
92 : {
93 2189 : if( rStrImpValue.indexOf( sal_Unicode('%') ) != -1 )
94 : {
95 3 : sal_Int32 nPrc = 100;
96 3 : if (::sax::Converter::convertPercent( nPrc, rStrImpValue ))
97 : {
98 3 : rValue <<= (sal_Int16)nPrc;
99 3 : return sal_True;
100 : }
101 : }
102 :
103 2186 : return sal_False;
104 : }
105 :
106 0 : sal_Bool XMLCharHeightPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
107 : {
108 0 : OUStringBuffer aOut( rStrExpValue );
109 :
110 0 : sal_Int16 nValue = sal_Int16();
111 0 : if( rValue >>= nValue )
112 : {
113 0 : ::sax::Converter::convertPercent( aOut, nValue );
114 : }
115 :
116 0 : rStrExpValue = aOut.makeStringAndClear();
117 0 : return !rStrExpValue.isEmpty();
118 : }
119 :
120 : ///////////////////////////////////////////////////////////////////////////////
121 : //
122 : // class XMLEscapementPropHdl
123 : //
124 :
125 3862 : XMLCharHeightDiffHdl::~XMLCharHeightDiffHdl()
126 : {
127 : // nothing to do
128 3862 : }
129 :
130 0 : sal_Bool XMLCharHeightDiffHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
131 : {
132 0 : sal_Int32 nRel = 0;
133 :
134 0 : if (::sax::Converter::convertMeasure( nRel, rStrImpValue,
135 : util::MeasureUnit::POINT ))
136 : {
137 0 : rValue <<= (float)nRel;
138 0 : return sal_True;
139 : }
140 :
141 0 : return sal_False;
142 : }
143 :
144 0 : sal_Bool XMLCharHeightDiffHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
145 : {
146 0 : OUStringBuffer aOut;
147 :
148 0 : float nRel = 0;
149 0 : if( (rValue >>= nRel) && (nRel != 0) )
150 : {
151 : ::sax::Converter::convertMeasure( aOut, static_cast<sal_Int32>(nRel),
152 0 : util::MeasureUnit::POINT, util::MeasureUnit::POINT );
153 0 : rStrExpValue = aOut.makeStringAndClear();
154 : }
155 :
156 0 : return !rStrExpValue.isEmpty();
157 : }
158 :
159 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|