Cairo generates incorrect PDF files
Hello,
When I launch this program:
#include <cairo.h>
#include <cairo-pdf.h>
int main(void)
{
cairo_surface_t *surface;
cairo_t *cr;
surface = cairo_pdf_surface_create("out.pdf", 500, 500);
cr = cairo_create(surface);
cairo_set_source_rgb(cr, 0, 0, 0);
cairo_select_font_face (cr, "Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, 40.0);
cairo_move_to(cr, 10.0, 50.0);
cairo_show_text(cr, "TEST");
cairo_push_group(cr);
cairo_move_to(cr, 10.0, 250.0);
cairo_show_text(cr, "TEST");
cairo_pop_group_to_source(cr);
cairo_paint_with_alpha(cr, 0.5);
cairo_show_page(cr);
cairo_surface_destroy(surface);
cairo_destroy(cr);
return 0;
}
I get an incorrect PDF according to Ghostscript:
gs -o repaired.pdf -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress out.pdf
GPL Ghostscript 9.25 (2018-09-13)
Copyright (C) 2018 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 1.
Page 1
**** Error: Ignoring spurious ET operator.
Output may be incorrect.
**** Error: Executing Do inside a text block, attempting to recover
Output may be incorrect.
**** This file had errors that were repaired or ignored.
**** The file was produced by:
**** >>>> cairo 1.16.0 (https://cairographics.org) <<<<
**** Please notify the author of the software that produced this
**** file that it does not conform to Adobe's published PDF
**** specification.
I've tried various versions of Cairo and I think that the bug has been introduced in version 1.15.10, as 1.15.8 generates a correct PDF file.