fonts
This commit is contained in:
parent
f207ac0b06
commit
ab294950b4
3 changed files with 47 additions and 0 deletions
2
bingus/src/fnt.rs
Normal file
2
bingus/src/fnt.rs
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
mod fontkit;
|
||||||
|
pub use fontkit::Font;
|
42
bingus/src/fnt/fontkit.rs
Normal file
42
bingus/src/fnt/fontkit.rs
Normal 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
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
pub mod bin;
|
pub mod bin;
|
||||||
pub mod doc;
|
pub mod doc;
|
||||||
|
pub mod fnt;
|
||||||
pub mod img;
|
pub mod img;
|
||||||
pub mod snd;
|
pub mod snd;
|
||||||
pub mod txt;
|
pub mod txt;
|
||||||
|
@ -15,6 +16,7 @@ mod dynamic {
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
|
fnt::Font,
|
||||||
img::{self, DynamicImage},
|
img::{self, DynamicImage},
|
||||||
snd::{self, Audio},
|
snd::{self, Audio},
|
||||||
txt::{ShivaDocument, Text},
|
txt::{ShivaDocument, Text},
|
||||||
|
@ -37,6 +39,7 @@ mod dynamic {
|
||||||
Doc(ShivaDocument),
|
Doc(ShivaDocument),
|
||||||
Archive(PdfDocument),
|
Archive(PdfDocument),
|
||||||
Meta,
|
Meta,
|
||||||
|
Font(Font),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue