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
180 enum class Visibility
189 class SvgStyleAttributes
193 const SvgStyleAttributes
* mpCssStyleParent
;
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
;
208 SvgNumber maFontSizeNumber
;
209 FontStretch maFontStretch
;
210 FontStyle maFontStyle
;
211 FontWeight maFontWeight
;
212 TextAlign maTextAlign
;
213 TextDecoration maTextDecoration
;
214 TextAnchor maTextAnchor
;
218 Visibility maVisibility
;
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
;
235 // ClipRule setting (only valid when mbIsClipPathContent == true, default is FillRule_nonzero)
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
;
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;
280 const basegfx::B2DPolyPolygon
& rPath
,
281 drawinglayer::primitive2d::Primitive2DContainer
& rTarget
,
282 const basegfx::B2DRange
& rGeoRange
) const;
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;
293 const basegfx::B2DPolyPolygon
& rPath
,
294 drawinglayer::primitive2d::Primitive2DContainer
& rTarget
,
295 const basegfx::utils::PointIndexSet
* pHelpPointIndices
) const;
299 /// local attribute scanner
300 void parseStyleAttribute(SVGToken aSVGToken
, const OUString
& rContent
);
302 /// helper which does the necessary with a given path
304 drawinglayer::primitive2d::Primitive2DContainer
& rTarget
,
305 drawinglayer::primitive2d::Primitive2DContainer
&& rSource
) const;
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
; }
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;
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
; }
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;
396 const SvgStringVector
& getFontFamily() const;
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
; }
428 const basegfx::BColor
* getColor() const;
430 /// Resolve current color (defaults to black if no color is specified)
431 const basegfx::BColor
* getCurrentColor() const;
434 SvgNumber
getOpacity() const;
435 void setOpacity(const SvgNumber
& rOpacity
) { maOpacity
= rOpacity
; }
438 Overflow
getOverflow() const;
439 void setOverflow(const Overflow aOverflow
) { maOverflow
= aOverflow
; }
442 Visibility
getVisibility() const;
443 void setVisibility(const Visibility aVisibility
) { maVisibility
= aVisibility
; }
446 const OUString
& getTitle() const { return maTitle
; }
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;
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;
476 void setBaselineShift(const BaselineShift aBaselineShift
) { maBaselineShift
= aBaselineShift
; }
477 BaselineShift
getBaselineShift() const;
478 SvgNumber
getBaselineShiftNumber() const;
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: */