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
Support variable feature syntax #2432
Conversation
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. |
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 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. |
Yeah, I rebased against master (not main...). |
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: Remember you can rewind to 96f0169. |
83231ab
to
0f9ef95
Compare
Aha! I think we got it. Thank you. |
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 🙇♂️ |
@simoncozens You are defacto owner of feaLib, otlLib. You should feel free to ask @anthrotype for approval and merge as you see fit. |
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. |
There was a problem hiding this 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
Lib/fontTools/feaLib/ast.py
Outdated
return res | ||
|
||
class VariationBlock(Block): | ||
"""A named feature block.""" |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
:-)
There was a problem hiding this comment.
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()))
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 |
thanks Simon, apologies for taking so long to review this. Do feel free to ping me if something slips my attention
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) |
It would also be nice to get LGTM from one of the other feaLib stakeholders, e.g. @khaledhosny, @justvanrossum |
@simoncozens if you merge origin/main into your PR branch, it should fix the unrelated CI failures |
LGTM as well. |
Lib/fontTools/feaLib/ast.py
Outdated
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" |
There was a problem hiding this comment.
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)?
49c0efb
to
eab87ed
Compare
This supports the variable FEA syntax defined here.