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

[designspace] Add avar2 mapping support #3123

Merged
merged 30 commits into from Jun 8, 2023
Merged

[designspace] Add avar2 mapping support #3123

merged 30 commits into from Jun 8, 2023

Conversation

behdad
Copy link
Member

@behdad behdad commented May 24, 2023

This just uses list of list of dictionaries. Should use proper objects.

#3049

@behdad behdad marked this pull request as draft May 24, 2023 16:22
@behdad
Copy link
Member Author

behdad commented May 24, 2023

cc @justvanrossum Opening this such that we can work on it together.

@behdad behdad force-pushed the avar2-designspace branch 4 times, most recently from 044054a to 522b22d Compare May 25, 2023 20:55
@behdad
Copy link
Member Author

behdad commented May 25, 2023

I updated this to actually build an avar2 table, and successfully built one.

@Lorp
Copy link

Lorp commented May 25, 2023

Is this based on my proposed <map> syntax?

@behdad
Copy link
Member Author

behdad commented May 25, 2023

Is this based on my proposed <map> syntax?

Yes. Just using <mapping> instead of <map>.

@Lorp
Copy link

Lorp commented May 25, 2023

Are you dealing with supporting masters, thus only calculating duovar deltas after calculating supporting monovar deltas etc?

@behdad
Copy link
Member Author

behdad commented May 25, 2023

Are you dealing with supporting masters, thus only calculating duovar deltas after calculating supporting monovar deltas etc?

It's a full VariationModel solver.

@behdad
Copy link
Member Author

behdad commented May 25, 2023

Based on this experiment, I suggest this way forward:

  • If an output axis is specified with xvalue, then it must be also specified as an input axis,
  • Otherwise, an output axis can have a delta attribute, that has a value in normalized (-1..+1) range to be added to the axis value.

I think this makes most sense. I've willing to hear alternatives.

@Lorp
Copy link

Lorp commented May 25, 2023

That sounds like an excellent refinement.

Can you confirm your avar2 builder is happy crossing 0? (If specified absolutely, such a delta must be worked out in two steps.)

@behdad
Copy link
Member Author

behdad commented May 25, 2023

That sounds like an excellent refinement.

Can you confirm your avar2 builder is happy crossing 0? (If specified absolutely, such a delta must be worked out in two steps.)

It looks like it's happy to. In fact, the varLib modeler requires a region at 0.

@davelab6
Copy link
Contributor

davelab6 commented May 25, 2023

If an output axis is specified with xvalue, then it must be also specified as an input axis

I am not so familiar with the implemention, and was curious about the name of this variable; I pinged Behdad to ask, what is the x in xvalue, and he kindly explained,

it comes from mutatorMath, which supports non-uniform interpolation, so there's xvalue and yvalue; and if yvalue is omitted, it's copied from xvalue. But in varfonts we only support uniform interpolation, so you always only see xvalue

@behdad
Copy link
Member Author

behdad commented May 25, 2023

cc @LettError @justvanrossum

@Lorp
Copy link

Lorp commented May 26, 2023

Recall that there are valid concerns from @anthrotype @justvanrossum @belluzj about the terminology in the spec, so we should not regard it as firm. In particular I’m happy to avoid use of "xvalue". See #3049.

@LettError
Copy link
Collaborator

LettError commented May 26, 2023

"xvalue" is there to record anisotropic locations. This is perhaps not very useful for variable font but it is where this specification started and it is still used during design. As long as anisotropy remains possible I'm fine with any other name.

@behdad
Copy link
Member Author

behdad commented May 26, 2023

Based on this experiment, I suggest this way forward:

  • If an output axis is specified with xvalue, then it must be also specified as an input axis,
  • Otherwise, an output axis can have a delta attribute, that has a value in normalized (-1..+1) range to be added to the axis value.

This makes it ugly to represent in the code. Currently how it works, is that if an axis is only specified in output, then it will work as a delta from the axis's default value. Maybe we just document it that way and go home? @Lorp

@behdad behdad changed the title [designspace] Hack to read avar2 mapping [designspace] Add avar2 mapping support May 26, 2023
@behdad
Copy link
Member Author

behdad commented May 26, 2023

@Lorp Can you work on a patch to the designspace spec?

@behdad
Copy link
Member Author

behdad commented May 26, 2023

@Lorp Instead of <map><region> what do you think of <mappings><mapping>?

@behdad
Copy link
Member Author

behdad commented May 26, 2023

@Lorp Instead of <map><region> what do you think of <mappings><mapping>?

What's what I'm using in the designspaceLib code.

@Lorp
Copy link

Lorp commented May 27, 2023

Sounds good. We don’t talk about regions anywhere else in designspace. I’m mostly away for the weekend, but will do it soon.

@behdad behdad marked this pull request as ready for review May 28, 2023 20:00
@behdad behdad requested a review from justvanrossum May 28, 2023 20:00
@behdad
Copy link
Member Author

behdad commented May 28, 2023

Should the dimension element have axis name instead of tag?

@behdad
Copy link
Member Author

behdad commented Jun 1, 2023

@anthrotype Thanks for the review. I think I addressed them all.

@behdad
Copy link
Member Author

behdad commented Jun 1, 2023

@khaledhosny Is this something you can use in your font to build the avar2 table?

@behdad

This comment was marked as outdated.

@khaledhosny
Copy link
Collaborator

@khaledhosny Is this something you can use in your font to build the avar2 table?

Probably. I create a DS in code and pass it to varLib, so I can add the mapping there.

@khaledhosny
Copy link
Collaborator

@khaledhosny Is this something you can use in your font to build the avar2 table?

Probably. I create a DS in code and pass it to varLib, so I can add the mapping there.

aliftype/raqq@d5c7fd6

But I don’t understand these warnings, what am I doing wrong?

No input location specified for non-hidden axis 'SPAC' in axis mapping {'jstf': 0.0}; axis default value assumed.
No input location specified for non-hidden axis 'SPAC' in axis mapping {'jstf': 0.9}; axis default value assumed.
No input location specified for non-hidden axis 'SPAC' in axis mapping {'jstf': 1.0}; axis default value assumed.
No input location specified for non-hidden axis 'SPAC' in axis mapping {'jstf': -0.5}; axis default value assumed.
No input location specified for non-hidden axis 'SPAC' in axis mapping {'jstf': -1.0}; axis default value assumed.
No input location specified for non-hidden axis 'MSHQ' in axis mapping {'jstf': 0.0}; axis default value assumed.
No input location specified for non-hidden axis 'MSHQ' in axis mapping {'jstf': 0.9}; axis default value assumed.
No input location specified for non-hidden axis 'MSHQ' in axis mapping {'jstf': 1.0}; axis default value assumed.
No input location specified for non-hidden axis 'MSHQ' in axis mapping {'jstf': -0.5}; axis default value assumed.
No input location specified for non-hidden axis 'MSHQ' in axis mapping {'jstf': -1.0}; axis default value assumed.

@khaledhosny
Copy link
Collaborator

This fixes the warnings:

diff --git a/scripts/build.py b/scripts/build.py
index 8d19a4a..63d4531 100644
--- a/scripts/build.py
+++ b/scripts/build.py
@@ -726,11 +726,11 @@ def build(font, instance, args):
         ds.addSource(source)

     inputs = [
-        {"Justification": 0},
-        {"Justification": 90},
-        {"Justification": 100},
-        {"Justification": -50},
-        {"Justification": -100},
+        {"Justification": 0, "Spacing": 0, "Mashq": 10},
+        {"Justification": 90, "Spacing": 0, "Mashq": 10},
+        {"Justification": 100, "Spacing": 0, "Mashq": 10},
+        {"Justification": -50, "Spacing": 0, "Mashq": 10},
+        {"Justification": -100, "Spacing": 0, "Mashq": 10},
     ]

     outputs = [

But it feels redundant. Now I need to remember to update these if I ever change the default location of any of the axes.

@khaledhosny
Copy link
Collaborator

Also I’m seeing this ttx diff compared to my code:

   <avar>
     <version major="2" minor="0"/>
     <segment axis="SPAC">
+      <mapping from="-1.0" to="-1.0"/>
+      <mapping from="0.0" to="0.0"/>
+      <mapping from="1.0" to="1.0"/>
     </segment>
     <segment axis="MSHQ">
+      <mapping from="-1.0" to="-1.0"/>
+      <mapping from="0.0" to="0.0"/>
+      <mapping from="1.0" to="1.0"/>
     </segment>
     <segment axis="jstf">
+      <mapping from="-1.0" to="-1.0"/>
+      <mapping from="0.0" to="0.0"/>
+      <mapping from="1.0" to="1.0"/>
     </segment>

Probably harmless but also redundant.

@behdad
Copy link
Member Author

behdad commented Jun 1, 2023

But I don’t understand these warnings, what am I doing wrong?

Make the SPAC axis hidden and they should go away.

@behdad
Copy link
Member Author

behdad commented Jun 1, 2023

This fixes the warnings:

diff --git a/scripts/build.py b/scripts/build.py
index 8d19a4a..63d4531 100644
--- a/scripts/build.py
+++ b/scripts/build.py
@@ -726,11 +726,11 @@ def build(font, instance, args):
         ds.addSource(source)

     inputs = [
-        {"Justification": 0},
-        {"Justification": 90},
-        {"Justification": 100},
-        {"Justification": -50},
-        {"Justification": -100},
+        {"Justification": 0, "Spacing": 0, "Mashq": 10},
+        {"Justification": 90, "Spacing": 0, "Mashq": 10},
+        {"Justification": 100, "Spacing": 0, "Mashq": 10},
+        {"Justification": -50, "Spacing": 0, "Mashq": 10},
+        {"Justification": -100, "Spacing": 0, "Mashq": 10},
     ]

     outputs = [

But it feels redundant. Now I need to remember to update these if I ever change the default location of any of the axes.

Yeah it's one of the issues we've been discussing. Currently we warn if a non-hidden output axis is not specified.

@khaledhosny
Copy link
Collaborator

khaledhosny commented Jun 1, 2023

But I don’t understand these warnings, what am I doing wrong?

Make the SPAC axis hidden and they should go away.

But I want it the other way around, SPAC and MSHQ visible and jstf hidden since it should be used by justification algorithms and not directly by the user, unlike the other two.

@behdad
Copy link
Member Author

behdad commented Jun 1, 2023

But I don’t understand these warnings, what am I doing wrong?

Make the SPAC axis hidden and they should go away.

But I want it the other way around, SPAC and MSHQ visible and jstf hidden since it should be used by justification algorithms and not directly by the user, unlike the other two.

Interesting. Yeah I think we might want to nuke that warning then.

@justvanrossum
Copy link
Collaborator

Yes, let's get rid of the warning. But since leaving out the input value and putting it at the default value should behave the same way, I am also surprised at the ttx diff.

@khaledhosny
Copy link
Collaborator

But since leaving out the input value and putting it at the default value should behave the same way, I am also surprised at the ttx diff.

Sorry of I didn't make this clear, the ttx diff is not related to this issue but when generating avar with varLib in general (I’m comparing with the code I was using earlier which left the segments empty).

@behdad
Copy link
Member Author

behdad commented Jun 2, 2023

Removed warning.

Is this good to merge then?

@anthrotype
Copy link
Member

@behdad what about that diff that Khaled noticed?

@behdad
Copy link
Member Author

behdad commented Jun 2, 2023

@behdad what about that diff that Khaled noticed?

That's because of this pre-existing code block:

# Currently, some rasterizers require that the default value maps
# (-1 to -1, 0 to 0, and 1 to 1) be present for all the segment
# maps, even when the default normalization mapping for the axis
# was not modified.
# https://github.com/googlei18n/fontmake/issues/295
# https://github.com/fonttools/fonttools/issues/1011
# TODO(anthrotype) revert this (and 19c4b37) when issue is fixed
curve = avar.segments[axis.tag] = {-1.0: -1.0, 0.0: 0.0, 1.0: 1.0}

@anthrotype
Copy link
Member

Are we all happy to merge this? We can start making avar2 fonts and come back fix things as needed

@anthrotype
Copy link
Member

@behdad hm that commit you quoted is quite old, from 2017
04eacf1

I’m comparing with the code I was using earlier which left the segments empty

@khaledhosny does that mean you had not rebuilt your fonts since 2017?

@khaledhosny
Copy link
Collaborator

@behdad hm that commit you quoted is quite old, from 2017 04eacf1

I’m comparing with the code I was using earlier which left the segments empty

@khaledhosny does that mean you had not rebuilt your fonts since 2017?

I wasn’t using DS to generate avar table.

@anthrotype anthrotype merged commit b3ce097 into main Jun 8, 2023
10 checks passed
@anthrotype anthrotype deleted the avar2-designspace branch June 8, 2023 11:58
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

Successfully merging this pull request may close these issues.

None yet

8 participants