/src/libreoffice/xmloff/source/style/chrhghdl.cxx
Line | Count | Source |
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 | | |
35 | | XMLCharHeightHdl::~XMLCharHeightHdl() |
36 | 165k | { |
37 | | // nothing to do |
38 | 165k | } |
39 | | |
40 | | bool XMLCharHeightHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const |
41 | 101k | { |
42 | 101k | if( rStrImpValue.indexOf( '%' ) == -1 ) |
43 | 97.9k | { |
44 | 97.9k | double fSize; |
45 | 97.9k | sal_Int16 const eSrcUnit = ::sax::Converter::GetUnitFromString( |
46 | 97.9k | rStrImpValue, util::MeasureUnit::POINT ); |
47 | 97.9k | if (::sax::Converter::convertDouble(fSize, rStrImpValue, |
48 | 97.9k | eSrcUnit, util::MeasureUnit::POINT)) |
49 | 97.9k | { |
50 | 97.9k | fSize = ::std::max<double>(fSize, 1.0); // fdo#49876: 0pt is invalid |
51 | 97.9k | rValue <<= static_cast<float>(fSize); |
52 | 97.9k | return true; |
53 | 97.9k | } |
54 | 97.9k | } |
55 | | |
56 | 3.47k | return false; |
57 | 101k | } |
58 | | |
59 | | bool XMLCharHeightHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const |
60 | 66 | { |
61 | 66 | OUStringBuffer aOut; |
62 | | |
63 | 66 | float fSize = 0; |
64 | 66 | if( rValue >>= fSize ) |
65 | 66 | { |
66 | 66 | fSize = ::std::max<float>(fSize, 1.0f); // fdo#49876: 0pt is invalid |
67 | 66 | ::sax::Converter::convertDouble(aOut, static_cast<double>(fSize), true, |
68 | 66 | util::MeasureUnit::POINT, util::MeasureUnit::POINT); |
69 | 66 | aOut.append( "pt" ); |
70 | 66 | } |
71 | | |
72 | 66 | rStrExpValue = aOut.makeStringAndClear(); |
73 | 66 | return !rStrExpValue.isEmpty(); |
74 | 66 | } |
75 | | |
76 | | |
77 | | |
78 | | |
79 | | XMLCharHeightPropHdl::~XMLCharHeightPropHdl() |
80 | 158k | { |
81 | | // nothing to do |
82 | 158k | } |
83 | | |
84 | | bool XMLCharHeightPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const |
85 | 98.7k | { |
86 | 98.7k | if( rStrImpValue.indexOf( '%' ) != -1 ) |
87 | 3.45k | { |
88 | 3.45k | sal_Int32 nPrc = 100; |
89 | 3.45k | if (::sax::Converter::convertPercent( nPrc, rStrImpValue )) |
90 | 3.41k | { |
91 | 3.41k | rValue <<= static_cast<sal_Int16>(nPrc); |
92 | 3.41k | return true; |
93 | 3.41k | } |
94 | 3.45k | } |
95 | | |
96 | 95.3k | return false; |
97 | 98.7k | } |
98 | | |
99 | | bool XMLCharHeightPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const |
100 | 0 | { |
101 | 0 | OUStringBuffer aOut( rStrExpValue ); |
102 | |
|
103 | 0 | sal_Int16 nValue = sal_Int16(); |
104 | 0 | if( rValue >>= nValue ) |
105 | 0 | { |
106 | 0 | ::sax::Converter::convertPercent( aOut, nValue ); |
107 | 0 | } |
108 | |
|
109 | 0 | rStrExpValue = aOut.makeStringAndClear(); |
110 | 0 | return !rStrExpValue.isEmpty(); |
111 | 0 | } |
112 | | |
113 | | |
114 | | |
115 | | |
116 | | XMLCharHeightDiffHdl::~XMLCharHeightDiffHdl() |
117 | 158k | { |
118 | | // nothing to do |
119 | 158k | } |
120 | | |
121 | | bool XMLCharHeightDiffHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const |
122 | 0 | { |
123 | 0 | sal_Int32 nRel = 0; |
124 | |
|
125 | 0 | if (::sax::Converter::convertMeasure( nRel, rStrImpValue, |
126 | 0 | util::MeasureUnit::POINT )) |
127 | 0 | { |
128 | 0 | rValue <<= static_cast<float>(nRel); |
129 | 0 | return true; |
130 | 0 | } |
131 | | |
132 | 0 | return false; |
133 | 0 | } |
134 | | |
135 | | bool XMLCharHeightDiffHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const |
136 | 0 | { |
137 | 0 | float nRel = 0; |
138 | 0 | if( (rValue >>= nRel) && (nRel != 0) ) |
139 | 0 | { |
140 | 0 | OUStringBuffer aOut; |
141 | 0 | ::sax::Converter::convertMeasure( aOut, static_cast<sal_Int32>(nRel), |
142 | 0 | util::MeasureUnit::POINT, util::MeasureUnit::POINT ); |
143 | 0 | rStrExpValue = aOut.makeStringAndClear(); |
144 | 0 | } |
145 | |
|
146 | 0 | return !rStrExpValue.isEmpty(); |
147 | 0 | } |
148 | | |
149 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |