Coverage Report

Created: 2026-03-31 11:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/writerperfect/source/writer/exp/txtstyli.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 "txtstyli.hxx"
11
12
#include "xmlfmt.hxx"
13
14
using namespace com::sun::star;
15
16
namespace writerperfect::exp
17
{
18
namespace
19
{
20
/// Handler for <style:paragraph-properties>.
21
class XMLParagraphPropertiesContext : public XMLImportContext
22
{
23
public:
24
    XMLParagraphPropertiesContext(XMLImport& rImport, XMLStyleContext& rStyle);
25
26
    void SAL_CALL
27
    startElement(const OUString& rName,
28
                 const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
29
30
private:
31
    XMLStyleContext& mrStyle;
32
};
33
}
34
35
XMLParagraphPropertiesContext::XMLParagraphPropertiesContext(XMLImport& rImport,
36
                                                             XMLStyleContext& rStyle)
37
0
    : XMLImportContext(rImport)
38
0
    , mrStyle(rStyle)
39
0
{
40
0
}
41
42
void XMLParagraphPropertiesContext::startElement(
43
    const OUString& /*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs)
44
0
{
45
0
    for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
46
0
    {
47
0
        OString sName = OUStringToOString(xAttribs->getNameByIndex(i), RTL_TEXTENCODING_UTF8);
48
0
        OString sValue = OUStringToOString(xAttribs->getValueByIndex(i), RTL_TEXTENCODING_UTF8);
49
0
        mrStyle.GetParagraphPropertyList().insert(sName.getStr(), sValue.getStr());
50
0
    }
51
0
}
52
53
namespace
54
{
55
/// Handler for <style:text-properties>.
56
class XMLTextPropertiesContext : public XMLImportContext
57
{
58
public:
59
    XMLTextPropertiesContext(XMLImport& rImport, XMLStyleContext& rStyle);
60
61
    void SAL_CALL
62
    startElement(const OUString& rName,
63
                 const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
64
65
private:
66
    XMLStyleContext& mrStyle;
67
};
68
}
69
70
XMLTextPropertiesContext::XMLTextPropertiesContext(XMLImport& rImport, XMLStyleContext& rStyle)
71
0
    : XMLImportContext(rImport)
72
0
    , mrStyle(rStyle)
73
0
{
74
0
}
75
76
void XMLTextPropertiesContext::startElement(
77
    const OUString& /*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs)
78
0
{
79
0
    for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
80
0
    {
81
0
        OString sName = OUStringToOString(xAttribs->getNameByIndex(i), RTL_TEXTENCODING_UTF8);
82
0
        OString sValue = OUStringToOString(xAttribs->getValueByIndex(i), RTL_TEXTENCODING_UTF8);
83
0
        mrStyle.GetTextPropertyList().insert(sName.getStr(), sValue.getStr());
84
0
    }
85
0
}
86
87
namespace
88
{
89
/// Handler for <style:graphic-properties>.
90
class XMLGraphicPropertiesContext : public XMLImportContext
91
{
92
public:
93
    XMLGraphicPropertiesContext(XMLImport& rImport, XMLStyleContext& rStyle);
94
95
    void SAL_CALL
96
    startElement(const OUString& rName,
97
                 const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
98
99
private:
100
    XMLStyleContext& mrStyle;
101
};
102
}
103
104
XMLGraphicPropertiesContext::XMLGraphicPropertiesContext(XMLImport& rImport,
105
                                                         XMLStyleContext& rStyle)
106
0
    : XMLImportContext(rImport)
107
0
    , mrStyle(rStyle)
108
0
{
109
0
}
110
111
void XMLGraphicPropertiesContext::startElement(
112
    const OUString& /*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs)
113
0
{
114
0
    for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
115
0
    {
116
0
        OString sName = OUStringToOString(xAttribs->getNameByIndex(i), RTL_TEXTENCODING_UTF8);
117
0
        OString sValue = OUStringToOString(xAttribs->getValueByIndex(i), RTL_TEXTENCODING_UTF8);
118
0
        mrStyle.GetGraphicPropertyList().insert(sName.getStr(), sValue.getStr());
119
0
    }
120
0
}
121
122
namespace
123
{
124
/// Handler for <style:page-layout-properties>.
125
class XMLPageLayoutPropertiesContext : public XMLImportContext
126
{
127
public:
128
    XMLPageLayoutPropertiesContext(XMLImport& rImport, XMLStyleContext& rStyle);
129
130
    void SAL_CALL
131
    startElement(const OUString& rName,
132
                 const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
133
134
private:
135
    XMLStyleContext& mrStyle;
136
};
137
}
138
139
XMLPageLayoutPropertiesContext::XMLPageLayoutPropertiesContext(XMLImport& rImport,
140
                                                               XMLStyleContext& rStyle)
141
0
    : XMLImportContext(rImport)
142
0
    , mrStyle(rStyle)
143
0
{
144
0
}
145
146
void XMLPageLayoutPropertiesContext::startElement(
147
    const OUString& /*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs)
148
0
{
149
0
    for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
150
0
    {
151
0
        OString sName = OUStringToOString(xAttribs->getNameByIndex(i), RTL_TEXTENCODING_UTF8);
152
0
        OString sValue = OUStringToOString(xAttribs->getValueByIndex(i), RTL_TEXTENCODING_UTF8);
153
        // We only care about writing-mode for now.
154
0
        if (sName != "style:writing-mode")
155
0
            continue;
156
157
0
        mrStyle.GetPageLayoutPropertyList().insert(sName.getStr(), sValue.getStr());
158
0
    }
159
0
}
160
161
namespace
162
{
163
/// Handler for <style:table-properties>.
164
class XMLTablePropertiesContext : public XMLImportContext
165
{
166
public:
167
    XMLTablePropertiesContext(XMLImport& rImport, XMLStyleContext& rStyle);
168
169
    void SAL_CALL
170
    startElement(const OUString& rName,
171
                 const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
172
173
private:
174
    XMLStyleContext& mrStyle;
175
};
176
}
177
178
XMLTablePropertiesContext::XMLTablePropertiesContext(XMLImport& rImport, XMLStyleContext& rStyle)
179
0
    : XMLImportContext(rImport)
180
0
    , mrStyle(rStyle)
181
0
{
182
0
}
183
184
void XMLTablePropertiesContext::startElement(
185
    const OUString& /*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs)
186
0
{
187
0
    for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
188
0
    {
189
0
        OString sName = OUStringToOString(xAttribs->getNameByIndex(i), RTL_TEXTENCODING_UTF8);
190
0
        OString sValue = OUStringToOString(xAttribs->getValueByIndex(i), RTL_TEXTENCODING_UTF8);
191
0
        if (sName == "style:rel-width")
192
            // Make sure this is passed through as a string, and not parsed as a double.
193
0
            mrStyle.GetTablePropertyList().insert(
194
0
                sName.getStr(), librevenge::RVNGPropertyFactory::newStringProp(sValue.getStr()));
195
0
        else
196
0
            mrStyle.GetTablePropertyList().insert(sName.getStr(), sValue.getStr());
197
0
    }
198
0
}
199
200
namespace
201
{
202
/// Handler for <style:table-row-properties>.
203
class XMLTableRowPropertiesContext : public XMLImportContext
204
{
205
public:
206
    XMLTableRowPropertiesContext(XMLImport& rImport, XMLStyleContext& rStyle);
207
208
    void SAL_CALL
209
    startElement(const OUString& rName,
210
                 const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
211
212
private:
213
    XMLStyleContext& mrStyle;
214
};
215
}
216
217
XMLTableRowPropertiesContext::XMLTableRowPropertiesContext(XMLImport& rImport,
218
                                                           XMLStyleContext& rStyle)
219
0
    : XMLImportContext(rImport)
220
0
    , mrStyle(rStyle)
221
0
{
222
0
}
223
224
void XMLTableRowPropertiesContext::startElement(
225
    const OUString& /*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs)
226
0
{
227
0
    for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
228
0
    {
229
0
        OString sName = OUStringToOString(xAttribs->getNameByIndex(i), RTL_TEXTENCODING_UTF8);
230
0
        OString sValue = OUStringToOString(xAttribs->getValueByIndex(i), RTL_TEXTENCODING_UTF8);
231
0
        mrStyle.GetRowPropertyList().insert(sName.getStr(), sValue.getStr());
232
0
    }
233
0
}
234
235
namespace
236
{
237
/// Handler for <style:table-column-properties>.
238
class XMLTableColumnPropertiesContext : public XMLImportContext
239
{
240
public:
241
    XMLTableColumnPropertiesContext(XMLImport& rImport, XMLStyleContext& rStyle);
242
243
    void SAL_CALL
244
    startElement(const OUString& rName,
245
                 const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
246
247
private:
248
    XMLStyleContext& mrStyle;
249
};
250
}
251
252
XMLTableColumnPropertiesContext::XMLTableColumnPropertiesContext(XMLImport& rImport,
253
                                                                 XMLStyleContext& rStyle)
254
0
    : XMLImportContext(rImport)
255
0
    , mrStyle(rStyle)
256
0
{
257
0
}
258
259
void XMLTableColumnPropertiesContext::startElement(
260
    const OUString& /*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs)
261
0
{
262
0
    for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
263
0
    {
264
0
        OString sName = OUStringToOString(xAttribs->getNameByIndex(i), RTL_TEXTENCODING_UTF8);
265
0
        OString sValue = OUStringToOString(xAttribs->getValueByIndex(i), RTL_TEXTENCODING_UTF8);
266
0
        mrStyle.GetColumnPropertyList().insert(sName.getStr(), sValue.getStr());
267
0
    }
268
0
}
269
270
namespace
271
{
272
/// Handler for <style:table-cell-properties>.
273
class XMLTableCellPropertiesContext : public XMLImportContext
274
{
275
public:
276
    XMLTableCellPropertiesContext(XMLImport& rImport, XMLStyleContext& rStyle);
277
278
    void SAL_CALL
279
    startElement(const OUString& rName,
280
                 const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
281
282
private:
283
    XMLStyleContext& mrStyle;
284
};
285
}
286
287
XMLTableCellPropertiesContext::XMLTableCellPropertiesContext(XMLImport& rImport,
288
                                                             XMLStyleContext& rStyle)
289
0
    : XMLImportContext(rImport)
290
0
    , mrStyle(rStyle)
291
0
{
292
0
}
293
294
void XMLTableCellPropertiesContext::startElement(
295
    const OUString& /*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs)
296
0
{
297
0
    for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
298
0
    {
299
0
        OString sName = OUStringToOString(xAttribs->getNameByIndex(i), RTL_TEXTENCODING_UTF8);
300
0
        OString sValue = OUStringToOString(xAttribs->getValueByIndex(i), RTL_TEXTENCODING_UTF8);
301
0
        mrStyle.GetCellPropertyList().insert(sName.getStr(), sValue.getStr());
302
0
    }
303
0
}
304
305
XMLStyleContext::XMLStyleContext(XMLImport& rImport, XMLStylesContext& rStyles)
306
0
    : XMLImportContext(rImport)
307
0
    , m_rStyles(rStyles)
308
0
{
309
0
}
310
311
rtl::Reference<XMLImportContext> XMLStyleContext::CreateChildContext(
312
    const OUString& rName, const css::uno::Reference<css::xml::sax::XAttributeList>& /*xAttribs*/)
313
0
{
314
0
    if (rName == "style:paragraph-properties")
315
0
        return new XMLParagraphPropertiesContext(GetImport(), *this);
316
0
    if (rName == "style:text-properties")
317
0
        return new XMLTextPropertiesContext(GetImport(), *this);
318
0
    if (rName == "style:table-cell-properties")
319
0
        return new XMLTableCellPropertiesContext(GetImport(), *this);
320
0
    if (rName == "style:table-column-properties")
321
0
        return new XMLTableColumnPropertiesContext(GetImport(), *this);
322
0
    if (rName == "style:table-row-properties")
323
0
        return new XMLTableRowPropertiesContext(GetImport(), *this);
324
0
    if (rName == "style:table-properties")
325
0
        return new XMLTablePropertiesContext(GetImport(), *this);
326
0
    if (rName == "style:graphic-properties")
327
0
        return new XMLGraphicPropertiesContext(GetImport(), *this);
328
0
    if (rName == "style:page-layout-properties")
329
0
        return new XMLPageLayoutPropertiesContext(GetImport(), *this);
330
0
    return nullptr;
331
0
}
332
333
void XMLStyleContext::startElement(
334
    const OUString& /*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs)
335
0
{
336
0
    for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
337
0
    {
338
0
        const OUString aAttributeName = xAttribs->getNameByIndex(i);
339
0
        const OUString aAttributeValue = xAttribs->getValueByIndex(i);
340
0
        if (aAttributeName == "style:name")
341
0
            m_aName = aAttributeValue;
342
0
        else if (aAttributeName == "style:family")
343
0
            m_aFamily = aAttributeValue;
344
345
        // Remember properties of the style itself, e.g. parent name.
346
0
        OString sName = OUStringToOString(aAttributeName, RTL_TEXTENCODING_UTF8);
347
0
        OString sValue = OUStringToOString(aAttributeValue, RTL_TEXTENCODING_UTF8);
348
0
        m_aTextPropertyList.insert(sName.getStr(), sValue.getStr());
349
0
        m_aParagraphPropertyList.insert(sName.getStr(), sValue.getStr());
350
0
        m_aGraphicPropertyList.insert(sName.getStr(), sValue.getStr());
351
0
        m_aPageLayoutPropertyList.insert(sName.getStr(), sValue.getStr());
352
0
        m_aMasterPagePropertyList.insert(sName.getStr(), sValue.getStr());
353
0
        m_aTablePropertyList.insert(sName.getStr(), sValue.getStr());
354
0
    }
355
0
}
356
357
void XMLStyleContext::endElement(const OUString& rName)
358
0
{
359
0
    if (m_aName.isEmpty())
360
0
        return;
361
362
0
    if (m_aFamily == "text" || m_aFamily == "paragraph")
363
0
        m_rStyles.GetCurrentTextStyles()[m_aName] = m_aTextPropertyList;
364
0
    if (m_aFamily == "paragraph")
365
0
        m_rStyles.GetCurrentParagraphStyles()[m_aName] = m_aParagraphPropertyList;
366
0
    else if (m_aFamily == "table-cell")
367
0
        m_rStyles.GetCurrentCellStyles()[m_aName] = m_aCellPropertyList;
368
0
    else if (m_aFamily == "table-column")
369
0
        m_rStyles.GetCurrentColumnStyles()[m_aName] = m_aColumnPropertyList;
370
0
    else if (m_aFamily == "table-row")
371
0
        m_rStyles.GetCurrentRowStyles()[m_aName] = m_aRowPropertyList;
372
0
    else if (m_aFamily == "table")
373
0
        m_rStyles.GetCurrentTableStyles()[m_aName] = m_aTablePropertyList;
374
0
    else if (m_aFamily == "graphic")
375
0
        m_rStyles.GetCurrentGraphicStyles()[m_aName] = m_aGraphicPropertyList;
376
0
    else if (rName == "style:page-layout")
377
0
        m_rStyles.GetCurrentPageLayouts()[m_aName] = m_aPageLayoutPropertyList;
378
0
    else if (rName == "style:master-page")
379
0
        m_rStyles.GetCurrentMasterStyles()[m_aName] = m_aMasterPagePropertyList;
380
0
}
381
382
0
librevenge::RVNGPropertyList& XMLStyleContext::GetTextPropertyList() { return m_aTextPropertyList; }
383
384
librevenge::RVNGPropertyList& XMLStyleContext::GetParagraphPropertyList()
385
0
{
386
0
    return m_aParagraphPropertyList;
387
0
}
388
389
0
librevenge::RVNGPropertyList& XMLStyleContext::GetCellPropertyList() { return m_aCellPropertyList; }
390
391
librevenge::RVNGPropertyList& XMLStyleContext::GetColumnPropertyList()
392
0
{
393
0
    return m_aColumnPropertyList;
394
0
}
395
396
0
librevenge::RVNGPropertyList& XMLStyleContext::GetRowPropertyList() { return m_aRowPropertyList; }
397
398
librevenge::RVNGPropertyList& XMLStyleContext::GetTablePropertyList()
399
0
{
400
0
    return m_aTablePropertyList;
401
0
}
402
403
librevenge::RVNGPropertyList& XMLStyleContext::GetGraphicPropertyList()
404
0
{
405
0
    return m_aGraphicPropertyList;
406
0
}
407
408
librevenge::RVNGPropertyList& XMLStyleContext::GetPageLayoutPropertyList()
409
0
{
410
0
    return m_aPageLayoutPropertyList;
411
0
}
412
413
} // namespace writerperfect::exp
414
415
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */