mirror of
https://github.com/typst/typst
synced 2025-05-13 12:36:23 +08:00
Enhance docs (i.a. with examples) 📝
- Complete examples for pdf and opentype crates - Removes allow-unused attributes and fixes their warnings - Various small improvements
This commit is contained in:
parent
6214405766
commit
c8d3ea89cd
@ -1,5 +1,7 @@
|
||||
//! Generation of abstract documents from syntax trees.
|
||||
|
||||
#![allow(dead_code)]
|
||||
|
||||
use std::fmt;
|
||||
use crate::parsing::{SyntaxTree, Node};
|
||||
|
||||
@ -39,7 +41,7 @@ pub struct Text(pub String);
|
||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
||||
pub struct Size {
|
||||
/// The size in typographic points (1/72 inches).
|
||||
pub points: f32,
|
||||
points: f32,
|
||||
}
|
||||
|
||||
impl Size {
|
||||
@ -112,7 +114,7 @@ type GenResult<T> = std::result::Result<T, GenerationError>;
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
pub struct GenerationError {
|
||||
/// A message describing the error.
|
||||
pub message: String,
|
||||
message: String,
|
||||
}
|
||||
|
||||
impl fmt::Display for GenerationError {
|
||||
|
17
src/lib.rs
17
src/lib.rs
@ -1,10 +1,13 @@
|
||||
//! Typeset is a library for compiling _plain-text_ strings written in the
|
||||
//! corresponding typesetting language into a typesetted document in a
|
||||
//! file format like _PDF_.
|
||||
|
||||
#![allow(unused)]
|
||||
//! Typeset is a library for compiling documents written in the
|
||||
//! corresponding typesetting language into a typesetted document in an
|
||||
//! output format like _PDF_.
|
||||
|
||||
mod pdf;
|
||||
mod utility;
|
||||
pub mod parsing;
|
||||
pub mod doc;
|
||||
pub mod pdf;
|
||||
pub mod utility;
|
||||
|
||||
/// Writing of documents into supported formats.
|
||||
pub mod export {
|
||||
pub use crate::pdf::WritePdf;
|
||||
}
|
||||
|
@ -322,7 +322,7 @@ type ParseResult<T> = std::result::Result<T, ParseError>;
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
pub struct ParseError {
|
||||
/// A message describing the error.
|
||||
pub message: String,
|
||||
message: String,
|
||||
}
|
||||
|
||||
impl fmt::Display for ParseError {
|
||||
@ -590,7 +590,7 @@ mod token_tests {
|
||||
#[cfg(test)]
|
||||
mod parse_tests {
|
||||
use super::*;
|
||||
use Node::{Space as S, Newline as N, Word as W, Func as F};
|
||||
use Node::{Space as S, Word as W, Func as F};
|
||||
|
||||
/// Test if the source code parses into the syntax tree.
|
||||
fn test(src: &str, tree: SyntaxTree) {
|
||||
|
18
src/pdf.rs
18
src/pdf.rs
@ -45,22 +45,22 @@ impl<W: Write> WritePdf<Document> for W {
|
||||
kids: (pages_start .. pages_end).collect(),
|
||||
data: PageData {
|
||||
resources: Some(vec![Resource::Font(1, font_start)]),
|
||||
.. PageData::default()
|
||||
.. PageData::none()
|
||||
},
|
||||
})?;
|
||||
|
||||
// The page objects
|
||||
let mut id = pages_start;
|
||||
for page in &doc.pages {
|
||||
let width = page.size[0].points;
|
||||
let height = page.size[1].points;
|
||||
let width = page.size[0].to_points();
|
||||
let height = page.size[1].to_points();
|
||||
|
||||
writer.write_obj(id, &Page {
|
||||
parent: page_tree_id,
|
||||
data: PageData {
|
||||
media_box: Some(Rect::new(0.0, 0.0, width, height)),
|
||||
contents: Some((content_start .. content_end).collect()),
|
||||
.. PageData::default()
|
||||
.. PageData::none()
|
||||
},
|
||||
})?;
|
||||
|
||||
@ -78,12 +78,12 @@ impl<W: Write> WritePdf<Document> for W {
|
||||
for content in &page.contents {
|
||||
let string = &content.0;
|
||||
|
||||
let mut text = Text::new();
|
||||
text.set_font(1, 13.0)
|
||||
writer.write_obj(id, &Text::new()
|
||||
.set_font(1, 13.0)
|
||||
.move_pos(108.0, 734.0)
|
||||
.write_str(&string);
|
||||
|
||||
writer.write_obj(id, &text.as_stream())?;
|
||||
.write_str(&string)
|
||||
.to_stream()
|
||||
)?;
|
||||
id += 1;
|
||||
}
|
||||
}
|
||||
|
@ -12,8 +12,7 @@ pub trait Splinor {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// # use typeset::utility::*;
|
||||
/// ```ignore
|
||||
/// #[derive(Debug, Copy, Clone, PartialEq)]
|
||||
/// struct Space;
|
||||
///
|
||||
|
Loading…
x
Reference in New Issue
Block a user