bdf_reader/
lib.rs

1#![allow(clippy::tabs_in_doc_comments)]
2#![warn(rust_2018_idioms)]
3#![deny(unreachable_pub)]
4#![forbid(elided_lifetimes_in_paths, unsafe_code)]
5
6//! # BDF Reader
7//!
8//! A reader for the BDF ([Glyph Bitmap Distribution Format][wikipedia]) font format.
9//!
10//! ## Example
11//!
12//! ```rust,edition2021,no_run
13//! use bdf_reader::Font;
14//! use std::{fs::File, io::BufReader};
15//!
16//! # fn main() -> anyhow::Result<()> {
17//! let reader = BufReader::new(File::open("path/to/font.bdf")?);
18//! let font = Font::read(reader)?;
19//! # Ok(()) }
20//! ```
21//!
22//!  [wikipedia]: https://en.wikipedia.org/wiki/Glyph_Bitmap_Distribution_Format
23
24use std::{io, str::FromStr};
25use thiserror::Error;
26
27mod bitmap;
28mod font;
29mod reader;
30mod tokens;
31
32pub use bitmap::Bitmap;
33pub use font::{BoundingBox, Font, Glyph, Size, Value};
34use reader::State;
35use tokens::Token;
36
37#[derive(Debug, Error)]
38pub enum Error {
39	#[error("I/O Error: {0}")]
40	IOError(#[from] io::Error),
41
42	#[error("Syntax Error: {0}")]
43	SyntaxError(#[from] tokens::Error),
44
45	#[error("The token {0:?} may only appear in {2:?}, but is in {1:?}")]
46	InvalidContext(Token, State, &'static str),
47
48	#[error("Unexpected end of context {0}")]
49	UnexpectedEnd(&'static str),
50
51	#[error("Missing font name")]
52	MissingFontName,
53
54	#[error("Missing font size")]
55	MissingFontSize,
56
57	#[error("Missing font bounding box")]
58	MissingFontBoundingBox,
59
60	#[error("Missing glyph encoding")]
61	MissingGlyphEncoding,
62
63	#[error("Missing glyph bounding box")]
64	MissingGlyphBoundingBox,
65
66	#[error("Invalid Property Value: {0}. Note that strings need to be quoted.")]
67	InvalidPropertyValue(#[source] <i32 as FromStr>::Err),
68
69	#[error("Invalid bitmap value: {0}")]
70	InvalidBitmapValue(String)
71}