wip font stuff :p

This commit is contained in:
griffi-gh 2024-09-21 16:28:47 +02:00
parent 9dcdd26fdb
commit 70f7641214
6 changed files with 58 additions and 13 deletions

View file

@ -1,5 +1,6 @@
pub mod paint;
pub mod texture;
pub mod text;
use texture::TextureAtlas;

View file

@ -1,15 +1,16 @@
use std::{borrow::Cow, sync::Arc};
use fontdue::layout::{CoordinateSystem, Layout};
use crate::{paint::{
buffer::PaintBuffer,
command::PaintCommand,
}, Painter};
pub struct FontHandle(Arc<fontdue::Font>);
use crate::{
Painter,
paint::{
buffer::PaintBuffer,
command::PaintCommand,
},
};
pub struct TextChunk {
pub text: Cow<'static, str>,
pub font: FontHandle,
pub font: (),
pub size: f32,
}

View file

@ -1,9 +1,10 @@
use crate::{paint::{
buffer::PaintBuffer,
command::PaintCommand,
}, Painter};
//TODO: use generics instead
use crate::{
Painter,
paint::{
buffer::PaintBuffer,
command::PaintCommand,
},
};
pub struct PaintTransform {
pub transform: glam::Affine2,

2
hui-painter/src/text.rs Normal file
View file

@ -0,0 +1,2 @@
pub mod ftm;
pub mod font;

View file

View file

@ -0,0 +1,40 @@
use fontdue::layout::GlyphRasterConfig;
use hashbrown::HashMap;
use nohash_hasher::BuildNoHashHasher;
use crate::texture::{TextureAtlas, TextureHandle};
type FontId = u16;
#[derive(Clone, Copy)]
pub struct FontHandle(FontId);
/// Maps to the actual texture handle.
struct GlyphCacheItem {
handle: TextureHandle,
}
/// Map from raster config to glyph cache item.
///
/// Partitioned by font id in FtM :3
type PartitionKey = HashMap<GlyphRasterConfig, GlyphCacheItem>;
/// Manages glyph cache items in a texture atlas.
pub struct FontTextureManager {
partition: HashMap<FontId, PartitionKey, BuildNoHashHasher<FontId>>,
}
impl FontTextureManager {
/// Drop cached data for the specified font.
///
/// Panics:
/// - If the font handle is invalid.
/// - If any of the cached items are not found in the texture atlas or became invalid.\
/// This may happen if, for example, a different atlas is passed than the one used to allocate the items.
fn drop_font(&mut self, font: FontHandle, atlas: &mut TextureAtlas) {
let dump = self.partition.remove(&font.0).expect("Font handle is invalid");
for (_, item) in dump {
atlas.deallocate(item.handle);
}
}
}