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