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

[read-fonts] layout: selecting scripts for shaping #1154

Merged
merged 4 commits into from
Sep 20, 2024
Merged

[read-fonts] layout: selecting scripts for shaping #1154

merged 4 commits into from
Sep 20, 2024

Conversation

dfrg
Copy link
Member

@dfrg dfrg commented Sep 17, 2024

Adds HB equivalent functionality for selecting an OpenType script for a given Unicode script code.

Adds HB equivalent functionality for selecting an OpenType script for a given Unicode script code.
/// Index of the script in the [`ScriptList`].
pub index: u16,
/// True if a script was chosen that wasn't in the requested list.
pub is_fallback: bool,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Speculation: I wonder if a Rusty SelectedScript should be an enum instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's an equivalent representation but an enum with all variants carrying the same payload where the variant itself is secondary information is often awkward to use. In other words, we'll always want the tag/index but might occasionally care if we're using a fallback so it doesn't make sense to primarily categorize on that aspect.

/// Generated by [`script_tags_from_unicode`].
#[derive(Copy, Clone, PartialEq, Eq, Default)]
pub struct ScriptTags {
tags: [Tag; 3],
Copy link
Collaborator

Choose a reason for hiding this comment

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

this merits a comment explaining what it is

Copy link
Member Author

Choose a reason for hiding this comment

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

The comment above says "A prioritized list of OpenType script tags mapped from a Unicode script tag." but I added some additional context.

len: usize,
}

impl Deref for ScriptTags {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Optional, would an explicit call like as_tags() be overly horrid? - not a huge fan of Deref.

Copy link
Member

Choose a reason for hiding this comment

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

as_slice() would be the idiomatic conversion fn here, but since this type is essentially an array deref to slice is totally reasonable (having both would be the most idiomatic approach)

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed with Colin on both points. Added as_slice() for those that prefer explicit calls.

Copy link
Collaborator

@rsheeter rsheeter left a comment

Choose a reason for hiding this comment

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

LGTM subject to the typo rules being updated to fix the warnings

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.

looks good; noted inline that some of this is duplicating code that exists elsewhere, so let's open an issue to resolve that at some point.

}

// See <https://github.com/harfbuzz/harfbuzz/blob/63d09dbefcf7ad9f794ca96445d37b6d8c3c9124/src/hb-ot-tag.cc#L84>
fn new_tag_from_unicode(unicode_script: Tag) -> Option<Tag> {
Copy link
Member

Choose a reason for hiding this comment

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

I've definitely impl'd this somewhere before... looks like it's in fontbe? Let's open an issue to deduplicate.

Copy link
Collaborator

Choose a reason for hiding this comment

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

can we just find it and fix it now? - that smells like an issue that won't actually get fixed

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 in a different repo, at the very least we need to do a release of read-fonts before we can change anything there.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh sorry, I skimmed pastit being in fontc not here. Then +1 to issue or fast-follow PR to update fontc.

Copy link
Member Author

Choose a reason for hiding this comment

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

@cmyr I exposed a UNICODE_TO_NEW_OPENTYPE_SCRIPT_TAGS const that is basically the same as NEW_SCRIPT_TAGS in fontbe except the key is &[u8; 4] instead of &str. Does that work for you?

Copy link
Member

Choose a reason for hiding this comment

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

i'm not going to have time to dig into this before I take off, so let's merge as-is and we can figure that out when I get back.

len: usize,
}

impl Deref for ScriptTags {
Copy link
Member

Choose a reason for hiding this comment

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

as_slice() would be the idiomatic conversion fn here, but since this type is essentially an array deref to slice is totally reasonable (having both would be the most idiomatic approach)

@dfrg dfrg merged commit 762ff85 into main Sep 20, 2024
10 checks passed
@dfrg dfrg deleted the ot-scripts branch September 20, 2024 13:36
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.

3 participants