diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-03-24 17:12:34 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-03-24 17:12:34 +0100 |
| commit | 73615f7e3ce23f2ea656d04ea9f96184f5ebdc0a (patch) | |
| tree | 7691b792e1e4b33469a72c40fc76854f1de0814e /src/env.rs | |
| parent | 6720520ec06dd0718f81049b2b11e81664f7ef62 (diff) | |
Text shaping 🚀
- Shapes text with rustybuzz
- Font fallback with family list
- Tofus are shown in the first font
Co-Authored-By: Martin <mhaug@live.de>
Diffstat (limited to 'src/env.rs')
| -rw-r--r-- | src/env.rs | 41 |
1 files changed, 3 insertions, 38 deletions
@@ -7,14 +7,15 @@ use std::fs; use std::io::Cursor; use std::path::{Path, PathBuf}; -use fontdock::{FaceFromVec, FaceId, FontSource}; +use fontdock::{FaceId, FontSource}; use image::io::Reader as ImageReader; use image::{DynamicImage, GenericImageView, ImageFormat}; -use ttf_parser::Face; #[cfg(feature = "fs")] use fontdock::{FsIndex, FsSource}; +use crate::font::FaceBuf; + /// Encapsulates all environment dependencies (fonts, resources). #[derive(Debug)] pub struct Env { @@ -47,42 +48,6 @@ impl Env { /// A font loader that is backed by a dynamic source. pub type FontLoader = fontdock::FontLoader<Box<dyn FontSource<Face = FaceBuf>>>; -/// An owned font face. -pub struct FaceBuf { - data: Box<[u8]>, - face: Face<'static>, -} - -impl FaceBuf { - /// Get a reference to the underlying face. - pub fn get(&self) -> &Face<'_> { - // We can't implement Deref because that would leak the internal 'static - // lifetime. - &self.face - } - - /// The raw face data. - pub fn data(&self) -> &[u8] { - &self.data - } -} - -impl FaceFromVec for FaceBuf { - fn from_vec(vec: Vec<u8>, i: u32) -> Option<Self> { - let data = vec.into_boxed_slice(); - - // SAFETY: The slices's location is stable in memory since we don't - // touch it and it can't be touched from outside this type. - let slice: &'static [u8] = - unsafe { std::slice::from_raw_parts(data.as_ptr(), data.len()) }; - - Some(Self { - data, - face: Face::from_slice(slice, i).ok()?, - }) - } -} - /// Simplify font loader construction from an [`FsIndex`]. #[cfg(feature = "fs")] pub trait FsIndexExt { |
