mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Add more fonts 📜
This commit is contained in:
parent
3e9f42661e
commit
236ebab23a
@ -10,7 +10,7 @@ use pdf::font::{GlyphUnit, CMap, CMapEncoding, WidthRecord, FontStream};
|
|||||||
|
|
||||||
use crate::doc::{Document, Page as DocPage, TextAction};
|
use crate::doc::{Document, Page as DocPage, TextAction};
|
||||||
use crate::font::{Font, FontError};
|
use crate::font::{Font, FontError};
|
||||||
use crate::layout::{Size, Position};
|
use crate::layout::Size;
|
||||||
|
|
||||||
|
|
||||||
/// Exports documents into _PDFs_.
|
/// Exports documents into _PDFs_.
|
||||||
|
@ -144,8 +144,8 @@ impl Default for PageStyle {
|
|||||||
|
|
||||||
/// The error type for layouting.
|
/// The error type for layouting.
|
||||||
pub enum LayoutError {
|
pub enum LayoutError {
|
||||||
/// There was no suitable font.
|
/// There was no suitable font for the given character.
|
||||||
NoSuitableFont,
|
NoSuitableFont(char),
|
||||||
/// An error occured while gathering font data.
|
/// An error occured while gathering font data.
|
||||||
Font(FontError),
|
Font(FontError),
|
||||||
}
|
}
|
||||||
@ -156,7 +156,7 @@ pub type LayoutResult<T> = Result<T, LayoutError>;
|
|||||||
error_type! {
|
error_type! {
|
||||||
err: LayoutError,
|
err: LayoutError,
|
||||||
show: f => match err {
|
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),
|
LayoutError::Font(err) => write!(f, "font error: {}", err),
|
||||||
},
|
},
|
||||||
source: match err {
|
source: match err {
|
||||||
|
@ -104,7 +104,7 @@ impl<'a, 'p> TextLayouter<'a, 'p> {
|
|||||||
italic: self.italic,
|
italic: self.italic,
|
||||||
bold: self.bold,
|
bold: self.bold,
|
||||||
character,
|
character,
|
||||||
}).ok_or_else(|| LayoutError::NoSuitableFont)
|
}).ok_or_else(|| LayoutError::NoSuitableFont(character))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The width of a char in a specific font.
|
/// The width of a char in a specific font.
|
||||||
|
33
src/lib.rs
33
src/lib.rs
@ -26,8 +26,8 @@
|
|||||||
//! // (two sans-serif fonts and a fallback for the emoji).
|
//! // (two sans-serif fonts and a fallback for the emoji).
|
||||||
//! let mut typesetter = Typesetter::new();
|
//! let mut typesetter = Typesetter::new();
|
||||||
//! typesetter.add_font_provider(FileSystemFontProvider::new("../fonts", vec![
|
//! typesetter.add_font_provider(FileSystemFontProvider::new("../fonts", vec![
|
||||||
//! ("NotoSans-Regular.ttf", font_info!(["NotoSans", "Noto", SansSerif])),
|
//! ("CMU-SansSerif-Regular.ttf", font_info!(["Computer Modern", SansSerif])),
|
||||||
//! ("NotoSans-Italic.ttf", font_info!(["NotoSans", "Noto", SansSerif], italic)),
|
//! ("CMU-SansSerif-Italic.ttf", font_info!(["Computer Modern", SansSerif], italic)),
|
||||||
//! ("NotoEmoji-Regular.ttf", font_info!(["NotoEmoji", "Noto", SansSerif, Serif, Monospace])),
|
//! ("NotoEmoji-Regular.ttf", font_info!(["NotoEmoji", "Noto", SansSerif, Serif, Monospace])),
|
||||||
//! ]));
|
//! ]));
|
||||||
//!
|
//!
|
||||||
@ -202,11 +202,18 @@ mod test {
|
|||||||
fn test(name: &str, src: &str) {
|
fn test(name: &str, src: &str) {
|
||||||
let mut typesetter = Typesetter::new();
|
let mut typesetter = Typesetter::new();
|
||||||
typesetter.add_font_provider(FileSystemFontProvider::new("../fonts", vec![
|
typesetter.add_font_provider(FileSystemFontProvider::new("../fonts", vec![
|
||||||
("NotoSans-Regular.ttf", font_info!(["NotoSans", "Noto", SansSerif])),
|
("CMU-SansSerif-Regular.ttf", font_info!(["Computer Modern", SansSerif])),
|
||||||
("NotoSans-Italic.ttf", font_info!(["NotoSans", "Noto", SansSerif], italic)),
|
("CMU-SansSerif-Italic.ttf", font_info!(["Computer Modern", SansSerif], italic)),
|
||||||
("NotoSans-Bold.ttf", font_info!(["NotoSans", "Noto", SansSerif], bold)),
|
("CMU-SansSerif-Bold.ttf", font_info!(["Computer Modern", SansSerif], bold)),
|
||||||
("NotoSans-BoldItalic.ttf", font_info!(["NotoSans", "Noto", SansSerif], italic, bold)),
|
("CMU-SansSerif-Bold-Italic.ttf", font_info!(["Computer Modern", SansSerif], bold, italic)),
|
||||||
("NotoSansMath-Regular.ttf", font_info!(["NotoSansMath", "Noto", SansSerif])),
|
("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])),
|
("NotoEmoji-Regular.ttf", font_info!(["NotoEmoji", "Noto", SansSerif, Serif, Monospace])),
|
||||||
]));
|
]));
|
||||||
|
|
||||||
@ -225,21 +232,15 @@ mod test {
|
|||||||
test("features", r"
|
test("features", r"
|
||||||
**FEATURES TEST PAGE**
|
**FEATURES TEST PAGE**
|
||||||
|
|
||||||
__Simple multiline:__
|
__Multiline:__
|
||||||
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
|
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
|
||||||
eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam
|
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
|
voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet
|
||||||
clita kasd gubergren, no sea takimata sanctus est.
|
clita kasd gubergren, no sea takimata sanctus est.
|
||||||
|
|
||||||
__Parentheses:__ Text with ) and ( or (enclosed) works.
|
__Emoji:__ Hello World! 🌍
|
||||||
|
|
||||||
__Composite character:__ ‼
|
__Styles:__ This is **bold** and that is __italic__!
|
||||||
|
|
||||||
__Unicode:__ ∑mbe∂∂ed font with Unicode!
|
|
||||||
|
|
||||||
__Emoji:__ Hello World 🌍!
|
|
||||||
|
|
||||||
__Styles:__ This is **bold** and that is __great__!
|
|
||||||
");
|
");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user