Coverage Report

Created: 2026-05-16 09:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/xmloff/source/style/lspachdl.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 "lspachdl.hxx"
21
#include <xmloff/xmltoken.hxx>
22
#include <xmloff/xmluconv.hxx>
23
#include <sax/tools/converter.hxx>
24
#include <rtl/ustrbuf.hxx>
25
#include <com/sun/star/uno/Any.hxx>
26
#include <com/sun/star/style/LineSpacing.hpp>
27
#include <com/sun/star/style/LineSpacingMode.hpp>
28
29
using namespace ::com::sun::star;
30
using ::xmloff::token::IsXMLToken;
31
using ::xmloff::token::XML_NORMAL;
32
33
34
35
36
XMLLineHeightHdl::~XMLLineHeightHdl()
37
98.4k
{
38
    // nothing to do
39
98.4k
}
40
41
bool XMLLineHeightHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
42
852
{
43
852
    style::LineSpacing aLSp;
44
852
    sal_Int32 nTemp = 0;
45
46
852
    if( -1 != rStrImpValue.indexOf( '%' ) )
47
847
    {
48
847
        aLSp.Mode = style::LineSpacingMode::PROP;
49
847
        if (!::sax::Converter::convertPercent( nTemp, rStrImpValue ))
50
0
            return false;
51
847
        aLSp.Height = sal::static_int_cast< sal_Int16 >(nTemp);
52
847
    }
53
5
    else if( IsXMLToken( rStrImpValue, XML_NORMAL) )
54
0
    {
55
0
        aLSp.Mode = style::LineSpacingMode::PROP;
56
0
        aLSp.Height = 100;
57
0
    }
58
5
    else
59
5
    {
60
5
        aLSp.Mode = style::LineSpacingMode::FIX;
61
5
        if (!rUnitConverter.convertMeasureToCore(
62
5
                    nTemp, rStrImpValue, 0x0000, 0xffff))
63
5
            return false;
64
0
        aLSp.Height = sal::static_int_cast< sal_Int16 >(nTemp);
65
0
    }
66
67
847
    rValue <<= aLSp;
68
847
    return true;
69
852
}
70
71
bool XMLLineHeightHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
72
138
{
73
138
    OUStringBuffer aOut;
74
75
138
    style::LineSpacing aLSp;
76
138
    if(!(rValue >>= aLSp))
77
0
        return false;
78
79
138
    if( style::LineSpacingMode::PROP != aLSp.Mode && style::LineSpacingMode::FIX  != aLSp.Mode )
80
0
        return false;
81
82
138
    if( style::LineSpacingMode::PROP == aLSp.Mode )
83
138
    {
84
138
        ::sax::Converter::convertPercent( aOut, aLSp.Height );
85
138
    }
86
0
    else
87
0
    {
88
0
        rUnitConverter.convertMeasureToXML( aOut, aLSp.Height );
89
0
    }
90
91
138
    rStrExpValue = aOut.makeStringAndClear();
92
138
    return !rStrExpValue.isEmpty();
93
138
}
94
95
96
97
98
XMLLineHeightAtLeastHdl::~XMLLineHeightAtLeastHdl()
99
98.4k
{
100
    // nothing to do
101
98.4k
}
102
103
bool XMLLineHeightAtLeastHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
104
0
{
105
0
    style::LineSpacing aLSp;
106
107
0
    sal_Int32 nTemp;
108
0
    aLSp.Mode = style::LineSpacingMode::MINIMUM;
109
0
    if (!rUnitConverter.convertMeasureToCore( nTemp, rStrImpValue, 0, 0xffff))
110
0
        return false;
111
0
    aLSp.Height = sal::static_int_cast< sal_Int16 >(nTemp);
112
113
0
    rValue <<= aLSp;
114
0
    return true;
115
0
}
116
117
bool XMLLineHeightAtLeastHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
118
138
{
119
138
    OUStringBuffer aOut;
120
121
138
    style::LineSpacing aLSp;
122
138
    if(!(rValue >>= aLSp))
123
0
        return false;
124
125
138
    if( style::LineSpacingMode::MINIMUM != aLSp.Mode )
126
138
        return false;
127
128
0
    rUnitConverter.convertMeasureToXML( aOut, aLSp.Height );
129
130
0
    rStrExpValue = aOut.makeStringAndClear();
131
0
    return !rStrExpValue.isEmpty();
132
138
}
133
134
135
136
137
XMLLineSpacingHdl::~XMLLineSpacingHdl()
138
98.4k
{
139
    // nothing to do
140
98.4k
}
141
142
bool XMLLineSpacingHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
143
0
{
144
0
    style::LineSpacing aLSp;
145
0
    sal_Int32 nTemp;
146
147
0
    aLSp.Mode = style::LineSpacingMode::LEADING;
148
0
    if (!rUnitConverter.convertMeasureToCore( nTemp, rStrImpValue, 0, 0xffff))
149
0
        return false;
150
0
    aLSp.Height = sal::static_int_cast< sal_Int16 >(nTemp);
151
152
0
    rValue <<= aLSp;
153
0
    return true;
154
0
}
155
156
bool XMLLineSpacingHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
157
138
{
158
138
    OUStringBuffer aOut;
159
160
138
    style::LineSpacing aLSp;
161
138
    if(!(rValue >>= aLSp))
162
0
        return false;
163
164
138
    if( style::LineSpacingMode::LEADING != aLSp.Mode )
165
138
        return false;
166
167
0
    rUnitConverter.convertMeasureToXML( aOut, aLSp.Height );
168
169
0
    rStrExpValue = aOut.makeStringAndClear();
170
0
    return !rStrExpValue.isEmpty();
171
138
}
172
173
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */