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 "shadwhdl.hxx"
21 #include <com/sun/star/uno/Any.hxx>
22 #include <rtl/ustrbuf.hxx>
25 #include <com/sun/star/table/ShadowFormat.hpp>
26 #include <o3tl/safeint.hxx>
27 #include <tools/color.hxx>
28 #include <sax/tools/converter.hxx>
29 #include <xmloff/xmluconv.hxx>
30 #include <xmloff/xmltoken.hxx>
32 using namespace ::com::sun::star
;
33 using namespace ::xmloff::token
;
38 XMLShadowPropHdl::~XMLShadowPropHdl()
43 bool XMLShadowPropHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& rUnitConverter
) const
46 table::ShadowFormat aShadow
;
47 aShadow
.Location
= table::ShadowLocation_BOTTOM_RIGHT
;
49 bool bColorFound
= false;
50 bool bOffsetFound
= false;
51 SvXMLTokenEnumerator
aTokenEnum( rStrImpValue
);
52 Color
aColor( 128,128, 128 );
55 while( aTokenEnum
.getNextToken( aToken
) )
57 if( IsXMLToken( aToken
, XML_NONE
) )
59 aShadow
.Location
= table::ShadowLocation_NONE
;
63 else if( !bColorFound
&& aToken
.startsWith("#") )
65 bRet
= ::sax::Converter::convertColor( aColor
, aToken
);
70 else if( !bOffsetFound
)
72 sal_Int32 nX
= 0, nY
= 0;
74 bRet
= rUnitConverter
.convertMeasureToCore( nX
, aToken
);
75 if( bRet
&& aTokenEnum
.getNextToken( aToken
) )
76 bRet
= rUnitConverter
.convertMeasureToCore( nY
, aToken
);
83 aShadow
.Location
= table::ShadowLocation_TOP_LEFT
;
85 aShadow
.Location
= table::ShadowLocation_BOTTOM_LEFT
;
90 aShadow
.Location
= table::ShadowLocation_TOP_RIGHT
;
92 aShadow
.Location
= table::ShadowLocation_BOTTOM_RIGHT
;
96 nX
= o3tl::saturating_toggle_sign(nX
);
98 nY
= o3tl::saturating_toggle_sign(nY
);
101 bRet
= !o3tl::checked_add(nX
, nY
, nWidth
);
103 aShadow
.ShadowWidth
= sal::static_int_cast
<sal_Int16
>(nWidth
>> 1);
108 if( bRet
&& ( bColorFound
|| bOffsetFound
) )
110 aShadow
.IsTransparent
= aColor
.GetTransparency() > 0;
111 aShadow
.Color
= sal_Int32(aColor
);
120 bool XMLShadowPropHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& rUnitConverter
) const
123 table::ShadowFormat aShadow
;
125 if( rValue
>>= aShadow
)
127 sal_Int32 nX
= 1, nY
= 1;
129 switch( aShadow
.Location
)
131 case table::ShadowLocation_TOP_LEFT
:
135 case table::ShadowLocation_TOP_RIGHT
:
138 case table::ShadowLocation_BOTTOM_LEFT
:
141 case table::ShadowLocation_BOTTOM_RIGHT
:
143 case table::ShadowLocation_NONE
:
145 rStrExpValue
= GetXMLToken(XML_NONE
);
149 nX
*= aShadow
.ShadowWidth
;
150 nY
*= aShadow
.ShadowWidth
;
153 ::sax::Converter::convertColor( aOut
, aShadow
.Color
);
155 rUnitConverter
.convertMeasureToXML( aOut
, nX
);
157 rUnitConverter
.convertMeasureToXML( aOut
, nY
);
159 rStrExpValue
= aOut
.makeStringAndClear();
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */