script surface incorrectly causes current path to be dropped by cairo_fill_preserve in some cases
Consider the following example, which draws a single horizontal line either to an image surface (saved to png) or a script surface:
#include <stdio.h>
#include <cairo.h>
#include <cairo-script.h>
int main()
{
cairo_surface_t *cs1 = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 10, 10);
cairo_t *c1 = cairo_create(cs1);
cairo_new_path(c1);
cairo_move_to(c1, 1, 1);
cairo_line_to(c1, 9, 1);
cairo_fill_preserve(c1);
printf("%d ", cairo_has_current_point(c1));
cairo_stroke(c1);
cairo_surface_write_to_png(cs1, "test.png");
printf("%s\n", cairo_status_to_string(cairo_status(c1)));
cairo_surface_t *cs2 = cairo_script_surface_create(
cairo_script_create("test.cairoscript"), CAIRO_CONTENT_COLOR_ALPHA, 10, 10);
cairo_t *c2 = cairo_create(cs2);
cairo_new_path(c2);
cairo_move_to(c2, 1, 1);
cairo_line_to(c2, 9, 1); // line_to (9, 9) doesn't error.
cairo_fill_preserve(c2);
printf("%d ", cairo_has_current_point(c2));
cairo_stroke(c2);
printf("%s\n", cairo_status_to_string(cairo_status(c2)));
return 0;
}
(compile and run with gcc $(pkg-config --cflags --libs cairo) -o test test.c && ./test
).
As of cairo 1.17.4, this prints
1 no error has occurred
0 input path data not valid
The png output is fine, but inspecting test.cairoscript
reveals that that output is incomplete (stopping before the path coordinates are output). Given the print-debugging based on cairo_has_current_point, this appears to occur because cairo_fill_preserve caused the current path to be incorrectly dropped and the stroke-on-empty-path causes the script device to error out. Interestingly, as noted in the comment in the source, drawing a diagonal line does not cause such issues.