diff --git a/bdf-parser/src/lib.rs b/bdf-parser/src/lib.rs index 4d87c6b..9829d72 100644 --- a/bdf-parser/src/lib.rs +++ b/bdf-parser/src/lib.rs @@ -18,7 +18,7 @@ use crate::parser::{Line, Lines}; /// BDF Font. #[derive(Debug, Clone, PartialEq)] -pub struct BdfFont { +pub struct Font { /// Font metadata. pub metadata: Metadata, @@ -26,7 +26,7 @@ pub struct BdfFont { pub glyphs: Glyphs, } -impl BdfFont { +impl Font { /// Parses a BDF file. pub fn parse(input: &str) -> Result { let mut lines = Lines::new(input); @@ -45,7 +45,7 @@ impl BdfFont { let metadata = Metadata::parse(&mut lines)?; let glyphs = Glyphs::parse(&mut lines, &metadata)?; - Ok(BdfFont { metadata, glyphs }) + Ok(Font { metadata, glyphs }) } } @@ -143,7 +143,7 @@ mod tests { #[track_caller] pub(crate) fn assert_parser_error(input: &str, message: &str, line_number: Option) { assert_eq!( - BdfFont::parse(input), + Font::parse(input), Err(ParserError { message: message.to_string(), line_number, @@ -183,7 +183,7 @@ mod tests { ENDFONT "#}; - fn test_font(font: &BdfFont) { + fn test_font(font: &Font) { assert_eq!( font.metadata, Metadata { @@ -249,7 +249,7 @@ mod tests { #[test] fn parse_font() { - test_font(&BdfFont::parse(FONT).unwrap()) + test_font(&Font::parse(FONT).unwrap()) } #[test] @@ -260,7 +260,7 @@ mod tests { .collect(); let input = lines.join("\n"); - test_font(&BdfFont::parse(&input).unwrap()); + test_font(&Font::parse(&input).unwrap()); } #[test] @@ -271,7 +271,7 @@ mod tests { .collect(); let input = lines.join("\n"); - test_font(&BdfFont::parse(&input).unwrap()); + test_font(&Font::parse(&input).unwrap()); } #[test] @@ -282,7 +282,7 @@ mod tests { .collect(); let input = lines.join("\n"); - test_font(&BdfFont::parse(&input).unwrap()); + test_font(&Font::parse(&input).unwrap()); } #[test] @@ -290,7 +290,7 @@ mod tests { let lines: Vec<_> = FONT.lines().collect(); let input = lines.join("\r\n"); - test_font(&BdfFont::parse(&input).unwrap()); + test_font(&Font::parse(&input).unwrap()); } #[test] @@ -313,7 +313,7 @@ mod tests { let lines: Vec<_> = std::iter::once("").chain(FONT.lines()).collect(); let input = lines.join("\n"); - test_font(&BdfFont::parse(&input).unwrap()); + test_font(&Font::parse(&input).unwrap()); } #[test] diff --git a/bdf-parser/src/metadata.rs b/bdf-parser/src/metadata.rs index c34eb55..45213ca 100644 --- a/bdf-parser/src/metadata.rs +++ b/bdf-parser/src/metadata.rs @@ -128,7 +128,7 @@ mod tests { use indoc::indoc; use super::*; - use crate::{tests::assert_parser_error, BdfFont}; + use crate::{tests::assert_parser_error, Font}; #[test] fn complete_metadata() { @@ -142,7 +142,7 @@ mod tests { ENDFONT "#}; - BdfFont::parse(FONT).unwrap(); + Font::parse(FONT).unwrap(); } #[test] @@ -197,7 +197,7 @@ mod tests { ENDFONT "#}; - let font = BdfFont::parse(FONT).unwrap(); + let font = Font::parse(FONT).unwrap(); assert_eq!(font.metadata.metrics_set, MetricsSet::Both); } } diff --git a/eg-font-converter/src/eg_bdf_font.rs b/eg-font-converter/src/eg_bdf_font.rs index 679f996..919f6a8 100644 --- a/eg-font-converter/src/eg_bdf_font.rs +++ b/eg-font-converter/src/eg_bdf_font.rs @@ -10,7 +10,7 @@ use embedded_graphics::{ }; use quote::{format_ident, quote}; -use crate::Font; +use crate::ConvertedFont; /// Converts a BDF bounding box into an embedded-graphics rectangle. pub fn bounding_box_to_rectangle(bounding_box: &BoundingBox) -> Rectangle { @@ -29,14 +29,14 @@ pub fn bounding_box_to_rectangle(bounding_box: &BoundingBox) -> Rectangle { /// [`eg-bdf`]: eg_bdf #[derive(Debug)] pub struct EgBdfOutput { - pub(crate) font: Font, + pub(crate) font: ConvertedFont, data: BitVec, glyphs: Vec, bounding_box: Rectangle, } impl EgBdfOutput { - pub(crate) fn new(font: Font) -> Result { + pub(crate) fn new(font: ConvertedFont) -> Result { let mut data = BitVec::::new(); let mut glyphs = Vec::new(); let bounding_box = bounding_box_to_rectangle(&font.bdf.metadata.bounding_box); @@ -83,7 +83,7 @@ impl EgBdfOutput { fn try_rust(&self) -> Result { let constant_name = format_ident!("{}", self.font.name); let data_file = self.font.data_file().to_string_lossy().to_string(); - let Font { + let ConvertedFont { replacement_character, ascent, descent, diff --git a/eg-font-converter/src/lib.rs b/eg-font-converter/src/lib.rs index a5a4c48..10cbc03 100644 --- a/eg-font-converter/src/lib.rs +++ b/eg-font-converter/src/lib.rs @@ -72,7 +72,7 @@ #![deny(unsafe_code)] use anyhow::{anyhow, ensure, Context, Result}; -use bdf_parser::{BdfFont as ParserBdfFont, Encoding, Glyph, Property}; +use bdf_parser::{Encoding, Font, Glyph, Property}; use embedded_graphics::mono_font::mapping::GlyphMapping; use std::{ collections::BTreeSet, @@ -252,7 +252,7 @@ impl<'a> FontConverter<'a> { self } - fn convert(&self) -> Result { + fn convert(&self) -> Result { ensure!( is_valid_identifier(&self.name), "name is not a valid Rust identifier: {}", @@ -265,9 +265,9 @@ impl<'a> FontConverter<'a> { .with_context(|| format!("couldn't read BDF file from {file:?}"))?; let str = String::from_utf8_lossy(&data); - ParserBdfFont::parse(&str) + Font::parse(&str) } - FileOrString::String(str) => ParserBdfFont::parse(str), + FileOrString::String(str) => Font::parse(str), } .with_context(|| "couldn't parse BDF file".to_string())?; @@ -328,7 +328,7 @@ impl<'a> FontConverter<'a> { let strikethrough_position = (ascent + descent) / 2; let strikethrough_thickness = 1; - let mut font = Font { + let mut font = ConvertedFont { bdf, name: self.name.clone(), file_stem: self.file_stem.clone(), @@ -389,8 +389,8 @@ fn is_valid_identifier(ident: &str) -> bool { } #[derive(Debug, PartialEq)] -struct Font { - pub bdf: ParserBdfFont, +struct ConvertedFont { + pub bdf: Font, pub name: String, pub file_stem: String, pub constant_visibility: Visibility, @@ -411,7 +411,7 @@ struct Font { pub strikethrough_thickness: u32, } -impl Font { +impl ConvertedFont { fn glyph_index(&self, c: char) -> Option { // TODO: assumes unicode let encoding = Encoding::Standard(c as u32); @@ -443,7 +443,7 @@ impl Font { } } -impl GlyphMapping for Font { +impl GlyphMapping for ConvertedFont { fn index(&self, c: char) -> usize { // TODO: assumes unicode let encoding = Encoding::Standard(c as u32); diff --git a/eg-font-converter/src/mono_font.rs b/eg-font-converter/src/mono_font.rs index 9603353..62cc934 100644 --- a/eg-font-converter/src/mono_font.rs +++ b/eg-font-converter/src/mono_font.rs @@ -1,7 +1,7 @@ use std::{fs, io, ops::RangeInclusive, path::Path}; use anyhow::{bail, Context, Result}; -use bdf_parser::{BdfFont as ParserBdfFont, Encoding, Glyph}; +use bdf_parser::{Encoding, Font, Glyph}; use eg_bdf::BdfTextStyle; use embedded_graphics::{ image::ImageRaw, @@ -13,12 +13,12 @@ use embedded_graphics::{ use embedded_graphics_simulator::{OutputSettings, SimulatorDisplay}; use quote::{format_ident, quote}; -use crate::{EgBdfOutput, Font}; +use crate::{ConvertedFont, EgBdfOutput}; /// Font conversion output for [`MonoFont`]. #[derive(Debug)] pub struct MonoFontOutput { - font: Font, + font: ConvertedFont, bitmap: SimulatorDisplay, data: Vec, @@ -207,7 +207,7 @@ impl MonoFontOutput { } /// Returns the BDF file. - pub fn bdf(&self) -> &ParserBdfFont { + pub fn bdf(&self) -> &Font { &self.font.bdf } diff --git a/tools/test-bdf-parser/src/lib.rs b/tools/test-bdf-parser/src/lib.rs index 4bba5b8..fa7b547 100644 --- a/tools/test-bdf-parser/src/lib.rs +++ b/tools/test-bdf-parser/src/lib.rs @@ -3,7 +3,7 @@ use std::{ path::{Path, PathBuf}, }; -use bdf_parser::*; +use bdf_parser::Font; pub fn collect_font_files(dir: &Path) -> io::Result> { let mut files = Vec::new(); @@ -32,7 +32,7 @@ pub fn collect_font_files(dir: &Path) -> io::Result> { pub fn test_font_parse(filepath: &Path) -> Result<(), String> { let bdf = std::fs::read(filepath).unwrap(); let str = String::from_utf8_lossy(&bdf); - let font = BdfFont::parse(&str); + let font = Font::parse(&str); match font { Ok(_font) => Ok(()),