lib-font icon indicating copy to clipboard operation
lib-font copied to clipboard

optional CFF / CFF2 parsing?

Open Pomax opened this issue 6 years ago • 7 comments

While this lib may not be intended to be a text shaper, it might be useful to offer a separate CFF/CFF2 parser that can be loaded alongside Font.js, to allow Font.js to dig into the CFF/CFF2 blocks (without doing charstring interpretation), to add additional "raw data" inspection of the font.

Pomax avatar Nov 21 '19 18:11 Pomax

(note: font.js should still offer built in high-level deconstruction, but not operator/operand unpacking)

Pomax avatar Nov 22 '19 16:11 Pomax

+1. Right now I could use being able to tell whether a glyph contains any outlines at all.

hyvyys avatar Sep 25 '21 11:09 hyvyys

Can you sketch a use-case? Are you trying to determine if a glyph is printable from font, rather than from charset spec?

Pomax avatar Sep 26 '21 16:09 Pomax

Oh, it’s nothing really. I’m making a string generator to use with pattern fonts. Some of them will use a subset of the basic Latin alphabet for their pattern modules and have the remaining glyph slots empty instead of just leaving them out of the font. So being able to tell a glyph is empty would help automate the glyph selection process. Maybe there’s another way to do so, without having to parse CFF/CFF2?

hyvyys avatar Sep 26 '21 19:09 hyvyys

That seems like solving the symptom rather than the problem: don't include empty glyphs in your subset fonts, and you're done? Rather than parsing glyph outline strings, now it's back to a simple matter of "does font support codepoint X".

Pomax avatar Sep 26 '21 19:09 Pomax

Obviously. But sometimes curing the symptoms is all the doctor can do. I’m not working with my own fonts, and as the goal is to use a still smaller selection of the existing functional glyphs at any given time, manual glyph selection is still involved. I just thought I would detect and pre-select the filled glyphs after loading the font so that the users that come with their own custom-made, ad-hoc, imperfect fonts have a few clicks less.

hyvyys avatar Sep 26 '21 20:09 hyvyys

I see. In that case, you're probably better off loading a full-fat font library like OpenType.js, and then checking each glyph's metrics. I've implemented several TTF and CFF parsers in the past, and it's enough of an absolute nonsense job that unless someone's willing to fund the effort, I'm unlikely to get to it until I personally need it again.

(Mind you, if you need this because you work for a company and this helps you achieve a task set by your team/manager/company etc, please do talk to whoever has the power to fund third party work, because I'm more than happy to work on this library in exchange for monetary compensation =)

Pomax avatar Sep 26 '21 22:09 Pomax