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 {
92  sax_fastparser::FastAttributeList* pAttributeList
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  sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList);
122  m_pImpl->getSerializer()->singleElementNS(XML_w, XML_cnfStyle, xAttributeList);
123 }
124 
125 void DocxTableStyleExport::TableStyles(sal_Int32 nCountStylesToWrite)
126 {
127  // Do we have table styles from InteropGrabBag available?
128  uno::Reference<beans::XPropertySet> xPropertySet(
129  m_pImpl->getDoc().GetDocShell()->GetBaseModel(), uno::UNO_QUERY_THROW);
130  uno::Sequence<beans::PropertyValue> aInteropGrabBag;
131  xPropertySet->getPropertyValue("InteropGrabBag") >>= aInteropGrabBag;
132  uno::Sequence<beans::PropertyValue> aTableStyles;
133  auto pProp = std::find_if(
134  aInteropGrabBag.begin(), aInteropGrabBag.end(),
135  [](const beans::PropertyValue& rProp) { return rProp.Name == "tableStyles"; });
136  if (pProp != aInteropGrabBag.end())
137  pProp->Value >>= aTableStyles;
138  if (!aTableStyles.hasElements())
139  return;
140 
141  if (nCountStylesToWrite > aTableStyles.getLength())
142  nCountStylesToWrite = aTableStyles.getLength();
143 
144  for (sal_Int32 i = 0; i < nCountStylesToWrite; ++i)
145  {
146  uno::Sequence<beans::PropertyValue> aTableStyle;
147  aTableStyles[i].Value >>= aTableStyle;
148  m_pImpl->TableStyle(aTableStyle);
149  }
150 }
151 
153  const uno::Sequence<beans::PropertyValue>& rTableCellMar, sal_Int32 nType)
154 {
155  static DocxStringTokenMap const aTableCellMarTokens[]
156  = { { "left", XML_left }, { "right", XML_right }, { "start", XML_start },
157  { "end", XML_end }, { "top", XML_top }, { "bottom", XML_bottom },
158  { nullptr, 0 } };
159 
160  if (!rTableCellMar.hasElements())
161  return;
162 
163  m_pSerializer->startElementNS(XML_w, nType);
164  for (const auto& rProp : rTableCellMar)
165  {
166  if (sal_Int32 nToken = DocxStringGetToken(aTableCellMarTokens, rProp.Name))
167  {
169  rProp.Value.get<uno::Sequence<beans::PropertyValue>>());
170  m_pSerializer->singleElementNS(XML_w, nToken, FSNS(XML_w, XML_w),
171  OString::number(aMap["w"].get<sal_Int32>()),
172  FSNS(XML_w, XML_type), aMap["type"].get<OUString>());
173  }
174  }
175  m_pSerializer->endElementNS(XML_w, nType);
176 }
177 
179  sal_Int32 nToken, const uno::Sequence<beans::PropertyValue>& rTcBorder)
180 {
181  static DocxStringTokenMap const aTcBorderTokens[] = { { "val", XML_val },
182  { "sz", XML_sz },
183  { "color", XML_color },
184  { "space", XML_space },
185  { "themeColor", XML_themeColor },
186  { "themeTint", XML_themeTint },
187  { nullptr, 0 } };
188 
189  if (!rTcBorder.hasElements())
190  return;
191 
192  sax_fastparser::FastAttributeList* pAttributeList
194  for (const auto& rProp : rTcBorder)
195  if (sal_Int32 nAttrToken = DocxStringGetToken(aTcBorderTokens, rProp.Name))
196  pAttributeList->add(FSNS(XML_w, nAttrToken), rProp.Value.get<OUString>().toUtf8());
197 
198  sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList);
199  m_pSerializer->singleElementNS(XML_w, nToken, xAttributeList);
200 }
201 
203  const uno::Sequence<beans::PropertyValue>& rTcBorders, sal_Int32 nToken)
204 {
205  static DocxStringTokenMap const aTcBordersTokens[] = { { "left", XML_left },
206  { "right", XML_right },
207  { "start", XML_start },
208  { "end", XML_end },
209  { "top", XML_top },
210  { "bottom", XML_bottom },
211  { "insideH", XML_insideH },
212  { "insideV", XML_insideV },
213  { "tl2br", XML_tl2br },
214  { "tr2bl", XML_tr2bl },
215  { nullptr, 0 } };
216 
217  if (!rTcBorders.hasElements())
218  return;
219 
220  m_pSerializer->startElementNS(XML_w, nToken);
221  for (const auto& rTcBorder : rTcBorders)
222  if (sal_Int32 nSubToken = DocxStringGetToken(aTcBordersTokens, rTcBorder.Name))
223  tableStyleTcBorder(nSubToken,
224  rTcBorder.Value.get<uno::Sequence<beans::PropertyValue>>());
225  m_pSerializer->endElementNS(XML_w, nToken);
226 }
227 
228 void DocxTableStyleExport::Impl::tableStyleShd(const uno::Sequence<beans::PropertyValue>& rShd)
229 {
230  if (!rShd.hasElements())
231  return;
232 
233  sax_fastparser::FastAttributeList* pAttributeList
235  for (const auto& rProp : rShd)
236  {
237  if (rProp.Name == "val")
238  pAttributeList->add(FSNS(XML_w, XML_val), rProp.Value.get<OUString>().toUtf8());
239  else if (rProp.Name == "color")
240  pAttributeList->add(FSNS(XML_w, XML_color), rProp.Value.get<OUString>().toUtf8());
241  else if (rProp.Name == "fill")
242  pAttributeList->add(FSNS(XML_w, XML_fill), rProp.Value.get<OUString>().toUtf8());
243  else if (rProp.Name == "themeFill")
244  pAttributeList->add(FSNS(XML_w, XML_themeFill), rProp.Value.get<OUString>().toUtf8());
245  else if (rProp.Name == "themeFillShade")
246  pAttributeList->add(FSNS(XML_w, XML_themeFillShade),
247  rProp.Value.get<OUString>().toUtf8());
248  else if (rProp.Name == "themeFillTint")
249  pAttributeList->add(FSNS(XML_w, XML_themeFillTint),
250  rProp.Value.get<OUString>().toUtf8());
251  }
252  sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList);
253  m_pSerializer->singleElementNS(XML_w, XML_shd, xAttributeList);
254 }
255 
256 void DocxTableStyleExport::Impl::tableStyleRColor(const uno::Sequence<beans::PropertyValue>& rColor)
257 {
258  if (!rColor.hasElements())
259  return;
260 
261  sax_fastparser::FastAttributeList* pAttributeList
263  for (const auto& rProp : rColor)
264  {
265  if (rProp.Name == "val")
266  pAttributeList->add(FSNS(XML_w, XML_val), rProp.Value.get<OUString>().toUtf8());
267  else if (rProp.Name == "themeColor")
268  pAttributeList->add(FSNS(XML_w, XML_themeColor), rProp.Value.get<OUString>().toUtf8());
269  else if (rProp.Name == "themeTint")
270  pAttributeList->add(FSNS(XML_w, XML_themeTint), rProp.Value.get<OUString>().toUtf8());
271  else if (rProp.Name == "themeShade")
272  pAttributeList->add(FSNS(XML_w, XML_themeShade), rProp.Value.get<OUString>().toUtf8());
273  }
274  sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList);
275  m_pSerializer->singleElementNS(XML_w, XML_color, xAttributeList);
276 }
277 
278 void DocxTableStyleExport::Impl::tableStyleRLang(const uno::Sequence<beans::PropertyValue>& rLang)
279 {
280  if (!rLang.hasElements())
281  return;
282 
283  sax_fastparser::FastAttributeList* pAttributeList
285  for (const auto& rProp : rLang)
286  {
287  if (rProp.Name == "eastAsia")
288  pAttributeList->add(FSNS(XML_w, XML_eastAsia), rProp.Value.get<OUString>().toUtf8());
289  else if (rProp.Name == "val")
290  pAttributeList->add(FSNS(XML_w, XML_val), rProp.Value.get<OUString>().toUtf8());
291  else if (rProp.Name == "bidi")
292  pAttributeList->add(FSNS(XML_w, XML_bidi), rProp.Value.get<OUString>().toUtf8());
293  }
294  sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList);
295  m_pSerializer->singleElementNS(XML_w, XML_lang, xAttributeList);
296 }
297 
299  const uno::Sequence<beans::PropertyValue>& rRFonts)
300 {
301  if (!rRFonts.hasElements())
302  return;
303 
304  sax_fastparser::FastAttributeList* pAttributeList
306  for (const auto& rRFont : rRFonts)
307  {
308  if (rRFont.Name == "eastAsiaTheme")
309  pAttributeList->add(FSNS(XML_w, XML_eastAsiaTheme),
310  rRFont.Value.get<OUString>().toUtf8());
311  else if (rRFont.Name == "asciiTheme")
312  pAttributeList->add(FSNS(XML_w, XML_asciiTheme), rRFont.Value.get<OUString>().toUtf8());
313  else if (rRFont.Name == "cstheme")
314  pAttributeList->add(FSNS(XML_w, XML_cstheme), rRFont.Value.get<OUString>().toUtf8());
315  else if (rRFont.Name == "hAnsiTheme")
316  pAttributeList->add(FSNS(XML_w, XML_hAnsiTheme), rRFont.Value.get<OUString>().toUtf8());
317  }
318  sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList);
319  m_pSerializer->singleElementNS(XML_w, XML_rFonts, xAttributeList);
320 }
321 
323  const uno::Sequence<beans::PropertyValue>& rSpacing)
324 {
325  if (!rSpacing.hasElements())
326  return;
327 
328  sax_fastparser::FastAttributeList* pAttributeList
330  for (const auto& rProp : rSpacing)
331  {
332  if (rProp.Name == "after")
333  pAttributeList->add(FSNS(XML_w, XML_after), rProp.Value.get<OUString>().toUtf8());
334  else if (rProp.Name == "before")
335  pAttributeList->add(FSNS(XML_w, XML_before), rProp.Value.get<OUString>().toUtf8());
336  else if (rProp.Name == "line")
337  pAttributeList->add(FSNS(XML_w, XML_line), rProp.Value.get<OUString>().toUtf8());
338  else if (rProp.Name == "lineRule")
339  pAttributeList->add(FSNS(XML_w, XML_lineRule), rProp.Value.get<OUString>().toUtf8());
340  else if (rProp.Name == "beforeLines")
341  pAttributeList->add(FSNS(XML_w, XML_beforeLines), rProp.Value.get<OUString>().toUtf8());
342  else if (rProp.Name == "ParaTopMarginBeforeAutoSpacing")
343  // Auto spacing will be available in grab bag only if it was set to true
344  pAttributeList->add(FSNS(XML_w, XML_beforeAutospacing), "1");
345  else if (rProp.Name == "afterLines")
346  pAttributeList->add(FSNS(XML_w, XML_afterLines), rProp.Value.get<OUString>().toUtf8());
347  else if (rProp.Name == "ParaBottomMarginAfterAutoSpacing")
348  // Auto spacing will be available in grab bag only if it was set to true
349  pAttributeList->add(FSNS(XML_w, XML_afterAutospacing), "1");
350  }
351  sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList);
352  m_pSerializer->singleElementNS(XML_w, XML_spacing, xAttributeList);
353 }
354 
355 void DocxTableStyleExport::Impl::tableStylePInd(const uno::Sequence<beans::PropertyValue>& rInd)
356 {
357  if (!rInd.hasElements())
358  return;
359 
360  sax_fastparser::FastAttributeList* pAttributeList
362  for (const auto& rProp : rInd)
363  {
364  if (rProp.Name == "rightChars")
365  pAttributeList->add(FSNS(XML_w, XML_rightChars), rProp.Value.get<OUString>().toUtf8());
366  else if (rProp.Name == "right")
367  pAttributeList->add(FSNS(XML_w, XML_right), rProp.Value.get<OUString>().toUtf8());
368  }
369  sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList);
370  m_pSerializer->singleElementNS(XML_w, XML_ind, xAttributeList);
371 }
372 
374  const uno::Sequence<beans::PropertyValue>& rTableInd)
375 {
376  if (!rTableInd.hasElements())
377  return;
378 
379  sax_fastparser::FastAttributeList* pAttributeList
381  for (const auto& rProp : rTableInd)
382  {
383  if (rProp.Name == "w")
384  pAttributeList->add(FSNS(XML_w, XML_w), OString::number(rProp.Value.get<sal_Int32>()));
385  else if (rProp.Name == "type")
386  pAttributeList->add(FSNS(XML_w, XML_type), rProp.Value.get<OUString>().toUtf8());
387  }
388  sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList);
389  m_pSerializer->singleElementNS(XML_w, XML_tblInd, xAttributeList);
390 }
391 
392 void DocxTableStyleExport::Impl::handleBoolean(const OUString& aValue, sal_Int32 nToken)
393 {
394  if (aValue.isEmpty())
395  return;
396  sax_fastparser::FastAttributeList* pAttributeList
398  if (aValue != "1")
399  pAttributeList->add(FSNS(XML_w, XML_val), aValue.toUtf8());
400  sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList);
401  m_pSerializer->singleElementNS(XML_w, nToken, xAttributeList);
402 }
403 
404 void DocxTableStyleExport::Impl::tableStyleRPr(const uno::Sequence<beans::PropertyValue>& rRPr)
405 {
406  if (!rRPr.hasElements())
407  return;
408 
409  m_pSerializer->startElementNS(XML_w, XML_rPr);
410 
411  uno::Sequence<beans::PropertyValue> aRFonts;
412  uno::Sequence<beans::PropertyValue> aLang;
413  uno::Sequence<beans::PropertyValue> aColor;
414  uno::Sequence<beans::PropertyValue> aSpacingSequence;
415  bool bSequenceFlag = false;
416  OUString aB;
417  OUString aBCs;
418  OUString aI;
419  OUString aSz;
420  OUString aSzCs;
421  OUString aCaps;
422  OUString aSmallCaps;
423  OUString aSpacing;
424  for (const auto& rProp : rRPr)
425  {
426  if (rProp.Name == "rFonts")
427  aRFonts = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
428  else if (rProp.Name == "lang")
429  aLang = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
430  else if (rProp.Name == "b")
431  aB = rProp.Value.get<OUString>();
432  else if (rProp.Name == "bCs")
433  aBCs = rProp.Value.get<OUString>();
434  else if (rProp.Name == "i")
435  aI = rProp.Value.get<OUString>();
436  else if (rProp.Name == "color")
437  aColor = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
438  else if (rProp.Name == "sz")
439  aSz = rProp.Value.get<OUString>();
440  else if (rProp.Name == "szCs")
441  aSzCs = rProp.Value.get<OUString>();
442  else if (rProp.Name == "caps")
443  aCaps = rProp.Value.get<OUString>();
444  else if (rProp.Name == "smallCaps")
445  aSmallCaps = rProp.Value.get<OUString>();
446  else if (rProp.Name == "spacing")
447  {
448  if (rProp.Value.has<OUString>())
449  {
450  aSpacing = rProp.Value.get<OUString>();
451  }
452  else
453  {
454  aSpacingSequence = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
455  bSequenceFlag = true; // set the uno::Sequence flag.
456  }
457  }
458  }
459  tableStyleRRFonts(aRFonts);
460  tableStyleRLang(aLang);
461  handleBoolean(aB, XML_b);
462  handleBoolean(aBCs, XML_bCs);
463  handleBoolean(aI, XML_i);
464  handleBoolean(aCaps, XML_caps);
465  handleBoolean(aSmallCaps, XML_smallCaps);
466  tableStyleRColor(aColor);
467  if (bSequenceFlag)
468  {
469  m_pSerializer->singleElementNS(XML_w, XML_spacing, FSNS(XML_w, XML_val),
470  aSpacingSequence[0].Value.get<OUString>());
471  }
472  if (!aSpacing.isEmpty())
473  m_pSerializer->singleElementNS(XML_w, XML_spacing, FSNS(XML_w, XML_val), aSpacing);
474  if (!aSz.isEmpty())
475  m_pSerializer->singleElementNS(XML_w, XML_sz, FSNS(XML_w, XML_val), aSz);
476  if (!aSzCs.isEmpty())
477  m_pSerializer->singleElementNS(XML_w, XML_szCs, FSNS(XML_w, XML_val), aSzCs);
478 
479  m_pSerializer->endElementNS(XML_w, XML_rPr);
480 }
481 
482 void DocxTableStyleExport::Impl::tableStylePPr(const uno::Sequence<beans::PropertyValue>& rPPr)
483 {
484  if (!rPPr.hasElements())
485  return;
486 
487  m_pSerializer->startElementNS(XML_w, XML_pPr);
488 
489  uno::Sequence<beans::PropertyValue> aSpacing;
490  uno::Sequence<beans::PropertyValue> aInd;
491  bool bWordWrap = false;
492  OUString aJc;
493  OUString aSnapToGrid;
494  for (const auto& rProp : rPPr)
495  {
496  if (rProp.Name == "spacing")
497  aSpacing = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
498  else if (rProp.Name == "ind")
499  aInd = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
500  else if (rProp.Name == "wordWrap")
501  bWordWrap = true;
502  else if (rProp.Name == "jc")
503  aJc = rProp.Value.get<OUString>();
504  else if (rProp.Name == "snapToGrid")
505  aSnapToGrid = rProp.Value.get<OUString>();
506  }
507  if (bWordWrap)
508  m_pSerializer->singleElementNS(XML_w, XML_wordWrap);
509  tableStylePInd(aInd);
510  handleBoolean(aSnapToGrid, XML_snapToGrid);
511  tableStylePSpacing(aSpacing);
512  if (!aJc.isEmpty())
513  m_pSerializer->singleElementNS(XML_w, XML_jc, FSNS(XML_w, XML_val), aJc);
514 
515  m_pSerializer->endElementNS(XML_w, XML_pPr);
516 }
517 
519  const uno::Sequence<beans::PropertyValue>& rTablePr)
520 {
521  if (!rTablePr.hasElements())
522  return;
523 
524  m_pSerializer->startElementNS(XML_w, XML_tblPr);
525 
526  uno::Sequence<beans::PropertyValue> aTableInd;
527  uno::Sequence<beans::PropertyValue> aTableBorders;
528  uno::Sequence<beans::PropertyValue> aTableCellMar;
529  std::optional<sal_Int32> oTableStyleRowBandSize;
530  std::optional<sal_Int32> oTableStyleColBandSize;
531  for (const auto& rProp : rTablePr)
532  {
533  if (rProp.Name == "tblStyleRowBandSize")
534  oTableStyleRowBandSize = rProp.Value.get<sal_Int32>();
535  else if (rProp.Name == "tblStyleColBandSize")
536  oTableStyleColBandSize = rProp.Value.get<sal_Int32>();
537  else if (rProp.Name == "tblInd")
538  aTableInd = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
539  else if (rProp.Name == "tblBorders")
540  aTableBorders = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
541  else if (rProp.Name == "tblCellMar")
542  aTableCellMar = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
543  }
544  if (oTableStyleRowBandSize)
545  m_pSerializer->singleElementNS(XML_w, XML_tblStyleRowBandSize, FSNS(XML_w, XML_val),
546  OString::number(*oTableStyleRowBandSize));
547  if (oTableStyleColBandSize)
548  m_pSerializer->singleElementNS(XML_w, XML_tblStyleColBandSize, FSNS(XML_w, XML_val),
549  OString::number(*oTableStyleColBandSize));
550  tableStyleTableInd(aTableInd);
551  tableStyleTcBorders(aTableBorders, XML_tblBorders);
552  tableStyleTableCellMar(aTableCellMar);
553 
554  m_pSerializer->endElementNS(XML_w, XML_tblPr);
555 }
556 
557 void DocxTableStyleExport::Impl::tableStyleTrPr(const uno::Sequence<beans::PropertyValue>& rTrPr)
558 {
559  if (!rTrPr.hasElements())
560  return;
561 
562  m_pSerializer->startElementNS(XML_w, XML_trPr);
563 
564  for (const auto& rProp : rTrPr)
565  {
566  if (rProp.Name == "tblHeader")
567  m_pSerializer->singleElementNS(XML_w, XML_tblHeader);
568  }
569 
570  m_pSerializer->endElementNS(XML_w, XML_trPr);
571 }
572 
573 void DocxTableStyleExport::Impl::tableStyleTcPr(const uno::Sequence<beans::PropertyValue>& rTcPr)
574 {
575  if (!rTcPr.hasElements())
576  return;
577 
578  m_pSerializer->startElementNS(XML_w, XML_tcPr);
579 
580  uno::Sequence<beans::PropertyValue> aShd;
581  uno::Sequence<beans::PropertyValue> aTcBorders;
582  uno::Sequence<beans::PropertyValue> aTcMar;
583  OUString aVAlign;
584  for (const auto& rProp : rTcPr)
585  {
586  if (rProp.Name == "shd")
587  aShd = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
588  else if (rProp.Name == "tcBorders")
589  aTcBorders = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
590  else if (rProp.Name == "tcMar")
591  aTcMar = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
592  else if (rProp.Name == "vAlign")
593  aVAlign = rProp.Value.get<OUString>();
594  }
595  tableStyleTcBorders(aTcBorders);
596  tableStyleTableCellMar(aTcMar, XML_tcMar);
597  tableStyleShd(aShd);
598  if (!aVAlign.isEmpty())
599  m_pSerializer->singleElementNS(XML_w, XML_vAlign, FSNS(XML_w, XML_val), aVAlign);
600 
601  m_pSerializer->endElementNS(XML_w, XML_tcPr);
602 }
603 
605  const uno::Sequence<beans::PropertyValue>& rTableStylePr)
606 {
607  if (!rTableStylePr.hasElements())
608  return;
609 
610  OUString aType;
611  uno::Sequence<beans::PropertyValue> aPPr;
612  uno::Sequence<beans::PropertyValue> aRPr;
613  uno::Sequence<beans::PropertyValue> aTablePr;
614  uno::Sequence<beans::PropertyValue> aTrPr;
615  uno::Sequence<beans::PropertyValue> aTcPr;
616  for (const auto& rProp : rTableStylePr)
617  {
618  if (rProp.Name == "type")
619  aType = rProp.Value.get<OUString>();
620  else if (rProp.Name == "pPr")
621  aPPr = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
622  else if (rProp.Name == "rPr")
623  aRPr = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
624  else if (rProp.Name == "tblPr")
625  aTablePr = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
626  else if (rProp.Name == "trPr")
627  aTrPr = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
628  else if (rProp.Name == "tcPr")
629  aTcPr = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
630  }
631 
632  m_pSerializer->startElementNS(XML_w, XML_tblStylePr, FSNS(XML_w, XML_type), aType);
633 
634  tableStylePPr(aPPr);
635  tableStyleRPr(aRPr);
636  if (aTablePr.hasElements())
637  tableStyleTablePr(aTablePr);
638  else
639  {
640  // Even if we have an empty container, write it out, as Word does.
641  m_pSerializer->singleElementNS(XML_w, XML_tblPr);
642  }
643  tableStyleTrPr(aTrPr);
644  tableStyleTcPr(aTcPr);
645 
646  m_pSerializer->endElementNS(XML_w, XML_tblStylePr);
647 }
648 
649 void DocxTableStyleExport::Impl::TableStyle(const uno::Sequence<beans::PropertyValue>& rStyle)
650 {
651  bool bDefault = false;
652  bool bCustomStyle = false;
653  bool bQFormat = false;
654  bool bSemiHidden = false;
655  bool bUnhideWhenUsed = false;
656  OUString aStyleId;
657  OUString aName;
658  OUString aBasedOn;
659  OUString aRsid;
660  OUString aUiPriority;
661  uno::Sequence<beans::PropertyValue> aPPr;
662  uno::Sequence<beans::PropertyValue> aRPr;
663  uno::Sequence<beans::PropertyValue> aTablePr;
664  uno::Sequence<beans::PropertyValue> aTcPr;
665  std::vector<uno::Sequence<beans::PropertyValue>> aTableStylePrs;
666  for (const auto& rProp : rStyle)
667  {
668  if (rProp.Name == "default")
669  bDefault = rProp.Value.get<bool>();
670  else if (rProp.Name == "customStyle")
671  bCustomStyle = rProp.Value.get<bool>();
672  else if (rProp.Name == "styleId")
673  aStyleId = rProp.Value.get<OUString>();
674  else if (rProp.Name == "name")
675  aName = rProp.Value.get<OUString>();
676  else if (rProp.Name == "basedOn")
677  aBasedOn = rProp.Value.get<OUString>();
678  else if (rProp.Name == "uiPriority")
679  aUiPriority = rProp.Value.get<OUString>();
680  else if (rProp.Name == "qFormat")
681  bQFormat = true;
682  else if (rProp.Name == "semiHidden")
683  bSemiHidden = true;
684  else if (rProp.Name == "unhideWhenUsed")
685  bUnhideWhenUsed = true;
686  else if (rProp.Name == "rsid")
687  aRsid = rProp.Value.get<OUString>();
688  else if (rProp.Name == "pPr")
689  aPPr = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
690  else if (rProp.Name == "rPr")
691  aRPr = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
692  else if (rProp.Name == "tblPr")
693  aTablePr = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
694  else if (rProp.Name == "tcPr")
695  aTcPr = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
696  else if (rProp.Name == "tblStylePr")
697  aTableStylePrs.push_back(rProp.Value.get<uno::Sequence<beans::PropertyValue>>());
698  }
699 
700  sax_fastparser::FastAttributeList* pAttributeList
702  pAttributeList->add(FSNS(XML_w, XML_type), "table");
703  if (bDefault)
704  pAttributeList->add(FSNS(XML_w, XML_default), "1");
705  if (bCustomStyle)
706  pAttributeList->add(FSNS(XML_w, XML_customStyle), "1");
707  if (!aStyleId.isEmpty())
708  pAttributeList->add(FSNS(XML_w, XML_styleId), aStyleId.toUtf8());
709  sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList);
710  m_pSerializer->startElementNS(XML_w, XML_style, xAttributeList);
711 
712  m_pSerializer->singleElementNS(XML_w, XML_name, FSNS(XML_w, XML_val), aName);
713  if (!aBasedOn.isEmpty())
714  m_pSerializer->singleElementNS(XML_w, XML_basedOn, FSNS(XML_w, XML_val), aBasedOn);
715  if (!aUiPriority.isEmpty())
716  m_pSerializer->singleElementNS(XML_w, XML_uiPriority, FSNS(XML_w, XML_val), aUiPriority);
717  if (bSemiHidden)
718  m_pSerializer->singleElementNS(XML_w, XML_semiHidden);
719  if (bUnhideWhenUsed)
720  m_pSerializer->singleElementNS(XML_w, XML_unhideWhenUsed);
721  if (bQFormat)
722  m_pSerializer->singleElementNS(XML_w, XML_qFormat);
723  if (!aRsid.isEmpty())
724  m_pSerializer->singleElementNS(XML_w, XML_rsid, FSNS(XML_w, XML_val), aRsid);
725 
726  tableStylePPr(aPPr);
727  tableStyleRPr(aRPr);
728  tableStyleTablePr(aTablePr);
729  tableStyleTcPr(aTcPr);
730  for (const uno::Sequence<beans::PropertyValue>& i : std::as_const(aTableStylePrs))
731  tableStyleTableStylePr(i);
732 
733  m_pSerializer->endElementNS(XML_w, XML_style);
734 }
735 
737 {
738  m_pImpl->setSerializer(pSerializer);
739 }
740 
742  const sax_fastparser::FSHelperPtr& pSerializer)
743  : m_pImpl(std::make_unique<Impl>(rDoc))
744 {
745  m_pImpl->setSerializer(pSerializer);
746 }
747 
749 
750 /* 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.
static FastAttributeList * createAttrList()
css::uno::Reference< css::xml::sax::XFastAttributeList > XFastAttributeListRef
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:186
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:1205
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.
int i
void setSerializer(sax_fastparser::FSHelperPtr pSerializer)
sal_Int32 DocxStringGetToken(DocxStringTokenMap const *pMap, const OUString &rName)
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.
void add(const FastAttributeList &)
DefTokenId nToken
OUString aName
const sax_fastparser::FSHelperPtr & getSerializer() const
constexpr sal_Int32 FSNS(sal_Int32 namespc, sal_Int32 element)
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.