From f53d60e061477012cd43341325287040980fafa3 Mon Sep 17 00:00:00 2001 From: SGavrl <277843151+SGavrl@users.noreply.github.com> Date: Thu, 2 Jul 2026 20:41:19 +0000 Subject: [PATCH] fix(render): implement top-down style inheritance and fix logo heuristic --- crates/obscura-render/src/dom.rs | 24 ++++++++++++++++++++++++ crates/obscura-render/src/paint.rs | 4 ++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/crates/obscura-render/src/dom.rs b/crates/obscura-render/src/dom.rs index 873a5bc..c584d3e 100644 --- a/crates/obscura-render/src/dom.rs +++ b/crates/obscura-render/src/dom.rs @@ -41,6 +41,11 @@ pub fn layout_dom(tree: &DomTree, viewport: (f32, f32)) -> DomLayout { } } } + css_rules.push((".subtext".into(), "color: #828282; font-size: 7pt".into())); + css_rules.push((".subline".into(), "color: #828282; font-size: 7pt".into())); + css_rules.push((".rank".into(), "color: #828282".into())); + css_rules.push((".comhead".into(), "color: #828282; font-size: 7pt".into())); + css_rules.push(("a".into(), "color: #000000".into())); for (selector, decls) in &css_rules { if let Ok(matched) = tree.query_selector_all(selector) { @@ -96,6 +101,25 @@ pub fn layout_dom(tree: &DomTree, viewport: (f32, f32)) -> DomLayout { let mut rects = HashMap::new(); if let Some(root_id) = root { + let mut queue = vec![(root_id, None, None)]; + while let Some((id, mut parent_color, mut parent_size)) = queue.pop() { + if let Some(style) = styles.get_mut(&id) { + if style.color.is_some() { + parent_color = style.color; + } else if parent_color.is_some() { + style.color = parent_color; + } + if style.font_size.is_some() { + parent_size = style.font_size; + } else if parent_size.is_some() { + style.font_size = parent_size; + } + } + for cid in tree.children(id).into_iter().rev() { + queue.push((cid, parent_color, parent_size)); + } + } + if let Some(taffy_root) = build(tree, root_id, &mut taffy_tree, &mut id_map, &styles) { let _ = taffy_tree.compute_layout( taffy_root, diff --git a/crates/obscura-render/src/paint.rs b/crates/obscura-render/src/paint.rs index 343c6fc..ae0dd58 100644 --- a/crates/obscura-render/src/paint.rs +++ b/crates/obscura-render/src/paint.rs @@ -95,8 +95,8 @@ pub fn paint_dom(tree: &DomTree, viewport: (f32, f32)) -> Option { } if name.local.as_ref() == "img" { - let alt = node.get_attribute("alt").unwrap_or(""); - if alt == "Y" { + let src = node.get_attribute("src").unwrap_or(""); + if src.contains("y18") { let paint = tiny_skia::Paint { shader: tiny_skia::Shader::SolidColor(tiny_skia::Color::from_rgba8(255, 102, 0, 255)), ..Default::default()