1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
10 #include "txtstyli.hxx"
14 using namespace com::sun::star
;
16 namespace writerperfect::exp
20 /// Handler for <style:paragraph-properties>.
21 class XMLParagraphPropertiesContext
: public XMLImportContext
24 XMLParagraphPropertiesContext(XMLImport
& rImport
, XMLStyleContext
& rStyle
);
27 startElement(const OUString
& rName
,
28 const css::uno::Reference
<css::xml::sax::XAttributeList
>& xAttribs
) override
;
31 XMLStyleContext
& mrStyle
;
35 XMLParagraphPropertiesContext::XMLParagraphPropertiesContext(XMLImport
& rImport
,
36 XMLStyleContext
& rStyle
)
37 : XMLImportContext(rImport
)
42 void XMLParagraphPropertiesContext::startElement(
43 const OUString
& /*rName*/, const css::uno::Reference
<css::xml::sax::XAttributeList
>& xAttribs
)
45 for (sal_Int16 i
= 0; i
< xAttribs
->getLength(); ++i
)
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());
55 /// Handler for <style:text-properties>.
56 class XMLTextPropertiesContext
: public XMLImportContext
59 XMLTextPropertiesContext(XMLImport
& rImport
, XMLStyleContext
& rStyle
);
62 startElement(const OUString
& rName
,
63 const css::uno::Reference
<css::xml::sax::XAttributeList
>& xAttribs
) override
;
66 XMLStyleContext
& mrStyle
;
70 XMLTextPropertiesContext::XMLTextPropertiesContext(XMLImport
& rImport
, XMLStyleContext
& rStyle
)
71 : XMLImportContext(rImport
)
76 void XMLTextPropertiesContext::startElement(
77 const OUString
& /*rName*/, const css::uno::Reference
<css::xml::sax::XAttributeList
>& xAttribs
)
79 for (sal_Int16 i
= 0; i
< xAttribs
->getLength(); ++i
)
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());
89 /// Handler for <style:graphic-properties>.
90 class XMLGraphicPropertiesContext
: public XMLImportContext
93 XMLGraphicPropertiesContext(XMLImport
& rImport
, XMLStyleContext
& rStyle
);
96 startElement(const OUString
& rName
,
97 const css::uno::Reference
<css::xml::sax::XAttributeList
>& xAttribs
) override
;
100 XMLStyleContext
& mrStyle
;
104 XMLGraphicPropertiesContext::XMLGraphicPropertiesContext(XMLImport
& rImport
,
105 XMLStyleContext
& rStyle
)
106 : XMLImportContext(rImport
)
111 void XMLGraphicPropertiesContext::startElement(
112 const OUString
& /*rName*/, const css::uno::Reference
<css::xml::sax::XAttributeList
>& xAttribs
)
114 for (sal_Int16 i
= 0; i
< xAttribs
->getLength(); ++i
)
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());
124 /// Handler for <style:page-layout-properties>.
125 class XMLPageLayoutPropertiesContext
: public XMLImportContext
128 XMLPageLayoutPropertiesContext(XMLImport
& rImport
, XMLStyleContext
& rStyle
);
131 startElement(const OUString
& rName
,
132 const css::uno::Reference
<css::xml::sax::XAttributeList
>& xAttribs
) override
;
135 XMLStyleContext
& mrStyle
;
139 XMLPageLayoutPropertiesContext::XMLPageLayoutPropertiesContext(XMLImport
& rImport
,
140 XMLStyleContext
& rStyle
)
141 : XMLImportContext(rImport
)
146 void XMLPageLayoutPropertiesContext::startElement(
147 const OUString
& /*rName*/, const css::uno::Reference
<css::xml::sax::XAttributeList
>& xAttribs
)
149 for (sal_Int16 i
= 0; i
< xAttribs
->getLength(); ++i
)
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")
157 mrStyle
.GetPageLayoutPropertyList().insert(sName
.getStr(), sValue
.getStr());
163 /// Handler for <style:table-properties>.
164 class XMLTablePropertiesContext
: public XMLImportContext
167 XMLTablePropertiesContext(XMLImport
& rImport
, XMLStyleContext
& rStyle
);
170 startElement(const OUString
& rName
,
171 const css::uno::Reference
<css::xml::sax::XAttributeList
>& xAttribs
) override
;
174 XMLStyleContext
& mrStyle
;
178 XMLTablePropertiesContext::XMLTablePropertiesContext(XMLImport
& rImport
, XMLStyleContext
& rStyle
)
179 : XMLImportContext(rImport
)
184 void XMLTablePropertiesContext::startElement(
185 const OUString
& /*rName*/, const css::uno::Reference
<css::xml::sax::XAttributeList
>& xAttribs
)
187 for (sal_Int16 i
= 0; i
< xAttribs
->getLength(); ++i
)
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()));
196 mrStyle
.GetTablePropertyList().insert(sName
.getStr(), sValue
.getStr());
202 /// Handler for <style:table-row-properties>.
203 class XMLTableRowPropertiesContext
: public XMLImportContext
206 XMLTableRowPropertiesContext(XMLImport
& rImport
, XMLStyleContext
& rStyle
);
209 startElement(const OUString
& rName
,
210 const css::uno::Reference
<css::xml::sax::XAttributeList
>& xAttribs
) override
;
213 XMLStyleContext
& mrStyle
;
217 XMLTableRowPropertiesContext::XMLTableRowPropertiesContext(XMLImport
& rImport
,
218 XMLStyleContext
& rStyle
)
219 : XMLImportContext(rImport
)
224 void XMLTableRowPropertiesContext::startElement(
225 const OUString
& /*rName*/, const css::uno::Reference
<css::xml::sax::XAttributeList
>& xAttribs
)
227 for (sal_Int16 i
= 0; i
< xAttribs
->getLength(); ++i
)
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());
237 /// Handler for <style:table-column-properties>.
238 class XMLTableColumnPropertiesContext
: public XMLImportContext
241 XMLTableColumnPropertiesContext(XMLImport
& rImport
, XMLStyleContext
& rStyle
);
244 startElement(const OUString
& rName
,
245 const css::uno::Reference
<css::xml::sax::XAttributeList
>& xAttribs
) override
;
248 XMLStyleContext
& mrStyle
;
252 XMLTableColumnPropertiesContext::XMLTableColumnPropertiesContext(XMLImport
& rImport
,
253 XMLStyleContext
& rStyle
)
254 : XMLImportContext(rImport
)
259 void XMLTableColumnPropertiesContext::startElement(
260 const OUString
& /*rName*/, const css::uno::Reference
<css::xml::sax::XAttributeList
>& xAttribs
)
262 for (sal_Int16 i
= 0; i
< xAttribs
->getLength(); ++i
)
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());
272 /// Handler for <style:table-cell-properties>.
273 class XMLTableCellPropertiesContext
: public XMLImportContext
276 XMLTableCellPropertiesContext(XMLImport
& rImport
, XMLStyleContext
& rStyle
);
279 startElement(const OUString
& rName
,
280 const css::uno::Reference
<css::xml::sax::XAttributeList
>& xAttribs
) override
;
283 XMLStyleContext
& mrStyle
;
287 XMLTableCellPropertiesContext::XMLTableCellPropertiesContext(XMLImport
& rImport
,
288 XMLStyleContext
& rStyle
)
289 : XMLImportContext(rImport
)
294 void XMLTableCellPropertiesContext::startElement(
295 const OUString
& /*rName*/, const css::uno::Reference
<css::xml::sax::XAttributeList
>& xAttribs
)
297 for (sal_Int16 i
= 0; i
< xAttribs
->getLength(); ++i
)
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());
305 XMLStyleContext::XMLStyleContext(XMLImport
& rImport
, XMLStylesContext
& rStyles
)
306 : XMLImportContext(rImport
)
311 rtl::Reference
<XMLImportContext
> XMLStyleContext::CreateChildContext(
312 const OUString
& rName
, const css::uno::Reference
<css::xml::sax::XAttributeList
>& /*xAttribs*/)
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);
333 void XMLStyleContext::startElement(
334 const OUString
& /*rName*/, const css::uno::Reference
<css::xml::sax::XAttributeList
>& xAttribs
)
336 for (sal_Int16 i
= 0; i
< xAttribs
->getLength(); ++i
)
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
;
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());
357 void XMLStyleContext::endElement(const OUString
& rName
)
359 if (m_aName
.isEmpty())
362 if (m_aFamily
== "text" || m_aFamily
== "paragraph")
363 m_rStyles
.GetCurrentTextStyles()[m_aName
] = m_aTextPropertyList
;
364 if (m_aFamily
== "paragraph")
365 m_rStyles
.GetCurrentParagraphStyles()[m_aName
] = m_aParagraphPropertyList
;
366 else if (m_aFamily
== "table-cell")
367 m_rStyles
.GetCurrentCellStyles()[m_aName
] = m_aCellPropertyList
;
368 else if (m_aFamily
== "table-column")
369 m_rStyles
.GetCurrentColumnStyles()[m_aName
] = m_aColumnPropertyList
;
370 else if (m_aFamily
== "table-row")
371 m_rStyles
.GetCurrentRowStyles()[m_aName
] = m_aRowPropertyList
;
372 else if (m_aFamily
== "table")
373 m_rStyles
.GetCurrentTableStyles()[m_aName
] = m_aTablePropertyList
;
374 else if (m_aFamily
== "graphic")
375 m_rStyles
.GetCurrentGraphicStyles()[m_aName
] = m_aGraphicPropertyList
;
376 else if (rName
== "style:page-layout")
377 m_rStyles
.GetCurrentPageLayouts()[m_aName
] = m_aPageLayoutPropertyList
;
378 else if (rName
== "style:master-page")
379 m_rStyles
.GetCurrentMasterStyles()[m_aName
] = m_aMasterPagePropertyList
;
382 librevenge::RVNGPropertyList
& XMLStyleContext::GetTextPropertyList() { return m_aTextPropertyList
; }
384 librevenge::RVNGPropertyList
& XMLStyleContext::GetParagraphPropertyList()
386 return m_aParagraphPropertyList
;
389 librevenge::RVNGPropertyList
& XMLStyleContext::GetCellPropertyList() { return m_aCellPropertyList
; }
391 librevenge::RVNGPropertyList
& XMLStyleContext::GetColumnPropertyList()
393 return m_aColumnPropertyList
;
396 librevenge::RVNGPropertyList
& XMLStyleContext::GetRowPropertyList() { return m_aRowPropertyList
; }
398 librevenge::RVNGPropertyList
& XMLStyleContext::GetTablePropertyList()
400 return m_aTablePropertyList
;
403 librevenge::RVNGPropertyList
& XMLStyleContext::GetGraphicPropertyList()
405 return m_aGraphicPropertyList
;
408 librevenge::RVNGPropertyList
& XMLStyleContext::GetPageLayoutPropertyList()
410 return m_aPageLayoutPropertyList
;
413 } // namespace writerperfect::exp
415 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */