LibreOffice Module xmloff (master) 1
SchXMLLegendContext.cxx
Go to the documentation of this file.
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
22
23#include <xmloff/xmlimp.hxx>
26#include <xmloff/xmluconv.hxx>
27
28#include <sal/log.hxx>
29
30#include <com/sun/star/chart/ChartLegendExpansion.hpp>
31#include <com/sun/star/chart/XChartDocument.hpp>
32#include <com/sun/star/drawing/FillStyle.hpp>
33
34using namespace ::xmloff::token;
35using namespace com::sun::star;
36
38 SvXMLImportContext( rImport ),
39 mrImportHelper( rImpHelper )
40{
41}
42
43void SchXMLLegendContext::startFastElement( sal_Int32 /*nElement*/,
44 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
45{
46 uno::Reference< chart::XChartDocument > xDoc = mrImportHelper.GetChartDocument();
47 if( !xDoc.is() )
48 return;
49
50 // turn on legend
51 uno::Reference< beans::XPropertySet > xDocProp( xDoc, uno::UNO_QUERY );
52 if( xDocProp.is() )
53 {
54 try
55 {
56 xDocProp->setPropertyValue("HasLegend", uno::Any( true ) );
57 }
58 catch(const beans::UnknownPropertyException&)
59 {
60 SAL_INFO("xmloff.chart", "Property HasLegend not found" );
61 }
62 }
63
64 uno::Reference< drawing::XShape > xLegendShape = xDoc->getLegend();
65 uno::Reference< beans::XPropertySet > xLegendProps( xLegendShape, uno::UNO_QUERY );
66 if( !xLegendShape.is() || !xLegendProps.is() )
67 {
68 SAL_INFO("xmloff.chart", "legend could not be created" );
69 return;
70 }
71
72 // parse attributes
73 awt::Point aLegendPos;
74 bool bOverlay = false;
75 bool bHasXPosition=false;
76 bool bHasYPosition=false;
77 awt::Size aLegendSize;
78 bool bHasWidth=false;
79 bool bHasHeight=false;
80 chart::ChartLegendExpansion nLegendExpansion = chart::ChartLegendExpansion_HIGH;
81 bool bHasExpansion=false;
82
83 OUString sAutoStyleName;
84 uno::Any aAny;
85
86 for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
87 {
88 switch(aIter.getToken())
89 {
91 try
92 {
93 if( SchXMLEnumConverter::getLegendPositionConverter().importXML( aIter.toString(), aAny, GetImport().GetMM100UnitConverter() ) )
94 xLegendProps->setPropertyValue("Alignment", aAny );
95 }
96 catch(const beans::UnknownPropertyException&)
97 {
98 SAL_INFO("xmloff.chart", "Property Alignment (legend) not found" );
99 }
100 break;
101 case XML_ELEMENT(LO_EXT, XML_OVERLAY):
102 try
103 {
104 bOverlay = aIter.toBoolean();
105 xLegendProps->setPropertyValue("Overlay", uno::Any(bOverlay));
106 }
107 catch(const beans::UnknownPropertyException&)
108 {
109 SAL_INFO("xmloff.chart", "Property Overlay (legend) not found" );
110 }
111 break;
112 case XML_ELEMENT(SVG, XML_X):
113 case XML_ELEMENT(SVG_COMPAT, XML_X):
114 GetImport().GetMM100UnitConverter().convertMeasureToCore(
115 aLegendPos.X, aIter.toView() );
116 bHasXPosition = true;
117 break;
118 case XML_ELEMENT(SVG, XML_Y):
119 case XML_ELEMENT(SVG_COMPAT, XML_Y):
120 GetImport().GetMM100UnitConverter().convertMeasureToCore(
121 aLegendPos.Y, aIter.toView() );
122 bHasYPosition = true;
123 break;
125 sAutoStyleName = aIter.toString();
126 break;
128 SchXMLEnumConverter::getLegendPositionConverter().importXML( aIter.toString(), aAny, GetImport().GetMM100UnitConverter() );
129 bHasExpansion = (aAny>>=nLegendExpansion);
130 break;
132 break;
134 case XML_ELEMENT(SVG_COMPAT, XML_WIDTH):
135 case XML_ELEMENT(CHART_EXT, XML_WIDTH):
136 GetImport().GetMM100UnitConverter().convertMeasureToCore(
137 aLegendSize.Width, aIter.toView() );
138 bHasWidth = true;
139 break;
141 case XML_ELEMENT(SVG_COMPAT, XML_HEIGHT):
142 case XML_ELEMENT(CHART_EXT, XML_HEIGHT):
143 GetImport().GetMM100UnitConverter().convertMeasureToCore(
144 aLegendSize.Height, aIter.toView() );
145 bHasHeight = true;
146 break;
147 default:
148 XMLOFF_WARN_UNKNOWN("xmloff", aIter);
149 break;
150 }
151 }
152
153 if( bHasExpansion && nLegendExpansion!= chart::ChartLegendExpansion_CUSTOM )
154 xLegendProps->setPropertyValue("Expansion", uno::Any(nLegendExpansion) );
155 else if( bHasHeight && bHasWidth )
156 xLegendShape->setSize( aLegendSize );
157
158 if( bHasXPosition && bHasYPosition )
159 xLegendShape->setPosition( aLegendPos );
160
161 // the fill style has the default "none" in XML, but "solid" in the model.
162 xLegendProps->setPropertyValue("FillStyle", uno::Any( drawing::FillStyle_NONE ));
163
164 // set auto-styles for Legend
165 mrImportHelper.FillAutoStyle(sAutoStyleName, xLegendProps);
166}
167
169{
170}
171
172/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static XMLEnumPropertyHdl & getLegendPositionConverter()
With this class you can import a <chart:chart> element containing its data as <table:table> element o...
const css::uno::Reference< css::chart::XChartDocument > & GetChartDocument() const
void FillAutoStyle(const OUString &rAutoStyleName, const css::uno::Reference< css::beans::XPropertySet > &rProp)
Fill in the autostyle.
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
SchXMLImportHelper & mrImportHelper
SchXMLLegendContext(SchXMLImportHelper &rImpHelper, SvXMLImport &rImport)
virtual ~SchXMLLegendContext() override
This class deliberately does not support XWeak, to improve performance when loading large documents.
Definition: xmlictxt.hxx:48
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:60
virtual bool importXML(const OUString &rStrImpValue, css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Imports the given value according to the XML-data-type corresponding to the derived class.
#define SAL_INFO(area, stream)
XMLOFF_DLLPUBLIC bool importXML(css::uno::Reference< css::xml::sax::XFastAttributeList > const &xAttrList, css::uno::Any &rValue, OUString &rStrName, SvXMLImport &rImport)
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
Handling of tokens in XML:
@ XML_LEGEND_EXPANSION_ASPECT_RATIO
Definition: xmltoken.hxx:3370
#define XMLOFF_WARN_UNKNOWN(area, rIter)
Definition: xmlictxt.hxx:114
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:97