Skip to content

Fill opacity conflict with stroke opacity using Canvas #1186

@jfgirard

Description

@jfgirard

When I use CANVAS to render a Polygon, there is a case where the opacity is not well set. Its fine using SVG.

1- Fill opacity < 1
2. Stroke Opacity = 1

In this case, both fill and stroke opacity are set to the fill's one.

Current implementation:
Path.Canvas.js From Line 105

if (options.fill) {
    if (options.fillOpacity < 1) {
    ctx.globalAlpha = options.fillOpacity;
    }
    ctx.fill();
}
if (options.stroke) {
    if (options.opacity < 1) {
        ctx.globalAlpha = options.opacity;
    }
    ctx.stroke();
}

A simple fix is to add a else if for stroke:

if (options.stroke) {
    if (options.opacity < 1) {
        ctx.globalAlpha = options.opacity;
    }else if (options.fill && options.fillOpacity !== 1) {
        ctx.globalAlpha = 1;
    }
    ctx.stroke();
}

What do you think ? I'm a bit lazy to do a PR ;)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions