mirror of
https://github.com/typst/typst
synced 2025-08-22 02:34:14 +08:00
Move shift settings to ShapingContext
This commit is contained in:
parent
71b637396f
commit
566a06302d
@ -672,7 +672,7 @@ fn shape<'a>(
|
|||||||
region: Option<Region>,
|
region: Option<Region>,
|
||||||
) -> ShapedText<'a> {
|
) -> ShapedText<'a> {
|
||||||
let size = TextElem::size_in(styles);
|
let size = TextElem::size_in(styles);
|
||||||
let script_settings = TextElem::shift_settings_in(styles);
|
let shift_settings = TextElem::shift_settings_in(styles);
|
||||||
let mut ctx = ShapingContext {
|
let mut ctx = ShapingContext {
|
||||||
engine,
|
engine,
|
||||||
size,
|
size,
|
||||||
@ -683,10 +683,11 @@ fn shape<'a>(
|
|||||||
features: features(styles),
|
features: features(styles),
|
||||||
fallback: TextElem::fallback_in(styles),
|
fallback: TextElem::fallback_in(styles),
|
||||||
dir,
|
dir,
|
||||||
|
shift_settings,
|
||||||
};
|
};
|
||||||
|
|
||||||
if !text.is_empty() {
|
if !text.is_empty() {
|
||||||
shape_segment(&mut ctx, base, text, families(styles), script_settings);
|
shape_segment(&mut ctx, base, text, families(styles));
|
||||||
}
|
}
|
||||||
|
|
||||||
track_and_space(&mut ctx);
|
track_and_space(&mut ctx);
|
||||||
@ -728,6 +729,7 @@ struct ShapingContext<'a, 'v> {
|
|||||||
features: Vec<rustybuzz::Feature>,
|
features: Vec<rustybuzz::Feature>,
|
||||||
fallback: bool,
|
fallback: bool,
|
||||||
dir: Dir,
|
dir: Dir,
|
||||||
|
shift_settings: Option<ShiftSettings>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Shape text with font fallback using the `families` iterator.
|
/// Shape text with font fallback using the `families` iterator.
|
||||||
@ -736,7 +738,6 @@ fn shape_segment<'a>(
|
|||||||
base: usize,
|
base: usize,
|
||||||
text: &str,
|
text: &str,
|
||||||
mut families: impl Iterator<Item = &'a FontFamily> + Clone,
|
mut families: impl Iterator<Item = &'a FontFamily> + Clone,
|
||||||
shift_settings: Option<ShiftSettings>,
|
|
||||||
) {
|
) {
|
||||||
// Don't try shaping newlines, tabs, or default ignorables.
|
// Don't try shaping newlines, tabs, or default ignorables.
|
||||||
if text
|
if text
|
||||||
@ -804,7 +805,7 @@ fn shape_segment<'a>(
|
|||||||
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) =
|
||||||
compute_synthesized_shift(ctx, text, &font, shift_settings);
|
compute_synthesized_shift(ctx, text, &font);
|
||||||
|
|
||||||
// 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.
|
||||||
@ -941,13 +942,7 @@ fn shape_segment<'a>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Recursively shape the tofu sequence with the next family.
|
// Recursively shape the tofu sequence with the next family.
|
||||||
shape_segment(
|
shape_segment(ctx, base + start, &text[start..end], families.clone());
|
||||||
ctx,
|
|
||||||
base + start,
|
|
||||||
&text[start..end],
|
|
||||||
families.clone(),
|
|
||||||
shift_settings,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
i += 1;
|
i += 1;
|
||||||
@ -969,9 +964,8 @@ fn compute_synthesized_shift(
|
|||||||
ctx: &mut ShapingContext,
|
ctx: &mut ShapingContext,
|
||||||
text: &str,
|
text: &str,
|
||||||
font: &Font,
|
font: &Font,
|
||||||
settings: Option<ShiftSettings>,
|
|
||||||
) -> (Em, Em, Em) {
|
) -> (Em, Em, Em) {
|
||||||
match settings {
|
match ctx.shift_settings {
|
||||||
None => (Em::zero(), Em::zero(), Em::one()),
|
None => (Em::zero(), Em::zero(), Em::one()),
|
||||||
Some(settings) => settings
|
Some(settings) => settings
|
||||||
.typographic
|
.typographic
|
||||||
|
Loading…
x
Reference in New Issue
Block a user