Comments (5)
Something like this:
let mut section = Section {
text: "gŽ",
color: [0.0, 0.0, 0.0, 1.0],
scale: Scale::uniform(scale as f32),
bounds: (size.width as f32, size.height as f32),
..Section::default()
};
let pixel_bounds =
glyph_brush.pixel_bounds(section).expect("Pixel bounds");
section.screen_position = (
size.width as f32 * 0.5 - pixel_bounds.min.x as f32 * 0.5,
size.height as f32 * 0.5 - pixel_bounds.min.y as f32 * 0.5,
);
section.layout = Layout::default_single_line()
.h_align(HorizontalAlign::Center)
.v_align(VerticalAlign::Center);
glyph_brush.queue(section);
Produces:
It doesn't seem to be entirely centered still (?).
from wgpu_glyph.
glyph-brush
's vertical align doesn't align a set of glyphs in particular. It think it only uses the font properties, so it accounts for accents and other kind of symbols on top of some glyphs.
This is desirable for most use cases when you have dynamic text because it avoids awkward jumps. I am guessing the small difference that is still left depends entirely on the font.
If you want to completely center the produced glyphs, you should be able to use GlyphBrush::pixel_bounds
(from the GlyphCruncher
implementation) and then set the screen_position
appropriately when queueing.
from wgpu_glyph.
Also, I am sure we could implement our own GlyphPositioner
to do this directly without using pixel_bounds
.
from wgpu_glyph.
I was also imagining a centering strategy that did not depend dynamically on the particular glyphs.
Maybe it's wrong to approach this with the expectation that the baseline of the text and the top of a capital letter are perfectly equidistant from the edges; I'm not an expert in text layout. Trying out a bunch of different fonts in a text box in Google Docs, the vertical alignment seems to depend a bit on the selected typeface.
Overall I think it might make sense to close this issue, since it seems like wgpu_glyph
is probably handling vertical centering in a good wya.
from wgpu_glyph.
The built-in glyph-brush
glyph positioner uses rusttype::VMetrics
, which seems to talk about highest/lowest glyph points, to align lines.
I am not sure if fonts provide enough information to perform the alignment you describe, but rusttype
doesn't seem to expose it.
from wgpu_glyph.
Related Issues (20)
- Bug: wgpu_glyph renders gibberish psuedo-glyphs when used with ANGLE and or OpenGL backend on ARM OSX
- Comparison with glyphon crate.
- The published version wgpu dependency version mismatching HOT 2
- Multi line text can cause validation error if scale factor != 1 HOT 1
- error: could not compile `wgpu`
- Slight inconsistency between generated images HOT 1
- repeatedly blinks HOT 1
- Owned Types
- Stroked text?
- Broken text rendering on wasm32 target in Firefox HOT 5
- Latest release fails with validation error using wgpu 0.11.1 HOT 2
- Wrong Render Result for SourceHanSerif fonts
- Get bounding box of drawn text HOT 2
- Font weight problem HOT 2
- Depth example doesn't show anything on macOS HOT 1
- Background color
- Stoke text
- Alignment/Positioning doesn't work correctly
- Broken Documentation links?
- No support for resolve_target?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wgpu_glyph.