1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #include <TDefTableHandler.hxx>
20 #include <PropertyMap.hxx>
21 #include <ConversionHelper.hxx>
22 #include <ooxml/resourceids.hxx>
23 #include <doctok/resourceids.hxx>
24 #include <com/sun/star/table/BorderLine2.hpp>
25 #include <com/sun/star/text/TableColumnSeparator.hpp>
26 #include <com/sun/star/text/VertOrientation.hpp>
28 #include "dmapperLoggers.hxx"
30 namespace writerfilter
{
33 using namespace ::com::sun::star
;
37 TDefTableHandler::TDefTableHandler(bool bOOXML
) :
38 LoggedProperties(dmapper_logger
, "TDefTableHandler"),
48 TDefTableHandler::~TDefTableHandler()
53 void TDefTableHandler::lcl_attribute(Id rName
, Value
& rVal
)
55 sal_Int32 nIntValue
= rVal
.getInt();
60 case NS_rtf::LN_cellx
:
61 // nIntValue contains the vert. line position
62 //TODO: nIntValue is wrong for negative values!
63 if( nIntValue
> 0x7fff )
65 m_aCellBorderPositions
.push_back( ConversionHelper::convertTwipToMM100( nIntValue
) );
69 writerfilter::Reference
<Properties
>::Pointer_t pProperties
= rVal
.getProperties();
70 if( pProperties
.get())
72 pProperties
->resolve( *this );
77 case NS_rtf::LN_FFIRSTMERGED
:
78 case NS_rtf::LN_FMERGED
:
79 case NS_rtf::LN_FVERTICAL
:
80 case NS_rtf::LN_FBACKWARD
:
81 case NS_rtf::LN_FROTATEFONT
:
82 case NS_rtf::LN_FVERTMERGE
:
83 case NS_rtf::LN_FVERTRESTART
:
85 case NS_rtf::LN_VERTALIGN
:
86 //TODO: m_aCellVertAlign is just a temporary solution! 0 - top 1 - center 2 - bottom
87 m_aCellVertAlign
.push_back( nIntValue
);
89 case NS_rtf::LN_FUNUSED
:
90 case NS_rtf::LN_CellPrefferedSize
:
92 case NS_rtf::LN_BRCTOP
:
93 case NS_rtf::LN_BRCLEFT
:
94 case NS_rtf::LN_BRCBOTTOM
:
95 case NS_rtf::LN_BRCRIGHT
:
97 writerfilter::Reference
<Properties
>::Pointer_t pProperties
= rVal
.getProperties();
98 localResolve( rName
, pProperties
);
101 //from LN_BRCXXXX - handled within the BorderHandler
102 case NS_rtf::LN_DPTLINEWIDTH
: // 0x2871
103 // width of a single line in 1/8 pt, max of 32 pt -> twip * 5 / 2.
104 m_nLineWidth
= nIntValue
* 5 / 2;
106 case NS_rtf::LN_BRCTYPE
: // 0x2872
107 m_nLineType
= nIntValue
;
109 case NS_ooxml::LN_CT_Border_color
:
110 case NS_rtf::LN_ICO
: // 0x2873
111 m_nLineColor
= nIntValue
;
113 case NS_rtf::LN_DPTSPACE
: // 0x2874
114 m_nLineDistance
= nIntValue
;
116 case NS_rtf::LN_FSHADOW
: // 0x2875
117 //if 1 then line has shadow - unsupported
118 case NS_rtf::LN_FFRAME
: // 0x2876
119 case NS_rtf::LN_UNUSED2_15
: // 0x2877
122 case NS_ooxml::LN_CT_Border_themeColor
:
123 case NS_ooxml::LN_CT_Border_themeTint
:
124 case NS_ooxml::LN_CT_Border_themeShade
:
128 OSL_FAIL("unknown attribute");
133 void TDefTableHandler::localResolve(Id rName
, writerfilter::Reference
<Properties
>::Pointer_t pProperties
)
135 if( pProperties
.get())
137 m_nLineWidth
= m_nLineType
= m_nLineColor
= m_nLineDistance
= 0;
138 pProperties
->resolve( *this );
139 table::BorderLine2 aBorderLine
;
140 ConversionHelper::MakeBorderLine( m_nLineWidth
, m_nLineType
, m_nLineColor
,
141 aBorderLine
, m_bOOXML
);
142 bool rtl
= false; // TODO
145 case NS_ooxml::LN_CT_TcBorders_top
:
146 case NS_rtf::LN_BRCTOP
:
147 m_aTopBorderLines
.push_back(aBorderLine
);
149 case NS_ooxml::LN_CT_TcBorders_start
:
151 m_aRightBorderLines
.push_back(aBorderLine
);
153 m_aLeftBorderLines
.push_back(aBorderLine
);
155 case NS_ooxml::LN_CT_TcBorders_left
:
156 case NS_rtf::LN_BRCLEFT
:
157 m_aLeftBorderLines
.push_back(aBorderLine
);
159 case NS_ooxml::LN_CT_TcBorders_bottom
:
160 case NS_rtf::LN_BRCBOTTOM
:
161 m_aBottomBorderLines
.push_back(aBorderLine
);
163 case NS_ooxml::LN_CT_TcBorders_end
:
165 m_aLeftBorderLines
.push_back(aBorderLine
);
167 m_aRightBorderLines
.push_back(aBorderLine
);
169 case NS_ooxml::LN_CT_TcBorders_right
:
170 case NS_rtf::LN_BRCRIGHT
:
171 m_aRightBorderLines
.push_back(aBorderLine
);
173 case NS_ooxml::LN_CT_TcBorders_insideH
:
174 m_aInsideHBorderLines
.push_back(aBorderLine
);
176 case NS_ooxml::LN_CT_TcBorders_insideV
:
177 m_aInsideVBorderLines
.push_back(aBorderLine
);
185 void TDefTableHandler::lcl_sprm(Sprm
& rSprm
)
187 switch( rSprm
.getId() )
189 case NS_ooxml::LN_CT_TcBorders_top
:
190 case NS_ooxml::LN_CT_TcBorders_left
:
191 case NS_ooxml::LN_CT_TcBorders_start
:
192 case NS_ooxml::LN_CT_TcBorders_bottom
:
193 case NS_ooxml::LN_CT_TcBorders_right
:
194 case NS_ooxml::LN_CT_TcBorders_end
:
195 case NS_ooxml::LN_CT_TcBorders_insideH
:
196 case NS_ooxml::LN_CT_TcBorders_insideV
:
197 case NS_ooxml::LN_CT_TcBorders_tl2br
:
198 case NS_ooxml::LN_CT_TcBorders_tr2bl
:
200 writerfilter::Reference
<Properties
>::Pointer_t pProperties
= rSprm
.getProps();
201 localResolve( rSprm
.getId(), pProperties
);
209 PropertyMapPtr
TDefTableHandler::getRowProperties() const
211 PropertyMapPtr
pPropertyMap(new PropertyMap
);
213 // Writer only wants the separators, Word provides also the outer border positions
214 if( m_aCellBorderPositions
.size() > 2 )
216 //determine table width
217 double nFullWidth
= m_aCellBorderPositions
[m_aCellBorderPositions
.size() - 1] - m_aCellBorderPositions
[0];
218 //the positions have to be distibuted in a range of 10000
219 const double nFullWidthRelative
= 10000.;
220 uno::Sequence
< text::TableColumnSeparator
> aSeparators( m_aCellBorderPositions
.size() - 2 );
221 text::TableColumnSeparator
* pSeparators
= aSeparators
.getArray();
222 for( sal_uInt32 nBorder
= 1; nBorder
< m_aCellBorderPositions
.size() - 1; ++nBorder
)
225 sal::static_int_cast
< sal_Int16
>(double(m_aCellBorderPositions
[nBorder
]) * nFullWidthRelative
/ nFullWidth
);
227 pSeparators
[nBorder
- 1].Position
= nRelPos
;
228 pSeparators
[nBorder
- 1].IsVisible
= sal_True
;
230 pPropertyMap
->Insert( PROP_TABLE_COLUMN_SEPARATORS
, false, uno::makeAny( aSeparators
) );
237 void TDefTableHandler::fillCellProperties(
238 size_t nCell
, ::boost::shared_ptr
< TablePropertyMap
> pCellProperties
) const
240 if( m_aCellBorderPositions
.size() > nCell
)
242 sal_Int16 nVertOrient
= text::VertOrientation::NONE
;
243 switch( m_aCellVertAlign
[nCell
] ) //0 - top 1 - center 2 - bottom
245 case 1: nVertOrient
= text::VertOrientation::CENTER
; break;
246 case 2: nVertOrient
= text::VertOrientation::BOTTOM
; break;
249 pCellProperties
->Insert( PROP_VERT_ORIENT
, false, uno::makeAny( nVertOrient
) );
251 if( m_aTopBorderLines
.size() > nCell
)
252 pCellProperties
->Insert( PROP_TOP_BORDER
, false, uno::makeAny( m_aTopBorderLines
[nCell
] ) );
253 if( m_aLeftBorderLines
.size() > nCell
)
254 pCellProperties
->Insert( PROP_LEFT_BORDER
, false, uno::makeAny( m_aLeftBorderLines
[nCell
] ) );
255 if( m_aBottomBorderLines
.size() > nCell
)
256 pCellProperties
->Insert( PROP_BOTTOM_BORDER
, false, uno::makeAny( m_aBottomBorderLines
[nCell
] ) );
257 if( m_aRightBorderLines
.size() > nCell
)
258 pCellProperties
->Insert( PROP_RIGHT_BORDER
, false, uno::makeAny( m_aRightBorderLines
[nCell
] ) );
259 if( m_aInsideHBorderLines
.size() > nCell
)
260 pCellProperties
->Insert( META_PROP_HORIZONTAL_BORDER
, false, uno::makeAny( m_aInsideHBorderLines
[nCell
] ) );
261 if( m_aInsideVBorderLines
.size() > nCell
)
262 pCellProperties
->Insert( META_PROP_VERTICAL_BORDER
, false, uno::makeAny( m_aInsideVBorderLines
[nCell
] ) );
266 sal_Int32
TDefTableHandler::getTableWidth() const
268 sal_Int32 nWidth
= 0;
269 if( m_aCellBorderPositions
.size() > 1 )
271 //determine table width
272 nWidth
= m_aCellBorderPositions
[m_aCellBorderPositions
.size() - 1] - m_aCellBorderPositions
[0];
278 size_t TDefTableHandler::getCellCount() const
280 return m_aCellVertAlign
.size();
283 } //namespace dmapper
284 } //namespace writerfilter
286 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */