Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/writerperfect/source/writer/exp/XMLTextFrameContext.cxx
Line
Count
Source (jump to first uncovered line)
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 "XMLTextFrameContext.hxx"
11
12
#include "XMLBase64ImportContext.hxx"
13
#include "txtparai.hxx"
14
#include "xmlimp.hxx"
15
#include "xmltext.hxx"
16
17
#include <sal/log.hxx>
18
19
using namespace com::sun::star;
20
21
namespace writerperfect::exp
22
{
23
namespace
24
{
25
/// Handler for <draw:text-box>.
26
class XMLTextBoxContext : public XMLImportContext
27
{
28
public:
29
    XMLTextBoxContext(XMLImport& rImport);
30
31
    rtl::Reference<XMLImportContext>
32
    CreateChildContext(const OUString& rName,
33
                       const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
34
35
    void SAL_CALL
36
    startElement(const OUString& rName,
37
                 const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
38
    void SAL_CALL endElement(const OUString& rName) override;
39
};
40
}
41
42
XMLTextBoxContext::XMLTextBoxContext(XMLImport& rImport)
43
0
    : XMLImportContext(rImport)
44
0
{
45
0
}
46
47
rtl::Reference<XMLImportContext> XMLTextBoxContext::CreateChildContext(
48
    const OUString& rName, const css::uno::Reference<css::xml::sax::XAttributeList>& /*xAttribs*/)
49
0
{
50
0
    return CreateTextChildContext(GetImport(), rName);
51
0
}
52
53
void XMLTextBoxContext::startElement(
54
    const OUString& /*rName*/,
55
    const css::uno::Reference<css::xml::sax::XAttributeList>& /*xAttribs*/)
56
0
{
57
0
    GetImport().GetGenerator().openTextBox(librevenge::RVNGPropertyList());
58
0
}
59
60
void XMLTextBoxContext::endElement(const OUString& /*rName*/)
61
0
{
62
0
    GetImport().GetGenerator().closeTextBox();
63
0
}
64
65
namespace
66
{
67
/// Handler for <draw:image>.
68
class XMLTextImageContext : public XMLImportContext
69
{
70
public:
71
    XMLTextImageContext(XMLImport& rImport);
72
73
    rtl::Reference<XMLImportContext>
74
    CreateChildContext(const OUString& rName,
75
                       const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
76
77
    void SAL_CALL
78
    startElement(const OUString& rName,
79
                 const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
80
    void SAL_CALL endElement(const OUString& rName) override;
81
82
private:
83
    OString m_aMimeType;
84
    rtl::Reference<XMLBase64ImportContext> m_xBinaryData;
85
};
86
}
87
88
XMLTextImageContext::XMLTextImageContext(XMLImport& rImport)
89
0
    : XMLImportContext(rImport)
90
0
{
91
0
}
92
93
rtl::Reference<XMLImportContext> XMLTextImageContext::CreateChildContext(
94
    const OUString& rName, const css::uno::Reference<css::xml::sax::XAttributeList>& /*xAttribs*/)
95
0
{
96
0
    if (rName == "office:binary-data")
97
0
    {
98
0
        m_xBinaryData = new XMLBase64ImportContext(GetImport());
99
0
        return m_xBinaryData;
100
0
    }
101
0
    return nullptr;
102
0
}
103
104
void XMLTextImageContext::startElement(
105
    const OUString& /*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs)
106
0
{
107
0
    for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
108
0
    {
109
0
        const OUString aAttributeName = xAttribs->getNameByIndex(i);
110
0
        if (aAttributeName == "loext:mime-type" || aAttributeName == "draw:mime-type")
111
0
            m_aMimeType = OUStringToOString(xAttribs->getValueByIndex(i), RTL_TEXTENCODING_UTF8);
112
0
    }
113
0
}
114
115
void XMLTextImageContext::endElement(const OUString& /*rName*/)
116
0
{
117
0
    librevenge::RVNGPropertyList aPropertyList;
118
119
0
    aPropertyList.insert("librevenge:mime-type", m_aMimeType.getStr());
120
0
    if (m_xBinaryData.is())
121
0
        aPropertyList.insert("office:binary-data", m_xBinaryData->getBinaryData());
122
123
0
    GetImport().GetGenerator().insertBinaryObject(aPropertyList);
124
0
}
125
126
XMLTextFrameContext::XMLTextFrameContext(XMLImport& rImport)
127
0
    : XMLImportContext(rImport)
128
0
{
129
0
}
130
131
rtl::Reference<XMLImportContext> XMLTextFrameContext::CreateChildContext(
132
    const OUString& rName, const css::uno::Reference<css::xml::sax::XAttributeList>& /*xAttribs*/)
133
0
{
134
0
    if (rName == "draw:image")
135
0
        return new XMLTextImageContext(GetImport());
136
0
    if (rName == "draw:text-box")
137
0
        return new XMLTextBoxContext(GetImport());
138
0
    SAL_WARN("writerperfect", "XMLTextFrameContext::CreateChildContext: unhandled " << rName);
139
0
    return nullptr;
140
0
}
141
142
void XMLTextFrameContext::startElement(
143
    const OUString& /*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs)
144
0
{
145
0
    librevenge::RVNGPropertyList aPropertyList;
146
0
    for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
147
0
    {
148
0
        const OUString aAttributeName = xAttribs->getNameByIndex(i);
149
0
        const OUString aAttributeValue = xAttribs->getValueByIndex(i);
150
151
0
        if (aAttributeName == "draw:style-name")
152
0
            FillStyles(aAttributeValue, GetImport().GetAutomaticGraphicStyles(),
153
0
                       GetImport().GetGraphicStyles(), aPropertyList);
154
0
        else
155
0
        {
156
0
            OString sName = OUStringToOString(aAttributeName, RTL_TEXTENCODING_UTF8);
157
0
            OString sValue = OUStringToOString(aAttributeValue, RTL_TEXTENCODING_UTF8);
158
0
            aPropertyList.insert(sName.getStr(), sValue.getStr());
159
0
        }
160
0
    }
161
0
    GetImport().GetGenerator().openFrame(aPropertyList);
162
0
}
163
164
void XMLTextFrameContext::endElement(const OUString& /*rName*/)
165
0
{
166
0
    GetImport().GetGenerator().closeFrame();
167
0
}
168
169
} // namespace writerperfect::exp
170
171
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */