Index: trunk/Ohana/src/kapa2/src/PSOverlay.c
===================================================================
--- trunk/Ohana/src/kapa2/src/PSOverlay.c	(revision 19834)
+++ trunk/Ohana/src/kapa2/src/PSOverlay.c	(revision 19835)
@@ -1,3 +1,5 @@
 # include "Ximage.h"
+
+static char name[4][16] = {"red", "green", "blue", "yellow"};
 
 void PSOverlay (KapaImageWidget *image, int N, FILE *f, int extra) {
@@ -6,17 +8,18 @@
   double X, Y, dX, dY;
   int Xmin, Ymin, Xmax, Ymax;
-  double expand, X0, Y0;
+  double expand, pX, pY;
+  bDrawColor color;
  
+  /* translate color to bDrawColors : image[0].overlay[N].color */
+  color = KapaColorByName (name[N]);
+  fprintf (f, "%s setrgbcolor\n", KapaColorRGBString(color));
+  
   expand = 1.0;
   if (image[0].picture.expand > 0) {
-    expand = 1 / (1.0*image[0].picture.expand);
+    expand = image[0].picture.expand;
   }
   if (image[0].picture.expand < 0) {
-    expand = fabs((double)image[0].picture.expand);
+    expand = 1.0 / fabs((double)image[0].picture.expand);
   }
-
-  Image_to_Screen (&X0, &Y0, 0.0, 0.0, &image[0].picture);
-  X0 -= image[0].picture.x;
-  Y0 -= image[0].picture.y;
 
   Xmin = 0;
@@ -26,9 +29,17 @@
 
   for (i = 0; i < image[0].overlay[N].Nobjects; i++) {
-    X  = (image[0].overlay[N].objects[i].x)/expand + X0;
-    Y =  Ymax - (image[0].overlay[N].objects[i].y)/expand - Y0;
-    dX = (image[0].overlay[N].objects[i].dx)/expand;
-    dY = (image[0].overlay[N].objects[i].dy)/expand;
-    
+
+    Image_to_Screen (&X, &Y, image[0].overlay[N].objects[i].x, image[0].overlay[N].objects[i].y, &image[0].picture);
+    dX = image[0].overlay[N].objects[i].dx * expand;
+    dY = image[0].overlay[N].objects[i].dy * expand;
+    if (image[0].picture.flipx) dX *= -1;
+    if (image[0].picture.flipy) dY *= -1;
+
+    // PS coord system is flipped relative to screen
+    Y = Ymax - Y;
+
+    pX = (image[0].picture.flipx) ? -1.0 : +1.0;
+    pY = (image[0].picture.flipy) ? -1.0 : +1.0;
+
     switch (image[0].overlay[N].objects[i].type) {
       case KII_OVERLAY_LINE:
@@ -58,6 +69,27 @@
 	  break;
 	}
-	// XXX add in the rotated ellipse version (rotate in PS space)
-	fprintf (f, " %6.1f %6.1f %6.1f C\n", X, Y, fabs(dX + extra));
+	// is this a true circle, or is it an ellipse?
+	if (fabs(dX - dY) < 0.01) {
+	  fprintf (f, " %6.1f %6.1f %6.1f C\n", X, Y, fabs(dX + extra));
+	} else {
+	  // moderately-stupid rotated ellipse drawing:
+	  // ANGLE is distance ccw from the x-axis to the major axis
+	  double x0, y0, x1, y1, t;
+	  double angle = image[0].overlay[N].objects[i].angle * RAD_DEG;
+	  double cs = cos(angle);
+	  double sn = sin(angle);
+	  x0 = X + pX*dX*cs;
+	  y0 = Y + pY*dX*sn;
+	  // XXX dt should be based on the size of the ellipse...
+	  // 0.10 -> 60 segments on the ellipse
+	  # define DT 0.1
+	  for (t = DT; t < 2*M_PI + DT; t+=DT) {
+	    x1 = X + pX*dX*cos(t)*cs - pX*dY*sin(t)*sn;
+	    y1 = Y + pY*dX*cos(t)*sn + pY*dY*sin(t)*cs;
+	    fprintf (f, " %6.1f %6.1f %6.1f %6.1f L\n", x0 + extra, y0 + extra, x1 + extra, y1 + extra);
+	    x0 = x1;
+	    y0 = y1;
+	  }
+	}
 	break;
       default:
Index: trunk/Ohana/src/kapa2/src/PaintOverlay.c
===================================================================
--- trunk/Ohana/src/kapa2/src/PaintOverlay.c	(revision 19834)
+++ trunk/Ohana/src/kapa2/src/PaintOverlay.c	(revision 19835)
@@ -6,5 +6,5 @@
   int dX, dY, dx, dy;
   int x, y, Xmin, Ymin, Xmax, Ymax, Xrange, Yrange;
-  double t, expand, X, Y;
+  double t, expand, X, Y, pX, pY;
  
   XSetForeground (graphic[0].display, graphic[0].gc, image[0].overlay[N].color);
@@ -37,4 +37,7 @@
     if (Y - dY > Ymax);
 
+    pX = (image[0].picture.flipx) ? -1.0 : +1.0;
+    pY = (image[0].picture.flipy) ? -1.0 : +1.0;
+
     /* for a LINE, (x, y) is the start, (dx, dy) is the distance to end
        for a CIRCLE (x, y) is the center, (dx, dy) is the radius 
@@ -62,13 +65,20 @@
 	  XDrawArc (graphic[0].display, graphic[0].window, graphic[0].gc, (X - dx), (Y - dy), 2*dx, 2*dy, 0, 23040);
 	} else {
-	  // very stupid rotate ellipse drawing:
+	  // very stupid rotated ellipse drawing:
+	  double x0, y0, x1, y1;
 	  double angle = image[0].overlay[N].objects[i].angle * RAD_DEG;
 	  double cs = cos(angle);
 	  double sn = sin(angle);
+	  x0 = X + pX*dx*cs;
+	  y0 = Y - pY*dx*sn;
 	  // XXX dt should be based on the size of the ellipse...
-	  for (t = 0; t < 2*M_PI; t+=0.05) {
-	    x = X + dx*cos(t)*cs + dy*sin(t)*sn;
-	    y = Y - dx*cos(t)*sn + dy*sin(t)*cs;
-	    XDrawPoint (graphic[0].display, graphic[0].window, graphic[0].gc, x, y);
+	  // 0.10 -> 60 segments on the ellipse
+	  # define DT 0.1
+	  for (t = DT; t < 2*M_PI + DT; t+=DT) {
+	    x1 = X + pX*dx*cos(t)*cs + pX*dy*sin(t)*sn;
+	    y1 = Y - pY*dx*cos(t)*sn + pY*dy*sin(t)*cs;
+	    XDrawLine (graphic[0].display, graphic[0].window, graphic[0].gc, x0, y0, x1, y1);
+	    x0 = x1;
+	    y0 = y1;
 	  }
 	}
