diff --git a/src/export/pdf.rs b/src/export/pdf.rs index b521079e..c3f67afa 100644 --- a/src/export/pdf.rs +++ b/src/export/pdf.rs @@ -10,7 +10,7 @@ use pdf::font::{GlyphUnit, CMap, CMapEncoding, WidthRecord, FontStream}; use crate::doc::{Document, Page as DocPage, TextAction}; use crate::font::{Font, FontError}; -use crate::layout::{Size, Position}; +use crate::layout::Size; /// Exports documents into _PDFs_. diff --git a/src/layout/mod.rs b/src/layout/mod.rs index ab27314d..1c1f743e 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -144,8 +144,8 @@ impl Default for PageStyle { /// The error type for layouting. pub enum LayoutError { - /// There was no suitable font. - NoSuitableFont, + /// There was no suitable font for the given character. + NoSuitableFont(char), /// An error occured while gathering font data. Font(FontError), } @@ -156,7 +156,7 @@ pub type LayoutResult = Result; error_type! { err: LayoutError, show: f => match err { - LayoutError::NoSuitableFont => write!(f, "no suitable font"), + LayoutError::NoSuitableFont(c) => write!(f, "no suitable font for '{}'", c), LayoutError::Font(err) => write!(f, "font error: {}", err), }, source: match err { diff --git a/src/layout/text.rs b/src/layout/text.rs index 11a1e38c..d1e2afd7 100644 --- a/src/layout/text.rs +++ b/src/layout/text.rs @@ -104,7 +104,7 @@ impl<'a, 'p> TextLayouter<'a, 'p> { italic: self.italic, bold: self.bold, character, - }).ok_or_else(|| LayoutError::NoSuitableFont) + }).ok_or_else(|| LayoutError::NoSuitableFont(character)) } /// The width of a char in a specific font. diff --git a/src/lib.rs b/src/lib.rs index c56cbba1..398df467 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,8 +26,8 @@ //! // (two sans-serif fonts and a fallback for the emoji). //! let mut typesetter = Typesetter::new(); //! typesetter.add_font_provider(FileSystemFontProvider::new("../fonts", vec![ -//! ("NotoSans-Regular.ttf", font_info!(["NotoSans", "Noto", SansSerif])), -//! ("NotoSans-Italic.ttf", font_info!(["NotoSans", "Noto", SansSerif], italic)), +//! ("CMU-SansSerif-Regular.ttf", font_info!(["Computer Modern", SansSerif])), +//! ("CMU-SansSerif-Italic.ttf", font_info!(["Computer Modern", SansSerif], italic)), //! ("NotoEmoji-Regular.ttf", font_info!(["NotoEmoji", "Noto", SansSerif, Serif, Monospace])), //! ])); //! @@ -202,12 +202,19 @@ mod test { fn test(name: &str, src: &str) { let mut typesetter = Typesetter::new(); typesetter.add_font_provider(FileSystemFontProvider::new("../fonts", vec![ - ("NotoSans-Regular.ttf", font_info!(["NotoSans", "Noto", SansSerif])), - ("NotoSans-Italic.ttf", font_info!(["NotoSans", "Noto", SansSerif], italic)), - ("NotoSans-Bold.ttf", font_info!(["NotoSans", "Noto", SansSerif], bold)), - ("NotoSans-BoldItalic.ttf", font_info!(["NotoSans", "Noto", SansSerif], italic, bold)), - ("NotoSansMath-Regular.ttf", font_info!(["NotoSansMath", "Noto", SansSerif])), - ("NotoEmoji-Regular.ttf", font_info!(["NotoEmoji", "Noto", SansSerif, Serif, Monospace])), + ("CMU-SansSerif-Regular.ttf", font_info!(["Computer Modern", SansSerif])), + ("CMU-SansSerif-Italic.ttf", font_info!(["Computer Modern", SansSerif], italic)), + ("CMU-SansSerif-Bold.ttf", font_info!(["Computer Modern", SansSerif], bold)), + ("CMU-SansSerif-Bold-Italic.ttf", font_info!(["Computer Modern", SansSerif], bold, italic)), + ("CMU-Serif-Regular.ttf", font_info!(["Computer Modern", Serif])), + ("CMU-Serif-Italic.ttf", font_info!(["Computer Modern", Serif], italic)), + ("CMU-Serif-Bold.ttf", font_info!(["Computer Modern", Serif], bold)), + ("CMU-Serif-Bold-Italic.ttf", font_info!(["Computer Modern", Serif], bold, italic)), + ("CMU-Typewriter-Regular.ttf", font_info!(["Computer Modern", Monospace])), + ("CMU-Typewriter-Italic.ttf", font_info!(["Computer Modern", Monospace], italic)), + ("CMU-Typewriter-Bold.ttf", font_info!(["Computer Modern", Monospace], bold)), + ("CMU-Typewriter-Bold-Italic.ttf", font_info!(["Computer Modern", Monospace], bold, italic)), + ("NotoEmoji-Regular.ttf", font_info!(["NotoEmoji", "Noto", SansSerif, Serif, Monospace])), ])); // Typeset into document. @@ -225,21 +232,15 @@ mod test { test("features", r" **FEATURES TEST PAGE** - __Simple multiline:__ + __Multiline:__ Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est. - __Parentheses:__ Text with ) and ( or (enclosed) works. + __Emoji:__ Hello World! 🌍 - __Composite character:__ ‼ - - __Unicode:__ ∑mbe∂∂ed font with Unicode! - - __Emoji:__ Hello World 🌍! - - __Styles:__ This is **bold** and that is __great__! + __Styles:__ This is **bold** and that is __italic__! "); }