Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <lspachdl.hxx>
30 : : #include <xmloff/xmltoken.hxx>
31 : : #include <xmloff/xmluconv.hxx>
32 : : #include <sax/tools/converter.hxx>
33 : : #include <rtl/ustrbuf.hxx>
34 : : #include <com/sun/star/uno/Any.hxx>
35 : : #include <com/sun/star/style/LineSpacing.hpp>
36 : : #include <com/sun/star/style/LineSpacingMode.hpp>
37 : :
38 : : using ::rtl::OUString;
39 : : using ::rtl::OUStringBuffer;
40 : :
41 : : using namespace ::com::sun::star;
42 : : using ::xmloff::token::IsXMLToken;
43 : : using ::xmloff::token::XML_CASEMAP_NORMAL;
44 : :
45 : : // this is a copy of defines in svx/inc/escpitem.hxx
46 : : #define DFLT_ESC_PROP 58
47 : : #define DFLT_ESC_AUTO_SUPER 101
48 : : #define DFLT_ESC_AUTO_SUB -101
49 : :
50 : : ///////////////////////////////////////////////////////////////////////////////
51 : : //
52 : : // class XMLEscapementPropHdl
53 : : //
54 : :
55 : 1722 : XMLLineHeightHdl::~XMLLineHeightHdl()
56 : : {
57 : : // nothing to do
58 [ - + ]: 3444 : }
59 : :
60 : 72 : sal_Bool XMLLineHeightHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
61 : : {
62 : 72 : style::LineSpacing aLSp;
63 : 72 : sal_Int32 nTemp = 0;
64 : :
65 [ + - ]: 72 : if( -1 != rStrImpValue.indexOf( sal_Unicode( '%' ) ) )
66 : : {
67 : 72 : aLSp.Mode = style::LineSpacingMode::PROP;
68 [ + - ][ - + ]: 72 : if (!::sax::Converter::convertPercent( nTemp, rStrImpValue ))
69 : 0 : return sal_False;
70 : 72 : aLSp.Height = sal::static_int_cast< sal_Int16 >(nTemp);
71 : : }
72 [ # # ][ # # ]: 0 : else if( IsXMLToken( rStrImpValue, XML_CASEMAP_NORMAL) )
73 : : {
74 : 0 : aLSp.Mode = style::LineSpacingMode::PROP;
75 : 0 : aLSp.Height = 100;
76 : : }
77 : : else
78 : : {
79 : 0 : aLSp.Mode = style::LineSpacingMode::FIX;
80 [ # # ]: 0 : if (!rUnitConverter.convertMeasureToCore(
81 [ # # ]: 0 : nTemp, rStrImpValue, 0x0000, 0xffff))
82 : 0 : return sal_False;
83 : 0 : aLSp.Height = sal::static_int_cast< sal_Int16 >(nTemp);
84 : : }
85 : :
86 [ + - ]: 72 : rValue <<= aLSp;
87 : 72 : return sal_True;
88 : : }
89 : :
90 : 24 : sal_Bool XMLLineHeightHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
91 : : {
92 : 24 : OUStringBuffer aOut;
93 : :
94 : 24 : style::LineSpacing aLSp;
95 [ - + ][ + - ]: 24 : if(!(rValue >>= aLSp))
96 : 0 : return sal_False;
97 : :
98 [ - + ][ # # ]: 24 : if( style::LineSpacingMode::PROP != aLSp.Mode && style::LineSpacingMode::FIX != aLSp.Mode )
99 : 0 : return sal_False;
100 : :
101 [ + - ]: 24 : if( style::LineSpacingMode::PROP == aLSp.Mode )
102 : : {
103 [ + - ]: 24 : ::sax::Converter::convertPercent( aOut, aLSp.Height );
104 : : }
105 : : else
106 : : {
107 [ # # ]: 0 : rUnitConverter.convertMeasureToXML( aOut, aLSp.Height );
108 : : }
109 : :
110 [ + - ]: 24 : rStrExpValue = aOut.makeStringAndClear();
111 : 24 : return !rStrExpValue.isEmpty();
112 : : }
113 : :
114 : : ///////////////////////////////////////////////////////////////////////////////
115 : : //
116 : : // class XMLLineHeightAtLeastHdl
117 : : //
118 : :
119 : 1722 : XMLLineHeightAtLeastHdl::~XMLLineHeightAtLeastHdl()
120 : : {
121 : : // nothing to do
122 [ - + ]: 3444 : }
123 : :
124 : 0 : sal_Bool XMLLineHeightAtLeastHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
125 : : {
126 : 0 : style::LineSpacing aLSp;
127 : :
128 : : sal_Int32 nTemp;
129 : 0 : aLSp.Mode = style::LineSpacingMode::MINIMUM;
130 [ # # ][ # # ]: 0 : if (!rUnitConverter.convertMeasureToCore( nTemp, rStrImpValue, 0, 0xffff))
131 : 0 : return sal_False;
132 : 0 : aLSp.Height = sal::static_int_cast< sal_Int16 >(nTemp);
133 : :
134 [ # # ]: 0 : rValue <<= aLSp;
135 : 0 : return sal_True;
136 : : }
137 : :
138 : 24 : sal_Bool XMLLineHeightAtLeastHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
139 : : {
140 : 24 : OUStringBuffer aOut;
141 : :
142 : 24 : style::LineSpacing aLSp;
143 [ - + ][ + - ]: 24 : if(!(rValue >>= aLSp))
144 : 0 : return sal_False;
145 : :
146 [ + - ]: 24 : if( style::LineSpacingMode::MINIMUM != aLSp.Mode )
147 : 24 : return sal_False;
148 : :
149 [ # # ]: 0 : rUnitConverter.convertMeasureToXML( aOut, aLSp.Height );
150 : :
151 [ # # ]: 0 : rStrExpValue = aOut.makeStringAndClear();
152 : 24 : return !rStrExpValue.isEmpty();
153 : : }
154 : :
155 : : ///////////////////////////////////////////////////////////////////////////////
156 : : //
157 : : // class XMLLineSpacingHdl
158 : : //
159 : :
160 : 1722 : XMLLineSpacingHdl::~XMLLineSpacingHdl()
161 : : {
162 : : // nothing to do
163 [ - + ]: 3444 : }
164 : :
165 : 0 : sal_Bool XMLLineSpacingHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
166 : : {
167 : 0 : style::LineSpacing aLSp;
168 : : sal_Int32 nTemp;
169 : :
170 : 0 : aLSp.Mode = style::LineSpacingMode::LEADING;
171 [ # # ][ # # ]: 0 : if (!rUnitConverter.convertMeasureToCore( nTemp, rStrImpValue, 0, 0xffff))
172 : 0 : return sal_False;
173 : 0 : aLSp.Height = sal::static_int_cast< sal_Int16 >(nTemp);
174 : :
175 [ # # ]: 0 : rValue <<= aLSp;
176 : 0 : return sal_True;
177 : : }
178 : :
179 : 24 : sal_Bool XMLLineSpacingHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
180 : : {
181 : 24 : OUStringBuffer aOut;
182 : :
183 : 24 : style::LineSpacing aLSp;
184 [ - + ][ + - ]: 24 : if(!(rValue >>= aLSp))
185 : 0 : return sal_False;
186 : :
187 [ + - ]: 24 : if( style::LineSpacingMode::LEADING != aLSp.Mode )
188 : 24 : return sal_False;
189 : :
190 [ # # ]: 0 : rUnitConverter.convertMeasureToXML( aOut, aLSp.Height );
191 : :
192 [ # # ]: 0 : rStrExpValue = aOut.makeStringAndClear();
193 : 24 : return !rStrExpValue.isEmpty();
194 : : }
195 : :
196 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|