Coverage Report

Created: 2025-12-31 10:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/xmloff/source/chart/XMLChartStyleContext.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 <XMLChartStyleContext.hxx>
21
#include <xmloff/xmltoken.hxx>
22
#include <xmloff/xmlnamespace.hxx>
23
#include <xmloff/xmlnumfi.hxx>
24
#include <xmloff/families.hxx>
25
#include <xmloff/xmltypes.hxx>
26
#include <xmloff/xmlimp.hxx>
27
#include <xmloff/xmlimppr.hxx>
28
29
#include <com/sun/star/beans/XPropertySet.hpp>
30
#include <comphelper/diagnose_ex.hxx>
31
32
#include "XMLChartPropertyContext.hxx"
33
34
using namespace com::sun::star;
35
using ::xmloff::token::XML_DATA_STYLE_NAME;
36
using ::xmloff::token::XML_PERCENTAGE_DATA_STYLE_NAME;
37
using ::xmloff::token::XML_TEXT_PROPERTIES;
38
using ::xmloff::token::XML_PARAGRAPH_PROPERTIES;
39
using ::xmloff::token::XML_GRAPHIC_PROPERTIES;
40
using ::xmloff::token::XML_CHART_PROPERTIES;
41
42
void XMLChartStyleContext::SetAttribute(
43
    sal_Int32 nElement,
44
    const OUString& rValue )
45
1.60k
{
46
1.60k
    switch (nElement & TOKEN_MASK)
47
1.60k
    {
48
212
        case XML_DATA_STYLE_NAME:
49
212
            msDataStyleName = rValue;
50
212
            break;
51
0
        case XML_PERCENTAGE_DATA_STYLE_NAME:
52
0
            msPercentageDataStyleName = rValue;
53
0
            break;
54
1.39k
        default:
55
1.39k
            XMLShapeStyleContext::SetAttribute( nElement, rValue );
56
1.60k
    }
57
1.60k
}
58
59
XMLChartStyleContext::XMLChartStyleContext(
60
    SvXMLImport& rImport,
61
    SvXMLStylesContext& rStyles, XmlStyleFamily nFamily ) :
62
698
        XMLShapeStyleContext( rImport, rStyles, nFamily ),
63
698
        mrStyles( rStyles )
64
698
{}
65
66
XMLChartStyleContext::~XMLChartStyleContext()
67
698
{}
68
69
namespace
70
{
71
72
void lcl_NumberFormatStyleToProperty( const OUString& rStyleName, const OUString& rPropertyName,
73
        const SvXMLStylesContext& rStylesContext,
74
        const uno::Reference< beans::XPropertySet >& rPropSet )
75
0
{
76
0
    if( !rStyleName.isEmpty())
77
0
    {
78
0
        const SvXMLNumFormatContext* pStyle = static_cast<const SvXMLNumFormatContext *>(rStylesContext.FindStyleChildContext(
79
0
            XmlStyleFamily::DATA_STYLE, rStyleName, true ));
80
0
        if( pStyle )
81
0
        {
82
0
            sal_Int32 nNumberFormat = const_cast<SvXMLNumFormatContext*>(pStyle)->GetKey();
83
0
            rPropSet->setPropertyValue( rPropertyName, uno::Any(nNumberFormat) );
84
0
        }
85
0
    }
86
0
}
87
88
}
89
90
void XMLChartStyleContext::FillPropertySet(
91
    const uno::Reference< beans::XPropertySet > & rPropSet )
92
0
{
93
0
    try
94
0
    {
95
0
        XMLShapeStyleContext::FillPropertySet( rPropSet );
96
0
    }
97
0
    catch( beans::UnknownPropertyException&  )
98
0
    {
99
0
        TOOLS_WARN_EXCEPTION( "xmloff", "unknown property exception -> shape style not completely imported for chart style" );
100
0
    }
101
102
0
    lcl_NumberFormatStyleToProperty( msDataStyleName, u"NumberFormat"_ustr, mrStyles, rPropSet );
103
0
    lcl_NumberFormatStyleToProperty( msPercentageDataStyleName, u"PercentageNumberFormat"_ustr, mrStyles, rPropSet );
104
0
}
105
106
css::uno::Reference< css::xml::sax::XFastContextHandler > XMLChartStyleContext::createFastChildContext(
107
    sal_Int32 nElement,
108
    const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
109
1.38k
{
110
1.38k
    if( IsTokenInNamespace(nElement, XML_NAMESPACE_STYLE) ||
111
24
        IsTokenInNamespace(nElement, XML_NAMESPACE_LO_EXT) )
112
1.36k
    {
113
1.36k
        sal_Int32 nLocalName = nElement & TOKEN_MASK;
114
1.36k
        sal_uInt32 nFamily = 0;
115
1.36k
        if( nLocalName == XML_TEXT_PROPERTIES )
116
425
            nFamily = XML_TYPE_PROP_TEXT;
117
938
        else if( nLocalName == XML_PARAGRAPH_PROPERTIES )
118
0
            nFamily = XML_TYPE_PROP_PARAGRAPH;
119
938
        else if( nLocalName == XML_GRAPHIC_PROPERTIES )
120
441
            nFamily = XML_TYPE_PROP_GRAPHIC;
121
497
        else if( nLocalName == XML_CHART_PROPERTIES )
122
470
            nFamily = XML_TYPE_PROP_CHART;
123
1.36k
        if( nFamily )
124
1.33k
        {
125
1.33k
            SvXMLImportPropertyMapper* pImpPrMap =
126
1.33k
                GetStyles()->GetImportPropertyMapper( GetFamily() );
127
1.33k
            if( pImpPrMap )
128
1.33k
                return new XMLChartPropertyContext(
129
1.33k
                    GetImport(), nElement, xAttrList, nFamily,
130
1.33k
                    GetProperties(), pImpPrMap );
131
1.33k
        }
132
1.36k
    }
133
134
51
    return XMLShapeStyleContext::createFastChildContext( nElement, xAttrList );
135
1.38k
}
136
137
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */