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