nss: upgrade to release 3.73
[LibreOffice.git] / xmloff / source / style / shadwhdl.cxx
blob2b02a40cb1c8f6143a06aa6a747d52efa622d2cf
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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()
40 // nothing to do
43 bool XMLShadowPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
45 bool bRet = false;
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 );
53 OUString aToken;
55 while( aTokenEnum.getNextToken( aToken ) )
57 if( IsXMLToken( aToken, XML_NONE ) )
59 aShadow.Location = table::ShadowLocation_NONE;
60 bRet = true;
61 break;
63 else if( !bColorFound && aToken.startsWith("#") )
65 bRet = ::sax::Converter::convertColor( aColor, aToken );
66 if( !bRet )
67 return false;
68 bColorFound = true;
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 );
78 if( bRet )
80 if( nX < 0 )
82 if( nY < 0 )
83 aShadow.Location = table::ShadowLocation_TOP_LEFT;
84 else
85 aShadow.Location = table::ShadowLocation_BOTTOM_LEFT;
87 else
89 if( nY < 0 )
90 aShadow.Location = table::ShadowLocation_TOP_RIGHT;
91 else
92 aShadow.Location = table::ShadowLocation_BOTTOM_RIGHT;
95 if (nX < 0)
96 nX = o3tl::saturating_toggle_sign(nX);
97 if (nY < 0)
98 nY = o3tl::saturating_toggle_sign(nY);
100 sal_Int32 nWidth;
101 bRet = !o3tl::checked_add(nX, nY, nWidth);
102 if (bRet)
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);
112 bRet = true;
115 rValue <<= aShadow;
117 return bRet;
120 bool XMLShadowPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
122 bool bRet = false;
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:
132 nX = -1;
133 nY = -1;
134 break;
135 case table::ShadowLocation_TOP_RIGHT:
136 nY = -1;
137 break;
138 case table::ShadowLocation_BOTTOM_LEFT:
139 nX = -1;
140 break;
141 case table::ShadowLocation_BOTTOM_RIGHT:
142 break;
143 case table::ShadowLocation_NONE:
144 default:
145 rStrExpValue = GetXMLToken(XML_NONE);
146 return true;
149 nX *= aShadow.ShadowWidth;
150 nY *= aShadow.ShadowWidth;
152 OUStringBuffer aOut;
153 ::sax::Converter::convertColor( aOut, aShadow.Color );
154 aOut.append( ' ' );
155 rUnitConverter.convertMeasureToXML( aOut, nX );
156 aOut.append( ' ' );
157 rUnitConverter.convertMeasureToXML( aOut, nY );
159 rStrExpValue = aOut.makeStringAndClear();
161 bRet = true;
164 return bRet;
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */