Coverage Report

Created: 2026-11-06 11:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/writerperfect/source/writer/exp/xmlfmt.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 "xmlfmt.hxx"
11
12
#include "XMLBase64ImportContext.hxx"
13
#include "txtstyli.hxx"
14
#include "xmlimp.hxx"
15
16
#include <sal/log.hxx>
17
18
using namespace com::sun::star;
19
20
namespace writerperfect::exp
21
{
22
XMLStylesContext::XMLStylesContext(XMLImport& rImport, StyleType eType)
23
0
    : XMLImportContext(rImport)
24
0
    , m_rParagraphStyles(eType == StyleType_AUTOMATIC ? GetImport().GetAutomaticParagraphStyles()
25
0
                                                      : GetImport().GetParagraphStyles())
26
0
    , m_rTextStyles(eType == StyleType_AUTOMATIC ? GetImport().GetAutomaticTextStyles()
27
0
                                                 : GetImport().GetTextStyles())
28
0
    , m_rCellStyles(eType == StyleType_AUTOMATIC ? GetImport().GetAutomaticCellStyles()
29
0
                                                 : GetImport().GetCellStyles())
30
0
    , m_rColumnStyles(eType == StyleType_AUTOMATIC ? GetImport().GetAutomaticColumnStyles()
31
0
                                                   : GetImport().GetColumnStyles())
32
0
    , m_rRowStyles(eType == StyleType_AUTOMATIC ? GetImport().GetAutomaticRowStyles()
33
0
                                                : GetImport().GetRowStyles())
34
0
    , m_rTableStyles(eType == StyleType_AUTOMATIC ? GetImport().GetAutomaticTableStyles()
35
0
                                                  : GetImport().GetTableStyles())
36
0
    , m_rGraphicStyles(eType == StyleType_AUTOMATIC ? GetImport().GetAutomaticGraphicStyles()
37
0
                                                    : GetImport().GetGraphicStyles())
38
0
    , m_rListStyles(eType == StyleType_AUTOMATIC ? GetImport().GetAutomaticListStyles()
39
0
                                                 : GetImport().GetListStyles())
40
0
    , m_rPageLayouts(GetImport().GetPageLayouts())
41
0
    , m_rMasterStyles(GetImport().GetMasterStyles())
42
0
{
43
0
}
44
45
rtl::Reference<XMLImportContext> XMLStylesContext::CreateChildContext(
46
    const OUString& rName, const css::uno::Reference<css::xml::sax::XAttributeList>& /*xAttribs*/)
47
0
{
48
0
    if (rName == "style:style" || rName == "text:list-style" || rName == "style:page-layout"
49
0
        || rName == "style:master-page")
50
0
    {
51
0
        return new XMLStyleContext(GetImport(), *this);
52
0
    }
53
0
    return nullptr;
54
0
}
55
56
std::map<OUString, librevenge::RVNGPropertyList>& XMLStylesContext::GetCurrentParagraphStyles()
57
0
{
58
0
    return m_rParagraphStyles;
59
0
}
60
61
std::map<OUString, librevenge::RVNGPropertyList>& XMLStylesContext::GetCurrentTextStyles()
62
0
{
63
0
    return m_rTextStyles;
64
0
}
65
66
std::map<OUString, librevenge::RVNGPropertyList>& XMLStylesContext::GetCurrentCellStyles()
67
0
{
68
0
    return m_rCellStyles;
69
0
}
70
71
std::map<OUString, librevenge::RVNGPropertyList>& XMLStylesContext::GetCurrentColumnStyles()
72
0
{
73
0
    return m_rColumnStyles;
74
0
}
75
76
std::map<OUString, librevenge::RVNGPropertyList>& XMLStylesContext::GetCurrentRowStyles()
77
0
{
78
0
    return m_rRowStyles;
79
0
}
80
81
std::map<OUString, librevenge::RVNGPropertyList>& XMLStylesContext::GetCurrentTableStyles()
82
0
{
83
0
    return m_rTableStyles;
84
0
}
85
86
std::map<OUString, librevenge::RVNGPropertyList>& XMLStylesContext::GetCurrentGraphicStyles()
87
0
{
88
0
    return m_rGraphicStyles;
89
0
}
90
91
std::map<OUString, librevenge::RVNGPropertyList>& XMLStylesContext::GetCurrentListStyles()
92
0
{
93
0
    return m_rListStyles;
94
0
}
95
96
std::map<OUString, librevenge::RVNGPropertyList>& XMLStylesContext::GetCurrentPageLayouts()
97
0
{
98
0
    return m_rPageLayouts;
99
0
}
100
101
std::map<OUString, librevenge::RVNGPropertyList>& XMLStylesContext::GetCurrentMasterStyles()
102
0
{
103
0
    return m_rMasterStyles;
104
0
}
105
106
namespace
107
{
108
/// Handler for <style:font-face>.
109
class XMLFontFaceContext : public XMLImportContext
110
{
111
public:
112
    XMLFontFaceContext(XMLImport& rImport);
113
    void SAL_CALL
114
    startElement(const OUString& rName,
115
                 const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
116
117
    rtl::Reference<XMLImportContext>
118
    CreateChildContext(const OUString& rName,
119
                       const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
120
121
0
    OUString const& GetName() const { return maName; }
122
123
private:
124
    OUString maName;
125
};
126
127
/// Handler for <svg:font-face-src>.
128
class XMLFontFaceSrcContext : public XMLImportContext
129
{
130
public:
131
    XMLFontFaceSrcContext(XMLImport& rImport, XMLFontFaceContext& rFontFace);
132
133
    rtl::Reference<XMLImportContext>
134
    CreateChildContext(const OUString& rName,
135
                       const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
136
137
private:
138
    XMLFontFaceContext& mrFontFace;
139
};
140
141
/// Handler for <svg:font-face-uri>.
142
class XMLFontFaceUriContext : public XMLImportContext
143
{
144
public:
145
    XMLFontFaceUriContext(XMLImport& rImport, XMLFontFaceContext const& rFontFace);
146
    void SAL_CALL
147
    startElement(const OUString& rName,
148
                 const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
149
    void SAL_CALL endElement(const OUString& rName) override;
150
151
    rtl::Reference<XMLImportContext>
152
    CreateChildContext(const OUString& rName,
153
                       const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
154
155
0
    librevenge::RVNGPropertyList& GetPropertyList() { return maPropertyList; }
156
157
private:
158
    librevenge::RVNGPropertyList maPropertyList;
159
    rtl::Reference<XMLBase64ImportContext> mxBinaryData;
160
};
161
162
/// Handler for <svg:font-face-format>.
163
class XMLFontFaceFormatContext : public XMLImportContext
164
{
165
public:
166
    XMLFontFaceFormatContext(XMLImport& rImport, XMLFontFaceUriContext& rFontFaceUri);
167
    void SAL_CALL
168
    startElement(const OUString& rName,
169
                 const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
170
171
private:
172
    XMLFontFaceUriContext& mrFontFaceUri;
173
};
174
}
175
176
XMLFontFaceFormatContext::XMLFontFaceFormatContext(XMLImport& rImport,
177
                                                   XMLFontFaceUriContext& rFontFaceUri)
178
0
    : XMLImportContext(rImport)
179
0
    , mrFontFaceUri(rFontFaceUri)
180
0
{
181
0
}
182
183
void XMLFontFaceFormatContext::startElement(
184
    const OUString& /*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs)
185
0
{
186
0
    for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
187
0
    {
188
0
        const OUString aAttributeName = xAttribs->getNameByIndex(i);
189
0
        const OUString aAttributeValue = xAttribs->getValueByIndex(i);
190
0
        if (aAttributeName == "svg:string")
191
0
        {
192
0
            OString aAttributeValueU8 = OUStringToOString(aAttributeValue, RTL_TEXTENCODING_UTF8);
193
0
            mrFontFaceUri.GetPropertyList().insert("librevenge:mime-type",
194
0
                                                   aAttributeValueU8.getStr());
195
0
        }
196
0
    }
197
0
}
198
199
XMLFontFaceUriContext::XMLFontFaceUriContext(XMLImport& rImport,
200
                                             XMLFontFaceContext const& rFontFace)
201
0
    : XMLImportContext(rImport)
202
0
{
203
0
    OString aNameU8 = OUStringToOString(rFontFace.GetName(), RTL_TEXTENCODING_UTF8);
204
0
    maPropertyList.insert("librevenge:name", aNameU8.getStr());
205
0
}
206
207
void XMLFontFaceUriContext::startElement(
208
    const OUString& /*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs)
209
0
{
210
0
    for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
211
0
    {
212
0
        const OUString aAttributeName = xAttribs->getNameByIndex(i);
213
0
        const OUString aAttributeValue = xAttribs->getValueByIndex(i);
214
0
        if (aAttributeName == "loext:font-style")
215
0
        {
216
0
            OString aAttributeValueU8 = OUStringToOString(aAttributeValue, RTL_TEXTENCODING_UTF8);
217
0
            maPropertyList.insert("librevenge:font-style", aAttributeValueU8.getStr());
218
0
        }
219
0
        else if (aAttributeName == "loext:font-weight")
220
0
        {
221
0
            OString aAttributeValueU8 = OUStringToOString(aAttributeValue, RTL_TEXTENCODING_UTF8);
222
0
            maPropertyList.insert("librevenge:font-weight", aAttributeValueU8.getStr());
223
0
        }
224
0
    }
225
0
}
226
227
void XMLFontFaceUriContext::endElement(const OUString& /*rName*/)
228
0
{
229
0
    if (mxBinaryData.is())
230
0
        maPropertyList.insert("office:binary-data", mxBinaryData->getBinaryData());
231
0
    GetImport().GetGenerator().defineEmbeddedFont(maPropertyList);
232
0
}
233
234
rtl::Reference<XMLImportContext> XMLFontFaceUriContext::CreateChildContext(
235
    const OUString& rName, const css::uno::Reference<css::xml::sax::XAttributeList>& /*xAttribs*/)
236
0
{
237
0
    if (rName == "office:binary-data")
238
0
    {
239
0
        mxBinaryData = new XMLBase64ImportContext(GetImport());
240
0
        return mxBinaryData;
241
0
    }
242
0
    if (rName == "svg:font-face-format")
243
0
        return new XMLFontFaceFormatContext(GetImport(), *this);
244
245
0
    SAL_WARN("writerperfect", "XMLFontFaceUriContext::CreateChildContext: unhandled " << rName);
246
0
    return nullptr;
247
0
}
248
249
XMLFontFaceSrcContext::XMLFontFaceSrcContext(XMLImport& rImport, XMLFontFaceContext& rFontFace)
250
0
    : XMLImportContext(rImport)
251
0
    , mrFontFace(rFontFace)
252
0
{
253
0
}
254
255
rtl::Reference<XMLImportContext> XMLFontFaceSrcContext::CreateChildContext(
256
    const OUString& rName, const css::uno::Reference<css::xml::sax::XAttributeList>& /*xAttribs*/)
257
0
{
258
0
    if (rName == "svg:font-face-uri")
259
0
        return new XMLFontFaceUriContext(GetImport(), mrFontFace);
260
0
    SAL_WARN("writerperfect", "XMLFontFaceSrcContext::CreateChildContext: unhandled " << rName);
261
0
    return nullptr;
262
0
}
263
264
XMLFontFaceContext::XMLFontFaceContext(XMLImport& rImport)
265
0
    : XMLImportContext(rImport)
266
0
{
267
0
}
268
269
void XMLFontFaceContext::startElement(
270
    const OUString& /*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs)
271
0
{
272
0
    for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
273
0
    {
274
0
        const OUString aAttributeName = xAttribs->getNameByIndex(i);
275
0
        const OUString aAttributeValue = xAttribs->getValueByIndex(i);
276
0
        if (aAttributeName == "style:name")
277
0
            maName = aAttributeValue;
278
0
    }
279
0
}
280
281
rtl::Reference<XMLImportContext> XMLFontFaceContext::CreateChildContext(
282
    const OUString& rName, const css::uno::Reference<css::xml::sax::XAttributeList>& /*xAttribs*/)
283
0
{
284
0
    if (rName == "svg:font-face-src")
285
0
        return new XMLFontFaceSrcContext(GetImport(), *this);
286
0
    SAL_WARN("writerperfect", "XMLFontFaceContext::CreateChildContext: unhandled " << rName);
287
0
    return nullptr;
288
0
}
289
290
XMLFontFaceDeclsContext::XMLFontFaceDeclsContext(XMLImport& rImport)
291
0
    : XMLImportContext(rImport)
292
0
{
293
0
}
294
295
rtl::Reference<XMLImportContext> XMLFontFaceDeclsContext::CreateChildContext(
296
    const OUString& rName, const css::uno::Reference<css::xml::sax::XAttributeList>& /*xAttribs*/)
297
0
{
298
0
    if (rName == "style:font-face")
299
0
        return new XMLFontFaceContext(GetImport());
300
0
    return nullptr;
301
0
}
302
303
} // namespace writerperfect::exp
304
305
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */