opentype.js
opentype.js copied to clipboard
implement styling of fill/stroke/strokeWidth when using Font.draw() or Glyph.draw()
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
result:
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.
I'll review this later today.
I'll review this later today.
I ended up having a little time to go through it now before work.
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.
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.
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.
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.