diff --git a/fonts.d b/fonts.d index 64c3b8b..08eb337 100644 --- a/fonts.d +++ b/fonts.d @@ -32,7 +32,7 @@ struct Glyph } __gshared FT_Library FT_LIB; -alias FontFace = FT_Face; +alias FontFace = FT_Face; struct FontAtlasBuf { @@ -108,10 +108,7 @@ CreateAtlas(Arena* arena, FontFace font, f32 size, u32 dimension) Logf("%f %f %f", font.height, font.ascender, font.descender); - u32 max_w; - u32 max_h; - u32 current_h; - u32 count; + u32 max_w, max_h, current_h, count; i32 font_size = Float26(size); @@ -134,17 +131,17 @@ CreateAtlas(Arena* arena, FontFace font, f32 size, u32 dimension) assert(max_h < dimension, "Unable to pack atlas within dimensions"); - max_w += bmp_w; + max_w += bmp_w; current_h = bmp_h > current_h ? bmp_h : current_h; - count += 1; + count += 1; } const u32 PADDING = 2; - max_w = PADDING; - max_h = PADDING; + max_w = PADDING; + max_h = PADDING; current_h = 0; - count = 0; + count = 0; foreach(FT_ULong char_code; 0 .. 0x7F) { @@ -182,10 +179,7 @@ CreateAtlas(Arena* arena, FontFace font, f32 size, u32 dimension) u8 p_r = bmp.buffer[offset+2]; u8 p_a = bmp.buffer[offset+3]; - abuf.data[offset+0] = DeMultiply(p_r, p_a); - abuf.data[offset+1] = DeMultiply(p_b, p_a); - abuf.data[offset+2] = DeMultiply(p_g, p_a); - abuf.data[offset+3] = p_a; + abuf.data[offset .. offset+4] = [DeMultiply(p_r, p_a), DeMultiply(p_b, p_a), DeMultiply(p_g, p_a), p_a]; } } } break; @@ -210,11 +204,7 @@ CreateAtlas(Arena* arena, FontFace font, f32 size, u32 dimension) x = max_w + c; u64 offset = (y*dimension + x) * 4; - abuf.data[offset+0] = 255; - abuf.data[offset+1] = 255; - abuf.data[offset+2] = 255; - abuf.data[offset+3] = (bits & 0x80) ? 255 : 0; - + abuf.data[offset .. offset+4] = [255, 255, 255, bits & 0x80 ? 255 : 0]; bits <<= 1; } @@ -232,10 +222,7 @@ CreateAtlas(Arena* arena, FontFace font, f32 size, u32 dimension) x = max_w + c; u64 offset = (y*dimension + x) * 4; - abuf.data[offset+0] = 255; - abuf.data[offset+1] = 255; - abuf.data[offset+2] = 255; - abuf.data[offset+3] = bmp.buffer[r*bmp.pitch + c]; + abuf.data[offset .. offset+4] = [255, 255, 255, bmp.buffer[r*bmp.pitch + c]]; } } } break; @@ -273,3 +260,8 @@ CreateAtlas(Arena* arena, FontFace font, f32 size, u32 dimension) return abuf; } +unittest +{ + +} +