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
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
24using namespace com::sun::star;
25using namespace oox;
26
29{
30private:
33
34public:
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
48
49 SwDoc& getDoc() const { return m_rDoc; }
50
52 void handleBoolean(std::u16string_view 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
90void 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>());
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>());
118 }
119 }
120
121 m_pImpl->getSerializer()->singleElementNS(XML_w, XML_cnfStyle, pAttributeList);
122}
123
124void 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 std::cbegin(aInteropGrabBag), std::cend(aInteropGrabBag),
134 [](const beans::PropertyValue& rProp) { return rProp.Name == "tableStyles"; });
135 if (pProp != std::cend(aInteropGrabBag))
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>());
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
226void 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>());
237 else if (rProp.Name == "color")
238 pAttributeList->add(FSNS(XML_w, XML_color), rProp.Value.get<OUString>());
239 else if (rProp.Name == "fill")
240 pAttributeList->add(FSNS(XML_w, XML_fill), rProp.Value.get<OUString>());
241 else if (rProp.Name == "themeFill")
242 pAttributeList->add(FSNS(XML_w, XML_themeFill), rProp.Value.get<OUString>());
243 else if (rProp.Name == "themeFillShade")
244 pAttributeList->add(FSNS(XML_w, XML_themeFillShade), rProp.Value.get<OUString>());
245 else if (rProp.Name == "themeFillTint")
246 pAttributeList->add(FSNS(XML_w, XML_themeFillTint), rProp.Value.get<OUString>());
247 }
248 m_pSerializer->singleElementNS(XML_w, XML_shd, pAttributeList);
249}
250
251void DocxTableStyleExport::Impl::tableStyleRColor(const uno::Sequence<beans::PropertyValue>& rColor)
252{
253 if (!rColor.hasElements())
254 return;
255
258 for (const auto& rProp : rColor)
259 {
260 if (rProp.Name == "val")
261 pAttributeList->add(FSNS(XML_w, XML_val), rProp.Value.get<OUString>());
262 else if (rProp.Name == "themeColor")
263 pAttributeList->add(FSNS(XML_w, XML_themeColor), rProp.Value.get<OUString>());
264 else if (rProp.Name == "themeTint")
265 pAttributeList->add(FSNS(XML_w, XML_themeTint), rProp.Value.get<OUString>());
266 else if (rProp.Name == "themeShade")
267 pAttributeList->add(FSNS(XML_w, XML_themeShade), rProp.Value.get<OUString>());
268 }
269 m_pSerializer->singleElementNS(XML_w, XML_color, pAttributeList);
270}
271
272void DocxTableStyleExport::Impl::tableStyleRLang(const uno::Sequence<beans::PropertyValue>& rLang)
273{
274 if (!rLang.hasElements())
275 return;
276
279 for (const auto& rProp : rLang)
280 {
281 if (rProp.Name == "eastAsia")
282 pAttributeList->add(FSNS(XML_w, XML_eastAsia), rProp.Value.get<OUString>());
283 else if (rProp.Name == "val")
284 pAttributeList->add(FSNS(XML_w, XML_val), rProp.Value.get<OUString>());
285 else if (rProp.Name == "bidi")
286 pAttributeList->add(FSNS(XML_w, XML_bidi), rProp.Value.get<OUString>());
287 }
288 m_pSerializer->singleElementNS(XML_w, XML_lang, pAttributeList);
289}
290
292 const uno::Sequence<beans::PropertyValue>& rRFonts)
293{
294 if (!rRFonts.hasElements())
295 return;
296
299 for (const auto& rRFont : rRFonts)
300 {
301 if (rRFont.Name == "eastAsiaTheme")
302 pAttributeList->add(FSNS(XML_w, XML_eastAsiaTheme), rRFont.Value.get<OUString>());
303 else if (rRFont.Name == "asciiTheme")
304 pAttributeList->add(FSNS(XML_w, XML_asciiTheme), rRFont.Value.get<OUString>());
305 else if (rRFont.Name == "cstheme")
306 pAttributeList->add(FSNS(XML_w, XML_cstheme), rRFont.Value.get<OUString>());
307 else if (rRFont.Name == "hAnsiTheme")
308 pAttributeList->add(FSNS(XML_w, XML_hAnsiTheme), rRFont.Value.get<OUString>());
309 }
310 m_pSerializer->singleElementNS(XML_w, XML_rFonts, pAttributeList);
311}
312
314 const uno::Sequence<beans::PropertyValue>& rSpacing)
315{
316 if (!rSpacing.hasElements())
317 return;
318
321 for (const auto& rProp : rSpacing)
322 {
323 if (rProp.Name == "after")
324 pAttributeList->add(FSNS(XML_w, XML_after), rProp.Value.get<OUString>());
325 else if (rProp.Name == "before")
326 pAttributeList->add(FSNS(XML_w, XML_before), rProp.Value.get<OUString>());
327 else if (rProp.Name == "line")
328 pAttributeList->add(FSNS(XML_w, XML_line), rProp.Value.get<OUString>());
329 else if (rProp.Name == "lineRule")
330 pAttributeList->add(FSNS(XML_w, XML_lineRule), rProp.Value.get<OUString>());
331 else if (rProp.Name == "beforeLines")
332 pAttributeList->add(FSNS(XML_w, XML_beforeLines), rProp.Value.get<OUString>());
333 else if (rProp.Name == "ParaTopMarginBeforeAutoSpacing")
334 // Auto spacing will be available in grab bag only if it was set to true
335 pAttributeList->add(FSNS(XML_w, XML_beforeAutospacing), "1");
336 else if (rProp.Name == "afterLines")
337 pAttributeList->add(FSNS(XML_w, XML_afterLines), rProp.Value.get<OUString>());
338 else if (rProp.Name == "ParaBottomMarginAfterAutoSpacing")
339 // Auto spacing will be available in grab bag only if it was set to true
340 pAttributeList->add(FSNS(XML_w, XML_afterAutospacing), "1");
341 }
342 m_pSerializer->singleElementNS(XML_w, XML_spacing, pAttributeList);
343}
344
345void DocxTableStyleExport::Impl::tableStylePInd(const uno::Sequence<beans::PropertyValue>& rInd)
346{
347 if (!rInd.hasElements())
348 return;
349
352 for (const auto& rProp : rInd)
353 {
354 if (rProp.Name == "rightChars")
355 pAttributeList->add(FSNS(XML_w, XML_rightChars), rProp.Value.get<OUString>());
356 else if (rProp.Name == "right")
357 pAttributeList->add(FSNS(XML_w, XML_right), rProp.Value.get<OUString>());
358 }
359 m_pSerializer->singleElementNS(XML_w, XML_ind, pAttributeList);
360}
361
363 const uno::Sequence<beans::PropertyValue>& rTableInd)
364{
365 if (!rTableInd.hasElements())
366 return;
367
370 for (const auto& rProp : rTableInd)
371 {
372 if (rProp.Name == "w")
373 pAttributeList->add(FSNS(XML_w, XML_w), OString::number(rProp.Value.get<sal_Int32>()));
374 else if (rProp.Name == "type")
375 pAttributeList->add(FSNS(XML_w, XML_type), rProp.Value.get<OUString>());
376 }
377 m_pSerializer->singleElementNS(XML_w, XML_tblInd, pAttributeList);
378}
379
380void DocxTableStyleExport::Impl::handleBoolean(std::u16string_view aValue, sal_Int32 nToken)
381{
382 if (aValue.empty())
383 return;
386 if (aValue != u"1")
387 pAttributeList->add(FSNS(XML_w, XML_val), aValue);
388 m_pSerializer->singleElementNS(XML_w, nToken, pAttributeList);
389}
390
391void DocxTableStyleExport::Impl::tableStyleRPr(const uno::Sequence<beans::PropertyValue>& rRPr)
392{
393 if (!rRPr.hasElements())
394 return;
395
396 m_pSerializer->startElementNS(XML_w, XML_rPr);
397
398 uno::Sequence<beans::PropertyValue> aRFonts;
399 uno::Sequence<beans::PropertyValue> aLang;
400 uno::Sequence<beans::PropertyValue> aColor;
401 uno::Sequence<beans::PropertyValue> aSpacingSequence;
402 bool bSequenceFlag = false;
403 OUString aB;
404 OUString aBCs;
405 OUString aI;
406 OUString aSz;
407 OUString aSzCs;
408 OUString aCaps;
409 OUString aSmallCaps;
410 OUString aSpacing;
411 for (const auto& rProp : rRPr)
412 {
413 if (rProp.Name == "rFonts")
414 aRFonts = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
415 else if (rProp.Name == "lang")
416 aLang = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
417 else if (rProp.Name == "b")
418 aB = rProp.Value.get<OUString>();
419 else if (rProp.Name == "bCs")
420 aBCs = rProp.Value.get<OUString>();
421 else if (rProp.Name == "i")
422 aI = rProp.Value.get<OUString>();
423 else if (rProp.Name == "color")
424 aColor = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
425 else if (rProp.Name == "sz")
426 aSz = rProp.Value.get<OUString>();
427 else if (rProp.Name == "szCs")
428 aSzCs = rProp.Value.get<OUString>();
429 else if (rProp.Name == "caps")
430 aCaps = rProp.Value.get<OUString>();
431 else if (rProp.Name == "smallCaps")
432 aSmallCaps = rProp.Value.get<OUString>();
433 else if (rProp.Name == "spacing")
434 {
435 if (rProp.Value.has<OUString>())
436 {
437 aSpacing = rProp.Value.get<OUString>();
438 }
439 else
440 {
441 aSpacingSequence = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
442 bSequenceFlag = true; // set the uno::Sequence flag.
443 }
444 }
445 }
446 tableStyleRRFonts(aRFonts);
447 tableStyleRLang(aLang);
448 handleBoolean(aB, XML_b);
449 handleBoolean(aBCs, XML_bCs);
450 handleBoolean(aI, XML_i);
451 handleBoolean(aCaps, XML_caps);
452 handleBoolean(aSmallCaps, XML_smallCaps);
453 tableStyleRColor(aColor);
454 if (bSequenceFlag)
455 {
456 m_pSerializer->singleElementNS(XML_w, XML_spacing, FSNS(XML_w, XML_val),
457 aSpacingSequence[0].Value.get<OUString>());
458 }
459 if (!aSpacing.isEmpty())
460 m_pSerializer->singleElementNS(XML_w, XML_spacing, FSNS(XML_w, XML_val), aSpacing);
461 if (!aSz.isEmpty())
462 m_pSerializer->singleElementNS(XML_w, XML_sz, FSNS(XML_w, XML_val), aSz);
463 if (!aSzCs.isEmpty())
464 m_pSerializer->singleElementNS(XML_w, XML_szCs, FSNS(XML_w, XML_val), aSzCs);
465
466 m_pSerializer->endElementNS(XML_w, XML_rPr);
467}
468
469void DocxTableStyleExport::Impl::tableStylePPr(const uno::Sequence<beans::PropertyValue>& rPPr)
470{
471 if (!rPPr.hasElements())
472 return;
473
474 m_pSerializer->startElementNS(XML_w, XML_pPr);
475
476 uno::Sequence<beans::PropertyValue> aSpacing;
477 uno::Sequence<beans::PropertyValue> aInd;
478 bool bWordWrap = false;
479 OUString aJc;
480 OUString aSnapToGrid;
481 for (const auto& rProp : rPPr)
482 {
483 if (rProp.Name == "spacing")
484 aSpacing = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
485 else if (rProp.Name == "ind")
486 aInd = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
487 else if (rProp.Name == "wordWrap")
488 bWordWrap = true;
489 else if (rProp.Name == "jc")
490 aJc = rProp.Value.get<OUString>();
491 else if (rProp.Name == "snapToGrid")
492 aSnapToGrid = rProp.Value.get<OUString>();
493 }
494 if (bWordWrap)
495 m_pSerializer->singleElementNS(XML_w, XML_wordWrap);
496 tableStylePInd(aInd);
497 handleBoolean(aSnapToGrid, XML_snapToGrid);
498 tableStylePSpacing(aSpacing);
499 if (!aJc.isEmpty())
500 m_pSerializer->singleElementNS(XML_w, XML_jc, FSNS(XML_w, XML_val), aJc);
501
502 m_pSerializer->endElementNS(XML_w, XML_pPr);
503}
504
506 const uno::Sequence<beans::PropertyValue>& rTablePr)
507{
508 if (!rTablePr.hasElements())
509 return;
510
511 m_pSerializer->startElementNS(XML_w, XML_tblPr);
512
513 uno::Sequence<beans::PropertyValue> aTableInd;
514 uno::Sequence<beans::PropertyValue> aTableBorders;
515 uno::Sequence<beans::PropertyValue> aTableCellMar;
516 std::optional<sal_Int32> oTableStyleRowBandSize;
517 std::optional<sal_Int32> oTableStyleColBandSize;
518 for (const auto& rProp : rTablePr)
519 {
520 if (rProp.Name == "tblStyleRowBandSize")
521 oTableStyleRowBandSize = rProp.Value.get<sal_Int32>();
522 else if (rProp.Name == "tblStyleColBandSize")
523 oTableStyleColBandSize = rProp.Value.get<sal_Int32>();
524 else if (rProp.Name == "tblInd")
525 aTableInd = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
526 else if (rProp.Name == "tblBorders")
527 aTableBorders = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
528 else if (rProp.Name == "tblCellMar")
529 aTableCellMar = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
530 }
531 if (oTableStyleRowBandSize)
532 m_pSerializer->singleElementNS(XML_w, XML_tblStyleRowBandSize, FSNS(XML_w, XML_val),
533 OString::number(*oTableStyleRowBandSize));
534 if (oTableStyleColBandSize)
535 m_pSerializer->singleElementNS(XML_w, XML_tblStyleColBandSize, FSNS(XML_w, XML_val),
536 OString::number(*oTableStyleColBandSize));
537 tableStyleTableInd(aTableInd);
538 tableStyleTcBorders(aTableBorders, XML_tblBorders);
539 tableStyleTableCellMar(aTableCellMar);
540
541 m_pSerializer->endElementNS(XML_w, XML_tblPr);
542}
543
544void DocxTableStyleExport::Impl::tableStyleTrPr(const uno::Sequence<beans::PropertyValue>& rTrPr)
545{
546 if (!rTrPr.hasElements())
547 return;
548
549 m_pSerializer->startElementNS(XML_w, XML_trPr);
550
551 for (const auto& rProp : rTrPr)
552 {
553 if (rProp.Name == "tblHeader")
554 m_pSerializer->singleElementNS(XML_w, XML_tblHeader);
555 }
556
557 m_pSerializer->endElementNS(XML_w, XML_trPr);
558}
559
560void DocxTableStyleExport::Impl::tableStyleTcPr(const uno::Sequence<beans::PropertyValue>& rTcPr)
561{
562 if (!rTcPr.hasElements())
563 return;
564
565 m_pSerializer->startElementNS(XML_w, XML_tcPr);
566
567 uno::Sequence<beans::PropertyValue> aShd;
568 uno::Sequence<beans::PropertyValue> aTcBorders;
569 uno::Sequence<beans::PropertyValue> aTcMar;
570 OUString aVAlign;
571 for (const auto& rProp : rTcPr)
572 {
573 if (rProp.Name == "shd")
574 aShd = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
575 else if (rProp.Name == "tcBorders")
576 aTcBorders = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
577 else if (rProp.Name == "tcMar")
578 aTcMar = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
579 else if (rProp.Name == "vAlign")
580 aVAlign = rProp.Value.get<OUString>();
581 }
582 tableStyleTcBorders(aTcBorders);
583 tableStyleTableCellMar(aTcMar, XML_tcMar);
584 tableStyleShd(aShd);
585 if (!aVAlign.isEmpty())
586 m_pSerializer->singleElementNS(XML_w, XML_vAlign, FSNS(XML_w, XML_val), aVAlign);
587
588 m_pSerializer->endElementNS(XML_w, XML_tcPr);
589}
590
592 const uno::Sequence<beans::PropertyValue>& rTableStylePr)
593{
594 if (!rTableStylePr.hasElements())
595 return;
596
597 OUString aType;
598 uno::Sequence<beans::PropertyValue> aPPr;
599 uno::Sequence<beans::PropertyValue> aRPr;
600 uno::Sequence<beans::PropertyValue> aTablePr;
601 uno::Sequence<beans::PropertyValue> aTrPr;
602 uno::Sequence<beans::PropertyValue> aTcPr;
603 for (const auto& rProp : rTableStylePr)
604 {
605 if (rProp.Name == "type")
606 aType = rProp.Value.get<OUString>();
607 else if (rProp.Name == "pPr")
608 aPPr = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
609 else if (rProp.Name == "rPr")
610 aRPr = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
611 else if (rProp.Name == "tblPr")
612 aTablePr = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
613 else if (rProp.Name == "trPr")
614 aTrPr = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
615 else if (rProp.Name == "tcPr")
616 aTcPr = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
617 }
618
619 m_pSerializer->startElementNS(XML_w, XML_tblStylePr, FSNS(XML_w, XML_type), aType);
620
621 tableStylePPr(aPPr);
622 tableStyleRPr(aRPr);
623 if (aTablePr.hasElements())
624 tableStyleTablePr(aTablePr);
625 else
626 {
627 // Even if we have an empty container, write it out, as Word does.
628 m_pSerializer->singleElementNS(XML_w, XML_tblPr);
629 }
630 tableStyleTrPr(aTrPr);
631 tableStyleTcPr(aTcPr);
632
633 m_pSerializer->endElementNS(XML_w, XML_tblStylePr);
634}
635
636void DocxTableStyleExport::Impl::TableStyle(const uno::Sequence<beans::PropertyValue>& rStyle)
637{
638 bool bDefault = false;
639 bool bCustomStyle = false;
640 bool bQFormat = false;
641 bool bSemiHidden = false;
642 bool bUnhideWhenUsed = false;
643 OUString aStyleId;
644 OUString aName;
645 OUString aBasedOn;
646 OUString aRsid;
647 OUString aUiPriority;
648 uno::Sequence<beans::PropertyValue> aPPr;
649 uno::Sequence<beans::PropertyValue> aRPr;
650 uno::Sequence<beans::PropertyValue> aTablePr;
651 uno::Sequence<beans::PropertyValue> aTcPr;
652 std::vector<uno::Sequence<beans::PropertyValue>> aTableStylePrs;
653 for (const auto& rProp : rStyle)
654 {
655 if (rProp.Name == "default")
656 bDefault = rProp.Value.get<bool>();
657 else if (rProp.Name == "customStyle")
658 bCustomStyle = rProp.Value.get<bool>();
659 else if (rProp.Name == "styleId")
660 aStyleId = rProp.Value.get<OUString>();
661 else if (rProp.Name == "name")
662 aName = rProp.Value.get<OUString>();
663 else if (rProp.Name == "basedOn")
664 aBasedOn = rProp.Value.get<OUString>();
665 else if (rProp.Name == "uiPriority")
666 aUiPriority = rProp.Value.get<OUString>();
667 else if (rProp.Name == "qFormat")
668 bQFormat = true;
669 else if (rProp.Name == "semiHidden")
670 bSemiHidden = true;
671 else if (rProp.Name == "unhideWhenUsed")
672 bUnhideWhenUsed = true;
673 else if (rProp.Name == "rsid")
674 aRsid = rProp.Value.get<OUString>();
675 else if (rProp.Name == "pPr")
676 aPPr = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
677 else if (rProp.Name == "rPr")
678 aRPr = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
679 else if (rProp.Name == "tblPr")
680 aTablePr = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
681 else if (rProp.Name == "tcPr")
682 aTcPr = rProp.Value.get<uno::Sequence<beans::PropertyValue>>();
683 else if (rProp.Name == "tblStylePr")
684 aTableStylePrs.push_back(rProp.Value.get<uno::Sequence<beans::PropertyValue>>());
685 }
686
689 pAttributeList->add(FSNS(XML_w, XML_type), "table");
690 if (bDefault)
691 pAttributeList->add(FSNS(XML_w, XML_default), "1");
692 if (bCustomStyle)
693 pAttributeList->add(FSNS(XML_w, XML_customStyle), "1");
694 if (!aStyleId.isEmpty())
695 pAttributeList->add(FSNS(XML_w, XML_styleId), aStyleId);
696 m_pSerializer->startElementNS(XML_w, XML_style, pAttributeList);
697
698 m_pSerializer->singleElementNS(XML_w, XML_name, FSNS(XML_w, XML_val), aName);
699 if (!aBasedOn.isEmpty())
700 m_pSerializer->singleElementNS(XML_w, XML_basedOn, FSNS(XML_w, XML_val), aBasedOn);
701 if (!aUiPriority.isEmpty())
702 m_pSerializer->singleElementNS(XML_w, XML_uiPriority, FSNS(XML_w, XML_val), aUiPriority);
703 if (bSemiHidden)
704 m_pSerializer->singleElementNS(XML_w, XML_semiHidden);
705 if (bUnhideWhenUsed)
706 m_pSerializer->singleElementNS(XML_w, XML_unhideWhenUsed);
707 if (bQFormat)
708 m_pSerializer->singleElementNS(XML_w, XML_qFormat);
709 if (!aRsid.isEmpty())
710 m_pSerializer->singleElementNS(XML_w, XML_rsid, FSNS(XML_w, XML_val), aRsid);
711
712 tableStylePPr(aPPr);
713 tableStyleRPr(aRPr);
714 tableStyleTablePr(aTablePr);
715 tableStyleTcPr(aTcPr);
716 for (const uno::Sequence<beans::PropertyValue>& i : std::as_const(aTableStylePrs))
717 tableStyleTableStylePr(i);
718
719 m_pSerializer->endElementNS(XML_w, XML_style);
720}
721
723{
724 m_pImpl->setSerializer(pSerializer);
725}
726
728 const sax_fastparser::FSHelperPtr& pSerializer)
729 : m_pImpl(std::make_unique<Impl>(rDoc))
730{
731 m_pImpl->setSerializer(pSerializer);
732}
733
735
736/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void CnfStyle(const css::uno::Sequence< css::beans::PropertyValue > &rAttributeList)
Writes <w:cnfStyle .../> based on grab-bagged para, cell or row properties.
DocxTableStyleExport(SwDoc &rDoc, const sax_fastparser::FSHelperPtr &pSerializer)
void TableStyles(sal_Int32 nCountStylesToWrite)
std::unique_ptr< Impl > m_pImpl
void SetSerializer(const sax_fastparser::FSHelperPtr &pSerializer)
Definition: doc.hxx:197
static rtl::Reference< FastAttributeList > createAttrList()
sal_Int32 DocxStringGetToken(DocxStringTokenMap const *pMap, std::u16string_view rName)
float u
constexpr sal_Int32 FSNS(sal_Int32 namespc, sal_Int32 element)
OUString aName
Value
int i
std::shared_ptr< FastSerializerHelper > FSHelperPtr
XML_type
HashMap_OWString_Interface aMap
DefTokenId nToken
QPRO_FUNC_TYPE nType
Methods in this class handle values in a table style.
void tableStyleRLang(const uno::Sequence< beans::PropertyValue > &rLang)
Export of w:lang.
void tableStylePPr(const uno::Sequence< beans::PropertyValue > &rPPr)
Export of w:pPr.
void tableStyleTableInd(const uno::Sequence< beans::PropertyValue > &rTableInd)
Export of w:tblInd.
void tableStyleShd(const uno::Sequence< beans::PropertyValue > &rShd)
Export of w:shd.
sax_fastparser::FSHelperPtr m_pSerializer
void tableStyleRPr(const uno::Sequence< beans::PropertyValue > &rRPr)
Export of w:rPr.
void tableStyleTcPr(const uno::Sequence< beans::PropertyValue > &rTcPr)
Export of w:tcPr.
void tableStyleTcBorders(const uno::Sequence< beans::PropertyValue > &rTcBorders, sal_Int32 nToken=XML_tcBorders)
Export of w:tcBorders (and w:tblBorders).
void tableStyleTablePr(const uno::Sequence< beans::PropertyValue > &rTablePr)
Export of w:tblPr.
void tableStyleRColor(const uno::Sequence< beans::PropertyValue > &rColor)
Export of w:color.
void tableStyleTrPr(const uno::Sequence< beans::PropertyValue > &rTrPr)
Export of w:trPr.
void TableStyle(const uno::Sequence< beans::PropertyValue > &rStyle)
void setSerializer(sax_fastparser::FSHelperPtr pSerializer)
void handleBoolean(std::u16string_view aValue, sal_Int32 nToken)
Handles a boolean value.
void tableStyleTcBorder(sal_Int32 nToken, const uno::Sequence< beans::PropertyValue > &rTcBorder)
Export of a given table cell border type.
void tableStyleTableStylePr(const uno::Sequence< beans::PropertyValue > &rTableStylePr)
Export of w:tblStylePr.
const sax_fastparser::FSHelperPtr & getSerializer() const
void tableStyleTableCellMar(const uno::Sequence< beans::PropertyValue > &rTableCellMar, sal_Int32 nType=XML_tblCellMar)
Export of w:tblCellMar (and w:tcMar).
void tableStylePSpacing(const uno::Sequence< beans::PropertyValue > &rSpacing)
Export of w:spacing.
void tableStylePInd(const uno::Sequence< beans::PropertyValue > &rInd)
Export of w:ind in a pPr.
void tableStyleRRFonts(const uno::Sequence< beans::PropertyValue > &rRFonts)
Export of w:rFonts.