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

Shaping and instantiating variable fonts #2112

Closed
simoncozens opened this issue Jan 17, 2020 · 16 comments
Closed

Shaping and instantiating variable fonts #2112

simoncozens opened this issue Jan 17, 2020 · 16 comments

Comments

@simoncozens
Copy link
Collaborator

I seem to remember Behdad saying that Harfbuzz will not just be able to shape but also instantiate static instances of variable fonts. This will be helpful for me because, as a layout engine, SILE needs to pass fonts to a PDF generator, and the PDF library doesn't support variable fonts.

I just found the shaping example in the documentation (oops), but is the instantiator done yet? Is it on the radar?

@ebraminio
Copy link
Collaborator

ebraminio commented Jan 17, 2020

This will be instantiation feature of subsetter as also referred on #1558 as a not in scope there, perhaps @blueshade7 and @garretrieger can comment on the status and planning for instantiation.

@garretrieger
Copy link
Collaborator

It's something that we want to add, but not being actively worked on at the moment.

@simoncozens
Copy link
Collaborator Author

Thanks, good to know. I’m happy to try working on this if someone can spec out an interface to it.

@ebraminio
Copy link
Collaborator

ebraminio commented Jan 18, 2020

Perhaps Garret should comment here also, hb_subset has a simple API #1381 (comment) so I guess var coords will become a new field on subset_input, if, not another API like hb_subset_var_instantiate is considered that takes a hb_font_t instead hb_face_t and returns the instanced hb_face_t, which wouldn't need to use subset input object even. It should be started by removing var tables and applying mvar to the needed places, and the real challenge will be in glyf/CFF2 and GSUB/GSUB/GPOS rebuild. I guess we can progress with a bottom up approach with adding related methods to each of those tables, starting with easier ones like OS2 instancing (applying mvar to its values) or harder ones like applying gvar to glyf in TT-VF fonts or CFF2.

@khaledhosny
Copy link
Collaborator

I think one advantage of doing instanciation and sunsetting at the same time would be when instantiating large fonts to be embedded in PDF files, to avoid wasting time on glyphs that would be immediately sunsetted away.

@behdad
Copy link
Member

behdad commented Jan 28, 2020

We should add variation-space specification to subset input and cut the font to adhere to that. That defaults to preserving all variation space, but should allow for narrowing down the space all the way to instantiating a single instance and leaving no variation behind. So, @anthrotype's work on partial-instancing in fonttools should be considered at the same time, for API and implementation design purposes, even if not immediately implemented.

@simoncozens
Copy link
Collaborator Author

OK, I've been looking at this again; here are some things I think we will need to do.

  • Introduce a hb_variation_range_t with lower and upper bounds.
  • Add subsetting/serializing to tables we currently pass through: MVAR, avar, STAT, fvar.
  • Properly deserialise into objects things we currently just treat as blobs and extract data when required: TupleVariationHeader, possibly others.
  • Properly serialise a lot of things that we currently just copy: Glyph/contour_point_vector_t/contour_point__t.
  • Add hb_variation_range_t *variation_ranges; unsigned int variation_ranges_length; to hb_subset_plan_t
  • Subset/instance by applying all the variation ranges in gvar/glyf/MVAR/HVAR/VVAR/avar/STAT/fvar. (I don't care about CFF.)
  • Terrible and scary things to GSUB/GPOS/GDEF. :-/

@twardoch
Copy link

FWIW, while I admire the goal of reducing varfonts to other varfonts (limiting the variation space), I think a sensible v1.0 goal would be subsetting to statics ie. producing a font that represents only a point in the variation space, not a region.

@simoncozens
Copy link
Collaborator Author

Meh. It's not actually that much more code. I'd still have to do all the things I mentioned.

@KrasnayaPloshchad
Copy link

Does HarfBuzz having some APIs that could be helpful for this? If so, anyone could make use of them to subset a single instance, even if HarfBuzz doesn’t have such functionality.

@behdad
Copy link
Member

behdad commented Jul 13, 2022

This is starting to happen. First PR is #3708 (review)
Closing as no point keeping open.

@papandreou
Copy link

Hey, we've recently implemented tracing of used variation axis ranges in subfont, mainly in anticipation of this feature. We would like to do automatic instantiation/axis trimming to make it easier to author performant web pages with variable fonts. Just a 🤚 that we'd be excited to beta test whenever you have something ready! 🤗

We currently use the subsetting features via harfbuzzjs.

@garretrieger
Copy link
Collaborator

Full instancing (that is reducing a variable font to a fully static instance) should be ready for use in the very near future. Mainly we're waiting on #3816 to be merged. Partial instancing (pinning/modifying some but not all axes) will be worked on next.

@khaledhosny
Copy link
Collaborator

Is instantiating CFF2 table supported or planned?

@garretrieger
Copy link
Collaborator

CFF2 is not currently supported. Currently the focus is on implementing for glyf. We do plan to also do instancing for CFF2 as well once the glyf implementation is done.

@papandreou
Copy link

We've just released subfont 7.0.0, which uses hb_subset_input_pin_axis_location to automatically perform a full instancing of variable fonts when possible. Looking forward to partial instancing 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants