#![allow(clippy::field_reassign_with_default, clippy::too_many_arguments)]
use strata_layout::typography::{
InlineFormattingContext, InlineItem, InlineLayoutOptions, InlineTextStyle,
};
use strata_style::types::{FontStyle, FontWeight};
fn continuous_probe_measurer(
text: &str,
_font_size: f32,
_line_height_multiplier: f32,
_max_width: Option<f32>,
_is_monospace: bool,
_font_family: strata_primitives::AtomId,
_font_weight: FontWeight,
_font_style: FontStyle,
) -> (f32, f32) {
let chars = text.chars().count() as f32;
let shaping_bonus = if chars >= 8.0 { 13.0 } else { 0.0 };
(chars * 10.0 + shaping_bonus, 21.0)
}
#[test]
fn merged_fragment_advances_by_continuous_width() {
strata_layout::text::register_family_styled_text_measurer(continuous_probe_measurer);
let style = InlineTextStyle {
font_size: 18.0,
..Default::default()
};
let items = vec![
InlineItem::text("alpha-beta-gamma", style.clone()),
InlineItem::text("delta-epsilon", style),
];
let options = InlineLayoutOptions {
font_size: 18.0,
line_height: Some(21.0),
max_width: None,
..Default::default()
};
let ifc = InlineFormattingContext::new();
let result = ifc.layout_inline_stream(&items, &options);
assert_eq!(result.lines.len(), 1, "the probe stream must fit one line");
let line = &result.lines[0];
assert_eq!(
line.text_fragments.len(),
2,
"each item must produce its own fragment"
);
let first = &line.text_fragments[0];
let second = &line.text_fragments[1];
assert_eq!(first.text, "alpha-beta-gamma");
assert_eq!(second.text, "delta-epsilon");
assert!(
(first.bounds.width - 173.0).abs() < 0.01,
"first fragment must use the continuous width, got {}",
first.bounds.width
);
assert!(
(second.bounds.x - 173.0).abs() < 0.01,
"second fragment must start after the continuous width, got {}",
second.bounds.x
);
assert!(
(second.bounds.width - 143.0).abs() < 0.01,
"second fragment must use the continuous width, got {}",
second.bounds.width
);
assert!(
(result.total_width - 316.0).abs() < 0.01,
"line width must accumulate continuous advances, got {}",
result.total_width
);
}