opentype.js icon indicating copy to clipboard operation
opentype.js copied to clipboard

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

Open Connum opened this issue 1 year ago • 6 comments

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)
  • [X] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

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

Connum avatar Oct 20 '23 07:10 Connum

I'll review this later today.

ILOVEPIE avatar Oct 20 '23 20:10 ILOVEPIE

I'll review this later today.

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

ILOVEPIE avatar Oct 20 '23 20:10 ILOVEPIE

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.

Connum avatar Oct 21 '23 09:10 Connum

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.

ILOVEPIE avatar Oct 22 '23 00:10 ILOVEPIE

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.

Connum avatar Oct 22 '23 12:10 Connum

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.

ILOVEPIE avatar Oct 29 '23 20:10 ILOVEPIE