Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions bdf-parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ use crate::parser::{Line, Lines};

/// BDF Font.
#[derive(Debug, Clone, PartialEq)]
pub struct BdfFont {
pub struct Font {
/// Font metadata.
pub metadata: Metadata,

/// Glyphs.
pub glyphs: Glyphs,
}

impl BdfFont {
impl Font {
/// Parses a BDF file.
pub fn parse(input: &str) -> Result<Self, ParserError> {
let mut lines = Lines::new(input);
Expand All @@ -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 })
}
}

Expand Down Expand Up @@ -143,7 +143,7 @@ mod tests {
#[track_caller]
pub(crate) fn assert_parser_error(input: &str, message: &str, line_number: Option<usize>) {
assert_eq!(
BdfFont::parse(input),
Font::parse(input),
Err(ParserError {
message: message.to_string(),
line_number,
Expand Down Expand Up @@ -183,7 +183,7 @@ mod tests {
ENDFONT
"#};

fn test_font(font: &BdfFont) {
fn test_font(font: &Font) {
assert_eq!(
font.metadata,
Metadata {
Expand Down Expand Up @@ -249,7 +249,7 @@ mod tests {

#[test]
fn parse_font() {
test_font(&BdfFont::parse(FONT).unwrap())
test_font(&Font::parse(FONT).unwrap())
}

#[test]
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -282,15 +282,15 @@ mod tests {
.collect();
let input = lines.join("\n");

test_font(&BdfFont::parse(&input).unwrap());
test_font(&Font::parse(&input).unwrap());
}

#[test]
fn parse_font_with_windows_line_endings() {
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]
Expand All @@ -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]
Expand Down
6 changes: 3 additions & 3 deletions bdf-parser/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -142,7 +142,7 @@ mod tests {
ENDFONT
"#};

BdfFont::parse(FONT).unwrap();
Font::parse(FONT).unwrap();
}

#[test]
Expand Down Expand Up @@ -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);
}
}
8 changes: 4 additions & 4 deletions eg-font-converter/src/eg_bdf_font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<u8, Msb0>,
glyphs: Vec<BdfGlyph>,
bounding_box: Rectangle,
}

impl EgBdfOutput {
pub(crate) fn new(font: Font) -> Result<Self> {
pub(crate) fn new(font: ConvertedFont) -> Result<Self> {
let mut data = BitVec::<u8, Msb0>::new();
let mut glyphs = Vec::new();
let bounding_box = bounding_box_to_rectangle(&font.bdf.metadata.bounding_box);
Expand Down Expand Up @@ -83,7 +83,7 @@ impl EgBdfOutput {
fn try_rust(&self) -> Result<String> {
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,
Expand Down
18 changes: 9 additions & 9 deletions eg-font-converter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -252,7 +252,7 @@ impl<'a> FontConverter<'a> {
self
}

fn convert(&self) -> Result<Font> {
fn convert(&self) -> Result<ConvertedFont> {
ensure!(
is_valid_identifier(&self.name),
"name is not a valid Rust identifier: {}",
Expand All @@ -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())?;

Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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,
Expand All @@ -411,7 +411,7 @@ struct Font {
pub strikethrough_thickness: u32,
}

impl Font {
impl ConvertedFont {
fn glyph_index(&self, c: char) -> Option<usize> {
// TODO: assumes unicode
let encoding = Encoding::Standard(c as u32);
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions eg-font-converter/src/mono_font.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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<BinaryColor>,
data: Vec<u8>,

Expand Down Expand Up @@ -207,7 +207,7 @@ impl MonoFontOutput {
}

/// Returns the BDF file.
pub fn bdf(&self) -> &ParserBdfFont {
pub fn bdf(&self) -> &Font {
&self.font.bdf
}

Expand Down
4 changes: 2 additions & 2 deletions tools/test-bdf-parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<PathBuf>> {
let mut files = Vec::new();
Expand Down Expand Up @@ -32,7 +32,7 @@ pub fn collect_font_files(dir: &Path) -> io::Result<Vec<PathBuf>> {
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(()),
Expand Down