alexheretic / glyph-brush

Fast GPU cached text rendering
Apache License 2.0
688 stars 52 forks source link

`glyphs` method not skip space char #112

Closed M-Adoo closed 4 years ago

M-Adoo commented 4 years ago

I try to use glyphs to get how many char will be drawable, but found invisible glyphs also returned. Does this is a bug, or that is what your expect ?

let sec = Section::default().add_text(Text::new("Nice to meet you!"));
let count = brush.glyphs().count():

Get count 17, not 14.

alexheretic commented 4 years ago

Yep that is expected. See layout/CHANGELOG.md. I've now also included this in glyph_brush's changelog (c3ef50b3ec14ac22bf9ea8bac3cd69a149c60974).

M-Adoo commented 4 years ago

Thank you for your quick response,it's seems there isn's public api to know if a glyph will drawable ? I want know how many glyphs will be drawn.

alexheretic commented 4 years ago

That isn't provided by glyph_brush no. In general a glyph is drawable if it has an outline, so outlining the glyph determines this, which isn't super cheap (part of the reason it's no longer used to layout text).

You could:

It's technically possible that after running cache_queued glyph_brush could have something like brush.was_cached(font_id: FontId, glyph: &Glyph) -> bool method. false meaning either it wasn't queued at all, or it's a glyph that's invisible. This would be pretty fast. Would that be helpful?

M-Adoo commented 4 years ago

Yes, brush.was_cached is what I want.

alexheretic commented 4 years ago

Cool let me know if #113 looks ok to you. I went with ~is_cached~ is_draw_cached, as it seemed better.

M-Adoo commented 4 years ago

Great! It's work for me.