-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GlyphBrush::pixel_bounds
seems to return incorrect bounds
#68
Comments
GlyphBrush:.pixel_bounds
seems to return incorrect boundsGlyphBrush::pixel_bounds
seems to return incorrect bounds
This is why it has the 'pixel_' prefix, and relates closely to rusttype's |
It might be cool to have something like a Right now you can access this info using the |
I'm testing out this for layout-bound calculation: use glyph_brush::{rusttype::*, *};
use std::borrow::Cow;
pub trait ExtGlyphCruncher {
fn layout_bounds<'a, S>(&mut self, section: S) -> Option<Rect<f32>>
where
S: Into<Cow<'a, VariedSection<'a>>>;
}
impl<'font, T> ExtGlyphCruncher for T
where
T: GlyphCruncher<'font>,
{
#[inline]
fn layout_bounds<'a, S>(&mut self, section: S) -> Option<Rect<f32>>
where
S: Into<Cow<'a, VariedSection<'a>>>,
{
self.glyphs(section).fold(None, |b, glyph| {
if let Some(font) = glyph.font() {
let hm = glyph.unpositioned().h_metrics();
let vm = font.v_metrics(glyph.scale());
let pos = glyph.position();
let lbound = Rect {
min: point(pos.x - hm.left_side_bearing, pos.y - vm.ascent),
max: point(pos.x + hm.advance_width, pos.y - vm.descent),
};
b.map(|b| {
let min_x = b.min.x.min(lbound.min.x);
let max_x = b.max.x.max(lbound.max.x);
let min_y = b.min.y.min(lbound.min.y);
let max_y = b.max.y.max(lbound.max.y);
Rect { min: point(min_x, min_y), max: point(max_x, max_y) }
})
.or_else(|| Some(lbound))
} else {
b
}
})
}
} |
I see! My bad.
Right, I need this to measure text nodes when computing UI layout. I will give it a shot! It looks like we will need to use Oh, you just commented! 😅 🎉 I don't know much about |
Yeah I think it should work ok. Should work with any layout as it's glyph based. I'll have to add some benches to see how well it performs. It also needs decent docs, as the distinction could be confusing. I'll add this method when I get a chance, probably later on today. |
No hurries! Let me know if I can help. And thank you! :) |
Ok I've added this with 7c0eb23. I ended up calling it |
Amazing! Thank you again for your insanely quick support! |
No worries, I was kind of "in the area" anyway, just avoiding the issue. I'll make a new release tomorrow. |
I just wanted to say that I've implemented the fix on my end and it's working like a charm. Thank you! |
GlyphBrush::pixel_bounds
seems to return an incorrect result. I found about this when working on basic GUI support for Coffee. You can find more details in hecrj/coffee#43.Here is an SSCCE using
gfx_glyph
(full code):Which produces:
Is this a bug, or am I wrong when I assume the returned
pixel_bounds
should be compatible withSection::bounds
? I will investigate a bit and try to find the issue.The text was updated successfully, but these errors were encountered: