diff options
| author | Laurenz <laurmaedje@gmail.com> | 2019-02-17 00:08:46 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2019-02-17 00:08:46 +0100 |
| commit | c8d3ea89cd5badd796d17e83f2fb292210161227 (patch) | |
| tree | 9430ef11c944a1fbd5e528015c1e7ac34cb7a2f7 | |
| parent | 6214405766fae4e54ce1c743780019c1b771d3c7 (diff) | |
Enhance docs (i.a. with examples) 📝
- Complete examples for pdf and opentype crates
- Removes allow-unused attributes and fixes their warnings
- Various small improvements
| -rw-r--r-- | src/doc.rs | 6 | ||||
| -rw-r--r-- | src/lib.rs | 17 | ||||
| -rw-r--r-- | src/parsing.rs | 4 | ||||
| -rw-r--r-- | src/pdf.rs | 18 | ||||
| -rw-r--r-- | src/utility.rs | 3 |
5 files changed, 26 insertions, 22 deletions
@@ -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 { @@ -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; +} diff --git a/src/parsing.rs b/src/parsing.rs index 5efa69e5..1ed1ed9d 100644 --- a/src/parsing.rs +++ b/src/parsing.rs @@ -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) { @@ -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; } } diff --git a/src/utility.rs b/src/utility.rs index 8304025d..a0e6a295 100644 --- a/src/utility.rs +++ b/src/utility.rs @@ -12,8 +12,7 @@ pub trait Splinor { /// /// # Example /// - /// ``` - /// # use typeset::utility::*; + /// ```ignore /// #[derive(Debug, Copy, Clone, PartialEq)] /// struct Space; /// |
