/src/libreoffice/oox/source/drawingml/linepropertiescontext.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 <drawingml/linepropertiescontext.hxx> |
21 | | #include <drawingml/misccontexts.hxx> |
22 | | #include <drawingml/lineproperties.hxx> |
23 | | #include <oox/helper/attributelist.hxx> |
24 | | #include <oox/token/namespaces.hxx> |
25 | | #include <oox/token/tokens.hxx> |
26 | | #include <docmodel/theme/FormatScheme.hxx> |
27 | | |
28 | | using namespace ::oox::core; |
29 | | |
30 | | // CT_LineProperties |
31 | | |
32 | | namespace oox::drawingml { |
33 | | |
34 | | LinePropertiesContext::LinePropertiesContext( ContextHandler2Helper const & rParent, const AttributeList& rAttribs, |
35 | | LineProperties& rLineProperties, model::LineStyle* pLineStyle, |
36 | | bool bForChart) noexcept |
37 | 37.8k | : ContextHandler2(rParent) |
38 | 37.8k | , mpLineStyle(pLineStyle) |
39 | 37.8k | , mrLineProperties(rLineProperties) |
40 | 37.8k | { |
41 | 37.8k | if (bForChart) { |
42 | | // If width is not specified, then charts seem to assume a default line |
43 | | // width of 12700 emu |
44 | 0 | mrLineProperties.moLineWidth = rAttribs.getInteger( XML_w, 12700 ); |
45 | 37.8k | } else { |
46 | 37.8k | mrLineProperties.moLineWidth = rAttribs.getInteger( XML_w ); |
47 | 37.8k | } |
48 | 37.8k | mrLineProperties.moLineCompound = rAttribs.getToken( XML_cmpd ); |
49 | 37.8k | mrLineProperties.moLineCap = rAttribs.getToken( XML_cap ); |
50 | | |
51 | 37.8k | if (mpLineStyle) |
52 | 14.9k | { |
53 | 14.9k | mpLineStyle->mnWidth = rAttribs.getInteger(XML_w, 0); |
54 | | |
55 | 14.9k | switch (rAttribs.getToken(XML_cap, XML_TOKEN_INVALID)) |
56 | 14.9k | { |
57 | 40 | case XML_rnd: mpLineStyle->meCapType = model::CapType::Round; break; |
58 | 0 | case XML_sq: mpLineStyle->meCapType = model::CapType::Square; break; |
59 | 14.9k | case XML_flat: mpLineStyle->meCapType = model::CapType::Flat; break; |
60 | 24 | default: |
61 | 24 | mpLineStyle->meCapType = model::CapType::Unset; break; |
62 | 14.9k | } |
63 | | |
64 | 14.9k | switch (rAttribs.getToken(XML_cmpd, XML_TOKEN_INVALID)) |
65 | 14.9k | { |
66 | 14.9k | case XML_sng: mpLineStyle->meCompoundLineType = model::CompoundLineType::Single; break; |
67 | 0 | case XML_dbl: mpLineStyle->meCompoundLineType = model::CompoundLineType::Double; break; |
68 | 0 | case XML_thickThin: mpLineStyle->meCompoundLineType = model::CompoundLineType::ThickThin_Double; break; |
69 | 0 | case XML_thinThick: mpLineStyle->meCompoundLineType = model::CompoundLineType::ThinThick_Double; break; |
70 | 0 | case XML_tri: mpLineStyle->meCompoundLineType = model::CompoundLineType::Triple; break; |
71 | 24 | default: |
72 | 24 | mpLineStyle->meCompoundLineType = model::CompoundLineType::Unset; break; |
73 | 14.9k | } |
74 | | |
75 | 14.9k | switch (rAttribs.getToken(XML_algn, XML_TOKEN_INVALID)) |
76 | 14.9k | { |
77 | 14.9k | case XML_ctr: mpLineStyle->mePenAlignment = model::PenAlignmentType::Center; break; |
78 | 0 | case XML_in: mpLineStyle->mePenAlignment = model::PenAlignmentType::Inset; break; |
79 | 24 | default: |
80 | 24 | mpLineStyle->mePenAlignment = model::PenAlignmentType::Unset; break; |
81 | 14.9k | } |
82 | 14.9k | } |
83 | 37.8k | } |
84 | | |
85 | | LinePropertiesContext::~LinePropertiesContext() |
86 | 37.8k | { |
87 | 37.8k | } |
88 | | |
89 | | ContextHandlerRef LinePropertiesContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) |
90 | 80.5k | { |
91 | 80.5k | switch( nElement ) |
92 | 80.5k | { |
93 | | // LineFillPropertiesGroup |
94 | 12.9k | case A_TOKEN( noFill ): |
95 | 37.2k | case A_TOKEN( solidFill ): |
96 | 37.3k | case A_TOKEN( gradFill ): |
97 | 37.3k | case A_TOKEN( pattFill ): |
98 | 37.3k | { |
99 | 37.3k | model::FillStyle* pFillStyle = nullptr; |
100 | 37.3k | if (mpLineStyle) |
101 | 14.9k | { |
102 | 14.9k | pFillStyle = &mpLineStyle->maLineFillStyle; |
103 | 14.9k | } |
104 | 37.3k | return FillPropertiesContext::createFillContext(*this, nElement, rAttribs, mrLineProperties.maLineFill, pFillStyle); |
105 | 37.3k | } |
106 | 0 | break; |
107 | | |
108 | | // LineDashPropertiesGroup |
109 | 20.5k | case A_TOKEN( prstDash ): // CT_PresetLineDashProperties |
110 | 20.5k | { |
111 | 20.5k | mrLineProperties.moPresetDash = rAttribs.getToken( XML_val ); |
112 | | |
113 | 20.5k | if (mpLineStyle) |
114 | 14.9k | { |
115 | 14.9k | auto& rLineDash = mpLineStyle->maLineDash; |
116 | 14.9k | switch (rAttribs.getToken(XML_val, XML_TOKEN_INVALID)) |
117 | 14.9k | { |
118 | 14.9k | case XML_solid: rLineDash.mePresetType = model::PresetDashType::Solid; break; |
119 | 0 | case XML_dot: rLineDash.mePresetType = model::PresetDashType::Dot; break; |
120 | 0 | case XML_dash: rLineDash.mePresetType = model::PresetDashType::Dash; break; |
121 | 0 | case XML_lgDash: rLineDash.mePresetType = model::PresetDashType::LargeDash; break; |
122 | 0 | case XML_dashDot: rLineDash.mePresetType = model::PresetDashType::DashDot; break; |
123 | 0 | case XML_lgDashDot: rLineDash.mePresetType = model::PresetDashType::LargeDashDot; break; |
124 | 0 | case XML_lgDashDotDot: rLineDash.mePresetType = model::PresetDashType::LargeDashDotDot; break; |
125 | 0 | case XML_sysDash: rLineDash.mePresetType = model::PresetDashType::SystemDash; break; |
126 | 0 | case XML_sysDot: rLineDash.mePresetType = model::PresetDashType::SystemDot; break; |
127 | 0 | case XML_sysDashDot: rLineDash.mePresetType = model::PresetDashType::SystemDashDot; break; |
128 | 0 | case XML_sysDashDotDot: rLineDash.mePresetType = model::PresetDashType::SystemDashDotDot; break; |
129 | 0 | default: |
130 | 0 | rLineDash.mePresetType = model::PresetDashType::Unset; break; |
131 | 14.9k | } |
132 | 14.9k | } |
133 | 20.5k | } |
134 | 20.5k | break; |
135 | 20.5k | case A_TOKEN( custDash ): // CT_DashStopList |
136 | 0 | return this; |
137 | 0 | case A_TOKEN( ds ): |
138 | 0 | { |
139 | | // 'a:ds' has 2 attributes : 'd' and 'sp' |
140 | | // both are of type 'a:ST_PositivePercentage' |
141 | | // according to the specs Office will read percentages formatted with a trailing percent sign |
142 | | // or formatted as 1000th of a percent without a trailing percent sign, but only write percentages |
143 | | // as 1000th's of a percent without a trailing percent sign. |
144 | | // The code below takes care of both scenarios by converting to '1000th of a percent' always |
145 | 0 | OUString aStr; |
146 | 0 | sal_Int32 nDashLength = 0; |
147 | 0 | aStr = rAttribs.getStringDefaulted( XML_d); |
148 | 0 | if ( aStr.endsWith("%") ) |
149 | 0 | { |
150 | | // Ends with a '%' |
151 | 0 | aStr = aStr.copy(0, aStr.getLength() - 1); |
152 | 0 | aStr = aStr.trim(); |
153 | 0 | nDashLength = aStr.toInt32(); |
154 | | |
155 | | // Convert to 1000th of a percent |
156 | 0 | nDashLength *= 1000; |
157 | 0 | } |
158 | 0 | else |
159 | 0 | { |
160 | 0 | nDashLength = rAttribs.getInteger( XML_d, 0 ); |
161 | 0 | } |
162 | |
|
163 | 0 | sal_Int32 nSpaceLength = 0; |
164 | 0 | aStr = rAttribs.getStringDefaulted( XML_sp); |
165 | 0 | if ( aStr.endsWith("%") ) |
166 | 0 | { |
167 | | // Ends with a '%' |
168 | 0 | aStr = aStr.copy(0, aStr.getLength() - 1); |
169 | 0 | aStr = aStr.trim(); |
170 | 0 | nSpaceLength = aStr.toInt32(); |
171 | | |
172 | | // Convert to 1000th of a percent |
173 | 0 | nSpaceLength *= 1000; |
174 | 0 | } |
175 | 0 | else |
176 | 0 | { |
177 | 0 | nSpaceLength = rAttribs.getInteger( XML_sp, 0 ); |
178 | 0 | } |
179 | |
|
180 | 0 | mrLineProperties.maCustomDash.emplace_back( nDashLength, nSpaceLength ); |
181 | |
|
182 | 0 | if (mpLineStyle) |
183 | 0 | { |
184 | 0 | mpLineStyle->maLineDash.maCustomList.push_back({ nDashLength, nSpaceLength }); |
185 | 0 | } |
186 | 0 | } |
187 | 0 | break; |
188 | | |
189 | | // LineJoinPropertiesGroup |
190 | 5.57k | case A_TOKEN( round ): |
191 | 5.58k | case A_TOKEN( bevel ): |
192 | 11.9k | case A_TOKEN( miter ): |
193 | 11.9k | { |
194 | 11.9k | sal_Int32 nToken = getBaseToken(nElement); |
195 | 11.9k | mrLineProperties.moLineJoint = nToken; |
196 | | |
197 | 11.9k | if (mpLineStyle) |
198 | 2.31k | { |
199 | 2.31k | switch (nToken) |
200 | 2.31k | { |
201 | 0 | case XML_round: mpLineStyle->maLineJoin.meType = model::LineJoinType::Round; break; |
202 | 0 | case XML_bevel: mpLineStyle->maLineJoin.meType = model::LineJoinType::Bevel; break; |
203 | 2.31k | case XML_miter: mpLineStyle->maLineJoin.meType = model::LineJoinType::Miter; break; |
204 | 0 | default: |
205 | 0 | mpLineStyle->maLineJoin.meType = model::LineJoinType::Miter; |
206 | 2.31k | } |
207 | 2.31k | if (nToken == XML_miter) |
208 | 2.31k | { |
209 | 2.31k | sal_Int32 nMiterLimit = rAttribs.getInteger(XML_lim, 0); |
210 | 2.31k | mpLineStyle->maLineJoin.mnMiterLimit = nMiterLimit; |
211 | 2.31k | } |
212 | 2.31k | } |
213 | 11.9k | } |
214 | 11.9k | break; |
215 | | |
216 | 11.9k | case A_TOKEN( headEnd ): // CT_LineEndProperties |
217 | 10.6k | case A_TOKEN( tailEnd ): // CT_LineEndProperties |
218 | 10.6k | { // ST_LineEndType |
219 | 10.6k | bool bTailEnd = nElement == A_TOKEN( tailEnd ); |
220 | 10.6k | LineArrowProperties& rArrowProps = bTailEnd ? mrLineProperties.maEndArrow : mrLineProperties.maStartArrow; |
221 | 10.6k | rArrowProps.moArrowType = rAttribs.getToken( XML_type ); |
222 | 10.6k | rArrowProps.moArrowWidth = rAttribs.getToken( XML_w ); |
223 | 10.6k | rArrowProps.moArrowLength = rAttribs.getToken( XML_len ); |
224 | | |
225 | 10.6k | if (mpLineStyle) |
226 | 0 | { |
227 | 0 | model::LineEndType eLineEndType = model::LineEndType::None; |
228 | 0 | switch (rAttribs.getToken(XML_type, XML_none)) |
229 | 0 | { |
230 | 0 | case XML_triangle: eLineEndType = model::LineEndType::Triangle; break; |
231 | 0 | case XML_stealth: eLineEndType = model::LineEndType::Stealth; break; |
232 | 0 | case XML_diamond: eLineEndType = model::LineEndType::Diamond; break; |
233 | 0 | case XML_oval: eLineEndType = model::LineEndType::Oval; break; |
234 | 0 | case XML_arrow: eLineEndType = model::LineEndType::Arrow; break; |
235 | 0 | default: |
236 | 0 | case XML_none: eLineEndType = model::LineEndType::None; break; |
237 | 0 | } |
238 | | |
239 | 0 | model::LineEndLength eLineEndLength = model::LineEndLength::Unset; |
240 | 0 | switch (rAttribs.getToken(XML_len, XML_TOKEN_INVALID)) |
241 | 0 | { |
242 | 0 | case XML_sm: eLineEndLength = model::LineEndLength::Small; break; |
243 | 0 | case XML_med: eLineEndLength = model::LineEndLength::Medium; break; |
244 | 0 | case XML_lg: eLineEndLength = model::LineEndLength::Large; break; |
245 | 0 | default: |
246 | 0 | break; |
247 | 0 | } |
248 | | |
249 | 0 | model::LineEndWidth eLineEndWidth = model::LineEndWidth::Unset; |
250 | 0 | switch (rAttribs.getToken(XML_w, XML_TOKEN_INVALID)) |
251 | 0 | { |
252 | 0 | case XML_sm: eLineEndWidth = model::LineEndWidth::Small; break; |
253 | 0 | case XML_med: eLineEndWidth = model::LineEndWidth::Medium; break; |
254 | 0 | case XML_lg: eLineEndWidth = model::LineEndWidth::Large; break; |
255 | 0 | default: |
256 | 0 | break; |
257 | 0 | } |
258 | | |
259 | 0 | if (nElement == A_TOKEN(tailEnd)) |
260 | 0 | { |
261 | 0 | mpLineStyle->maTailEnd.meType = eLineEndType; |
262 | 0 | mpLineStyle->maTailEnd.meLength = eLineEndLength; |
263 | 0 | mpLineStyle->maTailEnd.meWidth = eLineEndWidth; |
264 | 0 | } |
265 | 0 | else if (nElement == A_TOKEN(headEnd)) |
266 | 0 | { |
267 | 0 | mpLineStyle->maHeadEnd.meType = eLineEndType; |
268 | 0 | mpLineStyle->maHeadEnd.meLength = eLineEndLength; |
269 | 0 | mpLineStyle->maHeadEnd.meWidth = eLineEndWidth; |
270 | 0 | } |
271 | 0 | } |
272 | 10.6k | } |
273 | 10.6k | break; |
274 | 80.5k | } |
275 | 43.1k | return nullptr; |
276 | 80.5k | } |
277 | | |
278 | | } |
279 | | |
280 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |