Bump version to 4.3-4
[LibreOffice.git] / writerfilter / source / dmapper / TDefTableHandler.cxx
blob58b551d27654c1967e954716f62f62d261e74735
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 <filter/msfilter/util.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()
52 OUString TDefTableHandler::getBorderTypeString(sal_Int32 nType)
54 switch (nType)
56 case 255: return OUString("nil");
57 case 0: return OUString("none");
58 case 1: return OUString("single");
59 case 2: return OUString("thick");
60 case 3: return OUString("double");
61 case 6: return OUString("dotted");
62 case 7: return OUString("dashed");
63 case 8: return OUString("dotDash");
64 case 9: return OUString("dotDotDash");
65 case 10: return OUString("triple");
66 case 11: return OUString("thinThickSmallGap");
67 case 12: return OUString("thickThinSmallGap");
68 case 13: return OUString("thinThickThinSmallGap");
69 case 14: return OUString("thinThickMediumGap");
70 case 15: return OUString("thickThinMediumGap");
71 case 16: return OUString("thinThickThinMediumGap");
72 case 17: return OUString("thinThickLargeGap");
73 case 18: return OUString("thickThinLargeGap");
74 case 19: return OUString("thinThickThinLargeGap");
75 case 20: return OUString("wave");
76 case 21: return OUString("doubleWave");
77 case 22: return OUString("dashSmallGap");
78 case 23: return OUString("dashDotStroked");
79 case 24: return OUString("threeDEmboss");
80 case 25: return OUString("threeDEngrave");
81 case 26: return OUString("outset");
82 case 27: return OUString("inset");
83 case 64: return OUString("apples");
84 case 65: return OUString("archedScallops");
85 case 66: return OUString("babyPacifier");
86 case 67: return OUString("babyRattle");
87 case 68: return OUString("balloons3Colors");
88 case 69: return OUString("balloonsHotAir");
89 case 70: return OUString("basicBlackDashes");
90 case 71: return OUString("basicBlackDots");
91 case 72: return OUString("basicBlackSquares");
92 case 73: return OUString("basicThinLines");
93 case 74: return OUString("basicWhiteDashes");
94 case 75: return OUString("basicWhiteDots");
95 case 76: return OUString("basicWhiteSquares");
96 case 77: return OUString("basicWideInline");
97 case 78: return OUString("basicWideMidline");
98 case 79: return OUString("basicWideOutline");
99 case 80: return OUString("bats");
100 case 81: return OUString("birds");
101 case 82: return OUString("birdsFlight");
102 case 83: return OUString("cabins");
103 case 84: return OUString("cakeSlice");
104 case 85: return OUString("candyCorn");
105 case 86: return OUString("celticKnotwork");
106 case 87: return OUString("certificateBanner");
107 case 88: return OUString("chainLink");
108 case 89: return OUString("champagneBottle");
109 case 90: return OUString("checkedBarBlack");
110 case 91: return OUString("checkedBarColor");
111 case 92: return OUString("checkered");
112 case 93: return OUString("christmasTree");
113 case 94: return OUString("circlesLines");
114 case 95: return OUString("circlesRectangles");
115 case 96: return OUString("classicalWave");
116 case 97: return OUString("clocks");
117 case 98: return OUString("compass");
118 case 99: return OUString("confetti");
119 case 100: return OUString("confettiGrays");
120 case 101: return OUString("confettiOutline");
121 case 102: return OUString("confettiStreamers");
122 case 103: return OUString("confettiWhite");
123 case 104: return OUString("cornerTriangles");
124 case 105: return OUString("couponCutoutDashes");
125 case 106: return OUString("couponCutoutDots");
126 case 107: return OUString("crazyMaze");
127 case 108: return OUString("creaturesButterfly");
128 case 109: return OUString("creaturesFish");
129 case 110: return OUString("creaturesInsects");
130 case 111: return OUString("creaturesLadyBug");
131 case 112: return OUString("crossStitch");
132 case 113: return OUString("cup");
133 case 114: return OUString("decoArch");
134 case 115: return OUString("decoArchColor");
135 case 116: return OUString("decoBlocks");
136 case 117: return OUString("diamondsGray");
137 case 118: return OUString("doubleD");
138 case 119: return OUString("doubleDiamonds");
139 case 120: return OUString("earth1");
140 case 121: return OUString("earth2");
141 case 122: return OUString("eclipsingSquares1");
142 case 123: return OUString("eclipsingSquares2");
143 case 124: return OUString("eggsBlack");
144 case 125: return OUString("fans");
145 case 126: return OUString("film");
146 case 127: return OUString("firecrackers");
147 case 128: return OUString("flowersBlockPrint");
148 case 129: return OUString("flowersDaisies");
149 case 130: return OUString("flowersModern1");
150 case 131: return OUString("flowersModern2");
151 case 132: return OUString("flowersPansy");
152 case 133: return OUString("flowersRedRose");
153 case 134: return OUString("flowersRoses");
154 case 135: return OUString("flowersTeacup");
155 case 136: return OUString("flowersTiny");
156 case 137: return OUString("gems");
157 case 138: return OUString("gingerbreadMan");
158 case 139: return OUString("gradient");
159 case 140: return OUString("handmade1");
160 case 141: return OUString("handmade2");
161 case 142: return OUString("heartBalloon");
162 case 143: return OUString("heartGray");
163 case 144: return OUString("hearts");
164 case 145: return OUString("heebieJeebies");
165 case 146: return OUString("holly");
166 case 147: return OUString("houseFunky");
167 case 148: return OUString("hypnotic");
168 case 149: return OUString("iceCreamCones");
169 case 150: return OUString("lightBulb");
170 case 151: return OUString("lightning1");
171 case 152: return OUString("lightning2");
172 case 153: return OUString("mapPins");
173 case 154: return OUString("mapleLeaf");
174 case 155: return OUString("mapleMuffins");
175 case 156: return OUString("marquee");
176 case 157: return OUString("marqueeToothed");
177 case 158: return OUString("moons");
178 case 159: return OUString("mosaic");
179 case 160: return OUString("musicNotes");
180 case 161: return OUString("northwest");
181 case 162: return OUString("ovals");
182 case 163: return OUString("packages");
183 case 164: return OUString("palmsBlack");
184 case 165: return OUString("palmsColor");
185 case 166: return OUString("paperClips");
186 case 167: return OUString("papyrus");
187 case 168: return OUString("partyFavor");
188 case 169: return OUString("partyGlass");
189 case 170: return OUString("pencils");
190 case 171: return OUString("people");
191 case 172: return OUString("peopleWaving");
192 case 173: return OUString("peopleHats");
193 case 174: return OUString("poinsettias");
194 case 175: return OUString("postageStamp");
195 case 176: return OUString("pumpkin1");
196 case 177: return OUString("pushPinNote2");
197 case 178: return OUString("pushPinNote1");
198 case 179: return OUString("pyramids");
199 case 180: return OUString("pyramidsAbove");
200 case 181: return OUString("quadrants");
201 case 182: return OUString("rings");
202 case 183: return OUString("safari");
203 case 184: return OUString("sawtooth");
204 case 185: return OUString("sawtoothGray");
205 case 186: return OUString("scaredCat");
206 case 187: return OUString("seattle");
207 case 188: return OUString("shadowedSquares");
208 case 189: return OUString("sharksTeeth");
209 case 190: return OUString("shorebirdTracks");
210 case 191: return OUString("skyrocket");
211 case 192: return OUString("snowflakeFancy");
212 case 193: return OUString("snowflakes");
213 case 194: return OUString("sombrero");
214 case 195: return OUString("southwest");
215 case 196: return OUString("stars");
216 case 197: return OUString("starsTop");
217 case 198: return OUString("stars3d");
218 case 199: return OUString("starsBlack");
219 case 200: return OUString("starsShadowed");
220 case 201: return OUString("sun");
221 case 202: return OUString("swirligig");
222 case 203: return OUString("tornPaper");
223 case 204: return OUString("tornPaperBlack");
224 case 205: return OUString("trees");
225 case 206: return OUString("triangleParty");
226 case 207: return OUString("triangles");
227 case 208: return OUString("tribal1");
228 case 209: return OUString("tribal2");
229 case 210: return OUString("tribal3");
230 case 211: return OUString("tribal4");
231 case 212: return OUString("tribal5");
232 case 213: return OUString("tribal6");
233 case 214: return OUString("twistedLines1");
234 case 215: return OUString("twistedLines2");
235 case 216: return OUString("vine");
236 case 217: return OUString("waveline");
237 case 218: return OUString("weavingAngles");
238 case 219: return OUString("weavingBraid");
239 case 220: return OUString("weavingRibbon");
240 case 221: return OUString("weavingStrips");
241 case 222: return OUString("whiteFlowers");
242 case 223: return OUString("woodwork");
243 case 224: return OUString("xIllusions");
244 case 225: return OUString("zanyTriangles");
245 case 226: return OUString("zigZag");
246 case 227: return OUString("zigZagStitch");
247 default: break;
249 return OUString();
252 OUString TDefTableHandler::getThemeColorTypeString(sal_Int32 nType)
254 switch (nType)
256 case NS_ooxml::LN_Value_St_ThemeColor_dark1: return OUString("dark1");
257 case NS_ooxml::LN_Value_St_ThemeColor_light1: return OUString("light1");
258 case NS_ooxml::LN_Value_St_ThemeColor_dark2: return OUString("dark2");
259 case NS_ooxml::LN_Value_St_ThemeColor_light2: return OUString("light2");
260 case NS_ooxml::LN_Value_St_ThemeColor_accent1: return OUString("accent1");
261 case NS_ooxml::LN_Value_St_ThemeColor_accent2: return OUString("accent2");
262 case NS_ooxml::LN_Value_St_ThemeColor_accent3: return OUString("accent3");
263 case NS_ooxml::LN_Value_St_ThemeColor_accent4: return OUString("accent4");
264 case NS_ooxml::LN_Value_St_ThemeColor_accent5: return OUString("accent5");
265 case NS_ooxml::LN_Value_St_ThemeColor_accent6: return OUString("accent6");
266 case NS_ooxml::LN_Value_St_ThemeColor_hyperlink: return OUString("hyperlink");
267 case NS_ooxml::LN_Value_St_ThemeColor_followedHyperlink: return OUString("followedHyperlink");
268 case NS_ooxml::LN_Value_St_ThemeColor_none: return OUString("none");
269 case NS_ooxml::LN_Value_St_ThemeColor_background1: return OUString("background1");
270 case NS_ooxml::LN_Value_St_ThemeColor_text1: return OUString("text1");
271 case NS_ooxml::LN_Value_St_ThemeColor_background2: return OUString("background2");
272 case NS_ooxml::LN_Value_St_ThemeColor_text2: return OUString("text2");
273 default: break;
275 return OUString();
278 void TDefTableHandler::lcl_attribute(Id rName, Value & rVal)
280 sal_Int32 nIntValue = rVal.getInt();
281 (void)nIntValue;
282 (void)rName;
283 switch( rName )
285 case NS_ooxml::LN_CT_Border_sz:
286 // width of a single line in 1/8 pt, max of 32 pt -> twip * 5 / 2.
287 m_nLineWidth = nIntValue * 5 / 2;
288 appendGrabBag("sz", OUString::number(nIntValue));
289 break;
290 case NS_ooxml::LN_CT_Border_val:
291 m_nLineType = nIntValue;
292 appendGrabBag("val", TDefTableHandler::getBorderTypeString(nIntValue));
293 break;
294 case NS_ooxml::LN_CT_Border_color:
295 appendGrabBag("color", OStringToOUString(msfilter::util::ConvertColor(nIntValue, /*bAutoColor=*/true), RTL_TEXTENCODING_UTF8));
296 m_nLineColor = nIntValue;
297 break;
298 case NS_ooxml::LN_CT_Border_space:
299 appendGrabBag("space", OUString::number(nIntValue));
300 m_nLineDistance = nIntValue;
301 break;
302 case NS_ooxml::LN_CT_Border_shadow:
303 //if 1 then line has shadow - unsupported
304 case NS_ooxml::LN_CT_Border_frame:
305 // ignored
306 break;
307 case NS_ooxml::LN_CT_Border_themeColor:
308 appendGrabBag("themeColor", TDefTableHandler::getThemeColorTypeString(nIntValue));
309 break;
310 case NS_ooxml::LN_CT_Border_themeTint:
311 case NS_ooxml::LN_CT_Border_themeShade:
312 // ignored
313 break;
314 default:
315 OSL_FAIL("unknown attribute");
320 void TDefTableHandler::localResolve(Id rName, writerfilter::Reference<Properties>::Pointer_t pProperties)
322 if( pProperties.get())
324 m_nLineWidth = m_nLineType = m_nLineColor = m_nLineDistance = 0;
325 std::vector<beans::PropertyValue> aSavedGrabBag;
326 if (!m_aInteropGrabBagName.isEmpty())
328 aSavedGrabBag = m_aInteropGrabBag;
329 m_aInteropGrabBag.clear();
331 pProperties->resolve( *this );
332 table::BorderLine2 aBorderLine;
333 ConversionHelper::MakeBorderLine( m_nLineWidth, m_nLineType, m_nLineColor,
334 aBorderLine, m_bOOXML );
335 bool rtl = false; // TODO
336 switch( rName )
338 case NS_ooxml::LN_CT_TcBorders_top:
339 m_aTopBorderLines.push_back(aBorderLine);
340 if (!m_aInteropGrabBagName.isEmpty())
341 aSavedGrabBag.push_back(getInteropGrabBag("top"));
342 break;
343 case NS_ooxml::LN_CT_TcBorders_start:
344 if( rtl )
345 m_aRightBorderLines.push_back(aBorderLine);
346 else
347 m_aLeftBorderLines.push_back(aBorderLine);
348 if (!m_aInteropGrabBagName.isEmpty())
349 aSavedGrabBag.push_back(getInteropGrabBag("start"));
350 break;
351 case NS_ooxml::LN_CT_TcBorders_left:
352 m_aLeftBorderLines.push_back(aBorderLine);
353 if (!m_aInteropGrabBagName.isEmpty())
354 aSavedGrabBag.push_back(getInteropGrabBag("left"));
355 break;
356 case NS_ooxml::LN_CT_TcBorders_bottom:
357 m_aBottomBorderLines.push_back(aBorderLine);
358 if (!m_aInteropGrabBagName.isEmpty())
359 aSavedGrabBag.push_back(getInteropGrabBag("bottom"));
360 break;
361 case NS_ooxml::LN_CT_TcBorders_end:
362 if( rtl )
363 m_aLeftBorderLines.push_back(aBorderLine);
364 else
365 m_aRightBorderLines.push_back(aBorderLine);
366 if (!m_aInteropGrabBagName.isEmpty())
367 aSavedGrabBag.push_back(getInteropGrabBag("end"));
368 break;
369 case NS_ooxml::LN_CT_TcBorders_right:
370 m_aRightBorderLines.push_back(aBorderLine);
371 if (!m_aInteropGrabBagName.isEmpty())
372 aSavedGrabBag.push_back(getInteropGrabBag("right"));
373 break;
374 case NS_ooxml::LN_CT_TcBorders_insideH:
375 m_aInsideHBorderLines.push_back(aBorderLine);
376 if (!m_aInteropGrabBagName.isEmpty())
377 aSavedGrabBag.push_back(getInteropGrabBag("insideH"));
378 break;
379 case NS_ooxml::LN_CT_TcBorders_insideV:
380 m_aInsideVBorderLines.push_back(aBorderLine);
381 if (!m_aInteropGrabBagName.isEmpty())
382 aSavedGrabBag.push_back(getInteropGrabBag("insideV"));
383 break;
384 case NS_ooxml::LN_CT_TcBorders_tl2br:
385 if (!m_aInteropGrabBagName.isEmpty())
386 aSavedGrabBag.push_back(getInteropGrabBag("tl2br"));
387 break;
388 case NS_ooxml::LN_CT_TcBorders_tr2bl:
389 if (!m_aInteropGrabBagName.isEmpty())
390 aSavedGrabBag.push_back(getInteropGrabBag("tr2bl"));
391 break;
392 default:;
394 if (!m_aInteropGrabBagName.isEmpty())
395 m_aInteropGrabBag = aSavedGrabBag;
400 void TDefTableHandler::lcl_sprm(Sprm & rSprm)
402 switch( rSprm.getId() )
404 case NS_ooxml::LN_CT_TcBorders_top:
405 case NS_ooxml::LN_CT_TcBorders_left:
406 case NS_ooxml::LN_CT_TcBorders_start:
407 case NS_ooxml::LN_CT_TcBorders_bottom:
408 case NS_ooxml::LN_CT_TcBorders_right:
409 case NS_ooxml::LN_CT_TcBorders_end:
410 case NS_ooxml::LN_CT_TcBorders_insideH:
411 case NS_ooxml::LN_CT_TcBorders_insideV:
412 case NS_ooxml::LN_CT_TcBorders_tl2br:
413 case NS_ooxml::LN_CT_TcBorders_tr2bl:
415 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
416 localResolve( rSprm.getId(), pProperties );
418 break;
419 default:;
424 PropertyMapPtr TDefTableHandler::getRowProperties() const
426 PropertyMapPtr pPropertyMap(new PropertyMap);
428 // Writer only wants the separators, Word provides also the outer border positions
429 if( m_aCellBorderPositions.size() > 2 )
431 //determine table width
432 double nFullWidth = m_aCellBorderPositions[m_aCellBorderPositions.size() - 1] - m_aCellBorderPositions[0];
433 //the positions have to be distibuted in a range of 10000
434 const double nFullWidthRelative = 10000.;
435 uno::Sequence< text::TableColumnSeparator > aSeparators( m_aCellBorderPositions.size() - 2 );
436 text::TableColumnSeparator* pSeparators = aSeparators.getArray();
437 for( sal_uInt32 nBorder = 1; nBorder < m_aCellBorderPositions.size() - 1; ++nBorder )
439 sal_Int16 nRelPos =
440 sal::static_int_cast< sal_Int16 >(double(m_aCellBorderPositions[nBorder]) * nFullWidthRelative / nFullWidth );
442 pSeparators[nBorder - 1].Position = nRelPos;
443 pSeparators[nBorder - 1].IsVisible = sal_True;
445 pPropertyMap->Insert( PROP_TABLE_COLUMN_SEPARATORS, uno::makeAny( aSeparators ) );
448 return pPropertyMap;
452 void TDefTableHandler::fillCellProperties(
453 size_t nCell, ::boost::shared_ptr< TablePropertyMap > pCellProperties ) const
455 if( m_aCellBorderPositions.size() > nCell )
457 sal_Int16 nVertOrient = text::VertOrientation::NONE;
458 switch( m_aCellVertAlign[nCell] ) //0 - top 1 - center 2 - bottom
460 case 1: nVertOrient = text::VertOrientation::CENTER; break;
461 case 2: nVertOrient = text::VertOrientation::BOTTOM; break;
462 default:;
464 pCellProperties->Insert( PROP_VERT_ORIENT, uno::makeAny( nVertOrient ) );
466 if( m_aTopBorderLines.size() > nCell )
467 pCellProperties->Insert( PROP_TOP_BORDER, uno::makeAny( m_aTopBorderLines[nCell] ) );
468 if( m_aLeftBorderLines.size() > nCell )
469 pCellProperties->Insert( PROP_LEFT_BORDER, uno::makeAny( m_aLeftBorderLines[nCell] ) );
470 if( m_aBottomBorderLines.size() > nCell )
471 pCellProperties->Insert( PROP_BOTTOM_BORDER, uno::makeAny( m_aBottomBorderLines[nCell] ) );
472 if( m_aRightBorderLines.size() > nCell )
473 pCellProperties->Insert( PROP_RIGHT_BORDER, uno::makeAny( m_aRightBorderLines[nCell] ) );
474 if( m_aInsideHBorderLines.size() > nCell )
475 pCellProperties->Insert( META_PROP_HORIZONTAL_BORDER, uno::makeAny( m_aInsideHBorderLines[nCell] ) );
476 if( m_aInsideVBorderLines.size() > nCell )
477 pCellProperties->Insert( META_PROP_VERTICAL_BORDER, uno::makeAny( m_aInsideVBorderLines[nCell] ) );
481 sal_Int32 TDefTableHandler::getTableWidth() const
483 sal_Int32 nWidth = 0;
484 if( m_aCellBorderPositions.size() > 1 )
486 //determine table width
487 nWidth = m_aCellBorderPositions[m_aCellBorderPositions.size() - 1] - m_aCellBorderPositions[0];
489 return nWidth;
493 size_t TDefTableHandler::getCellCount() const
495 return m_aCellVertAlign.size();
498 void TDefTableHandler::enableInteropGrabBag(const OUString& aName)
500 m_aInteropGrabBagName = aName;
503 beans::PropertyValue TDefTableHandler::getInteropGrabBag(const OUString& aName)
505 beans::PropertyValue aRet;
506 if (aName.isEmpty())
507 aRet.Name = m_aInteropGrabBagName;
508 else
509 aRet.Name = aName;
511 uno::Sequence<beans::PropertyValue> aSeq(m_aInteropGrabBag.size());
512 beans::PropertyValue* pSeq = aSeq.getArray();
513 for (std::vector<beans::PropertyValue>::iterator i = m_aInteropGrabBag.begin(); i != m_aInteropGrabBag.end(); ++i)
514 *pSeq++ = *i;
515 m_aInteropGrabBag.clear();
517 aRet.Value = uno::makeAny(aSeq);
518 return aRet;
521 void TDefTableHandler::appendGrabBag(const OUString& aKey, const OUString& aValue)
523 beans::PropertyValue aProperty;
524 aProperty.Name = aKey;
525 aProperty.Value = uno::makeAny(aValue);
526 m_aInteropGrabBag.push_back(aProperty);
529 } //namespace dmapper
530 } //namespace writerfilter
532 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */