/src/libreoffice/writerperfect/source/writer/exp/txtparai.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 <sal/config.h> |
11 | | |
12 | | #include "txtparai.hxx" |
13 | | |
14 | | #include <string_view> |
15 | | |
16 | | #include "XMLFootnoteImportContext.hxx" |
17 | | #include "XMLTextFrameContext.hxx" |
18 | | #include "xmlimp.hxx" |
19 | | |
20 | | #include <sal/log.hxx> |
21 | | |
22 | | using namespace com::sun::star; |
23 | | |
24 | | namespace |
25 | | { |
26 | | /// Looks for rName in rStyles and fills rPropertyList based on that |
27 | | /// (rAutomaticStyles and rNamedStyles are a list of possible parents). |
28 | | void FillStyle(const OUString& rName, std::map<OUString, librevenge::RVNGPropertyList>& rStyles, |
29 | | std::map<OUString, librevenge::RVNGPropertyList>& rAutomaticStyles, |
30 | | std::map<OUString, librevenge::RVNGPropertyList>& rNamedStyles, |
31 | | librevenge::RVNGPropertyList& rPropertyList) |
32 | 0 | { |
33 | 0 | auto itStyle = rStyles.find(rName); |
34 | 0 | if (itStyle == rStyles.end()) |
35 | 0 | return; |
36 | | |
37 | 0 | const librevenge::RVNGPropertyList& rStyle = itStyle->second; |
38 | 0 | if (rStyle["style:parent-style-name"]) |
39 | 0 | { |
40 | | // The style has a parent. |
41 | 0 | OUString aParent = OStringToOUString(rStyle["style:parent-style-name"]->getStr().cstr(), |
42 | 0 | RTL_TEXTENCODING_UTF8); |
43 | 0 | if (!aParent.isEmpty()) |
44 | 0 | writerperfect::exp::FillStyles(aParent, rAutomaticStyles, rNamedStyles, rPropertyList); |
45 | 0 | } |
46 | | |
47 | | // Apply properties from named style. |
48 | 0 | librevenge::RVNGPropertyList::Iter itProp(rStyle); |
49 | 0 | for (itProp.rewind(); itProp.next();) |
50 | 0 | { |
51 | 0 | if (std::string_view("style:parent-style-name") != itProp.key()) |
52 | 0 | rPropertyList.insert(itProp.key(), itProp()->clone()); |
53 | 0 | } |
54 | 0 | } |
55 | | } |
56 | | |
57 | | namespace writerperfect::exp |
58 | | { |
59 | | namespace |
60 | | { |
61 | | /// Handler for <text:sequence>. |
62 | | class XMLTextSequenceContext : public XMLImportContext |
63 | | { |
64 | | public: |
65 | | XMLTextSequenceContext(XMLImport& rImport, const librevenge::RVNGPropertyList& rPropertyList); |
66 | | |
67 | | void SAL_CALL characters(const OUString& rChars) override; |
68 | | |
69 | | private: |
70 | | librevenge::RVNGPropertyList m_aPropertyList; |
71 | | }; |
72 | | } |
73 | | |
74 | | XMLTextSequenceContext::XMLTextSequenceContext(XMLImport& rImport, |
75 | | const librevenge::RVNGPropertyList& rPropertyList) |
76 | 0 | : XMLImportContext(rImport) |
77 | 0 | { |
78 | | // Inherit properties from parent. |
79 | 0 | librevenge::RVNGPropertyList::Iter itProp(rPropertyList); |
80 | 0 | for (itProp.rewind(); itProp.next();) |
81 | 0 | m_aPropertyList.insert(itProp.key(), itProp()->clone()); |
82 | 0 | } |
83 | | |
84 | | void XMLTextSequenceContext::characters(const OUString& rChars) |
85 | 0 | { |
86 | 0 | GetImport().GetGenerator().openSpan(m_aPropertyList); |
87 | |
|
88 | 0 | OString sCharU8 = OUStringToOString(rChars, RTL_TEXTENCODING_UTF8); |
89 | 0 | GetImport().GetGenerator().insertText(librevenge::RVNGString(sCharU8.getStr())); |
90 | |
|
91 | 0 | GetImport().GetGenerator().closeSpan(); |
92 | 0 | } |
93 | | |
94 | | namespace |
95 | | { |
96 | | /// Handler for <text:span>. |
97 | | class XMLSpanContext : public XMLImportContext |
98 | | { |
99 | | public: |
100 | | XMLSpanContext(XMLImport& rImport, const librevenge::RVNGPropertyList& rPropertyList); |
101 | | |
102 | | rtl::Reference<XMLImportContext> |
103 | | CreateChildContext(const OUString& rName, |
104 | | const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override; |
105 | | |
106 | | void SAL_CALL |
107 | | startElement(const OUString& rName, |
108 | | const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override; |
109 | | void SAL_CALL characters(const OUString& rChars) override; |
110 | | |
111 | | private: |
112 | | librevenge::RVNGPropertyList m_aPropertyList; |
113 | | }; |
114 | | } |
115 | | |
116 | | XMLSpanContext::XMLSpanContext(XMLImport& rImport, |
117 | | const librevenge::RVNGPropertyList& rPropertyList) |
118 | 0 | : XMLImportContext(rImport) |
119 | 0 | { |
120 | | // Inherit properties from parent. |
121 | 0 | librevenge::RVNGPropertyList::Iter itProp(rPropertyList); |
122 | 0 | for (itProp.rewind(); itProp.next();) |
123 | 0 | m_aPropertyList.insert(itProp.key(), itProp()->clone()); |
124 | 0 | } |
125 | | |
126 | | rtl::Reference<XMLImportContext> XMLSpanContext::CreateChildContext( |
127 | | const OUString& rName, const css::uno::Reference<css::xml::sax::XAttributeList>& /*xAttribs*/) |
128 | 0 | { |
129 | 0 | return CreateParagraphOrSpanChildContext(GetImport(), rName, m_aPropertyList); |
130 | 0 | } |
131 | | |
132 | | void XMLSpanContext::startElement( |
133 | | const OUString& /*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) |
134 | 0 | { |
135 | 0 | for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i) |
136 | 0 | { |
137 | 0 | const OUString aAttributeName = xAttribs->getNameByIndex(i); |
138 | 0 | const OUString aAttributeValue = xAttribs->getValueByIndex(i); |
139 | 0 | if (aAttributeName == "text:style-name") |
140 | 0 | FillStyles(aAttributeValue, GetImport().GetAutomaticTextStyles(), |
141 | 0 | GetImport().GetTextStyles(), m_aPropertyList); |
142 | 0 | else |
143 | 0 | { |
144 | 0 | OString sName = OUStringToOString(aAttributeName, RTL_TEXTENCODING_UTF8); |
145 | 0 | OString sValue = OUStringToOString(aAttributeValue, RTL_TEXTENCODING_UTF8); |
146 | 0 | m_aPropertyList.insert(sName.getStr(), sValue.getStr()); |
147 | 0 | } |
148 | 0 | } |
149 | 0 | } |
150 | | |
151 | | void XMLSpanContext::characters(const OUString& rChars) |
152 | 0 | { |
153 | 0 | GetImport().GetGenerator().openSpan(m_aPropertyList); |
154 | |
|
155 | 0 | OString sCharU8 = OUStringToOString(rChars, RTL_TEXTENCODING_UTF8); |
156 | 0 | GetImport().GetGenerator().insertText(librevenge::RVNGString(sCharU8.getStr())); |
157 | |
|
158 | 0 | GetImport().GetGenerator().closeSpan(); |
159 | 0 | } |
160 | | |
161 | | namespace |
162 | | { |
163 | | /// Handler for <text:ruby>. |
164 | | class XMLRubyContext : public XMLImportContext |
165 | | { |
166 | | public: |
167 | | XMLRubyContext(XMLImport& rImport, const librevenge::RVNGPropertyList& rPropertyList); |
168 | | |
169 | | rtl::Reference<XMLImportContext> |
170 | | CreateChildContext(const OUString& rName, |
171 | | const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override; |
172 | | |
173 | | void SAL_CALL endElement(const OUString& rName) override; |
174 | | |
175 | 0 | void SetRubyText(const OUString& rRubyText) { m_sRubyText = rRubyText; } |
176 | | |
177 | 0 | OUString& GetRubyBase() { return m_sRubyBase; } |
178 | | |
179 | | private: |
180 | | OUString m_sRubyText; |
181 | | OUString m_sRubyBase; |
182 | | librevenge::RVNGPropertyList m_aPropertyList; |
183 | | }; |
184 | | |
185 | | /// Handler for <text:ruby-text>. |
186 | | class XMLRubyTextContext : public XMLImportContext |
187 | | { |
188 | | public: |
189 | | XMLRubyTextContext(XMLImport& rImport, XMLRubyContext& rParent) |
190 | 0 | : XMLImportContext(rImport) |
191 | 0 | , m_rParent(rParent) |
192 | 0 | { |
193 | 0 | } |
194 | | |
195 | 0 | void SAL_CALL characters(const OUString& rChars) override { m_rParent.SetRubyText(rChars); } |
196 | | |
197 | | private: |
198 | | XMLRubyContext& m_rParent; |
199 | | }; |
200 | | |
201 | | /// Handler for <text:ruby-base>. |
202 | | class XMLRubyBaseContext : public XMLImportContext |
203 | | { |
204 | | public: |
205 | | XMLRubyBaseContext(XMLImport& rImport, XMLRubyContext& rParent) |
206 | 0 | : XMLImportContext(rImport) |
207 | 0 | , m_rParent(rParent) |
208 | 0 | { |
209 | 0 | } |
210 | | |
211 | 0 | void SAL_CALL characters(const OUString& rChars) override { m_rParent.GetRubyBase() += rChars; } |
212 | | |
213 | | private: |
214 | | XMLRubyContext& m_rParent; |
215 | | }; |
216 | | } |
217 | | |
218 | | XMLRubyContext::XMLRubyContext(XMLImport& rImport, |
219 | | const librevenge::RVNGPropertyList& rPropertyList) |
220 | 0 | : XMLImportContext(rImport) |
221 | 0 | { |
222 | | // Inherit properties from parent. |
223 | 0 | librevenge::RVNGPropertyList::Iter itProp(rPropertyList); |
224 | 0 | for (itProp.rewind(); itProp.next();) |
225 | 0 | m_aPropertyList.insert(itProp.key(), itProp()->clone()); |
226 | 0 | } |
227 | | |
228 | | rtl::Reference<XMLImportContext> XMLRubyContext::CreateChildContext( |
229 | | const OUString& rName, const css::uno::Reference<css::xml::sax::XAttributeList>& /*xAttribs*/) |
230 | 0 | { |
231 | 0 | if (rName == "text:ruby-base") |
232 | 0 | return new XMLRubyBaseContext(GetImport(), *this); |
233 | 0 | if (rName == "text:ruby-text") |
234 | 0 | return new XMLRubyTextContext(GetImport(), *this); |
235 | 0 | return nullptr; |
236 | 0 | } |
237 | | |
238 | | void XMLRubyContext::endElement(const OUString& /*rName*/) |
239 | 0 | { |
240 | 0 | OString sRubyText = OUStringToOString(m_sRubyText, RTL_TEXTENCODING_UTF8); |
241 | 0 | OString sRubyBase = OUStringToOString(m_sRubyBase, RTL_TEXTENCODING_UTF8); |
242 | 0 | if (sRubyText.getLength()) |
243 | 0 | m_aPropertyList.insert("text:ruby-text", sRubyText.getStr()); |
244 | 0 | GetImport().GetGenerator().openSpan(m_aPropertyList); |
245 | 0 | GetImport().GetGenerator().insertText(sRubyBase.getStr()); |
246 | 0 | GetImport().GetGenerator().closeSpan(); |
247 | 0 | } |
248 | | |
249 | | namespace |
250 | | { |
251 | | /// Base class for contexts that represent a single character only. |
252 | | class XMLCharContext : public XMLImportContext |
253 | | { |
254 | | public: |
255 | | XMLCharContext(XMLImport& rImport, const librevenge::RVNGPropertyList& rPropertyList); |
256 | | |
257 | 0 | const librevenge::RVNGPropertyList& GetPropertyList() const { return m_aPropertyList; } |
258 | | |
259 | | private: |
260 | | librevenge::RVNGPropertyList m_aPropertyList; |
261 | | }; |
262 | | } |
263 | | |
264 | | XMLCharContext::XMLCharContext(XMLImport& rImport, |
265 | | const librevenge::RVNGPropertyList& rPropertyList) |
266 | 0 | : XMLImportContext(rImport) |
267 | 0 | { |
268 | | // Inherit properties from parent. |
269 | 0 | librevenge::RVNGPropertyList::Iter itProp(rPropertyList); |
270 | 0 | for (itProp.rewind(); itProp.next();) |
271 | 0 | m_aPropertyList.insert(itProp.key(), itProp()->clone()); |
272 | 0 | } |
273 | | |
274 | | namespace |
275 | | { |
276 | | /// Handler for <text:line-break>. |
277 | | class XMLLineBreakContext : public XMLCharContext |
278 | | { |
279 | | public: |
280 | | XMLLineBreakContext(XMLImport& rImport, const librevenge::RVNGPropertyList& rPropertyList); |
281 | | |
282 | | void SAL_CALL |
283 | | startElement(const OUString& rName, |
284 | | const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override; |
285 | | }; |
286 | | } |
287 | | |
288 | | XMLLineBreakContext::XMLLineBreakContext(XMLImport& rImport, |
289 | | const librevenge::RVNGPropertyList& rPropertyList) |
290 | 0 | : XMLCharContext(rImport, rPropertyList) |
291 | 0 | { |
292 | 0 | } |
293 | | |
294 | | void XMLLineBreakContext::startElement( |
295 | | const OUString& /*rName*/, |
296 | | const css::uno::Reference<css::xml::sax::XAttributeList>& /*xAttribs*/) |
297 | 0 | { |
298 | 0 | GetImport().GetGenerator().openSpan(GetPropertyList()); |
299 | 0 | GetImport().GetGenerator().insertLineBreak(); |
300 | 0 | GetImport().GetGenerator().closeSpan(); |
301 | 0 | } |
302 | | |
303 | | namespace |
304 | | { |
305 | | /// Handler for <text:s>. |
306 | | class XMLSpaceContext : public XMLCharContext |
307 | | { |
308 | | public: |
309 | | XMLSpaceContext(XMLImport& rImport, const librevenge::RVNGPropertyList& rPropertyList); |
310 | | |
311 | | void SAL_CALL |
312 | | startElement(const OUString& rName, |
313 | | const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override; |
314 | | }; |
315 | | } |
316 | | |
317 | | XMLSpaceContext::XMLSpaceContext(XMLImport& rImport, |
318 | | const librevenge::RVNGPropertyList& rPropertyList) |
319 | 0 | : XMLCharContext(rImport, rPropertyList) |
320 | 0 | { |
321 | 0 | } |
322 | | |
323 | | void XMLSpaceContext::startElement( |
324 | | const OUString& /*rName*/, |
325 | | const css::uno::Reference<css::xml::sax::XAttributeList>& /*xAttribs*/) |
326 | 0 | { |
327 | 0 | GetImport().GetGenerator().openSpan(GetPropertyList()); |
328 | 0 | GetImport().GetGenerator().insertSpace(); |
329 | 0 | GetImport().GetGenerator().closeSpan(); |
330 | 0 | } |
331 | | |
332 | | namespace |
333 | | { |
334 | | /// Handler for <text:tab>. |
335 | | class XMLTabContext : public XMLCharContext |
336 | | { |
337 | | public: |
338 | | XMLTabContext(XMLImport& rImport, const librevenge::RVNGPropertyList& rPropertyList); |
339 | | |
340 | | void SAL_CALL |
341 | | startElement(const OUString& rName, |
342 | | const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override; |
343 | | }; |
344 | | } |
345 | | |
346 | | XMLTabContext::XMLTabContext(XMLImport& rImport, const librevenge::RVNGPropertyList& rPropertyList) |
347 | 0 | : XMLCharContext(rImport, rPropertyList) |
348 | 0 | { |
349 | 0 | } |
350 | | |
351 | | void XMLTabContext::startElement( |
352 | | const OUString& /*rName*/, |
353 | | const css::uno::Reference<css::xml::sax::XAttributeList>& /*xAttribs*/) |
354 | 0 | { |
355 | 0 | GetImport().GetGenerator().openSpan(GetPropertyList()); |
356 | 0 | GetImport().GetGenerator().insertTab(); |
357 | 0 | GetImport().GetGenerator().closeSpan(); |
358 | 0 | } |
359 | | |
360 | | namespace |
361 | | { |
362 | | /// Handler for <draw:a>. |
363 | | class XMLTextFrameHyperlinkContext : public XMLImportContext |
364 | | { |
365 | | public: |
366 | | XMLTextFrameHyperlinkContext(XMLImport& rImport, |
367 | | const librevenge::RVNGPropertyList& rPropertyList); |
368 | | rtl::Reference<XMLImportContext> |
369 | | CreateChildContext(const OUString& rName, |
370 | | const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override; |
371 | | |
372 | | void SAL_CALL |
373 | | startElement(const OUString& rName, |
374 | | const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override; |
375 | | void SAL_CALL endElement(const OUString& rName) override; |
376 | | void SAL_CALL characters(const OUString& rChars) override; |
377 | | |
378 | | private: |
379 | | librevenge::RVNGPropertyList m_aPropertyList; |
380 | | PopupState m_ePopupState = PopupState::NONE; |
381 | | }; |
382 | | } |
383 | | |
384 | | XMLTextFrameHyperlinkContext::XMLTextFrameHyperlinkContext( |
385 | | XMLImport& rImport, const librevenge::RVNGPropertyList& rPropertyList) |
386 | 0 | : XMLImportContext(rImport) |
387 | 0 | { |
388 | | // Inherit properties from parent. |
389 | 0 | librevenge::RVNGPropertyList::Iter itProp(rPropertyList); |
390 | 0 | for (itProp.rewind(); itProp.next();) |
391 | 0 | m_aPropertyList.insert(itProp.key(), itProp()->clone()); |
392 | 0 | } |
393 | | |
394 | | rtl::Reference<XMLImportContext> XMLTextFrameHyperlinkContext::CreateChildContext( |
395 | | const OUString& rName, const css::uno::Reference<css::xml::sax::XAttributeList>& /*xAttribs*/) |
396 | 0 | { |
397 | 0 | return CreateParagraphOrSpanChildContext(GetImport(), rName, m_aPropertyList); |
398 | 0 | } |
399 | | |
400 | | void XMLTextFrameHyperlinkContext::startElement( |
401 | | const OUString& /*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) |
402 | 0 | { |
403 | 0 | librevenge::RVNGPropertyList aPropertyList; |
404 | 0 | for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i) |
405 | 0 | { |
406 | 0 | const OUString aAttributeName = xAttribs->getNameByIndex(i); |
407 | 0 | const OUString aAttributeValue = xAttribs->getValueByIndex(i); |
408 | 0 | if (aAttributeName == "text:style-name") |
409 | | // This affects the nested span's properties. |
410 | 0 | FillStyles(aAttributeValue, GetImport().GetAutomaticTextStyles(), |
411 | 0 | GetImport().GetTextStyles(), m_aPropertyList); |
412 | 0 | else |
413 | 0 | { |
414 | 0 | if (aAttributeName == "xlink:href") |
415 | 0 | { |
416 | 0 | m_ePopupState = GetImport().FillPopupData(aAttributeValue, aPropertyList); |
417 | 0 | if (m_ePopupState != PopupState::NotConsumed) |
418 | 0 | continue; |
419 | 0 | } |
420 | | |
421 | | // This affects the link's properties. |
422 | 0 | OString sName = OUStringToOString(aAttributeName, RTL_TEXTENCODING_UTF8); |
423 | 0 | OString sValue = OUStringToOString(aAttributeValue, RTL_TEXTENCODING_UTF8); |
424 | 0 | aPropertyList.insert(sName.getStr(), sValue.getStr()); |
425 | 0 | } |
426 | 0 | } |
427 | |
|
428 | 0 | if (m_ePopupState != PopupState::Ignore) |
429 | 0 | GetImport().GetGenerator().openLink(aPropertyList); |
430 | 0 | } |
431 | | |
432 | | void XMLTextFrameHyperlinkContext::endElement(const OUString& /*rName*/) |
433 | 0 | { |
434 | 0 | if (m_ePopupState != PopupState::Ignore) |
435 | 0 | GetImport().GetGenerator().closeLink(); |
436 | 0 | } |
437 | | |
438 | | void XMLTextFrameHyperlinkContext::characters(const OUString& rChars) |
439 | 0 | { |
440 | 0 | GetImport().GetGenerator().openSpan(m_aPropertyList); |
441 | |
|
442 | 0 | OString sCharU8 = OUStringToOString(rChars, RTL_TEXTENCODING_UTF8); |
443 | 0 | GetImport().GetGenerator().insertText(librevenge::RVNGString(sCharU8.getStr())); |
444 | |
|
445 | 0 | GetImport().GetGenerator().closeSpan(); |
446 | 0 | } |
447 | | |
448 | | namespace |
449 | | { |
450 | | /// Handler for <text:a>. |
451 | | class XMLHyperlinkContext : public XMLImportContext |
452 | | { |
453 | | public: |
454 | | XMLHyperlinkContext(XMLImport& rImport, const librevenge::RVNGPropertyList& rPropertyList); |
455 | | rtl::Reference<XMLImportContext> |
456 | | CreateChildContext(const OUString& rName, |
457 | | const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override; |
458 | | |
459 | | void SAL_CALL |
460 | | startElement(const OUString& rName, |
461 | | const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override; |
462 | | void SAL_CALL endElement(const OUString& rName) override; |
463 | | void SAL_CALL characters(const OUString& rChars) override; |
464 | | |
465 | | private: |
466 | | librevenge::RVNGPropertyList m_aPropertyList; |
467 | | PopupState m_ePopupState = PopupState::NONE; |
468 | | }; |
469 | | } |
470 | | |
471 | | XMLHyperlinkContext::XMLHyperlinkContext(XMLImport& rImport, |
472 | | const librevenge::RVNGPropertyList& rPropertyList) |
473 | 0 | : XMLImportContext(rImport) |
474 | 0 | { |
475 | | // Inherit properties from parent. |
476 | 0 | librevenge::RVNGPropertyList::Iter itProp(rPropertyList); |
477 | 0 | for (itProp.rewind(); itProp.next();) |
478 | 0 | m_aPropertyList.insert(itProp.key(), itProp()->clone()); |
479 | 0 | } |
480 | | |
481 | | rtl::Reference<XMLImportContext> XMLHyperlinkContext::CreateChildContext( |
482 | | const OUString& rName, const css::uno::Reference<css::xml::sax::XAttributeList>& /*xAttribs*/) |
483 | 0 | { |
484 | 0 | return CreateParagraphOrSpanChildContext(GetImport(), rName, m_aPropertyList); |
485 | 0 | } |
486 | | |
487 | | void XMLHyperlinkContext::startElement( |
488 | | const OUString& /*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) |
489 | 0 | { |
490 | 0 | librevenge::RVNGPropertyList aPropertyList; |
491 | 0 | for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i) |
492 | 0 | { |
493 | 0 | const OUString aAttributeName = xAttribs->getNameByIndex(i); |
494 | 0 | const OUString aAttributeValue = xAttribs->getValueByIndex(i); |
495 | 0 | if (aAttributeName == "text:style-name") |
496 | | // This affects the nested span's properties. |
497 | 0 | FillStyles(aAttributeValue, GetImport().GetAutomaticTextStyles(), |
498 | 0 | GetImport().GetTextStyles(), m_aPropertyList); |
499 | 0 | else |
500 | 0 | { |
501 | 0 | if (aAttributeName == "xlink:href") |
502 | 0 | { |
503 | 0 | m_ePopupState = GetImport().FillPopupData(aAttributeValue, aPropertyList); |
504 | 0 | if (m_ePopupState != PopupState::NotConsumed) |
505 | 0 | continue; |
506 | 0 | } |
507 | | |
508 | | // This affects the link's properties. |
509 | 0 | OString sName = OUStringToOString(aAttributeName, RTL_TEXTENCODING_UTF8); |
510 | 0 | OString sValue = OUStringToOString(aAttributeValue, RTL_TEXTENCODING_UTF8); |
511 | 0 | aPropertyList.insert(sName.getStr(), sValue.getStr()); |
512 | 0 | } |
513 | 0 | } |
514 | |
|
515 | 0 | if (m_ePopupState != PopupState::Ignore) |
516 | 0 | GetImport().GetGenerator().openLink(aPropertyList); |
517 | 0 | } |
518 | | |
519 | | void XMLHyperlinkContext::endElement(const OUString& /*rName*/) |
520 | 0 | { |
521 | 0 | if (m_ePopupState != PopupState::Ignore) |
522 | 0 | GetImport().GetGenerator().closeLink(); |
523 | 0 | } |
524 | | |
525 | | void XMLHyperlinkContext::characters(const OUString& rChars) |
526 | 0 | { |
527 | 0 | GetImport().GetGenerator().openSpan(m_aPropertyList); |
528 | |
|
529 | 0 | OString sCharU8 = OUStringToOString(rChars, RTL_TEXTENCODING_UTF8); |
530 | 0 | GetImport().GetGenerator().insertText(librevenge::RVNGString(sCharU8.getStr())); |
531 | |
|
532 | 0 | GetImport().GetGenerator().closeSpan(); |
533 | 0 | } |
534 | | |
535 | | XMLParaContext::XMLParaContext(XMLImport& rImport, bool bTopLevel) |
536 | 0 | : XMLImportContext(rImport) |
537 | 0 | , m_bTopLevel(bTopLevel) |
538 | 0 | { |
539 | 0 | } |
540 | | |
541 | | rtl::Reference<XMLImportContext> XMLParaContext::CreateChildContext( |
542 | | const OUString& rName, const css::uno::Reference<css::xml::sax::XAttributeList>& /*xAttribs*/) |
543 | 0 | { |
544 | 0 | if (rName == "text:a") |
545 | 0 | return new XMLHyperlinkContext(GetImport(), m_aTextPropertyList); |
546 | 0 | if (rName == "draw:a") |
547 | 0 | return new XMLTextFrameHyperlinkContext(GetImport(), m_aTextPropertyList); |
548 | 0 | if (rName == "text:ruby") |
549 | 0 | return new XMLRubyContext(GetImport(), m_aTextPropertyList); |
550 | 0 | return CreateParagraphOrSpanChildContext(GetImport(), rName, m_aTextPropertyList); |
551 | 0 | } |
552 | | |
553 | | void XMLParaContext::startElement( |
554 | | const OUString& /*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) |
555 | 0 | { |
556 | 0 | librevenge::RVNGPropertyList aPropertyList; |
557 | 0 | for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i) |
558 | 0 | { |
559 | 0 | const OUString aAttributeName = xAttribs->getNameByIndex(i); |
560 | 0 | const OUString aAttributeValue = xAttribs->getValueByIndex(i); |
561 | 0 | if (aAttributeName == "text:style-name") |
562 | 0 | { |
563 | 0 | m_aStyleName = aAttributeValue; |
564 | 0 | FillStyles(m_aStyleName, GetImport().GetAutomaticParagraphStyles(), |
565 | 0 | GetImport().GetParagraphStyles(), aPropertyList); |
566 | 0 | FillStyles(m_aStyleName, GetImport().GetAutomaticTextStyles(), |
567 | 0 | GetImport().GetTextStyles(), m_aTextPropertyList); |
568 | 0 | if (m_bTopLevel) |
569 | 0 | GetImport().HandlePageSpan(aPropertyList); |
570 | 0 | } |
571 | 0 | else |
572 | 0 | { |
573 | 0 | OString sName = OUStringToOString(aAttributeName, RTL_TEXTENCODING_UTF8); |
574 | 0 | OString sValue = OUStringToOString(aAttributeValue, RTL_TEXTENCODING_UTF8); |
575 | 0 | aPropertyList.insert(sName.getStr(), sValue.getStr()); |
576 | 0 | } |
577 | 0 | } |
578 | |
|
579 | 0 | GetImport().GetGenerator().openParagraph(aPropertyList); |
580 | 0 | } |
581 | | |
582 | | void XMLParaContext::endElement(const OUString& /*rName*/) |
583 | 0 | { |
584 | 0 | GetImport().GetGenerator().closeParagraph(); |
585 | 0 | } |
586 | | |
587 | | void XMLParaContext::characters(const OUString& rChars) |
588 | 0 | { |
589 | 0 | librevenge::RVNGPropertyList aPropertyList; |
590 | 0 | if (!m_aStyleName.isEmpty()) |
591 | 0 | FillStyles(m_aStyleName, GetImport().GetAutomaticTextStyles(), GetImport().GetTextStyles(), |
592 | 0 | aPropertyList); |
593 | 0 | GetImport().GetGenerator().openSpan(aPropertyList); |
594 | |
|
595 | 0 | OString sCharU8 = OUStringToOString(rChars, RTL_TEXTENCODING_UTF8); |
596 | 0 | GetImport().GetGenerator().insertText(librevenge::RVNGString(sCharU8.getStr())); |
597 | |
|
598 | 0 | GetImport().GetGenerator().closeSpan(); |
599 | 0 | } |
600 | | |
601 | | rtl::Reference<XMLImportContext> |
602 | | CreateParagraphOrSpanChildContext(XMLImport& rImport, const OUString& rName, |
603 | | const librevenge::RVNGPropertyList& rTextPropertyList) |
604 | 0 | { |
605 | 0 | if (rName == "text:span") |
606 | 0 | return new XMLSpanContext(rImport, rTextPropertyList); |
607 | 0 | if (rName == "text:line-break") |
608 | 0 | return new XMLLineBreakContext(rImport, rTextPropertyList); |
609 | 0 | if (rName == "text:s") |
610 | 0 | return new XMLSpaceContext(rImport, rTextPropertyList); |
611 | 0 | if (rName == "text:tab") |
612 | 0 | return new XMLTabContext(rImport, rTextPropertyList); |
613 | 0 | if (rName == "draw:frame") |
614 | 0 | return new XMLTextFrameContext(rImport); |
615 | 0 | if (rName == "text:sequence") |
616 | 0 | return new XMLTextSequenceContext(rImport, rTextPropertyList); |
617 | 0 | if (rName == "text:note") |
618 | 0 | return new XMLFootnoteImportContext(rImport); |
619 | 0 | SAL_WARN("writerperfect", "CreateParagraphOrSpanChildContext: unhandled " << rName); |
620 | 0 | return nullptr; |
621 | 0 | } |
622 | | |
623 | | void FillStyles(const OUString& rName, |
624 | | std::map<OUString, librevenge::RVNGPropertyList>& rAutomaticStyles, |
625 | | std::map<OUString, librevenge::RVNGPropertyList>& rNamedStyles, |
626 | | librevenge::RVNGPropertyList& rPropertyList) |
627 | 0 | { |
628 | 0 | FillStyle(rName, rAutomaticStyles, rAutomaticStyles, rNamedStyles, rPropertyList); |
629 | 0 | FillStyle(rName, rNamedStyles, rAutomaticStyles, rNamedStyles, rPropertyList); |
630 | 0 | } |
631 | | |
632 | | } // namespace writerperfect |
633 | | |
634 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |