Skip to content

The headless browser for AI agents and web scraping

Merge pull request #955 from pederbe/learn/934-word-spacing

SGavrl7634f464c0de
diff --cc crates/obscura-render/src/dom.rs
index bb827e37,376a43d5..f6ef26fc
--- a/crates/obscura-render/src/dom.rs
+++ b/crates/obscura-render/src/dom.rs
@@@ -12,8 -12,13 +12,13 @@@ use std::sync::Arc
use obscura_dom::tree::{DomTree, NodeId};
use taffy::prelude::*;
-use crate::{to_taffy_style, Rect};
+use crate::{Rect, to_taffy_style};
+ pub(crate) fn word_spacing_advance(text: &str, spacing: f32) -> f32 {
+ if spacing == 0.0 { return 0.0; }
+ text.chars().filter(|c| matches!(c, ' ' | '\u{00a0}')).count() as f32 * spacing
+ }
+
/// Text width for layout. With the `paint` feature this is exact (real glyph
/// metrics from the embedded font, shared with rasterization). Without it
/// (layout-only builds, e.g. for `getBoundingClientRect`), fall back to a
@@@ -5225,9 -4811,9 +5234,10 @@@ fn layout_dom_once
font_optical_sizing: crate::FontOpticalSizing,
font_variation_settings: Vec<crate::FontVariationSetting>,
letter_spacing: f32,
+ word_spacing: f32,
letter_spacing_non_normal: bool,
container_type: crate::ContainerType,
+ containment: u8,
container_names: Vec<String>,
text_align: Option<taffy::AlignItems>,
text_indent: crate::Dimension,
@@@ -5287,9 -4864,9 +5297,10 @@@
font_optical_sizing: crate::FontOpticalSizing::Auto,
font_variation_settings: Vec::new(),
letter_spacing: 0.0,
+ word_spacing: 0.0,
letter_spacing_non_normal: false,
container_type: crate::ContainerType::Normal,
+ containment: 0,
container_names: Vec::new(),
text_align: None,
text_indent: crate::Dimension::Px(0.0),