LibreOffice Module oox (master) 1
import.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 <oox/mathml/import.hxx>
11
14#include <oox/token/namespaces.hxx>
15
17
18
19using namespace ::com::sun::star;
20
21namespace oox
22{
23
25{
26}
27
28namespace formulaimport {
29
30namespace {
31
32class LazyMathBufferingContext : public core::ContextHandler
33{
34private:
35 XmlStreamBuilder & m_rBuilder;
36 std::vector<sal_Int32> m_OpenElements;
37
38public:
39 LazyMathBufferingContext(core::ContextHandler const& rParent,
40 drawingml::TextParagraph & rPara);
41
42 // com.sun.star.xml.sax.XFastContextHandler interface ---------------------
43
44 virtual void SAL_CALL startFastElement(::sal_Int32 Element, const uno::Reference<xml::sax::XFastAttributeList>& xAttribs) override;
45 virtual void SAL_CALL endFastElement(::sal_Int32 Element) override;
46 virtual uno::Reference< xml::sax::XFastContextHandler> SAL_CALL createFastChildContext(::sal_Int32 Element, const uno::Reference<xml::sax::XFastAttributeList >& xAttribs) override;
47 virtual void SAL_CALL characters(const OUString& rChars) override;
48
49};
50
51}
52
53LazyMathBufferingContext::LazyMathBufferingContext(
54 core::ContextHandler const& rParent, drawingml::TextParagraph & rPara)
55 : core::ContextHandler(rParent)
56 , m_rBuilder(rPara.GetMathXml())
57{
58}
59
60void SAL_CALL LazyMathBufferingContext::startFastElement(
61 sal_Int32 const nElement,
62 uno::Reference<xml::sax::XFastAttributeList> const& xAttrs)
63{
64 if (0 < m_OpenElements.size()) // ignore a14:m
65 { // ignore outer oMathPara
66 if (1 != m_OpenElements.size() || OOX_TOKEN(officeMath, oMathPara) != nElement)
67 {
68 m_rBuilder.appendOpeningTag(nElement, xAttrs);
69 }
70 }
71 m_OpenElements.push_back(nElement);
72}
73
74void SAL_CALL LazyMathBufferingContext::endFastElement(sal_Int32 const nElement)
75{
76 m_OpenElements.pop_back();
77 if (0 < m_OpenElements.size()) // ignore a14:m
78 { // ignore outer oMathPara
79 if (1 != m_OpenElements.size() || OOX_TOKEN(officeMath, oMathPara) != nElement)
80 {
81 m_rBuilder.appendClosingTag(nElement);
82 }
83 }
84}
85
86uno::Reference<xml::sax::XFastContextHandler> SAL_CALL
87LazyMathBufferingContext::createFastChildContext(sal_Int32 const,
88 uno::Reference<xml::sax::XFastAttributeList> const&)
89{
90 return this;
91}
92
93void SAL_CALL LazyMathBufferingContext::characters(OUString const& rChars)
94{
95 if (0 < m_OpenElements.size()) // ignore a14:m
96 {
97 if (m_OpenElements.back() == OOX_TOKEN(officeMath, t))
98 {
99 m_rBuilder.appendCharacters(rChars);
100 }
101 }
102}
103
104} // namespace oox::formulaimport
105
107 core::ContextHandler const& rParent, drawingml::TextParagraph & rPara)
108{
109 return new formulaimport::LazyMathBufferingContext(rParent, rPara);
110}
111
112} // namespace oox
113
114/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XmlStreamBuilder & m_rBuilder
Definition: import.cxx:35
std::vector< sal_Int32 > m_OpenElements
Definition: import.cxx:36
rtl::Reference< core::ContextHandler > CreateLazyMathBufferingContext(core::ContextHandler const &rParent, drawingml::TextParagraph &rPara)
Definition: import.cxx:106