Extract None case outside of compute_synthesized_shift

This commit is contained in:
Malo 2025-06-24 19:25:58 +01:00
parent 7195f97b9b
commit 899157af24

View File

@ -804,8 +804,11 @@ fn shape_segment<'a>(
// text extraction.
buffer.set_flags(BufferFlags::REMOVE_DEFAULT_IGNORABLES);
let (script_shift, script_compensation, scale) =
compute_synthesized_shift(ctx, text, &font);
let (script_shift, script_compensation, scale) = ctx
.shift_settings
.map_or((Em::zero(), Em::zero(), Em::one()), |settings| {
compute_synthesized_shift(ctx, text, &font, settings)
});
// Prepare the shape plan. This plan depends on direction, script, language,
// and features, but is independent from the text and can thus be memoized.
@ -964,10 +967,9 @@ fn compute_synthesized_shift(
ctx: &mut ShapingContext,
text: &str,
font: &Font,
settings: ShiftSettings,
) -> (Em, Em, Em) {
match ctx.shift_settings {
None => (Em::zero(), Em::zero(), Em::one()),
Some(settings) => settings
settings
.typographic
.then(|| {
// If typographic scripts are enabled (i.e., we want to use the
@ -989,11 +991,13 @@ fn compute_synthesized_shift(
})
.then(|| {
ctx.features.push(Feature::new(settings.kind.feature(), 1, ..));
// If we can use the OpenType feature, we can keep the text
// as is.
(Em::zero(), Em::zero(), Em::one())
})
})
// Reunite the cases where `typographic` is `false` or where using
// the OpenType feature would not work.
// Reunite the cases where `typographic` is `false` or where using the
// OpenType feature would not work.
.flatten()
.unwrap_or_else(|| {
let script_metrics = settings.kind.read_metrics(font.metrics());
@ -1002,8 +1006,7 @@ fn compute_synthesized_shift(
script_metrics.horizontal_offset,
settings.size.unwrap_or(script_metrics.height),
)
}),
}
})
}
/// Create a shape plan.