LibreOffice Module writerperfect (master) 1
txtstyli.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 "txtstyli.hxx"
11
12#include "xmlfmt.hxx"
13
14using namespace com::sun::star;
15
16namespace writerperfect::exp
17{
18namespace
19{
21class XMLParagraphPropertiesContext : public XMLImportContext
22{
23public:
24 XMLParagraphPropertiesContext(XMLImport& rImport, XMLStyleContext& rStyle);
25
26 void SAL_CALL
27 startElement(const OUString& rName,
28 const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
29
30private:
31 XMLStyleContext& mrStyle;
32};
33}
34
35XMLParagraphPropertiesContext::XMLParagraphPropertiesContext(XMLImport& rImport,
36 XMLStyleContext& rStyle)
37 : XMLImportContext(rImport)
38 , mrStyle(rStyle)
39{
40}
41
42void XMLParagraphPropertiesContext::startElement(
43 const OUString& /*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs)
44{
45 for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
46 {
47 OString sName = OUStringToOString(xAttribs->getNameByIndex(i), RTL_TEXTENCODING_UTF8);
48 OString sValue = OUStringToOString(xAttribs->getValueByIndex(i), RTL_TEXTENCODING_UTF8);
49 mrStyle.GetParagraphPropertyList().insert(sName.getStr(), sValue.getStr());
50 }
51}
52
53namespace
54{
56class XMLTextPropertiesContext : public XMLImportContext
57{
58public:
59 XMLTextPropertiesContext(XMLImport& rImport, XMLStyleContext& rStyle);
60
61 void SAL_CALL
62 startElement(const OUString& rName,
63 const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
64
65private:
66 XMLStyleContext& mrStyle;
67};
68}
69
70XMLTextPropertiesContext::XMLTextPropertiesContext(XMLImport& rImport, XMLStyleContext& rStyle)
71 : XMLImportContext(rImport)
72 , mrStyle(rStyle)
73{
74}
75
76void XMLTextPropertiesContext::startElement(
77 const OUString& /*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs)
78{
79 for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
80 {
81 OString sName = OUStringToOString(xAttribs->getNameByIndex(i), RTL_TEXTENCODING_UTF8);
82 OString sValue = OUStringToOString(xAttribs->getValueByIndex(i), RTL_TEXTENCODING_UTF8);
83 mrStyle.GetTextPropertyList().insert(sName.getStr(), sValue.getStr());
84 }
85}
86
87namespace
88{
90class XMLGraphicPropertiesContext : public XMLImportContext
91{
92public:
93 XMLGraphicPropertiesContext(XMLImport& rImport, XMLStyleContext& rStyle);
94
95 void SAL_CALL
96 startElement(const OUString& rName,
97 const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
98
99private:
100 XMLStyleContext& mrStyle;
101};
102}
103
104XMLGraphicPropertiesContext::XMLGraphicPropertiesContext(XMLImport& rImport,
105 XMLStyleContext& rStyle)
106 : XMLImportContext(rImport)
107 , mrStyle(rStyle)
108{
109}
110
111void XMLGraphicPropertiesContext::startElement(
112 const OUString& /*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs)
113{
114 for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
115 {
116 OString sName = OUStringToOString(xAttribs->getNameByIndex(i), RTL_TEXTENCODING_UTF8);
117 OString sValue = OUStringToOString(xAttribs->getValueByIndex(i), RTL_TEXTENCODING_UTF8);
118 mrStyle.GetGraphicPropertyList().insert(sName.getStr(), sValue.getStr());
119 }
120}
121
122namespace
123{
125class XMLPageLayoutPropertiesContext : public XMLImportContext
126{
127public:
128 XMLPageLayoutPropertiesContext(XMLImport& rImport, XMLStyleContext& rStyle);
129
130 void SAL_CALL
131 startElement(const OUString& rName,
132 const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
133
134private:
135 XMLStyleContext& mrStyle;
136};
137}
138
139XMLPageLayoutPropertiesContext::XMLPageLayoutPropertiesContext(XMLImport& rImport,
140 XMLStyleContext& rStyle)
141 : XMLImportContext(rImport)
142 , mrStyle(rStyle)
143{
144}
145
146void XMLPageLayoutPropertiesContext::startElement(
147 const OUString& /*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs)
148{
149 for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
150 {
151 OString sName = OUStringToOString(xAttribs->getNameByIndex(i), RTL_TEXTENCODING_UTF8);
152 OString sValue = OUStringToOString(xAttribs->getValueByIndex(i), RTL_TEXTENCODING_UTF8);
153 // We only care about writing-mode for now.
154 if (sName != "style:writing-mode")
155 continue;
156
157 mrStyle.GetPageLayoutPropertyList().insert(sName.getStr(), sValue.getStr());
158 }
159}
160
161namespace
162{
164class XMLTablePropertiesContext : public XMLImportContext
165{
166public:
167 XMLTablePropertiesContext(XMLImport& rImport, XMLStyleContext& rStyle);
168
169 void SAL_CALL
170 startElement(const OUString& rName,
171 const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
172
173private:
174 XMLStyleContext& mrStyle;
175};
176}
177
178XMLTablePropertiesContext::XMLTablePropertiesContext(XMLImport& rImport, XMLStyleContext& rStyle)
179 : XMLImportContext(rImport)
180 , mrStyle(rStyle)
181{
182}
183
184void XMLTablePropertiesContext::startElement(
185 const OUString& /*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs)
186{
187 for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
188 {
189 OString sName = OUStringToOString(xAttribs->getNameByIndex(i), RTL_TEXTENCODING_UTF8);
190 OString sValue = OUStringToOString(xAttribs->getValueByIndex(i), RTL_TEXTENCODING_UTF8);
191 if (sName == "style:rel-width")
192 // Make sure this is passed through as a string, and not parsed as a double.
193 mrStyle.GetTablePropertyList().insert(
194 sName.getStr(), librevenge::RVNGPropertyFactory::newStringProp(sValue.getStr()));
195 else
196 mrStyle.GetTablePropertyList().insert(sName.getStr(), sValue.getStr());
197 }
198}
199
200namespace
201{
203class XMLTableRowPropertiesContext : public XMLImportContext
204{
205public:
206 XMLTableRowPropertiesContext(XMLImport& rImport, XMLStyleContext& rStyle);
207
208 void SAL_CALL
209 startElement(const OUString& rName,
210 const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
211
212private:
213 XMLStyleContext& mrStyle;
214};
215}
216
217XMLTableRowPropertiesContext::XMLTableRowPropertiesContext(XMLImport& rImport,
218 XMLStyleContext& rStyle)
219 : XMLImportContext(rImport)
220 , mrStyle(rStyle)
221{
222}
223
224void XMLTableRowPropertiesContext::startElement(
225 const OUString& /*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs)
226{
227 for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
228 {
229 OString sName = OUStringToOString(xAttribs->getNameByIndex(i), RTL_TEXTENCODING_UTF8);
230 OString sValue = OUStringToOString(xAttribs->getValueByIndex(i), RTL_TEXTENCODING_UTF8);
231 mrStyle.GetRowPropertyList().insert(sName.getStr(), sValue.getStr());
232 }
233}
234
235namespace
236{
238class XMLTableColumnPropertiesContext : public XMLImportContext
239{
240public:
241 XMLTableColumnPropertiesContext(XMLImport& rImport, XMLStyleContext& rStyle);
242
243 void SAL_CALL
244 startElement(const OUString& rName,
245 const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
246
247private:
248 XMLStyleContext& mrStyle;
249};
250}
251
252XMLTableColumnPropertiesContext::XMLTableColumnPropertiesContext(XMLImport& rImport,
253 XMLStyleContext& rStyle)
254 : XMLImportContext(rImport)
255 , mrStyle(rStyle)
256{
257}
258
259void XMLTableColumnPropertiesContext::startElement(
260 const OUString& /*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs)
261{
262 for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
263 {
264 OString sName = OUStringToOString(xAttribs->getNameByIndex(i), RTL_TEXTENCODING_UTF8);
265 OString sValue = OUStringToOString(xAttribs->getValueByIndex(i), RTL_TEXTENCODING_UTF8);
266 mrStyle.GetColumnPropertyList().insert(sName.getStr(), sValue.getStr());
267 }
268}
269
270namespace
271{
273class XMLTableCellPropertiesContext : public XMLImportContext
274{
275public:
276 XMLTableCellPropertiesContext(XMLImport& rImport, XMLStyleContext& rStyle);
277
278 void SAL_CALL
279 startElement(const OUString& rName,
280 const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
281
282private:
283 XMLStyleContext& mrStyle;
284};
285}
286
287XMLTableCellPropertiesContext::XMLTableCellPropertiesContext(XMLImport& rImport,
288 XMLStyleContext& rStyle)
289 : XMLImportContext(rImport)
290 , mrStyle(rStyle)
291{
292}
293
294void XMLTableCellPropertiesContext::startElement(
295 const OUString& /*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs)
296{
297 for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
298 {
299 OString sName = OUStringToOString(xAttribs->getNameByIndex(i), RTL_TEXTENCODING_UTF8);
300 OString sValue = OUStringToOString(xAttribs->getValueByIndex(i), RTL_TEXTENCODING_UTF8);
301 mrStyle.GetCellPropertyList().insert(sName.getStr(), sValue.getStr());
302 }
303}
304
305XMLStyleContext::XMLStyleContext(XMLImport& rImport, XMLStylesContext& rStyles)
306 : XMLImportContext(rImport)
307 , m_rStyles(rStyles)
308{
309}
310
312 const OUString& rName, const css::uno::Reference<css::xml::sax::XAttributeList>& /*xAttribs*/)
313{
314 if (rName == "style:paragraph-properties")
315 return new XMLParagraphPropertiesContext(GetImport(), *this);
316 if (rName == "style:text-properties")
317 return new XMLTextPropertiesContext(GetImport(), *this);
318 if (rName == "style:table-cell-properties")
319 return new XMLTableCellPropertiesContext(GetImport(), *this);
320 if (rName == "style:table-column-properties")
321 return new XMLTableColumnPropertiesContext(GetImport(), *this);
322 if (rName == "style:table-row-properties")
323 return new XMLTableRowPropertiesContext(GetImport(), *this);
324 if (rName == "style:table-properties")
325 return new XMLTablePropertiesContext(GetImport(), *this);
326 if (rName == "style:graphic-properties")
327 return new XMLGraphicPropertiesContext(GetImport(), *this);
328 if (rName == "style:page-layout-properties")
329 return new XMLPageLayoutPropertiesContext(GetImport(), *this);
330 return nullptr;
331}
332
334 const OUString& /*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs)
335{
336 for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
337 {
338 const OUString& rAttributeName = xAttribs->getNameByIndex(i);
339 const OUString& rAttributeValue = xAttribs->getValueByIndex(i);
340 if (rAttributeName == "style:name")
341 m_aName = rAttributeValue;
342 else if (rAttributeName == "style:family")
343 m_aFamily = rAttributeValue;
344
345 // Remember properties of the style itself, e.g. parent name.
346 OString sName = OUStringToOString(rAttributeName, RTL_TEXTENCODING_UTF8);
347 OString sValue = OUStringToOString(rAttributeValue, RTL_TEXTENCODING_UTF8);
348 m_aTextPropertyList.insert(sName.getStr(), sValue.getStr());
349 m_aParagraphPropertyList.insert(sName.getStr(), sValue.getStr());
350 m_aGraphicPropertyList.insert(sName.getStr(), sValue.getStr());
351 m_aPageLayoutPropertyList.insert(sName.getStr(), sValue.getStr());
352 m_aMasterPagePropertyList.insert(sName.getStr(), sValue.getStr());
353 m_aTablePropertyList.insert(sName.getStr(), sValue.getStr());
354 }
355}
356
357void XMLStyleContext::endElement(const OUString& rName)
358{
359 if (m_aName.isEmpty())
360 return;
361
362 if (m_aFamily == "text" || m_aFamily == "paragraph")
364 if (m_aFamily == "paragraph")
366 else if (m_aFamily == "table-cell")
368 else if (m_aFamily == "table-column")
370 else if (m_aFamily == "table-row")
372 else if (m_aFamily == "table")
374 else if (m_aFamily == "graphic")
376 else if (rName == "style:page-layout")
378 else if (rName == "style:master-page")
380}
381
382librevenge::RVNGPropertyList& XMLStyleContext::GetTextPropertyList() { return m_aTextPropertyList; }
383
384librevenge::RVNGPropertyList& XMLStyleContext::GetParagraphPropertyList()
385{
387}
388
389librevenge::RVNGPropertyList& XMLStyleContext::GetCellPropertyList() { return m_aCellPropertyList; }
390
391librevenge::RVNGPropertyList& XMLStyleContext::GetColumnPropertyList()
392{
394}
395
396librevenge::RVNGPropertyList& XMLStyleContext::GetRowPropertyList() { return m_aRowPropertyList; }
397
398librevenge::RVNGPropertyList& XMLStyleContext::GetTablePropertyList()
399{
401}
402
403librevenge::RVNGPropertyList& XMLStyleContext::GetGraphicPropertyList()
404{
406}
407
408librevenge::RVNGPropertyList& XMLStyleContext::GetPageLayoutPropertyList()
409{
411}
412
413} // namespace writerperfect::exp
414
415/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Base class for a handler of a single XML element during ODF -> librevenge conversion.
Definition: xmlictxt.hxx:23
ODT export feeds this class to make librevenge calls.
Definition: xmlimp.hxx:69
librevenge::RVNGPropertyList & GetGraphicPropertyList()
Definition: txtstyli.cxx:403
librevenge::RVNGPropertyList m_aCellPropertyList
Definition: txtstyli.hxx:48
librevenge::RVNGPropertyList & GetPageLayoutPropertyList()
Definition: txtstyli.cxx:408
librevenge::RVNGPropertyList & GetRowPropertyList()
Definition: txtstyli.cxx:396
librevenge::RVNGPropertyList m_aTablePropertyList
Definition: txtstyli.hxx:51
librevenge::RVNGPropertyList & GetTablePropertyList()
Definition: txtstyli.cxx:398
librevenge::RVNGPropertyList m_aColumnPropertyList
Definition: txtstyli.hxx:49
librevenge::RVNGPropertyList m_aMasterPagePropertyList
Definition: txtstyli.hxx:54
librevenge::RVNGPropertyList m_aGraphicPropertyList
Definition: txtstyli.hxx:52
librevenge::RVNGPropertyList & GetColumnPropertyList()
Definition: txtstyli.cxx:391
void SAL_CALL startElement(const OUString &rName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttribs) override
Definition: txtstyli.cxx:333
librevenge::RVNGPropertyList m_aTextPropertyList
Definition: txtstyli.hxx:46
void SAL_CALL endElement(const OUString &rName) override
Definition: txtstyli.cxx:357
librevenge::RVNGPropertyList & GetTextPropertyList()
Definition: txtstyli.cxx:382
librevenge::RVNGPropertyList m_aParagraphPropertyList
Definition: txtstyli.hxx:47
librevenge::RVNGPropertyList & GetParagraphPropertyList()
Definition: txtstyli.cxx:384
rtl::Reference< XMLImportContext > CreateChildContext(const OUString &rName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttribs) override
Definition: txtstyli.cxx:311
librevenge::RVNGPropertyList m_aRowPropertyList
Definition: txtstyli.hxx:50
librevenge::RVNGPropertyList & GetCellPropertyList()
Definition: txtstyli.cxx:389
librevenge::RVNGPropertyList m_aPageLayoutPropertyList
Definition: txtstyli.hxx:53
Handler for <office:automatic-styles>/<office:styles>.
Definition: xmlfmt.hxx:25
std::map< OUString, librevenge::RVNGPropertyList > & GetCurrentPageLayouts()
Definition: xmlfmt.cxx:86
std::map< OUString, librevenge::RVNGPropertyList > & GetCurrentColumnStyles()
Definition: xmlfmt.cxx:66
std::map< OUString, librevenge::RVNGPropertyList > & GetCurrentRowStyles()
Definition: xmlfmt.cxx:71
std::map< OUString, librevenge::RVNGPropertyList > & GetCurrentMasterStyles()
Definition: xmlfmt.cxx:91
std::map< OUString, librevenge::RVNGPropertyList > & GetCurrentTableStyles()
Definition: xmlfmt.cxx:76
std::map< OUString, librevenge::RVNGPropertyList > & GetCurrentGraphicStyles()
Definition: xmlfmt.cxx:81
std::map< OUString, librevenge::RVNGPropertyList > & GetCurrentCellStyles()
Definition: xmlfmt.cxx:61
std::map< OUString, librevenge::RVNGPropertyList > & GetCurrentParagraphStyles()
Definition: xmlfmt.cxx:51
std::map< OUString, librevenge::RVNGPropertyList > & GetCurrentTextStyles()
Definition: xmlfmt.cxx:56
OUString sName
int i
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
XMLStyleContext & mrStyle
Definition: txtstyli.cxx:31