LibreOffice Module sw (master)  1
docxtablestyleexport.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  */
9 
10 #include "docxtablestyleexport.hxx"
11 #include "docxhelper.hxx"
12 #include <doc.hxx>
13 #include <docsh.hxx>
14 #include <oox/token/tokens.hxx>
16 #include <sax/fastattribs.hxx>
17 
18 #include <optional>
19 
20 #include <com/sun/star/beans/XPropertySet.hpp>
21 #include <com/sun/star/beans/PropertyValue.hpp>
22 #include <com/sun/star/frame/XModel.hpp>
23 
24 using namespace com::sun::star;
25 using namespace oox;
26 
29 {
30 private:
33 
34 public:
35  Impl(SwDoc& rDoc)
36  : m_rDoc(rDoc)
37  {
38  }
39 
40  void TableStyle(const uno::Sequence<beans::PropertyValue>& rStyle);
41 
43  {
44  m_pSerializer = std::move(pSerializer);
45  }
46 
47  const sax_fastparser::FSHelperPtr& getSerializer() const { return m_pSerializer; }
48 
49  SwDoc& getDoc() const { return m_rDoc; }
50 
52  void handleBoolean(const OUString& aValue, sal_Int32 nToken);
53 
55  void tableStylePPr(const uno::Sequence<beans::PropertyValue>& rPPr);
57  void tableStyleTableStylePr(const uno::Sequence<beans::PropertyValue>& rTableStylePr);
59  void tableStyleRPr(const uno::Sequence<beans::PropertyValue>& rRPr);
61  void tableStyleRRFonts(const uno::Sequence<beans::PropertyValue>& rRFonts);
63  void tableStyleRLang(const uno::Sequence<beans::PropertyValue>& rLang);
65  void tableStylePInd(const uno::Sequence<beans::PropertyValue>& rInd);
67  void tableStylePSpacing(const uno::Sequence<beans::PropertyValue>& rSpacing);
69  void tableStyleTablePr(const uno::Sequence<beans::PropertyValue>& rTablePr);
71  void tableStyleTrPr(const uno::Sequence<beans::PropertyValue>& rTrPr);
73  void tableStyleTcPr(const uno::Sequence<beans::PropertyValue>& rTcPr);
75  void tableStyleTcBorders(const uno::Sequence<beans::PropertyValue>& rTcBorders,
76  sal_Int32 nToken = XML_tcBorders);
78  void tableStyleTableInd(const uno::Sequence<beans::PropertyValue>& rTableInd);
80  void tableStyleTableCellMar(const uno::Sequence<beans::PropertyValue>& rTableCellMar,
81  sal_Int32 nType = XML_tblCellMar);
83  void tableStyleTcBorder(sal_Int32 nToken, const uno::Sequence<beans::PropertyValue>& rTcBorder);
85  void tableStyleShd(const uno::Sequence<beans::PropertyValue>& rShd);
87  void tableStyleRColor(const uno::Sequence<beans::PropertyValue>& rColor);
88 };
89 
90 void DocxTableStyleExport::CnfStyle(const uno::Sequence<beans::PropertyValue>& rAttributeList)
91 {
94 
95  for (const auto& rAttribute : rAttributeList)
96  {
97  if (rAttribute.Name == "val")
98  pAttributeList->add(FSNS(XML_w, XML_val), rAttribute.Value.get<OUString>().toUtf8());
99  else
100  {
101  static DocxStringTokenMap const aTokens[]
102  = { { "firstRow", XML_firstRow },
103  { "lastRow", XML_lastRow },
104  { "firstColumn", XML_firstColumn },
105  { "lastColumn", XML_lastColumn },
106  { "oddVBand", XML_oddVBand },
107  { "evenVBand", XML_evenVBand },
108  { "oddHBand", XML_oddHBand },
109  { "evenHBand", XML_evenHBand },
110  { "firstRowFirstColumn", XML_firstRowFirstColumn },
111  { "firstRowLastColumn", XML_firstRowLastColumn },
112  { "lastRowFirstColumn", XML_lastRowFirstColumn },
113  { "lastRowLastColumn", XML_lastRowLastColumn },
114  { nullptr, 0 } };
115 
116  if (sal_Int32 nToken = DocxStringGetToken(aTokens, rAttribute.Name))
117  pAttributeList->add(FSNS(XML_w, nToken), rAttribute.Value.get<OUString>().toUtf8());
118  }
119  }
120 
121  m_pImpl->getSerializer()->singleElementNS(XML_w, XML_cnfStyle, pAttributeList);
122 }
123 
124 void DocxTableStyleExport::TableStyles(sal_Int32 nCountStylesToWrite)
125 {
126  // Do we have table styles from InteropGrabBag available?
127  uno::Reference<beans::XPropertySet> xPropertySet(
128  m_pImpl->getDoc().GetDocShell()->GetBaseModel(), uno::UNO_QUERY_THROW);
129  uno::Sequence<beans::PropertyValue> aInteropGrabBag;
130  xPropertySet->getPropertyValue("InteropGrabBag") >>= aInteropGrabBag;
131  uno::Sequence<beans::PropertyValue> aTableStyles;
132  auto pProp = std::find_if(
133  aInteropGrabBag.begin(), aInteropGrabBag.end(),
134  [](const beans::PropertyValue& rProp) { return rProp.Name == "tableStyles"; });
135  if (pProp != aInteropGrabBag.end())
136  pProp->Value >>= aTableStyles;
137  if (!aTableStyles.hasElements())
138  return;
139 
140  if (nCountStylesToWrite > aTableStyles.getLength())
141  nCountStylesToWrite = aTableStyles.getLength();
142 
143  for (sal_Int32 i = 0; i < nCountStylesToWrite; ++i)
144  {
145  uno::Sequence<beans::PropertyValue> aTableStyle;
146  aTableStyles[i].Value >>= aTableStyle;
147  m_pImpl->TableStyle(aTableStyle);
148  }
149 }
150 
152  const uno::Sequence<beans::PropertyValue>& rTableCellMar, sal_Int32 nType)
153 {
154  static DocxStringTokenMap const aTableCellMarTokens[]
155  = { { "left", XML_left }, { "right", XML_right }, { "start", XML_start },
156  { "end", XML_end }, { "top", XML_top }, { "bottom", XML_bottom },
157  { nullptr, 0 } };
158 
159  if (!rTableCellMar.hasElements())
160  return;
161 
162  m_pSerializer->startElementNS(XML_w, nType);
163  for (const auto& rProp : rTableCellMar)
164  {
165  if (sal_Int32 nToken = DocxStringGetToken(aTableCellMarTokens, rProp.Name))
166  {
168  rProp.Value.get<uno::Sequence<beans::PropertyValue>>());
169  m_pSerializer->singleElementNS(XML_w, nToken, FSNS(XML_w, XML_w),
170  OString::number(aMap["w"].get<sal_Int32>()),
171  FSNS(XML_w, XML_type), aMap["type"].get<OUString>());
172  }
173  }
174  m_pSerializer->endElementNS(XML_w, nType);
175 }
176 
178  sal_Int32 nToken, const uno::Sequence<beans::PropertyValue>& rTcBorder)
179 {
180  static DocxStringTokenMap const aTcBorderTokens[] = { { "val", XML_val },
181  { "sz", XML_sz },
182  { "color", XML_color },
183  { "space", XML_space },
184  { "themeColor", XML_themeColor },
185  { "themeTint", XML_themeTint },
186  { nullptr, 0 } };
187 
188  if (!rTcBorder.hasElements())
189  return;
190 
193  for (const auto& rProp : rTcBorder)
194  if (sal_Int32 nAttrToken = DocxStringGetToken(aTcBorderTokens, rProp.Name))
195  pAttributeList->add(FSNS(XML_w, nAttrToken), rProp.Value.get<OUString>().toUtf8());
196 
197  m_pSerializer->singleElementNS(XML_w, nToken, pAttributeList);
198 }
199 
201  const uno::Sequence<beans::PropertyValue>& rTcBorders, sal_Int32 nToken)
202 {
203  static DocxStringTokenMap const aTcBordersTokens[] = { { "left", XML_left },
204  { "right", XML_right },
205  { "start", XML_start },
206  { "end", XML_end },
207  { "top", XML_top },
208  { "bottom", XML_bottom },
209  { "insideH", XML_insideH },
210  { "insideV", XML_insideV },
211  { "tl2br", XML_tl2br },
212  { "tr2bl", XML_tr2bl },
213  { nullptr, 0 } };
214 
215  if (!rTcBorders.hasElements())
216  return;
217 
218  m_pSerializer->startElementNS(XML_w, nToken);
219  for (const auto& rTcBorder : rTcBorders)
220  if (sal_Int32 nSubToken = DocxStringGetToken(aTcBordersTokens, rTcBorder.Name))
221  tableStyleTcBorder(nSubToken,
222  rTcBorder.Value.get<uno::Sequence<beans::PropertyValue>>());
223  m_pSerializer->endElementNS(XML_w, nToken);
224 }
225 
226 void DocxTableStyleExport::Impl::tableStyleShd(const uno::Sequence<beans::PropertyValue>& rShd)
227 {
228  if (!rShd.hasElements())
229  return;
230 
233  for (const auto& rProp : rShd)
234  {
235  if (rProp.Name == "val")
236  pAttributeList->add(FSNS(XML_w, XML_val), rProp.Value.get<OUString>().toUtf8());
237  else if (rProp.Name == "color")
238  pAttributeList->add(FSNS(XML_w, XML_color), rProp.Value.get<OUString>().toUtf8());
239  else if (rProp.Name == "fill")
240  pAttributeList->add(FSNS(XML_w, XML_fill), rProp.Value.get<OUString>().toUtf8());
241  else if (rProp.Name == "themeFill")
242  pAttributeList->add(FSNS(XML_w, XML_themeFill), rProp.Value.get<OUString>().toUtf8());
243  else if (rProp.Name == "themeFillShade")
244  pAttributeList->add(FSNS(XML_w, XML_themeFillShade),
245  rProp.Value.get<OUString>().toUtf8());
246  else if (rProp.Name == "themeFillTint")
247  pAttributeList->add(FSNS(XML_w, XML_themeFillTint),
248  rProp.Value.get<OUString>().toUtf8());
249  }
250  m_pSerializer->singleElementNS(XML_w, XML_shd, pAttributeList);
251 }
252 
253 void DocxTableStyleExport::Impl::tableStyleRColor(const uno::Sequence<beans::PropertyValue>& rColor)
254 {
255  if (!rColor.hasElements())
256  return;
257 
260  for (const auto& rProp : rColor)
261  {
262  if (rProp.Name == "val")
263  pAttributeList->add(FSNS(XML_w, XML_val), rProp.Value.get<OUString>().toUtf8());
264  else if (rProp.Name == "themeColor")
265  pAttributeList->add(FSNS(XML_w, XML_themeColor), rProp.Value.get<OUString>().toUtf8());
266  else if (rProp.Name == "themeTint")
267  pAttributeList->add(FSNS(XML_w, XML_themeTint), rProp.Value.get<OUString>().toUtf8());
268  else if (rProp.Name == "themeShade")
269  pAttributeList->add(FSNS(XML_w, XML_themeShade), rProp.Value.get<OUString>().toUtf8());
270  }
271  m_pSerializer->singleElementNS(XML_w, XML_color, pAttributeList);
272 }
273 
274 void DocxTableStyleExport::Impl::tableStyleRLang(const uno::Sequence<beans::PropertyValue>& rLang)
275 {
276  if (!rLang.hasElements())
277  return;
278 
281  for (const auto& rProp : rLang)
282  {
283  if (rProp.Name == "eastAsia")
284  pAttributeList->add(FSNS(XML_w, XML_eastAsia), rProp.Value.get<OUString>().toUtf8());
285  else if (rProp.Name == "val")
286  pAttributeList->add(FSNS(XML_w, XML_val), rProp.Value.get<OUString>().toUtf8());
287  else if (rProp.Name == "bidi")
288  pAttributeList->add(FSNS(XML_w, XML_bidi), rProp.Value.get<OUString>().toUtf8());
289  }
290  m_pSerializer->singleElementNS(XML_w, XML_lang, pAttributeList);
291 }
292 
294  const uno::Sequence<beans::PropertyValue>& rRFonts)
295 {
296  if (!rRFonts.hasElements())
297  return;
298 
301  for (const auto& rRFont : rRFonts)
302  {
303  if (rRFont.Name == "eastAsiaTheme")
304  pAttributeList->add(FSNS(XML_w, XML_eastAsiaTheme),
305  rRFont.Value.get<OUString>().toUtf8());
306  else if (rRFont.Name == "asciiTheme")
307  pAttributeList->add(FSNS(XML_w, XML_asciiTheme), rRFont.Value.get<OUString>().toUtf8());
308  else if (rRFont.Name == "cstheme")
309  pAttributeList->add(FSNS(XML_w, XML_cstheme), rRFont.Value.get<OUString>().toUtf8());
310  else if (rRFont.Name == "hAnsiTheme")
311  pAttributeList->add(FSNS(XML_w, XML_hAnsiTheme), rRFont.Value.get<OUString>().toUtf8());
312  }
313  m_pSerializer->singleElementNS(XML_w, XML_rFonts, pAttributeList);
314 }
315 
317  const uno::Sequence<beans::PropertyValue>& rSpacing)
318 {
319  if (!rSpacing.hasElements())
320  return;
321 
324  for (const auto& rProp : rSpacing)
325  {
326  if (rProp.Name == "after")
327  pAttributeList->add(FSNS(XML_w, XML_after), rProp.Value.get<OUString>().toUtf8());
328  else if (rProp.Name == "before")
329  pAttributeList->add(FSNS(XML_w, XML_before), rProp.Value.get<OUString>().toUtf8());
330  else if (rProp.Name == "line")
331  pAttributeList->add(FSNS(XML_w, XML_line), rProp.Value.get<OUString>().toUtf8());
332  else if (rProp.Name == "lineRule")
333  pAttributeList->add(FSNS(XML_w, XML_lineRule), rProp.Value.get<OUString>().toUtf8());
334  else if (rProp.Name == "beforeLines")
335  pAttributeList->add(FSNS(XML_w, XML_beforeLines), rProp.Value.get<OUString>().toUtf8());
336  else if (rProp.Name == "ParaTopMarginBeforeAutoSpacing")
337  // Auto spacing will be available in grab bag only if it was set to true
338  pAttributeList->add(FSNS(XML_w, XML_beforeAutospacing), "1");
339  else if (rProp.Name == "afterLines")
340  pAttributeList->add(FSNS(XML_w, XML_afterLines), rProp.Value.get<OUString>().toUtf8());
341  else if (rProp.Name == "ParaBottomMarginAfterAutoSpacing")
342  // Auto spacing will be available in grab bag only if it was set to true
343  pAttributeList->add(FSNS(XML_w, XML_afterAutospacing), "1");
344  }
345  m_pSerializer->singleElementNS(XML_w, XML_spacing, pAttributeList);
346 }
347 
348 void DocxTableStyleExport::Impl::tableStylePInd(const uno::Sequence<beans::PropertyValue>& rInd)
349 {
350  if (!rInd.hasElements())
351  return;
352 
355  for (const auto& rProp : rInd)
356  {
357  if (rProp.Name == "rightChars")
358  pAttributeList->add(FSNS(XML_w, XML_rightChars), rProp.Value.get<OUString>().toUtf8());
359  else if (rProp.Name == "right")
360  pAttributeList->add(FSNS(XML_w, XML_right), rProp.Value.get<OUString>().toUtf8());
361  }
362  m_pSerializer->singleElementNS(XML_w, XML_ind, pAttributeList);
363 }
364 
366  const uno::Sequence<beans::PropertyValue>& rTableInd)
367 {
368  if (!rTableInd.hasElements())
369  return;
370 
373  for (const auto& rProp : rTableInd)
374  {
375  if (rProp.Name == "w")
376  pAttributeList->add(FSNS(XML_w, XML_w), OString::number(rProp.Value.get<sal_Int32>()));
377  else if (rProp.Name == "type")
378  pAttributeList->add(FSNS(XML_w, XML_type), rProp.Value.get<OUString>().toUtf8());
379  }
380  m_pSerializer->singleElementNS(XML_w, XML_tblInd, pAttributeList);
381 }
382 
383 void DocxTableStyleExport::Impl::handleBoolean(const OUString& aValue, sal_Int32 nToken)
384 {
385  if (aValue.isEmpty())
386  return;
389  if (aValue != "1")
390  pAttributeList->add(FSNS(XML_w, XML_val), aValue.toUtf8());
391  m_pSerializer->singleElementNS(XML_w, nToken, pAttributeList);
392 }
393 
394 void DocxTableStyleExport::Impl::tableStyleRPr(const uno::Sequence<beans::PropertyValue>& rRPr)
395 {
396  if (!rRPr.hasElements())
397  return;
398 
399  m_pSerializer->startElementNS(XML_w, XML_rPr);
400 
401  uno::Sequence<beans::PropertyValue> aRFonts;
402  uno::Sequence<beans::PropertyValue> aLang;
403  uno::Sequence<beans::PropertyValue> aColor;
404  uno::Sequence<beans::PropertyValue> aSpacingSequence;
405  bool bSequenceFlag = false;
406  OUString aB;
407  OUString aBCs;
408  OUString aI;
409  OUString aSz;
410  OUString aSzCs;
411  OUString aCaps;
412  OUString aSmallCaps;
413  OUString aSpacing;
414  for (const auto& rProp : rRPr)
415  {
416  if (rProp.Name == "rFonts")
417  aRFonts = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
418  else if (rProp.Name == "lang")
419  aLang = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
420  else if (rProp.Name == "b")
421  aB = rProp.Value.get<OUString>();
422  else if (rProp.Name == "bCs")
423  aBCs = rProp.Value.get<OUString>();
424  else if (rProp.Name == "i")
425  aI = rProp.Value.get<OUString>();
426  else if (rProp.Name == "color")
427  aColor = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
428  else if (rProp.Name == "sz")
429  aSz = rProp.Value.get<OUString>();
430  else if (rProp.Name == "szCs")
431  aSzCs = rProp.Value.get<OUString>();
432  else if (rProp.Name == "caps")
433  aCaps = rProp.Value.get<OUString>();
434  else if (rProp.Name == "smallCaps")
435  aSmallCaps = rProp.Value.get<OUString>();
436  else if (rProp.Name == "spacing")
437  {
438  if (rProp.Value.has<OUString>())
439  {
440  aSpacing = rProp.Value.get<OUString>();
441  }
442  else
443  {
444  aSpacingSequence = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
445  bSequenceFlag = true; // set the uno::Sequence flag.
446  }
447  }
448  }
449  tableStyleRRFonts(aRFonts);
450  tableStyleRLang(aLang);
451  handleBoolean(aB, XML_b);
452  handleBoolean(aBCs, XML_bCs);
453  handleBoolean(aI, XML_i);
454  handleBoolean(aCaps, XML_caps);
455  handleBoolean(aSmallCaps, XML_smallCaps);
456  tableStyleRColor(aColor);
457  if (bSequenceFlag)
458  {
459  m_pSerializer->singleElementNS(XML_w, XML_spacing, FSNS(XML_w, XML_val),
460  aSpacingSequence[0].Value.get<OUString>());
461  }
462  if (!aSpacing.isEmpty())
463  m_pSerializer->singleElementNS(XML_w, XML_spacing, FSNS(XML_w, XML_val), aSpacing);
464  if (!aSz.isEmpty())
465  m_pSerializer->singleElementNS(XML_w, XML_sz, FSNS(XML_w, XML_val), aSz);
466  if (!aSzCs.isEmpty())
467  m_pSerializer->singleElementNS(XML_w, XML_szCs, FSNS(XML_w, XML_val), aSzCs);
468 
469  m_pSerializer->endElementNS(XML_w, XML_rPr);
470 }
471 
472 void DocxTableStyleExport::Impl::tableStylePPr(const uno::Sequence<beans::PropertyValue>& rPPr)
473 {
474  if (!rPPr.hasElements())
475  return;
476 
477  m_pSerializer->startElementNS(XML_w, XML_pPr);
478 
479  uno::Sequence<beans::PropertyValue> aSpacing;
480  uno::Sequence<beans::PropertyValue> aInd;
481  bool bWordWrap = false;
482  OUString aJc;
483  OUString aSnapToGrid;
484  for (const auto& rProp : rPPr)
485  {
486  if (rProp.Name == "spacing")
487  aSpacing = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
488  else if (rProp.Name == "ind")
489  aInd = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
490  else if (rProp.Name == "wordWrap")
491  bWordWrap = true;
492  else if (rProp.Name == "jc")
493  aJc = rProp.Value.get<OUString>();
494  else if (rProp.Name == "snapToGrid")
495  aSnapToGrid = rProp.Value.get<OUString>();
496  }
497  if (bWordWrap)
498  m_pSerializer->singleElementNS(XML_w, XML_wordWrap);
499  tableStylePInd(aInd);
500  handleBoolean(aSnapToGrid, XML_snapToGrid);
501  tableStylePSpacing(aSpacing);
502  if (!aJc.isEmpty())
503  m_pSerializer->singleElementNS(XML_w, XML_jc, FSNS(XML_w, XML_val), aJc);
504 
505  m_pSerializer->endElementNS(XML_w, XML_pPr);
506 }
507 
509  const uno::Sequence<beans::PropertyValue>& rTablePr)
510 {
511  if (!rTablePr.hasElements())
512  return;
513 
514  m_pSerializer->startElementNS(XML_w, XML_tblPr);
515 
516  uno::Sequence<beans::PropertyValue> aTableInd;
517  uno::Sequence<beans::PropertyValue> aTableBorders;
518  uno::Sequence<beans::PropertyValue> aTableCellMar;
519  std::optional<sal_Int32> oTableStyleRowBandSize;
520  std::optional<sal_Int32> oTableStyleColBandSize;
521  for (const auto& rProp : rTablePr)
522  {
523  if (rProp.Name == "tblStyleRowBandSize")
524  oTableStyleRowBandSize = rProp.Value.get<sal_Int32>();
525  else if (rProp.Name == "tblStyleColBandSize")
526  oTableStyleColBandSize = rProp.Value.get<sal_Int32>();
527  else if (rProp.Name == "tblInd")
528  aTableInd = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
529  else if (rProp.Name == "tblBorders")
530  aTableBorders = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
531  else if (rProp.Name == "tblCellMar")
532  aTableCellMar = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
533  }
534  if (oTableStyleRowBandSize)
535  m_pSerializer->singleElementNS(XML_w, XML_tblStyleRowBandSize, FSNS(XML_w, XML_val),
536  OString::number(*oTableStyleRowBandSize));
537  if (oTableStyleColBandSize)
538  m_pSerializer->singleElementNS(XML_w, XML_tblStyleColBandSize, FSNS(XML_w, XML_val),
539  OString::number(*oTableStyleColBandSize));
540  tableStyleTableInd(aTableInd);
541  tableStyleTcBorders(aTableBorders, XML_tblBorders);
542  tableStyleTableCellMar(aTableCellMar);
543 
544  m_pSerializer->endElementNS(XML_w, XML_tblPr);
545 }
546 
547 void DocxTableStyleExport::Impl::tableStyleTrPr(const uno::Sequence<beans::PropertyValue>& rTrPr)
548 {
549  if (!rTrPr.hasElements())
550  return;
551 
552  m_pSerializer->startElementNS(XML_w, XML_trPr);
553 
554  for (const auto& rProp : rTrPr)
555  {
556  if (rProp.Name == "tblHeader")
557  m_pSerializer->singleElementNS(XML_w, XML_tblHeader);
558  }
559 
560  m_pSerializer->endElementNS(XML_w, XML_trPr);
561 }
562 
563 void DocxTableStyleExport::Impl::tableStyleTcPr(const uno::Sequence<beans::PropertyValue>& rTcPr)
564 {
565  if (!rTcPr.hasElements())
566  return;
567 
568  m_pSerializer->startElementNS(XML_w, XML_tcPr);
569 
570  uno::Sequence<beans::PropertyValue> aShd;
571  uno::Sequence<beans::PropertyValue> aTcBorders;
572  uno::Sequence<beans::PropertyValue> aTcMar;
573  OUString aVAlign;
574  for (const auto& rProp : rTcPr)
575  {
576  if (rProp.Name == "shd")
577  aShd = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
578  else if (rProp.Name == "tcBorders")
579  aTcBorders = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
580  else if (rProp.Name == "tcMar")
581  aTcMar = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
582  else if (rProp.Name == "vAlign")
583  aVAlign = rProp.Value.get<OUString>();
584  }
585  tableStyleTcBorders(aTcBorders);
586  tableStyleTableCellMar(aTcMar, XML_tcMar);
587  tableStyleShd(aShd);
588  if (!aVAlign.isEmpty())
589  m_pSerializer->singleElementNS(XML_w, XML_vAlign, FSNS(XML_w, XML_val), aVAlign);
590 
591  m_pSerializer->endElementNS(XML_w, XML_tcPr);
592 }
593 
595  const uno::Sequence<beans::PropertyValue>& rTableStylePr)
596 {
597  if (!rTableStylePr.hasElements())
598  return;
599 
600  OUString aType;
601  uno::Sequence<beans::PropertyValue> aPPr;
602  uno::Sequence<beans::PropertyValue> aRPr;
603  uno::Sequence<beans::PropertyValue> aTablePr;
604  uno::Sequence<beans::PropertyValue> aTrPr;
605  uno::Sequence<beans::PropertyValue> aTcPr;
606  for (const auto& rProp : rTableStylePr)
607  {
608  if (rProp.Name == "type")
609  aType = rProp.Value.get<OUString>();
610  else if (rProp.Name == "pPr")
611  aPPr = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
612  else if (rProp.Name == "rPr")
613  aRPr = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
614  else if (rProp.Name == "tblPr")
615  aTablePr = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
616  else if (rProp.Name == "trPr")
617  aTrPr = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
618  else if (rProp.Name == "tcPr")
619  aTcPr = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
620  }
621 
622  m_pSerializer->startElementNS(XML_w, XML_tblStylePr, FSNS(XML_w, XML_type), aType);
623 
624  tableStylePPr(aPPr);
625  tableStyleRPr(aRPr);
626  if (aTablePr.hasElements())
627  tableStyleTablePr(aTablePr);
628  else
629  {
630  // Even if we have an empty container, write it out, as Word does.
631  m_pSerializer->singleElementNS(XML_w, XML_tblPr);
632  }
633  tableStyleTrPr(aTrPr);
634  tableStyleTcPr(aTcPr);
635 
636  m_pSerializer->endElementNS(XML_w, XML_tblStylePr);
637 }
638 
639 void DocxTableStyleExport::Impl::TableStyle(const uno::Sequence<beans::PropertyValue>& rStyle)
640 {
641  bool bDefault = false;
642  bool bCustomStyle = false;
643  bool bQFormat = false;
644  bool bSemiHidden = false;
645  bool bUnhideWhenUsed = false;
646  OUString aStyleId;
647  OUString aName;
648  OUString aBasedOn;
649  OUString aRsid;
650  OUString aUiPriority;
651  uno::Sequence<beans::PropertyValue> aPPr;
652  uno::Sequence<beans::PropertyValue> aRPr;
653  uno::Sequence<beans::PropertyValue> aTablePr;
654  uno::Sequence<beans::PropertyValue> aTcPr;
655  std::vector<uno::Sequence<beans::PropertyValue>> aTableStylePrs;
656  for (const auto& rProp : rStyle)
657  {
658  if (rProp.Name == "default")
659  bDefault = rProp.Value.get<bool>();
660  else if (rProp.Name == "customStyle")
661  bCustomStyle = rProp.Value.get<bool>();
662  else if (rProp.Name == "styleId")
663  aStyleId = rProp.Value.get<OUString>();
664  else if (rProp.Name == "name")
665  aName = rProp.Value.get<OUString>();
666  else if (rProp.Name == "basedOn")
667  aBasedOn = rProp.Value.get<OUString>();
668  else if (rProp.Name == "uiPriority")
669  aUiPriority = rProp.Value.get<OUString>();
670  else if (rProp.Name == "qFormat")
671  bQFormat = true;
672  else if (rProp.Name == "semiHidden")
673  bSemiHidden = true;
674  else if (rProp.Name == "unhideWhenUsed")
675  bUnhideWhenUsed = true;
676  else if (rProp.Name == "rsid")
677  aRsid = rProp.Value.get<OUString>();
678  else if (rProp.Name == "pPr")
679  aPPr = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
680  else if (rProp.Name == "rPr")
681  aRPr = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
682  else if (rProp.Name == "tblPr")
683  aTablePr = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
684  else if (rProp.Name == "tcPr")
685  aTcPr = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
686  else if (rProp.Name == "tblStylePr")
687  aTableStylePrs.push_back(rProp.Value.get<uno::Sequence<beans::PropertyValue>>());
688  }
689 
692  pAttributeList->add(FSNS(XML_w, XML_type), "table");
693  if (bDefault)
694  pAttributeList->add(FSNS(XML_w, XML_default), "1");
695  if (bCustomStyle)
696  pAttributeList->add(FSNS(XML_w, XML_customStyle), "1");
697  if (!aStyleId.isEmpty())
698  pAttributeList->add(FSNS(XML_w, XML_styleId), aStyleId.toUtf8());
699  m_pSerializer->startElementNS(XML_w, XML_style, pAttributeList);
700 
701  m_pSerializer->singleElementNS(XML_w, XML_name, FSNS(XML_w, XML_val), aName);
702  if (!aBasedOn.isEmpty())
703  m_pSerializer->singleElementNS(XML_w, XML_basedOn, FSNS(XML_w, XML_val), aBasedOn);
704  if (!aUiPriority.isEmpty())
705  m_pSerializer->singleElementNS(XML_w, XML_uiPriority, FSNS(XML_w, XML_val), aUiPriority);
706  if (bSemiHidden)
707  m_pSerializer->singleElementNS(XML_w, XML_semiHidden);
708  if (bUnhideWhenUsed)
709  m_pSerializer->singleElementNS(XML_w, XML_unhideWhenUsed);
710  if (bQFormat)
711  m_pSerializer->singleElementNS(XML_w, XML_qFormat);
712  if (!aRsid.isEmpty())
713  m_pSerializer->singleElementNS(XML_w, XML_rsid, FSNS(XML_w, XML_val), aRsid);
714 
715  tableStylePPr(aPPr);
716  tableStyleRPr(aRPr);
717  tableStyleTablePr(aTablePr);
718  tableStyleTcPr(aTcPr);
719  for (const uno::Sequence<beans::PropertyValue>& i : std::as_const(aTableStylePrs))
720  tableStyleTableStylePr(i);
721 
722  m_pSerializer->endElementNS(XML_w, XML_style);
723 }
724 
726 {
727  m_pImpl->setSerializer(pSerializer);
728 }
729 
731  const sax_fastparser::FSHelperPtr& pSerializer)
732  : m_pImpl(std::make_unique<Impl>(rDoc))
733 {
734  m_pImpl->setSerializer(pSerializer);
735 }
736 
738 
739 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void tableStyleTableInd(const uno::Sequence< beans::PropertyValue > &rTableInd)
Export of w:tblInd.
void tableStyleTablePr(const uno::Sequence< beans::PropertyValue > &rTablePr)
Export of w:tblPr.
Methods in this class handle values in a table style.
void TableStyle(const uno::Sequence< beans::PropertyValue > &rStyle)
void tableStyleRColor(const uno::Sequence< beans::PropertyValue > &rColor)
Export of w:color.
void tableStyleTableCellMar(const uno::Sequence< beans::PropertyValue > &rTableCellMar, sal_Int32 nType=XML_tblCellMar)
Export of w:tblCellMar (and w:tcMar).
std::unique_ptr< Impl > m_pImpl
Definition: doc.hxx:187
void tableStylePSpacing(const uno::Sequence< beans::PropertyValue > &rSpacing)
Export of w:spacing.
void TableStyles(sal_Int32 nCountStylesToWrite)
void tableStyleTrPr(const uno::Sequence< beans::PropertyValue > &rTrPr)
Export of w:trPr.
void CnfStyle(const css::uno::Sequence< css::beans::PropertyValue > &rAttributeList)
Writes based on grab-bagged para, cell or row properties.
Value
HashMap_OWString_Interface aMap
SwDoc & m_rDoc
Definition: docbm.cxx:1206
void tableStyleTcBorders(const uno::Sequence< beans::PropertyValue > &rTcBorders, sal_Int32 nToken=XML_tcBorders)
Export of w:tcBorders (and w:tblBorders).
void SetSerializer(const sax_fastparser::FSHelperPtr &pSerializer)
void tableStyleRPr(const uno::Sequence< beans::PropertyValue > &rRPr)
Export of w:rPr.
void tableStyleShd(const uno::Sequence< beans::PropertyValue > &rShd)
Export of w:shd.
void tableStyleTableStylePr(const uno::Sequence< beans::PropertyValue > &rTableStylePr)
Export of w:tblStylePr.
void tableStylePPr(const uno::Sequence< beans::PropertyValue > &rPPr)
Export of w:pPr.
static rtl::Reference< FastAttributeList > createAttrList()
int i
void setSerializer(sax_fastparser::FSHelperPtr pSerializer)
std::shared_ptr< FastSerializerHelper > FSHelperPtr
DocxTableStyleExport(SwDoc &rDoc, const sax_fastparser::FSHelperPtr &pSerializer)
void tableStyleTcPr(const uno::Sequence< beans::PropertyValue > &rTcPr)
Export of w:tcPr.
void tableStylePInd(const uno::Sequence< beans::PropertyValue > &rInd)
Export of w:ind in a pPr.
DefTokenId nToken
OUString aName
const sax_fastparser::FSHelperPtr & getSerializer() const
constexpr sal_Int32 FSNS(sal_Int32 namespc, sal_Int32 element)
sal_Int32 DocxStringGetToken(DocxStringTokenMap const *pMap, std::u16string_view rName)
void handleBoolean(const OUString &aValue, sal_Int32 nToken)
Handles a boolean value.
if(!pCandidateA->getEnd().equal(pCandidateB->getStart()))
sax_fastparser::FSHelperPtr m_pSerializer
::std::unique_ptr< XmlIdRegistry_Impl > m_pImpl
void tableStyleTcBorder(sal_Int32 nToken, const uno::Sequence< beans::PropertyValue > &rTcBorder)
Export of a given table cell border type.
void tableStyleRRFonts(const uno::Sequence< beans::PropertyValue > &rRFonts)
Export of w:rFonts.
void tableStyleRLang(const uno::Sequence< beans::PropertyValue > &rLang)
Export of w:lang.