opentypejs / opentype.js

Read and write OpenType fonts using JavaScript.
https://opentype.js.org/
MIT License
4.42k stars 474 forks source link

Support for enabling alternate characters/stylistic sets #478

Open bgmort opened 3 years ago

bgmort commented 3 years ago

I'm trying to use alternate characters in fonts (specific example: use Raleway with its more geometric and less weird stylistic alternates) for an application I'm building. I've been trying to debug why the following doesn't work:

font.forEachGlyph('wow such W', 0, 0, 24, {
  ss01: true,
})

And I finally realized that only liga and rlig are supported right now, unless I have overlooked something. What's the status of this? Is there a plan for implementing it? Is there currently any workaround (without the application having specific knowledge of the font in use)?

I'm willing to contribute as well, but not sure how to effiiciently go about acquiring the necessary base knowledge. I'm brand new to opentype, but a seasoned JS/TS developer.

Expected Behavior

font.forEachGlyph should make use of alternate characters and stylistic sets, such as a conventional geometric W in the linked example.

Current Behavior

Only the liga and rlig features are supported

Steps to Reproduce (for bugs)

This example uses makerjs to simplify the code and render to SVG, but it's a relatively simple wrapper around font.forEachGlyph. https://codesandbox.io/s/cool-boyd-3r6ls?file=/src/index.js

Context

Wanting to provide access to stylistic alternates in a design webapp.

Your Environment

alexkolodko commented 2 years ago

I used SvgTextToPath library to generate design layouts. This library works with opentype.js. І will use OpenType features in CSS (tabular numbers or alternates stylistic set). But script replaces alternate symbols with the ordinary. Demo: tabular symbols "1" at the top replaced to ordinary.

Can you add support of other OT features (stylistic sets and tabular numbers)?

Typogram commented 1 year ago

Please support more opentype features like smcp and c2sc and others. I mean it is called opentype.js!

ILOVEPIE commented 1 year ago

@Typogram if you'd like to contribute support for those, we'd be happy to accept a PR for them.

ILOVEPIE commented 1 year ago

@bgmort I'd take a look at the microsoft typography documentation for the features you want implemented, that should get you started.