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