1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 #include <escphdl.hxx>
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>
30 using namespace ::com::sun::star
;
31 using namespace ::xmloff::token
;
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
38 ///////////////////////////////////////////////////////////////////////////////
40 // class XMLEscapementPropHdl
43 XMLEscapementPropHdl::~XMLEscapementPropHdl()
48 sal_Bool
XMLEscapementPropHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
52 SvXMLTokenEnumerator
aTokens( rStrImpValue
);
55 if( ! aTokens
.getNextToken( aToken
) )
58 if( IsXMLToken( aToken
, XML_ESCAPEMENT_SUB
) )
60 nVal
= DFLT_ESC_AUTO_SUB
;
62 else if( IsXMLToken( aToken
, XML_ESCAPEMENT_SUPER
) )
64 nVal
= DFLT_ESC_AUTO_SUPER
;
69 if (!::sax::Converter::convertPercent( nNewEsc
, aToken
))
72 nVal
= (sal_Int16
) nNewEsc
;
79 sal_Bool
XMLEscapementPropHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
84 if( rValue
>>= nValue
)
86 if( nValue
== DFLT_ESC_AUTO_SUPER
)
88 aOut
.append( GetXMLToken(XML_ESCAPEMENT_SUPER
) );
90 else if( nValue
== DFLT_ESC_AUTO_SUB
)
92 aOut
.append( GetXMLToken(XML_ESCAPEMENT_SUB
) );
96 ::sax::Converter::convertPercent( aOut
, nValue
);
100 rStrExpValue
= aOut
.makeStringAndClear();
104 ///////////////////////////////////////////////////////////////////////////////
106 // class XMLEscapementHeightPropHdl
109 XMLEscapementHeightPropHdl::~XMLEscapementHeightPropHdl()
114 sal_Bool
XMLEscapementHeightPropHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
116 if( IsXMLToken( rStrImpValue
, XML_CASEMAP_SMALL_CAPS
) )
119 SvXMLTokenEnumerator
aTokens( rStrImpValue
);
122 if( ! aTokens
.getNextToken( aToken
) )
126 if( aTokens
.getNextToken( aToken
) )
129 if (!::sax::Converter::convertPercent( nNewProp
, aToken
))
131 nProp
= (sal_Int8
)nNewProp
;
135 sal_Int32 nEscapementPosition
=0;
136 if (::sax::Converter::convertPercent( nEscapementPosition
, aToken
)
137 && (nEscapementPosition
== 0))
139 nProp
= 100; //if escapement position is zero and no escapement height is given the default height should be 100percent and not something smaller (#i91800#)
142 nProp
= (sal_Int8
) DFLT_ESC_PROP
;
149 sal_Bool
XMLEscapementHeightPropHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
151 OUStringBuffer
aOut( rStrExpValue
);
153 sal_Int32 nValue
= 0;
154 if( rValue
>>= nValue
)
156 if( !rStrExpValue
.isEmpty() )
157 aOut
.append( sal_Unicode(' '));
159 ::sax::Converter::convertPercent( aOut
, nValue
);
162 rStrExpValue
= aOut
.makeStringAndClear();
163 return !rStrExpValue
.isEmpty();
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */