Browse Source

Curve subdivision!

master
A.Olokhtonov 4 years ago
parent
commit
baf60622e4
  1. 58
      main.c

58
main.c

@ -26,7 +26,7 @@ @@ -26,7 +26,7 @@
#define PER_PIXEL 0
#define PER_ROW 0
#define DEBUG_SHOW_POINTS 1
#define DEBUG_SHOW_POINTS 0
/*
int total_hits = 0;
@ -408,8 +408,8 @@ render_glyph(struct glyph g, struct line_contour *lines, @@ -408,8 +408,8 @@ render_glyph(struct glyph g, struct line_contour *lines,
int x0 = 0; // g.xmin * scale;
int gwidth = (g.xmax - g.xmin) * scale + 2;
int gheight = (g.ymax - g.ymin) * scale + 2;
int gwidth = (g.xmax - g.xmin) * scale;
int gheight = (g.ymax - g.ymin) * scale + 1;
pixels = pixels + width * 100 + 100;
@ -480,6 +480,7 @@ outline_to_lines(struct glyph g, f32 scale, struct line_contour *dest, int *cnt) @@ -480,6 +480,7 @@ outline_to_lines(struct glyph g, f32 scale, struct line_contour *dest, int *cnt)
{
int nlines = 0;
int points_from = 0;
int curve_segments = 5;
for (int c = 0; c < g.ncontours; ++c) {
for (int p = points_from; p < g.end_pts_of_contours[c] + 1; ++p) {
@ -513,20 +514,41 @@ outline_to_lines(struct glyph g, f32 scale, struct line_contour *dest, int *cnt) @@ -513,20 +514,41 @@ outline_to_lines(struct glyph g, f32 scale, struct line_contour *dest, int *cnt)
f32 x3 = (nextnextgp.x - g.xmin) * scale;
f32 y3 = nextnextgp.y * scale;
if (gp.y != nextgp.y) {
if (dest->data) {
dest->data[nlines].a = (struct v2f) { x1, y1 };
dest->data[nlines].b = (struct v2f) { x2, y2 };
}
++nlines;
}
/* P(t) = P0*t^2 + P1*2*t*(1-t) + P2*(1-t)^2 */
f32 t_step = 1.0f / curve_segments;
f32 x_prev = x1;
f32 y_prev = y1;
if (nextgp.y != nextnextgp.y) {
if (dest->data) {
dest->data[nlines].a = (struct v2f) { x2, y2 };
dest->data[nlines].b = (struct v2f) { x3, y3 };
/* s = 1 for exact beginning */
for (int s = 1; s <= curve_segments; ++s) {
f32 t_now = t_step * s;
f32 x_now;
f32 y_now;
if (s < curve_segments) {
x_now = x3 * t_now * t_now
+ x2 * 2.0f * t_now * (1.0f - t_now)
+ x1 * (1.0f - t_now) * (1.0f - t_now);
y_now = y3 * t_now * t_now
+ y2 * 2.0f * t_now * (1.0f - t_now)
+ y1 * (1.0f - t_now) * (1.0f - t_now);
} else {
/* For exact match between neighbours */
x_now = x3;
y_now = y3;
}
++nlines;
if (abs_f32(y_now - y_prev) > F32EPS) {
if (dest->data) {
dest->data[nlines].a = (struct v2f) { x_prev, y_prev };
dest->data[nlines].b = (struct v2f) { x_now, y_now };
}
++nlines;
}
x_prev = x_now;
y_prev = y_now;
}
++p;
@ -604,11 +626,11 @@ main(int argc, char **argv) @@ -604,11 +626,11 @@ main(int argc, char **argv)
printf("Loaded font\n");
//struct glyph g = get_outline(&font, 0x046C);
int codepoint = 0x0431;
int codepoint = 0x0020;
struct glyph g = get_outline(&font, codepoint);
int nlines = 0;
u32 px_size = 120;
u32 px_size = 20;
u32 *pixels = hc_vram;
int t = 0;
@ -629,7 +651,7 @@ main(int argc, char **argv) @@ -629,7 +651,7 @@ main(int argc, char **argv)
render_glyph(g, &lines, font, px_size, pixels, width, height);
XPutImage(display, window, default_gc, xwindow_buffer, 0, 0, 0, 0, width, height);
#if 0
#if 1
//printf("%d\n", px_size);
++px_size;

Loading…
Cancel
Save