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
159 OSL_ENSURE(false, "unknown attribute");
162 /*-- 08.10.2007 12:55:32---------------------------------------------------
164 -----------------------------------------------------------------------*/
165 void TDefTableHandler::localResolve(Id rName
, writerfilter::Reference
<Properties
>::Pointer_t pProperties
)
167 if( pProperties
.get())
169 m_nLineWidth
= m_nLineType
= m_nLineColor
= m_nLineDistance
= 0;
170 pProperties
->resolve( *this );
171 table::BorderLine aBorderLine
;
172 ConversionHelper::MakeBorderLine( m_nLineWidth
, m_nLineType
, m_nLineColor
,
173 aBorderLine
, m_bOOXML
);
175 /* WRITERFILTERSTATUS: table: TDefTable_localresolve */
178 /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
179 case NS_ooxml::LN_CT_TcBorders_top
:
180 /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
181 case NS_rtf::LN_BRCTOP
:
182 m_aTopBorderLines
.push_back(aBorderLine
);
184 /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
185 case NS_ooxml::LN_CT_TcBorders_left
:
186 /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
187 case NS_rtf::LN_BRCLEFT
:
188 m_aLeftBorderLines
.push_back(aBorderLine
);
190 /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
191 case NS_ooxml::LN_CT_TcBorders_bottom
:
192 /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
193 case NS_rtf::LN_BRCBOTTOM
:
194 m_aBottomBorderLines
.push_back(aBorderLine
);
196 /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
197 case NS_ooxml::LN_CT_TcBorders_right
:
198 /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
199 case NS_rtf::LN_BRCRIGHT
:
200 m_aRightBorderLines
.push_back(aBorderLine
);
206 /*-- 24.04.2007 09:06:35---------------------------------------------------
208 -----------------------------------------------------------------------*/
209 void TDefTableHandler::sprm(Sprm
& rSprm
)
211 /* WRITERFILTERSTATUS: table: TDefTable_sprm */
212 switch( rSprm
.getId() )
214 /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
215 case NS_ooxml::LN_CT_TcBorders_top
:
216 /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
217 case NS_ooxml::LN_CT_TcBorders_left
:
218 /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
219 case NS_ooxml::LN_CT_TcBorders_bottom
:
220 /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
221 case NS_ooxml::LN_CT_TcBorders_right
:
223 writerfilter::Reference
<Properties
>::Pointer_t pProperties
= rSprm
.getProps();
224 localResolve( rSprm
.getId(), pProperties
);
230 /*-- 24.04.2007 09:09:01---------------------------------------------------
232 -----------------------------------------------------------------------*/
233 PropertyMapPtr
TDefTableHandler::getRowProperties() const
235 PropertyMapPtr
pPropertyMap(new PropertyMap
);
237 // Writer only wants the separators, Word provides also the outer border positions
238 if( m_aCellBorderPositions
.size() > 2 )
240 //determine table width
241 double nFullWidth
= m_aCellBorderPositions
[m_aCellBorderPositions
.size() - 1] - m_aCellBorderPositions
[0];
242 //the positions have to be distibuted in a range of 10000
243 const double nFullWidthRelative
= 10000.;
244 uno::Sequence
< text::TableColumnSeparator
> aSeparators( m_aCellBorderPositions
.size() - 2 );
245 text::TableColumnSeparator
* pSeparators
= aSeparators
.getArray();
246 for( sal_uInt32 nBorder
= 1; nBorder
< m_aCellBorderPositions
.size() - 1; ++nBorder
)
249 sal::static_int_cast
< sal_Int16
>(double(m_aCellBorderPositions
[nBorder
]) * nFullWidthRelative
/ nFullWidth
);
251 pSeparators
[nBorder
- 1].Position
= nRelPos
;
252 pSeparators
[nBorder
- 1].IsVisible
= sal_True
;
254 pPropertyMap
->Insert( PROP_TABLE_COLUMN_SEPARATORS
, false, uno::makeAny( aSeparators
) );
259 /*-- 10.05.2007 16:10:33---------------------------------------------------
261 -----------------------------------------------------------------------*/
262 void TDefTableHandler::fillCellProperties(
263 size_t nCell
, ::boost::shared_ptr
< TablePropertyMap
> pCellProperties
) const
265 if( m_aCellBorderPositions
.size() > nCell
)
267 sal_Int16 nVertOrient
= text::VertOrientation::NONE
;
268 switch( m_aCellVertAlign
[nCell
] ) //0 - top 1 - center 2 - bottom
270 case 1: nVertOrient
= text::VertOrientation::CENTER
; break;
271 case 2: nVertOrient
= text::VertOrientation::BOTTOM
; break;
274 pCellProperties
->Insert( PROP_VERT_ORIENT
, false, uno::makeAny( nVertOrient
) );
276 if( m_aTopBorderLines
.size() > nCell
)
277 pCellProperties
->Insert( PROP_TOP_BORDER
, false, uno::makeAny( m_aTopBorderLines
[nCell
] ) );
278 if( m_aLeftBorderLines
.size() > nCell
)
279 pCellProperties
->Insert( PROP_LEFT_BORDER
, false, uno::makeAny( m_aLeftBorderLines
[nCell
] ) );
280 if( m_aBottomBorderLines
.size() > nCell
)
281 pCellProperties
->Insert( PROP_BOTTOM_BORDER
, false, uno::makeAny( m_aBottomBorderLines
[nCell
] ) );
282 if( m_aRightBorderLines
.size() > nCell
)
283 pCellProperties
->Insert( PROP_RIGHT_BORDER
, false, uno::makeAny( m_aRightBorderLines
[nCell
] ) );
285 /*-- 09.05.2007 13:14:17---------------------------------------------------
287 -----------------------------------------------------------------------*/
288 sal_Int32
TDefTableHandler::getTableWidth() const
290 sal_Int32 nWidth
= 0;
291 if( m_aCellBorderPositions
.size() > 1 )
293 //determine table width
294 nWidth
= m_aCellBorderPositions
[m_aCellBorderPositions
.size() - 1] - m_aCellBorderPositions
[0];
298 /*-- 10.05.2007 16:09:10---------------------------------------------------
300 -----------------------------------------------------------------------*/
301 size_t TDefTableHandler::getCellCount() const
303 return m_aCellVertAlign
.size();
306 } //namespace dmapper
307 } //namespace writerfilter