Update git submodules
[LibreOffice.git] / svgio / inc / svgstyleattributes.hxx
blob30cbab965644712755df674145d131f26fd68b0b
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 SvgFilterNode;
38 class SvgMaskNode;
42 namespace svgio::svgreader
44 enum class StrokeLinecap
46 notset,
47 butt,
48 round,
49 square
52 enum class StrokeLinejoin
54 notset,
55 miter,
56 round,
57 bevel
60 enum class FontSize
62 notset,
63 xx_small,
64 x_small,
65 small,
66 smaller,
67 medium,
68 large,
69 larger,
70 x_large,
71 xx_large,
72 initial
75 enum class FontStretch
77 notset,
78 normal,
79 wider,
80 narrower,
81 ultra_condensed,
82 extra_condensed,
83 condensed,
84 semi_condensed,
85 semi_expanded,
86 expanded,
87 extra_expanded,
88 ultra_expanded
91 FontStretch getWider(FontStretch aSource);
92 FontStretch getNarrower(FontStretch aSource);
94 enum class FontStyle
96 notset,
97 normal,
98 italic,
99 oblique
102 enum class FontWeight
104 notset,
105 N100,
106 N200,
107 N300,
108 N400, // same as normal
109 N500,
110 N600,
111 N700, // same as bold
112 N800,
113 N900,
114 bolder,
115 lighter,
118 FontWeight getBolder(FontWeight aSource);
119 FontWeight getLighter(FontWeight aSource);
120 ::FontWeight getVclFontWeight(FontWeight aSource);
122 enum class TextAlign
124 notset,
125 left,
126 right,
127 center,
128 justify
131 enum class TextDecoration
133 notset,
134 none,
135 underline,
136 overline,
137 line_through,
138 blink
141 enum class TextAnchor
143 notset,
144 start,
145 middle,
149 enum class FillRule
151 notset,
152 nonzero,
153 evenodd
156 enum class BaselineShift
158 Baseline,
159 Sub,
160 Super,
161 Percentage,
162 Length
165 enum class DominantBaseline
167 Auto,
168 Middle,
169 Hanging,
170 Central
173 enum class Overflow
175 notset,
176 hidden,
177 visible
180 enum class Visibility
182 notset,
183 visible,
184 hidden,
185 collapse,
186 inherit
189 class SvgStyleAttributes
191 private:
192 SvgNode& mrOwner;
193 const SvgStyleAttributes* mpCssStyleParent;
194 SvgPaint maFill;
195 SvgPaint maStroke;
196 SvgPaint maStopColor;
197 SvgNumber maStrokeWidth;
198 SvgNumber maStopOpacity;
199 SvgNumber maFillOpacity;
200 SvgNumberVector maStrokeDasharray;
201 SvgNumber maStrokeDashOffset;
202 StrokeLinecap maStrokeLinecap;
203 StrokeLinejoin maStrokeLinejoin;
204 SvgNumber maStrokeMiterLimit;
205 SvgNumber maStrokeOpacity;
206 SvgStringVector maFontFamily;
207 FontSize maFontSize;
208 SvgNumber maFontSizeNumber;
209 FontStretch maFontStretch;
210 FontStyle maFontStyle;
211 FontWeight maFontWeight;
212 TextAlign maTextAlign;
213 TextDecoration maTextDecoration;
214 TextAnchor maTextAnchor;
215 SvgPaint maColor;
216 SvgNumber maOpacity;
217 Overflow maOverflow;
218 Visibility maVisibility;
219 OUString maTitle;
220 OUString maDesc;
222 /// link to content. If set, the node can be fetched on demand
223 OUString maClipPathXLink;
224 OUString maFilterXLink;
225 OUString maMaskXLink;
227 /// link to markers. If set, the node can be fetched on demand
228 OUString maMarkerStartXLink;
229 OUString maMarkerMidXLink;
230 OUString maMarkerEndXLink;
232 /// fill rule
233 FillRule maFillRule;
235 // ClipRule setting (only valid when mbIsClipPathContent == true, default is FillRule_nonzero)
236 FillRule maClipRule;
238 // BaselineShift: Type and number (in case of BaselineShift_Percentage or BaselineShift_Length)
239 BaselineShift maBaselineShift;
240 SvgNumber maBaselineShiftNumber;
242 DominantBaseline maDominantBaseline;
244 mutable std::vector<sal_uInt16> maResolvingParent;
247 // #121221# Defines if evtl. an empty array *is* set
248 bool mbStrokeDasharraySet : 1;
250 // tdf#155651 Defines if 'context-fill' is used in fill
251 bool mbContextFill : 1;
253 // tdf#155651 Defines if 'context-stroke' is used in stroke
254 bool mbContextStroke : 1;
256 // tdf#94765 Check id references in gradient/pattern getters
257 OUString maNodeFillURL;
258 OUString maNodeStrokeURL;
260 const basegfx::BColor* maContextFill;
261 const basegfx::BColor* maContextStroke;
263 /// internal helpers
264 void add_fillGradient(
265 const basegfx::B2DPolyPolygon& rPath,
266 drawinglayer::primitive2d::Primitive2DContainer& rTarget,
267 const SvgGradientNode& rFillGradient,
268 const basegfx::B2DRange& rGeoRange) const;
269 void add_fillPatternTransform(
270 const basegfx::B2DPolyPolygon& rPath,
271 drawinglayer::primitive2d::Primitive2DContainer& rTarget,
272 const SvgPatternNode& rFillGradient,
273 const basegfx::B2DRange& rGeoRange) const;
274 void add_fillPattern(
275 const basegfx::B2DPolyPolygon& rPath,
276 drawinglayer::primitive2d::Primitive2DContainer& rTarget,
277 const SvgPatternNode& rFillGradient,
278 const basegfx::B2DRange& rGeoRange) const;
279 void add_fill(
280 const basegfx::B2DPolyPolygon& rPath,
281 drawinglayer::primitive2d::Primitive2DContainer& rTarget,
282 const basegfx::B2DRange& rGeoRange) const;
283 void add_stroke(
284 const basegfx::B2DPolyPolygon& rPath,
285 drawinglayer::primitive2d::Primitive2DContainer& rTarget,
286 const basegfx::B2DRange& rGeoRange) const;
287 bool prepare_singleMarker(
288 drawinglayer::primitive2d::Primitive2DContainer& rMarkerPrimitives,
289 basegfx::B2DHomMatrix& rMarkerTransform,
290 basegfx::B2DRange& rClipRange,
291 const SvgMarkerNode& rMarker) const;
292 void add_markers(
293 const basegfx::B2DPolyPolygon& rPath,
294 drawinglayer::primitive2d::Primitive2DContainer& rTarget,
295 const basegfx::utils::PointIndexSet* pHelpPointIndices) const;
298 public:
299 /// local attribute scanner
300 void parseStyleAttribute(SVGToken aSVGToken, const OUString& rContent);
302 /// helper which does the necessary with a given path
303 void add_text(
304 drawinglayer::primitive2d::Primitive2DContainer& rTarget,
305 drawinglayer::primitive2d::Primitive2DContainer&& rSource) const;
306 void add_path(
307 const basegfx::B2DPolyPolygon& rPath,
308 drawinglayer::primitive2d::Primitive2DContainer& rTarget,
309 const basegfx::utils::PointIndexSet* pHelpPointIndices) const;
310 void add_postProcess(
311 drawinglayer::primitive2d::Primitive2DContainer& rTarget,
312 drawinglayer::primitive2d::Primitive2DContainer&& rSource,
313 const std::optional<basegfx::B2DHomMatrix>& pTransform) const;
315 /// helper to set mpCssStyleParent temporarily for CSS style hierarchies
316 void setCssStyleParent(const SvgStyleAttributes* pNew) { mpCssStyleParent = pNew; }
317 const SvgStyleAttributes* getCssStyleParent() const { return mpCssStyleParent; }
319 /// scan helpers
320 void readCssStyle(std::u16string_view rCandidate);
321 const SvgStyleAttributes* getParentStyle() const;
323 SvgStyleAttributes(SvgNode& rOwner);
324 ~SvgStyleAttributes();
326 // Check if this attribute is part of a ClipPath.
327 // If so, rough geometry will be created on decomposition by patching
328 // values for fill, stroke, strokeWidth and others
329 bool isClipPathContent() const;
331 /// fill content
332 bool isFillSet() const; // #i125258# ask if fill is a direct hard attribute (no hierarchy)
333 const basegfx::BColor* getFill() const;
334 void setFill(const SvgPaint& rFill) { maFill = rFill; }
336 /// stroke content
337 const basegfx::BColor* getStroke() const;
339 /// context fill content
340 const basegfx::BColor* getContextFill() const;
342 /// context stroke content
343 const basegfx::BColor* getContextStroke() const;
345 /// stop color content
346 const basegfx::BColor& getStopColor() const;
348 /// stroke-width content
349 SvgNumber getStrokeWidth() const;
351 /// stop opacity content
352 SvgNumber getStopOpacity() const;
354 /// access to evtl. set fill gradient
355 const SvgGradientNode* getSvgGradientNodeFill() const;
357 /// access to evtl. set fill pattern
358 const SvgPatternNode* getSvgPatternNodeFill() const;
360 /// access to evtl. set stroke gradient
361 const SvgGradientNode* getSvgGradientNodeStroke() const;
363 /// access to evtl. set stroke pattern
364 const SvgPatternNode* getSvgPatternNodeStroke() const;
366 /// fill opacity content
367 SvgNumber getFillOpacity() const;
369 /// fill rule content
370 FillRule getFillRule() const;
372 /// clip rule content
373 FillRule getClipRule() const;
375 /// fill StrokeDasharray content
376 const SvgNumberVector& getStrokeDasharray() const;
378 /// StrokeDashOffset content
379 SvgNumber getStrokeDashOffset() const;
381 /// StrokeLinecap content
382 StrokeLinecap getStrokeLinecap() const;
383 void setStrokeLinecap(const StrokeLinecap aStrokeLinecap) { maStrokeLinecap = aStrokeLinecap; }
385 /// StrokeLinejoin content
386 StrokeLinejoin getStrokeLinejoin() const;
387 void setStrokeLinejoin(const StrokeLinejoin aStrokeLinejoin) { maStrokeLinejoin = aStrokeLinejoin; }
389 /// StrokeMiterLimit content
390 SvgNumber getStrokeMiterLimit() const;
392 /// StrokeOpacity content
393 SvgNumber getStrokeOpacity() const;
395 /// Font content
396 const SvgStringVector& getFontFamily() const;
398 /// FontSize content
399 void setFontSize(const FontSize aFontSize) { maFontSize = aFontSize; }
400 SvgNumber getFontSizeNumber() const;
402 /// FontStretch content
403 FontStretch getFontStretch() const;
404 void setFontStretch(const FontStretch aFontStretch) { maFontStretch = aFontStretch; }
406 /// FontStyle content
407 FontStyle getFontStyle() const;
408 void setFontStyle(const FontStyle aFontStyle) { maFontStyle = aFontStyle; }
410 /// FontWeight content
411 FontWeight getFontWeight() const;
412 void setFontWeight(const FontWeight aFontWeight) { maFontWeight = aFontWeight; }
414 /// TextAlign content
415 TextAlign getTextAlign() const;
416 void setTextAlign(const TextAlign aTextAlign) { maTextAlign = aTextAlign; }
418 /// TextDecoration content
419 const SvgStyleAttributes* getTextDecorationDefiningSvgStyleAttributes() const;
420 TextDecoration getTextDecoration() const;
421 void setTextDecoration(const TextDecoration aTextDecoration) { maTextDecoration = aTextDecoration; }
423 /// TextAnchor content
424 TextAnchor getTextAnchor() const;
425 void setTextAnchor(const TextAnchor aTextAnchor) { maTextAnchor = aTextAnchor; }
427 /// Color content
428 const basegfx::BColor* getColor() const;
430 /// Resolve current color (defaults to black if no color is specified)
431 const basegfx::BColor* getCurrentColor() const;
433 /// Opacity content
434 SvgNumber getOpacity() const;
435 void setOpacity(const SvgNumber& rOpacity) { maOpacity = rOpacity; }
437 /// Overflow
438 Overflow getOverflow() const;
439 void setOverflow(const Overflow aOverflow) { maOverflow = aOverflow; }
441 /// Visibility
442 Visibility getVisibility() const;
443 void setVisibility(const Visibility aVisibility) { maVisibility = aVisibility; }
445 // Title content
446 const OUString& getTitle() const { return maTitle; }
448 // Desc content
449 const OUString& getDesc() const { return maDesc; }
451 // ClipPathXLink content
452 OUString getClipPathXLink() const;
453 const SvgClipPathNode* accessClipPathXLink() const;
455 // FilterXLink content
456 OUString getFilterXLink() const;
457 const SvgFilterNode* accessFilterXLink() const;
459 // MaskXLink content
460 OUString getMaskXLink() const;
461 const SvgMaskNode* accessMaskXLink() const;
463 // MarkerStartXLink content
464 OUString getMarkerStartXLink() const;
465 const SvgMarkerNode* accessMarkerStartXLink() const;
467 // MarkerMidXLink content
468 OUString getMarkerMidXLink() const;
469 const SvgMarkerNode* accessMarkerMidXLink() const;
471 // MarkerEndXLink content
472 OUString getMarkerEndXLink() const;
473 const SvgMarkerNode* accessMarkerEndXLink() const;
475 // BaselineShift
476 void setBaselineShift(const BaselineShift aBaselineShift) { maBaselineShift = aBaselineShift; }
477 BaselineShift getBaselineShift() const;
478 SvgNumber getBaselineShiftNumber() const;
480 // DominantBaseline
481 void setDominantBaseline(const DominantBaseline aDominantBaseline) { maDominantBaseline = aDominantBaseline; }
482 DominantBaseline getDominantBaseline() const;
485 } // end of namespace svgio::svgreader
487 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */