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 <tools/color.hxx>
27 #include <sax/tools/converter.hxx>
28 #include <xmloff/xmluconv.hxx>
29 #include <xmloff/xmltoken.hxx>
31 using namespace ::com::sun::star
;
32 using namespace ::xmloff::token
;
35 // class XMLMeasurePropHdl
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("#") )
66 bRet
= ::sax::Converter::convertColor( nColor
, aToken
);
70 aColor
.SetColor(nColor
);
73 else if( !bOffsetFound
)
75 sal_Int32 nX
= 0, nY
= 0;
77 bRet
= rUnitConverter
.convertMeasureToCore( nX
, aToken
);
78 if( bRet
&& aTokenEnum
.getNextToken( aToken
) )
79 bRet
= rUnitConverter
.convertMeasureToCore( nY
, aToken
);
86 aShadow
.Location
= table::ShadowLocation_TOP_LEFT
;
88 aShadow
.Location
= table::ShadowLocation_BOTTOM_LEFT
;
93 aShadow
.Location
= table::ShadowLocation_TOP_RIGHT
;
95 aShadow
.Location
= table::ShadowLocation_BOTTOM_RIGHT
;
98 if( nX
< 0 ) nX
*= -1;
99 if( nY
< 0 ) nY
*= -1;
101 aShadow
.ShadowWidth
= sal::static_int_cast
< sal_Int16
>(
107 if( bRet
&& ( bColorFound
|| bOffsetFound
) )
109 aShadow
.IsTransparent
= aColor
.GetTransparency() > 0;
110 aShadow
.Color
= aColor
.GetColor();
119 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
;
152 ::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: */