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

Drop quotes from names parsed from fea earlier so we detect empty ones correctly #1194

Merged
merged 2 commits into from
Jan 8, 2025

Conversation

rsheeter
Copy link
Contributor

@rsheeter rsheeter commented Jan 5, 2025

Parsing NameSpec from fea retains the double quotes, dropping them only when generating final name records. That causes fontc to produce unwanted empty name records because it filters using is_empty. Naive solution: drop the quotes earlier so is_empty works as expected.

Makes name identical for python resources/scripts/ttx_diff.py 'https://github.com/marcologous/hanken-grotesk#sources/HankenGrotesk.glyphs'.

@rsheeter rsheeter requested a review from cmyr January 5, 2025 18:52
@rsheeter rsheeter added this to the fontc 1.0 milestone Jan 8, 2025
Copy link
Member

@cmyr cmyr left a comment

Choose a reason for hiding this comment

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

so I'm still slightly confused about where the is_empty check is, but if I'm understanding the intent of this patch correctly, I think that the cleanest fix is to replace the string() method on the NameSpec type in token_tree::typed with something like,

    pub(crate) fn string(&self) -> &str {
        self.find_token(Kind::String)
            .unwrap()
            .text
            .trim_matches('"')
    }

(although honestly just doing it inline in resolve_name_spec seems fine too.)

...and then since the actual bug is with something ending up in the binary, the best way to test this would be to add a new case in fea-rs/test-data/compile-tests; there's a readme there that explains this process but it's easy.

BUT if part of the complication here is that there is some filtering happening outside of fea-rs then that won't work, and in that case we should figure out if fea-rs should be doing this filtering or not.

I've left a few little comments on the PR as written, for informational purposes.

(i'm not marking this approved yet because I want to understand where the filtering you mention is happening first)

fea-rs/src/compile/compile_ctx.rs Outdated Show resolved Hide resolved
fea-rs/src/compile/compile_ctx.rs Outdated Show resolved Hide resolved
Comment on lines 2251 to 2255
vec!["", "duck"],
vec![
parse_name_spec("3 1 0x409 \"\"").string,
parse_name_spec("3 1 0x409 \"duck\"").string
]
Copy link
Member

Choose a reason for hiding this comment

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

trivia, but fwiw you don't need the vec here you can just have these be arrays..

@@ -89,7 +89,7 @@ macro_rules! ast_node {
#[derive(Clone, Debug)]
#[allow(missing_docs)]
pub struct $typ {
inner: Node,
pub(crate) inner: Node,
Copy link
Member

Choose a reason for hiding this comment

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

we generate a node() method you can call, so this shouldn't be necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was to enable construction of a test value, not reading, but perhaps that will be unnecessary once revised

Copy link
Member

@cmyr cmyr left a comment

Choose a reason for hiding this comment

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

nice okay ya I do think this is much cleaner. Thanks!

@rsheeter rsheeter added this pull request to the merge queue Jan 8, 2025
Merged via the queue into main with commit 1ea3b8a Jan 8, 2025
10 checks passed
@rsheeter rsheeter deleted the mrhanken branch January 8, 2025 22:51
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.

2 participants