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 : :
30 : : #include <escphdl.hxx>
31 : :
32 : : #include <sax/tools/converter.hxx>
33 : : #include <xmloff/xmltoken.hxx>
34 : : #include <xmloff/xmluconv.hxx>
35 : : #include <rtl/ustrbuf.hxx>
36 : : #include <com/sun/star/uno/Any.hxx>
37 : :
38 : : using ::rtl::OUString;
39 : : using ::rtl::OUStringBuffer;
40 : :
41 : : using namespace ::com::sun::star;
42 : : using namespace ::xmloff::token;
43 : :
44 : : // this is a copy of defines in svx/inc/escpitem.hxx
45 : : #define DFLT_ESC_PROP 58
46 : : #define DFLT_ESC_AUTO_SUPER 101
47 : : #define DFLT_ESC_AUTO_SUB -101
48 : :
49 : : ///////////////////////////////////////////////////////////////////////////////
50 : : //
51 : : // class XMLEscapementPropHdl
52 : : //
53 : :
54 : 2285 : XMLEscapementPropHdl::~XMLEscapementPropHdl()
55 : : {
56 : : // nothing to do
57 [ - + ]: 4570 : }
58 : :
59 : 52 : sal_Bool XMLEscapementPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
60 : : {
61 : : sal_Int16 nVal;
62 : :
63 [ + - ]: 52 : SvXMLTokenEnumerator aTokens( rStrImpValue );
64 : :
65 : 52 : OUString aToken;
66 [ - + ][ + - ]: 52 : if( ! aTokens.getNextToken( aToken ) )
67 : 0 : return sal_False;
68 : :
69 [ + - ][ + + ]: 52 : if( IsXMLToken( aToken, XML_ESCAPEMENT_SUB ) )
70 : : {
71 : 2 : nVal = DFLT_ESC_AUTO_SUB;
72 : : }
73 [ + - ][ + + ]: 50 : else if( IsXMLToken( aToken, XML_ESCAPEMENT_SUPER ) )
74 : : {
75 : 12 : nVal = DFLT_ESC_AUTO_SUPER;
76 : : }
77 : : else
78 : : {
79 : : sal_Int32 nNewEsc;
80 [ + - ][ - + ]: 38 : if (!::sax::Converter::convertPercent( nNewEsc, aToken ))
81 : 0 : return sal_False;
82 : :
83 : 38 : nVal = (sal_Int16) nNewEsc;
84 : : }
85 : :
86 [ + - ]: 52 : rValue <<= nVal;
87 : 52 : return sal_True;
88 : : }
89 : :
90 : 0 : sal_Bool XMLEscapementPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
91 : : {
92 : 0 : sal_Int32 nValue = 0;
93 : 0 : OUStringBuffer aOut;
94 : :
95 [ # # ]: 0 : if( rValue >>= nValue )
96 : : {
97 [ # # ]: 0 : if( nValue == DFLT_ESC_AUTO_SUPER )
98 : : {
99 [ # # ][ # # ]: 0 : aOut.append( GetXMLToken(XML_ESCAPEMENT_SUPER) );
100 : : }
101 [ # # ]: 0 : else if( nValue == DFLT_ESC_AUTO_SUB )
102 : : {
103 [ # # ][ # # ]: 0 : aOut.append( GetXMLToken(XML_ESCAPEMENT_SUB) );
104 : : }
105 : : else
106 : : {
107 [ # # ]: 0 : ::sax::Converter::convertPercent( aOut, nValue );
108 : : }
109 : : }
110 : :
111 [ # # ]: 0 : rStrExpValue = aOut.makeStringAndClear();
112 : 0 : return sal_True;
113 : : }
114 : :
115 : : ///////////////////////////////////////////////////////////////////////////////
116 : : //
117 : : // class XMLEscapementHeightPropHdl
118 : : //
119 : :
120 : 2285 : XMLEscapementHeightPropHdl::~XMLEscapementHeightPropHdl()
121 : : {
122 : : // nothing to do
123 [ - + ]: 4570 : }
124 : :
125 : 52 : sal_Bool XMLEscapementHeightPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
126 : : {
127 [ + - ][ - + ]: 52 : if( IsXMLToken( rStrImpValue, XML_CASEMAP_SMALL_CAPS ) )
128 : 0 : return sal_False;
129 : :
130 [ + - ]: 52 : SvXMLTokenEnumerator aTokens( rStrImpValue );
131 : :
132 : 52 : OUString aToken;
133 [ - + ][ + - ]: 52 : if( ! aTokens.getNextToken( aToken ) )
134 : 0 : return sal_False;
135 : :
136 : : sal_Int8 nProp;
137 [ + - ][ + + ]: 52 : if( aTokens.getNextToken( aToken ) )
138 : : {
139 : : sal_Int32 nNewProp;
140 [ + - ][ - + ]: 16 : if (!::sax::Converter::convertPercent( nNewProp, aToken ))
141 : 0 : return sal_False;
142 : 16 : nProp = (sal_Int8)nNewProp;
143 : : }
144 : : else
145 : : {
146 : 36 : sal_Int32 nEscapementPosition=0;
147 [ + - ][ + - ]: 36 : if (::sax::Converter::convertPercent( nEscapementPosition, aToken )
[ + - ][ + - ]
148 : : && (nEscapementPosition == 0))
149 : : {
150 : 36 : nProp = 100; //if escapement position is zero and no escapement height is given the default height should be 100percent and not something smaller (#i91800#)
151 : : }
152 : : else
153 : 36 : nProp = (sal_Int8) DFLT_ESC_PROP;
154 : : }
155 : :
156 [ + - ]: 52 : rValue <<= nProp;
157 : 52 : return sal_True;
158 : : }
159 : :
160 : 0 : sal_Bool XMLEscapementHeightPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
161 : : {
162 [ # # ]: 0 : OUStringBuffer aOut( rStrExpValue );
163 : :
164 : 0 : sal_Int32 nValue = 0;
165 [ # # ]: 0 : if( rValue >>= nValue )
166 : : {
167 [ # # ]: 0 : if( !rStrExpValue.isEmpty() )
168 [ # # ]: 0 : aOut.append( sal_Unicode(' '));
169 : :
170 [ # # ]: 0 : ::sax::Converter::convertPercent( aOut, nValue );
171 : : }
172 : :
173 [ # # ]: 0 : rStrExpValue = aOut.makeStringAndClear();
174 : 0 : return !rStrExpValue.isEmpty();
175 : : }
176 : :
177 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|