bump product version to 7.6.3.2-android
[LibreOffice.git] / svgio / inc / svgstyleattributes.hxx
blobacd310adbf6d4939ccd6163c2a9a74748c4d78f6
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
172 enum class Visibility
174 notset,
175 visible,
176 hidden,
177 collapse,
178 inherit
181 class SvgStyleAttributes
183 private:
184 SvgNode& mrOwner;
185 const SvgStyleAttributes* mpCssStyleParent;
186 SvgPaint maFill;
187 SvgPaint maStroke;
188 SvgPaint maStopColor;
189 SvgNumber maStrokeWidth;
190 SvgNumber maStopOpacity;
191 SvgNumber maFillOpacity;
192 SvgNumberVector maStrokeDasharray;
193 SvgNumber maStrokeDashOffset;
194 StrokeLinecap maStrokeLinecap;
195 StrokeLinejoin maStrokeLinejoin;
196 SvgNumber maStrokeMiterLimit;
197 SvgNumber maStrokeOpacity;
198 SvgStringVector maFontFamily;
199 FontSize maFontSize;
200 SvgNumber maFontSizeNumber;
201 FontStretch maFontStretch;
202 FontStyle maFontStyle;
203 FontWeight maFontWeight;
204 TextAlign maTextAlign;
205 TextDecoration maTextDecoration;
206 TextAnchor maTextAnchor;
207 SvgPaint maColor;
208 SvgNumber maOpacity;
209 Visibility maVisibility;
210 OUString maTitle;
211 OUString maDesc;
213 /// link to content. If set, the node can be fetched on demand
214 OUString maClipPathXLink;
215 const SvgClipPathNode* mpClipPathXLink;
216 OUString maFilterXLink;
217 const SvgFilterNode* mpFilterXLink;
218 OUString maMaskXLink;
219 const SvgMaskNode* mpMaskXLink;
221 /// link to markers. If set, the node can be fetched on demand
222 OUString maMarkerStartXLink;
223 const SvgMarkerNode* mpMarkerStartXLink;
224 OUString maMarkerMidXLink;
225 const SvgMarkerNode* mpMarkerMidXLink;
226 OUString maMarkerEndXLink;
227 const SvgMarkerNode* mpMarkerEndXLink;
229 /// fill rule
230 FillRule maFillRule;
232 // ClipRule setting (only valid when mbIsClipPathContent == true, default is FillRule_nonzero)
233 FillRule maClipRule;
235 // BaselineShift: Type and number (in case of BaselineShift_Percentage or BaselineShift_Length)
236 BaselineShift maBaselineShift;
237 SvgNumber maBaselineShiftNumber;
239 DominantBaseline maDominantBaseline;
241 mutable std::vector<sal_uInt16> maResolvingParent;
243 // defines if this attributes are part of a ClipPath. If yes,
244 // rough geometry will be created on decomposition by patching
245 // values for fill, stroke, strokeWidth and others
246 bool mbIsClipPathContent : 1;
248 // #121221# Defines if evtl. an empty array *is* set
249 bool mbStrokeDasharraySet : 1;
251 // tdf#94765 Check id references in gradient/pattern getters
252 OUString maNodeFillURL;
253 OUString maNodeStrokeURL;
255 /// internal helpers
256 void add_fillGradient(
257 const basegfx::B2DPolyPolygon& rPath,
258 drawinglayer::primitive2d::Primitive2DContainer& rTarget,
259 const SvgGradientNode& rFillGradient,
260 const basegfx::B2DRange& rGeoRange) const;
261 void add_fillPatternTransform(
262 const basegfx::B2DPolyPolygon& rPath,
263 drawinglayer::primitive2d::Primitive2DContainer& rTarget,
264 const SvgPatternNode& rFillGradient,
265 const basegfx::B2DRange& rGeoRange) const;
266 void add_fillPattern(
267 const basegfx::B2DPolyPolygon& rPath,
268 drawinglayer::primitive2d::Primitive2DContainer& rTarget,
269 const SvgPatternNode& rFillGradient,
270 const basegfx::B2DRange& rGeoRange) const;
271 void add_fill(
272 const basegfx::B2DPolyPolygon& rPath,
273 drawinglayer::primitive2d::Primitive2DContainer& rTarget,
274 const basegfx::B2DRange& rGeoRange) const;
275 void add_stroke(
276 const basegfx::B2DPolyPolygon& rPath,
277 drawinglayer::primitive2d::Primitive2DContainer& rTarget,
278 const basegfx::B2DRange& rGeoRange) const;
279 bool prepare_singleMarker(
280 drawinglayer::primitive2d::Primitive2DContainer& rMarkerPrimitives,
281 basegfx::B2DHomMatrix& rMarkerTransform,
282 basegfx::B2DRange& rClipRange,
283 const SvgMarkerNode& rMarker) const;
284 void add_markers(
285 const basegfx::B2DPolyPolygon& rPath,
286 drawinglayer::primitive2d::Primitive2DContainer& rTarget,
287 const basegfx::utils::PointIndexSet* pHelpPointIndices) const;
290 public:
291 /// local attribute scanner
292 void parseStyleAttribute(SVGToken aSVGToken, const OUString& rContent);
294 /// helper which does the necessary with a given path
295 void add_text(
296 drawinglayer::primitive2d::Primitive2DContainer& rTarget,
297 drawinglayer::primitive2d::Primitive2DContainer&& rSource) const;
298 void add_path(
299 const basegfx::B2DPolyPolygon& rPath,
300 drawinglayer::primitive2d::Primitive2DContainer& rTarget,
301 const basegfx::utils::PointIndexSet* pHelpPointIndices) const;
302 void add_postProcess(
303 drawinglayer::primitive2d::Primitive2DContainer& rTarget,
304 drawinglayer::primitive2d::Primitive2DContainer&& rSource,
305 const std::optional<basegfx::B2DHomMatrix>& pTransform) const;
307 /// helper to set mpCssStyleParent temporarily for CSS style hierarchies
308 void setCssStyleParent(const SvgStyleAttributes* pNew) { mpCssStyleParent = pNew; }
309 const SvgStyleAttributes* getCssStyleParent() const { return mpCssStyleParent; }
311 /// scan helpers
312 void readCssStyle(std::u16string_view rCandidate);
313 const SvgStyleAttributes* getParentStyle() const;
315 SvgStyleAttributes(SvgNode& rOwner);
316 ~SvgStyleAttributes();
318 /// fill content
319 bool isFillSet() const; // #i125258# ask if fill is a direct hard attribute (no hierarchy)
320 const basegfx::BColor* getFill() const;
321 void setFill(const SvgPaint& rFill) { maFill = rFill; }
323 /// stroke content
324 const basegfx::BColor* getStroke() const;
326 /// stop color content
327 const basegfx::BColor& getStopColor() const;
329 /// stroke-width content
330 SvgNumber getStrokeWidth() const;
332 /// stop opacity content
333 SvgNumber getStopOpacity() const;
335 /// access to evtl. set fill gradient
336 const SvgGradientNode* getSvgGradientNodeFill() const;
338 /// access to evtl. set fill pattern
339 const SvgPatternNode* getSvgPatternNodeFill() const;
341 /// access to evtl. set stroke gradient
342 const SvgGradientNode* getSvgGradientNodeStroke() const;
344 /// access to evtl. set stroke pattern
345 const SvgPatternNode* getSvgPatternNodeStroke() const;
347 /// fill opacity content
348 SvgNumber getFillOpacity() const;
350 /// fill rule content
351 FillRule getFillRule() const;
353 /// clip rule content
354 FillRule getClipRule() const;
356 /// fill StrokeDasharray content
357 const SvgNumberVector& getStrokeDasharray() const;
359 /// StrokeDashOffset content
360 SvgNumber getStrokeDashOffset() const;
362 /// StrokeLinecap content
363 StrokeLinecap getStrokeLinecap() const;
364 void setStrokeLinecap(const StrokeLinecap aStrokeLinecap) { maStrokeLinecap = aStrokeLinecap; }
366 /// StrokeLinejoin content
367 StrokeLinejoin getStrokeLinejoin() const;
368 void setStrokeLinejoin(const StrokeLinejoin aStrokeLinejoin) { maStrokeLinejoin = aStrokeLinejoin; }
370 /// StrokeMiterLimit content
371 SvgNumber getStrokeMiterLimit() const;
373 /// StrokeOpacity content
374 SvgNumber getStrokeOpacity() const;
376 /// Font content
377 const SvgStringVector& getFontFamily() const;
379 /// FontSize content
380 void setFontSize(const FontSize aFontSize) { maFontSize = aFontSize; }
381 SvgNumber getFontSizeNumber() const;
383 /// FontStretch content
384 FontStretch getFontStretch() const;
385 void setFontStretch(const FontStretch aFontStretch) { maFontStretch = aFontStretch; }
387 /// FontStyle content
388 FontStyle getFontStyle() const;
389 void setFontStyle(const FontStyle aFontStyle) { maFontStyle = aFontStyle; }
391 /// FontWeight content
392 FontWeight getFontWeight() const;
393 void setFontWeight(const FontWeight aFontWeight) { maFontWeight = aFontWeight; }
395 /// TextAlign content
396 TextAlign getTextAlign() const;
397 void setTextAlign(const TextAlign aTextAlign) { maTextAlign = aTextAlign; }
399 /// TextDecoration content
400 const SvgStyleAttributes* getTextDecorationDefiningSvgStyleAttributes() const;
401 TextDecoration getTextDecoration() const;
402 void setTextDecoration(const TextDecoration aTextDecoration) { maTextDecoration = aTextDecoration; }
404 /// TextAnchor content
405 TextAnchor getTextAnchor() const;
406 void setTextAnchor(const TextAnchor aTextAnchor) { maTextAnchor = aTextAnchor; }
408 /// Color content
409 const basegfx::BColor* getColor() const;
411 /// Resolve current color (defaults to black if no color is specified)
412 const basegfx::BColor* getCurrentColor() const;
414 /// Opacity content
415 SvgNumber getOpacity() const;
416 void setOpacity(const SvgNumber& rOpacity) { maOpacity = rOpacity; }
418 /// Visibility
419 Visibility getVisibility() const;
420 void setVisibility(const Visibility aVisibility) { maVisibility = aVisibility; }
422 // Title content
423 const OUString& getTitle() const { return maTitle; }
425 // Desc content
426 const OUString& getDesc() const { return maDesc; }
428 // ClipPathXLink content
429 OUString getClipPathXLink() const;
430 const SvgClipPathNode* accessClipPathXLink() const;
432 // FilterXLink content
433 OUString getFilterXLink() const;
434 const SvgFilterNode* accessFilterXLink() const;
436 // MaskXLink content
437 OUString getMaskXLink() const;
438 const SvgMaskNode* accessMaskXLink() const;
440 // MarkerStartXLink content
441 OUString getMarkerStartXLink() const;
442 const SvgMarkerNode* accessMarkerStartXLink() const;
444 // MarkerMidXLink content
445 OUString getMarkerMidXLink() const;
446 const SvgMarkerNode* accessMarkerMidXLink() const;
448 // MarkerEndXLink content
449 OUString getMarkerEndXLink() const;
450 const SvgMarkerNode* accessMarkerEndXLink() const;
452 // BaselineShift
453 void setBaselineShift(const BaselineShift aBaselineShift) { maBaselineShift = aBaselineShift; }
454 BaselineShift getBaselineShift() const;
455 SvgNumber getBaselineShiftNumber() const;
457 // DominantBaseline
458 void setDominantBaseline(const DominantBaseline aDominantBaseline) { maDominantBaseline = aDominantBaseline; }
459 DominantBaseline getDominantBaseline() const;
462 } // end of namespace svgio::svgreader
464 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */