fixes
This commit is contained in:
parent
5b6a36f845
commit
4c84d0ca40
38
fonts.d
38
fonts.d
@ -32,7 +32,7 @@ struct Glyph
|
|||||||
}
|
}
|
||||||
|
|
||||||
__gshared FT_Library FT_LIB;
|
__gshared FT_Library FT_LIB;
|
||||||
alias FontFace = FT_Face;
|
alias FontFace = FT_Face;
|
||||||
|
|
||||||
struct FontAtlasBuf
|
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);
|
Logf("%f %f %f", font.height, font.ascender, font.descender);
|
||||||
|
|
||||||
u32 max_w;
|
u32 max_w, max_h, current_h, count;
|
||||||
u32 max_h;
|
|
||||||
u32 current_h;
|
|
||||||
u32 count;
|
|
||||||
|
|
||||||
i32 font_size = Float26(size);
|
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");
|
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;
|
current_h = bmp_h > current_h ? bmp_h : current_h;
|
||||||
count += 1;
|
count += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
const u32 PADDING = 2;
|
const u32 PADDING = 2;
|
||||||
|
|
||||||
max_w = PADDING;
|
max_w = PADDING;
|
||||||
max_h = PADDING;
|
max_h = PADDING;
|
||||||
current_h = 0;
|
current_h = 0;
|
||||||
count = 0;
|
count = 0;
|
||||||
|
|
||||||
foreach(FT_ULong char_code; 0 .. 0x7F)
|
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_r = bmp.buffer[offset+2];
|
||||||
u8 p_a = bmp.buffer[offset+3];
|
u8 p_a = bmp.buffer[offset+3];
|
||||||
|
|
||||||
abuf.data[offset+0] = DeMultiply(p_r, p_a);
|
abuf.data[offset .. offset+4] = [DeMultiply(p_r, p_a), DeMultiply(p_b, p_a), DeMultiply(p_g, p_a), 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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
@ -210,11 +204,7 @@ CreateAtlas(Arena* arena, FontFace font, f32 size, u32 dimension)
|
|||||||
x = max_w + c;
|
x = max_w + c;
|
||||||
u64 offset = (y*dimension + x) * 4;
|
u64 offset = (y*dimension + x) * 4;
|
||||||
|
|
||||||
abuf.data[offset+0] = 255;
|
abuf.data[offset .. offset+4] = [255, 255, 255, bits & 0x80 ? 255 : 0];
|
||||||
abuf.data[offset+1] = 255;
|
|
||||||
abuf.data[offset+2] = 255;
|
|
||||||
abuf.data[offset+3] = (bits & 0x80) ? 255 : 0;
|
|
||||||
|
|
||||||
bits <<= 1;
|
bits <<= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,10 +222,7 @@ CreateAtlas(Arena* arena, FontFace font, f32 size, u32 dimension)
|
|||||||
x = max_w + c;
|
x = max_w + c;
|
||||||
u64 offset = (y*dimension + x) * 4;
|
u64 offset = (y*dimension + x) * 4;
|
||||||
|
|
||||||
abuf.data[offset+0] = 255;
|
abuf.data[offset .. offset+4] = [255, 255, 255, bmp.buffer[r*bmp.pitch + c]];
|
||||||
abuf.data[offset+1] = 255;
|
|
||||||
abuf.data[offset+2] = 255;
|
|
||||||
abuf.data[offset+3] = bmp.buffer[r*bmp.pitch + c];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
@ -273,3 +260,8 @@ CreateAtlas(Arena* arena, FontFace font, f32 size, u32 dimension)
|
|||||||
return abuf;
|
return abuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user