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

Implement anchor extraction from OpenType files #68

Merged
merged 1 commit into from
Sep 24, 2024

Conversation

rimas-kudelis
Copy link
Contributor

Fixes #67

Disclaimer: I'm not really a Python developer, so it's possible that I didn't do some things the right way. Fell free to help me improve this code. :)

@rimas-kudelis rimas-kudelis force-pushed the feat/67-extract-anchors branch 3 times, most recently from 9126a76 to 124a25b Compare September 4, 2024 05:01
@rimas-kudelis
Copy link
Contributor Author

rimas-kudelis commented Sep 13, 2024

Hmmm, I just noticed that my code failed to extract two anchor groups (is this the correct term to use?) from a TTF I'm working on. I have twelve of them in the font, but only the first ten (0-9) got extracted. Weird.

@rimas-kudelis
Copy link
Contributor Author

Hmmm, I just noticed that my code failed to extract two anchor groups (is this the correct term to use?) from a TTF I'm working on. I have twelve of them in the font, but only the first ten (0-9) got extracted. Weird.

False alarm. It appears the TTF fonts I'm working on use incorrect feature tags for the last two lookups (zz11 and zz12 instead of mark). Fixing that bit in a ttx dump and recompiling the font causes the anchors to be exported correctly.

So, will this PR be accepted or do I need to do something more?

Comment on lines 1115 to 1125
try:
anchor = Anchor(destination[base], {"x": baseAnchors[base]["x"], "y": baseAnchors[base]["y"], "name": f"Anchor-{groupIndex}"})
destination[base].appendAnchor(anchor)
except:
continue
for mark in markAnchors.keys():
try:
anchor = Anchor(destination[mark], {"x": markAnchors[mark]["x"], "y": markAnchors[mark]["y"], "name": f"_Anchor-{groupIndex}"})
destination[mark].appendAnchor(anchor)
except:
continue
Copy link
Contributor

Choose a reason for hiding this comment

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

You can rewrite this without using the defcon.Anchor object and thus get rid of the defcon dependency:

        for base in baseAnchors.keys():
            try:
                anchor = {
                    "x": baseAnchors[base]["x"],
                    "y": baseAnchors[base]["y"],
                    "name": f"Anchor-{groupIndex}",
                }
                destination[base].appendAnchor(anchor)
            except:
                continue
        for mark in markAnchors.keys():
            try:
                anchor = {
                    "x": markAnchors[mark]["x"],
                    "y": markAnchors[mark]["y"],
                    "name": f"_Anchor-{groupIndex}",
                }
                destination[mark].appendAnchor(anchor)
            except:
                continue

Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder about the try...except statements here. In what case could it go wrong, and would we want to know about it instead of silently ignoring the anchors?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess you're right. I didn't want my additions to potentially break the code, but I suppose it's better to fix it properly if something breaks instead of pretending like nothing happened.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You can rewrite this without using the defcon.Anchor object and thus get rid of the defcon dependency:

Done. Also rebased on the current master and force-pushed everything in a single commit.

@jenskutilek
Copy link
Contributor

False alarm. It appears the TTF fonts I'm working on use incorrect feature tags for the last two lookups (zz11 and zz12 instead of mark). Fixing that bit in a ttx dump and recompiling the font causes the anchors to be exported correctly.

IIRC those are unofficial feature tags used by MS VOLT to store its "source code".

@rimas-kudelis
Copy link
Contributor Author

False alarm. It appears the TTF fonts I'm working on use incorrect feature tags for the last two lookups (zz11 and zz12 instead of mark). Fixing that bit in a ttx dump and recompiling the font causes the anchors to be exported correctly.

IIRC those are unofficial feature tags used by MS VOLT to store its "source code".

Ah, I see. Indeed, all the anchors were added to these fonts using MS VOLT. Apparently, the original designer created the two lookups in question, but did not reference them from the mark feature under latn/dflt (unlike other lookups), so they were/are basically unused. I guess he wasn't satisfied with the result but opted not to waste time on a feature they didn't plan to use (using the combining solidus characters U+0337 and U+0338). It all makes sense now.

@benkiel
Copy link
Member

benkiel commented Sep 24, 2024

This looks good to me. Thanks for the nudge and the update.

@benkiel benkiel merged commit f479213 into robotools:master Sep 24, 2024
2 checks passed
@rimas-kudelis rimas-kudelis deleted the feat/67-extract-anchors branch September 24, 2024 16:19
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.

Extract glyph anchors when extracting glyphs
3 participants