Coverage Report

Created: 2026-11-06 11:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/xmloff/source/style/xmlbahdl.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 <xmlbahdl.hxx>
21
22
#include <XMLNumberWithAutoForVoidPropHdl.hxx>
23
#include <sal/log.hxx>
24
#include <o3tl/any.hxx>
25
#include <o3tl/safeint.hxx>
26
#include <o3tl/string_view.hxx>
27
#include <sax/tools/converter.hxx>
28
#include <xmloff/xmluconv.hxx>
29
#include <com/sun/star/uno/Any.hxx>
30
#include <com/sun/star/beans/Pair.hpp>
31
#include <xmloff/xmltoken.hxx>
32
33
#include <limits.h>
34
35
using namespace ::com::sun::star::uno;
36
using namespace ::xmloff::token;
37
38
static void lcl_xmloff_setAny( Any& rValue, sal_Int32 nValue, sal_Int8 nBytes )
39
136k
{
40
136k
    switch( nBytes )
41
136k
    {
42
259
    case 1:
43
259
        if( nValue < SCHAR_MIN )
44
0
            nValue = SCHAR_MIN;
45
259
        else if( nValue > SCHAR_MAX )
46
2
            nValue = SCHAR_MAX;
47
259
        rValue <<= static_cast<sal_Int8>(nValue);
48
259
        break;
49
33.6k
    case 2:
50
33.6k
        if( nValue < SHRT_MIN )
51
3
            nValue = SHRT_MIN;
52
33.6k
        else if( nValue > SHRT_MAX )
53
4
            nValue = SHRT_MAX;
54
33.6k
        rValue <<= static_cast<sal_Int16>(nValue);
55
33.6k
        break;
56
102k
    case 4:
57
102k
        rValue <<= nValue;
58
102k
        break;
59
136k
    }
60
136k
}
61
62
static bool lcl_xmloff_getAny( const Any& rValue, sal_Int32& nValue,
63
                            sal_Int8 nBytes )
64
2.64k
{
65
2.64k
    bool bRet = false;
66
67
2.64k
    switch( nBytes )
68
2.64k
    {
69
0
    case 1:
70
0
        {
71
0
            sal_Int8 nValue8 = 0;
72
0
            bRet = rValue >>= nValue8;
73
0
            nValue = nValue8;
74
0
        }
75
0
        break;
76
1.24k
    case 2:
77
1.24k
        {
78
1.24k
            sal_Int16 nValue16 = 0;
79
1.24k
            bRet = rValue >>= nValue16;
80
1.24k
            nValue = nValue16;
81
1.24k
        }
82
1.24k
        break;
83
1.40k
    case 4:
84
1.40k
        bRet = rValue >>= nValue;
85
1.40k
        break;
86
2.64k
    }
87
88
2.64k
    return bRet;
89
2.64k
}
90
91
92
XMLNumberPropHdl::~XMLNumberPropHdl()
93
232k
{
94
    // nothing to do
95
232k
}
96
97
bool XMLNumberPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
98
7.58k
{
99
7.58k
    sal_Int32 nValue = 0;
100
7.58k
    bool bRet = ::sax::Converter::convertNumber( nValue, rStrImpValue );
101
7.58k
    lcl_xmloff_setAny( rValue, nValue, nBytes );
102
103
7.58k
    return bRet;
104
7.58k
}
105
106
bool XMLNumberPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
107
0
{
108
0
    bool bRet = false;
109
0
    sal_Int32 nValue;
110
111
0
    if( lcl_xmloff_getAny( rValue, nValue, nBytes ) )
112
0
    {
113
0
        rStrExpValue = OUString::number( nValue );
114
115
0
        bRet = true;
116
0
    }
117
118
0
    return bRet;
119
0
}
120
121
122
XMLNumberNonePropHdl::XMLNumberNonePropHdl( sal_Int8 nB ) :
123
43.0k
    sZeroStr( GetXMLToken(XML_NO_LIMIT) ),
124
43.0k
    nBytes( nB )
125
43.0k
{
126
43.0k
}
127
128
XMLNumberNonePropHdl::XMLNumberNonePropHdl( enum XMLTokenEnum eZeroString, sal_Int8 nB ) :
129
2.60k
    sZeroStr( GetXMLToken( eZeroString ) ),
130
2.60k
    nBytes( nB )
131
2.60k
{
132
2.60k
}
133
134
XMLNumberNonePropHdl::~XMLNumberNonePropHdl()
135
45.6k
{
136
    // nothing to do
137
45.6k
}
138
139
bool XMLNumberNonePropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
140
1.67k
{
141
1.67k
    bool bRet = false;
142
143
1.67k
    sal_Int32 nValue = 0;
144
1.67k
    if( rStrImpValue == sZeroStr )
145
1.66k
    {
146
1.66k
        bRet = true;
147
1.66k
    }
148
15
    else
149
15
    {
150
15
        bRet = ::sax::Converter::convertNumber( nValue, rStrImpValue );
151
15
    }
152
1.67k
    lcl_xmloff_setAny( rValue, nValue, nBytes );
153
154
1.67k
    return bRet;
155
1.67k
}
156
157
bool XMLNumberNonePropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
158
0
{
159
0
    bool bRet = false;
160
0
    sal_Int32 nValue;
161
162
0
    if( lcl_xmloff_getAny( rValue, nValue, nBytes ) )
163
0
    {
164
0
        if( nValue == 0 )
165
0
        {
166
0
            rStrExpValue = sZeroStr;
167
0
        }
168
0
        else
169
0
        {
170
0
            rStrExpValue = OUString::number( nValue );
171
0
        }
172
173
0
        bRet = true;
174
0
    }
175
176
0
    return bRet;
177
0
}
178
179
180
XMLMeasurePropHdl::~XMLMeasurePropHdl()
181
151k
{
182
    // nothing to do
183
151k
}
184
185
bool XMLMeasurePropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
186
91.8k
{
187
91.8k
    sal_Int32 nValue = 0;
188
91.8k
    bool bRet = rUnitConverter.convertMeasureToCore( nValue, rStrImpValue );
189
91.8k
    lcl_xmloff_setAny( rValue, nValue, nBytes );
190
91.8k
    return bRet;
191
91.8k
}
192
193
bool XMLMeasurePropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
194
1.40k
{
195
1.40k
    bool bRet = false;
196
1.40k
    sal_Int32 nValue;
197
198
1.40k
    if( lcl_xmloff_getAny( rValue, nValue, nBytes ) )
199
1.40k
    {
200
1.40k
        OUStringBuffer aOut;
201
1.40k
        rUnitConverter.convertMeasureToXML( aOut, nValue );
202
1.40k
        rStrExpValue = aOut.makeStringAndClear();
203
204
1.40k
        bRet = true;
205
1.40k
    }
206
207
1.40k
    return bRet;
208
1.40k
}
209
210
211
bool XMLUnitMeasurePropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
212
0
{
213
0
    double fValue = 0.0;
214
0
    std::optional<sal_Int16> nValueUnit;
215
216
0
    auto bRet = ::sax::Converter::convertMeasureUnit( fValue, nValueUnit, rStrImpValue );
217
218
0
    if(bRet)
219
0
    {
220
        // This importer may only accept font-relative units.
221
        // Discard all other units to allow fall-through to other attributes.
222
0
        if (css::util::MeasureUnit::FONT_EM != nValueUnit
223
0
            && css::util::MeasureUnit::FONT_CJK_ADVANCE != nValueUnit)
224
0
        {
225
0
            return false;
226
0
        }
227
228
0
        css::beans::Pair<double, sal_Int16> stValue{fValue, nValueUnit.value()};
229
0
        rValue <<= stValue;
230
0
    }
231
232
0
    return bRet;
233
0
}
234
235
bool XMLUnitMeasurePropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
236
141
{
237
141
    bool bRet = false;
238
141
    css::beans::Pair<double, sal_Int16> stValue{0.0, css::util::MeasureUnit::MM_100TH};
239
240
141
    if( rValue >>= stValue )
241
0
    {
242
0
        auto [fValue, nValueUnit] = stValue;
243
244
        // This exporter may only produce font-relative units.
245
        // Discard all other units to allow fall-through to other attributes.
246
0
        if (css::util::MeasureUnit::FONT_EM != nValueUnit
247
0
            && css::util::MeasureUnit::FONT_CJK_ADVANCE != nValueUnit)
248
0
        {
249
0
            return false;
250
0
        }
251
252
0
        OUStringBuffer aOut;
253
0
        ::sax::Converter::convertMeasureUnit( aOut, fValue, nValueUnit );
254
0
        rStrExpValue = aOut.makeStringAndClear();
255
256
0
        bRet = true;
257
0
    }
258
259
141
    return bRet;
260
141
}
261
262
263
XMLBoolFalsePropHdl::~XMLBoolFalsePropHdl()
264
0
{
265
    // nothing to do
266
0
}
267
268
bool XMLBoolFalsePropHdl::importXML( const OUString&, Any&, const SvXMLUnitConverter& ) const
269
0
{
270
0
    return false;
271
0
}
272
273
bool XMLBoolFalsePropHdl::exportXML( OUString& rStrExpValue, const Any& /*rValue*/, const SvXMLUnitConverter& rCnv) const
274
0
{
275
0
    return XMLBoolPropHdl::exportXML( rStrExpValue, Any( false ), rCnv );
276
0
}
277
278
279
XMLBoolPropHdl::~XMLBoolPropHdl()
280
159k
{
281
    // nothing to do
282
159k
}
283
284
bool XMLBoolPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
285
53.1k
{
286
53.1k
    bool bValue(false);
287
53.1k
    bool const bRet = ::sax::Converter::convertBool( bValue, rStrImpValue );
288
53.1k
    rValue <<= bValue;
289
290
53.1k
    return bRet;
291
53.1k
}
292
293
bool XMLBoolPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
294
928
{
295
928
    bool bRet = false;
296
928
    bool bValue;
297
298
928
    if (rValue >>= bValue)
299
928
    {
300
928
        OUStringBuffer aOut;
301
928
        ::sax::Converter::convertBool( aOut, bValue );
302
928
        rStrExpValue = aOut.makeStringAndClear();
303
304
928
        bRet = true;
305
928
    }
306
307
928
    return bRet;
308
928
}
309
310
311
XMLNBoolPropHdl::~XMLNBoolPropHdl()
312
23.1k
{
313
    // nothing to do
314
23.1k
}
315
316
bool XMLNBoolPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
317
1
{
318
1
    bool bValue(false);
319
1
    bool const bRet = ::sax::Converter::convertBool( bValue, rStrImpValue );
320
1
    rValue <<= !bValue;
321
322
1
    return bRet;
323
1
}
324
325
bool XMLNBoolPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
326
0
{
327
0
    bool bRet = false;
328
0
    bool bValue;
329
330
0
    if (rValue >>= bValue)
331
0
    {
332
0
        OUStringBuffer aOut;
333
0
        ::sax::Converter::convertBool( aOut, !bValue );
334
0
        rStrExpValue = aOut.makeStringAndClear();
335
336
0
        bRet = true;
337
0
    }
338
339
0
    return bRet;
340
0
}
341
342
343
XMLPercentPropHdl::~XMLPercentPropHdl()
344
250k
{
345
    // nothing to do
346
250k
}
347
348
bool XMLPercentPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
349
31.7k
{
350
31.7k
    sal_Int32 nValue = 0;
351
31.7k
    bool const bRet = ::sax::Converter::convertPercent( nValue, rStrImpValue );
352
31.7k
    lcl_xmloff_setAny( rValue, nValue, nBytes );
353
354
31.7k
    return bRet;
355
31.7k
}
356
357
bool XMLPercentPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
358
554
{
359
554
    bool bRet = false;
360
554
    sal_Int32 nValue;
361
362
554
    if( lcl_xmloff_getAny( rValue, nValue, nBytes ) )
363
554
    {
364
554
        OUStringBuffer aOut;
365
554
        ::sax::Converter::convertPercent( aOut, nValue );
366
554
        rStrExpValue = aOut.makeStringAndClear();
367
368
554
        bRet = true;
369
554
    }
370
371
554
    return bRet;
372
554
}
373
374
375
bool XMLDoublePercentPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
376
416
{
377
416
    bool bRet = false;
378
379
416
    double fValue = 1.0;
380
381
416
    if( rStrImpValue.indexOf( '%' ) == -1 )
382
1
    {
383
1
        fValue = rStrImpValue.toDouble();
384
1
    }
385
415
    else
386
415
    {
387
415
        sal_Int32 nValue = 0;
388
415
        bRet = ::sax::Converter::convertPercent( nValue, rStrImpValue );
389
415
        fValue = static_cast<double>(nValue) / 100.0;
390
415
    }
391
416
    rValue <<= fValue;
392
393
416
    return bRet;
394
416
}
395
396
bool XMLDoublePercentPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
397
9
{
398
9
    bool bRet = false;
399
9
    double fValue = 0;
400
401
9
    if( rValue >>= fValue )
402
9
    {
403
9
        fValue *= 100.0;
404
9
        if( fValue > 0 ) fValue += 0.5; else    fValue -= 0.5;
405
406
9
        sal_Int32 nValue = static_cast<sal_Int32>(fValue);
407
408
9
        OUStringBuffer aOut;
409
9
        ::sax::Converter::convertPercent( aOut, nValue );
410
9
        rStrExpValue = aOut.makeStringAndClear();
411
412
9
        bRet = true;
413
9
    }
414
415
9
    return bRet;
416
9
}
417
418
bool XML100thPercentPropHdl::importXML(const OUString& rStrImpValue, Any& rValue,
419
                                       const SvXMLUnitConverter&) const
420
0
{
421
0
    bool bRet = false;
422
423
0
    sal_Int32 nValue = 0;
424
0
    bRet = sax::Converter::convertPercent(nValue, rStrImpValue);
425
0
    rValue <<= static_cast<sal_Int16>(nValue * 100);
426
427
0
    return bRet;
428
0
}
429
430
bool XML100thPercentPropHdl::exportXML(OUString& rStrExpValue, const Any& rValue,
431
                                       const SvXMLUnitConverter&) const
432
0
{
433
0
    bool bRet = false;
434
0
    sal_Int16 nValue = 0;
435
436
0
    if (rValue >>= nValue)
437
0
    {
438
0
        nValue = std::round(static_cast<double>(nValue) / 100);
439
0
        OUStringBuffer aOut;
440
0
        sax::Converter::convertPercent(aOut, nValue);
441
0
        rStrExpValue = aOut.makeStringAndClear();
442
0
        bRet = true;
443
0
    }
444
445
0
    return bRet;
446
0
}
447
448
449
XMLNegPercentPropHdl::~XMLNegPercentPropHdl()
450
168k
{
451
    // nothing to do
452
168k
}
453
454
bool XMLNegPercentPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
455
914
{
456
914
    sal_Int32 nValue = 0;
457
914
    bool bRet = ::sax::Converter::convertPercent( nValue, rStrImpValue );
458
914
    if (!bRet)
459
19
        return false;
460
895
    if (nValue < 0 || nValue > 100)
461
147
    {
462
147
        SAL_WARN("xmloff", "Percentage property out of range, ignoring");
463
147
        return false;
464
147
    }
465
748
    bRet = !o3tl::checked_sub<sal_Int32>(100, nValue, nValue);
466
748
    if (bRet)
467
748
        lcl_xmloff_setAny( rValue, nValue, nBytes );
468
748
    return bRet;
469
895
}
470
471
bool XMLNegPercentPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
472
687
{
473
687
    bool bRet = false;
474
687
    sal_Int32 nValue;
475
476
687
    if( lcl_xmloff_getAny( rValue, nValue, nBytes ) )
477
687
    {
478
687
        OUStringBuffer aOut;
479
687
        ::sax::Converter::convertPercent( aOut, 100-nValue );
480
687
        rStrExpValue = aOut.makeStringAndClear();
481
482
687
        bRet = true;
483
687
    }
484
485
687
    return bRet;
486
687
}
487
488
XMLMeasurePxPropHdl::~XMLMeasurePxPropHdl()
489
50.0k
{
490
    // nothing to do
491
50.0k
}
492
493
bool XMLMeasurePxPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
494
0
{
495
0
    sal_Int32 nValue = 0;
496
0
    bool bRet = ::sax::Converter::convertMeasurePx( nValue, rStrImpValue );
497
0
    lcl_xmloff_setAny( rValue, nValue, nBytes );
498
0
    return bRet;
499
0
}
500
501
bool XMLMeasurePxPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
502
0
{
503
0
    bool bRet = false;
504
0
    sal_Int32 nValue;
505
506
0
    if( lcl_xmloff_getAny( rValue, nValue, nBytes ) )
507
0
    {
508
0
        OUStringBuffer aOut;
509
0
        ::sax::Converter::convertMeasurePx( aOut, nValue );
510
0
        rStrExpValue = aOut.makeStringAndClear();
511
512
0
        bRet = true;
513
0
    }
514
515
0
    return bRet;
516
0
}
517
518
519
XMLColorPropHdl::~XMLColorPropHdl()
520
119k
{
521
    // Nothing to do
522
119k
}
523
524
bool XMLColorPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
525
4.81k
{
526
4.81k
    bool bRet = false;
527
528
4.81k
    if( rStrImpValue.matchIgnoreAsciiCase( "hsl" ) )
529
0
    {
530
0
        sal_Int32 nOpen = rStrImpValue.indexOf( '(' );
531
0
        sal_Int32 nClose = rStrImpValue.lastIndexOf( ')' );
532
533
0
        if( (nOpen != -1) && (nClose > nOpen) )
534
0
        {
535
0
            const std::u16string_view aTmp( rStrImpValue.subView( nOpen+1, nClose - nOpen-1) );
536
537
0
            sal_Int32 nIndex = 0;
538
539
0
            Sequence< double > aHSL
540
0
            {
541
0
                o3tl::toDouble(o3tl::getToken(aTmp, 0, ',', nIndex )),
542
0
                o3tl::toDouble(o3tl::getToken(aTmp, 0, ',', nIndex )) / 100.0,
543
0
                o3tl::toDouble(o3tl::getToken(aTmp, 0, ',', nIndex )) / 100.0
544
0
            };
545
0
            rValue <<= aHSL;
546
0
            bRet = true;
547
0
        }
548
0
    }
549
4.81k
    else
550
4.81k
    {
551
4.81k
        sal_Int32 nColor(0);
552
4.81k
        bRet = ::sax::Converter::convertColor( nColor, rStrImpValue );
553
4.81k
        rValue <<= nColor;
554
4.81k
    }
555
556
4.81k
    return bRet;
557
4.81k
}
558
559
bool XMLColorPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
560
1.00k
{
561
1.00k
    bool bRet = false;
562
1.00k
    sal_Int32 nColor = 0;
563
564
1.00k
    OUStringBuffer aOut;
565
1.00k
    if( rValue >>= nColor )
566
1.00k
    {
567
1.00k
        ::sax::Converter::convertColor( aOut, nColor );
568
1.00k
        rStrExpValue = aOut.makeStringAndClear();
569
570
1.00k
        bRet = true;
571
1.00k
    }
572
0
    else
573
0
    {
574
0
        Sequence< double > aHSL;
575
0
        if( (rValue >>= aHSL) && (aHSL.getLength() == 3) )
576
0
        {
577
0
            rStrExpValue = "hsl(" + OUString::number(aHSL[0]) + "," +
578
0
                    OUString::number(aHSL[1] * 100.0) +  "%," +
579
0
                    OUString::number(aHSL[2] * 100.0) + "%)";
580
581
0
            bRet = true;
582
0
        }
583
0
    }
584
585
1.00k
    return bRet;
586
1.00k
}
587
588
589
XMLHexPropHdl::~XMLHexPropHdl()
590
66.0k
{
591
    // Nothing to do
592
66.0k
}
593
594
bool XMLHexPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
595
1.05k
{
596
1.05k
    sal_uInt32 nRsid;
597
1.05k
    bool bRet = SvXMLUnitConverter::convertHex( nRsid, rStrImpValue );
598
1.05k
    rValue <<= nRsid;
599
600
1.05k
    return bRet;
601
1.05k
}
602
603
bool XMLHexPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
604
0
{
605
0
    bool bRet = false;
606
0
    sal_uInt32 nRsid = 0;
607
608
0
    if( rValue >>= nRsid )
609
0
    {
610
0
        OUStringBuffer aOut;
611
0
        SvXMLUnitConverter::convertHex( aOut, nRsid );
612
0
        rStrExpValue = aOut.makeStringAndClear();
613
614
0
        bRet = true;
615
0
    }
616
0
    else
617
0
    {
618
0
        bRet = false;
619
0
    }
620
621
0
    return bRet;
622
0
}
623
624
625
XMLStringPropHdl::~XMLStringPropHdl()
626
245k
{
627
    // Nothing to do
628
245k
}
629
630
bool XMLStringPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
631
1.65k
{
632
1.65k
    rValue <<= rStrImpValue;
633
1.65k
    return true;
634
1.65k
}
635
636
bool XMLStringPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
637
1.04k
{
638
1.04k
    bool bRet = false;
639
640
1.04k
    if( rValue >>= rStrExpValue )
641
1.04k
        bRet = true;
642
643
1.04k
    return bRet;
644
1.04k
}
645
646
647
XMLStyleNamePropHdl::~XMLStyleNamePropHdl()
648
{
649
    // Nothing to do
650
}
651
652
bool XMLStyleNamePropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
653
486
{
654
486
    bool bRet = false;
655
656
486
    if( rValue >>= rStrExpValue )
657
486
    {
658
486
        rStrExpValue = rUnitConverter.encodeStyleName( rStrExpValue );
659
486
        bRet = true;
660
486
    }
661
662
486
    return bRet;
663
486
}
664
665
666
XMLDoublePropHdl::~XMLDoublePropHdl()
667
17.0k
{
668
    // Nothing to do
669
17.0k
}
670
671
bool XMLDoublePropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
672
0
{
673
0
    double fDblValue(0.0);
674
0
    bool const bRet = ::sax::Converter::convertDouble(fDblValue, rStrImpValue);
675
0
    rValue <<= fDblValue;
676
0
    return bRet;
677
0
}
678
679
bool XMLDoublePropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
680
0
{
681
0
    bool bRet = false;
682
683
0
    double fValue = 0;
684
685
0
    if( rValue >>= fValue )
686
0
    {
687
0
        OUStringBuffer aOut;
688
0
        ::sax::Converter::convertDouble( aOut, fValue );
689
0
        rStrExpValue = aOut.makeStringAndClear();
690
0
        bRet = true;
691
0
    }
692
693
0
    return bRet;
694
0
}
695
696
697
XMLColorTransparentPropHdl::XMLColorTransparentPropHdl(
698
    enum XMLTokenEnum eTransparent ) :
699
272k
    sTransparent( GetXMLToken(
700
272k
        eTransparent != XML_TOKEN_INVALID ? eTransparent : XML_TRANSPARENT ) )
701
272k
{
702
    // Nothing to do
703
272k
}
704
705
XMLColorTransparentPropHdl::~XMLColorTransparentPropHdl()
706
272k
{
707
    // Nothing to do
708
272k
}
709
710
bool XMLColorTransparentPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
711
2.99k
{
712
2.99k
    bool bRet = false;
713
714
2.99k
    if( rStrImpValue != sTransparent )
715
2.52k
    {
716
2.52k
        sal_Int32 nColor(0);
717
2.52k
        bRet = ::sax::Converter::convertColor( nColor, rStrImpValue );
718
2.52k
        rValue <<= nColor;
719
2.52k
    }
720
721
2.99k
    return bRet;
722
2.99k
}
723
724
bool XMLColorTransparentPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
725
255
{
726
255
    bool bRet = false;
727
255
    sal_Int32 nColor = 0;
728
729
255
    if( rStrExpValue == sTransparent )
730
0
        bRet = false;
731
255
    else if( rValue >>= nColor )
732
255
    {
733
255
        OUStringBuffer aOut;
734
255
        ::sax::Converter::convertColor( aOut, nColor );
735
255
        rStrExpValue = aOut.makeStringAndClear();
736
737
255
        bRet = true;
738
255
    }
739
740
255
    return bRet;
741
255
}
742
743
744
XMLIsTransparentPropHdl::XMLIsTransparentPropHdl(
745
    enum XMLTokenEnum eTransparent, bool bTransPropVal ) :
746
264k
    sTransparent( GetXMLToken(
747
264k
        eTransparent != XML_TOKEN_INVALID ? eTransparent : XML_TRANSPARENT ) ),
748
264k
    bTransPropValue( bTransPropVal )
749
264k
{
750
264k
}
751
752
XMLIsTransparentPropHdl::~XMLIsTransparentPropHdl()
753
264k
{
754
    // Nothing to do
755
264k
}
756
757
bool XMLIsTransparentPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
758
2.99k
{
759
2.99k
    bool bValue = ( (rStrImpValue == sTransparent) == bTransPropValue);
760
2.99k
    rValue <<= bValue;
761
762
2.99k
    return true;
763
2.99k
}
764
765
bool XMLIsTransparentPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
766
255
{
767
255
    bool bRet = false;
768
769
    // MIB: This looks a bit strange, because bTransPropValue == bValue should
770
    // do the same, but this only applies if 'true' is represented by the same
771
    // 8 bit value in bValue and bTransPropValue. Who will ensure this?
772
255
    bool bValue = *o3tl::doAccess<bool>(rValue);
773
255
    bool bIsTrans = bTransPropValue ? bValue : !bValue;
774
775
255
    if( bIsTrans )
776
255
    {
777
255
        rStrExpValue = sTransparent;
778
255
        bRet = true;
779
255
    }
780
781
255
    return bRet;
782
255
}
783
784
785
XMLColorAutoPropHdl::XMLColorAutoPropHdl()
786
73.6k
{
787
    // Nothing to do
788
73.6k
}
789
790
XMLColorAutoPropHdl::~XMLColorAutoPropHdl()
791
73.6k
{
792
    // Nothing to do
793
73.6k
}
794
795
bool XMLColorAutoPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
796
18.6k
{
797
18.6k
    bool bRet = false;
798
799
    // This is a multi property: the value might be set to AUTO_COLOR
800
    // already by the XMLIsAutoColorPropHdl!
801
18.6k
    sal_Int32 nColor = 0;
802
18.6k
    if( !(rValue >>= nColor) || -1 != nColor )
803
18.6k
    {
804
18.6k
        bRet = ::sax::Converter::convertColor( nColor, rStrImpValue );
805
18.6k
        if( bRet )
806
11.9k
            rValue <<= nColor;
807
18.6k
    }
808
809
18.6k
    return bRet;
810
18.6k
}
811
812
bool XMLColorAutoPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
813
678
{
814
678
    bool bRet = false;
815
816
678
    sal_Int32 nColor = 0;
817
678
    if( (rValue >>= nColor) && -1 != nColor )
818
584
    {
819
584
        OUStringBuffer aOut;
820
584
        ::sax::Converter::convertColor( aOut, nColor );
821
584
        rStrExpValue = aOut.makeStringAndClear();
822
823
584
        bRet = true;
824
584
    }
825
826
678
    return bRet;
827
678
}
828
829
830
XMLIsAutoColorPropHdl::XMLIsAutoColorPropHdl()
831
73.6k
{
832
73.6k
}
833
834
XMLIsAutoColorPropHdl::~XMLIsAutoColorPropHdl()
835
73.6k
{
836
    // Nothing to do
837
73.6k
}
838
839
bool XMLIsAutoColorPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
840
3.89k
{
841
    // An auto color overrides any other color set!
842
3.89k
    bool bValue;
843
3.89k
    bool const bRet = ::sax::Converter::convertBool( bValue, rStrImpValue );
844
3.89k
    if( bRet && bValue )
845
3.82k
        rValue <<= sal_Int32(-1);
846
847
3.89k
    return true;
848
3.89k
}
849
850
bool XMLIsAutoColorPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
851
678
{
852
678
    bool bRet = false;
853
678
    sal_Int32 nColor = 0;
854
855
678
    if( (rValue >>= nColor) && -1 == nColor )
856
94
    {
857
94
        OUStringBuffer aOut;
858
94
        ::sax::Converter::convertBool( aOut, true );
859
94
        rStrExpValue = aOut.makeStringAndClear();
860
861
94
        bRet = true;
862
94
    }
863
864
678
    return bRet;
865
678
}
866
867
868
XMLCompareOnlyPropHdl::~XMLCompareOnlyPropHdl()
869
118k
{
870
    // Nothing to do
871
118k
}
872
873
bool XMLCompareOnlyPropHdl::importXML( const OUString&, Any&, const SvXMLUnitConverter& ) const
874
0
{
875
0
    SAL_WARN( "xmloff", "importXML called for compare-only-property" );
876
0
    return false;
877
0
}
878
879
bool XMLCompareOnlyPropHdl::exportXML( OUString&, const Any&, const SvXMLUnitConverter& ) const
880
0
{
881
0
    SAL_WARN( "xmloff", "exportXML called for compare-only-property" );
882
0
    return false;
883
0
}
884
885
886
XMLNumberWithoutZeroPropHdl::XMLNumberWithoutZeroPropHdl( sal_Int8 nB ) :
887
43.0k
    nBytes( nB )
888
43.0k
{
889
43.0k
}
890
891
XMLNumberWithoutZeroPropHdl::~XMLNumberWithoutZeroPropHdl()
892
43.0k
{
893
43.0k
}
894
895
bool XMLNumberWithoutZeroPropHdl::importXML(
896
    const OUString& rStrImpValue,
897
    Any& rValue,
898
    const SvXMLUnitConverter& ) const
899
2.34k
{
900
2.34k
    sal_Int32 nValue = 0;
901
2.34k
    bool const bRet = ::sax::Converter::convertNumber( nValue, rStrImpValue );
902
2.34k
    if( bRet )
903
2.34k
        lcl_xmloff_setAny( rValue, nValue, nBytes );
904
2.34k
    return bRet;
905
2.34k
}
906
907
bool XMLNumberWithoutZeroPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
908
0
{
909
910
0
    sal_Int32 nValue = 0;
911
0
    bool bRet = lcl_xmloff_getAny( rValue, nValue, nBytes );
912
0
    bRet &= nValue != 0;
913
914
0
    if( bRet )
915
0
    {
916
0
        rStrExpValue = OUString::number(nValue);
917
0
    }
918
919
0
    return bRet;
920
0
}
921
922
923
XMLNumberWithAutoForVoidPropHdl::~XMLNumberWithAutoForVoidPropHdl()
924
43.0k
{
925
43.0k
}
926
927
bool XMLNumberWithAutoForVoidPropHdl::importXML(
928
    const OUString& rStrImpValue,
929
    Any& rValue,
930
    const SvXMLUnitConverter& ) const
931
980
{
932
980
    sal_Int32 nValue = 0;
933
980
    bool bRet = ::sax::Converter::convertNumber( nValue, rStrImpValue );
934
980
    if( bRet )
935
0
        lcl_xmloff_setAny( rValue, nValue, 2 );
936
980
    else if( rStrImpValue == GetXMLToken( XML_AUTO ) )
937
977
    {
938
977
        rValue.clear(); // void
939
977
        bRet = true;
940
977
    }
941
980
    return bRet;
942
980
}
943
944
bool XMLNumberWithAutoForVoidPropHdl::exportXML(
945
        OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter&) const
946
0
{
947
948
0
    sal_Int32 nValue = 0;
949
0
    bool bRet = lcl_xmloff_getAny( rValue, nValue, 2 );
950
951
    // note: 0 is a valid value here, see CTF_PAGENUMBEROFFSET for when it isn't
952
953
0
    if (!bRet)
954
0
        rStrExpValue = GetXMLToken( XML_AUTO );
955
0
    else
956
0
    {
957
0
        rStrExpValue = OUString::number(nValue);
958
0
    }
959
960
0
    return true;
961
0
}
962
963
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */