Coverage Report

Created: 2025-12-08 09:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/oox/source/mathml/imexport.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 <oox/mathml/imexport.hxx>
11
12
#include <oox/mathml/importutils.hxx>
13
#include <oox/core/contexthandler.hxx>
14
#include <oox/token/namespaces.hxx>
15
16
#include <drawingml/textparagraph.hxx>
17
18
19
using namespace ::com::sun::star;
20
21
namespace oox
22
{
23
24
FormulaImExportBase::FormulaImExportBase()
25
27.4k
{
26
27.4k
}
27
28
namespace formulaimport {
29
30
namespace {
31
32
class LazyMathBufferingContext : public core::ContextHandler
33
{
34
private:
35
    XmlStreamBuilder & m_rBuilder;
36
    std::vector<sal_Int32> m_OpenElements;
37
38
public:
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
53
LazyMathBufferingContext::LazyMathBufferingContext(
54
        core::ContextHandler const& rParent, drawingml::TextParagraph & rPara)
55
0
    : core::ContextHandler(rParent)
56
0
    , m_rBuilder(rPara.GetMathXml())
57
0
{
58
0
}
59
60
void SAL_CALL LazyMathBufferingContext::startFastElement(
61
        sal_Int32 const nElement,
62
        uno::Reference<xml::sax::XFastAttributeList> const& xAttrs)
63
0
{
64
0
    if (0 < m_OpenElements.size()) // ignore a14:m
65
0
    {   // ignore outer oMathPara
66
0
        if (1 != m_OpenElements.size() || OOX_TOKEN(officeMath, oMathPara) != nElement)
67
0
        {
68
0
            m_rBuilder.appendOpeningTag(nElement, xAttrs);
69
0
        }
70
0
    }
71
0
    m_OpenElements.push_back(nElement);
72
0
}
73
74
void SAL_CALL LazyMathBufferingContext::endFastElement(sal_Int32 const nElement)
75
0
{
76
0
    m_OpenElements.pop_back();
77
0
    if (0 < m_OpenElements.size()) // ignore a14:m
78
0
    {   // ignore outer oMathPara
79
0
        if (1 != m_OpenElements.size() || OOX_TOKEN(officeMath, oMathPara) != nElement)
80
0
        {
81
0
            m_rBuilder.appendClosingTag(nElement);
82
0
        }
83
0
    }
84
0
}
85
86
uno::Reference<xml::sax::XFastContextHandler> SAL_CALL
87
LazyMathBufferingContext::createFastChildContext(sal_Int32 const,
88
        uno::Reference<xml::sax::XFastAttributeList> const&)
89
0
{
90
0
    return this;
91
0
}
92
93
void SAL_CALL LazyMathBufferingContext::characters(OUString const& rChars)
94
0
{
95
0
    if (0 < m_OpenElements.size()) // ignore a14:m
96
0
    {
97
0
        if (m_OpenElements.back() == OOX_TOKEN(officeMath, t))
98
0
        {
99
0
            m_rBuilder.appendCharacters(rChars);
100
0
        }
101
0
    }
102
0
}
103
104
} // namespace oox::formulaimport
105
106
rtl::Reference<core::ContextHandler> CreateLazyMathBufferingContext(
107
        core::ContextHandler const& rParent, drawingml::TextParagraph & rPara)
108
0
{
109
0
    return new formulaimport::LazyMathBufferingContext(rParent, rPara);
110
0
}
111
112
} // namespace oox
113
114
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */