LibreOffice Module xmloff (master) 1
lspachdl.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 "lspachdl.hxx"
21#include <xmloff/xmltoken.hxx>
22#include <xmloff/xmluconv.hxx>
24#include <rtl/ustrbuf.hxx>
25#include <com/sun/star/uno/Any.hxx>
26#include <com/sun/star/style/LineSpacing.hpp>
27#include <com/sun/star/style/LineSpacingMode.hpp>
28
29using namespace ::com::sun::star;
32
33
34
35
37{
38 // nothing to do
39}
40
41bool XMLLineHeightHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
42{
43 style::LineSpacing aLSp;
44 sal_Int32 nTemp = 0;
45
46 if( -1 != rStrImpValue.indexOf( '%' ) )
47 {
48 aLSp.Mode = style::LineSpacingMode::PROP;
49 if (!::sax::Converter::convertPercent( nTemp, rStrImpValue ))
50 return false;
51 aLSp.Height = sal::static_int_cast< sal_Int16 >(nTemp);
52 }
53 else if( IsXMLToken( rStrImpValue, XML_NORMAL) )
54 {
55 aLSp.Mode = style::LineSpacingMode::PROP;
56 aLSp.Height = 100;
57 }
58 else
59 {
60 aLSp.Mode = style::LineSpacingMode::FIX;
61 if (!rUnitConverter.convertMeasureToCore(
62 nTemp, rStrImpValue, 0x0000, 0xffff))
63 return false;
64 aLSp.Height = sal::static_int_cast< sal_Int16 >(nTemp);
65 }
66
67 rValue <<= aLSp;
68 return true;
69}
70
71bool XMLLineHeightHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
72{
73 OUStringBuffer aOut;
74
75 style::LineSpacing aLSp;
76 if(!(rValue >>= aLSp))
77 return false;
78
79 if( style::LineSpacingMode::PROP != aLSp.Mode && style::LineSpacingMode::FIX != aLSp.Mode )
80 return false;
81
82 if( style::LineSpacingMode::PROP == aLSp.Mode )
83 {
84 ::sax::Converter::convertPercent( aOut, aLSp.Height );
85 }
86 else
87 {
88 rUnitConverter.convertMeasureToXML( aOut, aLSp.Height );
89 }
90
91 rStrExpValue = aOut.makeStringAndClear();
92 return !rStrExpValue.isEmpty();
93}
94
95
96
97
99{
100 // nothing to do
101}
102
103bool XMLLineHeightAtLeastHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
104{
105 style::LineSpacing aLSp;
106
107 sal_Int32 nTemp;
108 aLSp.Mode = style::LineSpacingMode::MINIMUM;
109 if (!rUnitConverter.convertMeasureToCore( nTemp, rStrImpValue, 0, 0xffff))
110 return false;
111 aLSp.Height = sal::static_int_cast< sal_Int16 >(nTemp);
112
113 rValue <<= aLSp;
114 return true;
115}
116
117bool XMLLineHeightAtLeastHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
118{
119 OUStringBuffer aOut;
120
121 style::LineSpacing aLSp;
122 if(!(rValue >>= aLSp))
123 return false;
124
125 if( style::LineSpacingMode::MINIMUM != aLSp.Mode )
126 return false;
127
128 rUnitConverter.convertMeasureToXML( aOut, aLSp.Height );
129
130 rStrExpValue = aOut.makeStringAndClear();
131 return !rStrExpValue.isEmpty();
132}
133
134
135
136
138{
139 // nothing to do
140}
141
142bool XMLLineSpacingHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
143{
144 style::LineSpacing aLSp;
145 sal_Int32 nTemp;
146
147 aLSp.Mode = style::LineSpacingMode::LEADING;
148 if (!rUnitConverter.convertMeasureToCore( nTemp, rStrImpValue, 0, 0xffff))
149 return false;
150 aLSp.Height = sal::static_int_cast< sal_Int16 >(nTemp);
151
152 rValue <<= aLSp;
153 return true;
154}
155
156bool XMLLineSpacingHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
157{
158 OUStringBuffer aOut;
159
160 style::LineSpacing aLSp;
161 if(!(rValue >>= aLSp))
162 return false;
163
164 if( style::LineSpacingMode::LEADING != aLSp.Mode )
165 return false;
166
167 rUnitConverter.convertMeasureToXML( aOut, aLSp.Height );
168
169 rStrExpValue = aOut.makeStringAndClear();
170 return !rStrExpValue.isEmpty();
171}
172
173/* 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
bool convertMeasureToCore(sal_Int32 &rValue, std::u16string_view rString, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32) const
convert string to measure with meCoreMeasureUnit, using optional min and max values
Definition: xmluconv.cxx:188
void convertMeasureToXML(OUStringBuffer &rBuffer, sal_Int32 nMeasure) const
convert measure to string: from meCoreMeasureUnit to meXMLMeasureUnit
Definition: xmluconv.cxx:208
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: lspachdl.cxx:103
virtual ~XMLLineHeightAtLeastHdl() override
Definition: lspachdl.cxx:98
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: lspachdl.cxx:117
virtual ~XMLLineHeightHdl() override
Definition: lspachdl.cxx:36
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: lspachdl.cxx:71
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: lspachdl.cxx:41
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: lspachdl.cxx:156
virtual ~XMLLineSpacingHdl() override
Definition: lspachdl.cxx:137
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: lspachdl.cxx:142
static bool convertPercent(sal_Int32 &rValue, std::u16string_view rString)
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3597