1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: TDefTableHandler.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #include <TDefTableHandler.hxx>
31 #include <PropertyMap.hxx>
32 #include <ConversionHelper.hxx>
33 #include <ooxml/resourceids.hxx>
34 #include <doctok/resourceids.hxx>
35 #include <com/sun/star/table/BorderLine.hpp>
36 #include <com/sun/star/text/TableColumnSeparator.hpp>
37 #include <com/sun/star/text/VertOrientation.hpp>
39 namespace writerfilter
{
42 using namespace ::com::sun::star
;
44 /*-- 24.04.2007 09:06:35---------------------------------------------------
46 -----------------------------------------------------------------------*/
47 TDefTableHandler::TDefTableHandler(bool bOOXML
) :
55 /*-- 24.04.2007 09:06:35---------------------------------------------------
57 -----------------------------------------------------------------------*/
58 TDefTableHandler::~TDefTableHandler()
61 /*-- 24.04.2007 09:06:35---------------------------------------------------
63 -----------------------------------------------------------------------*/
64 void TDefTableHandler::attribute(Id rName
, Value
& rVal
)
66 sal_Int32 nIntValue
= rVal
.getInt();
69 /* WRITERFILTERSTATUS: table: TDefTable_attributedata */
72 /* WRITERFILTERSTATUS: done: 50, planned: 0, spent: 0 */
73 case NS_rtf::LN_cellx
:
74 // nIntValue contains the vert. line position
75 //TODO: nIntValue is wrong for negative values!
76 if( nIntValue
> 0x7fff )
78 m_aCellBorderPositions
.push_back( ConversionHelper::convertTwipToMM100( nIntValue
) );
80 /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
83 writerfilter::Reference
<Properties
>::Pointer_t pProperties
= rVal
.getProperties();
84 if( pProperties
.get())
86 pProperties
->resolve( *this );
91 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
92 case NS_rtf::LN_FFIRSTMERGED
:
93 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
94 case NS_rtf::LN_FMERGED
:
95 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
96 case NS_rtf::LN_FVERTICAL
:
97 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
98 case NS_rtf::LN_FBACKWARD
:
99 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
100 case NS_rtf::LN_FROTATEFONT
:
101 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
102 case NS_rtf::LN_FVERTMERGE
:
103 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
104 case NS_rtf::LN_FVERTRESTART
:
106 /* WRITERFILTERSTATUS: done: 50, planned: 0, spent: 0 */
107 case NS_rtf::LN_VERTALIGN
:
108 //TODO: m_aCellVertAlign is just a temporary solution! 0 - top 1 - center 2 - bottom
109 m_aCellVertAlign
.push_back( nIntValue
);
111 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
112 case NS_rtf::LN_FUNUSED
:
113 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
114 case NS_rtf::LN_CellPrefferedSize
:
116 /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
117 case NS_rtf::LN_BRCTOP
:
118 /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
119 case NS_rtf::LN_BRCLEFT
:
120 /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
121 case NS_rtf::LN_BRCBOTTOM
:
122 /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
123 case NS_rtf::LN_BRCRIGHT
:
125 writerfilter::Reference
<Properties
>::Pointer_t pProperties
= rVal
.getProperties();
126 localResolve( rName
, pProperties
);
129 //from LN_BRCXXXX - handled within the BorderHandler
130 /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
131 case NS_rtf::LN_DPTLINEWIDTH
: // 0x2871
132 // width of a single line in 1/8 pt, max of 32 pt -> twip * 5 / 2.
133 m_nLineWidth
= ConversionHelper::convertTwipToMM100( nIntValue
* 5 / 2 );
135 /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
136 case NS_rtf::LN_BRCTYPE
: // 0x2872
137 m_nLineType
= nIntValue
;
139 /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
140 case NS_ooxml::LN_CT_Border_color
:
141 /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
142 case NS_rtf::LN_ICO
: // 0x2873
143 m_nLineColor
= nIntValue
;
145 /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
146 case NS_rtf::LN_DPTSPACE
: // 0x2874
147 m_nLineDistance
= nIntValue
;
149 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
150 case NS_rtf::LN_FSHADOW
: // 0x2875
151 //if 1 then line has shadow - unsupported
152 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
153 case NS_rtf::LN_FFRAME
: // 0x2876
154 /* WRITERFILTERSTATUS: done: 0, planned: 0, spent: 0 */
155 case NS_rtf::LN_UNUSED2_15
: // 0x2877
158 case NS_ooxml::LN_CT_Border_themeColor
:
159 case NS_ooxml::LN_CT_Border_themeTint
:
160 case NS_ooxml::LN_CT_Border_themeShade
:
164 OSL_ENSURE(false, "unknown attribute");
167 /*-- 08.10.2007 12:55:32---------------------------------------------------
169 -----------------------------------------------------------------------*/
170 void TDefTableHandler::localResolve(Id rName
, writerfilter::Reference
<Properties
>::Pointer_t pProperties
)
172 if( pProperties
.get())
174 m_nLineWidth
= m_nLineType
= m_nLineColor
= m_nLineDistance
= 0;
175 pProperties
->resolve( *this );
176 table::BorderLine aBorderLine
;
177 ConversionHelper::MakeBorderLine( m_nLineWidth
, m_nLineType
, m_nLineColor
,
178 aBorderLine
, m_bOOXML
);
180 /* WRITERFILTERSTATUS: table: TDefTable_localresolve */
183 /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
184 case NS_ooxml::LN_CT_TcBorders_top
:
185 /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
186 case NS_rtf::LN_BRCTOP
:
187 m_aTopBorderLines
.push_back(aBorderLine
);
189 /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
190 case NS_ooxml::LN_CT_TcBorders_left
:
191 /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
192 case NS_rtf::LN_BRCLEFT
:
193 m_aLeftBorderLines
.push_back(aBorderLine
);
195 /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
196 case NS_ooxml::LN_CT_TcBorders_bottom
:
197 /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
198 case NS_rtf::LN_BRCBOTTOM
:
199 m_aBottomBorderLines
.push_back(aBorderLine
);
201 /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
202 case NS_ooxml::LN_CT_TcBorders_right
:
203 /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
204 case NS_rtf::LN_BRCRIGHT
:
205 m_aRightBorderLines
.push_back(aBorderLine
);
207 case NS_ooxml::LN_CT_TcBorders_insideH
:
208 m_aInsideHBorderLines
.push_back(aBorderLine
);
210 case NS_ooxml::LN_CT_TcBorders_insideV
:
211 m_aInsideVBorderLines
.push_back(aBorderLine
);
217 /*-- 24.04.2007 09:06:35---------------------------------------------------
219 -----------------------------------------------------------------------*/
220 void TDefTableHandler::sprm(Sprm
& rSprm
)
222 /* WRITERFILTERSTATUS: table: TDefTable_sprm */
223 switch( rSprm
.getId() )
225 /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
226 case NS_ooxml::LN_CT_TcBorders_top
:
227 /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
228 case NS_ooxml::LN_CT_TcBorders_left
:
229 /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
230 case NS_ooxml::LN_CT_TcBorders_bottom
:
231 /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
232 case NS_ooxml::LN_CT_TcBorders_right
:
233 case NS_ooxml::LN_CT_TcBorders_insideH
:
234 case NS_ooxml::LN_CT_TcBorders_insideV
:
235 case NS_ooxml::LN_CT_TcBorders_tl2br
:
236 case NS_ooxml::LN_CT_TcBorders_tr2bl
:
238 writerfilter::Reference
<Properties
>::Pointer_t pProperties
= rSprm
.getProps();
239 localResolve( rSprm
.getId(), pProperties
);
245 /*-- 24.04.2007 09:09:01---------------------------------------------------
247 -----------------------------------------------------------------------*/
248 PropertyMapPtr
TDefTableHandler::getRowProperties() const
250 PropertyMapPtr
pPropertyMap(new PropertyMap
);
252 // Writer only wants the separators, Word provides also the outer border positions
253 if( m_aCellBorderPositions
.size() > 2 )
255 //determine table width
256 double nFullWidth
= m_aCellBorderPositions
[m_aCellBorderPositions
.size() - 1] - m_aCellBorderPositions
[0];
257 //the positions have to be distibuted in a range of 10000
258 const double nFullWidthRelative
= 10000.;
259 uno::Sequence
< text::TableColumnSeparator
> aSeparators( m_aCellBorderPositions
.size() - 2 );
260 text::TableColumnSeparator
* pSeparators
= aSeparators
.getArray();
261 for( sal_uInt32 nBorder
= 1; nBorder
< m_aCellBorderPositions
.size() - 1; ++nBorder
)
264 sal::static_int_cast
< sal_Int16
>(double(m_aCellBorderPositions
[nBorder
]) * nFullWidthRelative
/ nFullWidth
);
266 pSeparators
[nBorder
- 1].Position
= nRelPos
;
267 pSeparators
[nBorder
- 1].IsVisible
= sal_True
;
269 pPropertyMap
->Insert( PROP_TABLE_COLUMN_SEPARATORS
, false, uno::makeAny( aSeparators
) );
274 /*-- 10.05.2007 16:10:33---------------------------------------------------
276 -----------------------------------------------------------------------*/
277 void TDefTableHandler::fillCellProperties(
278 size_t nCell
, ::boost::shared_ptr
< TablePropertyMap
> pCellProperties
) const
280 if( m_aCellBorderPositions
.size() > nCell
)
282 sal_Int16 nVertOrient
= text::VertOrientation::NONE
;
283 switch( m_aCellVertAlign
[nCell
] ) //0 - top 1 - center 2 - bottom
285 case 1: nVertOrient
= text::VertOrientation::CENTER
; break;
286 case 2: nVertOrient
= text::VertOrientation::BOTTOM
; break;
289 pCellProperties
->Insert( PROP_VERT_ORIENT
, false, uno::makeAny( nVertOrient
) );
291 if( m_aTopBorderLines
.size() > nCell
)
292 pCellProperties
->Insert( PROP_TOP_BORDER
, false, uno::makeAny( m_aTopBorderLines
[nCell
] ) );
293 if( m_aLeftBorderLines
.size() > nCell
)
294 pCellProperties
->Insert( PROP_LEFT_BORDER
, false, uno::makeAny( m_aLeftBorderLines
[nCell
] ) );
295 if( m_aBottomBorderLines
.size() > nCell
)
296 pCellProperties
->Insert( PROP_BOTTOM_BORDER
, false, uno::makeAny( m_aBottomBorderLines
[nCell
] ) );
297 if( m_aRightBorderLines
.size() > nCell
)
298 pCellProperties
->Insert( PROP_RIGHT_BORDER
, false, uno::makeAny( m_aRightBorderLines
[nCell
] ) );
299 if( m_aInsideHBorderLines
.size() > nCell
)
300 pCellProperties
->Insert( META_PROP_HORIZONTAL_BORDER
, false, uno::makeAny( m_aInsideHBorderLines
[nCell
] ) );
301 if( m_aInsideVBorderLines
.size() > nCell
)
302 pCellProperties
->Insert( META_PROP_VERTICAL_BORDER
, false, uno::makeAny( m_aInsideVBorderLines
[nCell
] ) );
304 /*-- 09.05.2007 13:14:17---------------------------------------------------
306 -----------------------------------------------------------------------*/
307 sal_Int32
TDefTableHandler::getTableWidth() const
309 sal_Int32 nWidth
= 0;
310 if( m_aCellBorderPositions
.size() > 1 )
312 //determine table width
313 nWidth
= m_aCellBorderPositions
[m_aCellBorderPositions
.size() - 1] - m_aCellBorderPositions
[0];
317 /*-- 10.05.2007 16:09:10---------------------------------------------------
319 -----------------------------------------------------------------------*/
320 size_t TDefTableHandler::getCellCount() const
322 return m_aCellVertAlign
.size();
325 } //namespace dmapper
326 } //namespace writerfilter