Center line around its bounding box

This commit is contained in:
Antonio Scandurra 2021-03-25 17:21:26 +01:00
parent 4dc1b1e179
commit 466f6e0479
3 changed files with 8 additions and 6 deletions

View File

@ -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;

View File

@ -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(),

View File

@ -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,
});
}