Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SVG render context does not honor stroke style #1621

Open
jaredjj3 opened this issue Jun 17, 2024 · 1 comment
Open

SVG render context does not honor stroke style #1621

jaredjj3 opened this issue Jun 17, 2024 · 1 comment

Comments

@jaredjj3
Copy link
Contributor

jaredjj3 commented Jun 17, 2024

I'm using RenderContext as a convenient way to render shapes on top of a vexflow music sheet. I'm drawing rectangles like this:

ctx.save();
ctx.setStrokeStyle(strokeStyle);
ctx.rect(x, y, w, h);
ctx.stroke();
ctx.restore();

When I draw with SVGContext, the stroke style is always black. When I draw with CanvasContext, the stroke style is correct. FWIW, SVGContext.arc seems to work correctly (which is evident by the red circles).

SVG

image

Canvas

image
@AaronDavidNewman
Copy link
Collaborator

This looks like an issue specifically with rect in svgcontext. Unlike line and path, svgcontext.rect is a single call - it doesn't build a path and then call stroke to close if off (even though all 3 shapes end up in a single svg element). There is a way to pass the line attributes into rect specifically, but no way to call it on the rendercontext interface.

It would be pretty simple to change svgcontext.rect to do something like:

  rect(x: number, y: number, width: number, height: number, attributes?: Attributes): this {
   // ...
    attributes = attributes ?? { fill: 'none', 'stroke-width': this.lineWidth };  // don't assign stroke here
    attributes.stroke = (typeof(attributes.stroke) === 'undefined' && typeof(this.attributes.stroke) === 'string') ?
        this.attributes.stroke : 'black';

That shouldn't break anything, unless existing apps are used to leave the 'stroke' value as something strange, and then use rect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants