summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-03-24 21:48:25 +0100
committerLaurenz <laurmaedje@gmail.com>2021-03-24 21:48:25 +0100
commite8057a53856dc09594c9e5861f1cd328531616e0 (patch)
tree36d7ffe8dc0aee0ab2ab96b37c130a8835f48f06 /src
parent73615f7e3ce23f2ea656d04ea9f96184f5ebdc0a (diff)
Make pdf module top-level 🧱
Diffstat (limited to 'src')
-rw-r--r--src/export/mod.rs3
-rw-r--r--src/font.rs13
-rw-r--r--src/layout/shaping.rs16
-rw-r--r--src/lib.rs9
-rw-r--r--src/main.rs2
-rw-r--r--src/pdf/mod.rs (renamed from src/export/pdf.rs)8
6 files changed, 27 insertions, 24 deletions
diff --git a/src/export/mod.rs b/src/export/mod.rs
deleted file mode 100644
index 71b87b03..00000000
--- a/src/export/mod.rs
+++ /dev/null
@@ -1,3 +0,0 @@
-//! Exporting into external formats.
-
-pub mod pdf;
diff --git a/src/font.rs b/src/font.rs
index 78fc0d44..bcc64627 100644
--- a/src/font.rs
+++ b/src/font.rs
@@ -7,6 +7,7 @@ use fontdock::FaceFromVec;
/// An owned font face.
pub struct FaceBuf {
data: Box<[u8]>,
+ index: u32,
ttf: ttf_parser::Face<'static>,
buzz: rustybuzz::Face<'static>,
}
@@ -17,6 +18,11 @@ impl FaceBuf {
&self.data
}
+ /// The collection index.
+ pub fn index(&self) -> u32 {
+ self.index
+ }
+
/// Get a reference to the underlying ttf-parser face.
pub fn ttf(&self) -> &ttf_parser::Face<'_> {
// We can't implement Deref because that would leak the internal 'static
@@ -33,7 +39,7 @@ impl FaceBuf {
}
impl FaceFromVec for FaceBuf {
- fn from_vec(vec: Vec<u8>, i: u32) -> Option<Self> {
+ fn from_vec(vec: Vec<u8>, index: u32) -> Option<Self> {
let data = vec.into_boxed_slice();
// SAFETY: The slices's location is stable in memory since we don't
@@ -43,8 +49,9 @@ impl FaceFromVec for FaceBuf {
Some(Self {
data,
- ttf: ttf_parser::Face::from_slice(slice, i).ok()?,
- buzz: rustybuzz::Face::from_slice(slice, i)?,
+ index,
+ ttf: ttf_parser::Face::from_slice(slice, index).ok()?,
+ buzz: rustybuzz::Face::from_slice(slice, index)?,
})
}
}
diff --git a/src/layout/shaping.rs b/src/layout/shaping.rs
index f7eece92..8d035516 100644
--- a/src/layout/shaping.rs
+++ b/src/layout/shaping.rs
@@ -5,12 +5,12 @@ use ttf_parser::GlyphId;
use super::{Element, Frame, ShapedText};
use crate::env::FontLoader;
use crate::exec::FontProps;
-use crate::geom::{Length, Point, Size};
+use crate::geom::{Point, Size};
-/// Shape text into a frame containing shaped [`ShapedText`] runs.
+/// Shape text into a frame containing [`ShapedText`] runs.
pub fn shape(text: &str, loader: &mut FontLoader, props: &FontProps) -> Frame {
- let mut frame = Frame::new(Size::new(Length::ZERO, Length::ZERO));
- shape_segment(&mut frame, text, props.families.iter(), None, loader, props);
+ let mut frame = Frame::new(Size::ZERO);
+ shape_segment(&mut frame, text, loader, props, props.families.iter(), None);
frame
}
@@ -18,10 +18,10 @@ pub fn shape(text: &str, loader: &mut FontLoader, props: &FontProps) -> Frame {
fn shape_segment<'a>(
frame: &mut Frame,
text: &str,
- mut families: impl Iterator<Item = &'a str> + Clone,
- mut first: Option<FaceId>,
loader: &mut FontLoader,
props: &FontProps,
+ mut families: impl Iterator<Item = &'a str> + Clone,
+ mut first: Option<FaceId>,
) {
// Select the font family.
let (id, fallback) = loop {
@@ -41,12 +41,12 @@ fn shape_segment<'a>(
};
// Register that this is the first available font.
- let face = loader.face(id);
if first.is_none() {
first = Some(id);
}
// Find out some metrics and prepare the shaped text container.
+ let face = loader.face(id);
let ttf = face.ttf();
let units_per_em = f64::from(ttf.units_per_em().unwrap_or(1000));
let convert = |units| f64::from(units) / units_per_em * props.size;
@@ -104,7 +104,7 @@ fn shape_segment<'a>(
let range = start .. end + offset;
// Recursively shape the tofu sequence with the next family.
- shape_segment(frame, &text[range], families.clone(), first, loader, props);
+ shape_segment(frame, &text[range], loader, props, families.clone(), first);
} else {
// Add the glyph to the shaped output.
// TODO: Don't ignore y_advance and y_offset.
diff --git a/src/lib.rs b/src/lib.rs
index 20c69fe9..9e09a9b4 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -17,8 +17,7 @@
//! typeset document. The output of this is a collection of [`Frame`]s (one
//! per page), ready for exporting.
//! - **Exporting:** The finished layout can be exported into a supported
-//! format. Submodules for these formats are located in the [export] module.
-//! Currently, the only supported output format is [_PDF_].
+//! format. Currently, the only supported output format is [PDF].
//!
//! [tokens]: parse::Tokens
//! [parsed]: parse::parse
@@ -27,7 +26,7 @@
//! [execute]: exec::exec
//! [layout tree]: layout::Tree
//! [layouted]: layout::layout
-//! [_PDF_]: export::pdf
+//! [PDF]: pdf
#[macro_use]
pub mod diag;
@@ -36,13 +35,13 @@ pub mod eval;
pub mod color;
pub mod env;
pub mod exec;
-pub mod export;
pub mod font;
pub mod geom;
pub mod layout;
pub mod library;
pub mod paper;
pub mod parse;
+pub mod pdf;
pub mod pretty;
pub mod syntax;
@@ -52,7 +51,7 @@ use crate::eval::Scope;
use crate::exec::State;
use crate::layout::Frame;
-/// Process _Typst_ source code directly into a collection of frames.
+/// Process source code directly into a collection of frames.
pub fn typeset(
env: &mut Env,
src: &str,
diff --git a/src/main.rs b/src/main.rs
index 9d72440e..80990035 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -7,9 +7,9 @@ use fontdock::FsIndex;
use typst::diag::Pass;
use typst::env::{Env, FsIndexExt, ResourceLoader};
use typst::exec::State;
-use typst::export::pdf;
use typst::library;
use typst::parse::LineMap;
+use typst::pdf;
use typst::typeset;
fn main() -> anyhow::Result<()> {
diff --git a/src/export/pdf.rs b/src/pdf/mod.rs
index 1abe104d..a97dfa2c 100644
--- a/src/export/pdf.rs
+++ b/src/pdf/mod.rs
@@ -1,4 +1,4 @@
-//! Exporting into _PDF_ documents.
+//! Exporting into PDF documents.
use std::cmp::Eq;
use std::collections::HashMap;
@@ -18,13 +18,13 @@ use crate::env::{Env, ImageResource, ResourceId};
use crate::geom::{self, Length, Size};
use crate::layout::{Element, Fill, Frame, Image, Shape};
-/// Export a collection of frames into a _PDF_ document.
+/// Export a collection of frames into a PDF document.
///
/// This creates one page per frame. In addition to the frames, you need to pass
/// in the environment used for typesetting such that things like fonts and
-/// images can be included in the _PDF_.
+/// images can be included in the PDF.
///
-/// Returns the raw bytes making up the _PDF_ document.
+/// Returns the raw bytes making up the PDF document.
pub fn export(env: &Env, frames: &[Frame]) -> Vec<u8> {
PdfExporter::new(env, frames).write()
}