/src/libreoffice/writerperfect/source/writer/exp/xmlfmt.cxx
Line | Count | Source |
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 "xmlfmt.hxx" |
11 | | |
12 | | #include "XMLBase64ImportContext.hxx" |
13 | | #include "txtstyli.hxx" |
14 | | #include "xmlimp.hxx" |
15 | | |
16 | | #include <sal/log.hxx> |
17 | | |
18 | | using namespace com::sun::star; |
19 | | |
20 | | namespace writerperfect::exp |
21 | | { |
22 | | XMLStylesContext::XMLStylesContext(XMLImport& rImport, StyleType eType) |
23 | 0 | : XMLImportContext(rImport) |
24 | 0 | , m_rParagraphStyles(eType == StyleType_AUTOMATIC ? GetImport().GetAutomaticParagraphStyles() |
25 | 0 | : GetImport().GetParagraphStyles()) |
26 | 0 | , m_rTextStyles(eType == StyleType_AUTOMATIC ? GetImport().GetAutomaticTextStyles() |
27 | 0 | : GetImport().GetTextStyles()) |
28 | 0 | , m_rCellStyles(eType == StyleType_AUTOMATIC ? GetImport().GetAutomaticCellStyles() |
29 | 0 | : GetImport().GetCellStyles()) |
30 | 0 | , m_rColumnStyles(eType == StyleType_AUTOMATIC ? GetImport().GetAutomaticColumnStyles() |
31 | 0 | : GetImport().GetColumnStyles()) |
32 | 0 | , m_rRowStyles(eType == StyleType_AUTOMATIC ? GetImport().GetAutomaticRowStyles() |
33 | 0 | : GetImport().GetRowStyles()) |
34 | 0 | , m_rTableStyles(eType == StyleType_AUTOMATIC ? GetImport().GetAutomaticTableStyles() |
35 | 0 | : GetImport().GetTableStyles()) |
36 | 0 | , m_rGraphicStyles(eType == StyleType_AUTOMATIC ? GetImport().GetAutomaticGraphicStyles() |
37 | 0 | : GetImport().GetGraphicStyles()) |
38 | 0 | , m_rPageLayouts(GetImport().GetPageLayouts()) |
39 | 0 | , m_rMasterStyles(GetImport().GetMasterStyles()) |
40 | 0 | { |
41 | 0 | } |
42 | | |
43 | | rtl::Reference<XMLImportContext> XMLStylesContext::CreateChildContext( |
44 | | const OUString& rName, const css::uno::Reference<css::xml::sax::XAttributeList>& /*xAttribs*/) |
45 | 0 | { |
46 | 0 | if (rName == "style:style" || rName == "style:page-layout" || rName == "style:master-page") |
47 | 0 | return new XMLStyleContext(GetImport(), *this); |
48 | 0 | return nullptr; |
49 | 0 | } |
50 | | |
51 | | std::map<OUString, librevenge::RVNGPropertyList>& XMLStylesContext::GetCurrentParagraphStyles() |
52 | 0 | { |
53 | 0 | return m_rParagraphStyles; |
54 | 0 | } |
55 | | |
56 | | std::map<OUString, librevenge::RVNGPropertyList>& XMLStylesContext::GetCurrentTextStyles() |
57 | 0 | { |
58 | 0 | return m_rTextStyles; |
59 | 0 | } |
60 | | |
61 | | std::map<OUString, librevenge::RVNGPropertyList>& XMLStylesContext::GetCurrentCellStyles() |
62 | 0 | { |
63 | 0 | return m_rCellStyles; |
64 | 0 | } |
65 | | |
66 | | std::map<OUString, librevenge::RVNGPropertyList>& XMLStylesContext::GetCurrentColumnStyles() |
67 | 0 | { |
68 | 0 | return m_rColumnStyles; |
69 | 0 | } |
70 | | |
71 | | std::map<OUString, librevenge::RVNGPropertyList>& XMLStylesContext::GetCurrentRowStyles() |
72 | 0 | { |
73 | 0 | return m_rRowStyles; |
74 | 0 | } |
75 | | |
76 | | std::map<OUString, librevenge::RVNGPropertyList>& XMLStylesContext::GetCurrentTableStyles() |
77 | 0 | { |
78 | 0 | return m_rTableStyles; |
79 | 0 | } |
80 | | |
81 | | std::map<OUString, librevenge::RVNGPropertyList>& XMLStylesContext::GetCurrentGraphicStyles() |
82 | 0 | { |
83 | 0 | return m_rGraphicStyles; |
84 | 0 | } |
85 | | |
86 | | std::map<OUString, librevenge::RVNGPropertyList>& XMLStylesContext::GetCurrentPageLayouts() |
87 | 0 | { |
88 | 0 | return m_rPageLayouts; |
89 | 0 | } |
90 | | |
91 | | std::map<OUString, librevenge::RVNGPropertyList>& XMLStylesContext::GetCurrentMasterStyles() |
92 | 0 | { |
93 | 0 | return m_rMasterStyles; |
94 | 0 | } |
95 | | |
96 | | namespace |
97 | | { |
98 | | /// Handler for <style:font-face>. |
99 | | class XMLFontFaceContext : public XMLImportContext |
100 | | { |
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; |
106 | | |
107 | | rtl::Reference<XMLImportContext> |
108 | | CreateChildContext(const OUString& rName, |
109 | | const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override; |
110 | | |
111 | 0 | OUString const& GetName() const { return maName; } |
112 | | |
113 | | private: |
114 | | OUString maName; |
115 | | }; |
116 | | |
117 | | /// Handler for <svg:font-face-src>. |
118 | | class XMLFontFaceSrcContext : public XMLImportContext |
119 | | { |
120 | | public: |
121 | | XMLFontFaceSrcContext(XMLImport& rImport, XMLFontFaceContext& rFontFace); |
122 | | |
123 | | rtl::Reference<XMLImportContext> |
124 | | CreateChildContext(const OUString& rName, |
125 | | const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override; |
126 | | |
127 | | private: |
128 | | XMLFontFaceContext& mrFontFace; |
129 | | }; |
130 | | |
131 | | /// Handler for <svg:font-face-uri>. |
132 | | class XMLFontFaceUriContext : public XMLImportContext |
133 | | { |
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; |
140 | | |
141 | | rtl::Reference<XMLImportContext> |
142 | | CreateChildContext(const OUString& rName, |
143 | | const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override; |
144 | | |
145 | 0 | librevenge::RVNGPropertyList& GetPropertyList() { return maPropertyList; } |
146 | | |
147 | | private: |
148 | | librevenge::RVNGPropertyList maPropertyList; |
149 | | rtl::Reference<XMLBase64ImportContext> mxBinaryData; |
150 | | }; |
151 | | |
152 | | /// Handler for <svg:font-face-format>. |
153 | | class XMLFontFaceFormatContext : public XMLImportContext |
154 | | { |
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; |
160 | | |
161 | | private: |
162 | | XMLFontFaceUriContext& mrFontFaceUri; |
163 | | }; |
164 | | } |
165 | | |
166 | | XMLFontFaceFormatContext::XMLFontFaceFormatContext(XMLImport& rImport, |
167 | | XMLFontFaceUriContext& rFontFaceUri) |
168 | 0 | : XMLImportContext(rImport) |
169 | 0 | , mrFontFaceUri(rFontFaceUri) |
170 | 0 | { |
171 | 0 | } |
172 | | |
173 | | void XMLFontFaceFormatContext::startElement( |
174 | | const OUString& /*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) |
175 | 0 | { |
176 | 0 | for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i) |
177 | 0 | { |
178 | 0 | const OUString aAttributeName = xAttribs->getNameByIndex(i); |
179 | 0 | const OUString aAttributeValue = xAttribs->getValueByIndex(i); |
180 | 0 | if (aAttributeName == "svg:string") |
181 | 0 | { |
182 | 0 | OString aAttributeValueU8 = OUStringToOString(aAttributeValue, RTL_TEXTENCODING_UTF8); |
183 | 0 | mrFontFaceUri.GetPropertyList().insert("librevenge:mime-type", |
184 | 0 | aAttributeValueU8.getStr()); |
185 | 0 | } |
186 | 0 | } |
187 | 0 | } |
188 | | |
189 | | XMLFontFaceUriContext::XMLFontFaceUriContext(XMLImport& rImport, |
190 | | XMLFontFaceContext const& rFontFace) |
191 | 0 | : XMLImportContext(rImport) |
192 | 0 | { |
193 | 0 | OString aNameU8 = OUStringToOString(rFontFace.GetName(), RTL_TEXTENCODING_UTF8); |
194 | 0 | maPropertyList.insert("librevenge:name", aNameU8.getStr()); |
195 | 0 | } |
196 | | |
197 | | void XMLFontFaceUriContext::startElement( |
198 | | const OUString& /*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) |
199 | 0 | { |
200 | 0 | for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i) |
201 | 0 | { |
202 | 0 | const OUString aAttributeName = xAttribs->getNameByIndex(i); |
203 | 0 | const OUString aAttributeValue = xAttribs->getValueByIndex(i); |
204 | 0 | if (aAttributeName == "loext:font-style") |
205 | 0 | { |
206 | 0 | OString aAttributeValueU8 = OUStringToOString(aAttributeValue, RTL_TEXTENCODING_UTF8); |
207 | 0 | maPropertyList.insert("librevenge:font-style", aAttributeValueU8.getStr()); |
208 | 0 | } |
209 | 0 | else if (aAttributeName == "loext:font-weight") |
210 | 0 | { |
211 | 0 | OString aAttributeValueU8 = OUStringToOString(aAttributeValue, RTL_TEXTENCODING_UTF8); |
212 | 0 | maPropertyList.insert("librevenge:font-weight", aAttributeValueU8.getStr()); |
213 | 0 | } |
214 | 0 | } |
215 | 0 | } |
216 | | |
217 | | void XMLFontFaceUriContext::endElement(const OUString& /*rName*/) |
218 | 0 | { |
219 | 0 | if (mxBinaryData.is()) |
220 | 0 | maPropertyList.insert("office:binary-data", mxBinaryData->getBinaryData()); |
221 | 0 | GetImport().GetGenerator().defineEmbeddedFont(maPropertyList); |
222 | 0 | } |
223 | | |
224 | | rtl::Reference<XMLImportContext> XMLFontFaceUriContext::CreateChildContext( |
225 | | const OUString& rName, const css::uno::Reference<css::xml::sax::XAttributeList>& /*xAttribs*/) |
226 | 0 | { |
227 | 0 | if (rName == "office:binary-data") |
228 | 0 | { |
229 | 0 | mxBinaryData = new XMLBase64ImportContext(GetImport()); |
230 | 0 | return mxBinaryData; |
231 | 0 | } |
232 | 0 | if (rName == "svg:font-face-format") |
233 | 0 | return new XMLFontFaceFormatContext(GetImport(), *this); |
234 | | |
235 | 0 | SAL_WARN("writerperfect", "XMLFontFaceUriContext::CreateChildContext: unhandled " << rName); |
236 | 0 | return nullptr; |
237 | 0 | } |
238 | | |
239 | | XMLFontFaceSrcContext::XMLFontFaceSrcContext(XMLImport& rImport, XMLFontFaceContext& rFontFace) |
240 | 0 | : XMLImportContext(rImport) |
241 | 0 | , mrFontFace(rFontFace) |
242 | 0 | { |
243 | 0 | } |
244 | | |
245 | | rtl::Reference<XMLImportContext> XMLFontFaceSrcContext::CreateChildContext( |
246 | | const OUString& rName, const css::uno::Reference<css::xml::sax::XAttributeList>& /*xAttribs*/) |
247 | 0 | { |
248 | 0 | if (rName == "svg:font-face-uri") |
249 | 0 | return new XMLFontFaceUriContext(GetImport(), mrFontFace); |
250 | 0 | SAL_WARN("writerperfect", "XMLFontFaceSrcContext::CreateChildContext: unhandled " << rName); |
251 | 0 | return nullptr; |
252 | 0 | } |
253 | | |
254 | | XMLFontFaceContext::XMLFontFaceContext(XMLImport& rImport) |
255 | 0 | : XMLImportContext(rImport) |
256 | 0 | { |
257 | 0 | } |
258 | | |
259 | | void XMLFontFaceContext::startElement( |
260 | | const OUString& /*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) |
261 | 0 | { |
262 | 0 | for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i) |
263 | 0 | { |
264 | 0 | const OUString aAttributeName = xAttribs->getNameByIndex(i); |
265 | 0 | const OUString aAttributeValue = xAttribs->getValueByIndex(i); |
266 | 0 | if (aAttributeName == "style:name") |
267 | 0 | maName = aAttributeValue; |
268 | 0 | } |
269 | 0 | } |
270 | | |
271 | | rtl::Reference<XMLImportContext> XMLFontFaceContext::CreateChildContext( |
272 | | const OUString& rName, const css::uno::Reference<css::xml::sax::XAttributeList>& /*xAttribs*/) |
273 | 0 | { |
274 | 0 | if (rName == "svg:font-face-src") |
275 | 0 | return new XMLFontFaceSrcContext(GetImport(), *this); |
276 | 0 | SAL_WARN("writerperfect", "XMLFontFaceContext::CreateChildContext: unhandled " << rName); |
277 | 0 | return nullptr; |
278 | 0 | } |
279 | | |
280 | | XMLFontFaceDeclsContext::XMLFontFaceDeclsContext(XMLImport& rImport) |
281 | 0 | : XMLImportContext(rImport) |
282 | 0 | { |
283 | 0 | } |
284 | | |
285 | | rtl::Reference<XMLImportContext> XMLFontFaceDeclsContext::CreateChildContext( |
286 | | const OUString& rName, const css::uno::Reference<css::xml::sax::XAttributeList>& /*xAttribs*/) |
287 | 0 | { |
288 | 0 | if (rName == "style:font-face") |
289 | 0 | return new XMLFontFaceContext(GetImport()); |
290 | 0 | return nullptr; |
291 | 0 | } |
292 | | |
293 | | } // namespace writerperfect::exp |
294 | | |
295 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |