[cairo] Visible lines between adjacent semi-transparent polygons

Jennifer Adams jma at cola.iges.org
Mon Nov 21 10:35:26 PST 2011


Dear Experts, 
I am working toward implementing Cairo in GrADS, an open source program for the analysis and display of meteorological data. My use of cairo is fairly basic. In a test program, I am drawing two adjacent triangles with transparency set to 0.50, writing out .pdf and .png formats. A faint line shows up along the common boundary of the two triangles (i.e., along the diagonal of what should be a solid rectangle). Disabling anti-aliasing makes the line go away in the .png file, but it persists in the .pdf. What is causing this and is there a remedy? 

My test program looks like this:

#include <stdio.h>
#include <stdlib.h>
#include <cairo.h>
#include <cairo-pdf.h>

int main (int argc, char *argv[]) {
  cairo_surface_t *surface=NULL;
  cairo_t *cr;
  int winx,winy;

  winx = winy = 200; 
  surface = cairo_pdf_surface_create ("hello.pdf",winx,winy);
  cr = cairo_create (surface);

  /* fill white background */
  cairo_set_source_rgb(cr,1,1,1);
  cairo_rectangle(cr,0,0,winx,winy);
  cairo_fill(cr);

  /* two adjacent semi-transparent filled triangles with anti-aliasiang turned off */
  cairo_set_antialias(cr,CAIRO_ANTIALIAS_NONE); 
  cairo_set_source_rgb (cr, 0, 0, 0);
  cairo_move_to (cr, 20, 15);
  cairo_set_font_size (cr, 10);
  cairo_show_text (cr, "without anti-alias");
  cairo_set_source_rgba (cr, 0, 0, 0, 0.5);
  cairo_move_to(cr,  20,  20); /* ul */
  cairo_line_to(cr, 120,  20); /* ur */
  cairo_line_to(cr, 120,  90); /* lr */
  cairo_fill(cr);
  cairo_move_to(cr,  20,  20); /* ul */
  cairo_line_to(cr,  20,  90); /* ll */
  cairo_line_to(cr, 120,  90); /* lr */
  cairo_fill(cr);

  /* two adjacent semi-transparent filled triangles with anti-aliasiang turned on */
  cairo_set_antialias(cr,CAIRO_ANTIALIAS_DEFAULT); 
  cairo_set_source_rgb (cr, 0, 0, 0);
  cairo_move_to (cr, 20, 115);
  cairo_set_font_size (cr, 10);
  cairo_show_text (cr, "with anti-alias");
  cairo_set_source_rgba (cr, 0, 0, 0, 0.5);
  cairo_move_to(cr,  20, 120); /* ul */
  cairo_line_to(cr, 120, 120); /* ur */
  cairo_line_to(cr, 120, 190); /* lr */
  cairo_fill(cr);
  cairo_move_to(cr,  20, 120); /* ul */
  cairo_line_to(cr,  20, 190); /* ll */
  cairo_line_to(cr, 120, 190); /* lr */
  cairo_fill(cr);

  /* finish up */
  cairo_surface_show_page (surface);
  cairo_destroy (cr);
  cairo_surface_finish (surface);
  cairo_surface_destroy (surface);

  return 0;
}

The .pdf and .png output are here:
http://iges.org/jma/hello.pdf
http://iges.org/jma/hello.png

I'm working with the macports install of cairo for Mac OSX Lion, and I am using Preview and Adobe Acrobat Professional to display the .pdf file -- the diagonal line is visible in both, but it is lighter than the rest of the rectangle in Preview and darker in Acrobat. I was unable to create a trace file; I got this message when running cairo-trace:
Assertion failed: (cairo_pdf_surface_create_real != NULL), function cairo_pdf_surface_create, file trace.c, line 4310.
/opt/local/bin/cairo-trace: line 136: 82232 Abort trap: 6           (core dumped) CAIRO_TRACE_FD=3 "$@" 3>&1 > /dev/null

Many thanks for any guidance you can provide. 
--Jennifer

--
Jennifer M. Adams
IGES/COLA
4041 Powder Mill Road, Suite 302
Calverton, MD 20705
jma at cola.iges.org



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cairographics.org/archives/cairo/attachments/20111121/27cb3c39/attachment.htm>


More information about the cairo mailing list