/src/libreoffice/oox/source/drawingml/chart/stylefragment.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 <optional> |
21 | | |
22 | | #include <drawingml/chart/stylefragment.hxx> |
23 | | |
24 | | #include <drawingml/shapepropertiescontext.hxx> |
25 | | #include <drawingml/textbodycontext.hxx> |
26 | | #include <drawingml/textbodypropertiescontext.hxx> |
27 | | #include <drawingml/textcharacterpropertiescontext.hxx> |
28 | | #include <drawingml/chart/stylemodel.hxx> |
29 | | #include <drawingml/chart/colorsmodel.hxx> |
30 | | #include <drawingml/colorchoicecontext.hxx> |
31 | | #include <docmodel/styles/ChartStyle.hxx> |
32 | | #include <oox/drawingml/color.hxx> |
33 | | #include <oox/core/xmlfilterbase.hxx> |
34 | | #include <oox/helper/attributelist.hxx> |
35 | | #include <oox/token/namespaces.hxx> |
36 | | #include <oox/token/tokens.hxx> |
37 | | |
38 | | #include <tools/UnitConversion.hxx> |
39 | | |
40 | | namespace oox::drawingml::chart |
41 | | { |
42 | | using namespace ::oox::core; |
43 | | using namespace model; |
44 | | |
45 | | //======= |
46 | | // StyleEntryContext |
47 | | //======= |
48 | | StyleEntryContext::StyleEntryContext(ContextHandler2Helper& rParent, StyleEntryModel& rModel) |
49 | 0 | : ContextBase<StyleEntryModel>(rParent, rModel) |
50 | 0 | { |
51 | 0 | } |
52 | | |
53 | 0 | StyleEntryContext::~StyleEntryContext() {} |
54 | | |
55 | | ContextHandlerRef StyleEntryContext::onCreateContext(sal_Int32 nElement, |
56 | | const AttributeList& rAttribs) |
57 | 0 | { |
58 | 0 | if (isRootElement()) |
59 | 0 | switch (nElement) |
60 | 0 | { |
61 | 0 | case CS_TOKEN(lnRef): // CT_StyleReference |
62 | 0 | return new StyleReferenceContext(*this, rAttribs.getInteger(XML_idx, -1), |
63 | 0 | mrModel.mxLnRef.create()); |
64 | 0 | case CS_TOKEN(lineWidthScale): // double |
65 | 0 | return this; |
66 | 0 | case CS_TOKEN(fillRef): // CT_StyleReference |
67 | 0 | return new StyleReferenceContext(*this, rAttribs.getInteger(XML_idx, -1), |
68 | 0 | mrModel.mxFillRef.create()); |
69 | 0 | case CS_TOKEN(effectRef): // CT_StyleReference |
70 | 0 | return new StyleReferenceContext(*this, rAttribs.getInteger(XML_idx, -1), |
71 | 0 | mrModel.mxEffectRef.create()); |
72 | 0 | case CS_TOKEN(fontRef): // CT_FontReference |
73 | 0 | return new FontReferenceContext(*this, rAttribs.getString(XML_idx, ""), |
74 | 0 | mrModel.mxFontRef.create()); |
75 | 0 | case CS_TOKEN(spPr): // a:CT_ShapeProperties |
76 | 0 | return new ShapePropertiesContext(*this, mrModel.mxShapeProp.create()); |
77 | 0 | case CS_TOKEN(defRPr): // a:CT_TextCharacterProperties |
78 | 0 | return new TextCharacterPropertiesContext( |
79 | 0 | *this, rAttribs, mrModel.mrTextCharacterProperties.create()); |
80 | 0 | case CS_TOKEN(bodyPr): // a:CT_TextBodyProperties |
81 | 0 | return new TextBodyPropertiesContext(*this, rAttribs, mrModel.mxBodyPr.create()); |
82 | 0 | case CS_TOKEN(extLst): // a:CT_OfficeArtExtensionList |
83 | 0 | return nullptr; |
84 | 0 | } |
85 | 0 | return nullptr; |
86 | 0 | } |
87 | | |
88 | | void StyleEntryContext::onCharacters(const OUString& rChars) |
89 | 0 | { |
90 | 0 | switch (getCurrentElement()) |
91 | 0 | { |
92 | 0 | case CS_TOKEN(lineWidthScale): |
93 | 0 | mrModel.mfLineWidthScale = rChars.toDouble(); |
94 | 0 | break; |
95 | 0 | default: |
96 | 0 | assert(false); |
97 | 0 | } |
98 | 0 | } |
99 | | |
100 | | //======= |
101 | | // StyleReferenceContext |
102 | | //======= |
103 | | StyleReferenceContext::StyleReferenceContext(ContextHandler2Helper& rParent, const sal_Int32 nIdx, |
104 | | model::StyleRef& rModel) |
105 | 0 | : ContextBase<StyleRef>(rParent, rModel) |
106 | 0 | { |
107 | 0 | mrModel.mnIdx = nIdx; |
108 | 0 | } |
109 | | |
110 | 0 | StyleReferenceContext::~StyleReferenceContext() {} |
111 | | |
112 | | ContextHandlerRef StyleReferenceContext::onCreateContext(sal_Int32 nElement, |
113 | | const AttributeList& rAttribs) |
114 | 0 | { |
115 | 0 | if (isRootElement()) |
116 | 0 | switch (nElement) |
117 | 0 | { |
118 | 0 | case CS_TOKEN(styleClr): |
119 | 0 | mrModel.setColorValStr(rAttribs.getString(XML_val)); |
120 | 0 | return nullptr; |
121 | 0 | case A_TOKEN(scrgbClr): |
122 | 0 | case A_TOKEN(srgbClr): |
123 | 0 | case A_TOKEN(hslClr): |
124 | 0 | case A_TOKEN(sysClr): |
125 | 0 | case A_TOKEN(schemeClr): |
126 | 0 | case A_TOKEN(prstClr): |
127 | 0 | return new ColorValueContext(*this, nullptr, &mrModel.maComplexColor); |
128 | 0 | } |
129 | 0 | return nullptr; |
130 | 0 | } |
131 | | |
132 | | //======= |
133 | | // FontReferenceContext |
134 | | //======= |
135 | | FontReferenceContext::FontReferenceContext(ContextHandler2Helper& rParent, std::u16string_view sIdx, |
136 | | model::FontRef& rModel) |
137 | 0 | : ContextBase<FontRef>(rParent, rModel) |
138 | 0 | { |
139 | 0 | mrModel.setFontCollectionIndex(sIdx); |
140 | 0 | } |
141 | | |
142 | 0 | FontReferenceContext::~FontReferenceContext() {} |
143 | | |
144 | | ContextHandlerRef FontReferenceContext::onCreateContext(sal_Int32 nElement, |
145 | | const AttributeList& rAttribs) |
146 | 0 | { |
147 | 0 | if (isRootElement()) |
148 | 0 | switch (nElement) |
149 | 0 | { |
150 | 0 | case CS_TOKEN(styleClr): |
151 | 0 | mrModel.setColorValStr(rAttribs.getString(XML_val)); |
152 | 0 | return nullptr; |
153 | 0 | case A_TOKEN(scrgbClr): |
154 | 0 | case A_TOKEN(srgbClr): |
155 | 0 | case A_TOKEN(hslClr): |
156 | 0 | case A_TOKEN(sysClr): |
157 | 0 | case A_TOKEN(schemeClr): |
158 | 0 | case A_TOKEN(prstClr): |
159 | 0 | return new ColorValueContext(*this, nullptr, &mrModel.maComplexColor); |
160 | 0 | } |
161 | 0 | return nullptr; |
162 | 0 | } |
163 | | |
164 | | //======= |
165 | | // StyleFragment |
166 | | //======= |
167 | | StyleFragment::StyleFragment(XmlFilterBase& rFilter, const OUString& rFragmentPath, |
168 | | StyleModel& rModel) |
169 | 0 | : FragmentBase<StyleModel>(rFilter, rFragmentPath, rModel) |
170 | 0 | { |
171 | 0 | } |
172 | | |
173 | 0 | StyleFragment::~StyleFragment() {} |
174 | | |
175 | | ContextHandlerRef StyleFragment::onCreateContext(sal_Int32 nElement, const AttributeList& rAttribs) |
176 | 0 | { |
177 | 0 | switch (getCurrentElement()) |
178 | 0 | { |
179 | 0 | case XML_ROOT_CONTEXT: |
180 | 0 | switch (nElement) |
181 | 0 | { |
182 | 0 | case CS_TOKEN(chartStyle): |
183 | 0 | mrModel.mnId = rAttribs.getInteger(XML_id, -1); |
184 | 0 | return this; |
185 | 0 | } |
186 | 0 | break; |
187 | | |
188 | 0 | case CS_TOKEN(chartStyle): |
189 | 0 | switch (nElement) |
190 | 0 | { |
191 | | // All of these have "mods" attributes that aren't currently |
192 | | // handled. TODO |
193 | 0 | case CS_TOKEN(axisTitle): |
194 | 0 | return new StyleEntryContext(*this, mrModel.mxAxisTitle.create()); |
195 | 0 | case CS_TOKEN(categoryAxis): |
196 | 0 | return new StyleEntryContext(*this, mrModel.mxCategoryAxis.create()); |
197 | 0 | case CS_TOKEN(chartArea): |
198 | 0 | return new StyleEntryContext(*this, mrModel.mxChartArea.create()); |
199 | 0 | case CS_TOKEN(dataLabel): |
200 | 0 | return new StyleEntryContext(*this, mrModel.mxDataLabel.create()); |
201 | 0 | case CS_TOKEN(dataLabelCallout): |
202 | 0 | return new StyleEntryContext(*this, mrModel.mxDataLabelCallout.create()); |
203 | 0 | case CS_TOKEN(dataPoint): |
204 | 0 | return new StyleEntryContext(*this, mrModel.mxDataPoint.create()); |
205 | 0 | case CS_TOKEN(dataPoint3D): |
206 | 0 | return new StyleEntryContext(*this, mrModel.mxDataPoint3D.create()); |
207 | 0 | case CS_TOKEN(dataPointLine): |
208 | 0 | return new StyleEntryContext(*this, mrModel.mxDataPointLine.create()); |
209 | 0 | case CS_TOKEN(dataPointMarker): |
210 | 0 | return new StyleEntryContext(*this, mrModel.mxDataPointMarker.create()); |
211 | 0 | case CS_TOKEN(dataPointMarkerLayout): |
212 | 0 | return new StyleEntryContext(*this, mrModel.mxDataPointMarkerLayout.create()); |
213 | 0 | case CS_TOKEN(dataPointWireframe): |
214 | 0 | return new StyleEntryContext(*this, mrModel.mxDataPointWireframe.create()); |
215 | 0 | case CS_TOKEN(dataTable): |
216 | 0 | return new StyleEntryContext(*this, mrModel.mxDataTable.create()); |
217 | 0 | case CS_TOKEN(downBar): |
218 | 0 | return new StyleEntryContext(*this, mrModel.mxDownBar.create()); |
219 | 0 | case CS_TOKEN(dropLine): |
220 | 0 | return new StyleEntryContext(*this, mrModel.mxDropLine.create()); |
221 | 0 | case CS_TOKEN(errorBar): |
222 | 0 | return new StyleEntryContext(*this, mrModel.mxErrorBar.create()); |
223 | 0 | case CS_TOKEN(floor): |
224 | 0 | return new StyleEntryContext(*this, mrModel.mxFloor.create()); |
225 | 0 | case CS_TOKEN(gridlineMajor): |
226 | 0 | return new StyleEntryContext(*this, mrModel.mxGridlineMajor.create()); |
227 | 0 | case CS_TOKEN(gridlineMinor): |
228 | 0 | return new StyleEntryContext(*this, mrModel.mxGridlineMinor.create()); |
229 | 0 | case CS_TOKEN(hiLoLine): |
230 | 0 | return new StyleEntryContext(*this, mrModel.mxHiLoLine.create()); |
231 | 0 | case CS_TOKEN(leaderLine): |
232 | 0 | return new StyleEntryContext(*this, mrModel.mxLeaderLine.create()); |
233 | 0 | case CS_TOKEN(legend): |
234 | 0 | return new StyleEntryContext(*this, mrModel.mxLegend.create()); |
235 | 0 | case CS_TOKEN(plotArea): |
236 | 0 | return new StyleEntryContext(*this, mrModel.mxPlotArea.create()); |
237 | 0 | case CS_TOKEN(plotArea3D): |
238 | 0 | return new StyleEntryContext(*this, mrModel.mxPlotArea3D.create()); |
239 | 0 | case CS_TOKEN(seriesAxis): |
240 | 0 | return new StyleEntryContext(*this, mrModel.mxSeriesAxis.create()); |
241 | 0 | case CS_TOKEN(seriesLine): |
242 | 0 | return new StyleEntryContext(*this, mrModel.mxSeriesLine.create()); |
243 | 0 | case CS_TOKEN(title): |
244 | 0 | return new StyleEntryContext(*this, mrModel.mxTitle.create()); |
245 | 0 | case CS_TOKEN(trendline): |
246 | 0 | return new StyleEntryContext(*this, mrModel.mxTrendline.create()); |
247 | 0 | case CS_TOKEN(trendlineLabel): |
248 | 0 | return new StyleEntryContext(*this, mrModel.mxTrendlineLabel.create()); |
249 | 0 | case CS_TOKEN(upBar): |
250 | 0 | return new StyleEntryContext(*this, mrModel.mxUpBar.create()); |
251 | 0 | case CS_TOKEN(valueAxis): |
252 | 0 | return new StyleEntryContext(*this, mrModel.mxValueAxis.create()); |
253 | 0 | case CS_TOKEN(wall): |
254 | 0 | return new StyleEntryContext(*this, mrModel.mxWall.create()); |
255 | 0 | case CS_TOKEN(extLst): |
256 | | // Don't handle this, at least yet |
257 | 0 | return nullptr; |
258 | 0 | } |
259 | 0 | break; |
260 | 0 | } |
261 | 0 | return nullptr; |
262 | 0 | } |
263 | | |
264 | | //======= |
265 | | // ColorsFragment |
266 | | //======= |
267 | | ColorsFragment::ColorsFragment(XmlFilterBase& rFilter, const OUString& rFragmentPath, |
268 | | ColorStyleModel& rModel) |
269 | 0 | : FragmentBase<ColorStyleModel>(rFilter, rFragmentPath, rModel) |
270 | 0 | { |
271 | 0 | } |
272 | | |
273 | 0 | ColorsFragment::~ColorsFragment() {} |
274 | | |
275 | | ContextHandlerRef ColorsFragment::onCreateContext(sal_Int32 nElement, const AttributeList& rAttribs) |
276 | 0 | { |
277 | 0 | switch (getCurrentElement()) |
278 | 0 | { |
279 | 0 | case XML_ROOT_CONTEXT: |
280 | 0 | switch (nElement) |
281 | 0 | { |
282 | 0 | case CS_TOKEN(colorStyle): |
283 | 0 | mrModel.mnId = rAttribs.getInteger(XML_id, -1); |
284 | 0 | std::optional<OUString> sMethod = rAttribs.getString(XML_meth); |
285 | 0 | if (sMethod) |
286 | 0 | { |
287 | 0 | if (*sMethod == "cycle") |
288 | 0 | { |
289 | 0 | mrModel.meMethod = ColorStyleMethod::CYCLE; |
290 | 0 | } |
291 | 0 | else if (*sMethod == "withinLinear") |
292 | 0 | { |
293 | 0 | mrModel.meMethod = ColorStyleMethod::WITHIN_LINEAR; |
294 | 0 | } |
295 | 0 | else if (*sMethod == "acrossLinear") |
296 | 0 | { |
297 | 0 | mrModel.meMethod = ColorStyleMethod::ACROSS_LINEAR; |
298 | 0 | } |
299 | 0 | else if (*sMethod == "withinLinearReversed") |
300 | 0 | { |
301 | 0 | mrModel.meMethod = ColorStyleMethod::WITHIN_LINEAR_REVERSED; |
302 | 0 | } |
303 | 0 | else if (*sMethod == "acrossLinearReversed") |
304 | 0 | { |
305 | 0 | mrModel.meMethod = ColorStyleMethod::ACROSS_LINEAR_REVERSED; |
306 | 0 | } |
307 | 0 | else |
308 | 0 | { |
309 | 0 | assert(false); |
310 | 0 | } |
311 | 0 | } |
312 | 0 | return this; |
313 | 0 | } |
314 | 0 | break; |
315 | | |
316 | 0 | case CS_TOKEN(colorStyle): |
317 | 0 | switch (nElement) |
318 | 0 | { |
319 | 0 | case A_TOKEN(scrgbClr): |
320 | 0 | case A_TOKEN(srgbClr): |
321 | 0 | case A_TOKEN(hslClr): |
322 | 0 | case A_TOKEN(sysClr): |
323 | 0 | case A_TOKEN(schemeClr): |
324 | 0 | case A_TOKEN(prstClr): |
325 | 0 | mrModel.maColors.emplace_back(); |
326 | 0 | mrModel.maComplexColors.emplace_back(); |
327 | 0 | return new ColorValueContext(*this, &mrModel.maColors.back(), |
328 | 0 | &mrModel.maComplexColors.back()); |
329 | | |
330 | 0 | case CS_TOKEN(variation): |
331 | | // "variation"s presumably apply to the preceding color entry |
332 | 0 | return new VariationContext(*this, &mrModel.maColors.back(), |
333 | 0 | &mrModel.maComplexColors.back()); |
334 | 0 | } |
335 | 0 | break; |
336 | 0 | } |
337 | 0 | return nullptr; |
338 | 0 | } |
339 | | |
340 | | } // namespace oox::drawingml::chart |
341 | | |
342 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |