fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / writerfilter / source / dmapper / TDefTableHandler.cxx
blob79e72b09e683c906fd631d6b3732863b52906369
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 {
31 namespace dmapper {
33 using namespace ::com::sun::star;
37 TDefTableHandler::TDefTableHandler(bool bOOXML) :
38 LoggedProperties(dmapper_logger, "TDefTableHandler"),
39 m_nLineWidth(0),
40 m_nLineType(0),
41 m_nLineColor(0),
42 m_nLineDistance(0),
43 m_bOOXML( bOOXML )
48 TDefTableHandler::~TDefTableHandler()
53 void TDefTableHandler::lcl_attribute(Id rName, Value & rVal)
55 sal_Int32 nIntValue = rVal.getInt();
56 (void)nIntValue;
57 (void)rName;
58 switch( rName )
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 )
64 nIntValue -= 0xffff;
65 m_aCellBorderPositions.push_back( ConversionHelper::convertTwipToMM100( nIntValue ) );
66 break;
67 case NS_rtf::LN_tc:
69 writerfilter::Reference<Properties>::Pointer_t pProperties = rVal.getProperties();
70 if( pProperties.get())
72 pProperties->resolve( *this );
75 break;
76 //from LN_tc
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:
84 break;
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 );
88 break;
89 case NS_rtf::LN_FUNUSED:
90 case NS_rtf::LN_CellPrefferedSize:
91 break;
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 );
100 break;
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;
105 break;
106 case NS_rtf::LN_BRCTYPE: // 0x2872
107 m_nLineType = nIntValue;
108 break;
109 case NS_ooxml::LN_CT_Border_color:
110 case NS_rtf::LN_ICO: // 0x2873
111 m_nLineColor = nIntValue;
112 break;
113 case NS_rtf::LN_DPTSPACE: // 0x2874
114 m_nLineDistance = nIntValue;
115 break;
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
120 // ignored
121 break;
122 case NS_ooxml::LN_CT_Border_themeColor:
123 case NS_ooxml::LN_CT_Border_themeTint:
124 case NS_ooxml::LN_CT_Border_themeShade:
125 // ignored
126 break;
127 default:
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
143 switch( rName )
145 case NS_ooxml::LN_CT_TcBorders_top:
146 case NS_rtf::LN_BRCTOP:
147 m_aTopBorderLines.push_back(aBorderLine);
148 break;
149 case NS_ooxml::LN_CT_TcBorders_start:
150 if( rtl )
151 m_aRightBorderLines.push_back(aBorderLine);
152 else
153 m_aLeftBorderLines.push_back(aBorderLine);
154 break;
155 case NS_ooxml::LN_CT_TcBorders_left:
156 case NS_rtf::LN_BRCLEFT:
157 m_aLeftBorderLines.push_back(aBorderLine);
158 break;
159 case NS_ooxml::LN_CT_TcBorders_bottom:
160 case NS_rtf::LN_BRCBOTTOM:
161 m_aBottomBorderLines.push_back(aBorderLine);
162 break;
163 case NS_ooxml::LN_CT_TcBorders_end:
164 if( rtl )
165 m_aLeftBorderLines.push_back(aBorderLine);
166 else
167 m_aRightBorderLines.push_back(aBorderLine);
168 break;
169 case NS_ooxml::LN_CT_TcBorders_right:
170 case NS_rtf::LN_BRCRIGHT:
171 m_aRightBorderLines.push_back(aBorderLine);
172 break;
173 case NS_ooxml::LN_CT_TcBorders_insideH:
174 m_aInsideHBorderLines.push_back(aBorderLine);
175 break;
176 case NS_ooxml::LN_CT_TcBorders_insideV:
177 m_aInsideVBorderLines.push_back(aBorderLine);
178 break;
179 default:;
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 );
203 break;
204 default:;
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 )
224 sal_Int16 nRelPos =
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 ) );
233 return pPropertyMap;
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;
247 default:;
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];
274 return nWidth;
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: */