bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / style / escphdl.cxx
blob957370688dc693e136c8511c29583ddd1c48aebe
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <escphdl.hxx>
22 #include <sax/tools/converter.hxx>
23 #include <xmloff/xmltoken.hxx>
24 #include <xmloff/xmluconv.hxx>
25 #include <rtl/ustrbuf.hxx>
26 #include <com/sun/star/uno/Any.hxx>
28 using namespace ::com::sun::star;
29 using namespace ::xmloff::token;
31 // this is a copy of defines in svx/inc/escpitem.hxx
32 #define DFLT_ESC_PROP 58
33 #define DFLT_ESC_AUTO_SUPER 101
34 #define DFLT_ESC_AUTO_SUB -101
37 // class XMLEscapementPropHdl
40 XMLEscapementPropHdl::~XMLEscapementPropHdl()
42 // nothing to do
45 bool XMLEscapementPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
47 sal_Int16 nVal;
49 SvXMLTokenEnumerator aTokens( rStrImpValue );
51 OUString aToken;
52 if( ! aTokens.getNextToken( aToken ) )
53 return false;
55 if( IsXMLToken( aToken, XML_ESCAPEMENT_SUB ) )
57 nVal = DFLT_ESC_AUTO_SUB;
59 else if( IsXMLToken( aToken, XML_ESCAPEMENT_SUPER ) )
61 nVal = DFLT_ESC_AUTO_SUPER;
63 else
65 sal_Int32 nNewEsc;
66 if (!::sax::Converter::convertPercent( nNewEsc, aToken ))
67 return false;
69 nVal = (sal_Int16) nNewEsc;
72 rValue <<= nVal;
73 return true;
76 bool XMLEscapementPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
78 sal_Int32 nValue = 0;
79 OUStringBuffer aOut;
81 if( rValue >>= nValue )
83 if( nValue == DFLT_ESC_AUTO_SUPER )
85 aOut.append( GetXMLToken(XML_ESCAPEMENT_SUPER) );
87 else if( nValue == DFLT_ESC_AUTO_SUB )
89 aOut.append( GetXMLToken(XML_ESCAPEMENT_SUB) );
91 else
93 ::sax::Converter::convertPercent( aOut, nValue );
97 rStrExpValue = aOut.makeStringAndClear();
98 return true;
102 // class XMLEscapementHeightPropHdl
105 XMLEscapementHeightPropHdl::~XMLEscapementHeightPropHdl()
107 // nothing to do
110 bool XMLEscapementHeightPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
112 if( IsXMLToken( rStrImpValue, XML_CASEMAP_SMALL_CAPS ) )
113 return false;
115 SvXMLTokenEnumerator aTokens( rStrImpValue );
117 OUString aToken;
118 if( ! aTokens.getNextToken( aToken ) )
119 return false;
121 sal_Int8 nProp;
122 if( aTokens.getNextToken( aToken ) )
124 sal_Int32 nNewProp;
125 if (!::sax::Converter::convertPercent( nNewProp, aToken ))
126 return false;
127 nProp = (sal_Int8)nNewProp;
129 else
131 sal_Int32 nEscapementPosition=0;
132 if (::sax::Converter::convertPercent( nEscapementPosition, aToken )
133 && (nEscapementPosition == 0))
135 nProp = 100; //if escapement position is zero and no escapement height is given the default height should be 100percent and not something smaller (#i91800#)
137 else
138 nProp = (sal_Int8) DFLT_ESC_PROP;
141 rValue <<= nProp;
142 return true;
145 bool XMLEscapementHeightPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
147 OUStringBuffer aOut( rStrExpValue );
149 sal_Int32 nValue = 0;
150 if( rValue >>= nValue )
152 if( !rStrExpValue.isEmpty() )
153 aOut.append( ' ');
155 ::sax::Converter::convertPercent( aOut, nValue );
158 rStrExpValue = aOut.makeStringAndClear();
159 return !rStrExpValue.isEmpty();
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */