pub fn resolve_with_metrics(&self, font_size_px: f32, metrics: &LayoutFontMetrics) -> f32 {
let mut chains: HashMap<FontChainKey, rust_fontconfig::FontFallbackChain> = HashMap::new();
let glyph_check = |id: FontId, ch: char| loaded.get(&id).map(|font| font.has_glyph(ch as u32));
/// (`request_fonts_fast` returns only faces that cover at least one of the requested chars — the
/// 2. the coverage-based resolver (`resolve_font_chain_with_scripts`) over the `FcFontCache` for
pub fn covering_font(chain: &rust_fontconfig::FontFallbackChain, ch: char) -> Option<FontId> {
Some((id, source)) if source != rust_fontconfig::fallback::LAST_RESORT_SOURCE => Some(id),
pub fn resolve_font_by_hash(&self, font_hash: u64) -> Option<azul_css::props::basic::FontRef>
pub fn extend_chains_for_content<F>(&mut self, content: &[InlineContent], load_fn: F) -> usize
// [g119 az-web-lift FIX] `#[repr(C, u8)]` (was repr(Rust)): the String/FontSelector payloads give
// `Result<T, LayoutError>` (e.g. measure_intrinsic_widths' return + reorder/shape/orientation `?`)
// a POINTER-niche disc the web lift mis-reads → Ok→Err. Explicit u8 tag = simple-compare niche the
/// * Per spec: "logical width of a line box is equal to the inner logical width of its containing
/// - \u274c NOT IMPLEMENTED: text-box-edge property +spec:box-model:c09331 - text-box-trim trims
// +spec:box-model:415ef3 - initial letters use standard margin/padding/border box model; exclusion
// area = margin box +spec:box-model:d53ea3 - when block-start padding+border are zero, content edge
// [g121 az-web-lift] `#[repr(C, u8)]` — same disc-mis-lift guard as the other text3 enums; matched
// in shape_visual_items (`match &style.font_stack { Ref => shape, Stack => resolve }`). repr(Rust)
// niche (from the Vec/FontRef payloads) could mis-route. Explicit u8 tag = simple load. Internal to
// +spec:font-metrics:df51b1 - font metrics (ascent, descent, line_gap) used as baselines for inline
// layout +spec:font-metrics:797593 - font metrics (ascent, descent, line-gap) used for baseline
// calculations +spec:font-metrics:842d6a - font metrics (ascent, descent) used for precise spacing
// control +spec:font-metrics:eb97e0 - Font baseline metrics (ascent/descent) from font tables used
// for baseline alignment +spec:font-metrics:f2cd75 - em-over/em-under baselines intentionally not
// included (not used by CSS per spec) +spec:inline-formatting-context:76cd57 - ascent/descent font
// metrics for inline formatting context layout +spec:font-metrics:207e6b - ascent/descent metrics
// +spec:font-metrics:006bd8 - baseline position from font design coordinates, scaled with font
// (language-aware automatic hyphenation) +spec:line-breaking:68c6ad - hyphens property controls
// breaks +spec:line-breaking:35817b - normal/pre/nowrap/pre-wrap/break-spaces/pre-line behaviors
// +spec:display-property:162c99 - Initial letter box: in-flow inline-level box with special layout
// behavior +spec:display-property:72a797 - Initial letter handled like inline-level content in
// +spec:containing-block:46a499 - subsequent block must clear previous block's initial letter if it
// starts with its own initial letter, establishes independent FC, or specifies clear in initial
// (N-1)*line_height + surrounding cap-height +spec:font-metrics:3aa518 - initial-letter-align:
// cap-height/ideographic/hanging/leading/border-box baseline alignment +spec:writing-modes:9698b0 -
// [g117 az-web-lift FIX] `#[repr(C, u8)]` (was repr(Rust)): the web lift MIS-READS a repr(Rust)
// niche/compiler-placed discriminant — `<InlineContent as Clone>::clone` and create_logical_items'
// match both mis-route a Text(disc 0) to a Vec-bearing variant → clone reads a heap ptr as a Vec
// create_logical_items; content is CLEAN: len=1, ptr ok, disc-at-0=0). An explicit u8 tag at offset
// 0 (no niche) lowers to a simple load the lift handles correctly — the layout other (repr(C,u8))
// enums use. Not FFI-exposed (internal to text3; only native shell code matches it), so the repr
// baseline) +spec:inline-formatting-context:340729 - alignment-baseline values for IFC baseline
// alignment (only baseline/top/bottom/middle implemented) CSS 2.2 §10.8.1 vertical-align property
// inline-level children +spec:inline-formatting-context:3996a6 - dominant-baseline defaults to
// alphabetic in horizontal mode; vertical-align handles baseline alignment and super/sub shifting
/// When text-align-last is auto (default), justify falls back to start; others use text-align.
// justify→start +spec:line-breaking:9b10d2 - text-align-last applies to last line and lines before
/// +spec:text-alignment-spacing:8d88ce - text-align-last overrides justify on last line/forced
#[allow(clippy::suboptimal_flops)] // mul_add not guaranteed faster/available without target +fma; keep explicit a*b+c
// +spec:line-breaking:d70ffd - Defines forced line break (Hard) vs soft wrap break (Soft) types
// InlineContent above. LogicalItem is matched in measure Stage-2 (`if let LogicalItem::Text`) +
// reorder_logical_items; a repr(Rust) niche disc mis-lifts on the web. Explicit u8 tag at offset 0
// + LogicalItem (g117). ShapedItem is matched in measure Stage-5 (`match item { ShapedItem::Cluster
// + cloned/matched throughout shaping; a repr(Rust) niche disc mis-lifts on the web. Explicit u8
if text.ends_with('\u{002D}') || text.ends_with('\u{2010}') || text.ends_with('\u{002F}') {
#[allow(clippy::suboptimal_flops)] // mul_add not guaranteed faster/available without target +fma; keep explicit a*b+c
#[allow(clippy::too_many_lines)] // large but cohesive: single-purpose layout/render/parse routine (one branch per case)
pub fn cursor_from_grapheme_offset(stops: &[GraphemeClusterId], offset: usize) -> TextCursor {
#[allow(clippy::match_same_arms)] // enum/value mapping/dispatch table: one arm per input variant
pub fn extract_line_breaks(items: &[PositionedItem], available_width: f32) -> CachedLineBreaks {
while seg_cursor < self.segments.len() && self.segments[seg_cursor].clusters.end <= ci {
#[allow(clippy::field_reassign_with_default)] // struct built incrementally / test setup; a struct literal is not clearer here
#[allow(clippy::too_many_lines)] // large but cohesive: single-purpose layout/render/parse routine (one branch per case)
if self.per_item_shaped.len() > PER_ITEM_CACHE_MAX || l.max(v).max(sh) > STAGE_CACHE_MAX {
#[allow(clippy::too_many_lines)] // large but cohesive: single-purpose layout/render/parse routine (one branch per case)
if self.per_item_shaped.len() > PER_ITEM_CACHE_MAX || l.max(v).max(sh) > STAGE_CACHE_MAX {
let min_content_width = if matches!(constraints.white_space_mode, WhiteSpaceMode::Nowrap) {
#[allow(clippy::too_many_lines, clippy::cognitive_complexity)] // large but cohesive: single-purpose layout/render/parse routine (one branch per case)
let mut run_overrides: HashMap<u32, HashMap<u32, &PartialStyleProperties>> = HashMap::new();
// +spec:containing-block:149255 - bidi reordering produces inline box fragments that may separate
// in wide containing blocks +spec:containing-block:c7c08f - bidi reordering produces inline box
// fragments that may be adjacent in narrow containing blocks +spec:containing-block:2936ae - bidi
// +spec:display-property:0cdbd3 - bidi reordering splits inline boxes into visual runs; each run is
// shaped/formatted independently +spec:display-property:0d62a2 - bidi reordering of inline content
// paragraph breaks within inline boxes: each IFC does independent bidi analysis, so splitting an
// +spec:writing-modes:330b8f - text ordered according to Unicode bidi algorithm after white-space
// processing +spec:writing-modes:7a9e7d - bidi control translation: text passed to unicode_bidi for
// reordering +spec:writing-modes:8e7281 - unicode-bidi property: bidi control codes inserted via
// enum/value mapping/dispatch table: one arm per input variant (or cross-type bindings that can't
#[allow(clippy::too_many_lines)] // large but cohesive: single-purpose layout/render/parse routine (one branch per case)
/// // +spec:display-property:9c6d59 - text shaping not broken across inline box boundaries when no
/// effective formatting change // +spec:display-property:cf8917 - text shaping not broken across
#[allow(clippy::implicit_hasher)] // internal helper; only ever called with the default-hasher HashMap/HashSet
let dbg = *FONT_FB_DEBUG.get_or_init(|| std::env::var_os("AZ_FONT_FALLBACK_DEBUG").is_some());
#[allow(clippy::cast_possible_truncation, clippy::cast_precision_loss)] // bounded pixel/coord/colour/glyph cast
#[allow(clippy::implicit_hasher)] // internal helper; only ever called with the default-hasher HashMap/HashSet
// enum/value mapping/dispatch table: one arm per input variant (or cross-type bindings that can't
#[allow(clippy::too_many_lines, clippy::cognitive_complexity)] // large but cohesive: single-purpose layout/render/parse routine (one branch per case)
// +spec:box-model:8bbcd1 - non-zero inline-axis borders/padding between hangable glyph and line
#[allow(clippy::too_many_lines)] // large but cohesive: single-purpose layout/render/parse routine
// +spec:block-formatting-context:227171 - vertical glyph orientation with fallback vertical metrics
// enum/value mapping/dispatch table: one arm per input variant (or cross-type bindings that can't
/// Gets the ascent (distance from baseline to top) and descent (distance from baseline to bottom)
// (leading model) +spec:display-property:184f0d - Inline box baseline derives from first available
// font metrics +spec:display-property:238bf5 - Inline box layout bounds from own text metrics, not
// child boxes +spec:display-property:29b194 - baseline determination for inline boxes (CSS Box
// Alignment 3 §9.1) +spec:display-property:2987db - per-glyph font metrics impact inline box layout
/// +spec:display-property:fd42a9 - line-height affects line box contribution, not inline box size
// +spec:font-metrics:506abb - A/D from font metrics with half-leading: L = line-height - (A+D), A'
// = A + L/2, D' = D + L/2 +spec:font-metrics:773029 - ascent/descent font metrics used for baseline
// calculations (visual centering depends on these) +spec:font-metrics:f42870 - half-leading model:
// leading = line-height - (ascent + descent), distributed equally above/below +spec:writing-modes:
// +spec:block-formatting-context:861155 - vertical-align affects vertical positioning inside line
/// // +spec:display-contents:66d910 - line box height fitted to contents, controlled by line-height
// +spec:inline-formatting-context:c3fc54 - line box tall enough for all boxes, vertical-align
/// 1. First pass: compute line box height from baseline-aligned items only (baseline, sub, super,
/// 2. Second pass: check if any top/bottom-aligned items are taller than the line box from pass 1,
let effective_align = get_item_vertical_align(item).unwrap_or(default_vertical_align);
#[allow(clippy::too_many_lines, clippy::cognitive_complexity)] // large but cohesive: single-purpose layout/render/parse routine (one branch per case)
"Constraints: available_width={:?}, available_height={:?}, columns={}, text_wrap={:?}",
/// - If `line_constraints.total_available` is 0.0 (from `available_width: 0.0` bug), every word
/// - word-break property (normal, break-all, keep-all) - IMPLEMENTED via `BreakCursor.word_break`
/// - \u26a0\ufe0f line-break property: anywhere implemented; loose/normal/strict CJK strictness
// around every typographic character unit including preserved white spaces; with break-spaces
#[allow(clippy::cognitive_complexity)] // cohesive line-break state machine: one branch per CSS line-break case
#[allow(clippy::too_many_lines)] // large but cohesive: single-purpose layout/render/parse routine (one branch per case)
let all_breaks = find_all_hyphenation_breaks(&word_clusters, hyphenator, is_vertical, fonts)?;
/// A tuple containing the `Vec` of positioned items and the calculated height of the line box.
/// +spec:containing-block:8d5146 - text-align aligns within line box, not viewport/containing block
/// - \u26a0\ufe0f If segment.width is infinite (from intrinsic sizing), sets `alignment_offset=0`
/// to avoid infinite positioning. This is correct for measurement but documented for clarity.
/// - The function assumes `line_index == 0` means first line for text-indent. A more robust system
/// - \u274c \u00a7 3.3 Initial Letters (drop caps) // +spec:display-property:265c04 - initial
/// letter exclusion area must continue into subsequent blocks when paragraph is shorter than drop
#[allow(clippy::suboptimal_flops)] // mul_add not guaranteed faster/available without target +fma; keep explicit a*b+c
// enum/value mapping/dispatch table: one arm per input variant (or cross-type bindings that can't
#[allow(clippy::too_many_lines, clippy::cognitive_complexity)] // large but cohesive: single-purpose
// +spec:text-alignment-spacing:13b72d - line box start/end determined by inline base direction
// +spec:line-height:9ca9d9 - line box height = distance from uppermost box top to lowermost box
// +spec:display-contents:654278 - distributes remaining space to fill line box when justifying
// +spec:text-alignment-spacing:56c7f4 - equal distribution of justification space within priority
// text-justify value (inter-word = word separators, inter-character = character juxtaposition)
#[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)] // bounded pixel/coord/colour/glyph cast
#[allow(clippy::too_many_lines)] // large but cohesive: single-purpose layout/render/parse routine
// +spec:margin-collapsing:6706c1 - fixed-width spaces (U+2000–U+200A, U+3000) excluded from word
#[allow(clippy::match_same_arms)] // enum/value mapping/dispatch table: one arm per input variant
// +spec:font-metrics:b8eb97 - Script group classification for justification/letter-spacing behavior
#[allow(clippy::match_same_arms)] // enum/value mapping/dispatch table: one arm per input variant
#[allow(clippy::match_same_arms)] // enum/value mapping/dispatch table: one arm per input variant
/// space. Curves are assumed already flattened to `LineTo`s by `flatten_svg_to_path_segments`.
#[allow(clippy::suboptimal_flops)] // mul_add not guaranteed faster/available without target +fma;
fn get_shape_horizontal_spans(shape: &ShapeBoundary, y: f32, line_height: f32) -> Vec<(f32, f32)> {
/// Computes horizontal line segments where a polygon intersects a scanline at the given y range.
#[allow(clippy::suboptimal_flops)] // mul_add not guaranteed faster/available without target +fma;
fn polygon_line_intersection(points: &[Point], y: f32, line_height: f32) -> Vec<LineSegment> {
// +spec:inline-block:6e7dd9 - Non-tailorable Unicode line breaking controls take precedence over
// +spec:line-breaking:495247 - CJK/syllabic writing systems allow breaks between typographic letter
// units with varying strictness §5.2 word-break: determines if a character is CJK ideograph/kana
// +spec:line-breaking:31ef1a - word-break property controls soft wrap opportunities between letters
// (NU/AL/AI/ID classes as letter units) +spec:line-breaking:798252 - word-break property affects
// +spec:line-breaking:e2b374 - word-break: normal (only at separators) vs break-all (between all
// line-break strictness rules +spec:line-breaking:1c830a - word-break: normal/break-all/keep-all
// +spec:line-breaking:a75147 - word-break property: normal (CJK breaks), break-all (every cluster),
// keep-all (suppress CJK breaks) +spec:line-breaking:65ab41 - word-break: normal/break-all/keep-all
// break opportunity rules +spec:line-breaking:7eca16 - U+200B ZERO WIDTH SPACE is always a break
// loose/normal/strict/anywhere with CJK punctuation rules +spec:line-breaking:67bfe8 - line-break
// strictness (auto/loose/normal/strict/anywhere) controls CSS Text Level 3 §5.3: Determines whether
// a break opportunity before a character is allowed based on the line-break strictness level. The
// - strict: forbids breaks before small kana (class CJ), CJK hyphens, and certain punctuation
// - normal: allows breaks before small kana (CJ); allows CJK hyphen breaks for CJK writing systems
#[allow(clippy::match_same_arms)] // enum/value mapping/dispatch table: one arm per input variant
/// Returns true if the character is a Japanese small kana or Katakana-Hiragana prolonged sound mark
// a single typographic character unit (every character is a soft wrap opportunity), including
fn shaped_glyph(st: Arc<StyleProperties>, fm: LayoutFontMetrics, advance: f32) -> ShapedGlyph {
fn resolve_effective_alignment_explicit_text_align_last_left_is_indistinguishable_from_auto() {