Lorp / fencer

GUI app to create avar2 mappings in fonts
Apache License 2.0
10 stars 0 forks source link

Obtain designspace mappings from avar2 data #25

Open Lorp opened 2 months ago

Lorp commented 2 months ago

Currently Fencer ignores any existing avar data, though it would be very useful if it could visualize existing avar1 and avar2 data as mappings.

Although a general solution may not be possible, it should be possible at least in all the cases where the avar2 table was compiled from mappings, which includes all fonts made via a .designspace document and all fonts exported from Fencer.

This code from Fontra is suggested by @justvanrossum, as noted in https://github.com/fonttools/fonttools/issues/3086

https://github.com/googlefonts/fontra/blob/087fac4c01d5bbd918f3550d03fae5693f0dc292/src/fontra/backends/opentype.py#L255-L285

Lorp commented 1 month ago

The logic is actually pretty simple:

behdad commented 1 month ago

See this comment for how that logic can fail: https://github.com/fonttools/fonttools/issues/3086#issuecomment-2263626285

Lorp commented 1 month ago

Thanks for the discussion. Indeed the corners definitely need to be considered for representation as mappings. Trying now with this logic:

Will it work to take 2^n+1 locations from every region encoded in the IVS? (where n=number of dimensions having value!=default, thus encoding all of the n-D region’s corners, and the +1 is for the n-D peak). Then we transform the unique locations with the IVS to obtain the deltas, and thereby the mappings.

Lorp commented 1 month ago

It seems to work well on arbitrary mappings on a 2-axis font, except for adding some redundant pin mappings. Amstelvar seems not to be working however.

Lorp commented 1 month ago

@behdad @justvanrossum if you care to take a look, the code is here.

https://github.com/Lorp/fencer/blob/82d572753ff81865f9bb32b2f5a5767f249e37d0/src/fencer.js#L709-L779

behdad commented 1 month ago

@behdad @justvanrossum if you care to take look, the code is here.

The Fontra link is outdated now?

Lorp commented 1 month ago

Yes, since we’re agreed that a tent’s start and end need to be accounted for, as well as peak.

behdad commented 1 month ago

@behdad @justvanrossum if you care to take look, the code is here.

Looks about right, except that part about getting delta from first ivsd?

behdad commented 1 month ago

@behdad @justvanrossum if you care to take look, the code is here.

Looks about right, except that part about getting delta from first ivsd?

I actually don't fully understand that comment.

Lorp commented 1 month ago

Ah, that’s an old comment. It does handle multiple IVDs. I’ll delete.

Lorp commented 1 month ago

Hang on, there is a bug there (the [0] index at the end), which will affect IVDs after the 0th one. On it…

Lorp commented 1 month ago

Now uses [ivdIndex] instead of [0].