2020-03-31 22:16:17 +02:00
|
|
|
#include "hvif-light.h"
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2020-04-01 23:23:59 +02:00
|
|
|
#include <assert.h>
|
2020-03-31 22:16:17 +02:00
|
|
|
#include <cairo.h>
|
|
|
|
|
|
|
|
#define INTERNAL_DATASTRUCTURES
|
|
|
|
#include "hvif-light.c"
|
|
|
|
#undef INTERNAL_DATASTRUCTURES
|
|
|
|
|
2020-04-01 23:23:59 +02:00
|
|
|
/* 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);
|
|
|
|
}
|
|
|
|
|
2020-03-31 22:16:17 +02:00
|
|
|
bool
|
|
|
|
hvif_render_image(const char* filename, hvif_image* image)
|
|
|
|
{
|
|
|
|
cairo_surface_t* surface =
|
2020-04-01 23:23:59 +02:00
|
|
|
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 254, 254);
|
2020-03-31 22:16:17 +02:00
|
|
|
cairo_t* cr = cairo_create(surface);
|
2020-04-01 23:23:59 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2020-03-31 22:16:17 +02:00
|
|
|
|
|
|
|
cairo_destroy(cr);
|
|
|
|
|
|
|
|
bool result = true;
|
|
|
|
if (cairo_surface_write_to_png(surface, filename) != CAIRO_STATUS_SUCCESS)
|
|
|
|
result = false;
|
|
|
|
cairo_surface_destroy(surface);
|
|
|
|
return result;
|
|
|
|
}
|