Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "shadwhdl.hxx"
21 : #include <com/sun/star/uno/Any.hxx>
22 : #include <rtl/ustrbuf.hxx>
23 :
24 :
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>
30 :
31 : using namespace ::com::sun::star;
32 : using namespace ::xmloff::token;
33 :
34 :
35 : // class XMLMeasurePropHdl
36 :
37 :
38 50124 : XMLShadowPropHdl::~XMLShadowPropHdl()
39 : {
40 : // nothing to do
41 50124 : }
42 :
43 160 : bool XMLShadowPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
44 : {
45 160 : bool bRet = false;
46 160 : table::ShadowFormat aShadow;
47 160 : aShadow.Location = table::ShadowLocation_BOTTOM_RIGHT;
48 :
49 160 : bool bColorFound = false;
50 160 : bool bOffsetFound = false;
51 160 : SvXMLTokenEnumerator aTokenEnum( rStrImpValue );
52 160 : Color aColor( 128,128, 128 );
53 160 : OUString aToken;
54 :
55 436 : while( aTokenEnum.getNextToken( aToken ) )
56 : {
57 218 : if( IsXMLToken( aToken, XML_NONE ) )
58 : {
59 102 : aShadow.Location = table::ShadowLocation_NONE;
60 102 : bRet = true;
61 102 : break;
62 : }
63 116 : else if( !bColorFound && aToken.startsWith("#") )
64 : {
65 58 : sal_Int32 nColor(0);
66 58 : bRet = ::sax::Converter::convertColor( nColor, aToken );
67 58 : if( !bRet )
68 0 : return false;
69 :
70 58 : aColor.SetColor(nColor);
71 58 : bColorFound = true;
72 : }
73 58 : else if( !bOffsetFound )
74 : {
75 58 : sal_Int32 nX = 0, nY = 0;
76 :
77 58 : bRet = rUnitConverter.convertMeasureToCore( nX, aToken );
78 58 : if( bRet && aTokenEnum.getNextToken( aToken ) )
79 58 : bRet = rUnitConverter.convertMeasureToCore( nY, aToken );
80 :
81 58 : if( bRet )
82 : {
83 58 : if( nX < 0 )
84 : {
85 16 : if( nY < 0 )
86 6 : aShadow.Location = table::ShadowLocation_TOP_LEFT;
87 : else
88 10 : aShadow.Location = table::ShadowLocation_BOTTOM_LEFT;
89 : }
90 : else
91 : {
92 42 : if( nY < 0 )
93 20 : aShadow.Location = table::ShadowLocation_TOP_RIGHT;
94 : else
95 22 : aShadow.Location = table::ShadowLocation_BOTTOM_RIGHT;
96 : }
97 :
98 58 : if( nX < 0 ) nX *= -1;
99 58 : if( nY < 0 ) nY *= -1;
100 :
101 : aShadow.ShadowWidth = sal::static_int_cast< sal_Int16 >(
102 58 : (nX + nY) >> 1);
103 : }
104 : }
105 : }
106 :
107 160 : if( bRet && ( bColorFound || bOffsetFound ) )
108 : {
109 58 : aShadow.IsTransparent = aColor.GetTransparency() > 0;
110 58 : aShadow.Color = aColor.GetColor();
111 58 : bRet = true;
112 : }
113 :
114 160 : rValue <<= aShadow;
115 :
116 160 : return bRet;
117 : }
118 :
119 28 : bool XMLShadowPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
120 : {
121 28 : bool bRet = false;
122 28 : OUStringBuffer aOut;
123 28 : table::ShadowFormat aShadow;
124 :
125 28 : if( rValue >>= aShadow )
126 : {
127 28 : sal_Int32 nX = 1, nY = 1;
128 :
129 28 : switch( aShadow.Location )
130 : {
131 : case table::ShadowLocation_TOP_LEFT:
132 0 : nX = -1;
133 0 : nY = -1;
134 0 : break;
135 : case table::ShadowLocation_TOP_RIGHT:
136 2 : nY = -1;
137 2 : break;
138 : case table::ShadowLocation_BOTTOM_LEFT:
139 2 : nX = -1;
140 2 : break;
141 : case table::ShadowLocation_BOTTOM_RIGHT:
142 6 : break;
143 : case table::ShadowLocation_NONE:
144 : default:
145 18 : rStrExpValue = GetXMLToken(XML_NONE);
146 18 : return true;
147 : }
148 :
149 10 : nX *= aShadow.ShadowWidth;
150 10 : nY *= aShadow.ShadowWidth;
151 :
152 10 : ::sax::Converter::convertColor( aOut, aShadow.Color );
153 :
154 10 : aOut.append( ' ' );
155 10 : rUnitConverter.convertMeasureToXML( aOut, nX );
156 10 : aOut.append( ' ' );
157 10 : rUnitConverter.convertMeasureToXML( aOut, nY );
158 :
159 10 : rStrExpValue = aOut.makeStringAndClear();
160 :
161 10 : bRet = true;
162 : }
163 :
164 10 : return bRet;
165 : }
166 :
167 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|