Skip to content

Skia rect dashed path effect for svg #177

@peterchenadded

Description

@peterchenadded

It seems the SVG canvas does not apply any patheffects for canvas.drawRect(...)

from IPython.core.display import SVG
import io

stream = skia.DynamicMemoryWStream()
canvas = skia.SVGCanvas.Make((100, 100), stream)

rect = skia.Rect(10, 10, 50, 50)
paint = skia.Paint(
            AntiAlias=True,
            PathEffect=skia.DashPathEffect.Make([10.0, 5.0], 0.0),
            Style=skia.Paint.kStroke_Style,
            StrokeWidth=1,
)
canvas.drawRect(rect, paint)

del canvas
stream.flush()

SVG(stream.detachAsData())

image

The patheffects e.g. dashedpatheffect is being applied for PNG images without issues.

surface = skia.Surface(100, 100)
canvas = surface.getCanvas()
rect = skia.Rect(10, 10, 50, 50)
paint = skia.Paint(
        AntiAlias=True,
        PathEffect=skia.DashPathEffect.Make([10.0, 5.0], 0.0),
        Style=skia.Paint.kStroke_Style,
        StrokeWidth=1,
)
canvas.drawRect(rect, paint)
image = surface.makeImageSnapshot()

display(image)

image

I know we can use path.addRect(...), but the output xml is very large.

Does anyone know if it possible to add a stroke-dasharray attribute directly to a rect in the output .svg instead?

Cheers,

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions