Fill the page background with pagecolor
This commit is contained in:
1 parent
4cb456743a
commit
1ab2a29bfa
6 files changed
+56
-5
No files matched your search
@@ -512,6 +512,16 @@ fn page_content(
|
||||
origin: PageOrigin,
|
||||
) -> String {
|
||||
let mut content = String::from("q\n0 0 0 rg\n");
|
||||
if let Some(DisplayItem::Background(color)) = list.items.first() {
|
||||
content.push_str(&format!(
|
||||
"{:.3} {:.3} {:.3} rg\n0 0 {} {} re f\n0 0 0 rg\n",
|
||||
color[0] as f64 / 255.0,
|
||||
color[1] as f64 / 255.0,
|
||||
color[2] as f64 / 255.0,
|
||||
pt(list.width),
|
||||
pt(height)
|
||||
));
|
||||
}
|
||||
if origin != PageOrigin::default() {
|
||||
content.push_str(&format!(
|
||||
"1 0 0 1 {} {} cm\n",
|
||||
@@ -562,6 +572,7 @@ fn page_content(
|
||||
operand
|
||||
));
|
||||
}
|
||||
DisplayItem::Background(_) => {}
|
||||
DisplayItem::Rule {
|
||||
x,
|
||||
y,
|
||||
|
||||
@@ -76,6 +76,8 @@ pub enum DisplayItem {
|
||||
height: i64,
|
||||
url: String,
|
||||
},
|
||||
/// Fill the whole page with a background colour (RGB).
|
||||
Background([u8; 3]),
|
||||
/// Switch the fill colour for following text (RGB).
|
||||
Fill([u8; 3]),
|
||||
Special(String),
|
||||
@@ -164,7 +166,7 @@ impl DisplayList {
|
||||
*x += dx;
|
||||
*y += dy;
|
||||
}
|
||||
DisplayItem::Fill(_) => {}
|
||||
DisplayItem::Fill(_) | DisplayItem::Background(_) => {}
|
||||
DisplayItem::Special(_) => {}
|
||||
}
|
||||
}
|
||||
@@ -180,6 +182,14 @@ impl DisplayList {
|
||||
let mut fill = [0u8, 0, 0];
|
||||
for item in &self.items {
|
||||
match item {
|
||||
DisplayItem::Background(color) => {
|
||||
let width = self.width as f64 / 65_536.0;
|
||||
let height = self.height as f64 / 65_536.0;
|
||||
out.push_str(&format!(
|
||||
"<rect x=\"0\" y=\"0\" width=\"{width:.3}\" height=\"{height:.3}\" fill=\"#{:02x}{:02x}{:02x}\"/>\n",
|
||||
color[0], color[1], color[2]
|
||||
));
|
||||
}
|
||||
DisplayItem::Fill(color) => fill = *color,
|
||||
DisplayItem::Text {
|
||||
x,
|
||||
|
||||
Reference in new issue
Block a user