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};
|
use std::{rc::Rc, sync::Arc};
|
||||||
|
|
||||||
pub use layout::{Alignment, FontStyle, Layout, LayoutJob};
|
pub use layout::{Alignment, FontStyle, Layout, LayoutJob, LayoutToLogical};
|
||||||
|
|
||||||
mod atlas;
|
mod atlas;
|
||||||
mod glyph_key;
|
mod glyph_key;
|
||||||
|
|||||||
+10
-4
@@ -1,11 +1,19 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
color::Srgba,
|
color::Srgba,
|
||||||
dpi::{LogicalPoint, LogicalRect},
|
dpi::{LogicalPoint, LogicalScreenSpace},
|
||||||
|
math::{Rect, Translation},
|
||||||
uv::UvRect,
|
uv::UvRect,
|
||||||
};
|
};
|
||||||
use ordered_float::OrderedFloat;
|
use ordered_float::OrderedFloat;
|
||||||
use parley::{FontFamily, FontFamilyName};
|
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)]
|
#[derive(Copy, Clone, Default, Debug, Hash, PartialEq)]
|
||||||
pub enum Alignment {
|
pub enum Alignment {
|
||||||
#[default]
|
#[default]
|
||||||
@@ -104,9 +112,7 @@ impl std::hash::Hash for LayoutJob<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct PositionedGlyph {
|
pub struct PositionedGlyph {
|
||||||
// relative to layout origin
|
pub rect: LayoutRect<f32>,
|
||||||
// TODO: introduce new "layout space"?
|
|
||||||
pub rect: LogicalRect<f32>,
|
|
||||||
pub uv: UvRect,
|
pub uv: UvRect,
|
||||||
pub layer_idx: u32,
|
pub layer_idx: u32,
|
||||||
pub color: Srgba,
|
pub color: Srgba,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
color::Srgba,
|
color::Srgba,
|
||||||
dpi::{LogicalRect, LogicalVector, PhysicalPoint, PhysicalRect, PhysicalVector, ScaleFactor},
|
dpi::{LogicalVector, PhysicalPoint, PhysicalRect, PhysicalVector, ScaleFactor},
|
||||||
fonts::{atlas::FontAtlas, glyph_key::GlyphKey},
|
fonts::{atlas::FontAtlas, glyph_key::GlyphKey, layout::LayoutRect},
|
||||||
math::Size,
|
math::Size,
|
||||||
uv::UvRect,
|
uv::UvRect,
|
||||||
};
|
};
|
||||||
@@ -57,8 +57,7 @@ pub struct CachedGlyph {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct RasterizedGlyph {
|
pub struct RasterizedGlyph {
|
||||||
// NOTE: this is relative to the layout origin
|
pub rect: LayoutRect<f32>,
|
||||||
pub rect: LogicalRect<f32>,
|
|
||||||
pub uv: UvRect,
|
pub uv: UvRect,
|
||||||
pub texture_layer_idx: u32,
|
pub texture_layer_idx: u32,
|
||||||
pub color: Srgba,
|
pub color: Srgba,
|
||||||
@@ -77,7 +76,8 @@ impl RasterizedGlyph {
|
|||||||
);
|
);
|
||||||
|
|
||||||
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,
|
uv: cached.uv,
|
||||||
texture_layer_idx: cached.texture_layer_idx,
|
texture_layer_idx: cached.texture_layer_idx,
|
||||||
color,
|
color,
|
||||||
|
|||||||
+4
-2
@@ -3,7 +3,7 @@ use crate::{
|
|||||||
color::Srgba,
|
color::Srgba,
|
||||||
dpi::{LogicalPoint, LogicalRect},
|
dpi::{LogicalPoint, LogicalRect},
|
||||||
draw_commands::DrawCommand,
|
draw_commands::DrawCommand,
|
||||||
fonts::{Alignment, FontStyle, Fonts, LayoutJob},
|
fonts::{Alignment, FontStyle, Fonts, LayoutJob, LayoutToLogical},
|
||||||
installer::download::{
|
installer::download::{
|
||||||
DownloadEvent, ExtractionRule, build_client, download_and_extract_tarball,
|
DownloadEvent, ExtractionRule, build_client, download_and_extract_tarball,
|
||||||
download_file_to_disk, fetch_file_contents,
|
download_file_to_disk, fetch_file_contents,
|
||||||
@@ -144,7 +144,9 @@ impl Installer {
|
|||||||
.layout(job, self.window_state.scale_factor());
|
.layout(job, self.window_state.scale_factor());
|
||||||
for glyph in &layout.glyphs {
|
for glyph in &layout.glyphs {
|
||||||
draw_commands.push(DrawCommand {
|
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(),
|
uvs: glyph.uv.into(),
|
||||||
color: glyph.color,
|
color: glyph.color,
|
||||||
// font atlas always lives at default texture ID
|
// 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::Point2D as Point;
|
||||||
pub use euclid::Scale;
|
pub use euclid::Scale;
|
||||||
pub use euclid::Size2D as Size;
|
pub use euclid::Size2D as Size;
|
||||||
|
pub use euclid::Translation2D as Translation;
|
||||||
pub use euclid::Vector2D as Vector;
|
pub use euclid::Vector2D as Vector;
|
||||||
pub use quad::Quad;
|
pub use quad::Quad;
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
color::Srgba,
|
color::Srgba,
|
||||||
dpi::LogicalPoint,
|
dpi::LogicalPoint,
|
||||||
fonts::{Alignment, FontStyle, LayoutJob},
|
fonts::{Alignment, FontStyle, LayoutJob, LayoutToLogical},
|
||||||
math::{Point, Quad, Rect, Size},
|
math::{Point, Quad, Rect, Size},
|
||||||
pob::Context,
|
pob::{Context, api::image_handle::image_handle_texture_id},
|
||||||
pob::api::image_handle::image_handle_texture_id,
|
|
||||||
};
|
};
|
||||||
use core::ffi::c_int;
|
use core::ffi::c_int;
|
||||||
use mlua::{
|
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);
|
let layout = ctx.fonts.borrow_mut().layout(job, scale_factor);
|
||||||
for glyph in &layout.glyphs {
|
for glyph in &layout.glyphs {
|
||||||
ctx.recorder.draw_glyph(
|
ctx.recorder.draw_glyph(
|
||||||
glyph.rect.translate(position.to_vector()),
|
LayoutToLogical::new(position.x, position.y).transform_box(&glyph.rect),
|
||||||
glyph.uv,
|
glyph.uv,
|
||||||
glyph.color,
|
glyph.color,
|
||||||
glyph.layer_idx,
|
glyph.layer_idx,
|
||||||
|
|||||||
Reference in new issue
Block a user