fix(render): implement top-down style inheritance and fix logo heuristic
This commit is contained in:
1 parent
cd3571ddc0
commit
f53d60e061
2 files changed
+26
-2
No files matched your search
@@ -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 {
|
for (selector, decls) in &css_rules {
|
||||||
if let Ok(matched) = tree.query_selector_all(selector) {
|
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();
|
let mut rects = HashMap::new();
|
||||||
if let Some(root_id) = root {
|
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) {
|
if let Some(taffy_root) = build(tree, root_id, &mut taffy_tree, &mut id_map, &styles) {
|
||||||
let _ = taffy_tree.compute_layout(
|
let _ = taffy_tree.compute_layout(
|
||||||
taffy_root,
|
taffy_root,
|
||||||
|
|||||||
@@ -95,8 +95,8 @@ pub fn paint_dom(tree: &DomTree, viewport: (f32, f32)) -> Option<Pixmap> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if name.local.as_ref() == "img" {
|
if name.local.as_ref() == "img" {
|
||||||
let alt = node.get_attribute("alt").unwrap_or("");
|
let src = node.get_attribute("src").unwrap_or("");
|
||||||
if alt == "Y" {
|
if src.contains("y18") {
|
||||||
let paint = tiny_skia::Paint {
|
let paint = tiny_skia::Paint {
|
||||||
shader: tiny_skia::Shader::SolidColor(tiny_skia::Color::from_rgba8(255, 102, 0, 255)),
|
shader: tiny_skia::Shader::SolidColor(tiny_skia::Color::from_rgba8(255, 102, 0, 255)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
|||||||
Reference in new issue
Block a user