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:
Laurenz 2019-02-17 00:08:46 +01:00
parent 6214405766
commit c8d3ea89cd
5 changed files with 26 additions and 22 deletions

View File

@ -1,5 +1,7 @@
//! Generation of abstract documents from syntax trees. //! Generation of abstract documents from syntax trees.
#![allow(dead_code)]
use std::fmt; use std::fmt;
use crate::parsing::{SyntaxTree, Node}; use crate::parsing::{SyntaxTree, Node};
@ -39,7 +41,7 @@ pub struct Text(pub String);
#[derive(Debug, Copy, Clone, PartialEq)] #[derive(Debug, Copy, Clone, PartialEq)]
pub struct Size { pub struct Size {
/// The size in typographic points (1/72 inches). /// The size in typographic points (1/72 inches).
pub points: f32, points: f32,
} }
impl Size { impl Size {
@ -112,7 +114,7 @@ type GenResult<T> = std::result::Result<T, GenerationError>;
#[derive(Debug, Clone, Eq, PartialEq)] #[derive(Debug, Clone, Eq, PartialEq)]
pub struct GenerationError { pub struct GenerationError {
/// A message describing the error. /// A message describing the error.
pub message: String, message: String,
} }
impl fmt::Display for GenerationError { impl fmt::Display for GenerationError {

View File

@ -1,10 +1,13 @@
//! Typeset is a library for compiling _plain-text_ strings written in the //! Typeset is a library for compiling documents written in the
//! corresponding typesetting language into a typesetted document in a //! corresponding typesetting language into a typesetted document in an
//! file format like _PDF_. //! output format like _PDF_.
#![allow(unused)]
mod pdf;
mod utility;
pub mod parsing; pub mod parsing;
pub mod doc; pub mod doc;
pub mod pdf;
pub mod utility; /// Writing of documents into supported formats.
pub mod export {
pub use crate::pdf::WritePdf;
}

View File

@ -322,7 +322,7 @@ type ParseResult<T> = std::result::Result<T, ParseError>;
#[derive(Debug, Clone, Eq, PartialEq)] #[derive(Debug, Clone, Eq, PartialEq)]
pub struct ParseError { pub struct ParseError {
/// A message describing the error. /// A message describing the error.
pub message: String, message: String,
} }
impl fmt::Display for ParseError { impl fmt::Display for ParseError {
@ -590,7 +590,7 @@ mod token_tests {
#[cfg(test)] #[cfg(test)]
mod parse_tests { mod parse_tests {
use super::*; 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. /// Test if the source code parses into the syntax tree.
fn test(src: &str, tree: SyntaxTree) { fn test(src: &str, tree: SyntaxTree) {

View File

@ -45,22 +45,22 @@ impl<W: Write> WritePdf<Document> for W {
kids: (pages_start .. pages_end).collect(), kids: (pages_start .. pages_end).collect(),
data: PageData { data: PageData {
resources: Some(vec![Resource::Font(1, font_start)]), resources: Some(vec![Resource::Font(1, font_start)]),
.. PageData::default() .. PageData::none()
}, },
})?; })?;
// The page objects // The page objects
let mut id = pages_start; let mut id = pages_start;
for page in &doc.pages { for page in &doc.pages {
let width = page.size[0].points; let width = page.size[0].to_points();
let height = page.size[1].points; let height = page.size[1].to_points();
writer.write_obj(id, &Page { writer.write_obj(id, &Page {
parent: page_tree_id, parent: page_tree_id,
data: PageData { data: PageData {
media_box: Some(Rect::new(0.0, 0.0, width, height)), media_box: Some(Rect::new(0.0, 0.0, width, height)),
contents: Some((content_start .. content_end).collect()), 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 { for content in &page.contents {
let string = &content.0; let string = &content.0;
let mut text = Text::new(); writer.write_obj(id, &Text::new()
text.set_font(1, 13.0) .set_font(1, 13.0)
.move_pos(108.0, 734.0) .move_pos(108.0, 734.0)
.write_str(&string); .write_str(&string)
.to_stream()
writer.write_obj(id, &text.as_stream())?; )?;
id += 1; id += 1;
} }
} }

View File

@ -12,8 +12,7 @@ pub trait Splinor {
/// ///
/// # Example /// # Example
/// ///
/// ``` /// ```ignore
/// # use typeset::utility::*;
/// #[derive(Debug, Copy, Clone, PartialEq)] /// #[derive(Debug, Copy, Clone, PartialEq)]
/// struct Space; /// struct Space;
/// ///