Coverage Report

Created: 2026-08-14 10:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/xmloff/source/style/escphdl.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
#include "escphdl.hxx"
21
22
#include <editeng/escapementitem.hxx>
23
#include <sax/tools/converter.hxx>
24
#include <xmloff/xmltoken.hxx>
25
#include <xmloff/xmluconv.hxx>
26
#include <rtl/ustrbuf.hxx>
27
#include <com/sun/star/uno/Any.hxx>
28
29
using namespace ::com::sun::star;
30
using namespace ::xmloff::token;
31
32
33
34
35
XMLEscapementPropHdl::~XMLEscapementPropHdl()
36
80.2k
{
37
    // nothing to do
38
80.2k
}
39
40
bool XMLEscapementPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
41
7.87k
{
42
7.87k
    sal_Int16 nVal;
43
44
7.87k
    SvXMLTokenEnumerator aTokens( rStrImpValue );
45
46
7.87k
    std::u16string_view aToken;
47
7.87k
    if( ! aTokens.getNextToken( aToken ) )
48
0
        return false;
49
50
7.87k
    if( IsXMLToken( aToken, XML_ESCAPEMENT_SUB ) )
51
997
    {
52
997
        nVal = DFLT_ESC_AUTO_SUB;
53
997
    }
54
6.87k
    else if( IsXMLToken( aToken, XML_ESCAPEMENT_SUPER ) )
55
1.60k
    {
56
1.60k
        nVal = DFLT_ESC_AUTO_SUPER;
57
1.60k
    }
58
5.27k
    else
59
5.27k
    {
60
5.27k
        sal_Int32 nNewEsc;
61
5.27k
        if (!::sax::Converter::convertPercent( nNewEsc, aToken ))
62
15
            return false;
63
64
5.25k
        nVal = static_cast<sal_Int16>(nNewEsc);
65
5.25k
    }
66
67
7.85k
    rValue <<= nVal;
68
7.85k
    return true;
69
7.87k
}
70
71
bool XMLEscapementPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
72
0
{
73
0
    sal_Int32 nValue = 0;
74
0
    OUStringBuffer aOut;
75
76
0
    if( rValue >>= nValue )
77
0
    {
78
0
        if( nValue == DFLT_ESC_AUTO_SUPER )
79
0
        {
80
0
            aOut.append( GetXMLToken(XML_ESCAPEMENT_SUPER) );
81
0
        }
82
0
        else if( nValue == DFLT_ESC_AUTO_SUB )
83
0
        {
84
0
            aOut.append( GetXMLToken(XML_ESCAPEMENT_SUB) );
85
0
        }
86
0
        else
87
0
        {
88
0
            ::sax::Converter::convertPercent( aOut, nValue );
89
0
        }
90
0
    }
91
92
0
    rStrExpValue = aOut.makeStringAndClear();
93
0
    return !rStrExpValue.isEmpty();
94
0
}
95
96
97
98
99
XMLEscapementHeightPropHdl::~XMLEscapementHeightPropHdl()
100
80.2k
{
101
    // nothing to do
102
80.2k
}
103
104
bool XMLEscapementHeightPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
105
7.87k
{
106
7.87k
    if( IsXMLToken( rStrImpValue, XML_CASEMAP_SMALL_CAPS ) )
107
0
        return false;
108
109
7.87k
    SvXMLTokenEnumerator aTokens( rStrImpValue );
110
111
7.87k
    std::u16string_view aToken;
112
7.87k
    if( ! aTokens.getNextToken( aToken ) )
113
0
        return false;
114
115
7.87k
    sal_Int8 nProp;
116
7.87k
    if( aTokens.getNextToken( aToken ) )
117
2.61k
    {
118
2.61k
        sal_Int32 nNewProp;
119
2.61k
        if (!::sax::Converter::convertPercent( nNewProp, aToken ))
120
24
            return false;
121
2.58k
        nProp = static_cast<sal_Int8>(nNewProp);
122
2.58k
    }
123
5.25k
    else
124
5.25k
    {
125
5.25k
        sal_Int32 nEscapementPosition=0;
126
5.25k
        if (::sax::Converter::convertPercent( nEscapementPosition, aToken )
127
5.25k
            && (nEscapementPosition == 0))
128
5.25k
        {
129
5.25k
            nProp = 100; //if escapement position is zero and no escapement height is given the default height should be 100percent and not something smaller (#i91800#)
130
5.25k
        }
131
3
        else
132
3
            nProp = sal_Int8(DFLT_ESC_PROP);
133
5.25k
    }
134
135
7.84k
    rValue <<= nProp;
136
7.84k
    return true;
137
7.87k
}
138
139
bool XMLEscapementHeightPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
140
0
{
141
0
    OUStringBuffer aOut( rStrExpValue );
142
143
0
    sal_Int32 nValue = 0;
144
0
    if( rValue >>= nValue )
145
0
    {
146
0
        if( !rStrExpValue.isEmpty() )
147
0
            aOut.append( ' ');
148
149
0
        ::sax::Converter::convertPercent( aOut, nValue );
150
0
    }
151
152
0
    rStrExpValue = aOut.makeStringAndClear();
153
0
    return !rStrExpValue.isEmpty();
154
0
}
155
156
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */