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