Introduce new coordinate space for glyph positions within a layout
This commit is contained in:
1 parent
7b925876a5
commit
a50ea4cdaf
6 files changed
+24
-16
No files matched your search
+1
-1
@@ -16,7 +16,7 @@ use parley::{
|
||||
};
|
||||
use std::{rc::Rc, sync::Arc};
|
||||
|
||||
pub use layout::{Alignment, FontStyle, Layout, LayoutJob};
|
||||
pub use layout::{Alignment, FontStyle, Layout, LayoutJob, LayoutToLogical};
|
||||
|
||||
mod atlas;
|
||||
mod glyph_key;
|
||||
|
||||
+10
-4
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
+4
-2
@@ -3,7 +3,7 @@ use crate::{
|
||||
color::Srgba,
|
||||
dpi::{LogicalPoint, LogicalRect},
|
||||
draw_commands::DrawCommand,
|
||||
fonts::{Alignment, FontStyle, Fonts, LayoutJob},
|
||||
fonts::{Alignment, FontStyle, Fonts, LayoutJob, LayoutToLogical},
|
||||
installer::download::{
|
||||
DownloadEvent, ExtractionRule, build_client, download_and_extract_tarball,
|
||||
download_file_to_disk, fetch_file_contents,
|
||||
@@ -144,7 +144,9 @@ impl Installer {
|
||||
.layout(job, self.window_state.scale_factor());
|
||||
for glyph in &layout.glyphs {
|
||||
draw_commands.push(DrawCommand {
|
||||
positions: glyph.rect.translate(pos.to_vector()).into(),
|
||||
positions: LayoutToLogical::new(pos.x, pos.y)
|
||||
.transform_box(&glyph.rect)
|
||||
.into(),
|
||||
uvs: glyph.uv.into(),
|
||||
color: glyph.color,
|
||||
// font atlas always lives at default texture ID
|
||||
|
||||
@@ -2,6 +2,7 @@ pub use euclid::Box2D as Rect;
|
||||
pub use euclid::Point2D as Point;
|
||||
pub use euclid::Scale;
|
||||
pub use euclid::Size2D as Size;
|
||||
pub use euclid::Translation2D as Translation;
|
||||
pub use euclid::Vector2D as Vector;
|
||||
pub use quad::Quad;
|
||||
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
use crate::{
|
||||
color::Srgba,
|
||||
dpi::LogicalPoint,
|
||||
fonts::{Alignment, FontStyle, LayoutJob},
|
||||
fonts::{Alignment, FontStyle, LayoutJob, LayoutToLogical},
|
||||
math::{Point, Quad, Rect, Size},
|
||||
pob::Context,
|
||||
pob::api::image_handle::image_handle_texture_id,
|
||||
pob::{Context, api::image_handle::image_handle_texture_id},
|
||||
};
|
||||
use core::ffi::c_int;
|
||||
use mlua::{
|
||||
@@ -363,7 +362,7 @@ unsafe extern "C-unwind" fn draw_string(state: *mut ffi::lua_State) -> c_int {
|
||||
let layout = ctx.fonts.borrow_mut().layout(job, scale_factor);
|
||||
for glyph in &layout.glyphs {
|
||||
ctx.recorder.draw_glyph(
|
||||
glyph.rect.translate(position.to_vector()),
|
||||
LayoutToLogical::new(position.x, position.y).transform_box(&glyph.rect),
|
||||
glyph.uv,
|
||||
glyph.color,
|
||||
glyph.layer_idx,
|
||||
|
||||
Reference in new issue
Block a user