diff --git a/.cquery b/.cquery deleted file mode 100644 index b841bc7..0000000 --- a/.cquery +++ /dev/null @@ -1,5 +0,0 @@ -%clang -%c -std=gnu99 - --I./src --I. diff --git a/.gitignore b/.gitignore index 22e3fa9..ad6bb22 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,4 @@ depcomp hvif install-sh missing +.cquery diff --git a/src/Makefile.am b/src/Makefile.am index a006fac..22e34a3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -26,3 +26,9 @@ hvif_SOURCES = \ src/hvif-cairo.h \ $(NULL) +cquery: + echo '%clang' > .cquery + echo '%c -std=gnu11' >> .cquery + echo '$(CAIRO_CFLAGS)' | sed "s/ /\\n/g" >> .cquery + +.PHONY: cquery diff --git a/src/hvif-cairo.c b/src/hvif-cairo.c index 52d09d2..071ddde 100644 --- a/src/hvif-cairo.c +++ b/src/hvif-cairo.c @@ -1,18 +1,62 @@ #include "hvif-light.h" #include +#include #include #define INTERNAL_DATASTRUCTURES #include "hvif-light.c" #undef INTERNAL_DATASTRUCTURES +/* TODO: + * 1. Draw the path in each shape as outline + * 2. Then do the same for the styles + * 3. Put everything together + */ + +void +create_path(cairo_t* cr, hvif_path* path) +{ + assert(path->num_points > 0); + + for (unsigned i = 0; i < path->num_points; ++i) { + hvif_point p = path->points[3 * i]; + hvif_point cp1 = path->points[3 * i + 1]; + hvif_point cp2 = path->points[3 * i + 2]; + cairo_curve_to(cr, cp1.x, cp1.y, cp2.x, cp2.y, p.x, p.y); + } + + if (path->closed) + cairo_close_path(cr); +} + bool hvif_render_image(const char* filename, hvif_image* image) { cairo_surface_t* surface = - cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 240, 80); + cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 254, 254); cairo_t* cr = cairo_create(surface); + cairo_scale(cr, 4.0, 4.0); + + cairo_set_line_width(cr, 0.2); + + double r = 0; + double delta = 1.0 / image->num_shapes; + + for (unsigned i = 0; i < image->num_shapes; ++i) { + cairo_set_source_rgb(cr, r, 0, 0); + r = r + delta; + hvif_shape s = image->shapes[i]; + if (s.hinting) + printf("shape %u has hinting\n", i); + else + printf("shape %u has no hinting\n", i); + for (unsigned j = 0; j < s.num_paths; ++j) { + hvif_path* p = &image->paths[s.path_idxs[j]]; + create_path(cr, p); + cairo_stroke(cr); + } + } cairo_destroy(cr); diff --git a/src/hvif-cairo.h b/src/hvif-cairo.h index e49c0aa..0daa5ed 100644 --- a/src/hvif-cairo.h +++ b/src/hvif-cairo.h @@ -1,7 +1,7 @@ #ifndef HVIF_CAIRO_H #define HVIF_CAIRO_H -#include "hvif-ligh.h" +#include "hvif-light.h" bool hvif_render_image(const char* filename, hvif_image* image); diff --git a/src/hvif-light.c b/src/hvif-light.c index 9718cb6..6def08d 100644 --- a/src/hvif-light.c +++ b/src/hvif-light.c @@ -463,7 +463,7 @@ read_path_points(FILE* file, hvif_path* path) printf("%s: read v line.\n", __func__); #endif point = last; - status = read_coordinate(file, &point.x); + status = read_coordinate(file, &point.y); if (status != SUCCESS) return status; point_in = point_out = point; break; @@ -485,17 +485,14 @@ read_path_points(FILE* file, hvif_path* path) if (status != SUCCESS) return status; status = read_coordinate(file, &point.y); if (status != SUCCESS) return status; - point_in = point_out = point; status = read_coordinate(file, &point_in.x); if (status != SUCCESS) return status; status = read_coordinate(file, &point_in.y); if (status != SUCCESS) return status; - point_in = point_out = point; status = read_coordinate(file, &point_out.x); if (status != SUCCESS) return status; status = read_coordinate(file, &point_out.y); if (status != SUCCESS) return status; - point_in = point_out = point; break; } unsigned base = i * 3; diff --git a/src/main.c b/src/main.c index 17cd65d..5dccbd0 100644 --- a/src/main.c +++ b/src/main.c @@ -1,5 +1,6 @@ #include "config.h" #include "hvif-light.h" +#include "hvif-cairo.h" #include #include @@ -36,6 +37,9 @@ main(int argc, char* argv[argc + 1]) return EXIT_FAILURE; } puts("Reading image succeeded."); + + hvif_render_image("test.png", result.image); + hvif_free(result.image); return EXIT_SUCCESS;