1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
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>
32 namespace svgio::svgreader
{
33 class SvgGradientNode
;
36 class SvgClipPathNode
;
42 namespace svgio::svgreader
44 enum class StrokeLinecap
52 enum class StrokeLinejoin
75 enum class FontStretch
91 FontStretch
getWider(FontStretch aSource
);
92 FontStretch
getNarrower(FontStretch aSource
);
102 enum class FontWeight
108 N400
, // same as normal
111 N700
, // same as bold
118 FontWeight
getBolder(FontWeight aSource
);
119 FontWeight
getLighter(FontWeight aSource
);
120 ::FontWeight
getVclFontWeight(FontWeight aSource
);
131 enum class TextDecoration
141 enum class TextAnchor
156 enum class BaselineShift
165 enum class DominantBaseline
172 enum class Visibility
181 class SvgStyleAttributes
185 const SvgStyleAttributes
* mpCssStyleParent
;
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
;
200 SvgNumber maFontSizeNumber
;
201 FontStretch maFontStretch
;
202 FontStyle maFontStyle
;
203 FontWeight maFontWeight
;
204 TextAlign maTextAlign
;
205 TextDecoration maTextDecoration
;
206 TextAnchor maTextAnchor
;
209 Visibility maVisibility
;
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
;
232 // ClipRule setting (only valid when mbIsClipPathContent == true, default is FillRule_nonzero)
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
;
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;
272 const basegfx::B2DPolyPolygon
& rPath
,
273 drawinglayer::primitive2d::Primitive2DContainer
& rTarget
,
274 const basegfx::B2DRange
& rGeoRange
) const;
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;
285 const basegfx::B2DPolyPolygon
& rPath
,
286 drawinglayer::primitive2d::Primitive2DContainer
& rTarget
,
287 const basegfx::utils::PointIndexSet
* pHelpPointIndices
) const;
291 /// local attribute scanner
292 void parseStyleAttribute(SVGToken aSVGToken
, const OUString
& rContent
);
294 /// helper which does the necessary with a given path
296 drawinglayer::primitive2d::Primitive2DContainer
& rTarget
,
297 drawinglayer::primitive2d::Primitive2DContainer
&& rSource
) const;
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
; }
312 void readCssStyle(std::u16string_view rCandidate
);
313 const SvgStyleAttributes
* getParentStyle() const;
315 SvgStyleAttributes(SvgNode
& rOwner
);
316 ~SvgStyleAttributes();
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
; }
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;
377 const SvgStringVector
& getFontFamily() const;
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
; }
409 const basegfx::BColor
* getColor() const;
411 /// Resolve current color (defaults to black if no color is specified)
412 const basegfx::BColor
* getCurrentColor() const;
415 SvgNumber
getOpacity() const;
416 void setOpacity(const SvgNumber
& rOpacity
) { maOpacity
= rOpacity
; }
419 Visibility
getVisibility() const;
420 void setVisibility(const Visibility aVisibility
) { maVisibility
= aVisibility
; }
423 const OUString
& getTitle() const { return maTitle
; }
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;
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;
453 void setBaselineShift(const BaselineShift aBaselineShift
) { maBaselineShift
= aBaselineShift
; }
454 BaselineShift
getBaselineShift() const;
455 SvgNumber
getBaselineShiftNumber() const;
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: */