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 <TDefTableHandler.hxx>
24 #include <PropertyMap.hxx>
25 #include <ConversionHelper.hxx>
26 #include <ooxml/resourceids.hxx>
27 #include <doctok/resourceids.hxx>
28 #include <com/sun/star/table/BorderLine.hpp>
29 #include <com/sun/star/text/TableColumnSeparator.hpp>
30 #include <com/sun/star/text/VertOrientation.hpp>
31 
32 #include "dmapperLoggers.hxx"
33 
34 namespace writerfilter {
35 namespace dmapper {
36 
37 using namespace ::com::sun::star;
38 
39 /*-- 24.04.2007 09:06:35---------------------------------------------------
40 
41   -----------------------------------------------------------------------*/
TDefTableHandler(bool bOOXML)42 TDefTableHandler::TDefTableHandler(bool bOOXML) :
43 LoggedProperties(dmapper_logger, "TDefTableHandler"),
44 m_nLineWidth(0),
45 m_nLineType(0),
46 m_nLineColor(0),
47 m_nLineDistance(0),
48 m_bOOXML( bOOXML )
49 {
50 }
51 /*-- 24.04.2007 09:06:35---------------------------------------------------
52 
53   -----------------------------------------------------------------------*/
~TDefTableHandler()54 TDefTableHandler::~TDefTableHandler()
55 {
56 }
57 /*-- 24.04.2007 09:06:35---------------------------------------------------
58 
59   -----------------------------------------------------------------------*/
lcl_attribute(Id rName,Value & rVal)60 void TDefTableHandler::lcl_attribute(Id rName, Value & rVal)
61 {
62     sal_Int32 nIntValue = rVal.getInt();
63     (void)nIntValue;
64     (void)rName;
65     /* WRITERFILTERSTATUS: table: TDefTable_attributedata */
66     switch( rName )
67     {
68         /* WRITERFILTERSTATUS: done: 50, planned: 0, spent: 0 */
69         case NS_rtf::LN_cellx:
70             // nIntValue contains the vert. line position
71             //TODO: nIntValue is wrong for negative values!
72             if( nIntValue > 0x7fff )
73                 nIntValue -= 0xffff;
74             m_aCellBorderPositions.push_back( ConversionHelper::convertTwipToMM100( nIntValue ) );
75         break;
76         /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
77         case NS_rtf::LN_tc:
78         {
79             writerfilter::Reference<Properties>::Pointer_t pProperties = rVal.getProperties();
80             if( pProperties.get())
81             {
82                 pProperties->resolve( *this );
83             }
84         }
85         break;
86         //from LN_tc
87         /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
88         case NS_rtf::LN_FFIRSTMERGED:
89         /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
90         case NS_rtf::LN_FMERGED:
91         /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
92         case NS_rtf::LN_FVERTICAL:
93         /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
94         case NS_rtf::LN_FBACKWARD:
95         /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
96         case NS_rtf::LN_FROTATEFONT:
97         /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
98         case NS_rtf::LN_FVERTMERGE:
99         /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
100         case NS_rtf::LN_FVERTRESTART:
101         break;
102         /* WRITERFILTERSTATUS: done: 50, planned: 0, spent: 0 */
103         case NS_rtf::LN_VERTALIGN:
104             //TODO: m_aCellVertAlign is just a temporary solution! 0 - top 1 - center 2 - bottom
105             m_aCellVertAlign.push_back( nIntValue );
106         break;
107         /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
108         case NS_rtf::LN_FUNUSED:
109         /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
110         case NS_rtf::LN_CellPrefferedSize:
111         break;
112         /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
113         case NS_rtf::LN_BRCTOP:
114         /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
115         case NS_rtf::LN_BRCLEFT:
116         /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
117         case NS_rtf::LN_BRCBOTTOM:
118         /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
119         case NS_rtf::LN_BRCRIGHT:
120         {
121             writerfilter::Reference<Properties>::Pointer_t pProperties = rVal.getProperties();
122             localResolve( rName, pProperties );
123         }
124         break;
125         //from LN_BRCXXXX - handled within the BorderHandler
126         /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
127         case NS_rtf::LN_DPTLINEWIDTH: // 0x2871
128             //  width of a single line in 1/8 pt, max of 32 pt -> twip * 5 / 2.
129             m_nLineWidth = ConversionHelper::convertTwipToMM100( nIntValue * 5 / 2 );
130         break;
131         /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
132         case NS_rtf::LN_BRCTYPE:    // 0x2872
133             m_nLineType = nIntValue;
134         break;
135         /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
136         case NS_ooxml::LN_CT_Border_color:
137         /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
138         case NS_rtf::LN_ICO:        // 0x2873
139             m_nLineColor = nIntValue;
140         break;
141         /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
142         case NS_rtf::LN_DPTSPACE:   // 0x2874
143             m_nLineDistance = nIntValue;
144         break;
145         /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
146         case NS_rtf::LN_FSHADOW:    // 0x2875
147             //if 1 then line has shadow - unsupported
148         /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
149         case NS_rtf::LN_FFRAME:     // 0x2876
150         /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
151         case NS_rtf::LN_UNUSED2_15: // 0x2877
152             // ignored
153         break;
154         case NS_ooxml::LN_CT_Border_themeColor:
155         case NS_ooxml::LN_CT_Border_themeTint:
156         case NS_ooxml::LN_CT_Border_themeShade:
157             // ignored
158         break;
159         default:
160             OSL_ENSURE(false, "unknown attribute");
161     }
162 }
163 /*-- 08.10.2007 12:55:32---------------------------------------------------
164 
165   -----------------------------------------------------------------------*/
localResolve(Id rName,writerfilter::Reference<Properties>::Pointer_t pProperties)166 void TDefTableHandler::localResolve(Id rName, writerfilter::Reference<Properties>::Pointer_t pProperties)
167 {
168     if( pProperties.get())
169     {
170         m_nLineWidth = m_nLineType = m_nLineColor = m_nLineDistance = 0;
171         pProperties->resolve( *this );
172         table::BorderLine aBorderLine;
173         ConversionHelper::MakeBorderLine( m_nLineWidth,   m_nLineType, m_nLineColor,
174                                                                         aBorderLine, m_bOOXML );
175 
176         /* WRITERFILTERSTATUS: table: TDefTable_localresolve */
177         switch( rName )
178         {
179             /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
180             case NS_ooxml::LN_CT_TcBorders_top:
181             /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
182             case NS_rtf::LN_BRCTOP:
183                 m_aTopBorderLines.push_back(aBorderLine);
184             break;
185             /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
186             case NS_ooxml::LN_CT_TcBorders_left:
187             /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
188             case NS_rtf::LN_BRCLEFT:
189                 m_aLeftBorderLines.push_back(aBorderLine);
190             break;
191             /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
192             case NS_ooxml::LN_CT_TcBorders_bottom:
193             /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
194             case NS_rtf::LN_BRCBOTTOM:
195                 m_aBottomBorderLines.push_back(aBorderLine);
196             break;
197             /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
198             case NS_ooxml::LN_CT_TcBorders_right:
199             /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
200             case NS_rtf::LN_BRCRIGHT:
201                 m_aRightBorderLines.push_back(aBorderLine);
202             break;
203             case NS_ooxml::LN_CT_TcBorders_insideH:
204                 m_aInsideHBorderLines.push_back(aBorderLine);
205             break;
206             case NS_ooxml::LN_CT_TcBorders_insideV:
207                 m_aInsideVBorderLines.push_back(aBorderLine);
208             break;
209             default:;
210         }
211     }
212 }
213 /*-- 24.04.2007 09:06:35---------------------------------------------------
214 
215   -----------------------------------------------------------------------*/
lcl_sprm(Sprm & rSprm)216 void TDefTableHandler::lcl_sprm(Sprm & rSprm)
217 {
218     /* WRITERFILTERSTATUS: table: TDefTable_sprm */
219     switch( rSprm.getId() )
220     {
221         /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
222         case NS_ooxml::LN_CT_TcBorders_top:
223         /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
224         case NS_ooxml::LN_CT_TcBorders_left:
225         /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
226         case NS_ooxml::LN_CT_TcBorders_bottom:
227         /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
228         case NS_ooxml::LN_CT_TcBorders_right:
229         case NS_ooxml::LN_CT_TcBorders_insideH:
230         case NS_ooxml::LN_CT_TcBorders_insideV:
231         case NS_ooxml::LN_CT_TcBorders_tl2br:
232         case NS_ooxml::LN_CT_TcBorders_tr2bl:
233         {
234             writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
235             localResolve( rSprm.getId(), pProperties );
236         }
237         break;
238         default:;
239     }
240 }
241 /*-- 24.04.2007 09:09:01---------------------------------------------------
242 
243   -----------------------------------------------------------------------*/
getRowProperties() const244 PropertyMapPtr  TDefTableHandler::getRowProperties() const
245 {
246     PropertyMapPtr pPropertyMap(new PropertyMap);
247 
248     // Writer only wants the separators, Word provides also the outer border positions
249     if( m_aCellBorderPositions.size() > 2 )
250     {
251         //determine table width
252         double nFullWidth = m_aCellBorderPositions[m_aCellBorderPositions.size() - 1] - m_aCellBorderPositions[0];
253         //the positions have to be distibuted in a range of 10000
254         const double nFullWidthRelative = 10000.;
255         uno::Sequence< text::TableColumnSeparator > aSeparators( m_aCellBorderPositions.size() - 2 );
256         text::TableColumnSeparator* pSeparators = aSeparators.getArray();
257         for( sal_uInt32 nBorder = 1; nBorder < m_aCellBorderPositions.size() - 1; ++nBorder )
258         {
259             sal_Int16 nRelPos =
260                 sal::static_int_cast< sal_Int16 >(double(m_aCellBorderPositions[nBorder]) * nFullWidthRelative / nFullWidth );
261 
262             pSeparators[nBorder - 1].Position =  nRelPos;
263             pSeparators[nBorder - 1].IsVisible = sal_True;
264         }
265         pPropertyMap->Insert( PROP_TABLE_COLUMN_SEPARATORS, false, uno::makeAny( aSeparators ) );
266     }
267 
268     return pPropertyMap;
269 }
270 /*-- 10.05.2007 16:10:33---------------------------------------------------
271 
272   -----------------------------------------------------------------------*/
fillCellProperties(size_t nCell,::boost::shared_ptr<TablePropertyMap> pCellProperties) const273 void TDefTableHandler::fillCellProperties(
274             size_t nCell, ::boost::shared_ptr< TablePropertyMap > pCellProperties ) const
275 {
276     if( m_aCellBorderPositions.size() > nCell )
277     {
278         sal_Int16 nVertOrient = text::VertOrientation::NONE;
279         switch( m_aCellVertAlign[nCell] ) //0 - top 1 - center 2 - bottom
280         {
281             case 1: nVertOrient = text::VertOrientation::CENTER; break;
282             case 2: nVertOrient = text::VertOrientation::BOTTOM; break;
283             default:;
284         }
285         pCellProperties->Insert( PROP_VERT_ORIENT, false, uno::makeAny( nVertOrient ) );
286     }
287     if( m_aTopBorderLines.size() > nCell )
288         pCellProperties->Insert( PROP_TOP_BORDER, false, uno::makeAny( m_aTopBorderLines[nCell] ) );
289     if( m_aLeftBorderLines.size() > nCell )
290         pCellProperties->Insert( PROP_LEFT_BORDER, false, uno::makeAny( m_aLeftBorderLines[nCell] ) );
291     if( m_aBottomBorderLines.size() > nCell )
292         pCellProperties->Insert( PROP_BOTTOM_BORDER, false, uno::makeAny( m_aBottomBorderLines[nCell] ) );
293     if( m_aRightBorderLines.size() > nCell )
294         pCellProperties->Insert( PROP_RIGHT_BORDER, false, uno::makeAny( m_aRightBorderLines[nCell] ) );
295     if( m_aInsideHBorderLines.size() > nCell )
296         pCellProperties->Insert( META_PROP_HORIZONTAL_BORDER, false, uno::makeAny( m_aInsideHBorderLines[nCell] ) );
297     if( m_aInsideVBorderLines.size() > nCell )
298         pCellProperties->Insert( META_PROP_VERTICAL_BORDER, false, uno::makeAny( m_aInsideVBorderLines[nCell] ) );
299 }
300 /*-- 09.05.2007 13:14:17---------------------------------------------------
301 
302   -----------------------------------------------------------------------*/
getTableWidth() const303 sal_Int32 TDefTableHandler::getTableWidth() const
304 {
305     sal_Int32 nWidth = 0;
306     if( m_aCellBorderPositions.size() > 1 )
307     {
308         //determine table width
309         nWidth = m_aCellBorderPositions[m_aCellBorderPositions.size() - 1] - m_aCellBorderPositions[0];
310     }
311     return nWidth;
312 }
313 /*-- 10.05.2007 16:09:10---------------------------------------------------
314 
315   -----------------------------------------------------------------------*/
getCellCount() const316 size_t TDefTableHandler::getCellCount() const
317 {
318     return m_aCellVertAlign.size();
319 }
320 
321 } //namespace dmapper
322 } //namespace writerfilter
323