Center line around its bounding box
This commit is contained in:
parent
4dc1b1e179
commit
466f6e0479
3 changed files with 8 additions and 6 deletions
|
@ -8,7 +8,7 @@ pub use font_cache::FontCache;
|
||||||
pub mod fonts;
|
pub mod fonts;
|
||||||
mod presenter;
|
mod presenter;
|
||||||
mod scene;
|
mod scene;
|
||||||
pub use scene::{Border, Scene};
|
pub use scene::{Border, Quad, Scene};
|
||||||
pub mod text_layout;
|
pub mod text_layout;
|
||||||
pub use text_layout::TextLayoutCache;
|
pub use text_layout::TextLayoutCache;
|
||||||
mod util;
|
mod util;
|
||||||
|
|
|
@ -112,7 +112,6 @@ impl SpriteCache {
|
||||||
// Snap sprite to pixel grid.
|
// Snap sprite to pixel grid.
|
||||||
let offset = glyph_bounds.origin().to_f32()
|
let offset = glyph_bounds.origin().to_f32()
|
||||||
- vec2f(target_position.x().fract(), target_position.y().fract());
|
- vec2f(target_position.x().fract(), target_position.y().fract());
|
||||||
|
|
||||||
Some(GlyphSprite {
|
Some(GlyphSprite {
|
||||||
atlas_id: atlasses.len() - 1,
|
atlas_id: atlasses.len() - 1,
|
||||||
atlas_origin: atlas_bounds.origin(),
|
atlas_origin: atlas_bounds.origin(),
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
color::ColorU,
|
color::ColorU,
|
||||||
fonts::{FontId, GlyphId},
|
fonts::{FontId, GlyphId},
|
||||||
geometry::rect::RectF,
|
geometry::{
|
||||||
|
rect::RectF,
|
||||||
|
vector::{vec2f, Vector2F},
|
||||||
|
},
|
||||||
platform, scene, PaintContext,
|
platform, scene, PaintContext,
|
||||||
};
|
};
|
||||||
use ordered_float::OrderedFloat;
|
use ordered_float::OrderedFloat;
|
||||||
use parking_lot::{Mutex, RwLock, RwLockUpgradableReadGuard};
|
use parking_lot::{Mutex, RwLock, RwLockUpgradableReadGuard};
|
||||||
use pathfinder_geometry::vector::Vector2F;
|
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
use std::{
|
use std::{
|
||||||
borrow::Borrow,
|
borrow::Borrow,
|
||||||
|
@ -185,9 +187,10 @@ impl Line {
|
||||||
|
|
||||||
for run in &self.runs {
|
for run in &self.runs {
|
||||||
let bounding_box = ctx.font_cache.bounding_box(run.font_id, self.font_size);
|
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();
|
let max_glyph_width = bounding_box.x();
|
||||||
for glyph in &run.glyphs {
|
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() {
|
if glyph_origin.x() + max_glyph_width < bounds.origin().x() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -208,7 +211,7 @@ impl Line {
|
||||||
font_id: run.font_id,
|
font_id: run.font_id,
|
||||||
font_size: self.font_size,
|
font_size: self.font_size,
|
||||||
id: glyph.id,
|
id: glyph.id,
|
||||||
origin: glyph_origin,
|
origin: glyph_origin + vec2f(0., bounding_box.y() / 2.),
|
||||||
color,
|
color,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue