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

implement styling of fill/stroke/strokeWidth when using Font.draw() or Glyph.draw() #626

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Connum
Copy link
Contributor

@Connum Connum commented Oct 20, 2023

Description

Implements a new method Path.applyStyles(), which applies valid style properties (fill, stroke, strokeWidth) to the Path. This is used in Glyph.getPath() and Font.getPath() and allows to specify styling options e.g. when using Font.draw() or Glyph.draw().

Motivation and Context

Implements #623.

How Has This Been Tested?

Temporarily modifying docs/index.html

Screenshots (if appropriate):

options in renderText() of docs/index.html
image
result:
image

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I did npm run test and all tests passed green (including code styling checks).
  • I have added tests to cover my changes.
  • My change requires a change to the documentation.
  • I have updated the README accordingly.
  • I have read the CONTRIBUTING document.

@ILOVEPIE
Copy link
Contributor

I'll review this later today.

Copy link
Contributor

@ILOVEPIE ILOVEPIE left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One discrepancy here with regard to other font renderers is the fact that lineWidth draws half the line inside the fill area, which means our stroke is actually half-width this way (at least with canvas, not sure about SVG). Also, Miter type becomes important when rendering the stroke on text, so we need to do some additional research with regards to that before this can go through. In my code base I'm using lineCap = "round" and lineJoin = "round" but this may only be correct for my use case.

@ILOVEPIE
Copy link
Contributor

I'll review this later today.

I ended up having a little time to go through it now before work.

@Connum
Copy link
Contributor Author

Connum commented Oct 21, 2023

I would treat the outline positioning as a separate follow-up issue. It comes into play during the actual canvas drawing and we'll have to take it into account there, but at least the values get passed along with the Path now.

But good point with the line behaviour. We should take a look at that and find good values for it, and probably add an option to influence it according to one's needs.

@ILOVEPIE
Copy link
Contributor

In my codebase I'm doing a kind of dirty hack by multiplying the outline width by 2 then filling the text with destination-out compositing mode to cut out the inner part of the stroke.

@Connum
Copy link
Contributor Author

Connum commented Oct 22, 2023

In my codebase I'm doing a kind of dirty hack by multiplying the outline width by 2 then filling the text with destination-out compositing mode to cut out the inner part of the stroke.

That's what I thought of doing. Doesn't even feel too dirty to me.

@ILOVEPIE
Copy link
Contributor

In my codebase I'm doing a kind of dirty hack by multiplying the outline width by 2 then filling the text with destination-out compositing mode to cut out the inner part of the stroke.

That's what I thought of doing. Doesn't even feel too dirty to me.

The problem with that is that it doesn't work for SVG output, unless we want to use masking.

@Connum Connum marked this pull request as draft November 30, 2023 23:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants