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 : #include <CellColorHandler.hxx>
20 : #include <PropertyMap.hxx>
21 : #include <doctok/resourceids.hxx>
22 : #include <ConversionHelper.hxx>
23 : #include <ooxml/resourceids.hxx>
24 : #include <sal/macros.h>
25 : #include "dmapperLoggers.hxx"
26 :
27 : #define OOXML_COLOR_AUTO 0x0a //todo: AutoColor needs symbol
28 :
29 : namespace writerfilter {
30 : namespace dmapper {
31 :
32 : using namespace ::com::sun::star;
33 : using namespace ::writerfilter;
34 :
35 :
36 120 : CellColorHandler::CellColorHandler() :
37 : LoggedProperties(dmapper_logger, "CellColorHandler"),
38 : m_nShadowType( 0 ),
39 : m_nColor( 0xffffffff ),
40 : m_nFillColor( 0xffffffff ),
41 120 : m_OutputFormat( Form )
42 : {
43 120 : }
44 :
45 240 : CellColorHandler::~CellColorHandler()
46 : {
47 240 : }
48 :
49 280 : void CellColorHandler::lcl_attribute(Id rName, Value & rVal)
50 : {
51 280 : sal_Int32 nIntValue = rVal.getInt();
52 280 : switch( rName )
53 : {
54 : case NS_rtf::LN_cellTopColor:
55 : case NS_rtf::LN_cellLeftColor:
56 : case NS_rtf::LN_cellBottomColor:
57 : case NS_rtf::LN_cellRightColor:
58 : // nIntValue contains the color, directly
59 0 : break;
60 : case NS_ooxml::LN_CT_Shd_val:
61 : {
62 : //might be clear, pct5...90, some hatch types
63 : //TODO: The values need symbolic names!
64 110 : m_nShadowType = nIntValue; //clear == 0, solid: 1, pct5: 2, pct50:8, pct95: x3c, horzStripe:0x0e, thinVertStripe: 0x15
65 : }
66 110 : break;
67 : case NS_ooxml::LN_CT_Shd_fill:
68 120 : if( nIntValue == OOXML_COLOR_AUTO )
69 76 : nIntValue = 0xffffff; //fill color auto means white
70 120 : m_nFillColor = nIntValue;
71 120 : break;
72 : case NS_ooxml::LN_CT_Shd_color:
73 22 : if( nIntValue == OOXML_COLOR_AUTO )
74 22 : nIntValue = 0; //shading color auto means black
75 : //color of the shading
76 22 : m_nColor = nIntValue;
77 22 : break;
78 : case NS_ooxml::LN_CT_Shd_themeFill:
79 : case NS_ooxml::LN_CT_Shd_themeFillTint:
80 : case NS_ooxml::LN_CT_Shd_themeFillShade:
81 : // ignored
82 28 : break;
83 : default:
84 : OSL_FAIL( "unknown attribute");
85 : }
86 280 : }
87 :
88 0 : void CellColorHandler::lcl_sprm(Sprm & rSprm)
89 : {
90 : (void)rSprm;
91 0 : }
92 :
93 120 : TablePropertyMapPtr CellColorHandler::getProperties()
94 : {
95 120 : TablePropertyMapPtr pPropertyMap(new TablePropertyMap);
96 : //code from binary word filter
97 : static const sal_Int32 eMSGrayScale[] =
98 : {
99 : // Nul-Brush
100 : 0, // 0
101 : // Solid-Brush
102 : 1000, // 1
103 : // percent values
104 : 50, // 2
105 : 100, // 3
106 : 200, // 4
107 : 250, // 5
108 : 300, // 6
109 : 400, // 7
110 : 500, // 8
111 : 600, // 9
112 : 700, // 10
113 : 750, // 11
114 : 800, // 12
115 : 900, // 13
116 : 333, // 14 Dark Horizontal
117 : 333, // 15 Dark Vertical
118 : 333, // 16 Dark Forward Diagonal
119 : 333, // 17 Dark Backward Diagonal
120 : 333, // 18 Dark Cross
121 : 333, // 19 Dark Diagonal Cross
122 : 333, // 20 Horizontal
123 : 333, // 21 Vertical
124 : 333, // 22 Forward Diagonal
125 : 333, // 23 Backward Diagonal
126 : 333, // 24 Cross
127 : 333, // 25 Diagonal Cross
128 : // some undefined values
129 : 500, // 26
130 : 500, // 27
131 : 500, // 28
132 : 500, // 29
133 : 500, // 30
134 : 500, // 31
135 : 500, // 32
136 : 500, // 33
137 : 500, // 34
138 : // different shading types
139 : 25, // 35
140 : 75, // 36
141 : 125, // 37
142 : 150, // 38
143 : 175, // 39
144 : 225, // 40
145 : 275, // 41
146 : 325, // 42
147 : 350, // 43
148 : 375, // 44
149 : 425, // 45
150 : 450, // 46
151 : 475, // 47
152 : 525, // 48
153 : 550, // 49
154 : 575, // 50
155 : 625, // 51
156 : 650, // 52
157 : 675, // 53
158 : 725, // 54
159 : 775, // 55
160 : 825, // 56
161 : 850, // 57
162 : 875, // 58
163 : 925, // 59
164 : 950, // 60
165 : 975, // 61
166 : // und zu guter Letzt:
167 : 970
168 : };// 62
169 120 : if( m_nShadowType >= (sal_Int32)SAL_N_ELEMENTS( eMSGrayScale ) )
170 0 : m_nShadowType = 0;
171 :
172 120 : sal_Int32 nWW8BrushStyle = eMSGrayScale[m_nShadowType];
173 120 : sal_Int32 nApplyColor = 0;
174 120 : if( !nWW8BrushStyle )
175 : {
176 : // Null-Brush
177 120 : nApplyColor = m_nFillColor;
178 : }
179 : else
180 : {
181 0 : sal_Int32 nFore = m_nColor;
182 0 : sal_Int32 nBack = m_nFillColor;
183 :
184 0 : sal_uInt32 nRed = ((nFore & 0xff0000)>>0x10) * nWW8BrushStyle;
185 0 : sal_uInt32 nGreen = ((nFore & 0xff00)>>0x8) * nWW8BrushStyle;
186 0 : sal_uInt32 nBlue = (nFore & 0xff) * nWW8BrushStyle;
187 0 : nRed += ((nBack & 0xff0000)>>0x10) * (1000L - nWW8BrushStyle);
188 0 : nGreen += ((nBack & 0xff00)>>0x8)* (1000L - nWW8BrushStyle);
189 0 : nBlue += (nBack & 0xff) * (1000L - nWW8BrushStyle);
190 :
191 0 : nApplyColor = ( (nRed/1000) << 0x10 ) + ((nGreen/1000) << 8) + nBlue/1000;
192 : }
193 :
194 120 : pPropertyMap->Insert( m_OutputFormat == Form ? PROP_BACK_COLOR
195 : : m_OutputFormat == Paragraph ? PROP_PARA_BACK_COLOR
196 240 : : PROP_CHAR_BACK_COLOR, false, uno::makeAny( nApplyColor ));
197 120 : return pPropertyMap;
198 : }
199 : } //namespace dmapper
200 30 : } //namespace writerfilter
201 :
202 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|