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

[skrifa] new hinting options type #1087

Merged
merged 9 commits into from
Aug 28, 2024
Merged

[skrifa] new hinting options type #1087

merged 9 commits into from
Aug 28, 2024

Conversation

dfrg
Copy link
Member

@dfrg dfrg commented Aug 15, 2024

Replaces the current HintingMode with a new HintingOptions type to support autohinting. Specifically, it allows for selecting the hinting engine (interpreter, auto or auto fallback). Also reintroduces a "light" mode to match FT_RENDER_MODE_LIGHT since this actually represents a different mode in the autohinter (but didn't for TrueType or CFF).

Adds the symmetric_rendering flag as well (closes #1080).

Based on #1086 since it depends on the new public GlyphStyles type.

@drott this is the same as the reference code in the preview branch

Exposes the glyph style map as a public type and wrapped in an `Arc` to make it shareable among multiple autohinting instances.
Per IM, changes skrifa to use `FontRef` directly rather than `TableProvider`.

Extracts some shared functionality into a `BaseScaler` type for outlines in preparation for more autohinting work but no real functional changes.
Copy link
Contributor

@drott drott left a comment

Choose a reason for hiding this comment

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

Thank you for continuing to upstream autohinting, great to see this.

No concerns for HintingOptions and the configuration API. This looks as discussed earlier and seems good to be used in Skia (with a reservation that I have not tried it yet).

But the is_italic argument to Scale feels odd to me and seems a surprising configuration side effect to hinting later. I don't know how to set this argument correctly from the client side. (Besides the general concern with boolean API args that are hard to read at the call site.)

skrifa/src/outline/hint.rs Outdated Show resolved Hide resolved
skrifa/src/outline/hint.rs Outdated Show resolved Hide resolved
///
/// This matches the logic used in FreeType when neither of the
/// `FT_LOAD_FORCE_AUTOHINT` or `FT_LOAD_NO_AUTOHINT` flags are specified.
pub fn prefer_interpreter(&self) -> bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps explain in this comment from where this is used and how it relates to the Engine configuration option?

Copy link
Member Author

Choose a reason for hiding this comment

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

Will do.

Copy link
Member Author

Choose a reason for hiding this comment

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

And this one too

skrifa/src/outline/autohint/metrics.rs Outdated Show resolved Hide resolved
Base automatically changed from glyphstyles to main August 16, 2024 12:55
- Engine::AutoFallback docs: mention the relevant load flags wrt to FreeType's behavior; be more specific about PostScript/TrueType specific selection
- OutlineGlyphCollection::prefer_interpreter() docs: explain how this relates to HintingOptions and Engine::AutoFallback
- rework Scale constructor to take Style enum for determining whether the font is italic rather than using a boolean
Copy link
Contributor

@drott drott left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

skrifa/src/outline/hint.rs Outdated Show resolved Hide resolved
skrifa/src/outline/hint.rs Outdated Show resolved Hide resolved
skrifa/src/outline/autohint/metrics.rs Outdated Show resolved Hide resolved
Co-authored-by: Dominik Röttsches <[email protected]>
@dfrg dfrg linked an issue Aug 28, 2024 that may be closed by this pull request
@dfrg dfrg merged commit 61cd661 into main Aug 28, 2024
10 checks passed
@dfrg dfrg deleted the hintingopts branch August 28, 2024 12:18
@@ -28,6 +198,7 @@ use crate::alloc::{boxed::Box, vec::Vec};
/// FreeType 2.7.
///
/// The default value of this type is equivalent to `FT_LOAD_TARGET_NORMAL`.
#[doc(hidden)]
Copy link

Choose a reason for hiding this comment

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

Should this be #[deprecated]?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, but we require transitional states for rolling updates in Chrome and I specifically avoided the deprecated attribute to avoid raising warnings at compile time.

Copy link

Choose a reason for hiding this comment

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

Thanks for the explanation. I wonder if whatever uses this in chrome should use allow(deprecated) instead. I think that should be entirely equivalent for that use case.

I suppose that could cause problems if a non-skrifa library were updated?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, it seems like that could affect other things in undesirable ways. My plan was to mark these deprecated for the next cycle and then remove them which adds a bit of latency but should be fine.

Copy link

Choose a reason for hiding this comment

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

I've done some more digging, and this is exactly the use case for #[deprecated(since = "TBD")], which will only trigger the deprecated_in_future lint. I can't find exactly when this was stabilised, but experimentally, it has worked since rustc 1.75.

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.

ClearType symmetric rendering
3 participants