tdf#153192 support read protection in RTF documents
[LibreOffice.git] / writerperfect / source / writer / exp / xmlfmt.cxx
blob1fbad97d4eb382ee36fdc73c9a05af1f522c48c5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #include "xmlfmt.hxx"
12 #include "XMLBase64ImportContext.hxx"
13 #include "txtstyli.hxx"
14 #include "xmlimp.hxx"
16 #include <sal/log.hxx>
18 using namespace com::sun::star;
20 namespace writerperfect::exp
22 XMLStylesContext::XMLStylesContext(XMLImport& rImport, StyleType eType)
23 : XMLImportContext(rImport)
24 , m_rParagraphStyles(eType == StyleType_AUTOMATIC ? GetImport().GetAutomaticParagraphStyles()
25 : GetImport().GetParagraphStyles())
26 , m_rTextStyles(eType == StyleType_AUTOMATIC ? GetImport().GetAutomaticTextStyles()
27 : GetImport().GetTextStyles())
28 , m_rCellStyles(eType == StyleType_AUTOMATIC ? GetImport().GetAutomaticCellStyles()
29 : GetImport().GetCellStyles())
30 , m_rColumnStyles(eType == StyleType_AUTOMATIC ? GetImport().GetAutomaticColumnStyles()
31 : GetImport().GetColumnStyles())
32 , m_rRowStyles(eType == StyleType_AUTOMATIC ? GetImport().GetAutomaticRowStyles()
33 : GetImport().GetRowStyles())
34 , m_rTableStyles(eType == StyleType_AUTOMATIC ? GetImport().GetAutomaticTableStyles()
35 : GetImport().GetTableStyles())
36 , m_rGraphicStyles(eType == StyleType_AUTOMATIC ? GetImport().GetAutomaticGraphicStyles()
37 : GetImport().GetGraphicStyles())
38 , m_rPageLayouts(GetImport().GetPageLayouts())
39 , m_rMasterStyles(GetImport().GetMasterStyles())
43 rtl::Reference<XMLImportContext> XMLStylesContext::CreateChildContext(
44 const OUString& rName, const css::uno::Reference<css::xml::sax::XAttributeList>& /*xAttribs*/)
46 if (rName == "style:style" || rName == "style:page-layout" || rName == "style:master-page")
47 return new XMLStyleContext(GetImport(), *this);
48 return nullptr;
51 std::map<OUString, librevenge::RVNGPropertyList>& XMLStylesContext::GetCurrentParagraphStyles()
53 return m_rParagraphStyles;
56 std::map<OUString, librevenge::RVNGPropertyList>& XMLStylesContext::GetCurrentTextStyles()
58 return m_rTextStyles;
61 std::map<OUString, librevenge::RVNGPropertyList>& XMLStylesContext::GetCurrentCellStyles()
63 return m_rCellStyles;
66 std::map<OUString, librevenge::RVNGPropertyList>& XMLStylesContext::GetCurrentColumnStyles()
68 return m_rColumnStyles;
71 std::map<OUString, librevenge::RVNGPropertyList>& XMLStylesContext::GetCurrentRowStyles()
73 return m_rRowStyles;
76 std::map<OUString, librevenge::RVNGPropertyList>& XMLStylesContext::GetCurrentTableStyles()
78 return m_rTableStyles;
81 std::map<OUString, librevenge::RVNGPropertyList>& XMLStylesContext::GetCurrentGraphicStyles()
83 return m_rGraphicStyles;
86 std::map<OUString, librevenge::RVNGPropertyList>& XMLStylesContext::GetCurrentPageLayouts()
88 return m_rPageLayouts;
91 std::map<OUString, librevenge::RVNGPropertyList>& XMLStylesContext::GetCurrentMasterStyles()
93 return m_rMasterStyles;
96 namespace
98 /// Handler for <style:font-face>.
99 class XMLFontFaceContext : public XMLImportContext
101 public:
102 XMLFontFaceContext(XMLImport& rImport);
103 void SAL_CALL
104 startElement(const OUString& rName,
105 const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
107 rtl::Reference<XMLImportContext>
108 CreateChildContext(const OUString& rName,
109 const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
111 OUString const& GetName() const { return maName; }
113 private:
114 OUString maName;
117 /// Handler for <svg:font-face-src>.
118 class XMLFontFaceSrcContext : public XMLImportContext
120 public:
121 XMLFontFaceSrcContext(XMLImport& rImport, XMLFontFaceContext& rFontFace);
123 rtl::Reference<XMLImportContext>
124 CreateChildContext(const OUString& rName,
125 const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
127 private:
128 XMLFontFaceContext& mrFontFace;
131 /// Handler for <svg:font-face-uri>.
132 class XMLFontFaceUriContext : public XMLImportContext
134 public:
135 XMLFontFaceUriContext(XMLImport& rImport, XMLFontFaceContext const& rFontFace);
136 void SAL_CALL
137 startElement(const OUString& rName,
138 const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
139 void SAL_CALL endElement(const OUString& rName) override;
141 rtl::Reference<XMLImportContext>
142 CreateChildContext(const OUString& rName,
143 const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
145 librevenge::RVNGPropertyList& GetPropertyList() { return maPropertyList; }
147 private:
148 librevenge::RVNGPropertyList maPropertyList;
149 rtl::Reference<XMLBase64ImportContext> mxBinaryData;
152 /// Handler for <svg:font-face-format>.
153 class XMLFontFaceFormatContext : public XMLImportContext
155 public:
156 XMLFontFaceFormatContext(XMLImport& rImport, XMLFontFaceUriContext& rFontFaceUri);
157 void SAL_CALL
158 startElement(const OUString& rName,
159 const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
161 private:
162 XMLFontFaceUriContext& mrFontFaceUri;
166 XMLFontFaceFormatContext::XMLFontFaceFormatContext(XMLImport& rImport,
167 XMLFontFaceUriContext& rFontFaceUri)
168 : XMLImportContext(rImport)
169 , mrFontFaceUri(rFontFaceUri)
173 void XMLFontFaceFormatContext::startElement(
174 const OUString& /*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs)
176 for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
178 const OUString aAttributeName = xAttribs->getNameByIndex(i);
179 const OUString aAttributeValue = xAttribs->getValueByIndex(i);
180 if (aAttributeName == "svg:string")
182 OString aAttributeValueU8 = OUStringToOString(aAttributeValue, RTL_TEXTENCODING_UTF8);
183 mrFontFaceUri.GetPropertyList().insert("librevenge:mime-type",
184 aAttributeValueU8.getStr());
189 XMLFontFaceUriContext::XMLFontFaceUriContext(XMLImport& rImport,
190 XMLFontFaceContext const& rFontFace)
191 : XMLImportContext(rImport)
193 OString aNameU8 = OUStringToOString(rFontFace.GetName(), RTL_TEXTENCODING_UTF8);
194 maPropertyList.insert("librevenge:name", aNameU8.getStr());
197 void XMLFontFaceUriContext::startElement(
198 const OUString& /*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs)
200 for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
202 const OUString aAttributeName = xAttribs->getNameByIndex(i);
203 const OUString aAttributeValue = xAttribs->getValueByIndex(i);
204 if (aAttributeName == "loext:font-style")
206 OString aAttributeValueU8 = OUStringToOString(aAttributeValue, RTL_TEXTENCODING_UTF8);
207 maPropertyList.insert("librevenge:font-style", aAttributeValueU8.getStr());
209 else if (aAttributeName == "loext:font-weight")
211 OString aAttributeValueU8 = OUStringToOString(aAttributeValue, RTL_TEXTENCODING_UTF8);
212 maPropertyList.insert("librevenge:font-weight", aAttributeValueU8.getStr());
217 void XMLFontFaceUriContext::endElement(const OUString& /*rName*/)
219 if (mxBinaryData.is())
220 maPropertyList.insert("office:binary-data", mxBinaryData->getBinaryData());
221 GetImport().GetGenerator().defineEmbeddedFont(maPropertyList);
224 rtl::Reference<XMLImportContext> XMLFontFaceUriContext::CreateChildContext(
225 const OUString& rName, const css::uno::Reference<css::xml::sax::XAttributeList>& /*xAttribs*/)
227 if (rName == "office:binary-data")
229 mxBinaryData = new XMLBase64ImportContext(GetImport());
230 return mxBinaryData;
232 if (rName == "svg:font-face-format")
233 return new XMLFontFaceFormatContext(GetImport(), *this);
235 SAL_WARN("writerperfect", "XMLFontFaceUriContext::CreateChildContext: unhandled " << rName);
236 return nullptr;
239 XMLFontFaceSrcContext::XMLFontFaceSrcContext(XMLImport& rImport, XMLFontFaceContext& rFontFace)
240 : XMLImportContext(rImport)
241 , mrFontFace(rFontFace)
245 rtl::Reference<XMLImportContext> XMLFontFaceSrcContext::CreateChildContext(
246 const OUString& rName, const css::uno::Reference<css::xml::sax::XAttributeList>& /*xAttribs*/)
248 if (rName == "svg:font-face-uri")
249 return new XMLFontFaceUriContext(GetImport(), mrFontFace);
250 SAL_WARN("writerperfect", "XMLFontFaceSrcContext::CreateChildContext: unhandled " << rName);
251 return nullptr;
254 XMLFontFaceContext::XMLFontFaceContext(XMLImport& rImport)
255 : XMLImportContext(rImport)
259 void XMLFontFaceContext::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 const OUString aAttributeName = xAttribs->getNameByIndex(i);
265 const OUString aAttributeValue = xAttribs->getValueByIndex(i);
266 if (aAttributeName == "style:name")
267 maName = aAttributeValue;
271 rtl::Reference<XMLImportContext> XMLFontFaceContext::CreateChildContext(
272 const OUString& rName, const css::uno::Reference<css::xml::sax::XAttributeList>& /*xAttribs*/)
274 if (rName == "svg:font-face-src")
275 return new XMLFontFaceSrcContext(GetImport(), *this);
276 SAL_WARN("writerperfect", "XMLFontFaceContext::CreateChildContext: unhandled " << rName);
277 return nullptr;
280 XMLFontFaceDeclsContext::XMLFontFaceDeclsContext(XMLImport& rImport)
281 : XMLImportContext(rImport)
285 rtl::Reference<XMLImportContext> XMLFontFaceDeclsContext::CreateChildContext(
286 const OUString& rName, const css::uno::Reference<css::xml::sax::XAttributeList>& /*xAttribs*/)
288 if (rName == "style:font-face")
289 return new XMLFontFaceContext(GetImport());
290 return nullptr;
293 } // namespace writerperfect::exp
295 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */