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 : #include <lspachdl.hxx>
21 : #include <xmloff/xmltoken.hxx>
22 : #include <xmloff/xmluconv.hxx>
23 : #include <sax/tools/converter.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 :
29 :
30 : using namespace ::com::sun::star;
31 : using ::xmloff::token::IsXMLToken;
32 : using ::xmloff::token::XML_CASEMAP_NORMAL;
33 :
34 : ///////////////////////////////////////////////////////////////////////////////
35 : //
36 : // class XMLEscapementPropHdl
37 : //
38 :
39 2866 : XMLLineHeightHdl::~XMLLineHeightHdl()
40 : {
41 : // nothing to do
42 2866 : }
43 :
44 51 : sal_Bool XMLLineHeightHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
45 : {
46 51 : style::LineSpacing aLSp;
47 51 : sal_Int32 nTemp = 0;
48 :
49 51 : if( -1 != rStrImpValue.indexOf( sal_Unicode( '%' ) ) )
50 : {
51 51 : aLSp.Mode = style::LineSpacingMode::PROP;
52 51 : if (!::sax::Converter::convertPercent( nTemp, rStrImpValue ))
53 0 : return sal_False;
54 51 : aLSp.Height = sal::static_int_cast< sal_Int16 >(nTemp);
55 : }
56 0 : else if( IsXMLToken( rStrImpValue, XML_CASEMAP_NORMAL) )
57 : {
58 0 : aLSp.Mode = style::LineSpacingMode::PROP;
59 0 : aLSp.Height = 100;
60 : }
61 : else
62 : {
63 0 : aLSp.Mode = style::LineSpacingMode::FIX;
64 0 : if (!rUnitConverter.convertMeasureToCore(
65 0 : nTemp, rStrImpValue, 0x0000, 0xffff))
66 0 : return sal_False;
67 0 : aLSp.Height = sal::static_int_cast< sal_Int16 >(nTemp);
68 : }
69 :
70 51 : rValue <<= aLSp;
71 51 : return sal_True;
72 : }
73 :
74 31 : sal_Bool XMLLineHeightHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
75 : {
76 31 : OUStringBuffer aOut;
77 :
78 31 : style::LineSpacing aLSp;
79 31 : if(!(rValue >>= aLSp))
80 0 : return sal_False;
81 :
82 31 : if( style::LineSpacingMode::PROP != aLSp.Mode && style::LineSpacingMode::FIX != aLSp.Mode )
83 0 : return sal_False;
84 :
85 31 : if( style::LineSpacingMode::PROP == aLSp.Mode )
86 : {
87 31 : ::sax::Converter::convertPercent( aOut, aLSp.Height );
88 : }
89 : else
90 : {
91 0 : rUnitConverter.convertMeasureToXML( aOut, aLSp.Height );
92 : }
93 :
94 31 : rStrExpValue = aOut.makeStringAndClear();
95 31 : return !rStrExpValue.isEmpty();
96 : }
97 :
98 : ///////////////////////////////////////////////////////////////////////////////
99 : //
100 : // class XMLLineHeightAtLeastHdl
101 : //
102 :
103 2866 : XMLLineHeightAtLeastHdl::~XMLLineHeightAtLeastHdl()
104 : {
105 : // nothing to do
106 2866 : }
107 :
108 0 : sal_Bool XMLLineHeightAtLeastHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
109 : {
110 0 : style::LineSpacing aLSp;
111 :
112 : sal_Int32 nTemp;
113 0 : aLSp.Mode = style::LineSpacingMode::MINIMUM;
114 0 : if (!rUnitConverter.convertMeasureToCore( nTemp, rStrImpValue, 0, 0xffff))
115 0 : return sal_False;
116 0 : aLSp.Height = sal::static_int_cast< sal_Int16 >(nTemp);
117 :
118 0 : rValue <<= aLSp;
119 0 : return sal_True;
120 : }
121 :
122 31 : sal_Bool XMLLineHeightAtLeastHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
123 : {
124 31 : OUStringBuffer aOut;
125 :
126 31 : style::LineSpacing aLSp;
127 31 : if(!(rValue >>= aLSp))
128 0 : return sal_False;
129 :
130 31 : if( style::LineSpacingMode::MINIMUM != aLSp.Mode )
131 31 : return sal_False;
132 :
133 0 : rUnitConverter.convertMeasureToXML( aOut, aLSp.Height );
134 :
135 0 : rStrExpValue = aOut.makeStringAndClear();
136 0 : return !rStrExpValue.isEmpty();
137 : }
138 :
139 : ///////////////////////////////////////////////////////////////////////////////
140 : //
141 : // class XMLLineSpacingHdl
142 : //
143 :
144 2866 : XMLLineSpacingHdl::~XMLLineSpacingHdl()
145 : {
146 : // nothing to do
147 2866 : }
148 :
149 0 : sal_Bool XMLLineSpacingHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
150 : {
151 0 : style::LineSpacing aLSp;
152 : sal_Int32 nTemp;
153 :
154 0 : aLSp.Mode = style::LineSpacingMode::LEADING;
155 0 : if (!rUnitConverter.convertMeasureToCore( nTemp, rStrImpValue, 0, 0xffff))
156 0 : return sal_False;
157 0 : aLSp.Height = sal::static_int_cast< sal_Int16 >(nTemp);
158 :
159 0 : rValue <<= aLSp;
160 0 : return sal_True;
161 : }
162 :
163 31 : sal_Bool XMLLineSpacingHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
164 : {
165 31 : OUStringBuffer aOut;
166 :
167 31 : style::LineSpacing aLSp;
168 31 : if(!(rValue >>= aLSp))
169 0 : return sal_False;
170 :
171 31 : if( style::LineSpacingMode::LEADING != aLSp.Mode )
172 31 : return sal_False;
173 :
174 0 : rUnitConverter.convertMeasureToXML( aOut, aLSp.Height );
175 :
176 0 : rStrExpValue = aOut.makeStringAndClear();
177 0 : return !rStrExpValue.isEmpty();
178 : }
179 :
180 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|