text: Fixed atlas finding glyphs of wrong size
Signed-off-by: Jeremia Dominguez <me@jeremia.dev>
This commit is contained in:
parent
e661dcaf0a
commit
06f66d7a32
1 changed files with 13 additions and 2 deletions
|
|
@ -83,7 +83,13 @@ const Glyph = extern struct {
|
||||||
text_index: u32,
|
text_index: u32,
|
||||||
};
|
};
|
||||||
|
|
||||||
const RegionMap = std.AutoArrayHashMapUnmanaged(u21, mach.Atlas.Region);
|
const GlyphDetail = struct {
|
||||||
|
codepoint: u21 = 0,
|
||||||
|
font: FontRenderer,
|
||||||
|
// Auto Hashing doesn't work for floats, so we bitcast to integer.
|
||||||
|
size: u32,
|
||||||
|
};
|
||||||
|
const RegionMap = std.AutoArrayHashMapUnmanaged(u21, GlyphDetail);
|
||||||
|
|
||||||
const Pipeline = struct {
|
const Pipeline = struct {
|
||||||
render: *gpu.RenderPipeline,
|
render: *gpu.RenderPipeline,
|
||||||
|
|
@ -388,10 +394,15 @@ pub fn machGfxTextUpdated(
|
||||||
var offset_x: f32 = 0.0;
|
var offset_x: f32 = 0.0;
|
||||||
var offset_y: f32 = 0.0;
|
var offset_y: f32 = 0.0;
|
||||||
var utf8 = (try std.unicode.Utf8View.init(text)).iterator();
|
var utf8 = (try std.unicode.Utf8View.init(text)).iterator();
|
||||||
|
var glyph_detail = GlyphDetail{
|
||||||
|
.font = font,
|
||||||
|
.size = @bitCast(font_size),
|
||||||
|
};
|
||||||
while (utf8.nextCodepoint()) |codepoint| {
|
while (utf8.nextCodepoint()) |codepoint| {
|
||||||
const m = try font.measure(codepoint, font_size * px_density);
|
const m = try font.measure(codepoint, font_size * px_density);
|
||||||
|
glyph_detail.codepoint = codepoint;
|
||||||
if (codepoint != '\n') {
|
if (codepoint != '\n') {
|
||||||
var region = try pipeline.regions.getOrPut(engine.allocator, codepoint);
|
var region = try pipeline.regions.getOrPut(engine.allocator, glyph_detail);
|
||||||
if (!region.found_existing) {
|
if (!region.found_existing) {
|
||||||
const glyph = try font.render(codepoint, font_size * px_density);
|
const glyph = try font.render(codepoint, font_size * px_density);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue