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 .
20 #include <xmloff/controlpropertyhdl.hxx>
22 #include <com/sun/star/util/MeasureUnit.hpp>
23 #include <com/sun/star/awt/TextAlign.hpp>
24 #include <com/sun/star/awt/FontEmphasisMark.hpp>
26 #include <sax/tools/converter.hxx>
28 #include <xmloff/xmltypes.hxx>
29 #include <xmloff/NamedBoolPropertyHdl.hxx>
30 #include "formenums.hxx"
31 #include <xmloff/xmluconv.hxx>
32 #include <xmloff/xmltoken.hxx>
33 #include <rtl/ustrbuf.hxx>
34 #include <xmloff/XMLConstantsPropertyHandler.hxx>
39 using namespace ::com::sun::star
;
40 using namespace ::com::sun::star::uno
;
41 using namespace ::com::sun::star::awt
;
42 using namespace ::com::sun::star::beans
;
43 using namespace ::xmloff::token
;
45 //= OControlPropertyHandlerFactory
46 OControlPropertyHandlerFactory::OControlPropertyHandlerFactory()
50 const XMLPropertyHandler
* OControlPropertyHandlerFactory::GetPropertyHandler(sal_Int32 _nType
) const
52 const XMLPropertyHandler
* pHandler
= nullptr;
56 case XML_TYPE_TEXT_ALIGN
:
57 if (!m_pTextAlignHandler
)
58 m_pTextAlignHandler
= std::make_unique
<XMLConstantsPropertyHandler
>(aTextAlignMap
, XML_TOKEN_INVALID
);
59 pHandler
= m_pTextAlignHandler
.get();
62 case XML_TYPE_CONTROL_BORDER
:
63 if (!m_pControlBorderStyleHandler
)
64 m_pControlBorderStyleHandler
= std::make_unique
<OControlBorderHandler
>( OControlBorderHandler::STYLE
);
65 pHandler
= m_pControlBorderStyleHandler
.get();
68 case XML_TYPE_CONTROL_BORDER_COLOR
:
69 if ( !m_pControlBorderColorHandler
)
70 m_pControlBorderColorHandler
= std::make_unique
<OControlBorderHandler
>( OControlBorderHandler::COLOR
);
71 pHandler
= m_pControlBorderColorHandler
.get();
74 case XML_TYPE_ROTATION_ANGLE
:
75 if (!m_pRotationAngleHandler
)
76 m_pRotationAngleHandler
= std::make_unique
<ORotationAngleHandler
>();
77 pHandler
= m_pRotationAngleHandler
.get();
80 case XML_TYPE_FONT_WIDTH
:
81 if (!m_pFontWidthHandler
)
82 m_pFontWidthHandler
= std::make_unique
<OFontWidthHandler
>();
83 pHandler
= m_pFontWidthHandler
.get();
86 case XML_TYPE_CONTROL_TEXT_EMPHASIZE
:
87 if (!m_pFontEmphasisHandler
)
88 m_pFontEmphasisHandler
= std::make_unique
<XMLConstantsPropertyHandler
>( aFontEmphasisMap
, XML_NONE
);
89 pHandler
= m_pFontEmphasisHandler
.get();
92 case XML_TYPE_TEXT_FONT_RELIEF
:
93 if (!m_pFontReliefHandler
)
94 m_pFontReliefHandler
= std::make_unique
<XMLConstantsPropertyHandler
>( aFontReliefMap
, XML_NONE
);
95 pHandler
= m_pFontReliefHandler
.get();
97 case XML_TYPE_TEXT_LINE_MODE
:
98 if (!m_pTextLineModeHandler
)
100 m_pTextLineModeHandler
= std::make_unique
<XMLNamedBoolPropertyHdl
>(
101 ::xmloff::token::XML_SKIP_WHITE_SPACE
,
102 ::xmloff::token::XML_CONTINUOUS
);
104 pHandler
= m_pTextLineModeHandler
.get();
109 pHandler
= XMLPropertyHandlerFactory::GetPropertyHandler(_nType
);
113 //= OControlTextEmphasisHandler
114 OControlTextEmphasisHandler::OControlTextEmphasisHandler()
118 bool OControlTextEmphasisHandler::exportXML( OUString
& _rStrExpValue
, const Any
& _rValue
, const SvXMLUnitConverter
& ) const
120 bool bSuccess
= false;
121 sal_Int16 nFontEmphasis
= sal_Int16();
122 if (_rValue
>>= nFontEmphasis
)
125 sal_uInt16 nType
= nFontEmphasis
& ~(awt::FontEmphasisMark::ABOVE
| awt::FontEmphasisMark::BELOW
);
126 // the position of the mark
127 bool bBelow
= 0 != (nFontEmphasis
& awt::FontEmphasisMark::BELOW
);
130 OUStringBuffer aReturn
;
131 bSuccess
= SvXMLUnitConverter::convertEnum(aReturn
, nType
, aFontEmphasisMap
, XML_NONE
);
134 aReturn
.append( ' ' );
135 aReturn
.append( GetXMLToken(bBelow
? XML_BELOW
: XML_ABOVE
) );
137 _rStrExpValue
= aReturn
.makeStringAndClear();
144 bool OControlTextEmphasisHandler::importXML( const OUString
& _rStrImpValue
, Any
& _rValue
, const SvXMLUnitConverter
& ) const
146 bool bSuccess
= true;
147 sal_uInt16 nEmphasis
= awt::FontEmphasisMark::NONE
;
150 bool bHasPos
= false, bHasType
= false;
152 std::u16string_view sToken
;
153 SvXMLTokenEnumerator
aTokenEnum(_rStrImpValue
);
154 while (aTokenEnum
.getNextToken(sToken
))
158 if (IsXMLToken(sToken
, XML_ABOVE
))
163 else if (IsXMLToken(sToken
, XML_BELOW
))
171 if (SvXMLUnitConverter::convertEnum(nEmphasis
, sToken
, aFontEmphasisMap
))
185 nEmphasis
|= bBelow
? awt::FontEmphasisMark::BELOW
: awt::FontEmphasisMark::ABOVE
;
186 _rValue
<<= nEmphasis
;
192 //= OControlBorderHandlerBase
193 OControlBorderHandler::OControlBorderHandler( const OControlBorderHandler::BorderFacet _eFacet
)
198 bool OControlBorderHandler::importXML( const OUString
& _rStrImpValue
, Any
& _rValue
, const SvXMLUnitConverter
& ) const
200 std::u16string_view sToken
;
201 SvXMLTokenEnumerator
aTokens(_rStrImpValue
);
203 sal_uInt16 nStyle
= 1;
205 while ( aTokens
.getNextToken(sToken
) // have a new token
206 && (!sToken
.empty()) // really have a new token
209 // try interpreting the token as border style
210 if ( m_eFacet
== STYLE
)
212 // is it a valid enum value?
213 if ( SvXMLUnitConverter::convertEnum( nStyle
, sToken
, aBorderTypeMap
) )
220 // try interpreting it as color value
221 if ( m_eFacet
== COLOR
)
224 if (::sax::Converter::convertColor( nColor
, sToken
))
235 bool OControlBorderHandler::exportXML( OUString
& _rStrExpValue
, const Any
& _rValue
, const SvXMLUnitConverter
& ) const
237 bool bSuccess
= false;
244 sal_uInt16 nBorder
= 0;
245 bSuccess
= (_rValue
>>= nBorder
)
246 && SvXMLUnitConverter::convertEnum( aOut
, nBorder
, aBorderTypeMap
);
251 sal_Int32 nBorderColor
= 0;
252 if ( _rValue
>>= nBorderColor
)
254 ::sax::Converter::convertColor(aOut
, nBorderColor
);
259 } // switch ( m_eFacet )
264 if ( !_rStrExpValue
.isEmpty() )
265 _rStrExpValue
+= " ";
266 _rStrExpValue
+= aOut
;
271 //= OFontWidthHandler
272 OFontWidthHandler::OFontWidthHandler()
276 bool OFontWidthHandler::importXML( const OUString
& _rStrImpValue
, Any
& _rValue
, const SvXMLUnitConverter
& ) const
278 sal_Int32 nWidth
= 0;
279 bool const bSuccess
= ::sax::Converter::convertMeasure(
280 nWidth
, _rStrImpValue
, util::MeasureUnit::POINT
);
282 _rValue
<<= static_cast<sal_Int16
>(nWidth
);
287 bool OFontWidthHandler::exportXML( OUString
& _rStrExpValue
, const Any
& _rValue
, const SvXMLUnitConverter
& ) const
289 sal_Int16 nWidth
= 0;
290 OUStringBuffer aResult
;
291 if (_rValue
>>= nWidth
)
293 ::sax::Converter::convertMeasure(aResult
, nWidth
,
294 util::MeasureUnit::POINT
, util::MeasureUnit::POINT
);
296 _rStrExpValue
= aResult
.makeStringAndClear();
298 return !_rStrExpValue
.isEmpty();
301 //= ORotationAngleHandler
302 ORotationAngleHandler::ORotationAngleHandler()
306 bool ORotationAngleHandler::importXML( const OUString
& _rStrImpValue
, Any
& _rValue
, const SvXMLUnitConverter
& ) const
310 ::sax::Converter::convertDouble(fValue
, _rStrImpValue
);
314 _rValue
<<= static_cast<float>(fValue
);
320 bool ORotationAngleHandler::exportXML( OUString
& _rStrExpValue
, const Any
& _rValue
, const SvXMLUnitConverter
& ) const
323 bool bSuccess
= (_rValue
>>= fAngle
);
327 OUStringBuffer sValue
;
328 ::sax::Converter::convertDouble(sValue
, static_cast<double>(fAngle
) / 10);
329 _rStrExpValue
= sValue
.makeStringAndClear();
335 //= ImageScaleModeHandler
336 ImageScaleModeHandler::ImageScaleModeHandler()
337 :XMLConstantsPropertyHandler( aScaleModeMap
, XML_STRETCH
)
341 } // namespace xmloff
343 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */