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