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 <oox/mathml/import.hxx>
12 #include <oox/mathml/importutils.hxx>
13 #include <oox/core/contexthandler.hxx>
14 #include <oox/token/namespaces.hxx>
15 #include <oox/token/tokens.hxx>
17 #include <drawingml/textparagraph.hxx>
20 using namespace ::com::sun::star
;
25 FormulaImportBase::FormulaImportBase()
29 namespace formulaimport
{
31 class LazyMathBufferingContext
: public core::ContextHandler
34 XmlStreamBuilder
& m_rBuilder
;
35 std::vector
<sal_Int32
> m_OpenElements
;
38 LazyMathBufferingContext(core::ContextHandler
const& rParent
,
39 drawingml::TextParagraph
& rPara
);
41 // com.sun.star.xml.sax.XFastContextHandler interface ---------------------
43 virtual void SAL_CALL
startFastElement(::sal_Int32 Element
, const uno::Reference
<xml::sax::XFastAttributeList
>& xAttribs
) override
;
44 virtual void SAL_CALL
endFastElement(::sal_Int32 Element
) override
;
45 virtual uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
createFastChildContext(::sal_Int32 Element
, const uno::Reference
<xml::sax::XFastAttributeList
>& xAttribs
) override
;
46 virtual void SAL_CALL
characters(const OUString
& rChars
) override
;
50 LazyMathBufferingContext::LazyMathBufferingContext(
51 core::ContextHandler
const& rParent
, drawingml::TextParagraph
& rPara
)
52 : core::ContextHandler(rParent
)
53 , m_rBuilder(rPara
.GetMathXml())
57 void SAL_CALL
LazyMathBufferingContext::startFastElement(
58 sal_Int32
const nElement
,
59 uno::Reference
<xml::sax::XFastAttributeList
> const& xAttrs
)
61 if (0 < m_OpenElements
.size()) // ignore a14:m
62 { // ignore outer oMathPara
63 if (1 != m_OpenElements
.size() || OOX_TOKEN(officeMath
, oMathPara
) != nElement
)
65 m_rBuilder
.appendOpeningTag(nElement
, xAttrs
);
68 m_OpenElements
.push_back(nElement
);
71 void SAL_CALL
LazyMathBufferingContext::endFastElement(sal_Int32
const nElement
)
73 m_OpenElements
.pop_back();
74 if (0 < m_OpenElements
.size()) // ignore a14:m
75 { // ignore outer oMathPara
76 if (1 != m_OpenElements
.size() || OOX_TOKEN(officeMath
, oMathPara
) != nElement
)
78 m_rBuilder
.appendClosingTag(nElement
);
83 uno::Reference
<xml::sax::XFastContextHandler
> SAL_CALL
84 LazyMathBufferingContext::createFastChildContext(sal_Int32
const,
85 uno::Reference
<xml::sax::XFastAttributeList
> const&)
90 void SAL_CALL
LazyMathBufferingContext::characters(OUString
const& rChars
)
92 if (0 < m_OpenElements
.size()) // ignore a14:m
94 if (m_OpenElements
.back() == OOX_TOKEN(officeMath
, t
))
96 m_rBuilder
.appendCharacters(rChars
);
101 } // namespace formulaimport
103 rtl::Reference
<core::ContextHandler
> CreateLazyMathBufferingContext(
104 core::ContextHandler
const& rParent
, drawingml::TextParagraph
& rPara
)
106 return new formulaimport::LazyMathBufferingContext(rParent
, rPara
);
111 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */