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/FontEmphasisMark.hpp>
25 #include <sax/tools/converter.hxx>
27 #include <xmloff/xmltypes.hxx>
28 #include <xmloff/NamedBoolPropertyHdl.hxx>
29 #include "formenums.hxx"
30 #include <xmloff/xmluconv.hxx>
31 #include <xmloff/xmltoken.hxx>
32 #include <rtl/ustrbuf.hxx>
33 #include <xmloff/XMLConstantsPropertyHandler.hxx>
38 using namespace ::com::sun::star
;
39 using namespace ::com::sun::star::uno
;
40 using namespace ::com::sun::star::awt
;
41 using namespace ::com::sun::star::beans
;
42 using namespace ::xmloff::token
;
44 //= OControlPropertyHandlerFactory
45 OControlPropertyHandlerFactory::OControlPropertyHandlerFactory()
49 const XMLPropertyHandler
* OControlPropertyHandlerFactory::GetPropertyHandler(sal_Int32 _nType
) const
51 const XMLPropertyHandler
* pHandler
= nullptr;
55 case XML_TYPE_TEXT_ALIGN
:
56 if (!m_pTextAlignHandler
)
57 m_pTextAlignHandler
= std::make_unique
<XMLConstantsPropertyHandler
>(aTextAlignMap
, XML_TOKEN_INVALID
);
58 pHandler
= m_pTextAlignHandler
.get();
61 case XML_TYPE_CONTROL_BORDER
:
62 if (!m_pControlBorderStyleHandler
)
63 m_pControlBorderStyleHandler
= std::make_unique
<OControlBorderHandler
>( OControlBorderHandler::STYLE
);
64 pHandler
= m_pControlBorderStyleHandler
.get();
67 case XML_TYPE_CONTROL_BORDER_COLOR
:
68 if ( !m_pControlBorderColorHandler
)
69 m_pControlBorderColorHandler
= std::make_unique
<OControlBorderHandler
>( OControlBorderHandler::COLOR
);
70 pHandler
= m_pControlBorderColorHandler
.get();
73 case XML_TYPE_ROTATION_ANGLE
:
74 if (!m_pRotationAngleHandler
)
75 m_pRotationAngleHandler
= std::make_unique
<ORotationAngleHandler
>();
76 pHandler
= m_pRotationAngleHandler
.get();
79 case XML_TYPE_FONT_WIDTH
:
80 if (!m_pFontWidthHandler
)
81 m_pFontWidthHandler
= std::make_unique
<OFontWidthHandler
>();
82 pHandler
= m_pFontWidthHandler
.get();
85 case XML_TYPE_CONTROL_TEXT_EMPHASIZE
:
86 if (!m_pFontEmphasisHandler
)
87 m_pFontEmphasisHandler
= std::make_unique
<XMLConstantsPropertyHandler
>( aFontEmphasisMap
, XML_NONE
);
88 pHandler
= m_pFontEmphasisHandler
.get();
91 case XML_TYPE_TEXT_FONT_RELIEF
:
92 if (!m_pFontReliefHandler
)
93 m_pFontReliefHandler
= std::make_unique
<XMLConstantsPropertyHandler
>( aFontReliefMap
, XML_NONE
);
94 pHandler
= m_pFontReliefHandler
.get();
96 case XML_TYPE_TEXT_LINE_MODE
:
97 if (!m_pTextLineModeHandler
)
99 m_pTextLineModeHandler
= std::make_unique
<XMLNamedBoolPropertyHdl
>(
100 ::xmloff::token::XML_SKIP_WHITE_SPACE
,
101 ::xmloff::token::XML_CONTINUOUS
);
103 pHandler
= m_pTextLineModeHandler
.get();
108 pHandler
= XMLPropertyHandlerFactory::GetPropertyHandler(_nType
);
112 //= OControlTextEmphasisHandler
113 OControlTextEmphasisHandler::OControlTextEmphasisHandler()
117 bool OControlTextEmphasisHandler::exportXML( OUString
& _rStrExpValue
, const Any
& _rValue
, const SvXMLUnitConverter
& ) const
119 bool bSuccess
= false;
120 sal_Int16 nFontEmphasis
= sal_Int16();
121 if (_rValue
>>= nFontEmphasis
)
124 sal_uInt16 nType
= nFontEmphasis
& ~(awt::FontEmphasisMark::ABOVE
| awt::FontEmphasisMark::BELOW
);
125 // the position of the mark
126 bool bBelow
= 0 != (nFontEmphasis
& awt::FontEmphasisMark::BELOW
);
129 OUStringBuffer aReturn
;
130 bSuccess
= SvXMLUnitConverter::convertEnum(aReturn
, nType
, aFontEmphasisMap
, XML_NONE
);
133 aReturn
.append( ' ' );
134 aReturn
.append( GetXMLToken(bBelow
? XML_BELOW
: XML_ABOVE
) );
136 _rStrExpValue
= aReturn
.makeStringAndClear();
143 bool OControlTextEmphasisHandler::importXML( const OUString
& _rStrImpValue
, Any
& _rValue
, const SvXMLUnitConverter
& ) const
145 bool bSuccess
= true;
146 sal_uInt16 nEmphasis
= awt::FontEmphasisMark::NONE
;
149 bool bHasPos
= false, bHasType
= false;
151 std::u16string_view sToken
;
152 SvXMLTokenEnumerator
aTokenEnum(_rStrImpValue
);
153 while (aTokenEnum
.getNextToken(sToken
))
157 if (IsXMLToken(sToken
, XML_ABOVE
))
162 else if (IsXMLToken(sToken
, XML_BELOW
))
170 if (SvXMLUnitConverter::convertEnum(nEmphasis
, sToken
, aFontEmphasisMap
))
184 nEmphasis
|= bBelow
? awt::FontEmphasisMark::BELOW
: awt::FontEmphasisMark::ABOVE
;
185 _rValue
<<= nEmphasis
;
191 //= OControlBorderHandlerBase
192 OControlBorderHandler::OControlBorderHandler( const OControlBorderHandler::BorderFacet _eFacet
)
197 bool OControlBorderHandler::importXML( const OUString
& _rStrImpValue
, Any
& _rValue
, const SvXMLUnitConverter
& ) const
199 std::u16string_view sToken
;
200 SvXMLTokenEnumerator
aTokens(_rStrImpValue
);
202 sal_uInt16 nStyle
= 1;
204 while ( aTokens
.getNextToken(sToken
) // have a new token
205 && (!sToken
.empty()) // really have a new token
208 // try interpreting the token as border style
209 if ( m_eFacet
== STYLE
)
211 // is it a valid enum value?
212 if ( SvXMLUnitConverter::convertEnum( nStyle
, sToken
, aBorderTypeMap
) )
218 // The internal LO default is flat, which deviates from the import default of 3d
219 _rValue
<<= sal_uInt16(1);
224 // try interpreting it as color value
225 if ( m_eFacet
== COLOR
)
228 if (::sax::Converter::convertColor( nColor
, sToken
))
239 bool OControlBorderHandler::exportXML( OUString
& _rStrExpValue
, const Any
& _rValue
, const SvXMLUnitConverter
& ) const
241 bool bSuccess
= false;
248 sal_uInt16 nBorder
= 0;
249 bSuccess
= (_rValue
>>= nBorder
)
250 && SvXMLUnitConverter::convertEnum( aOut
, nBorder
, aBorderTypeMap
);
255 sal_Int32 nBorderColor
= 0;
256 if ( _rValue
>>= nBorderColor
)
258 ::sax::Converter::convertColor(aOut
, nBorderColor
);
263 } // switch ( m_eFacet )
268 if ( !_rStrExpValue
.isEmpty() )
269 _rStrExpValue
+= " ";
270 _rStrExpValue
+= aOut
;
275 //= OFontWidthHandler
276 OFontWidthHandler::OFontWidthHandler()
280 bool OFontWidthHandler::importXML( const OUString
& _rStrImpValue
, Any
& _rValue
, const SvXMLUnitConverter
& ) const
282 sal_Int32 nWidth
= 0;
283 bool const bSuccess
= ::sax::Converter::convertMeasure(
284 nWidth
, _rStrImpValue
, util::MeasureUnit::POINT
);
286 _rValue
<<= static_cast<sal_Int16
>(nWidth
);
291 bool OFontWidthHandler::exportXML( OUString
& _rStrExpValue
, const Any
& _rValue
, const SvXMLUnitConverter
& ) const
293 sal_Int16 nWidth
= 0;
294 OUStringBuffer aResult
;
295 if (_rValue
>>= nWidth
)
297 ::sax::Converter::convertMeasure(aResult
, nWidth
,
298 util::MeasureUnit::POINT
, util::MeasureUnit::POINT
);
300 _rStrExpValue
= aResult
.makeStringAndClear();
302 return !_rStrExpValue
.isEmpty();
305 //= ORotationAngleHandler
306 ORotationAngleHandler::ORotationAngleHandler()
310 bool ORotationAngleHandler::importXML( const OUString
& _rStrImpValue
, Any
& _rValue
, const SvXMLUnitConverter
& ) const
314 ::sax::Converter::convertDouble(fValue
, _rStrImpValue
);
318 _rValue
<<= static_cast<float>(fValue
);
324 bool ORotationAngleHandler::exportXML( OUString
& _rStrExpValue
, const Any
& _rValue
, const SvXMLUnitConverter
& ) const
327 bool bSuccess
= (_rValue
>>= fAngle
);
331 OUStringBuffer sValue
;
332 ::sax::Converter::convertDouble(sValue
, static_cast<double>(fAngle
) / 10);
333 _rStrExpValue
= sValue
.makeStringAndClear();
339 //= ImageScaleModeHandler
340 ImageScaleModeHandler::ImageScaleModeHandler()
341 :XMLConstantsPropertyHandler( aScaleModeMap
, XML_STRETCH
)
345 } // namespace xmloff
347 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */