Paint colorbox backgrounds
This commit is contained in:
1 parent
eebe6deac5
commit
d88e74cd29
8 files changed
+167
-25
No files matched your search
@@ -69,6 +69,13 @@ pub enum DisplayItem {
|
||||
height: i64,
|
||||
index: usize,
|
||||
},
|
||||
Rect {
|
||||
x: i64,
|
||||
y: i64,
|
||||
width: i64,
|
||||
height: i64,
|
||||
color: [u8; 3],
|
||||
},
|
||||
Link {
|
||||
x: i64,
|
||||
y: i64,
|
||||
@@ -162,7 +169,9 @@ impl DisplayList {
|
||||
*x2 += dx;
|
||||
*y2 += dy;
|
||||
}
|
||||
DisplayItem::Image { x, y, .. } | DisplayItem::Link { x, y, .. } => {
|
||||
DisplayItem::Rect { x, y, .. }
|
||||
| DisplayItem::Image { x, y, .. }
|
||||
| DisplayItem::Link { x, y, .. } => {
|
||||
*x += dx;
|
||||
*y += dy;
|
||||
}
|
||||
@@ -246,6 +255,24 @@ impl DisplayList {
|
||||
escape(text)
|
||||
));
|
||||
}
|
||||
DisplayItem::Rect {
|
||||
x,
|
||||
y,
|
||||
width,
|
||||
height,
|
||||
color,
|
||||
} => {
|
||||
out.push_str(&format!(
|
||||
"<rect x=\"{:.3}\" y=\"{:.3}\" width=\"{:.3}\" height=\"{:.3}\" fill=\"#{:02x}{:02x}{:02x}\"/>\n",
|
||||
*x as f64 / 65_536.0,
|
||||
*y as f64 / 65_536.0,
|
||||
*width as f64 / 65_536.0,
|
||||
*height as f64 / 65_536.0,
|
||||
color[0],
|
||||
color[1],
|
||||
color[2]
|
||||
));
|
||||
}
|
||||
DisplayItem::Rule {
|
||||
x,
|
||||
y,
|
||||
@@ -616,6 +643,17 @@ impl Page {
|
||||
} else {
|
||||
flush_link(&mut link_run, &mut list.items);
|
||||
}
|
||||
if let Some(background) = box_.background {
|
||||
list.items.push(DisplayItem::Rect {
|
||||
x,
|
||||
y: baseline - box_.height,
|
||||
width: box_.width,
|
||||
height: box_.height + box_.depth,
|
||||
color: background,
|
||||
});
|
||||
list.items.push(DisplayItem::Fill([0, 0, 0]));
|
||||
current_color = None;
|
||||
}
|
||||
if box_.color != current_color {
|
||||
let rgb = box_.color.unwrap_or([0, 0, 0]);
|
||||
list.items.push(DisplayItem::Fill(rgb));
|
||||
|
||||
Reference in new issue
Block a user