This commit is contained in:
Breval Ferrari 2025-04-15 19:00:52 -04:00
parent f207ac0b06
commit ab294950b4
Signed by: breval
GPG key ID: A2EEBF62257FF960
3 changed files with 47 additions and 0 deletions

2
bingus/src/fnt.rs Normal file
View file

@ -0,0 +1,2 @@
mod fontkit;
pub use fontkit::Font;

42
bingus/src/fnt/fontkit.rs Normal file
View file

@ -0,0 +1,42 @@
use font_kit::error::FontLoadingError;
pub use font_kit::font::Font;
use std::sync::Arc;
use crate::{Bendable, IntoDataBytes, TryFromDataBytes};
impl TryFromDataBytes for Font {
type Error = FontLoadingError;
type Format = ();
fn try_from_data_bytes(
bytes: crate::Bytes,
_format: Self::Format,
_crop: crate::Crop,
) -> Result<Self, Self::Error>
where
Self: Sized,
{
Self::from_bytes(Arc::new(bytes), 0)
}
}
impl IntoDataBytes for Font {
fn into_data_bytes(self) -> crate::Bytes {
self.copy_font_data()
.map(|v| v.as_ref().clone())
.unwrap_or_default()
}
}
impl Bendable for Font {
type Unit = u8;
fn map<F: Fn(&Self::Unit) -> Self::Unit + Sync>(self, f: F) -> Self {
Self::try_from_data_bytes(self.into_data_bytes().map(f), (), Default::default())
.expect("coudn't get font back from bytes after map")
}
fn format() -> crate::Format {
crate::Format::Font
}
}

View file

@ -1,5 +1,6 @@
pub mod bin;
pub mod doc;
pub mod fnt;
pub mod img;
pub mod snd;
pub mod txt;
@ -15,6 +16,7 @@ mod dynamic {
};
use super::{
fnt::Font,
img::{self, DynamicImage},
snd::{self, Audio},
txt::{ShivaDocument, Text},
@ -37,6 +39,7 @@ mod dynamic {
Doc(ShivaDocument),
Archive(PdfDocument),
Meta,
Font(Font),
}
#[derive(Debug, Error)]