summaryrefslogtreecommitdiff
path: root/src/export
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-12-02 15:41:39 +0100
committerLaurenz <laurmaedje@gmail.com>2022-12-02 15:45:18 +0100
commit9bc90c371fb41a2d6dc08eb4673e5be15f829514 (patch)
tree454a47ce82c2229e79a139a8bdeaed9add1e0a14 /src/export
parent5110a41de1ca2236739ace2d37a1af912bb029f1 (diff)
Introspection
Diffstat (limited to 'src/export')
-rw-r--r--src/export/pdf/mod.rs14
-rw-r--r--src/export/pdf/page.rs7
-rw-r--r--src/export/render.rs2
3 files changed, 13 insertions, 10 deletions
diff --git a/src/export/pdf/mod.rs b/src/export/pdf/mod.rs
index 8f9d9637..60cd4ea2 100644
--- a/src/export/pdf/mod.rs
+++ b/src/export/pdf/mod.rs
@@ -14,7 +14,7 @@ use pdf_writer::{Finish, Name, PdfWriter, Ref, TextStr};
use self::outline::HeadingNode;
use self::page::Page;
-use crate::doc::{Document, Lang, Metadata};
+use crate::doc::{Document, Lang};
use crate::font::Font;
use crate::geom::{Abs, Dir, Em};
use crate::image::Image;
@@ -23,7 +23,7 @@ use crate::image::Image;
///
/// Returns the raw bytes making up the PDF file.
pub fn pdf(document: &Document) -> Vec<u8> {
- let mut ctx = PdfContext::new(&document.metadata);
+ let mut ctx = PdfContext::new(document);
page::construct_pages(&mut ctx, &document.pages);
font::write_fonts(&mut ctx);
image::write_images(&mut ctx);
@@ -38,7 +38,7 @@ const D65_GRAY: Name<'static> = Name(b"d65gray");
/// Context for exporting a whole PDF document.
pub struct PdfContext<'a> {
- metadata: &'a Metadata,
+ document: &'a Document,
writer: PdfWriter,
pages: Vec<Page>,
page_heights: Vec<f32>,
@@ -55,11 +55,11 @@ pub struct PdfContext<'a> {
}
impl<'a> PdfContext<'a> {
- fn new(metadata: &'a Metadata) -> Self {
+ fn new(document: &'a Document) -> Self {
let mut alloc = Ref::new(1);
let page_tree_ref = alloc.bump();
Self {
- metadata,
+ document,
writer: PdfWriter::new(),
pages: vec![],
page_heights: vec![],
@@ -116,10 +116,10 @@ fn write_catalog(ctx: &mut PdfContext) {
// Write the document information.
let mut info = ctx.writer.document_info(ctx.alloc.bump());
- if let Some(title) = &ctx.metadata.title {
+ if let Some(title) = &ctx.document.title {
info.title(TextStr(title));
}
- if let Some(author) = &ctx.metadata.author {
+ if let Some(author) = &ctx.document.author {
info.author(TextStr(author));
}
info.creator(TextStr("Typst"));
diff --git a/src/export/pdf/page.rs b/src/export/pdf/page.rs
index fc714e7a..f2ab78e3 100644
--- a/src/export/pdf/page.rs
+++ b/src/export/pdf/page.rs
@@ -3,7 +3,7 @@ use pdf_writer::writers::ColorSpace;
use pdf_writer::{Content, Filter, Finish, Name, Rect, Ref, Str};
use super::{deflate, AbsExt, EmExt, PdfContext, RefExt, D65_GRAY, SRGB};
-use crate::doc::{Destination, Element, Frame, Group, Text};
+use crate::doc::{Destination, Element, Frame, Group, Meta, Text};
use crate::font::Font;
use crate::geom::{
self, Abs, Color, Em, Geometry, Numeric, Paint, Point, Ratio, Shape, Size, Stroke,
@@ -287,7 +287,10 @@ fn write_frame(ctx: &mut PageContext, frame: &Frame) {
Element::Text(text) => write_text(ctx, x, y, text),
Element::Shape(shape) => write_shape(ctx, x, y, shape),
Element::Image(image, size) => write_image(ctx, x, y, image, *size),
- Element::Link(dest, size) => write_link(ctx, pos, dest, *size),
+ Element::Meta(meta, size) => match meta {
+ Meta::Link(dest) => write_link(ctx, pos, dest, *size),
+ _ => {}
+ },
}
}
}
diff --git a/src/export/render.rs b/src/export/render.rs
index a61ff1be..68625e23 100644
--- a/src/export/render.rs
+++ b/src/export/render.rs
@@ -57,7 +57,7 @@ fn render_frame(
Element::Image(image, size) => {
render_image(canvas, ts, mask, image, *size);
}
- Element::Link(_, _) => {}
+ Element::Meta(_, _) => {}
}
}
}