Coverage Report

Created: 2026-02-14 09:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/xmloff/source/draw/propimp0.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 <rtl/ustrbuf.hxx>
21
#include <sal/log.hxx>
22
#include <propimp0.hxx>
23
#include <com/sun/star/util/Duration.hpp>
24
#include <com/sun/star/uno/Any.hxx>
25
26
#include <sax/tools/converter.hxx>
27
28
#include <xmloff/xmlexp.hxx>
29
#include <xmloff/xmluconv.hxx>
30
#include <xmloff/xmlimp.hxx>
31
32
#include <tools/time.hxx>
33
34
using namespace ::com::sun::star;
35
36
// implementation of graphic property Stroke
37
38
// implementation of presentation page property Change
39
40
// implementation of an effect duration property handler
41
42
XMLDurationPropertyHdl::~XMLDurationPropertyHdl()
43
26.9k
{
44
26.9k
}
45
46
bool XMLDurationPropertyHdl::importXML(
47
    const OUString& rStrImpValue,
48
    css::uno::Any& rValue,
49
    const SvXMLUnitConverter& ) const
50
0
{
51
0
    util::Duration aDuration;
52
53
0
    if (::sax::Converter::convertDuration(aDuration,  rStrImpValue))
54
0
    {
55
0
        const double fSeconds = ((aDuration.Days * 24 + aDuration.Hours) * 60
56
0
                                 + aDuration.Minutes) * 60
57
0
                                 + aDuration.Seconds
58
0
                                 + aDuration.NanoSeconds / static_cast<double>(::tools::Time::nanoSecPerSec);
59
0
        rValue <<= fSeconds;
60
61
0
        return true;
62
0
    }
63
64
0
    SAL_WARN_IF(!rStrImpValue.isEmpty(), "xmloff", "Invalid duration: " << rStrImpValue);
65
66
0
    return false;
67
0
}
68
69
bool XMLDurationPropertyHdl::exportXML(
70
    OUString& rStrExpValue,
71
    const css::uno::Any& rValue,
72
    const SvXMLUnitConverter& ) const
73
0
{
74
0
    double nVal = 0;
75
76
0
    if(rValue >>= nVal)
77
0
    {
78
0
        util::Duration aDuration;
79
0
        aDuration.Seconds = static_cast<sal_uInt16>(nVal);
80
0
        aDuration.NanoSeconds = static_cast<sal_uInt32>((nVal - aDuration.Seconds) * ::tools::Time::nanoSecPerSec);
81
82
0
        OUStringBuffer aOut;
83
0
        ::sax::Converter::convertDuration(aOut, aDuration);
84
0
        rStrExpValue = aOut.makeStringAndClear();
85
0
        return true;
86
0
    }
87
88
0
    return false;
89
0
}
90
91
// implementation of an opacity property handler
92
93
XMLOpacityPropertyHdl::XMLOpacityPropertyHdl( SvXMLImport* pImport )
94
34.8k
: mpImport( pImport )
95
34.8k
{
96
34.8k
}
97
98
XMLOpacityPropertyHdl::~XMLOpacityPropertyHdl()
99
34.8k
{
100
34.8k
}
101
102
bool XMLOpacityPropertyHdl::importXML(
103
    const OUString& rStrImpValue,
104
    css::uno::Any& rValue,
105
    const SvXMLUnitConverter& ) const
106
0
{
107
0
    bool bRet = false;
108
0
    sal_Int32 nValue = 0;
109
110
0
    if( rStrImpValue.indexOf( '%' ) != -1 )
111
0
    {
112
0
        if (::sax::Converter::convertPercent( nValue, rStrImpValue ))
113
0
            bRet = true;
114
0
    }
115
0
    else
116
0
    {
117
0
        nValue = sal_Int32( rStrImpValue.toDouble() * 100.0 );
118
0
        bRet = true;
119
0
    }
120
121
0
    if( bRet )
122
0
    {
123
        // check ranges
124
0
        if( nValue < 0 )
125
0
            nValue = 0;
126
0
        if( nValue > 100 )
127
0
            nValue = 100;
128
129
        // convert xml opacity to api transparency
130
0
        nValue = 100 - nValue;
131
132
        // #i42959#
133
0
        if( mpImport )
134
0
        {
135
0
            sal_Int32 nUPD, nBuild;
136
0
            if( mpImport->getBuildIds( nUPD, nBuild ) )
137
0
            {
138
                // correct import of documents written prior to StarOffice 8/OOO 2.0 final
139
0
                if( (nUPD == 680) && (nBuild < 8951) )
140
0
                    nValue = 100 - nValue;
141
0
            }
142
0
        }
143
144
0
        rValue <<= sal_uInt16(nValue);
145
0
    }
146
147
0
    return bRet;
148
0
}
149
150
bool XMLOpacityPropertyHdl::exportXML(
151
    OUString& rStrExpValue,
152
    const css::uno::Any& rValue,
153
    const SvXMLUnitConverter& ) const
154
0
{
155
0
    bool bRet = false;
156
0
    sal_uInt16 nVal = sal_uInt16();
157
158
0
    if( rValue >>= nVal )
159
0
    {
160
0
        OUStringBuffer aOut;
161
162
0
        nVal = 100 - nVal;
163
0
        ::sax::Converter::convertPercent( aOut, nVal );
164
0
        rStrExpValue = aOut.makeStringAndClear();
165
0
        bRet = true;
166
0
    }
167
168
0
    return bRet;
169
0
}
170
171
// implementation of a text animation step amount
172
173
XMLTextAnimationStepPropertyHdl::~XMLTextAnimationStepPropertyHdl()
174
34.7k
{
175
34.7k
}
176
177
bool XMLTextAnimationStepPropertyHdl::importXML(
178
    const OUString& rStrImpValue,
179
    css::uno::Any& rValue,
180
    const SvXMLUnitConverter& rUnitConverter ) const
181
0
{
182
0
    bool bRet = false;
183
0
    sal_Int32 nValue = 0;
184
185
0
    sal_Int32 nPos = rStrImpValue.indexOf( "px" );
186
0
    if( nPos != -1 )
187
0
    {
188
0
        if (::sax::Converter::convertNumber(nValue, rStrImpValue.subView(0, nPos), SAL_MIN_INT16+1, SAL_MAX_INT16))
189
0
        {
190
0
            rValue <<= sal_Int16( -nValue );
191
0
            bRet = true;
192
0
        }
193
0
    }
194
0
    else
195
0
    {
196
0
        if (rUnitConverter.convertMeasureToCore( nValue, rStrImpValue ))
197
0
        {
198
0
            rValue <<= sal_Int16( nValue );
199
0
            bRet = true;
200
0
        }
201
0
    }
202
203
0
    return bRet;
204
0
}
205
206
bool XMLTextAnimationStepPropertyHdl::exportXML(
207
    OUString& rStrExpValue,
208
    const css::uno::Any& rValue,
209
    const SvXMLUnitConverter& rUnitConverter ) const
210
0
{
211
0
    bool bRet = false;
212
0
    sal_Int16 nVal = sal_Int16();
213
214
0
    if( rValue >>= nVal )
215
0
    {
216
0
        OUStringBuffer aOut;
217
218
0
        if( nVal < 0 )
219
0
        {
220
0
            aOut.append( OUString::number(static_cast<sal_Int32>(-nVal) ) + "px" );
221
0
        }
222
0
        else
223
0
        {
224
0
            rUnitConverter.convertMeasureToXML( aOut, nVal );
225
0
        }
226
227
0
        rStrExpValue = aOut.makeStringAndClear();
228
0
        bRet = true;
229
0
    }
230
231
0
    return bRet;
232
0
}
233
234
XMLDateTimeFormatHdl::XMLDateTimeFormatHdl( SvXMLExport* pExport )
235
0
: mpExport( pExport )
236
0
{
237
0
}
238
239
XMLDateTimeFormatHdl::~XMLDateTimeFormatHdl()
240
0
{
241
0
}
242
243
bool XMLDateTimeFormatHdl::importXML( const OUString& rStrImpValue, css::uno::Any& rValue, const SvXMLUnitConverter& ) const
244
0
{
245
0
    rValue <<= rStrImpValue;
246
0
    return true;
247
0
}
248
249
bool XMLDateTimeFormatHdl::exportXML( OUString& rStrExpValue, const css::uno::Any& rValue, const SvXMLUnitConverter& ) const
250
0
{
251
0
    sal_Int32 nNumberFormat = 0;
252
0
    if( mpExport && (rValue >>= nNumberFormat) )
253
0
    {
254
0
        mpExport->addDataStyle( nNumberFormat );
255
0
        rStrExpValue = mpExport->getDataStyleName( nNumberFormat );
256
0
        return true;
257
0
    }
258
259
0
    return false;
260
0
}
261
262
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */