Debian Codegraph @

svgio/inc/svgstyleattributes.hxx

raw symbols SCIP
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 #pragma once
21
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>
28
29
30 // predefines
31
32 namespace svgio::svgreader {
33 class SvgGradientNode;
34 class SvgPatternNode;
35 class SvgMarkerNode;
36 class SvgClipPathNode;
37 class SvgFilterNode;
38 class SvgMaskNode;
39 }
40
41
42 namespace svgio::svgreader
43 {
44 enum class StrokeLinecap
45 {
46 notset,
47 butt,
48 round,
49 square
50 };
51
52 enum class StrokeLinejoin
53 {
54 notset,
55 miter,
56 round,
57 bevel
58 };
59
60 enum class FontSize
61 {
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
73 };
74
75 enum class FontStretch
76 {
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
89 };
90
91 FontStretch getWider(FontStretch aSource);
92 FontStretch getNarrower(FontStretch aSource);
93
94 enum class FontStyle
95 {
96 notset,
97 normal,
98 italic,
99 oblique
100 };
101
102 enum class FontWeight
103 {
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,
116 };
117
118 enum class FontDirection
119 {
120 notset,
121 LTR,
122 RTL,
123 };
124
125 enum class UnicodeBidi
126 {
127 notset,
128 normal,
129 bidi_override,
130 };
131
132 FontWeight getBolder(FontWeight aSource);
133 FontWeight getLighter(FontWeight aSource);
134 ::FontWeight getVclFontWeight(FontWeight aSource);
135
136 enum class TextAlign
137 {
138 notset,
139 left,
140 right,
141 center,
142 justify
143 };
144
145 enum class TextDecoration
146 {
147 notset,
148 none,
149 underline,
150 overline,
151 line_through,
152 blink
153 };
154
155 enum class TextAnchor
156 {
157 notset,
158 start,
159 middle,
160 end
161 };
162
163 enum class FillRule
164 {
165 notset,
166 nonzero,
167 evenodd
168 };
169
170 enum class BaselineShift
171 {
172 Baseline,
173 Sub,
174 Super,
175 Percentage,
176 Length
177 };
178
179 enum class DominantBaseline
180 {
181 Auto,
182 Middle,
183 Hanging,
184 Central
185 };
186
187 enum class Overflow
188 {
189 notset,
190 hidden,
191 visible
192 };
193
194 enum class Visibility
195 {
196 notset,
197 visible,
198 hidden,
199 collapse,
200 inherit
201 };
202
203 class SvgStyleAttributes
204 {
205 private:
206 SvgNode& mrOwner;
207 const SvgStyleAttributes* mpCssStyle;
208 SvgPaint maFill;
209 SvgPaint maStroke;
210 SvgPaint maStopColor;
211 SvgNumber maStrokeWidth;
212 SvgNumber maStopOpacity;
213 SvgNumber maFillOpacity;
214 SvgNumberVector maStrokeDasharray;
215 SvgNumber maStrokeDashOffset;
216 StrokeLinecap maStrokeLinecap;
217 StrokeLinejoin maStrokeLinejoin;
218 SvgNumber maStrokeMiterLimit;
219 SvgNumber maStrokeOpacity;
220 SvgStringVector maFontFamily;
221 FontSize maFontSize;
222 SvgNumber maFontSizeNumber;
223 FontStretch maFontStretch;
224 FontStyle maFontStyle;
225 FontWeight maFontWeight;
226 FontDirection maFontDirection;
227 UnicodeBidi maUnicodeBidi;
228 TextAlign maTextAlign;
229 TextDecoration maTextDecoration;
230 TextAnchor maTextAnchor;
231 SvgPaint maColor;
232 SvgNumber maOpacity;
233 Overflow maOverflow;
234 Visibility maVisibility;
235 OUString maTitle;
236 OUString maDesc;
237
238 /// link to content. If set, the node can be fetched on demand
239 OUString maClipPathXLink;
240 OUString maFilterXLink;
241 OUString maMaskXLink;
242
243 /// link to markers. If set, the node can be fetched on demand
244 OUString maMarkerStartXLink;
245 OUString maMarkerMidXLink;
246 OUString maMarkerEndXLink;
247
248 /// fill rule
249 FillRule maFillRule;
250
251 // ClipRule setting (only valid when mbIsClipPathContent == true, default is FillRule_nonzero)
252 FillRule maClipRule;
253
254 // BaselineShift: Type and number (in case of BaselineShift_Percentage or BaselineShift_Length)
255 BaselineShift maBaselineShift;
256 SvgNumber maBaselineShiftNumber;
257
258 DominantBaseline maDominantBaseline;
259
260 mutable std::vector<sal_uInt16> maResolvingParent;
261
262
263 // #121221# Defines if evtl. an empty array *is* set
264 bool mbStrokeDasharraySet : 1;
265
266 // tdf#155651 Defines if 'context-fill' is used in fill
267 bool mbUseFillFromContextFill : 1;
268
269 // tdf#155651 Defines if 'context-stroke' is used in fill
270 bool mbUseFillFromContextStroke : 1;
271
272 // tdf#155651 Defines if 'context-fill' is used in stroke
273 bool mbUseStrokeFromContextFill : 1;
274
275 // tdf#155651 Defines if 'context-stroke' is used in stroke
276 bool mbUseStrokeFromContextStroke : 1;
277
278 // tdf#94765 Check id references in gradient/pattern getters
279 OUString maNodeFillURL;
280 OUString maNodeStrokeURL;
281
282 /// internal helpers
283 void add_fillGradient(
284 const basegfx::B2DPolyPolygon& rPath,
285 drawinglayer::primitive2d::Primitive2DContainer& rTarget,
286 const SvgGradientNode& rFillGradient,
287 const basegfx::B2DRange& rGeoRange) const;
288 void add_fillPatternTransform(
289 const basegfx::B2DPolyPolygon& rPath,
290 drawinglayer::primitive2d::Primitive2DContainer& rTarget,
291 const SvgPatternNode& rFillGradient,
292 const basegfx::B2DRange& rGeoRange) const;
293 void add_fillPattern(
294 const basegfx::B2DPolyPolygon& rPath,
295 drawinglayer::primitive2d::Primitive2DContainer& rTarget,
296 const SvgPatternNode& rFillGradient,
297 const basegfx::B2DRange& rGeoRange) const;
298 void add_fill(
299 const basegfx::B2DPolyPolygon& rPath,
300 drawinglayer::primitive2d::Primitive2DContainer& rTarget,
301 const basegfx::B2DRange& rGeoRange) const;
302 void add_stroke(
303 const basegfx::B2DPolyPolygon& rPath,
304 drawinglayer::primitive2d::Primitive2DContainer& rTarget,
305 const basegfx::B2DRange& rGeoRange) const;
306 bool prepare_singleMarker(
307 drawinglayer::primitive2d::Primitive2DContainer& rMarkerPrimitives,
308 basegfx::B2DHomMatrix& rMarkerTransform,
309 basegfx::B2DRange& rClipRange,
310 const SvgMarkerNode& rMarker) const;
311 void add_markers(
312 const basegfx::B2DPolyPolygon& rPath,
313 drawinglayer::primitive2d::Primitive2DContainer& rTarget,
314 const basegfx::utils::PointIndexSet* pHelpPointIndices) const;
315
316
317 public:
318 /// local attribute scanner
319 void parseStyleAttribute(SVGToken aSVGToken, const OUString& rContent);
320
321 /// helper which does the necessary with a given path
322 void add_text(
323 drawinglayer::primitive2d::Primitive2DContainer& rTarget,
324 drawinglayer::primitive2d::Primitive2DContainer&& rSource) const;
325 void add_path(
326 const basegfx::B2DPolyPolygon& rPath,
327 drawinglayer::primitive2d::Primitive2DContainer& rTarget,
328 const basegfx::utils::PointIndexSet* pHelpPointIndices) const;
329 void add_postProcess(
330 drawinglayer::primitive2d::Primitive2DContainer& rTarget,
331 drawinglayer::primitive2d::Primitive2DContainer&& rSource,
332 const std::optional<basegfx::B2DHomMatrix>& pTransform) const;
333
334 /// helper to set mpCssStyle temporarily for CSS style hierarchies
335 void setCssStyle(const SvgStyleAttributes* pNew) { mpCssStyle = pNew; }
336 const SvgStyleAttributes* getCssStyle() const { return mpCssStyle; }
337
338 /// scan helpers
339 void readCssStyle(std::u16string_view rCandidate);
340 const SvgStyleAttributes* getCssStyleOrParentStyle() const;
341
342 const SvgMarkerNode* getMarkerParentNode() const;
343
344 SvgStyleAttributes(SvgNode& rOwner);
345 ~SvgStyleAttributes();
346
347 // Check if this attribute is part of a ClipPath.
348 // If so, rough geometry will be created on decomposition by patching
349 // values for fill, stroke, strokeWidth and others
350 bool isClipPathContent() const;
351
352 /// fill content
353 bool isFillSet() const; // #i125258# ask if fill is a direct hard attribute (no hierarchy)
354 const basegfx::BColor* getFill() const;
355 void setFill(const SvgPaint& rFill) { maFill = rFill; }
356
357 /// stroke content
358 const basegfx::BColor* getStroke() const;
359
360 /// context fill content
361 const basegfx::BColor* getContextFill() const;
362
363 /// context stroke content
364 const basegfx::BColor* getContextStroke() const;
365
366 /// stop color content
367 const basegfx::BColor& getStopColor() const;
368
369 /// stroke-width content
370 SvgNumber getStrokeWidth() const;
371
372 /// stop opacity content
373 SvgNumber getStopOpacity() const;
374
375 /// access to evtl. set fill gradient
376 const SvgGradientNode* getSvgGradientNodeFill() const;
377
378 /// access to evtl. set fill pattern
379 const SvgPatternNode* getSvgPatternNodeFill() const;
380
381 /// access to evtl. set stroke gradient
382 const SvgGradientNode* getSvgGradientNodeStroke() const;
383
384 /// access to evtl. set stroke pattern
385 const SvgPatternNode* getSvgPatternNodeStroke() const;
386
387 /// fill opacity content
388 SvgNumber getFillOpacity() const;
389
390 /// fill rule content
391 FillRule getFillRule() const;
392
393 /// clip rule content
394 FillRule getClipRule() const;
395
396 /// fill StrokeDasharray content
397 const SvgNumberVector& getStrokeDasharray() const;
398
399 /// StrokeDashOffset content
400 SvgNumber getStrokeDashOffset() const;
401
402 /// StrokeLinecap content
403 StrokeLinecap getStrokeLinecap() const;
404 void setStrokeLinecap(const StrokeLinecap aStrokeLinecap) { maStrokeLinecap = aStrokeLinecap; }
405
406 /// StrokeLinejoin content
407 StrokeLinejoin getStrokeLinejoin() const;
408 void setStrokeLinejoin(const StrokeLinejoin aStrokeLinejoin) { maStrokeLinejoin = aStrokeLinejoin; }
409
410 /// StrokeMiterLimit content
411 SvgNumber getStrokeMiterLimit() const;
412
413 /// StrokeOpacity content
414 SvgNumber getStrokeOpacity() const;
415
416 /// Font content
417 const SvgStringVector& getFontFamily() const;
418
419 /// FontSize content
420 void setFontSize(const FontSize aFontSize) { maFontSize = aFontSize; }
421 SvgNumber getFontSizeNumber() const;
422
423 /// FontStretch content
424 FontStretch getFontStretch() const;
425 void setFontStretch(const FontStretch aFontStretch) { maFontStretch = aFontStretch; }
426
427 /// FontStyle content
428 FontStyle getFontStyle() const;
429 void setFontStyle(const FontStyle aFontStyle) { maFontStyle = aFontStyle; }
430
431 /// FontWeight content
432 FontWeight getFontWeight() const;
433 void setFontWeight(const FontWeight aFontWeight) { maFontWeight = aFontWeight; }
434
435 /// FontDirection content
436 FontDirection getFontDirection() const;
437 void setFontDirection(const FontDirection aFontDirection) { maFontDirection = aFontDirection; }
438
439 /// UnicodeBidi content
440 UnicodeBidi getUnicodeBidi() const;
441 void setUnicodeBidi(const UnicodeBidi aUnicodeBidi) { maUnicodeBidi = aUnicodeBidi; }
442
443 /// TextAlign content
444 TextAlign getTextAlign() const;
445 void setTextAlign(const TextAlign aTextAlign) { maTextAlign = aTextAlign; }
446
447 /// TextDecoration content
448 const SvgStyleAttributes* getTextDecorationDefiningSvgStyleAttributes() const;
449 TextDecoration getTextDecoration() const;
450 void setTextDecoration(const TextDecoration aTextDecoration) { maTextDecoration = aTextDecoration; }
451
452 /// TextAnchor content
453 TextAnchor getTextAnchor() const;
454 void setTextAnchor(const TextAnchor aTextAnchor) { maTextAnchor = aTextAnchor; }
455
456 /// Color content
457 const basegfx::BColor* getColor() const;
458
459 /// Resolve current color (defaults to black if no color is specified)
460 const basegfx::BColor* getCurrentColor() const;
461
462 /// Opacity content
463 SvgNumber getOpacity() const;
464 void setOpacity(const SvgNumber& rOpacity) { maOpacity = rOpacity; }
465
466 /// Overflow
467 Overflow getOverflow() const;
468 void setOverflow(const Overflow aOverflow) { maOverflow = aOverflow; }
469
470 /// Visibility
471 Visibility getVisibility() const;
472 void setVisibility(const Visibility aVisibility) { maVisibility = aVisibility; }
473
474 // Title content
475 const OUString& getTitle() const { return maTitle; }
476
477 // Desc content
478 const OUString& getDesc() const { return maDesc; }
479
480 // ClipPathXLink content
481 OUString getClipPathXLink() const;
482 const SvgClipPathNode* accessClipPathXLink() const;
483
484 // FilterXLink content
485 OUString getFilterXLink() const;
486 const SvgFilterNode* accessFilterXLink() const;
487
488 // MaskXLink content
489 OUString getMaskXLink() const;
490 const SvgMaskNode* accessMaskXLink() const;
491
492 // MarkerStartXLink content
493 OUString getMarkerStartXLink() const;
494 const SvgMarkerNode* accessMarkerStartXLink() const;
495
496 // MarkerMidXLink content
497 OUString getMarkerMidXLink() const;
498 const SvgMarkerNode* accessMarkerMidXLink() const;
499
500 // MarkerEndXLink content
501 OUString getMarkerEndXLink() const;
502 const SvgMarkerNode* accessMarkerEndXLink() const;
503
504 // BaselineShift
505 void setBaselineShift(const BaselineShift aBaselineShift) { maBaselineShift = aBaselineShift; }
506 BaselineShift getBaselineShift() const;
507 SvgNumber getBaselineShiftNumber() const;
508
509 // DominantBaseline
510 void setDominantBaseline(const DominantBaseline aDominantBaseline) { maDominantBaseline = aDominantBaseline; }
511 DominantBaseline getDominantBaseline() const;
512 };
513
514 } // end of namespace svgio::svgreader
515
516 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */