Skip to content

Commit

Permalink
Trying to add pcsenior font to embedded graphics
Browse files Browse the repository at this point in the history
  • Loading branch information
jackra1n committed Nov 21, 2023
1 parent f645704 commit 4c57614
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
Binary file added data/pcsenior.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/pcsenior.raw
Binary file not shown.
26 changes: 24 additions & 2 deletions src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ use linux_embedded_hal::I2cdev;
use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306, mode::BufferedGraphicsMode};
use display_interface::DisplayError;
use embedded_graphics::{
mono_font::{ascii, MonoTextStyleBuilder, MonoTextStyle},
image::ImageRaw,
mono_font::{ascii, MonoTextStyleBuilder, MonoFont, MonoTextStyle, DecorationDimensions, mapping::StrGlyphMapping},
pixelcolor::BinaryColor,
prelude::*,
text::Text
};
use profont::PROFONT_12_POINT;

const PROFONT12: MonoTextStyle<'_, BinaryColor> = MonoTextStyleBuilder::new()
const OLD_PROFONT12: MonoTextStyle<'_, BinaryColor> = MonoTextStyleBuilder::new()
.font(&PROFONT_12_POINT)
.text_color(BinaryColor::On)
.build();
Expand All @@ -24,6 +25,27 @@ const FONT_5X8: MonoTextStyle<'_, BinaryColor> = MonoTextStyleBuilder::new()
.text_color(BinaryColor::On)
.build();

const GLYPH_MAPPING: StrGlyphMapping = StrGlyphMapping::new(" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~°", '?' as usize - ' ' as usize);

const PCSENIOR12: MonoFont = MonoFont {
image: ImageRaw::new(
include_bytes!("../data/pcsenior.raw"),
192,
),
character_size: Size::new(12, 15),
character_spacing: 0,
baseline: 11,
underline: DecorationDimensions::new(13, 1),
strikethrough: DecorationDimensions::new(15 / 2, 1),
glyph_mapping: &GLYPH_MAPPING,
};

const PROFONT12: MonoTextStyle<'_, BinaryColor> = MonoTextStyleBuilder::new()
.font(&PCSENIOR12)
.text_color(BinaryColor::On)
.build();


type Display = Ssd1306<I2CInterface<I2cdev>, DisplaySize128x32, BufferedGraphicsMode<DisplaySize128x32>>;

pub struct PoeDisplay {
Expand Down

0 comments on commit 4c57614

Please sign in to comment.