Coverage Report

Created: 2026-02-14 09:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/xmloff/source/text/XMLIndexTabStopEntryContext.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
 * This file incorporates work covered by the following license notice:
10
 *
11
 *   Licensed to the Apache Software Foundation (ASF) under one or more
12
 *   contributor license agreements. See the NOTICE file distributed
13
 *   with this work for additional information regarding copyright
14
 *   ownership. The ASF licenses this file to you under the Apache
15
 *   License, Version 2.0 (the "License"); you may not use this file
16
 *   except in compliance with the License. You may obtain a copy of
17
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18
 */
19
20
21
#include "XMLIndexTabStopEntryContext.hxx"
22
23
#include <sax/tools/converter.hxx>
24
25
#include "XMLIndexTemplateContext.hxx"
26
#include <xmloff/xmlimp.hxx>
27
#include <xmloff/xmlnamespace.hxx>
28
#include <xmloff/xmltoken.hxx>
29
#include <xmloff/xmluconv.hxx>
30
#include <rtl/ustring.hxx>
31
#include <sal/log.hxx>
32
33
using namespace ::xmloff::token;
34
35
using ::com::sun::star::uno::Sequence;
36
using ::com::sun::star::uno::Reference;
37
using ::com::sun::star::beans::PropertyValue;
38
39
40
XMLIndexTabStopEntryContext::XMLIndexTabStopEntryContext(
41
    SvXMLImport& rImport,
42
    XMLIndexTemplateContext& rTemplate ) :
43
0
        XMLIndexSimpleEntryContext(rImport, u"TokenTabStop"_ustr,
44
0
                                   rTemplate),
45
0
        nTabPosition(0),
46
0
        bTabPositionOK(false),
47
0
        bTabRightAligned(false),
48
0
        bLeaderCharOK(false),
49
0
        bWithTab(true) // #i21237#
50
0
{
51
0
}
52
53
XMLIndexTabStopEntryContext::~XMLIndexTabStopEntryContext()
54
0
{
55
0
}
56
57
void XMLIndexTabStopEntryContext::startFastElement(
58
    sal_Int32 nElement,
59
    const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
60
0
{
61
    // process three attributes: type, position, leader char
62
0
    for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
63
0
    {
64
0
        switch(aIter.getToken())
65
0
        {
66
0
            case XML_ELEMENT(STYLE, XML_TYPE):
67
0
            {
68
                // if it's neither left nor right, value is
69
                // ignored. Since left is default, we only need to
70
                // check for right
71
0
                bTabRightAligned = IsXMLToken( aIter, XML_RIGHT );
72
0
                break;
73
0
            }
74
0
            case XML_ELEMENT(STYLE, XML_POSITION):
75
0
            {
76
0
                sal_Int32 nTmp;
77
0
                if (GetImport().GetMM100UnitConverter().
78
0
                                        convertMeasureToCore(nTmp, aIter.toView()))
79
0
                {
80
0
                    nTabPosition = nTmp;
81
0
                    bTabPositionOK = true;
82
0
                }
83
0
                break;
84
0
            }
85
0
            case XML_ELEMENT(STYLE, XML_LEADER_CHAR):
86
0
            {
87
0
                sLeaderChar = aIter.toString();
88
                // valid only, if we have a char!
89
0
                bLeaderCharOK = !sLeaderChar.isEmpty();
90
0
                break;
91
0
            }
92
0
            case XML_ELEMENT(STYLE, XML_WITH_TAB):
93
0
            {
94
                // #i21237#
95
0
                bool bTmp(false);
96
0
                if (::sax::Converter::convertBool(bTmp, aIter.toView()))
97
0
                    bWithTab = bTmp;
98
0
                break;
99
0
            }
100
0
            default:
101
0
                XMLOFF_WARN_UNKNOWN("xmloff", aIter);
102
            // else: unknown style: attribute -> ignore
103
0
        }
104
0
    }
105
106
    // how many entries? #i21237#
107
0
    m_nValues += 2 + (bTabPositionOK ? 1 : 0) + (bLeaderCharOK ? 1 : 0);
108
109
    // now try parent class (for character style)
110
0
    XMLIndexSimpleEntryContext::startFastElement( nElement, xAttrList );
111
0
}
112
113
void XMLIndexTabStopEntryContext::FillPropertyValues(
114
    Sequence<PropertyValue> & rValues)
115
0
{
116
    // fill values from parent class (type + style name)
117
0
    XMLIndexSimpleEntryContext::FillPropertyValues(rValues);
118
119
    // get values array and next entry to be written;
120
0
    sal_Int32 nNextEntry = m_bCharStyleNameOK ? 2 : 1;
121
0
    PropertyValue* pValues = rValues.getArray();
122
123
    // right aligned?
124
0
    pValues[nNextEntry].Name = "TabStopRightAligned";
125
0
    pValues[nNextEntry].Value <<= bTabRightAligned;
126
0
    nNextEntry++;
127
128
    // position
129
0
    if (bTabPositionOK)
130
0
    {
131
0
        pValues[nNextEntry].Name = "TabStopPosition";
132
0
        pValues[nNextEntry].Value <<= nTabPosition;
133
0
        nNextEntry++;
134
0
    }
135
136
    // leader char
137
0
    if (bLeaderCharOK)
138
0
    {
139
0
        pValues[nNextEntry].Name = "TabStopFillCharacter";
140
0
        pValues[nNextEntry].Value <<= sLeaderChar;
141
0
        nNextEntry++;
142
0
    }
143
144
    // tab character #i21237#
145
0
    pValues[nNextEntry].Name = "WithTab";
146
0
    pValues[nNextEntry].Value <<= bWithTab;
147
0
    nNextEntry++;
148
149
    // check whether we really filled all elements of the sequence
150
0
    SAL_WARN_IF( nNextEntry != rValues.getLength(), "xmloff",
151
0
                "length incorrectly precomputed!" );
152
0
}
153
154
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */