Introduce new coordinate space for glyph positions within a layout

This commit is contained in:
meehl committed 2026-08-25 12:11:49 +02:00
1 parent 7b925876a5
commit a50ea4cdaf
6 files changed
+24 -16

No files matched your search

+10 -4
View File
@@ -1,11 +1,19 @@
use crate::{
color::Srgba,
dpi::{LogicalPoint, LogicalRect},
dpi::{LogicalPoint, LogicalScreenSpace},
math::{Rect, Translation},
uv::UvRect,
};
use ordered_float::OrderedFloat;
use parley::{FontFamily, FontFamilyName};
// All coordinates relative to layout origin
pub struct LayoutSpace;
pub type LayoutRect<T> = Rect<T, LayoutSpace>;
pub type LayoutToLogical = Translation<f32, LayoutSpace, LogicalScreenSpace>;
#[derive(Copy, Clone, Default, Debug, Hash, PartialEq)]
pub enum Alignment {
#[default]
@@ -104,9 +112,7 @@ impl std::hash::Hash for LayoutJob<'_> {
}
pub struct PositionedGlyph {
// relative to layout origin
// TODO: introduce new "layout space"?
pub rect: LogicalRect<f32>,
pub rect: LayoutRect<f32>,
pub uv: UvRect,
pub layer_idx: u32,
pub color: Srgba,
+5 -5
View File
@@ -1,7 +1,7 @@
use crate::{
color::Srgba,
dpi::{LogicalRect, LogicalVector, PhysicalPoint, PhysicalRect, PhysicalVector, ScaleFactor},
fonts::{atlas::FontAtlas, glyph_key::GlyphKey},
dpi::{LogicalVector, PhysicalPoint, PhysicalRect, PhysicalVector, ScaleFactor},
fonts::{atlas::FontAtlas, glyph_key::GlyphKey, layout::LayoutRect},
math::Size,
uv::UvRect,
};
@@ -57,8 +57,7 @@ pub struct CachedGlyph {
}
pub struct RasterizedGlyph {
// NOTE: this is relative to the layout origin
pub rect: LogicalRect<f32>,
pub rect: LayoutRect<f32>,
pub uv: UvRect,
pub texture_layer_idx: u32,
pub color: Srgba,
@@ -77,7 +76,8 @@ impl RasterizedGlyph {
);
RasterizedGlyph {
rect: glyph_rect.cast() / scale_factor,
// TODO: store sizes instead of rects
rect: (glyph_rect.cast() / scale_factor).cast_unit(),
uv: cached.uv,
texture_layer_idx: cached.texture_layer_idx,
color,