Paint framed colorbox backgrounds

This commit is contained in:
gloamxun committed 2026-10-26 03:08:37 +08:00
1 parent d88e74cd29
commit 2018e5f8b8
8 files changed
+240 -62

No files matched your search

+39
View File
@@ -76,6 +76,14 @@ pub enum DisplayItem {
height: i64,
color: [u8; 3],
},
Frame {
x: i64,
y: i64,
width: i64,
height: i64,
color: [u8; 3],
thickness: i64,
},
Link {
x: i64,
y: i64,
@@ -170,6 +178,7 @@ impl DisplayList {
*y2 += dy;
}
DisplayItem::Rect { x, y, .. }
| DisplayItem::Frame { x, y, .. }
| DisplayItem::Image { x, y, .. }
| DisplayItem::Link { x, y, .. } => {
*x += dx;
@@ -288,6 +297,26 @@ impl DisplayList {
));
}
// Link annotations are PDF metadata; the SVG preview omits them.
DisplayItem::Frame {
x,
y,
width,
height,
color,
thickness,
} => {
out.push_str(&format!(
"<rect x=\"{:.3}\" y=\"{:.3}\" width=\"{:.3}\" height=\"{:.3}\" fill=\"none\" stroke=\"#{:02x}{:02x}{:02x}\" stroke-width=\"{:.3}\"/>\n",
*x as f64 / 65_536.0,
(*y - *height) as f64 / 65_536.0,
*width as f64 / 65_536.0,
*height as f64 / 65_536.0,
color[0],
color[1],
color[2],
*thickness as f64 / 65_536.0
));
}
DisplayItem::Link { .. } => {}
DisplayItem::Special(content) => {
out.push_str(&format!(
@@ -654,6 +683,16 @@ impl Page {
list.items.push(DisplayItem::Fill([0, 0, 0]));
current_color = None;
}
if let Some((frame_color, thickness)) = box_.frame {
list.items.push(DisplayItem::Frame {
x,
y: baseline - box_.height,
width: box_.width,
height: box_.height + box_.depth,
color: frame_color,
thickness,
});
}
if box_.color != current_color {
let rgb = box_.color.unwrap_or([0, 0, 0]);
list.items.push(DisplayItem::Fill(rgb));