I'm converting the cairo samples (http://cairographics.org/samples/ http://cvs.cairographics.org/cairo-demo/cairo_snippets/) to pascal.

I'm getting a runtime error 207 (invalid float operation in win32) in two specific examples (arc and arc_negative). All other examples works fine.

Here's the converted code snippet (a compilable example is attached):

 xc := 0.5;
 yc := 0.5;
 radius := 0.4;
 angle1 := 45.0  * (PI/180.0);  (* angles are specified *)
 angle2 := 180.0 * (PI/180.0);  (* in radians           *)

 cairo_arc (cr, xc, yc, radius, angle1, angle2); -> works fine
 cairo_stroke (cr);

 cairo_set_source_rgba (cr, 1,0.2,0.2,0.6);
 cairo_arc (cr, xc, yc, 0.05, 0, 2*PI); -> works fine
 cairo_fill (cr);
 cairo_set_line_width (cr, 0.03);
//cairo_arc (cr, xc, yc, radius, angle1, angle1); -> uncomment and you will get the error
 cairo_line_to (cr, xc, yc);
//cairo_arc (cr, xc, yc, radius, angle2, angle2); -> uncomment and you will get the error
 cairo_line_to (cr, xc, yc);
 cairo_stroke (cr);

The first two cairo_arc works fine. But the third and fourth not. The later have the angle values equal.

I compiled the original code (c) and worked fine in the same system.
Here's the c code:

double xc = 0.5;
double yc = 0.5;
double radius = 0.4;
double angle1 = 45.0  * (M_PI/180.0);  /* angles are specified */
double angle2 = 180.0 * (M_PI/180.0);  /* in radians           */

cairo_scale (cr, width, height);
cairo_set_line_width (cr, 0.04);

cairo_arc (cr, xc, yc, radius, angle1, angle2);
cairo_stroke (cr);

cairo_set_source_rgba (cr, 1,0.2,0.2,0.6);
cairo_arc (cr, xc, yc, 0.05, 0, 2*M_PI);
cairo_fill (cr);
cairo_set_line_width (cr, 0.03);
cairo_arc (cr, xc, yc, radius, angle1, angle1);
cairo_line_to (cr, xc, yc);
cairo_arc (cr, xc, yc, radius, angle2, angle2);
cairo_line_to (cr, xc, yc);
cairo_stroke (cr);



Here's the c header (arc):
cairo_arc (cairo_t *cr,
      double xc, double yc,
      double radius,
      double angle1, double angle2);

Here's the pascal header (cairo.pp):
procedure cairo_arc(cr:Pcairo_t; xc:double; yc:double; radius:double; angle1:double; angle2:double); cdecl; external LIB_CAIRO;

I'm using fpc220 under Ubuntu 07.04

Anyone has a hint on whats going on?

Luiz
program cairobug;

uses
  cairo;

const
  IMAGE_WIDTH = 256;
  IMAGE_HEIGHT = 256;

procedure do_arc(cr: PCairo_t; width, height: Integer);
var
  xc: Double;
  yc: Double;
  radius: Double;
  angle1: Double;
  angle2: Double;
begin
  xc := 0.5;
  yc := 0.5;
  radius := 0.4;
  angle1 := 45.0  * (PI/180.0);  (* angles are specified *)
  angle2 := 180.0 * (PI/180.0);  (* in radians           *)

  cairo_scale (cr, width, height);
  cairo_set_line_width (cr, 0.04);

  cairo_arc (cr, xc, yc, radius, angle1, angle2);
  cairo_stroke (cr);

  (* draw helping lines *)
  cairo_set_source_rgba (cr, 1,0.2,0.2,0.6);
  cairo_arc (cr, xc, yc, 0.05, 0, 2*PI);
  cairo_fill (cr);
  cairo_set_line_width (cr, 0.03);
  //cairo_arc (cr, xc, yc, radius, angle1, angle1); //-> uncomment and you will get the error
  cairo_line_to (cr, xc, yc);
  //cairo_arc (cr, xc, yc, radius, angle2, angle2); //-> uncomment and you will get the error
  cairo_line_to (cr, xc, yc);
  cairo_stroke (cr);
end;

var
  cr: PCairo_t;
  surface: Pcairo_surface_t;

begin
  surface := cairo_image_surface_create (CAIRO_FORMAT_ARGB32, IMAGE_WIDTH, IMAGE_HEIGHT);
  cr := cairo_create (surface);
  
  cairo_save (cr);
  do_arc (cr, IMAGE_WIDTH, IMAGE_HEIGHT);
  cairo_restore (cr);
  
  cairo_surface_write_to_png (surface, 'testcairobug1.png');
    
  cairo_destroy (cr);
  cairo_surface_destroy (surface);
end.
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to