From 466f6e0479f46b4d15b5dfe506ce22638c040669 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 25 Mar 2021 17:21:26 +0100 Subject: [PATCH] Center line around its bounding box --- gpui/src/lib.rs | 2 +- gpui/src/platform/mac/sprite_cache.rs | 1 - gpui/src/text_layout.rs | 11 +++++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/gpui/src/lib.rs b/gpui/src/lib.rs index 5d62d04edff5b04c8784713fb5ceee29bdbd9854..0a08438c9d6749b5c57af1c72ef9e2efe29a54fa 100644 --- a/gpui/src/lib.rs +++ b/gpui/src/lib.rs @@ -8,7 +8,7 @@ pub use font_cache::FontCache; pub mod fonts; mod presenter; mod scene; -pub use scene::{Border, Scene}; +pub use scene::{Border, Quad, Scene}; pub mod text_layout; pub use text_layout::TextLayoutCache; mod util; diff --git a/gpui/src/platform/mac/sprite_cache.rs b/gpui/src/platform/mac/sprite_cache.rs index 70012212a6a8e8a435ef0b1dafc1d7886e0d433f..3d718a25f08cd1e81e49e0f09ec3b7c0a73ee05c 100644 --- a/gpui/src/platform/mac/sprite_cache.rs +++ b/gpui/src/platform/mac/sprite_cache.rs @@ -112,7 +112,6 @@ impl SpriteCache { // Snap sprite to pixel grid. let offset = glyph_bounds.origin().to_f32() - vec2f(target_position.x().fract(), target_position.y().fract()); - Some(GlyphSprite { atlas_id: atlasses.len() - 1, atlas_origin: atlas_bounds.origin(), diff --git a/gpui/src/text_layout.rs b/gpui/src/text_layout.rs index 2c3ae12ff5f7a9902cbbd78b28f4def779d56a8f..e7d784b033144b92dbf80485cb9cc15b78ecb765 100644 --- a/gpui/src/text_layout.rs +++ b/gpui/src/text_layout.rs @@ -1,12 +1,14 @@ use crate::{ color::ColorU, fonts::{FontId, GlyphId}, - geometry::rect::RectF, + geometry::{ + rect::RectF, + vector::{vec2f, Vector2F}, + }, platform, scene, PaintContext, }; use ordered_float::OrderedFloat; use parking_lot::{Mutex, RwLock, RwLockUpgradableReadGuard}; -use pathfinder_geometry::vector::Vector2F; use smallvec::SmallVec; use std::{ borrow::Borrow, @@ -185,9 +187,10 @@ impl Line { for run in &self.runs { let bounding_box = ctx.font_cache.bounding_box(run.font_id, self.font_size); + let descent = ctx.font_cache.descent(run.font_id, self.font_size); let max_glyph_width = bounding_box.x(); for glyph in &run.glyphs { - let glyph_origin = bounds.origin() + glyph.position; + let glyph_origin = bounds.origin() + glyph.position - vec2f(0.0, descent); if glyph_origin.x() + max_glyph_width < bounds.origin().x() { continue; } @@ -208,7 +211,7 @@ impl Line { font_id: run.font_id, font_size: self.font_size, id: glyph.id, - origin: glyph_origin, + origin: glyph_origin + vec2f(0., bounding_box.y() / 2.), color, }); }