|
|
|
@ -1,4 +1,3 @@
@@ -1,4 +1,3 @@
|
|
|
|
|
|
|
|
|
|
static int |
|
|
|
|
scanline_intersects_line(f32 y, struct v2f p0, struct v2f p1, f32 lasty, f32 *vx) |
|
|
|
|
{ |
|
|
|
@ -74,7 +73,7 @@ sort_intersections(struct intersection *intersections, int size)
@@ -74,7 +73,7 @@ sort_intersections(struct intersection *intersections, int size)
|
|
|
|
|
|
|
|
|
|
static void |
|
|
|
|
render_glyph(struct glyph g, int px_size, struct line_contour *lines, |
|
|
|
|
f32 scale, u32 *pixels, int width, int at_x, int at_y) |
|
|
|
|
f32 scale, u32 *pixels, int width, int at_x, int at_y, u32 color) |
|
|
|
|
{ |
|
|
|
|
int oversample_y = 4; |
|
|
|
|
if (px_size <= 12) { |
|
|
|
@ -131,10 +130,15 @@ render_glyph(struct glyph g, int px_size, struct line_contour *lines,
@@ -131,10 +130,15 @@ render_glyph(struct glyph g, int px_size, struct line_contour *lines,
|
|
|
|
|
for (int x = 0; x < gwidth; ++x) { |
|
|
|
|
//printf(" %.2f", accumulator[y * gwidth + x]);
|
|
|
|
|
u32 brightness = clamp_u32(accumulator[y * gwidth + x] * 255.99f, 255); |
|
|
|
|
u32 white = 0xFF000000 | brightness << 16 | brightness << 8 | brightness; |
|
|
|
|
|
|
|
|
|
if (brightness > 0) { |
|
|
|
|
pixels[(at_y + (gheight - 1 - y)) * width + (at_x + x)] = white; |
|
|
|
|
f32 alpha = brightness / 256.0f; |
|
|
|
|
u32 bg = pixels[(at_y + (gheight - 1 - y)) * width + (at_x + x)]; |
|
|
|
|
u8 r = ((bg & 0xff0000) >> 16) * (1.0f - alpha) + alpha * ((color & 0xff0000) >> 16); |
|
|
|
|
u8 g = ((bg & 0x00ff00) >> 8) * (1.0f - alpha) + alpha * ((color & 0x00ff00) >> 8); |
|
|
|
|
u8 b = ((bg & 0x0000ff) >> 0) * (1.0f - alpha) + alpha * ((color & 0x0000ff) >> 0); |
|
|
|
|
u32 value = 0xFF000000 | r << 16 | g << 8 | b; |
|
|
|
|
pixels[(at_y + (gheight - 1 - y)) * width + (at_x + x)] = value; |
|
|
|
|
} else { |
|
|
|
|
//pixels[(at_y + (gheight - 1 - y)) * width + (at_x + x)] = 0xFFFF0000;
|
|
|
|
|
} |
|
|
|
@ -242,10 +246,11 @@ outline_to_lines(struct glyph g, f32 scale, int max_descent, struct line_contour
@@ -242,10 +246,11 @@ outline_to_lines(struct glyph g, f32 scale, int max_descent, struct line_contour
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static struct v2 |
|
|
|
|
render_utf_string(struct ttf_font font, int px_size, u32 *pixels, u32 width, wchar_t *string, u32 fit_width, int at_x, int at_y) |
|
|
|
|
render_utf_string(struct ttf_font font, int px_size, u32 *pixels, u32 width, wchar_t *string, int fit_width, int at_x, int at_y) |
|
|
|
|
{ |
|
|
|
|
u32 offset_x = at_x; |
|
|
|
|
u32 offset_y = at_y; |
|
|
|
|
u32 color = 0xffffffff; |
|
|
|
|
s32 offset_x = at_x; |
|
|
|
|
s32 offset_y = at_y; |
|
|
|
|
f32 scale = (f32) px_size / ((f32) (font.hhea.ascent - font.hhea.descent)); |
|
|
|
|
|
|
|
|
|
u32 len = wcslen(string); |
|
|
|
@ -257,7 +262,25 @@ render_utf_string(struct ttf_font font, int px_size, u32 *pixels, u32 width, wch
@@ -257,7 +262,25 @@ render_utf_string(struct ttf_font font, int px_size, u32 *pixels, u32 width, wch
|
|
|
|
|
for (u32 i = 0; i < len; ++i) { |
|
|
|
|
u16 codepoint = string[i]; |
|
|
|
|
int advance; |
|
|
|
|
if (codepoint != ' ') { |
|
|
|
|
if (codepoint == ' ') { |
|
|
|
|
if (offset_x > 0) { |
|
|
|
|
advance = get_codepoint_width(&font, scale, codepoint); |
|
|
|
|
} else { |
|
|
|
|
advance = 0; |
|
|
|
|
} |
|
|
|
|
} else if (codepoint == '\t') { |
|
|
|
|
advance = get_codepoint_width(&font, scale, codepoint); |
|
|
|
|
advance *= 4; |
|
|
|
|
} else if (codepoint == '\n') { |
|
|
|
|
if (offset_x > box.x) { |
|
|
|
|
box.x = offset_x; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
advance = 0; |
|
|
|
|
offset_x = at_x; |
|
|
|
|
offset_y += px_size; |
|
|
|
|
box.y += px_size; |
|
|
|
|
} else { |
|
|
|
|
struct glyph g = get_outline(&font, codepoint); |
|
|
|
|
|
|
|
|
|
//exit(0);
|
|
|
|
@ -268,23 +291,25 @@ render_utf_string(struct ttf_font font, int px_size, u32 *pixels, u32 width, wch
@@ -268,23 +291,25 @@ render_utf_string(struct ttf_font font, int px_size, u32 *pixels, u32 width, wch
|
|
|
|
|
lines.data = malloc(nlines * sizeof(struct line)); |
|
|
|
|
outline_to_lines(g, scale, font.hhea.descent, &lines, 0); |
|
|
|
|
|
|
|
|
|
render_glyph(g, px_size, &lines, scale, pixels, width, offset_x, offset_y); |
|
|
|
|
render_glyph(g, px_size, &lines, scale, pixels, width, offset_x, offset_y, color); |
|
|
|
|
|
|
|
|
|
advance = ceil_f32(scale * g.advance); |
|
|
|
|
free(lines.data); |
|
|
|
|
} else { |
|
|
|
|
advance = get_codepoint_width(&font, scale, codepoint); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
offset_x += advance; |
|
|
|
|
box.x += advance; |
|
|
|
|
|
|
|
|
|
if (offset_x - at_x >= fit_width) { |
|
|
|
|
offset_x = at_x; |
|
|
|
|
offset_y += px_size; |
|
|
|
|
box.y += px_size; |
|
|
|
|
box.x = fit_width; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (offset_x > box.x) { |
|
|
|
|
box.x = offset_x - at_x; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return(box); |
|
|
|
|
} |