Coverage Report

Created: 2026-09-28 10:59

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
#include "xmlfmt.hxx"
12
13
using namespace com::sun::star;
14
15
namespace writerperfect::exp
16
{
17
namespace
18
{
19
/// Handler for <style:paragraph-properties>.
20
class XMLParagraphPropertiesContext : public XMLImportContext
21
{
22
public:
23
    XMLParagraphPropertiesContext(XMLImport& rImport, XMLStyleContext& rStyle);
24
25
    void SAL_CALL
26
    startElement(const OUString& rName,
27
                 const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
28
29
private:
30
    XMLStyleContext& mrStyle;
31
};
32
}
33
34
XMLParagraphPropertiesContext::XMLParagraphPropertiesContext(XMLImport& rImport,
35
                                                             XMLStyleContext& rStyle)
36
0
    : XMLImportContext(rImport)
37
0
    , mrStyle(rStyle)
38
0
{
39
0
}
40
41
void XMLParagraphPropertiesContext::startElement(
42
    const OUString& /*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs)
43
0
{
44
0
    for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
45
0
    {
46
0
        OString sName = OUStringToOString(xAttribs->getNameByIndex(i), RTL_TEXTENCODING_UTF8);
47
0
        OString sValue = OUStringToOString(xAttribs->getValueByIndex(i), RTL_TEXTENCODING_UTF8);
48
0
        mrStyle.GetParagraphPropertyList().insert(sName.getStr(), sValue.getStr());
49
0
    }
50
0
}
51
52
namespace
53
{
54
/// Handler for <style:text-properties>.
55
class XMLTextPropertiesContext : public XMLImportContext
56
{
57
public:
58
    XMLTextPropertiesContext(XMLImport& rImport, XMLStyleContext& rStyle);
59
60
    void SAL_CALL
61
    startElement(const OUString& rName,
62
                 const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
63
64
private:
65
    XMLStyleContext& mrStyle;
66
};
67
}
68
69
XMLTextPropertiesContext::XMLTextPropertiesContext(XMLImport& rImport, XMLStyleContext& rStyle)
70
0
    : XMLImportContext(rImport)
71
0
    , mrStyle(rStyle)
72
0
{
73
0
}
74
75
void XMLTextPropertiesContext::startElement(
76
    const OUString& /*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs)
77
0
{
78
0
    for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
79
0
    {
80
0
        OString sName = OUStringToOString(xAttribs->getNameByIndex(i), RTL_TEXTENCODING_UTF8);
81
0
        OString sValue = OUStringToOString(xAttribs->getValueByIndex(i), RTL_TEXTENCODING_UTF8);
82
0
        mrStyle.GetTextPropertyList().insert(sName.getStr(), sValue.getStr());
83
0
    }
84
0
}
85
86
namespace
87
{
88
/// Handler for <style:graphic-properties>.
89
class XMLGraphicPropertiesContext : public XMLImportContext
90
{
91
public:
92
    XMLGraphicPropertiesContext(XMLImport& rImport, XMLStyleContext& rStyle);
93
94
    void SAL_CALL
95
    startElement(const OUString& rName,
96
                 const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
97
98
private:
99
    XMLStyleContext& mrStyle;
100
};
101
}
102
103
XMLGraphicPropertiesContext::XMLGraphicPropertiesContext(XMLImport& rImport,
104
                                                         XMLStyleContext& rStyle)
105
0
    : XMLImportContext(rImport)
106
0
    , mrStyle(rStyle)
107
0
{
108
0
}
109
110
void XMLGraphicPropertiesContext::startElement(
111
    const OUString& /*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs)
112
0
{
113
0
    for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
114
0
    {
115
0
        OString sName = OUStringToOString(xAttribs->getNameByIndex(i), RTL_TEXTENCODING_UTF8);
116
0
        OString sValue = OUStringToOString(xAttribs->getValueByIndex(i), RTL_TEXTENCODING_UTF8);
117
0
        mrStyle.GetGraphicPropertyList().insert(sName.getStr(), sValue.getStr());
118
0
    }
119
0
}
120
121
namespace
122
{
123
/// Handler for <text:list-level-style-number> and <text:text:list-level-style-bullet>.
124
class XMLListPropertiesContext : public XMLImportContext
125
{
126
public:
127
    XMLListPropertiesContext(XMLImport& rImport, XMLStyleContext& rStyle,
128
                             const OUString& rStyleName);
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
    const OUString& mrStyleName;
137
};
138
}
139
140
XMLListPropertiesContext::XMLListPropertiesContext(XMLImport& rImport, XMLStyleContext& rStyle,
141
                                                   const OUString& rStyleName)
142
0
    : XMLImportContext(rImport)
143
0
    , mrStyle(rStyle)
144
0
    , mrStyleName(rStyleName)
145
0
{
146
0
}
147
148
void XMLListPropertiesContext::startElement(
149
    const OUString& /*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs)
150
0
{
151
0
    OString aStyleName = OUStringToOString(mrStyleName, RTL_TEXTENCODING_UTF8);
152
153
    // a list style is defined with:
154
    // 1 "text:list-style" tag which only contains the attribute "style:name"
155
    // several (most of times 10) "text:list-level-style-number" or "text:list-level-style-bullet" subtags
156
    // remark: these subtags contains other elements but we haven't dealt with them
157
    // anyway, that's why we need a RVNGPropertyListVector, this one will contain subtags.
158
    // All attributes of the subtag will be in a RVNGPropertyList
159
160
    // declare the vector for the current style
161
0
    librevenge::RVNGPropertyListVector aStyleCurrentVector;
162
163
    // check if there's an existing one and if it's the case, use it
164
0
    const librevenge::RVNGProperty* pStyleProperty
165
0
        = mrStyle.GetListPropertyList().child(aStyleName.getStr());
166
0
    if (pStyleProperty)
167
0
    {
168
0
        const librevenge::RVNGPropertyListVector* pStyleVector
169
0
            = static_cast<const librevenge::RVNGPropertyListVector*>(pStyleProperty);
170
0
        aStyleCurrentVector = *pStyleVector;
171
0
    }
172
173
    // create a RVNGPropertyList for the subtag of a style
174
0
    librevenge::RVNGPropertyList aCurrentPropertyList;
175
    // save all attributes of the subtag
176
0
    for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
177
0
    {
178
0
        OString sName = OUStringToOString(xAttribs->getNameByIndex(i), RTL_TEXTENCODING_UTF8);
179
0
        OString sValue = OUStringToOString(xAttribs->getValueByIndex(i), RTL_TEXTENCODING_UTF8);
180
0
        aCurrentPropertyList.insert(sName.getStr(), sValue.getStr());
181
0
    }
182
    // now we can add the subtag in the vector
183
0
    aStyleCurrentVector.append(aCurrentPropertyList);
184
185
    // and insert/reinsert it in mrStyle.GetListPropertyList
186
0
    mrStyle.GetListPropertyList().insert(aStyleName.getStr(), aStyleCurrentVector);
187
0
}
188
189
namespace
190
{
191
/// Handler for <style:page-layout-properties>.
192
class XMLPageLayoutPropertiesContext : public XMLImportContext
193
{
194
public:
195
    XMLPageLayoutPropertiesContext(XMLImport& rImport, XMLStyleContext& rStyle);
196
197
    void SAL_CALL
198
    startElement(const OUString& rName,
199
                 const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
200
201
private:
202
    XMLStyleContext& mrStyle;
203
};
204
}
205
206
XMLPageLayoutPropertiesContext::XMLPageLayoutPropertiesContext(XMLImport& rImport,
207
                                                               XMLStyleContext& rStyle)
208
0
    : XMLImportContext(rImport)
209
0
    , mrStyle(rStyle)
210
0
{
211
0
}
212
213
void XMLPageLayoutPropertiesContext::startElement(
214
    const OUString& /*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs)
215
0
{
216
0
    for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
217
0
    {
218
0
        OString sName = OUStringToOString(xAttribs->getNameByIndex(i), RTL_TEXTENCODING_UTF8);
219
0
        OString sValue = OUStringToOString(xAttribs->getValueByIndex(i), RTL_TEXTENCODING_UTF8);
220
        // We only care about writing-mode for now.
221
0
        if (sName != "style:writing-mode")
222
0
            continue;
223
224
0
        mrStyle.GetPageLayoutPropertyList().insert(sName.getStr(), sValue.getStr());
225
0
    }
226
0
}
227
228
namespace
229
{
230
/// Handler for <style:table-properties>.
231
class XMLTablePropertiesContext : public XMLImportContext
232
{
233
public:
234
    XMLTablePropertiesContext(XMLImport& rImport, XMLStyleContext& rStyle);
235
236
    void SAL_CALL
237
    startElement(const OUString& rName,
238
                 const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
239
240
private:
241
    XMLStyleContext& mrStyle;
242
};
243
}
244
245
XMLTablePropertiesContext::XMLTablePropertiesContext(XMLImport& rImport, XMLStyleContext& rStyle)
246
0
    : XMLImportContext(rImport)
247
0
    , mrStyle(rStyle)
248
0
{
249
0
}
250
251
void XMLTablePropertiesContext::startElement(
252
    const OUString& /*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs)
253
0
{
254
0
    for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
255
0
    {
256
0
        OString sName = OUStringToOString(xAttribs->getNameByIndex(i), RTL_TEXTENCODING_UTF8);
257
0
        OString sValue = OUStringToOString(xAttribs->getValueByIndex(i), RTL_TEXTENCODING_UTF8);
258
0
        if (sName == "style:rel-width")
259
            // Make sure this is passed through as a string, and not parsed as a double.
260
0
            mrStyle.GetTablePropertyList().insert(
261
0
                sName.getStr(), librevenge::RVNGPropertyFactory::newStringProp(sValue.getStr()));
262
0
        else
263
0
            mrStyle.GetTablePropertyList().insert(sName.getStr(), sValue.getStr());
264
0
    }
265
0
}
266
267
namespace
268
{
269
/// Handler for <style:table-row-properties>.
270
class XMLTableRowPropertiesContext : public XMLImportContext
271
{
272
public:
273
    XMLTableRowPropertiesContext(XMLImport& rImport, XMLStyleContext& rStyle);
274
275
    void SAL_CALL
276
    startElement(const OUString& rName,
277
                 const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
278
279
private:
280
    XMLStyleContext& mrStyle;
281
};
282
}
283
284
XMLTableRowPropertiesContext::XMLTableRowPropertiesContext(XMLImport& rImport,
285
                                                           XMLStyleContext& rStyle)
286
0
    : XMLImportContext(rImport)
287
0
    , mrStyle(rStyle)
288
0
{
289
0
}
290
291
void XMLTableRowPropertiesContext::startElement(
292
    const OUString& /*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs)
293
0
{
294
0
    for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
295
0
    {
296
0
        OString sName = OUStringToOString(xAttribs->getNameByIndex(i), RTL_TEXTENCODING_UTF8);
297
0
        OString sValue = OUStringToOString(xAttribs->getValueByIndex(i), RTL_TEXTENCODING_UTF8);
298
0
        mrStyle.GetRowPropertyList().insert(sName.getStr(), sValue.getStr());
299
0
    }
300
0
}
301
302
namespace
303
{
304
/// Handler for <style:table-column-properties>.
305
class XMLTableColumnPropertiesContext : public XMLImportContext
306
{
307
public:
308
    XMLTableColumnPropertiesContext(XMLImport& rImport, XMLStyleContext& rStyle);
309
310
    void SAL_CALL
311
    startElement(const OUString& rName,
312
                 const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
313
314
private:
315
    XMLStyleContext& mrStyle;
316
};
317
}
318
319
XMLTableColumnPropertiesContext::XMLTableColumnPropertiesContext(XMLImport& rImport,
320
                                                                 XMLStyleContext& rStyle)
321
0
    : XMLImportContext(rImport)
322
0
    , mrStyle(rStyle)
323
0
{
324
0
}
325
326
void XMLTableColumnPropertiesContext::startElement(
327
    const OUString& /*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs)
328
0
{
329
0
    for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
330
0
    {
331
0
        OString sName = OUStringToOString(xAttribs->getNameByIndex(i), RTL_TEXTENCODING_UTF8);
332
0
        OString sValue = OUStringToOString(xAttribs->getValueByIndex(i), RTL_TEXTENCODING_UTF8);
333
0
        mrStyle.GetColumnPropertyList().insert(sName.getStr(), sValue.getStr());
334
0
    }
335
0
}
336
337
namespace
338
{
339
/// Handler for <style:table-cell-properties>.
340
class XMLTableCellPropertiesContext : public XMLImportContext
341
{
342
public:
343
    XMLTableCellPropertiesContext(XMLImport& rImport, XMLStyleContext& rStyle);
344
345
    void SAL_CALL
346
    startElement(const OUString& rName,
347
                 const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
348
349
private:
350
    XMLStyleContext& mrStyle;
351
};
352
}
353
354
XMLTableCellPropertiesContext::XMLTableCellPropertiesContext(XMLImport& rImport,
355
                                                             XMLStyleContext& rStyle)
356
0
    : XMLImportContext(rImport)
357
0
    , mrStyle(rStyle)
358
0
{
359
0
}
360
361
void XMLTableCellPropertiesContext::startElement(
362
    const OUString& /*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs)
363
0
{
364
0
    for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
365
0
    {
366
0
        OString sName = OUStringToOString(xAttribs->getNameByIndex(i), RTL_TEXTENCODING_UTF8);
367
0
        OString sValue = OUStringToOString(xAttribs->getValueByIndex(i), RTL_TEXTENCODING_UTF8);
368
0
        mrStyle.GetCellPropertyList().insert(sName.getStr(), sValue.getStr());
369
0
    }
370
0
}
371
372
XMLStyleContext::XMLStyleContext(XMLImport& rImport, XMLStylesContext& rStyles)
373
0
    : XMLImportContext(rImport)
374
0
    , m_rStyles(rStyles)
375
0
{
376
0
}
377
378
rtl::Reference<XMLImportContext> XMLStyleContext::CreateChildContext(
379
    const OUString& rName, const css::uno::Reference<css::xml::sax::XAttributeList>& /*xAttribs*/)
380
0
{
381
0
    if (rName == "style:paragraph-properties")
382
0
        return new XMLParagraphPropertiesContext(GetImport(), *this);
383
0
    if (rName == "style:text-properties")
384
0
        return new XMLTextPropertiesContext(GetImport(), *this);
385
0
    if (rName == "style:table-cell-properties")
386
0
        return new XMLTableCellPropertiesContext(GetImport(), *this);
387
0
    if (rName == "style:table-column-properties")
388
0
        return new XMLTableColumnPropertiesContext(GetImport(), *this);
389
0
    if (rName == "style:table-row-properties")
390
0
        return new XMLTableRowPropertiesContext(GetImport(), *this);
391
0
    if (rName == "style:table-properties")
392
0
        return new XMLTablePropertiesContext(GetImport(), *this);
393
0
    if (rName == "style:graphic-properties")
394
0
        return new XMLGraphicPropertiesContext(GetImport(), *this);
395
0
    if (rName == "text:list-level-style-number" || rName == "text:list-level-style-bullet")
396
0
        return new XMLListPropertiesContext(GetImport(), *this, m_aName);
397
0
    if (rName == "style:page-layout-properties")
398
0
        return new XMLPageLayoutPropertiesContext(GetImport(), *this);
399
0
    return nullptr;
400
0
}
401
402
void XMLStyleContext::startElement(
403
    const OUString& /*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs)
404
0
{
405
0
    for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
406
0
    {
407
0
        const OUString aAttributeName = xAttribs->getNameByIndex(i);
408
0
        const OUString aAttributeValue = xAttribs->getValueByIndex(i);
409
0
        if (aAttributeName == "style:name")
410
0
            m_aName = aAttributeValue;
411
0
        else if (aAttributeName == "style:family")
412
0
            m_aFamily = aAttributeValue;
413
414
        // Remember properties of the style itself, e.g. parent name.
415
0
        OString sName = OUStringToOString(aAttributeName, RTL_TEXTENCODING_UTF8);
416
0
        OString sValue = OUStringToOString(aAttributeValue, RTL_TEXTENCODING_UTF8);
417
0
        m_aTextPropertyList.insert(sName.getStr(), sValue.getStr());
418
0
        m_aParagraphPropertyList.insert(sName.getStr(), sValue.getStr());
419
0
        m_aGraphicPropertyList.insert(sName.getStr(), sValue.getStr());
420
0
        m_aListPropertyList.insert(sName.getStr(), sValue.getStr());
421
0
        m_aPageLayoutPropertyList.insert(sName.getStr(), sValue.getStr());
422
0
        m_aMasterPagePropertyList.insert(sName.getStr(), sValue.getStr());
423
0
        m_aTablePropertyList.insert(sName.getStr(), sValue.getStr());
424
0
    }
425
0
}
426
427
void XMLStyleContext::endElement(const OUString& rName)
428
0
{
429
0
    if (m_aName.isEmpty())
430
0
        return;
431
432
0
    if (m_aFamily == "text" || m_aFamily == "paragraph")
433
0
        m_rStyles.GetCurrentTextStyles()[m_aName] = m_aTextPropertyList;
434
0
    if (m_aFamily == "paragraph")
435
0
        m_rStyles.GetCurrentParagraphStyles()[m_aName] = m_aParagraphPropertyList;
436
0
    else if (m_aFamily == "table-cell")
437
0
        m_rStyles.GetCurrentCellStyles()[m_aName] = m_aCellPropertyList;
438
0
    else if (m_aFamily == "table-column")
439
0
        m_rStyles.GetCurrentColumnStyles()[m_aName] = m_aColumnPropertyList;
440
0
    else if (m_aFamily == "table-row")
441
0
        m_rStyles.GetCurrentRowStyles()[m_aName] = m_aRowPropertyList;
442
0
    else if (m_aFamily == "table")
443
0
        m_rStyles.GetCurrentTableStyles()[m_aName] = m_aTablePropertyList;
444
0
    else if (m_aFamily == "graphic")
445
0
        m_rStyles.GetCurrentGraphicStyles()[m_aName] = m_aGraphicPropertyList;
446
0
    else if (rName == "text:list-style")
447
0
        m_rStyles.GetCurrentListStyles()[m_aName] = m_aListPropertyList;
448
0
    else if (rName == "style:page-layout")
449
0
        m_rStyles.GetCurrentPageLayouts()[m_aName] = m_aPageLayoutPropertyList;
450
0
    else if (rName == "style:master-page")
451
0
        m_rStyles.GetCurrentMasterStyles()[m_aName] = m_aMasterPagePropertyList;
452
0
}
453
454
0
librevenge::RVNGPropertyList& XMLStyleContext::GetTextPropertyList() { return m_aTextPropertyList; }
455
456
librevenge::RVNGPropertyList& XMLStyleContext::GetParagraphPropertyList()
457
0
{
458
0
    return m_aParagraphPropertyList;
459
0
}
460
461
0
librevenge::RVNGPropertyList& XMLStyleContext::GetCellPropertyList() { return m_aCellPropertyList; }
462
463
librevenge::RVNGPropertyList& XMLStyleContext::GetColumnPropertyList()
464
0
{
465
0
    return m_aColumnPropertyList;
466
0
}
467
468
0
librevenge::RVNGPropertyList& XMLStyleContext::GetRowPropertyList() { return m_aRowPropertyList; }
469
470
librevenge::RVNGPropertyList& XMLStyleContext::GetTablePropertyList()
471
0
{
472
0
    return m_aTablePropertyList;
473
0
}
474
475
librevenge::RVNGPropertyList& XMLStyleContext::GetGraphicPropertyList()
476
0
{
477
0
    return m_aGraphicPropertyList;
478
0
}
479
480
0
librevenge::RVNGPropertyList& XMLStyleContext::GetListPropertyList() { return m_aListPropertyList; }
481
482
librevenge::RVNGPropertyList& XMLStyleContext::GetPageLayoutPropertyList()
483
0
{
484
0
    return m_aPageLayoutPropertyList;
485
0
}
486
487
} // namespace writerperfect::exp
488
489
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */