This commit is contained in:
Ryan Oldenburg 2022-05-21 19:23:46 -05:00
parent ce4ac78b5d
commit 88576efdd3

View file

@ -297,44 +297,42 @@ proc parseSvgProperties(node: XmlNode, inherited: SvgProperties): SvgProperties
failInvalidTransform(transform) failInvalidTransform(transform)
proc fill(img: Image, path: Path, props: SvgProperties) = proc fill(img: Image, path: Path, props: SvgProperties) =
if props.display and props.opacity > 0: if props.fill == "none":
if props.fill == "none": return
return
var paint: Paint var paint: Paint
if props.fill.startsWith("url("): if props.fill.startsWith("url("):
let id = props.fill[5 .. ^2] let id = props.fill[5 .. ^2]
if id in props.linearGradients: if id in props.linearGradients:
let linearGradient = props.linearGradients[id] let linearGradient = props.linearGradients[id]
paint = newPaint(LinearGradientPaint) paint = newPaint(LinearGradientPaint)
paint.gradientHandlePositions = @[ paint.gradientHandlePositions = @[
props.transform * vec2(linearGradient.x1, linearGradient.y1), props.transform * vec2(linearGradient.x1, linearGradient.y1),
props.transform * vec2(linearGradient.x2, linearGradient.y2) props.transform * vec2(linearGradient.x2, linearGradient.y2)
] ]
paint.gradientStops = linearGradient.stops paint.gradientStops = linearGradient.stops
else:
raise newException(PixieError, "Missing SVG resource " & id)
else: else:
paint = parseHtmlColor(props.fill).rgbx raise newException(PixieError, "Missing SVG resource " & id)
else:
paint = parseHtmlColor(props.fill).rgbx
paint.opacity = props.fillOpacity * props.opacity paint.opacity = props.fillOpacity * props.opacity
img.fillPath(path, paint, props.transform, props.fillRule) img.fillPath(path, paint, props.transform, props.fillRule)
proc stroke(img: Image, path: Path, props: SvgProperties) = proc stroke(img: Image, path: Path, props: SvgProperties) =
if props.display and props.opacity > 0: let paint = newPaint(props.stroke)
let paint = newPaint(props.stroke) paint.color.a *= (props.opacity * props.strokeOpacity)
paint.color.a *= (props.opacity * props.strokeOpacity) img.strokePath(
img.strokePath( path,
path, paint,
paint, props.transform,
props.transform, props.strokeWidth,
props.strokeWidth, props.strokeLineCap,
props.strokeLineCap, props.strokeLineJoin,
props.strokeLineJoin, miterLimit = props.strokeMiterLimit,
miterLimit = props.strokeMiterLimit, dashes = props.strokeDashArray
dashes = props.strokeDashArray )
)
proc parseSvgElement( proc parseSvgElement(
node: XmlNode, propertiesStack: var seq[SvgProperties] node: XmlNode, propertiesStack: var seq[SvgProperties]
@ -576,9 +574,10 @@ proc decodeSvg*(
for node in root.items: for node in root.items:
renderInfos.add node.parseSvgElement(propertiesStack) renderInfos.add node.parseSvgElement(propertiesStack)
for (path, props) in renderInfos: for (path, props) in renderInfos:
result.fill(path, props) if props.display and props.opacity > 0:
if props.stroke != rgbx(0, 0, 0, 0) and props.strokeWidth > 0: result.fill(path, props)
result.stroke(path, props) if props.stroke != rgbx(0, 0, 0, 0) and props.strokeWidth > 0:
result.stroke(path, props)
except PixieError as e: except PixieError as e:
raise e raise e
except: except: