Skip to content

Conversation

@cmyr
Copy link
Member

@cmyr cmyr commented Dec 11, 2025

If there are explicit values in a font for the 'Os2Subscript___' metrics, we want to reuse those for the corresponding superscript metrics.

This means that we need to query metrics in this routine, which ran into borrowck issues due to the long-lived closure that had a mutable ref to self. To work around that, I've replaced that closure with a macro.

fontir/src/ir.rs Outdated
let units_per_em = units_per_em as f64;

let mut set_if_absent = |metric, value| self.set_if_absent(metric, pos.clone(), value);
// a macro instead of a closure to avoid borrowck
Copy link
Contributor

Choose a reason for hiding this comment

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

This smells, I didn't spot it at a glance, why can't this be normal code?

Copy link
Contributor

@wmedrano wmedrano Dec 15, 2025

Choose a reason for hiding this comment

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

Personally, I think calling self.set_if_absent(metric, pos.clone(), value); directly is fine.

  • set_if_absent can also take an Into<Cow<NormalizedLocation>> if you want to avoid the explicit clone

Copy link
Member Author

@cmyr cmyr Dec 16, 2025

Choose a reason for hiding this comment

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

The whole reason this exists afaict is because always calling self.set ends up just... being a bunch of extra lines? And the closure doesn't work with this patch because you can't call self.get because the closure has an &mut ref to self.

If there are explicit values in a font for the 'Os2Subscript___'
metrics, we want to reuse those for the corresponding superscript
metrics.

This means that we need to query metrics in this routine, which ran into
borrowck issues due to the long-lived closure that had a mutable ref to
self, so I've removed that.
@cmyr cmyr force-pushed the funny-os2-fallback-logic branch from 930710a to ad3af28 Compare January 28, 2026 15:11
@cmyr
Copy link
Member Author

cmyr commented Jan 28, 2026

oops forgot about this. I did something similar to @wmedrano's suggestion and tweaked the signature of set_if_absent which means I can delete the macro without introducing much line noise.

@cmyr cmyr added this pull request to the merge queue Jan 28, 2026
Merged via the queue into main with commit 3e48cbb Jan 28, 2026
13 checks passed
@cmyr cmyr deleted the funny-os2-fallback-logic branch January 28, 2026 15:16
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