Avoid potential negative array index access to cached text.
[LibreOffice.git] / svgio / inc / svgstyleattributes.hxx
blob61a3816e82cbe01605be4bb3b07a4e14787810e8
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-stroke' is used in stroke
251 bool mbContextStroke : 1;
253 // tdf#94765 Check id references in gradient/pattern getters
254 OUString maNodeFillURL;
255 OUString maNodeStrokeURL;
257 const basegfx::BColor* maContextStroke;
259 /// internal helpers
260 void add_fillGradient(
261 const basegfx::B2DPolyPolygon& rPath,
262 drawinglayer::primitive2d::Primitive2DContainer& rTarget,
263 const SvgGradientNode& rFillGradient,
264 const basegfx::B2DRange& rGeoRange) const;
265 void add_fillPatternTransform(
266 const basegfx::B2DPolyPolygon& rPath,
267 drawinglayer::primitive2d::Primitive2DContainer& rTarget,
268 const SvgPatternNode& rFillGradient,
269 const basegfx::B2DRange& rGeoRange) const;
270 void add_fillPattern(
271 const basegfx::B2DPolyPolygon& rPath,
272 drawinglayer::primitive2d::Primitive2DContainer& rTarget,
273 const SvgPatternNode& rFillGradient,
274 const basegfx::B2DRange& rGeoRange) const;
275 void add_fill(
276 const basegfx::B2DPolyPolygon& rPath,
277 drawinglayer::primitive2d::Primitive2DContainer& rTarget,
278 const basegfx::B2DRange& rGeoRange) const;
279 void add_stroke(
280 const basegfx::B2DPolyPolygon& rPath,
281 drawinglayer::primitive2d::Primitive2DContainer& rTarget,
282 const basegfx::B2DRange& rGeoRange) const;
283 bool prepare_singleMarker(
284 drawinglayer::primitive2d::Primitive2DContainer& rMarkerPrimitives,
285 basegfx::B2DHomMatrix& rMarkerTransform,
286 basegfx::B2DRange& rClipRange,
287 const SvgMarkerNode& rMarker) const;
288 void add_markers(
289 const basegfx::B2DPolyPolygon& rPath,
290 drawinglayer::primitive2d::Primitive2DContainer& rTarget,
291 const basegfx::utils::PointIndexSet* pHelpPointIndices) const;
294 public:
295 /// local attribute scanner
296 void parseStyleAttribute(SVGToken aSVGToken, const OUString& rContent);
298 /// helper which does the necessary with a given path
299 void add_text(
300 drawinglayer::primitive2d::Primitive2DContainer& rTarget,
301 drawinglayer::primitive2d::Primitive2DContainer&& rSource) const;
302 void add_path(
303 const basegfx::B2DPolyPolygon& rPath,
304 drawinglayer::primitive2d::Primitive2DContainer& rTarget,
305 const basegfx::utils::PointIndexSet* pHelpPointIndices) const;
306 void add_postProcess(
307 drawinglayer::primitive2d::Primitive2DContainer& rTarget,
308 drawinglayer::primitive2d::Primitive2DContainer&& rSource,
309 const std::optional<basegfx::B2DHomMatrix>& pTransform) const;
311 /// helper to set mpCssStyleParent temporarily for CSS style hierarchies
312 void setCssStyleParent(const SvgStyleAttributes* pNew) { mpCssStyleParent = pNew; }
313 const SvgStyleAttributes* getCssStyleParent() const { return mpCssStyleParent; }
315 /// scan helpers
316 void readCssStyle(std::u16string_view rCandidate);
317 const SvgStyleAttributes* getParentStyle() const;
319 SvgStyleAttributes(SvgNode& rOwner);
320 ~SvgStyleAttributes();
322 // Check if this attribute is part of a ClipPath.
323 // If so, rough geometry will be created on decomposition by patching
324 // values for fill, stroke, strokeWidth and others
325 bool isClipPathContent() const;
327 /// fill content
328 bool isFillSet() const; // #i125258# ask if fill is a direct hard attribute (no hierarchy)
329 const basegfx::BColor* getFill() const;
330 void setFill(const SvgPaint& rFill) { maFill = rFill; }
332 /// stroke content
333 const basegfx::BColor* getStroke() const;
335 /// context stroke content
336 const basegfx::BColor* getContextStroke() const;
338 /// stop color content
339 const basegfx::BColor& getStopColor() const;
341 /// stroke-width content
342 SvgNumber getStrokeWidth() const;
344 /// stop opacity content
345 SvgNumber getStopOpacity() const;
347 /// access to evtl. set fill gradient
348 const SvgGradientNode* getSvgGradientNodeFill() const;
350 /// access to evtl. set fill pattern
351 const SvgPatternNode* getSvgPatternNodeFill() const;
353 /// access to evtl. set stroke gradient
354 const SvgGradientNode* getSvgGradientNodeStroke() const;
356 /// access to evtl. set stroke pattern
357 const SvgPatternNode* getSvgPatternNodeStroke() const;
359 /// fill opacity content
360 SvgNumber getFillOpacity() const;
362 /// fill rule content
363 FillRule getFillRule() const;
365 /// clip rule content
366 FillRule getClipRule() const;
368 /// fill StrokeDasharray content
369 const SvgNumberVector& getStrokeDasharray() const;
371 /// StrokeDashOffset content
372 SvgNumber getStrokeDashOffset() const;
374 /// StrokeLinecap content
375 StrokeLinecap getStrokeLinecap() const;
376 void setStrokeLinecap(const StrokeLinecap aStrokeLinecap) { maStrokeLinecap = aStrokeLinecap; }
378 /// StrokeLinejoin content
379 StrokeLinejoin getStrokeLinejoin() const;
380 void setStrokeLinejoin(const StrokeLinejoin aStrokeLinejoin) { maStrokeLinejoin = aStrokeLinejoin; }
382 /// StrokeMiterLimit content
383 SvgNumber getStrokeMiterLimit() const;
385 /// StrokeOpacity content
386 SvgNumber getStrokeOpacity() const;
388 /// Font content
389 const SvgStringVector& getFontFamily() const;
391 /// FontSize content
392 void setFontSize(const FontSize aFontSize) { maFontSize = aFontSize; }
393 SvgNumber getFontSizeNumber() const;
395 /// FontStretch content
396 FontStretch getFontStretch() const;
397 void setFontStretch(const FontStretch aFontStretch) { maFontStretch = aFontStretch; }
399 /// FontStyle content
400 FontStyle getFontStyle() const;
401 void setFontStyle(const FontStyle aFontStyle) { maFontStyle = aFontStyle; }
403 /// FontWeight content
404 FontWeight getFontWeight() const;
405 void setFontWeight(const FontWeight aFontWeight) { maFontWeight = aFontWeight; }
407 /// TextAlign content
408 TextAlign getTextAlign() const;
409 void setTextAlign(const TextAlign aTextAlign) { maTextAlign = aTextAlign; }
411 /// TextDecoration content
412 const SvgStyleAttributes* getTextDecorationDefiningSvgStyleAttributes() const;
413 TextDecoration getTextDecoration() const;
414 void setTextDecoration(const TextDecoration aTextDecoration) { maTextDecoration = aTextDecoration; }
416 /// TextAnchor content
417 TextAnchor getTextAnchor() const;
418 void setTextAnchor(const TextAnchor aTextAnchor) { maTextAnchor = aTextAnchor; }
420 /// Color content
421 const basegfx::BColor* getColor() const;
423 /// Resolve current color (defaults to black if no color is specified)
424 const basegfx::BColor* getCurrentColor() const;
426 /// Opacity content
427 SvgNumber getOpacity() const;
428 void setOpacity(const SvgNumber& rOpacity) { maOpacity = rOpacity; }
430 /// Overflow
431 Overflow getOverflow() const;
432 void setOverflow(const Overflow aOverflow) { maOverflow = aOverflow; }
434 /// Visibility
435 Visibility getVisibility() const;
436 void setVisibility(const Visibility aVisibility) { maVisibility = aVisibility; }
438 // Title content
439 const OUString& getTitle() const { return maTitle; }
441 // Desc content
442 const OUString& getDesc() const { return maDesc; }
444 // ClipPathXLink content
445 OUString getClipPathXLink() const;
446 const SvgClipPathNode* accessClipPathXLink() const;
448 // FilterXLink content
449 OUString getFilterXLink() const;
450 const SvgFilterNode* accessFilterXLink() const;
452 // MaskXLink content
453 OUString getMaskXLink() const;
454 const SvgMaskNode* accessMaskXLink() const;
456 // MarkerStartXLink content
457 OUString getMarkerStartXLink() const;
458 const SvgMarkerNode* accessMarkerStartXLink() const;
460 // MarkerMidXLink content
461 OUString getMarkerMidXLink() const;
462 const SvgMarkerNode* accessMarkerMidXLink() const;
464 // MarkerEndXLink content
465 OUString getMarkerEndXLink() const;
466 const SvgMarkerNode* accessMarkerEndXLink() const;
468 // BaselineShift
469 void setBaselineShift(const BaselineShift aBaselineShift) { maBaselineShift = aBaselineShift; }
470 BaselineShift getBaselineShift() const;
471 SvgNumber getBaselineShiftNumber() const;
473 // DominantBaseline
474 void setDominantBaseline(const DominantBaseline aDominantBaseline) { maDominantBaseline = aDominantBaseline; }
475 DominantBaseline getDominantBaseline() const;
478 } // end of namespace svgio::svgreader
480 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */