calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / svgio / inc / svgstyleattributes.hxx
blob4455f2311b69512bb626e7f7416eeda9c43a0f29
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #pragma once
22 #include "svgpaint.hxx"
23 #include "svgnode.hxx"
24 #include "svgtools.hxx"
25 #include <tools/fontenum.hxx>
26 #include <basegfx/polygon/b2dpolypolygontools.hxx>
27 #include <drawinglayer/primitive2d/Primitive2DContainer.hxx>
30 // predefines
32 namespace svgio::svgreader {
33 class SvgGradientNode;
34 class SvgPatternNode;
35 class SvgMarkerNode;
36 class SvgClipPathNode;
37 class SvgMaskNode;
41 namespace svgio::svgreader
43 enum class StrokeLinecap
45 notset,
46 butt,
47 round,
48 square
51 enum class StrokeLinejoin
53 notset,
54 miter,
55 round,
56 bevel
59 enum class FontSize
61 notset,
62 xx_small,
63 x_small,
64 small,
65 smaller,
66 medium,
67 large,
68 larger,
69 x_large,
70 xx_large,
71 initial
74 enum class FontStretch
76 notset,
77 normal,
78 wider,
79 narrower,
80 ultra_condensed,
81 extra_condensed,
82 condensed,
83 semi_condensed,
84 semi_expanded,
85 expanded,
86 extra_expanded,
87 ultra_expanded
90 FontStretch getWider(FontStretch aSource);
91 FontStretch getNarrower(FontStretch aSource);
93 enum class FontStyle
95 notset,
96 normal,
97 italic,
98 oblique
101 enum class FontWeight
103 notset,
104 N100,
105 N200,
106 N300,
107 N400, // same as normal
108 N500,
109 N600,
110 N700, // same as bold
111 N800,
112 N900,
113 bolder,
114 lighter,
117 FontWeight getBolder(FontWeight aSource);
118 FontWeight getLighter(FontWeight aSource);
119 ::FontWeight getVclFontWeight(FontWeight aSource);
121 enum class TextAlign
123 notset,
124 left,
125 right,
126 center,
127 justify
130 enum class TextDecoration
132 notset,
133 none,
134 underline,
135 overline,
136 line_through,
137 blink
140 enum class TextAnchor
142 notset,
143 start,
144 middle,
148 enum class FillRule
150 notset,
151 nonzero,
152 evenodd
155 enum class BaselineShift
157 Baseline,
158 Sub,
159 Super,
160 Percentage,
161 Length
164 enum class Visibility
166 notset,
167 visible,
168 hidden,
169 collapse,
170 inherit
173 class SvgStyleAttributes
175 private:
176 SvgNode& mrOwner;
177 const SvgStyleAttributes* mpCssStyleParent;
178 SvgPaint maFill;
179 SvgPaint maStroke;
180 SvgPaint maStopColor;
181 SvgNumber maStrokeWidth;
182 SvgNumber maStopOpacity;
183 SvgNumber maFillOpacity;
184 SvgNumberVector maStrokeDasharray;
185 SvgNumber maStrokeDashOffset;
186 StrokeLinecap maStrokeLinecap;
187 StrokeLinejoin maStrokeLinejoin;
188 SvgNumber maStrokeMiterLimit;
189 SvgNumber maStrokeOpacity;
190 SvgStringVector maFontFamily;
191 FontSize maFontSize;
192 SvgNumber maFontSizeNumber;
193 FontStretch maFontStretch;
194 FontStyle maFontStyle;
195 FontWeight maFontWeight;
196 TextAlign maTextAlign;
197 TextDecoration maTextDecoration;
198 TextAnchor maTextAnchor;
199 SvgPaint maColor;
200 SvgNumber maOpacity;
201 Visibility maVisibility;
202 OUString maTitle;
203 OUString maDesc;
205 /// link to content. If set, the node can be fetched on demand
206 OUString maClipPathXLink;
207 const SvgClipPathNode* mpClipPathXLink;
208 OUString maMaskXLink;
209 const SvgMaskNode* mpMaskXLink;
211 /// link to markers. If set, the node can be fetched on demand
212 OUString maMarkerStartXLink;
213 const SvgMarkerNode* mpMarkerStartXLink;
214 OUString maMarkerMidXLink;
215 const SvgMarkerNode* mpMarkerMidXLink;
216 OUString maMarkerEndXLink;
217 const SvgMarkerNode* mpMarkerEndXLink;
219 /// fill rule
220 FillRule maFillRule;
222 // ClipRule setting (only valid when mbIsClipPathContent == true, default is FillRule_nonzero)
223 FillRule maClipRule;
225 // BaselineShift: Type and number (in case of BaselineShift_Percentage or BaselineShift_Length)
226 BaselineShift maBaselineShift;
227 SvgNumber maBaselineShiftNumber;
229 mutable std::vector<sal_uInt16> maResolvingParent;
231 // defines if this attributes are part of a ClipPath. If yes,
232 // rough geometry will be created on decomposition by patching
233 // values for fill, stroke, strokeWidth and others
234 bool mbIsClipPathContent : 1;
236 // #121221# Defines if evtl. an empty array *is* set
237 bool mbStrokeDasharraySet : 1;
239 // tdf#94765 Check id references in gradient/pattern getters
240 OUString maNodeFillURL;
241 OUString maNodeStrokeURL;
243 /// internal helpers
244 void add_fillGradient(
245 const basegfx::B2DPolyPolygon& rPath,
246 drawinglayer::primitive2d::Primitive2DContainer& rTarget,
247 const SvgGradientNode& rFillGradient,
248 const basegfx::B2DRange& rGeoRange) const;
249 void add_fillPatternTransform(
250 const basegfx::B2DPolyPolygon& rPath,
251 drawinglayer::primitive2d::Primitive2DContainer& rTarget,
252 const SvgPatternNode& rFillGradient,
253 const basegfx::B2DRange& rGeoRange) const;
254 void add_fillPattern(
255 const basegfx::B2DPolyPolygon& rPath,
256 drawinglayer::primitive2d::Primitive2DContainer& rTarget,
257 const SvgPatternNode& rFillGradient,
258 const basegfx::B2DRange& rGeoRange) const;
259 void add_fill(
260 const basegfx::B2DPolyPolygon& rPath,
261 drawinglayer::primitive2d::Primitive2DContainer& rTarget,
262 const basegfx::B2DRange& rGeoRange) const;
263 void add_stroke(
264 const basegfx::B2DPolyPolygon& rPath,
265 drawinglayer::primitive2d::Primitive2DContainer& rTarget,
266 const basegfx::B2DRange& rGeoRange) const;
267 bool prepare_singleMarker(
268 drawinglayer::primitive2d::Primitive2DContainer& rMarkerPrimitives,
269 basegfx::B2DHomMatrix& rMarkerTransform,
270 basegfx::B2DRange& rClipRange,
271 const SvgMarkerNode& rMarker) const;
272 void add_markers(
273 const basegfx::B2DPolyPolygon& rPath,
274 drawinglayer::primitive2d::Primitive2DContainer& rTarget,
275 const basegfx::utils::PointIndexSet* pHelpPointIndices) const;
278 public:
279 /// local attribute scanner
280 void parseStyleAttribute(SVGToken aSVGToken, const OUString& rContent);
282 /// helper which does the necessary with a given path
283 void add_text(
284 drawinglayer::primitive2d::Primitive2DContainer& rTarget,
285 drawinglayer::primitive2d::Primitive2DContainer&& rSource) const;
286 void add_path(
287 const basegfx::B2DPolyPolygon& rPath,
288 drawinglayer::primitive2d::Primitive2DContainer& rTarget,
289 const basegfx::utils::PointIndexSet* pHelpPointIndices) const;
290 void add_postProcess(
291 drawinglayer::primitive2d::Primitive2DContainer& rTarget,
292 drawinglayer::primitive2d::Primitive2DContainer&& rSource,
293 const std::optional<basegfx::B2DHomMatrix>& pTransform) const;
295 /// helper to set mpCssStyleParent temporarily for CSS style hierarchies
296 void setCssStyleParent(const SvgStyleAttributes* pNew) { mpCssStyleParent = pNew; }
297 const SvgStyleAttributes* getCssStyleParent() const { return mpCssStyleParent; }
299 /// scan helpers
300 void readCssStyle(std::u16string_view rCandidate);
301 const SvgStyleAttributes* getParentStyle() const;
303 SvgStyleAttributes(SvgNode& rOwner);
304 ~SvgStyleAttributes();
306 /// fill content
307 bool isFillSet() const; // #i125258# ask if fill is a direct hard attribute (no hierarchy)
308 const basegfx::BColor* getFill() const;
309 void setFill(const SvgPaint& rFill) { maFill = rFill; }
311 /// stroke content
312 const basegfx::BColor* getStroke() const;
314 /// stop color content
315 const basegfx::BColor& getStopColor() const;
317 /// stroke-width content
318 SvgNumber getStrokeWidth() const;
320 /// stop opacity content
321 SvgNumber getStopOpacity() const;
323 /// access to evtl. set fill gradient
324 const SvgGradientNode* getSvgGradientNodeFill() const;
326 /// access to evtl. set fill pattern
327 const SvgPatternNode* getSvgPatternNodeFill() const;
329 /// access to evtl. set stroke gradient
330 const SvgGradientNode* getSvgGradientNodeStroke() const;
332 /// access to evtl. set stroke pattern
333 const SvgPatternNode* getSvgPatternNodeStroke() const;
335 /// fill opacity content
336 SvgNumber getFillOpacity() const;
338 /// fill rule content
339 FillRule getFillRule() const;
341 /// clip rule content
342 FillRule getClipRule() const;
344 /// fill StrokeDasharray content
345 const SvgNumberVector& getStrokeDasharray() const;
347 /// StrokeDashOffset content
348 SvgNumber getStrokeDashOffset() const;
350 /// StrokeLinecap content
351 StrokeLinecap getStrokeLinecap() const;
352 void setStrokeLinecap(const StrokeLinecap aStrokeLinecap) { maStrokeLinecap = aStrokeLinecap; }
354 /// StrokeLinejoin content
355 StrokeLinejoin getStrokeLinejoin() const;
356 void setStrokeLinejoin(const StrokeLinejoin aStrokeLinejoin) { maStrokeLinejoin = aStrokeLinejoin; }
358 /// StrokeMiterLimit content
359 SvgNumber getStrokeMiterLimit() const;
361 /// StrokeOpacity content
362 SvgNumber getStrokeOpacity() const;
364 /// Font content
365 const SvgStringVector& getFontFamily() const;
367 /// FontSize content
368 void setFontSize(const FontSize aFontSize) { maFontSize = aFontSize; }
369 SvgNumber getFontSizeNumber() const;
371 /// FontStretch content
372 FontStretch getFontStretch() const;
373 void setFontStretch(const FontStretch aFontStretch) { maFontStretch = aFontStretch; }
375 /// FontStyle content
376 FontStyle getFontStyle() const;
377 void setFontStyle(const FontStyle aFontStyle) { maFontStyle = aFontStyle; }
379 /// FontWeight content
380 FontWeight getFontWeight() const;
381 void setFontWeight(const FontWeight aFontWeight) { maFontWeight = aFontWeight; }
383 /// TextAlign content
384 TextAlign getTextAlign() const;
385 void setTextAlign(const TextAlign aTextAlign) { maTextAlign = aTextAlign; }
387 /// TextDecoration content
388 const SvgStyleAttributes* getTextDecorationDefiningSvgStyleAttributes() const;
389 TextDecoration getTextDecoration() const;
390 void setTextDecoration(const TextDecoration aTextDecoration) { maTextDecoration = aTextDecoration; }
392 /// TextAnchor content
393 TextAnchor getTextAnchor() const;
394 void setTextAnchor(const TextAnchor aTextAnchor) { maTextAnchor = aTextAnchor; }
396 /// Color content
397 const basegfx::BColor* getColor() const;
399 /// Resolve current color (defaults to black if no color is specified)
400 const basegfx::BColor* getCurrentColor() const;
402 /// Opacity content
403 SvgNumber getOpacity() const;
404 void setOpacity(const SvgNumber& rOpacity) { maOpacity = rOpacity; }
406 /// Visibility
407 Visibility getVisibility() const;
408 void setVisibility(const Visibility aVisibility) { maVisibility = aVisibility; }
410 // Title content
411 const OUString& getTitle() const { return maTitle; }
413 // Desc content
414 const OUString& getDesc() const { return maDesc; }
416 // ClipPathXLink content
417 OUString getClipPathXLink() const;
418 const SvgClipPathNode* accessClipPathXLink() const;
420 // MaskXLink content
421 OUString getMaskXLink() const;
422 const SvgMaskNode* accessMaskXLink() const;
424 // MarkerStartXLink content
425 OUString getMarkerStartXLink() const;
426 const SvgMarkerNode* accessMarkerStartXLink() const;
428 // MarkerMidXLink content
429 OUString getMarkerMidXLink() const;
430 const SvgMarkerNode* accessMarkerMidXLink() const;
432 // MarkerEndXLink content
433 OUString getMarkerEndXLink() const;
434 const SvgMarkerNode* accessMarkerEndXLink() const;
436 // BaselineShift
437 void setBaselineShift(const BaselineShift aBaselineShift) { maBaselineShift = aBaselineShift; }
438 BaselineShift getBaselineShift() const { return maBaselineShift; }
439 SvgNumber getBaselineShiftNumber() const;
442 } // end of namespace svgio::svgreader
444 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */