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

Support variable feature syntax #2432

Merged
merged 22 commits into from Oct 28, 2021

Conversation

simoncozens
Copy link
Collaborator

This supports the variable FEA syntax defined here.

@simoncozens simoncozens changed the title Parse variable scalars in feature files. Support variable feature syntax Oct 22, 2021
@simoncozens
Copy link
Collaborator Author

I put a lot of work into this PR. Because of maintainer inactivity, the branch grew stale. I tried to resurrect it but now it doesn't work. I don't know how to fix it.

Good luck, everyone.

@ctrlcctrlv
Copy link
Contributor

ctrlcctrlv commented Oct 22, 2021

Hey @simoncozens I'm so sorry my request broke your work, you trashed your Git status pretty good and usually I'm told that I'm “really good at Git™” and in previous work it seems people always use me for Git issues but even I couldn't quite get us back where we were before perfectly (matching commit hashes and branch name) but ① the tests pass and ② the Git log is basically normal looking sort of.

Here you are then:

#!/bin/bash
cat << EOF > /tmp/patches
b880ae1787d168f656f92df07b656d2086f0d6a3
f84cacad5e1707bedbac07d29844043b5d56f299
18e84dd02df8022b8fb51e3fd92c6b2fcf01b112
7a69fb1b55903ed3be1da138d63bc181af10bf68
91cee05f17c001f61d882336756a8a14d9f10001
24c9c90fdf4e9e37f5765d372edd011d9395f5cc
c16553d6232e465b5e10c0b7c025f542f94d8364
6ca9fb02493fe35e5477b792d5f3e67de111fbc8
0c7e30740fac19555ad9714c6a5785a2cb983ede
be89af49535a52ff8d046ec5851b5dfda2229238
13a084efcb981e4462842f5a55c5453e324d755a
3b1b5fde2f4ac2519327a6e5298b99895e1f3e83
b30b8f1c8bd62374b1e52f110d9d57a58889d7fc
af66495c3c2bb1470f55d1b6702516c32ba6c077
80828cf433d2c94421b318d2a42dee1ef357378d
5f37300cbc6f81767c3724cf58ed276f3b2e2f37
ecef3eda962036ded4240d9f3fb7dc2712d72066
151fb92871d50af8036e1eebf151465b0208ea96
c4ca64c3a012d1d8295a5272c59b681310b12633
EOF

mkdir -p /tmp/simonpatches && (cd /tmp/simonpatches; while read -r line; do wget https://github.com/fonttools/fonttools/commit/$line.patch; done < /tmp/patches)

git clone https://github.com/simoncozens/fonttools/ simonのfontTools
cd !$
git checkout 96f0169d9d39972f80ebd1b245fc902fa1435722
git checkout -b 'oldSimonHead'
tac /tmp/patches | EMAIL='simon@simon-cozens.org' GIT_COMMITTER_NAME='Simon Cozens' GIT_COMMITTER_EMAIL='simon@simon-cozens.org' parallel --jobs 1 git am --committer-date-is-author-date '<' /tmp/simonpatches/{}.patch
git checkout -b variable-feature-syntax
git branch -d oldSimonHead
git log --oneline | head -n10 | xargs -I{} echo '#' {}
# d1513eb7 Allow float values in condition sets.
# 951e5ecc Set count fields when building feature variations
# 50c320f2 Put count fields in ttx
# 90bff8c5 Support building feature variations using the condition statement.
# 0b436327 feature_variations_ is a better name than conditionalFeatures_
# 5c303db1 Normalize condition sets when storing them
# 16d29ead A more generic interface, taking either GSUB or GPOS table
# 7bfba828 Oops, leftover when testing something else
# ec43cce5 Rearrange featureVars so we can do *really* raw feature builds (by lookup ID)
# 1d623bba Store the conditional features in a dictionary until we work out what to do with them

image

Sorry if the script looks hacky to you @simoncozens , I promise you that you completely trashed your working tree and blew away and reference to the commits outside of GitHub, literally downloading patch files from GitHub is the only way to get your work back.

@simoncozens
Copy link
Collaborator Author

Yeah, I rebased against master (not main...).

@ctrlcctrlv
Copy link
Contributor

Oh—Git might some day do some spring cleaning and wipe out disconnected commits (from any repo or branch) from its online interface, or limit allowing users to get them ("security breach!!!1"), so here's a zip if you ever find you need it:

patches.zip

Remember you can rewind to 96f0169.

@simoncozens
Copy link
Collaborator Author

Aha! I think we got it. Thank you.

@ctrlcctrlv
Copy link
Contributor

You're welcome...I fear I'm about to become a general purpose Git fixer ;-)

Please only call upon me if I'm partially responsible for the breakage 🙇‍♂️

@behdad
Copy link
Member

behdad commented Oct 22, 2021

@simoncozens You are defacto owner of feaLib, otlLib. You should feel free to ask @anthrotype for approval and merge as you see fit.

@simoncozens
Copy link
Collaborator Author

You are defacto owner of feaLib, otlLib.

The perils of working on open source software.

OK, @anthrotype, how about it? This is a backward-compatible extension which I think will help push along the new syntax proposal, so I think it's worth doing.

Copy link
Member

@anthrotype anthrotype left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

please also run black on the modules you touched

return res

class VariationBlock(Block):
"""A named feature block."""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"named feature block".. no mention of "variation" in this docstring?


features = builder.features_
builder.features_ = {}
Block.build(self, builder)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not immediately clear what's going on here, why is the features_ attributes temporarily swapped with an empty dict. Maybe add a comment



class Location(dict):
def __hash__(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm hashable and mutable objects (dict) are dangerous => https://hynek.me/articles/hashes-and-equality/

can you do without this? e.g. by storing location as tuple of tuples in your VariableScalar.values inner dict?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or perhaps class Location(frozenset): pass :-)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What could work is:

def Location(loc):
    return tuple(sorted(loc.items()))

@anthrotype
Copy link
Member

the test-cython CI test failure is unrelated, please ignore (it's failing to fetch some deps for 3.10, we shall pin to python 3.9 for now, I'll do that on main)

@anthrotype
Copy link
Member

thanks Simon, apologies for taking so long to review this. Do feel free to ping me if something slips my attention

This is a backward-compatible extension which I think will help push along the new syntax proposal, so I think it's worth doing.

sounds good. Ideally the spec changes would go in first, followed by implemetation, but in this case it's perhas worth doing the reverse (with a caveat that impl is experimental until spec settles and may change and break things)

@anthrotype
Copy link
Member

It would also be nice to get LGTM from one of the other feaLib stakeholders, e.g. @khaledhosny, @justvanrossum
or @dscorbett

@anthrotype
Copy link
Member

@simoncozens if you merge origin/main into your PR branch, it should fix the unrelated CI failures

@behdad
Copy link
Member

behdad commented Oct 25, 2021

LGTM as well.

def asFea(self, res="", indent=""):
res += indent + f"conditionset {self.name} " + "{\n"
for tag, (minvalue, maxvalue) in self.conditions.items():
res += indent + f" {tag} {minvalue} {maxvalue};\n"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why indent by three spaces instead of SHIFT (four spaces)?

@simoncozens simoncozens merged commit 563730f into fonttools:main Oct 28, 2021
@simoncozens simoncozens deleted the variable-feature-syntax branch October 28, 2021 10: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

6 participants