diff options
| author | Laurenz <laurmaedje@gmail.com> | 2024-07-20 14:51:24 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-20 12:51:24 +0000 |
| commit | 0c37a2c2334afb6947f265e00bded0fe75be6434 (patch) | |
| tree | c6dd66554f1f9cadc1f43f386639c05f3aa6bf3e /crates/typst-pdf/src | |
| parent | 3aa18beacf84e8e982a1cb28170d281769c06dd0 (diff) | |
Support transparent page fill (#4586)
Co-authored-by: Martin Haug <mhaug@live.de>
Diffstat (limited to 'crates/typst-pdf/src')
| -rw-r--r-- | crates/typst-pdf/src/color_font.rs | 2 | ||||
| -rw-r--r-- | crates/typst-pdf/src/content.rs | 6 | ||||
| -rw-r--r-- | crates/typst-pdf/src/page.rs | 9 | ||||
| -rw-r--r-- | crates/typst-pdf/src/pattern.rs | 2 |
4 files changed, 12 insertions, 7 deletions
diff --git a/crates/typst-pdf/src/color_font.rs b/crates/typst-pdf/src/color_font.rs index 201915b1..4889d915 100644 --- a/crates/typst-pdf/src/color_font.rs +++ b/crates/typst-pdf/src/color_font.rs @@ -243,7 +243,7 @@ impl ColorFontMap<()> { let width = font.advance(gid).unwrap_or(Em::new(0.0)).get() * font.units_per_em(); let instructions = - content::build(&mut self.resources, &frame, Some(width as f32)); + content::build(&mut self.resources, &frame, None, Some(width as f32)); color_font.glyphs.push(ColorGlyph { gid, instructions }); color_font.glyph_indices.insert(gid, index); diff --git a/crates/typst-pdf/src/content.rs b/crates/typst-pdf/src/content.rs index da9e4ed4..d9830e43 100644 --- a/crates/typst-pdf/src/content.rs +++ b/crates/typst-pdf/src/content.rs @@ -36,6 +36,7 @@ use crate::{deflate_deferred, AbsExt, EmExt}; pub fn build( resources: &mut Resources<()>, frame: &Frame, + fill: Option<Paint>, color_glyph_width: Option<f32>, ) -> Encoded { let size = frame.size(); @@ -53,6 +54,11 @@ pub fn build( .post_concat(Transform::translate(Abs::zero(), size.y)), ); + if let Some(fill) = fill { + let shape = Geometry::Rect(frame.size()).filled(fill); + write_shape(&mut ctx, Point::zero(), &shape); + } + // Encode the frame into the content stream. write_frame(&mut ctx, frame); diff --git a/crates/typst-pdf/src/page.rs b/crates/typst-pdf/src/page.rs index 2983f504..b07490cc 100644 --- a/crates/typst-pdf/src/page.rs +++ b/crates/typst-pdf/src/page.rs @@ -8,7 +8,7 @@ use pdf_writer::{ }; use typst::foundations::Label; use typst::introspection::Location; -use typst::layout::{Abs, Frame}; +use typst::layout::{Abs, Page}; use typst::model::{Destination, Numbering}; use typst::text::Case; @@ -33,7 +33,7 @@ pub fn traverse_pages( pages.push(None); skipped_pages += 1; } else { - let mut encoded = construct_page(&mut resources, &page.frame); + let mut encoded = construct_page(&mut resources, page); encoded.label = page .numbering .as_ref() @@ -60,9 +60,8 @@ pub fn traverse_pages( /// Construct a page object. #[typst_macros::time(name = "construct page")] -fn construct_page(out: &mut Resources<()>, frame: &Frame) -> EncodedPage { - let content = content::build(out, frame, None); - +fn construct_page(out: &mut Resources<()>, page: &Page) -> EncodedPage { + let content = content::build(out, &page.frame, page.fill_or_transparent(), None); EncodedPage { content, label: None } } diff --git a/crates/typst-pdf/src/pattern.rs b/crates/typst-pdf/src/pattern.rs index e06c04f8..d4f5a6e0 100644 --- a/crates/typst-pdf/src/pattern.rs +++ b/crates/typst-pdf/src/pattern.rs @@ -103,7 +103,7 @@ fn register_pattern( }; // Render the body. - let content = content::build(&mut patterns.resources, pattern.frame(), None); + let content = content::build(&mut patterns.resources, pattern.frame(), None, None); let pdf_pattern = PdfPattern { transform, |
