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
;
41 namespace svgio::svgreader
43 enum class StrokeLinecap
51 enum class StrokeLinejoin
74 enum class FontStretch
90 FontStretch
getWider(FontStretch aSource
);
91 FontStretch
getNarrower(FontStretch aSource
);
101 enum class FontWeight
107 N400
, // same as normal
110 N700
, // same as bold
117 FontWeight
getBolder(FontWeight aSource
);
118 FontWeight
getLighter(FontWeight aSource
);
119 ::FontWeight
getVclFontWeight(FontWeight aSource
);
130 enum class TextDecoration
140 enum class TextAnchor
155 enum class BaselineShift
164 enum class Visibility
173 class SvgStyleAttributes
177 const SvgStyleAttributes
* mpCssStyleParent
;
180 SvgPaint maStopColor
;
181 SvgNumber maStrokeWidth
;
182 SvgNumber maStopOpacity
;
183 SvgNumber maFillOpacity
;
184 SvgNumberVector maStrokeDasharray
;
185 SvgNumber maStrokeDashOffset
;
186 StrokeLinecap maStrokeLinecap
;
187 StrokeLinejoin maStrokeLinejoin
;
188 SvgNumber maStrokeMiterLimit
;
189 SvgNumber maStrokeOpacity
;
190 SvgStringVector maFontFamily
;
192 SvgNumber maFontSizeNumber
;
193 FontStretch maFontStretch
;
194 FontStyle maFontStyle
;
195 FontWeight maFontWeight
;
196 TextAlign maTextAlign
;
197 TextDecoration maTextDecoration
;
198 TextAnchor maTextAnchor
;
201 Visibility maVisibility
;
205 /// link to content. If set, the node can be fetched on demand
206 OUString maClipPathXLink
;
207 const SvgClipPathNode
* mpClipPathXLink
;
208 OUString maMaskXLink
;
209 const SvgMaskNode
* mpMaskXLink
;
211 /// link to markers. If set, the node can be fetched on demand
212 OUString maMarkerStartXLink
;
213 const SvgMarkerNode
* mpMarkerStartXLink
;
214 OUString maMarkerMidXLink
;
215 const SvgMarkerNode
* mpMarkerMidXLink
;
216 OUString maMarkerEndXLink
;
217 const SvgMarkerNode
* mpMarkerEndXLink
;
222 // ClipRule setting (only valid when mbIsClipPathContent == true, default is FillRule_nonzero)
225 // BaselineShift: Type and number (in case of BaselineShift_Percentage or BaselineShift_Length)
226 BaselineShift maBaselineShift
;
227 SvgNumber maBaselineShiftNumber
;
229 mutable std::vector
<sal_uInt16
> maResolvingParent
;
231 // defines if this attributes are part of a ClipPath. If yes,
232 // rough geometry will be created on decomposition by patching
233 // values for fill, stroke, strokeWidth and others
234 bool mbIsClipPathContent
: 1;
236 // #121221# Defines if evtl. an empty array *is* set
237 bool mbStrokeDasharraySet
: 1;
239 // tdf#94765 Check id references in gradient/pattern getters
240 OUString maNodeFillURL
;
241 OUString maNodeStrokeURL
;
244 void add_fillGradient(
245 const basegfx::B2DPolyPolygon
& rPath
,
246 drawinglayer::primitive2d::Primitive2DContainer
& rTarget
,
247 const SvgGradientNode
& rFillGradient
,
248 const basegfx::B2DRange
& rGeoRange
) const;
249 void add_fillPatternTransform(
250 const basegfx::B2DPolyPolygon
& rPath
,
251 drawinglayer::primitive2d::Primitive2DContainer
& rTarget
,
252 const SvgPatternNode
& rFillGradient
,
253 const basegfx::B2DRange
& rGeoRange
) const;
254 void add_fillPattern(
255 const basegfx::B2DPolyPolygon
& rPath
,
256 drawinglayer::primitive2d::Primitive2DContainer
& rTarget
,
257 const SvgPatternNode
& rFillGradient
,
258 const basegfx::B2DRange
& rGeoRange
) const;
260 const basegfx::B2DPolyPolygon
& rPath
,
261 drawinglayer::primitive2d::Primitive2DContainer
& rTarget
,
262 const basegfx::B2DRange
& rGeoRange
) const;
264 const basegfx::B2DPolyPolygon
& rPath
,
265 drawinglayer::primitive2d::Primitive2DContainer
& rTarget
,
266 const basegfx::B2DRange
& rGeoRange
) const;
267 bool prepare_singleMarker(
268 drawinglayer::primitive2d::Primitive2DContainer
& rMarkerPrimitives
,
269 basegfx::B2DHomMatrix
& rMarkerTransform
,
270 basegfx::B2DRange
& rClipRange
,
271 const SvgMarkerNode
& rMarker
) const;
273 const basegfx::B2DPolyPolygon
& rPath
,
274 drawinglayer::primitive2d::Primitive2DContainer
& rTarget
,
275 const basegfx::utils::PointIndexSet
* pHelpPointIndices
) const;
279 /// local attribute scanner
280 void parseStyleAttribute(SVGToken aSVGToken
, const OUString
& rContent
);
282 /// helper which does the necessary with a given path
284 drawinglayer::primitive2d::Primitive2DContainer
& rTarget
,
285 drawinglayer::primitive2d::Primitive2DContainer
&& rSource
) const;
287 const basegfx::B2DPolyPolygon
& rPath
,
288 drawinglayer::primitive2d::Primitive2DContainer
& rTarget
,
289 const basegfx::utils::PointIndexSet
* pHelpPointIndices
) const;
290 void add_postProcess(
291 drawinglayer::primitive2d::Primitive2DContainer
& rTarget
,
292 drawinglayer::primitive2d::Primitive2DContainer
&& rSource
,
293 const std::optional
<basegfx::B2DHomMatrix
>& pTransform
) const;
295 /// helper to set mpCssStyleParent temporarily for CSS style hierarchies
296 void setCssStyleParent(const SvgStyleAttributes
* pNew
) { mpCssStyleParent
= pNew
; }
297 const SvgStyleAttributes
* getCssStyleParent() const { return mpCssStyleParent
; }
300 void readCssStyle(std::u16string_view rCandidate
);
301 const SvgStyleAttributes
* getParentStyle() const;
303 SvgStyleAttributes(SvgNode
& rOwner
);
304 ~SvgStyleAttributes();
307 bool isFillSet() const; // #i125258# ask if fill is a direct hard attribute (no hierarchy)
308 const basegfx::BColor
* getFill() const;
309 void setFill(const SvgPaint
& rFill
) { maFill
= rFill
; }
312 const basegfx::BColor
* getStroke() const;
314 /// stop color content
315 const basegfx::BColor
& getStopColor() const;
317 /// stroke-width content
318 SvgNumber
getStrokeWidth() const;
320 /// stop opacity content
321 SvgNumber
getStopOpacity() const;
323 /// access to evtl. set fill gradient
324 const SvgGradientNode
* getSvgGradientNodeFill() const;
326 /// access to evtl. set fill pattern
327 const SvgPatternNode
* getSvgPatternNodeFill() const;
329 /// access to evtl. set stroke gradient
330 const SvgGradientNode
* getSvgGradientNodeStroke() const;
332 /// access to evtl. set stroke pattern
333 const SvgPatternNode
* getSvgPatternNodeStroke() const;
335 /// fill opacity content
336 SvgNumber
getFillOpacity() const;
338 /// fill rule content
339 FillRule
getFillRule() const;
341 /// clip rule content
342 FillRule
getClipRule() const;
344 /// fill StrokeDasharray content
345 const SvgNumberVector
& getStrokeDasharray() const;
347 /// StrokeDashOffset content
348 SvgNumber
getStrokeDashOffset() const;
350 /// StrokeLinecap content
351 StrokeLinecap
getStrokeLinecap() const;
352 void setStrokeLinecap(const StrokeLinecap aStrokeLinecap
) { maStrokeLinecap
= aStrokeLinecap
; }
354 /// StrokeLinejoin content
355 StrokeLinejoin
getStrokeLinejoin() const;
356 void setStrokeLinejoin(const StrokeLinejoin aStrokeLinejoin
) { maStrokeLinejoin
= aStrokeLinejoin
; }
358 /// StrokeMiterLimit content
359 SvgNumber
getStrokeMiterLimit() const;
361 /// StrokeOpacity content
362 SvgNumber
getStrokeOpacity() const;
365 const SvgStringVector
& getFontFamily() const;
368 void setFontSize(const FontSize aFontSize
) { maFontSize
= aFontSize
; }
369 SvgNumber
getFontSizeNumber() const;
371 /// FontStretch content
372 FontStretch
getFontStretch() const;
373 void setFontStretch(const FontStretch aFontStretch
) { maFontStretch
= aFontStretch
; }
375 /// FontStyle content
376 FontStyle
getFontStyle() const;
377 void setFontStyle(const FontStyle aFontStyle
) { maFontStyle
= aFontStyle
; }
379 /// FontWeight content
380 FontWeight
getFontWeight() const;
381 void setFontWeight(const FontWeight aFontWeight
) { maFontWeight
= aFontWeight
; }
383 /// TextAlign content
384 TextAlign
getTextAlign() const;
385 void setTextAlign(const TextAlign aTextAlign
) { maTextAlign
= aTextAlign
; }
387 /// TextDecoration content
388 const SvgStyleAttributes
* getTextDecorationDefiningSvgStyleAttributes() const;
389 TextDecoration
getTextDecoration() const;
390 void setTextDecoration(const TextDecoration aTextDecoration
) { maTextDecoration
= aTextDecoration
; }
392 /// TextAnchor content
393 TextAnchor
getTextAnchor() const;
394 void setTextAnchor(const TextAnchor aTextAnchor
) { maTextAnchor
= aTextAnchor
; }
397 const basegfx::BColor
* getColor() const;
399 /// Resolve current color (defaults to black if no color is specified)
400 const basegfx::BColor
* getCurrentColor() const;
403 SvgNumber
getOpacity() const;
404 void setOpacity(const SvgNumber
& rOpacity
) { maOpacity
= rOpacity
; }
407 Visibility
getVisibility() const;
408 void setVisibility(const Visibility aVisibility
) { maVisibility
= aVisibility
; }
411 const OUString
& getTitle() const { return maTitle
; }
414 const OUString
& getDesc() const { return maDesc
; }
416 // ClipPathXLink content
417 OUString
getClipPathXLink() const;
418 const SvgClipPathNode
* accessClipPathXLink() const;
421 OUString
getMaskXLink() const;
422 const SvgMaskNode
* accessMaskXLink() const;
424 // MarkerStartXLink content
425 OUString
getMarkerStartXLink() const;
426 const SvgMarkerNode
* accessMarkerStartXLink() const;
428 // MarkerMidXLink content
429 OUString
getMarkerMidXLink() const;
430 const SvgMarkerNode
* accessMarkerMidXLink() const;
432 // MarkerEndXLink content
433 OUString
getMarkerEndXLink() const;
434 const SvgMarkerNode
* accessMarkerEndXLink() const;
437 void setBaselineShift(const BaselineShift aBaselineShift
) { maBaselineShift
= aBaselineShift
; }
438 BaselineShift
getBaselineShift() const { return maBaselineShift
; }
439 SvgNumber
getBaselineShiftNumber() const;
442 } // end of namespace svgio::svgreader
444 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */