#include #include #include #include #include "draw.h" // Draw an image at a specific point int draw_image(cairo_t *c, char *path, double x, double y) { cairo_surface_t *image; // Checks if the file exists. If it doesn't, warn the user that it was not found. // A file not existing will not terminate the program, but simply not render the image. FILE *file; if((file = fopen(path, "r")) != NULL) { // file exists fclose(file); } else { printf("Warning: image \'%s\' does not exist.\n", path); return 1; } image = cairo_image_surface_create_from_png(path); double width = cairo_image_surface_get_width(image); double height = cairo_image_surface_get_height(image); double fake_width = 100; double fake_height = 100; double width_scale = fake_width / width; double height_scale = fake_height / height; cairo_scale(c, width_scale, height_scale); cairo_set_source_surface(c, image, x, y); cairo_paint(c); cairo_surface_destroy (image); return 0; } // Draw month art int draw_month_art(cairo_t *c, struct dimensions *d, char *path) { cairo_save(c); double width = d->header_width; // TODO: Make this relative to text height double height = d->header_height - (d->margin * 3.0); double cursor_x = d->margin; double cursor_y = d->margin; cairo_rectangle (c, d->margin, d->margin, width, height); cairo_clip(c); draw_image(c, path, cursor_x, cursor_y); cairo_restore(c); return 0; }