diff --git a/crates/typst-cli/src/compile.rs b/crates/typst-cli/src/compile.rs index 74d818a54..c6d37ffec 100644 --- a/crates/typst-cli/src/compile.rs +++ b/crates/typst-cli/src/compile.rs @@ -12,8 +12,7 @@ use typst::diag::{ bail, At, Severity, SourceDiagnostic, SourceResult, StrResult, Warned, }; use typst::foundations::{Datetime, Smart}; -use typst::layout::{Frame, Page, PageRanges}; -use typst::model::Document; +use typst::layout::{Frame, Page, PageRanges, PagedDocument}; use typst::syntax::{FileId, Source, Span}; use typst::WorldExt; use typst_pdf::{PdfOptions, PdfStandards}; @@ -171,7 +170,7 @@ pub fn compile_once( /// Export into the target format. fn export( world: &mut SystemWorld, - document: &Document, + document: &PagedDocument, command: &CompileCommand, watching: bool, ) -> SourceResult<()> { @@ -189,7 +188,7 @@ fn export( } /// Export to a PDF. -fn export_pdf(document: &Document, command: &CompileCommand) -> SourceResult<()> { +fn export_pdf(document: &PagedDocument, command: &CompileCommand) -> SourceResult<()> { let options = PdfOptions { ident: Smart::Auto, timestamp: convert_datetime( @@ -229,7 +228,7 @@ enum ImageExportFormat { /// Export to one or multiple images. fn export_image( world: &mut SystemWorld, - document: &Document, + document: &PagedDocument, command: &CompileCommand, watching: bool, fmt: ImageExportFormat, diff --git a/crates/typst-cli/src/query.rs b/crates/typst-cli/src/query.rs index 90d99a5a2..947a64850 100644 --- a/crates/typst-cli/src/query.rs +++ b/crates/typst-cli/src/query.rs @@ -3,7 +3,7 @@ use ecow::{eco_format, EcoString}; use serde::Serialize; use typst::diag::{bail, HintedStrResult, StrResult, Warned}; use typst::foundations::{Content, IntoValue, LocatableSelector, Scope}; -use typst::model::Document; +use typst::layout::PagedDocument; use typst::syntax::Span; use typst::World; use typst_eval::{eval_string, EvalMode}; @@ -53,7 +53,7 @@ pub fn query(command: &QueryCommand) -> HintedStrResult<()> { fn retrieve( world: &dyn World, command: &QueryCommand, - document: &Document, + document: &PagedDocument, ) -> HintedStrResult> { let selector = eval_string( &typst::ROUTINES, diff --git a/crates/typst-ide/src/analyze.rs b/crates/typst-ide/src/analyze.rs index eaf7248b7..0b41fb68d 100644 --- a/crates/typst-ide/src/analyze.rs +++ b/crates/typst-ide/src/analyze.rs @@ -1,7 +1,8 @@ use comemo::Track; use ecow::{eco_vec, EcoString, EcoVec}; use typst::foundations::{Label, Styles, Value}; -use typst::model::{BibliographyElem, Document}; +use typst::layout::PagedDocument; +use typst::model::BibliographyElem; use typst::syntax::{ast, LinkedNode, SyntaxKind}; use crate::IdeWorld; @@ -65,7 +66,9 @@ pub fn analyze_import(world: &dyn IdeWorld, source: &LinkedNode) -> Option (Vec<(Label, Option)>, usize) { +pub fn analyze_labels( + document: &PagedDocument, +) -> (Vec<(Label, Option)>, usize) { let mut output = vec![]; // Labels in the document. diff --git a/crates/typst-ide/src/complete.rs b/crates/typst-ide/src/complete.rs index 510db54ce..5c2b500a0 100644 --- a/crates/typst-ide/src/complete.rs +++ b/crates/typst-ide/src/complete.rs @@ -9,8 +9,7 @@ use typst::foundations::{ fields_on, repr, AutoValue, CastInfo, Func, Label, NoneValue, ParamInfo, Repr, StyleChain, Styles, Type, Value, }; -use typst::layout::{Alignment, Dir}; -use typst::model::Document; +use typst::layout::{Alignment, Dir, PagedDocument}; use typst::syntax::ast::AstNode; use typst::syntax::{ ast, is_id_continue, is_id_start, is_ident, FileId, LinkedNode, Side, Source, @@ -38,7 +37,7 @@ use crate::{analyze_expr, analyze_import, analyze_labels, named_items, IdeWorld} /// when the document is available. pub fn autocomplete( world: &dyn IdeWorld, - document: Option<&Document>, + document: Option<&PagedDocument>, source: &Source, cursor: usize, explicit: bool, @@ -1063,7 +1062,7 @@ fn code_completions(ctx: &mut CompletionContext, hash: bool) { /// Context for autocompletion. struct CompletionContext<'a> { world: &'a (dyn IdeWorld + 'a), - document: Option<&'a Document>, + document: Option<&'a PagedDocument>, text: &'a str, before: &'a str, after: &'a str, @@ -1079,7 +1078,7 @@ impl<'a> CompletionContext<'a> { /// Create a new autocompletion context. fn new( world: &'a (dyn IdeWorld + 'a), - document: Option<&'a Document>, + document: Option<&'a PagedDocument>, source: &'a Source, leaf: &'a LinkedNode<'a>, cursor: usize, @@ -1507,7 +1506,7 @@ impl BracketMode { mod tests { use std::collections::BTreeSet; - use typst::model::Document; + use typst::layout::PagedDocument; use typst::syntax::{FileId, Source, VirtualPath}; use typst::World; @@ -1607,7 +1606,7 @@ mod tests { fn test_full( world: &TestWorld, source: &Source, - doc: Option<&Document>, + doc: Option<&PagedDocument>, cursor: isize, ) -> Response { autocomplete(world, doc, source, source.cursor(cursor), true) diff --git a/crates/typst-ide/src/definition.rs b/crates/typst-ide/src/definition.rs index 9303aee43..c789430a2 100644 --- a/crates/typst-ide/src/definition.rs +++ b/crates/typst-ide/src/definition.rs @@ -1,5 +1,5 @@ use typst::foundations::{Label, Selector, Value}; -use typst::model::Document; +use typst::layout::PagedDocument; use typst::syntax::{ast, LinkedNode, Side, Source, Span}; use typst::utils::PicoStr; @@ -25,7 +25,7 @@ pub enum Definition { /// when the document is available. pub fn definition( world: &dyn IdeWorld, - document: Option<&Document>, + document: Option<&PagedDocument>, source: &Source, cursor: usize, side: Side, diff --git a/crates/typst-ide/src/jump.rs b/crates/typst-ide/src/jump.rs index 2dd5cf610..ba62b0ab9 100644 --- a/crates/typst-ide/src/jump.rs +++ b/crates/typst-ide/src/jump.rs @@ -1,7 +1,7 @@ use std::num::NonZeroUsize; -use typst::layout::{Frame, FrameItem, Point, Position, Size}; -use typst::model::{Destination, Document, Url}; +use typst::layout::{Frame, FrameItem, PagedDocument, Point, Position, Size}; +use typst::model::{Destination, Url}; use typst::syntax::{FileId, LinkedNode, Side, Source, Span, SyntaxKind}; use typst::visualize::Geometry; use typst::WorldExt; @@ -30,7 +30,7 @@ impl Jump { /// Determine where to jump to based on a click in a frame. pub fn jump_from_click( world: &dyn IdeWorld, - document: &Document, + document: &PagedDocument, frame: &Frame, click: Point, ) -> Option { @@ -110,7 +110,7 @@ pub fn jump_from_click( /// Find the output location in the document for a cursor position. pub fn jump_from_cursor( - document: &Document, + document: &PagedDocument, source: &Source, cursor: usize, ) -> Vec { diff --git a/crates/typst-ide/src/tooltip.rs b/crates/typst-ide/src/tooltip.rs index 30aca24fb..adfbeda50 100644 --- a/crates/typst-ide/src/tooltip.rs +++ b/crates/typst-ide/src/tooltip.rs @@ -4,8 +4,7 @@ use ecow::{eco_format, EcoString}; use if_chain::if_chain; use typst::engine::Sink; use typst::foundations::{repr, Capturer, CastInfo, Repr, Value}; -use typst::layout::Length; -use typst::model::Document; +use typst::layout::{Length, PagedDocument}; use typst::syntax::ast::AstNode; use typst::syntax::{ast, LinkedNode, Side, Source, SyntaxKind}; use typst::utils::{round_with_precision, Numeric}; @@ -21,7 +20,7 @@ use crate::{analyze_expr, analyze_import, analyze_labels, IdeWorld}; /// document is available. pub fn tooltip( world: &dyn IdeWorld, - document: Option<&Document>, + document: Option<&PagedDocument>, source: &Source, cursor: usize, side: Side, @@ -173,7 +172,7 @@ fn length_tooltip(length: Length) -> Option { } /// Tooltip for a hovered reference or label. -fn label_tooltip(document: &Document, leaf: &LinkedNode) -> Option { +fn label_tooltip(document: &PagedDocument, leaf: &LinkedNode) -> Option { let target = match leaf.kind() { SyntaxKind::RefMarker => leaf.text().trim_start_matches('@'), SyntaxKind::Label => leaf.text().trim_start_matches('<').trim_end_matches('>'), diff --git a/crates/typst-layout/src/pages/mod.rs b/crates/typst-layout/src/pages/mod.rs index b969749a1..667e16b3f 100644 --- a/crates/typst-layout/src/pages/mod.rs +++ b/crates/typst-layout/src/pages/mod.rs @@ -11,8 +11,8 @@ use typst_library::foundations::{Content, StyleChain}; use typst_library::introspection::{ Introspector, Locator, ManualPageCounter, SplitLocator, TagElem, }; -use typst_library::layout::{FrameItem, Page, Point}; -use typst_library::model::{Document, DocumentInfo}; +use typst_library::layout::{FrameItem, Page, PagedDocument, Point}; +use typst_library::model::DocumentInfo; use typst_library::routines::{Arenas, Pair, RealizationKind, Routines}; use typst_library::World; @@ -26,12 +26,12 @@ use self::run::{layout_blank_page, layout_page_run, LayoutedPage}; /// elements. In contrast to [`layout_fragment`](crate::layout_fragment), /// this does not take regions since the regions are defined by the page /// configuration in the content and style chain. -#[typst_macros::time(name = "document")] +#[typst_macros::time(name = "layout document")] pub fn layout_document( engine: &mut Engine, content: &Content, styles: StyleChain, -) -> SourceResult { +) -> SourceResult { layout_document_impl( engine.routines, engine.world, @@ -56,7 +56,7 @@ fn layout_document_impl( route: Tracked, content: &Content, styles: StyleChain, -) -> SourceResult { +) -> SourceResult { let mut locator = Locator::root().split(); let mut engine = Engine { routines, @@ -86,7 +86,7 @@ fn layout_document_impl( let pages = layout_pages(&mut engine, &mut children, locator, styles)?; let introspector = Introspector::new(&pages); - Ok(Document { pages, info, introspector }) + Ok(PagedDocument { pages, info, introspector }) } /// Layouts the document's pages. diff --git a/crates/typst-library/src/layout/page.rs b/crates/typst-library/src/layout/page.rs index 09aafa7f3..68fd89745 100644 --- a/crates/typst-library/src/layout/page.rs +++ b/crates/typst-library/src/layout/page.rs @@ -12,11 +12,12 @@ use crate::foundations::{ cast, elem, Args, AutoValue, Cast, Construct, Content, Context, Dict, Fold, Func, NativeElement, Set, Smart, StyleChain, Value, }; +use crate::introspection::Introspector; use crate::layout::{ Abs, Alignment, FlushElem, Frame, HAlignment, Length, OuterVAlignment, Ratio, Rel, Sides, SpecificAlignment, }; -use crate::model::Numbering; +use crate::model::{DocumentInfo, Numbering}; use crate::text::LocalName; use crate::visualize::{Color, Paint}; @@ -451,6 +452,17 @@ impl PagebreakElem { } } +/// A finished document with metadata and page frames. +#[derive(Debug, Default, Clone)] +pub struct PagedDocument { + /// The document's finished pages. + pub pages: Vec, + /// Details about the document. + pub info: DocumentInfo, + /// Provides the ability to execute queries on the document. + pub introspector: Introspector, +} + /// A finished page. #[derive(Debug, Clone)] pub struct Page { @@ -942,3 +954,14 @@ papers! { (PRESENTATION_16_9: 297.0, 167.0625, "presentation-16-9") (PRESENTATION_4_3: 280.0, 210.0, "presentation-4-3") } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_paged_document_is_send_and_sync() { + fn ensure_send_and_sync() {} + ensure_send_and_sync::(); + } +} diff --git a/crates/typst-library/src/model/document.rs b/crates/typst-library/src/model/document.rs index b693d7856..c333dff33 100644 --- a/crates/typst-library/src/model/document.rs +++ b/crates/typst-library/src/model/document.rs @@ -6,8 +6,6 @@ use crate::foundations::{ cast, elem, Args, Array, Construct, Content, Datetime, Fields, Smart, StyleChain, Styles, Value, }; -use crate::introspection::Introspector; -use crate::layout::Page; /// The root element of a document and its metadata. /// @@ -86,17 +84,6 @@ cast! { v: Array => Self(v.into_iter().map(Value::cast).collect::>()?), } -/// A finished document with metadata and page frames. -#[derive(Debug, Default, Clone)] -pub struct Document { - /// The document's finished pages. - pub pages: Vec, - /// Details about the document. - pub info: DocumentInfo, - /// Provides the ability to execute queries on the document. - pub introspector: Introspector, -} - /// Details about the document. #[derive(Debug, Default, Clone, PartialEq, Hash)] pub struct DocumentInfo { @@ -132,14 +119,3 @@ impl DocumentInfo { } } } - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_document_is_send_and_sync() { - fn ensure_send_and_sync() {} - ensure_send_and_sync::(); - } -} diff --git a/crates/typst-library/src/routines.rs b/crates/typst-library/src/routines.rs index 6b78b7fbf..000b3bba5 100644 --- a/crates/typst-library/src/routines.rs +++ b/crates/typst-library/src/routines.rs @@ -16,10 +16,11 @@ use crate::foundations::{ use crate::introspection::{Introspector, Locator, SplitLocator}; use crate::layout::{ Abs, BoxElem, ColumnsElem, Fragment, Frame, GridElem, InlineItem, MoveElem, PadElem, - Region, Regions, Rel, RepeatElem, RotateElem, ScaleElem, Size, SkewElem, StackElem, + PagedDocument, Region, Regions, Rel, RepeatElem, RotateElem, ScaleElem, Size, + SkewElem, StackElem, }; use crate::math::EquationElem; -use crate::model::{Document, DocumentInfo, EnumElem, ListElem, TableElem}; +use crate::model::{DocumentInfo, EnumElem, ListElem, TableElem}; use crate::visualize::{ CircleElem, EllipseElem, ImageElem, LineElem, PathElem, PolygonElem, RectElem, SquareElem, @@ -90,7 +91,7 @@ routines! { engine: &mut Engine, content: &Content, styles: StyleChain, - ) -> SourceResult + ) -> SourceResult /// Lays out content into multiple regions. fn layout_fragment( diff --git a/crates/typst-pdf/src/lib.rs b/crates/typst-pdf/src/lib.rs index efc99b749..f9b4e902d 100644 --- a/crates/typst-pdf/src/lib.rs +++ b/crates/typst-pdf/src/lib.rs @@ -24,8 +24,7 @@ use pdf_writer::{Chunk, Name, Pdf, Ref, Str, TextStr}; use serde::{Deserialize, Serialize}; use typst_library::diag::{bail, SourceResult, StrResult}; use typst_library::foundations::{Datetime, Smart}; -use typst_library::layout::{Abs, Em, PageRanges, Transform}; -use typst_library::model::Document; +use typst_library::layout::{Abs, Em, PageRanges, PagedDocument, Transform}; use typst_library::text::Font; use typst_library::visualize::Image; use typst_syntax::Span; @@ -49,7 +48,7 @@ use crate::resources::{ /// /// Returns the raw bytes making up the PDF file. #[typst_macros::time(name = "pdf")] -pub fn pdf(document: &Document, options: &PdfOptions) -> SourceResult> { +pub fn pdf(document: &PagedDocument, options: &PdfOptions) -> SourceResult> { PdfBuilder::new(document, options) .phase(|builder| builder.run(traverse_pages))? .phase(|builder| { @@ -176,7 +175,7 @@ struct PdfBuilder { /// this phase. struct WithDocument<'a> { /// The Typst document that is exported. - document: &'a Document, + document: &'a PagedDocument, /// Settings for PDF export. options: &'a PdfOptions<'a>, } @@ -186,7 +185,7 @@ struct WithDocument<'a> { /// /// This phase allocates some global references. struct WithResources<'a> { - document: &'a Document, + document: &'a PagedDocument, options: &'a PdfOptions<'a>, /// The content of the pages encoded as PDF content streams. /// @@ -235,7 +234,7 @@ impl<'a> From<(WithDocument<'a>, (Vec>, Resources<()>))> /// We are now writing objects corresponding to resources, and giving them references, /// that will be collected in [`References`]. struct WithGlobalRefs<'a> { - document: &'a Document, + document: &'a PagedDocument, options: &'a PdfOptions<'a>, pages: Vec>, /// Resources are the same as in previous phases, but each dictionary now has a reference. @@ -278,7 +277,7 @@ struct References { /// tree is going to be written, and given a reference. It is also at this point that /// the page contents is actually written. struct WithRefs<'a> { - document: &'a Document, + document: &'a PagedDocument, options: &'a PdfOptions<'a>, globals: GlobalRefs, pages: Vec>, @@ -304,7 +303,7 @@ impl<'a> From<(WithGlobalRefs<'a>, References)> for WithRefs<'a> { /// /// Each sub-resource gets its own isolated resource dictionary. struct WithEverything<'a> { - document: &'a Document, + document: &'a PagedDocument, options: &'a PdfOptions<'a>, globals: GlobalRefs, pages: Vec>, @@ -336,7 +335,7 @@ impl<'a> From<(WithRefs<'a>, Ref)> for WithEverything<'a> { impl<'a> PdfBuilder> { /// Start building a PDF for a Typst document. - fn new(document: &'a Document, options: &'a PdfOptions<'a>) -> Self { + fn new(document: &'a PagedDocument, options: &'a PdfOptions<'a>) -> Self { Self { alloc: Ref::new(1), pdf: Pdf::new(), diff --git a/crates/typst-render/src/lib.rs b/crates/typst-render/src/lib.rs index 8de3852d4..8595e7908 100644 --- a/crates/typst-render/src/lib.rs +++ b/crates/typst-render/src/lib.rs @@ -7,9 +7,9 @@ mod text; use tiny_skia as sk; use typst_library::layout::{ - Abs, Axes, Frame, FrameItem, FrameKind, GroupItem, Page, Point, Size, Transform, + Abs, Axes, Frame, FrameItem, FrameKind, GroupItem, Page, PagedDocument, Point, Size, + Transform, }; -use typst_library::model::Document; use typst_library::visualize::{Color, Geometry, Paint}; /// Export a page into a raster image. @@ -43,7 +43,7 @@ pub fn render(page: &Page, pixel_per_pt: f32) -> sk::Pixmap { /// Export a document with potentially multiple pages into a single raster image. pub fn render_merged( - document: &Document, + document: &PagedDocument, pixel_per_pt: f32, gap: Abs, fill: Option, diff --git a/crates/typst-svg/src/lib.rs b/crates/typst-svg/src/lib.rs index fb7d27c22..f9ce4b860 100644 --- a/crates/typst-svg/src/lib.rs +++ b/crates/typst-svg/src/lib.rs @@ -11,9 +11,9 @@ use std::fmt::{self, Display, Formatter, Write}; use ecow::EcoString; use ttf_parser::OutlineBuilder; use typst_library::layout::{ - Abs, Frame, FrameItem, FrameKind, GroupItem, Page, Point, Ratio, Size, Transform, + Abs, Frame, FrameItem, FrameKind, GroupItem, Page, PagedDocument, Point, Ratio, Size, + Transform, }; -use typst_library::model::Document; use typst_library::visualize::{Geometry, Gradient, Pattern}; use typst_utils::hash128; use xmlwriter::XmlWriter; @@ -35,7 +35,7 @@ pub fn svg(page: &Page) -> String { /// Export a document with potentially multiple pages into a single SVG file. /// /// The padding will be added around and between the individual frames. -pub fn svg_merged(document: &Document, padding: Abs) -> String { +pub fn svg_merged(document: &PagedDocument, padding: Abs) -> String { let width = 2.0 * padding + document .pages diff --git a/crates/typst/src/lib.rs b/crates/typst/src/lib.rs index db1673d2d..feb17ba9e 100644 --- a/crates/typst/src/lib.rs +++ b/crates/typst/src/lib.rs @@ -47,7 +47,7 @@ use typst_library::diag::{warning, FileError, SourceDiagnostic, SourceResult, Wa use typst_library::engine::{Engine, Route, Sink, Traced}; use typst_library::foundations::{StyleChain, Styles, Value}; use typst_library::introspection::Introspector; -use typst_library::model::Document; +use typst_library::layout::PagedDocument; use typst_library::routines::Routines; use typst_syntax::{FileId, Span}; use typst_timing::{timed, TimingScope}; @@ -57,7 +57,7 @@ use typst_timing::{timed, TimingScope}; /// - Returns `Ok(document)` if there were no fatal errors. /// - Returns `Err(errors)` if there were fatal errors. #[typst_macros::time] -pub fn compile(world: &dyn World) -> Warned> { +pub fn compile(world: &dyn World) -> Warned> { let mut sink = Sink::new(); let output = compile_impl(world.track(), Traced::default().track(), &mut sink) .map_err(deduplicate); @@ -80,7 +80,7 @@ fn compile_impl( world: Tracked, traced: Tracked, sink: &mut Sink, -) -> SourceResult { +) -> SourceResult { let library = world.library(); let styles = StyleChain::new(&library.styles); @@ -103,7 +103,7 @@ fn compile_impl( let mut iter = 0; let mut subsink; - let mut document = Document::default(); + let mut document = PagedDocument::default(); // Relayout until all introspections stabilize. // If that doesn't happen within five attempts, we give up. diff --git a/docs/src/lib.rs b/docs/src/lib.rs index 9228a9906..5ca3724ab 100644 --- a/docs/src/lib.rs +++ b/docs/src/lib.rs @@ -21,10 +21,10 @@ use typst::foundations::{ Scope, Smart, Type, Value, FOUNDATIONS, }; use typst::introspection::INTROSPECTION; -use typst::layout::{Abs, Margin, PageElem, LAYOUT}; +use typst::layout::{Abs, Margin, PageElem, PagedDocument, LAYOUT}; use typst::loading::DATA_LOADING; use typst::math::MATH; -use typst::model::{Document, MODEL}; +use typst::model::MODEL; use typst::symbols::SYMBOLS; use typst::text::{Font, FontBook, TEXT}; use typst::utils::LazyHash; @@ -105,7 +105,8 @@ pub trait Resolver { fn image(&self, filename: &str, data: &[u8]) -> String; /// Produce HTML for an example. - fn example(&self, hash: u128, source: Option, document: &Document) -> Html; + fn example(&self, hash: u128, source: Option, document: &PagedDocument) + -> Html; /// Determine the commits between two tags. fn commits(&self, from: &str, to: &str) -> Vec; @@ -800,7 +801,7 @@ mod tests { None } - fn example(&self, _: u128, _: Option, _: &Document) -> Html { + fn example(&self, _: u128, _: Option, _: &PagedDocument) -> Html { Html::new(String::new()) } diff --git a/docs/src/main.rs b/docs/src/main.rs index d87e359b9..f8d7c9345 100644 --- a/docs/src/main.rs +++ b/docs/src/main.rs @@ -2,7 +2,7 @@ use std::fs; use std::path::{Path, PathBuf}; use clap::Parser; -use typst::model::Document; +use typst::layout::PagedDocument; use typst_docs::{provide, Html, Resolver}; use typst_render::render; @@ -25,7 +25,7 @@ impl<'a> Resolver for CliResolver<'a> { &self, hash: u128, source: Option, - document: &Document, + document: &PagedDocument, ) -> typst_docs::Html { if self.verbose { eprintln!( diff --git a/tests/src/custom.rs b/tests/src/custom.rs index 9a5fef03c..965312abc 100644 --- a/tests/src/custom.rs +++ b/tests/src/custom.rs @@ -1,7 +1,8 @@ use std::fmt::Write; use typst::foundations::Smart; -use typst::model::{Document, DocumentInfo}; +use typst::layout::PagedDocument; +use typst::model::DocumentInfo; use typst::World; use crate::collect::Test; @@ -18,7 +19,7 @@ macro_rules! test_eq { /// Run special checks for specific tests for which it is not worth it to create /// custom annotations. -pub fn check(test: &Test, world: &TestWorld, doc: Option<&Document>) -> String { +pub fn check(test: &Test, world: &TestWorld, doc: Option<&PagedDocument>) -> String { let mut sink = String::new(); match test.name.as_str() { "document-set-author-date" => { @@ -41,6 +42,6 @@ pub fn check(test: &Test, world: &TestWorld, doc: Option<&Document>) -> String { } /// Extract the document information. -fn info(doc: Option<&Document>) -> DocumentInfo { +fn info(doc: Option<&PagedDocument>) -> DocumentInfo { doc.map(|doc| doc.info.clone()).unwrap_or_default() } diff --git a/tests/src/run.rs b/tests/src/run.rs index 1ea19a16a..1aa702041 100644 --- a/tests/src/run.rs +++ b/tests/src/run.rs @@ -5,8 +5,7 @@ use std::path::Path; use ecow::eco_vec; use tiny_skia as sk; use typst::diag::{SourceDiagnostic, Warned}; -use typst::layout::{Abs, Frame, FrameItem, Page, Transform}; -use typst::model::Document; +use typst::layout::{Abs, Frame, FrameItem, Page, PagedDocument, Transform}; use typst::visualize::Color; use typst::WorldExt; use typst_pdf::PdfOptions; @@ -116,7 +115,7 @@ impl<'a> Runner<'a> { /// Run custom checks for which it is not worth to create special /// annotations. - fn check_custom(&mut self, doc: Option<&Document>) { + fn check_custom(&mut self, doc: Option<&PagedDocument>) { let errors = crate::custom::check(self.test, &self.world, doc); if !errors.is_empty() { log!(self, "custom check failed"); @@ -127,7 +126,7 @@ impl<'a> Runner<'a> { } /// Check that the document output is correct. - fn check_document(&mut self, document: Option<&Document>) { + fn check_document(&mut self, document: Option<&PagedDocument>) { let live_path = format!("{}/render/{}.png", crate::STORE_PATH, self.test.name); let ref_path = format!("{}/{}.png", crate::REF_PATH, self.test.name); let has_ref = Path::new(&ref_path).exists(); @@ -351,7 +350,7 @@ impl<'a> Runner<'a> { } /// Draw all frames into one image with padding in between. -fn render(document: &Document, pixel_per_pt: f32) -> sk::Pixmap { +fn render(document: &PagedDocument, pixel_per_pt: f32) -> sk::Pixmap { for page in &document.pages { let limit = Abs::cm(100.0); if page.frame.width() > limit || page.frame.height() > limit {