1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #include <CellColorHandler.hxx>
24 #include <PropertyMap.hxx>
25 #include <doctok/resourceids.hxx>
26 #include <ConversionHelper.hxx>
27 #include <ooxml/resourceids.hxx>
28 #include "dmapperLoggers.hxx"
29 
30 #define OOXML_COLOR_AUTO 0x0a //todo: AutoColor needs symbol
31 
32 namespace writerfilter {
33 namespace dmapper {
34 
35 using namespace ::com::sun::star;
36 using namespace ::writerfilter;
37 //using namespace ::std;
38 
39 /*-- 24.04.2007 09:06:35---------------------------------------------------
40 
41   -----------------------------------------------------------------------*/
CellColorHandler()42 CellColorHandler::CellColorHandler() :
43 LoggedProperties(dmapper_logger, "CellColorHandler"),
44 m_nShadowType( 0 ),
45 m_nColor( 0xffffffff ),
46 m_nFillColor( 0xffffffff ),
47 m_eType( Others )
48 {
49 }
50 /*-- 24.04.2007 09:06:35---------------------------------------------------
51 
52   -----------------------------------------------------------------------*/
~CellColorHandler()53 CellColorHandler::~CellColorHandler()
54 {
55 }
56 /*-- 24.04.2007 09:06:35---------------------------------------------------
57 
58   -----------------------------------------------------------------------*/
lcl_attribute(Id rName,Value & rVal)59 void CellColorHandler::lcl_attribute(Id rName, Value & rVal)
60 {
61     sal_Int32 nIntValue = rVal.getInt();
62     (void)nIntValue;
63     (void)rName;
64     /* WRITERFILTERSTATUS: table: CellColor_attributedata */
65     switch( rName )
66     {
67         case NS_rtf::LN_cellTopColor:
68             /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
69         case NS_rtf::LN_cellLeftColor:
70             /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
71         case NS_rtf::LN_cellBottomColor:
72             /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
73         case NS_rtf::LN_cellRightColor:
74             /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
75             // nIntValue contains the color, directly
76         break;
77         case NS_ooxml::LN_CT_Shd_val:
78             /* WRITERFILTERSTATUS: done: 50, planned: 0, spent: 0 */
79         {
80             //might be clear, pct5...90, some hatch types
81             //TODO: The values need symbolic names!
82             m_nShadowType = nIntValue; //clear == 0, solid: 1, pct5: 2, pct50:8, pct95: x3c, horzStripe:0x0e, thinVertStripe: 0x15
83         }
84         break;
85         case NS_ooxml::LN_CT_Shd_fill:
86             /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
87             if( nIntValue == OOXML_COLOR_AUTO )
88                 nIntValue = 0xffffff; //fill color auto means white
89             m_nFillColor = nIntValue;
90         break;
91         case NS_ooxml::LN_CT_Shd_color:
92             /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
93             if( nIntValue == OOXML_COLOR_AUTO )
94                 nIntValue = 0; //shading color auto means black
95             //color of the shading
96             m_nColor = nIntValue;
97         break;
98 //        case NS_rtf::LN_rgbrc:
99 //        {
100 //            writerfilter::Reference<Properties>::Pointer_t pProperties = rVal.getProperties();
101 //            if( pProperties.get())
102 //            {
103 //                pProperties->resolve(*this);
104 //                //
105 //            }
106 //        }
107 //        break;
108         case NS_ooxml::LN_CT_Shd_themeFill:
109         case NS_ooxml::LN_CT_Shd_themeFillTint:
110         case NS_ooxml::LN_CT_Shd_themeFillShade:
111             // ignored
112             break;
113         default:
114             OSL_ENSURE( false, "unknown attribute");
115     }
116 }
117 /*-- 24.04.2007 09:06:35---------------------------------------------------
118 
119   -----------------------------------------------------------------------*/
lcl_sprm(Sprm & rSprm)120 void CellColorHandler::lcl_sprm(Sprm & rSprm)
121 {
122     (void)rSprm;
123 }
124 /*-- 24.04.2007 09:09:01---------------------------------------------------
125 
126   -----------------------------------------------------------------------*/
getProperties()127 TablePropertyMapPtr  CellColorHandler::getProperties()
128 {
129     TablePropertyMapPtr pPropertyMap(new TablePropertyMap);
130 //code from binary word filter
131     static const sal_Int32 eMSGrayScale[] =
132     {
133         // Nul-Brush
134            0,   // 0
135         // Solid-Brush
136         1000,   // 1
137         // percent values
138           50,   // 2
139          100,   // 3
140          200,   // 4
141          250,   // 5
142          300,   // 6
143          400,   // 7
144          500,   // 8
145          600,   // 9
146          700,   // 10
147          750,   // 11
148          800,   // 12
149          900,   // 13
150          333, // 14 Dark Horizontal
151          333, // 15 Dark Vertical
152          333, // 16 Dark Forward Diagonal
153          333, // 17 Dark Backward Diagonal
154          333, // 18 Dark Cross
155          333, // 19 Dark Diagonal Cross
156          333, // 20 Horizontal
157          333, // 21 Vertical
158          333, // 22 Forward Diagonal
159          333, // 23 Backward Diagonal
160          333, // 24 Cross
161          333, // 25 Diagonal Cross
162          // some undefined values
163          500, // 26
164          500, // 27
165          500, // 28
166          500, // 29
167          500, // 30
168          500, // 31
169          500, // 32
170          500, // 33
171          500, // 34
172          // different shading types
173           25,   // 35
174           75,   // 36
175          125,   // 37
176          150,   // 38
177          175,   // 39
178          225,   // 40
179          275,   // 41
180          325,   // 42
181          350,   // 43
182          375,   // 44
183          425,   // 45
184          450,   // 46
185          475,   // 47
186          525,   // 48
187          550,   // 49
188          575,   // 50
189          625,   // 51
190          650,   // 52
191          675,   // 53
192          725,   // 54
193          775,   // 55
194          825,   // 56
195          850,   // 57
196          875,   // 58
197          925,   // 59
198          950,   // 60
199          975,   // 61
200          // und zu guter Letzt:
201          970
202     };// 62
203     if( m_nShadowType >= (sal_Int32)(sizeof( eMSGrayScale ) / sizeof ( eMSGrayScale[ 0 ] )) )
204         m_nShadowType = 0;
205 
206     sal_Int32 nWW8BrushStyle = eMSGrayScale[m_nShadowType];
207     sal_Int32 nApplyColor = 0;
208     if( !nWW8BrushStyle )
209     {
210         // Null-Brush
211             nApplyColor = m_nFillColor;
212     }
213     else
214     {
215         sal_Int32 nFore = m_nColor;
216         sal_Int32 nBack = m_nFillColor;
217 
218         sal_uInt32 nRed = ((nFore & 0xff0000)>>0x10) * nWW8BrushStyle;
219         sal_uInt32 nGreen = ((nFore & 0xff00)>>0x8) * nWW8BrushStyle;
220         sal_uInt32 nBlue = (nFore & 0xff) * nWW8BrushStyle;
221         nRed += ((nBack & 0xff0000)>>0x10)  * (1000L - nWW8BrushStyle);
222         nGreen += ((nBack & 0xff00)>>0x8)* (1000L - nWW8BrushStyle);
223         nBlue += (nBack & 0xff) * (1000L - nWW8BrushStyle);
224 
225         nApplyColor = ( (nRed/1000) << 0x10 ) + ((nGreen/1000) << 8) + nBlue/1000;
226     }
227 
228 	sal_Int32 objType = PROP_CHAR_BACK_COLOR;
229 
230 	switch(m_eType)
231 	{
232 	case P:
233 		pPropertyMap->Insert( PROP_PARA_BACK_COLOR, false, uno::makeAny( nApplyColor ));
234 		break;
235 	case C:
236 		pPropertyMap->Insert( PROP_CHAR_BACK_COLOR, false, uno::makeAny( nApplyColor ));
237 		break;
238 	case Others:
239 	default:
240 		pPropertyMap->Insert( PROP_BACK_COLOR, false, uno::makeAny( nApplyColor ));
241 		break;
242 	}
243 
244     return pPropertyMap;
245 }
246 } //namespace dmapper
247 } //namespace writerfilter
248