LibreOffice Module xmloff (master)  1
escphdl.cxx
Go to the documentation of this file.
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 #include "escphdl.hxx"
21 
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 using namespace ::com::sun::star;
30 using namespace ::xmloff::token;
31 
32 
33 
34 
36 {
37  // nothing to do
38 }
39 
40 bool XMLEscapementPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
41 {
42  sal_Int16 nVal;
43 
44  SvXMLTokenEnumerator aTokens( rStrImpValue );
45 
46  OUString aToken;
47  if( ! aTokens.getNextToken( aToken ) )
48  return false;
49 
50  if( IsXMLToken( aToken, XML_ESCAPEMENT_SUB ) )
51  {
52  nVal = DFLT_ESC_AUTO_SUB;
53  }
54  else if( IsXMLToken( aToken, XML_ESCAPEMENT_SUPER ) )
55  {
56  nVal = DFLT_ESC_AUTO_SUPER;
57  }
58  else
59  {
60  sal_Int32 nNewEsc;
61  if (!::sax::Converter::convertPercent( nNewEsc, aToken ))
62  return false;
63 
64  nVal = static_cast<sal_Int16>(nNewEsc);
65  }
66 
67  rValue <<= nVal;
68  return true;
69 }
70 
71 bool XMLEscapementPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
72 {
73  sal_Int32 nValue = 0;
74  OUStringBuffer aOut;
75 
76  if( rValue >>= nValue )
77  {
78  if( nValue == DFLT_ESC_AUTO_SUPER )
79  {
80  aOut.append( GetXMLToken(XML_ESCAPEMENT_SUPER) );
81  }
82  else if( nValue == DFLT_ESC_AUTO_SUB )
83  {
84  aOut.append( GetXMLToken(XML_ESCAPEMENT_SUB) );
85  }
86  else
87  {
88  ::sax::Converter::convertPercent( aOut, nValue );
89  }
90  }
91 
92  rStrExpValue = aOut.makeStringAndClear();
93  return !rStrExpValue.isEmpty();
94 }
95 
96 
97 
98 
100 {
101  // nothing to do
102 }
103 
104 bool XMLEscapementHeightPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
105 {
106  if( IsXMLToken( rStrImpValue, XML_CASEMAP_SMALL_CAPS ) )
107  return false;
108 
109  SvXMLTokenEnumerator aTokens( rStrImpValue );
110 
111  OUString aToken;
112  if( ! aTokens.getNextToken( aToken ) )
113  return false;
114 
115  sal_Int8 nProp;
116  if( aTokens.getNextToken( aToken ) )
117  {
118  sal_Int32 nNewProp;
119  if (!::sax::Converter::convertPercent( nNewProp, aToken ))
120  return false;
121  nProp = static_cast<sal_Int8>(nNewProp);
122  }
123  else
124  {
125  sal_Int32 nEscapementPosition=0;
126  if (::sax::Converter::convertPercent( nEscapementPosition, aToken )
127  && (nEscapementPosition == 0))
128  {
129  nProp = 100; //if escapement position is zero and no escapement height is given the default height should be 100percent and not something smaller (#i91800#)
130  }
131  else
132  nProp = sal_Int8(DFLT_ESC_PROP);
133  }
134 
135  rValue <<= nProp;
136  return true;
137 }
138 
139 bool XMLEscapementHeightPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
140 {
141  OUStringBuffer aOut( rStrExpValue );
142 
143  sal_Int32 nValue = 0;
144  if( rValue >>= nValue )
145  {
146  if( !rStrExpValue.isEmpty() )
147  aOut.append( ' ');
148 
149  ::sax::Converter::convertPercent( aOut, nValue );
150  }
151 
152  rStrExpValue = aOut.makeStringAndClear();
153  return !rStrExpValue.isEmpty();
154 }
155 
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual ~XMLEscapementHeightPropHdl() override
Definition: escphdl.cxx:99
bool IsXMLToken(const OUString &rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3434
the SvXMLTypeConverter converts values of various types from their internal representation to the tex...
Definition: xmluconv.hxx:77
signed char sal_Int8
virtual bool exportXML(OUString &rStrExpValue, const css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Exports the given value according to the XML-data-type corresponding to the derived class...
Definition: escphdl.cxx:139
virtual bool exportXML(OUString &rStrExpValue, const css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Exports the given value according to the XML-data-type corresponding to the derived class...
Definition: escphdl.cxx:71
#define DFLT_ESC_AUTO_SUB
bool getNextToken(OUString &rToken)
Definition: xmluconv.cxx:449
virtual ~XMLEscapementPropHdl() override
Definition: escphdl.cxx:35
css::uno::Any const & rValue
Definition: ImageStyle.hxx:38
#define DFLT_ESC_AUTO_SUPER
#define DFLT_ESC_PROP
virtual bool importXML(const OUString &rStrImpValue, css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Imports the given value according to the XML-data-type corresponding to the derived class...
Definition: escphdl.cxx:40
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
return the OUString representation for eToken
Definition: xmltoken.cxx:3378
Handling of tokens in XML:
virtual bool importXML(const OUString &rStrImpValue, css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Imports the given value according to the XML-data-type corresponding to the derived class...
Definition: escphdl.cxx:104
sal_Int16 nValue
static bool convertPercent(sal_Int32 &rValue, const OUString &rString)