mirror of
https://github.com/typst/typst
synced 2025-05-15 01:25:28 +08:00
Move binary into separate crate and tidy dependencies 🎭
This commit is contained in:
parent
533374db14
commit
d5ff97f42e
22
Cargo.toml
22
Cargo.toml
@ -1,27 +1,29 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "typstc"
|
name = "typstc"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Laurenz Mädje <laurmaedje@gmail.com>"]
|
authors = ["The Typst Project Developers"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
|
[workspace]
|
||||||
|
members = ["main"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
async-trait = "0.1"
|
async-trait = "0.1"
|
||||||
fontdock = { path = "../fontdock", features = ["fs", "serialize"] }
|
fontdock = { path = "../fontdock", features = ["fs", "serialize"] }
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"], optional = true }
|
||||||
serde_json = "1"
|
|
||||||
smallvec = "1"
|
|
||||||
tide = { path = "../tide" }
|
tide = { path = "../tide" }
|
||||||
ttf-parser = "0.8.2"
|
ttf-parser = "0.8.2"
|
||||||
unicode-xid = "0.2"
|
unicode-xid = "0.2"
|
||||||
futures-executor = { version = "0.3", optional = true }
|
|
||||||
|
|
||||||
[[bin]]
|
[features]
|
||||||
name = "typst"
|
serialize = []
|
||||||
path = "src/bin/main.rs"
|
|
||||||
required-features = ["futures-executor"]
|
[dev-dependencies]
|
||||||
|
futures-executor = "0.3"
|
||||||
|
serde_json = "1"
|
||||||
|
|
||||||
[[test]]
|
[[test]]
|
||||||
name = "typeset"
|
name = "typeset"
|
||||||
path = "tests/src/typeset.rs"
|
path = "tests/src/typeset.rs"
|
||||||
harness = false
|
harness = false
|
||||||
required-features = ["futures-executor"]
|
required-features = ["serialize"]
|
||||||
|
14
main/Cargo.toml
Normal file
14
main/Cargo.toml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
[package]
|
||||||
|
name = "typstc-main"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["The Typst Project Developers"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
typstc = { path = ".." }
|
||||||
|
fontdock = { path = "../../fontdock", features = ["fs"] }
|
||||||
|
futures-executor = "0.3"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "typstc-main"
|
||||||
|
path = "main.rs"
|
@ -22,9 +22,7 @@ fn main() {
|
|||||||
fn run() -> Result<(), Box<dyn Error>> {
|
fn run() -> Result<(), Box<dyn Error>> {
|
||||||
let args: Vec<String> = std::env::args().collect();
|
let args: Vec<String> = std::env::args().collect();
|
||||||
if args.len() < 2 || args.len() > 3 {
|
if args.len() < 2 || args.len() > 3 {
|
||||||
println!("typst");
|
println!("Usage: typst src.typ [out.pdf]");
|
||||||
println!("usage: {} source [destination]",
|
|
||||||
args.first().map(|s| s.as_str()).unwrap_or("typst"));
|
|
||||||
std::process::exit(0);
|
std::process::exit(0);
|
||||||
}
|
}
|
||||||
|
|
@ -4,14 +4,17 @@
|
|||||||
//! layout. However, this is a best effort process and bad things will still
|
//! layout. However, this is a best effort process and bad things will still
|
||||||
//! generate errors and warnings.
|
//! generate errors and warnings.
|
||||||
|
|
||||||
|
#[cfg(feature = "serialize")]
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use crate::syntax::span::SpanVec;
|
use crate::syntax::span::SpanVec;
|
||||||
|
|
||||||
/// A list of spanned diagnostics.
|
/// A list of spanned diagnostics.
|
||||||
pub type Diagnostics = SpanVec<Diagnostic>;
|
pub type Diagnostics = SpanVec<Diagnostic>;
|
||||||
|
|
||||||
/// A diagnostic that arose in parsing or layouting.
|
/// A diagnostic that arose in parsing or layouting.
|
||||||
#[derive(Debug, Clone, Eq, PartialEq, Serialize)]
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||||
|
#[cfg_attr(feature = "serialize", derive(Serialize))]
|
||||||
pub struct Diagnostic {
|
pub struct Diagnostic {
|
||||||
/// How severe / important the diagnostic is.
|
/// How severe / important the diagnostic is.
|
||||||
pub level: Level,
|
pub level: Level,
|
||||||
@ -20,8 +23,9 @@ pub struct Diagnostic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// How severe / important a diagnostic is.
|
/// How severe / important a diagnostic is.
|
||||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize)]
|
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[cfg_attr(feature = "serialize", derive(Serialize))]
|
||||||
|
#[cfg_attr(feature = "serialize", serde(rename_all = "camelCase"))]
|
||||||
pub enum Level {
|
pub enum Level {
|
||||||
Warning,
|
Warning,
|
||||||
Error,
|
Error,
|
||||||
|
@ -3,11 +3,14 @@
|
|||||||
use std::fmt::{self, Debug, Formatter};
|
use std::fmt::{self, Debug, Formatter};
|
||||||
use std::ops::*;
|
use std::ops::*;
|
||||||
|
|
||||||
|
#[cfg(feature = "serialize")]
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use crate::layout::prelude::*;
|
use crate::layout::prelude::*;
|
||||||
|
|
||||||
/// A value in two dimensions.
|
/// A value in two dimensions.
|
||||||
#[derive(Default, Copy, Clone, Eq, PartialEq, Serialize)]
|
#[derive(Default, Copy, Clone, Eq, PartialEq)]
|
||||||
|
#[cfg_attr(feature = "serialize", derive(Serialize))]
|
||||||
pub struct Value2<T> {
|
pub struct Value2<T> {
|
||||||
/// The horizontal component.
|
/// The horizontal component.
|
||||||
pub x: T,
|
pub x: T,
|
||||||
@ -176,7 +179,8 @@ impl Neg for Size {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A value in four dimensions.
|
/// A value in four dimensions.
|
||||||
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq, Serialize)]
|
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
|
||||||
|
#[cfg_attr(feature = "serialize", derive(Serialize))]
|
||||||
pub struct Value4<T> {
|
pub struct Value4<T> {
|
||||||
/// The left extent.
|
/// The left extent.
|
||||||
pub left: T,
|
pub left: T,
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
//! Drawing and configuration actions composing layouts.
|
//! Drawing and configuration actions composing layouts.
|
||||||
|
|
||||||
use std::fmt::{self, Debug, Formatter};
|
use std::fmt::{self, Debug, Formatter};
|
||||||
use serde::ser::{Serialize, Serializer, SerializeTuple};
|
|
||||||
use fontdock::FaceId;
|
|
||||||
|
|
||||||
|
#[cfg(feature = "serialize")]
|
||||||
|
use serde::ser::{Serialize, Serializer, SerializeTuple};
|
||||||
|
|
||||||
|
use fontdock::FaceId;
|
||||||
use crate::geom::Size;
|
use crate::geom::Size;
|
||||||
use super::Layout;
|
use super::Layout;
|
||||||
use self::LayoutAction::*;
|
use self::LayoutAction::*;
|
||||||
@ -22,6 +24,7 @@ pub enum LayoutAction {
|
|||||||
DebugBox(Size),
|
DebugBox(Size),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "serialize")]
|
||||||
impl Serialize for LayoutAction {
|
impl Serialize for LayoutAction {
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: Serializer {
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: Serializer {
|
||||||
match self {
|
match self {
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
//! Layouting types and engines.
|
//! Layouting types and engines.
|
||||||
|
|
||||||
use std::fmt::{self, Display, Formatter};
|
use std::fmt::{self, Display, Formatter};
|
||||||
use smallvec::SmallVec;
|
|
||||||
use serde::Serialize;
|
|
||||||
use fontdock::FaceId;
|
|
||||||
|
|
||||||
|
#[cfg(feature = "serialize")]
|
||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use fontdock::FaceId;
|
||||||
use crate::geom::{Size, Margins};
|
use crate::geom::{Size, Margins};
|
||||||
use self::prelude::*;
|
use self::prelude::*;
|
||||||
|
|
||||||
@ -31,12 +32,13 @@ pub mod prelude {
|
|||||||
pub type MultiLayout = Vec<Layout>;
|
pub type MultiLayout = Vec<Layout>;
|
||||||
|
|
||||||
/// A finished box with content at fixed positions.
|
/// A finished box with content at fixed positions.
|
||||||
#[derive(Debug, Clone, PartialEq, Serialize)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
#[cfg_attr(feature = "serialize", derive(Serialize))]
|
||||||
pub struct Layout {
|
pub struct Layout {
|
||||||
/// The size of the box.
|
/// The size of the box.
|
||||||
pub dimensions: Size,
|
pub dimensions: Size,
|
||||||
/// How to align this layout in a parent container.
|
/// How to align this layout in a parent container.
|
||||||
#[serde(skip)]
|
#[cfg_attr(feature = "serialize", serde(skip))]
|
||||||
pub align: LayoutAlign,
|
pub align: LayoutAlign,
|
||||||
/// The actions composing this layout.
|
/// The actions composing this layout.
|
||||||
pub actions: Vec<LayoutAction>,
|
pub actions: Vec<LayoutAction>,
|
||||||
@ -59,7 +61,7 @@ impl Layout {
|
|||||||
|
|
||||||
/// A vector of layout spaces, that is stack allocated as long as it only
|
/// A vector of layout spaces, that is stack allocated as long as it only
|
||||||
/// contains at most 2 spaces.
|
/// contains at most 2 spaces.
|
||||||
pub type LayoutSpaces = SmallVec<[LayoutSpace; 2]>;
|
pub type LayoutSpaces = Vec<LayoutSpace>;
|
||||||
|
|
||||||
/// The space into which content is laid out.
|
/// The space into which content is laid out.
|
||||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
#[derive(Debug, Copy, Clone, PartialEq)]
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use smallvec::smallvec;
|
|
||||||
|
|
||||||
use crate::{Pass, Feedback};
|
use crate::{Pass, Feedback};
|
||||||
use crate::SharedFontLoader;
|
use crate::SharedFontLoader;
|
||||||
@ -271,7 +270,7 @@ impl<'a> ModelLayouter<'a> {
|
|||||||
// new page style and update it within the layouter.
|
// new page style and update it within the layouter.
|
||||||
let margins = style.margins();
|
let margins = style.margins();
|
||||||
self.ctx.base = style.dimensions.unpadded(margins);
|
self.ctx.base = style.dimensions.unpadded(margins);
|
||||||
self.layouter.set_spaces(smallvec![
|
self.layouter.set_spaces(vec![
|
||||||
LayoutSpace {
|
LayoutSpace {
|
||||||
dimensions: style.dimensions,
|
dimensions: style.dimensions,
|
||||||
padding: margins,
|
padding: margins,
|
||||||
|
@ -21,7 +21,6 @@
|
|||||||
//! The position of the first aligned box thus depends on the length of the
|
//! The position of the first aligned box thus depends on the length of the
|
||||||
//! sentence in the second box.
|
//! sentence in the second box.
|
||||||
|
|
||||||
use smallvec::smallvec;
|
|
||||||
use crate::geom::Value4;
|
use crate::geom::Value4;
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
@ -248,7 +247,7 @@ impl StackLayouter {
|
|||||||
pub fn remaining(&self) -> LayoutSpaces {
|
pub fn remaining(&self) -> LayoutSpaces {
|
||||||
let dimensions = self.usable();
|
let dimensions = self.usable();
|
||||||
|
|
||||||
let mut spaces = smallvec![LayoutSpace {
|
let mut spaces = vec![LayoutSpace {
|
||||||
dimensions,
|
dimensions,
|
||||||
padding: Margins::ZERO,
|
padding: Margins::ZERO,
|
||||||
expansion: LayoutExpansion::new(false, false),
|
expansion: LayoutExpansion::new(false, false),
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
//! serialized to pass it to a suitable renderer.
|
//! serialized to pass it to a suitable renderer.
|
||||||
|
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use smallvec::smallvec;
|
|
||||||
|
|
||||||
use crate::diagnostic::Diagnostics;
|
use crate::diagnostic::Diagnostics;
|
||||||
use crate::font::SharedFontLoader;
|
use crate::font::SharedFontLoader;
|
||||||
@ -109,7 +108,7 @@ impl Typesetter {
|
|||||||
loader: &self.loader,
|
loader: &self.loader,
|
||||||
style: &self.style,
|
style: &self.style,
|
||||||
base: self.style.page.dimensions.unpadded(margins),
|
base: self.style.page.dimensions.unpadded(margins),
|
||||||
spaces: smallvec![LayoutSpace {
|
spaces: vec![LayoutSpace {
|
||||||
dimensions: self.style.page.dimensions,
|
dimensions: self.style.page.dimensions,
|
||||||
padding: margins,
|
padding: margins,
|
||||||
expansion: LayoutExpansion::new(true, true),
|
expansion: LayoutExpansion::new(true, true),
|
||||||
|
@ -1,14 +1,17 @@
|
|||||||
//! Decorations for semantic syntax highlighting.
|
//! Decorations for semantic syntax highlighting.
|
||||||
|
|
||||||
|
#[cfg(feature = "serialize")]
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use super::span::SpanVec;
|
use super::span::SpanVec;
|
||||||
|
|
||||||
/// A list of spanned decorations.
|
/// A list of spanned decorations.
|
||||||
pub type Decorations = SpanVec<Decoration>;
|
pub type Decorations = SpanVec<Decoration>;
|
||||||
|
|
||||||
/// Decorations for semantic syntax highlighting.
|
/// Decorations for semantic syntax highlighting.
|
||||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Serialize)]
|
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[cfg_attr(feature = "serialize", derive(Serialize))]
|
||||||
|
#[cfg_attr(feature = "serialize", serde(rename_all = "camelCase"))]
|
||||||
pub enum Decoration {
|
pub enum Decoration {
|
||||||
/// A valid function name.
|
/// A valid function name.
|
||||||
/// ```typst
|
/// ```typst
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
use std::fmt::{self, Debug, Formatter};
|
use std::fmt::{self, Debug, Formatter};
|
||||||
use std::ops::{Add, Sub};
|
use std::ops::{Add, Sub};
|
||||||
|
|
||||||
|
#[cfg(feature = "serialize")]
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
/// Span offsetting.
|
/// Span offsetting.
|
||||||
@ -23,7 +25,8 @@ impl<T> Offset for SpanVec<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A value with the span it corresponds to in the source code.
|
/// A value with the span it corresponds to in the source code.
|
||||||
#[derive(Copy, Clone, Eq, PartialEq, Hash, Serialize)]
|
#[derive(Copy, Clone, Eq, PartialEq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serialize", derive(Serialize))]
|
||||||
pub struct Spanned<T> {
|
pub struct Spanned<T> {
|
||||||
/// The value.
|
/// The value.
|
||||||
pub v: T,
|
pub v: T,
|
||||||
@ -77,7 +80,8 @@ impl<T: Debug> Debug for Spanned<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Locates a slice of source code.
|
/// Locates a slice of source code.
|
||||||
#[derive(Copy, Clone, Eq, PartialEq, Hash, Serialize)]
|
#[derive(Copy, Clone, Eq, PartialEq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serialize", derive(Serialize))]
|
||||||
pub struct Span {
|
pub struct Span {
|
||||||
/// The inclusive start position.
|
/// The inclusive start position.
|
||||||
pub start: Pos,
|
pub start: Pos,
|
||||||
@ -129,7 +133,8 @@ impl Debug for Span {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Zero-indexed line-column position in source code.
|
/// Zero-indexed line-column position in source code.
|
||||||
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize)]
|
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
||||||
|
#[cfg_attr(feature = "serialize", derive(Serialize))]
|
||||||
pub struct Pos {
|
pub struct Pos {
|
||||||
/// The zero-indexed line.
|
/// The zero-indexed line.
|
||||||
pub line: usize,
|
pub line: usize,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user