1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmloff.hxx"
26
27
28 #include <escphdl.hxx>
29 #include <xmloff/xmltoken.hxx>
30 #include <xmloff/xmluconv.hxx>
31 #include <rtl/ustrbuf.hxx>
32 #include <com/sun/star/uno/Any.hxx>
33
34 using ::rtl::OUString;
35 using ::rtl::OUStringBuffer;
36
37 using namespace ::com::sun::star;
38 using namespace ::xmloff::token;
39
40 // this is a copy of defines in svx/inc/escpitem.hxx
41 #define DFLT_ESC_PROP 58
42 #define DFLT_ESC_AUTO_SUPER 101
43 #define DFLT_ESC_AUTO_SUB -101
44
45 ///////////////////////////////////////////////////////////////////////////////
46 //
47 // class XMLEscapementPropHdl
48 //
49
~XMLEscapementPropHdl()50 XMLEscapementPropHdl::~XMLEscapementPropHdl()
51 {
52 // nothing to do
53 }
54
importXML(const OUString & rStrImpValue,uno::Any & rValue,const SvXMLUnitConverter &) const55 sal_Bool XMLEscapementPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
56 {
57 sal_Int16 nVal;
58
59 SvXMLTokenEnumerator aTokens( rStrImpValue );
60
61 OUString aToken;
62 if( ! aTokens.getNextToken( aToken ) )
63 return sal_False;
64
65 if( IsXMLToken( aToken, XML_ESCAPEMENT_SUB ) )
66 {
67 nVal = DFLT_ESC_AUTO_SUB;
68 }
69 else if( IsXMLToken( aToken, XML_ESCAPEMENT_SUPER ) )
70 {
71 nVal = DFLT_ESC_AUTO_SUPER;
72 }
73 else
74 {
75 sal_Int32 nNewEsc;
76 if( !SvXMLUnitConverter::convertPercent( nNewEsc, aToken ) )
77 return sal_False;
78
79 nVal = (sal_Int16) nNewEsc;
80 }
81
82 rValue <<= nVal;
83 return sal_True;
84 }
85
exportXML(OUString & rStrExpValue,const uno::Any & rValue,const SvXMLUnitConverter &) const86 sal_Bool XMLEscapementPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
87 {
88 sal_Int32 nValue = 0;
89 OUStringBuffer aOut;
90
91 if( rValue >>= nValue )
92 {
93 if( nValue == DFLT_ESC_AUTO_SUPER )
94 {
95 aOut.append( GetXMLToken(XML_ESCAPEMENT_SUPER) );
96 }
97 else if( nValue == DFLT_ESC_AUTO_SUB )
98 {
99 aOut.append( GetXMLToken(XML_ESCAPEMENT_SUB) );
100 }
101 else
102 {
103 SvXMLUnitConverter::convertPercent( aOut, nValue );
104 }
105 }
106
107 rStrExpValue = aOut.makeStringAndClear();
108 return sal_True;
109 }
110
111 ///////////////////////////////////////////////////////////////////////////////
112 //
113 // class XMLEscapementHeightPropHdl
114 //
115
~XMLEscapementHeightPropHdl()116 XMLEscapementHeightPropHdl::~XMLEscapementHeightPropHdl()
117 {
118 // nothing to do
119 }
120
importXML(const OUString & rStrImpValue,uno::Any & rValue,const SvXMLUnitConverter &) const121 sal_Bool XMLEscapementHeightPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
122 {
123 if( IsXMLToken( rStrImpValue, XML_CASEMAP_SMALL_CAPS ) )
124 return sal_False;
125
126 SvXMLTokenEnumerator aTokens( rStrImpValue );
127
128 OUString aToken;
129 if( ! aTokens.getNextToken( aToken ) )
130 return sal_False;
131
132 sal_Int8 nProp;
133 if( aTokens.getNextToken( aToken ) )
134 {
135 sal_Int32 nNewProp;
136 if( !SvXMLUnitConverter::convertPercent( nNewProp, aToken ) )
137 return sal_False;
138 nProp = (sal_Int8)nNewProp;
139 }
140 else
141 {
142 sal_Int32 nEscapementPosition=0;
143 if( SvXMLUnitConverter::convertPercent( nEscapementPosition, aToken ) && nEscapementPosition==0 )
144 nProp = 100; //if escapement position is zero and no escapement height is given the default height should be 100percent and not something smaller (#i91800#)
145 else
146 nProp = (sal_Int8) DFLT_ESC_PROP;
147 }
148
149 rValue <<= nProp;
150 return sal_True;
151 }
152
exportXML(OUString & rStrExpValue,const uno::Any & rValue,const SvXMLUnitConverter &) const153 sal_Bool XMLEscapementHeightPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
154 {
155 OUStringBuffer aOut( rStrExpValue );
156
157 sal_Int32 nValue = 0;
158 if( rValue >>= nValue )
159 {
160 if( rStrExpValue.getLength() )
161 aOut.append( sal_Unicode(' '));
162
163 SvXMLUnitConverter::convertPercent( aOut, nValue );
164 }
165
166 rStrExpValue = aOut.makeStringAndClear();
167 return rStrExpValue.getLength() != 0;
168 }
169