Index: /branches/eam_branches/ipp-20101103/Ohana/src/libkapa/include/kapa.h
===================================================================
--- /branches/eam_branches/ipp-20101103/Ohana/src/libkapa/include/kapa.h	(revision 29813)
+++ /branches/eam_branches/ipp-20101103/Ohana/src/libkapa/include/kapa.h	(revision 29814)
@@ -115,6 +115,15 @@
 
 typedef struct {
-  int Nx, Ny;
+  int Nx, Ny, Nbyte;
   bDrawColor **pixels;
+  png_color *palette;
+  int Npalette;
+  // current drawing values:
+  int bWeight;
+  int bType;
+  bDrawColor bColor;
+  bDrawColor bColor_R;
+  bDrawColor bColor_G;
+  bDrawColor bColor_B;
 } bDrawBuffer;
 
@@ -165,4 +174,5 @@
 /* KapaWindow.c */
 int KiiResize (int fd, int Nx, int Ny);
+int KiiResizeByImage (int fd);
 int KiiRelocate (int fd, int x, int y);
 int KiiCenter (int fd, double x, double y, int zoom);
@@ -182,4 +192,5 @@
 int KapaGetLimits (int fd, float *dx, float *dy);
 int KapaSetSection (int fd, KapaSection *section);
+int KapaSetSectionByImage (int fd, KapaSection *section);
 int KapaSelectSection (int fd, char *name);
 int KapaGetSection (int fd, char *name);
@@ -221,29 +232,29 @@
 
 /* bDrawFuncs.c */
-bDrawBuffer *bDrawBufferCreate (int Nx, int Ny);
+bDrawBuffer *bDrawBufferCreate (int Nx, int Ny, int Nbyte, png_color *palette, int Npalette);
 void bDrawBufferFree (bDrawBuffer *buffer);
 void bDrawSetBuffer (bDrawBuffer *buffer);
-void bDrawSetStyle (bDrawColor color, int lw, int lt);
-void bDrawPoint (int x, int y);
-void bDrawPointf (float x, float y);
-
-void bDrawArc (double Xc, double Yc, double Xr, double Yr, double Ts, double Te);
-void bDrawCircle (double Xc, double Yc, double radius);
-void bDrawCircleFill (double xc, double yc, double radius);
-
-void bDrawLine (double x1, double y1, double x2, double y2);
-void bDrawLineWeight (int X1, int Y1, int X2, int Y2, int swapcoords);
-void bDrawLineBresen (int X1, int Y1, int X2, int Y2, int swapcoords);
-void bDrawLineHorizontal (int X1, int X2, int Y);
-void bDrawLineVertical (int X, int Y1, int Y2);
-
-void bDrawRectOpen (double x1, double y1, double x2, double y2);
-void bDrawRectFill (double x1, double y1, double x2, double y2);
-void bDrawTriOpen (double x1, double y1, double x2, double y2, double x3, double y3);
-void bDrawTriFill (double x1, double y1, double x2, double y2, double x3, double y3);
+void bDrawSetStyle (bDrawBuffer *buffer, bDrawColor color, int lw, int lt);
+void bDrawPoint (bDrawBuffer *buffer, int x, int y);
+void bDrawPointf (bDrawBuffer *buffer, float x, float y);
+
+void bDrawArc (bDrawBuffer *buffer, double Xc, double Yc, double Xr, double Yr, double Ts, double Te);
+void bDrawCircle (bDrawBuffer *buffer, double Xc, double Yc, double radius);
+void bDrawCircleFill (bDrawBuffer *buffer, double xc, double yc, double radius);
+
+void bDrawLine (bDrawBuffer *buffer, double x1, double y1, double x2, double y2);
+void bDrawLineWeight (bDrawBuffer *buffer, int X1, int Y1, int X2, int Y2, int swapcoords);
+void bDrawLineBresen (bDrawBuffer *buffer, int X1, int Y1, int X2, int Y2, int swapcoords);
+void bDrawLineHorizontal (bDrawBuffer *buffer, int X1, int X2, int Y);
+void bDrawLineVertical (bDrawBuffer *buffer, int X, int Y1, int Y2);
+
+void bDrawRectOpen (bDrawBuffer *buffer, double x1, double y1, double x2, double y2);
+void bDrawRectFill (bDrawBuffer *buffer, double x1, double y1, double x2, double y2);
+void bDrawTriOpen  (bDrawBuffer *buffer, double x1, double y1, double x2, double y2, double x3, double y3);
+void bDrawTriFill  (bDrawBuffer *buffer, double x1, double y1, double x2, double y2, double x3, double y3);
 
 /* bDrawRotFont.c */
-int bDrawRotText (int x, int y, char *string, int pos, double angle);
-int bDrawRotBitmap (int x, int y, int dx, int dy, unsigned char *bitmap, int mode, double angle, double scale);
+int bDrawRotText (bDrawBuffer *buffer, int x, int y, char *string, int pos, double angle);
+int bDrawRotBitmap (bDrawBuffer *buffer, int x, int y, int dx, int dy, unsigned char *bitmap, int mode, double angle, double scale);
 
 /* Kapa Socket functions */
Index: /branches/eam_branches/ipp-20101103/Ohana/src/libkapa/src/KapaWindow.c
===================================================================
--- /branches/eam_branches/ipp-20101103/Ohana/src/libkapa/src/KapaWindow.c	(revision 29813)
+++ /branches/eam_branches/ipp-20101103/Ohana/src/libkapa/src/KapaWindow.c	(revision 29814)
@@ -23,4 +23,11 @@
   KiiSendCommand (fd, 4, "RSIZ");
   KiiSendMessage (fd, "%d %d", Nx, Ny); 
+  KiiWaitAnswer (fd, "DONE");
+  return (TRUE);
+}
+
+int KiiResizeByImage (int fd) {
+
+  KiiSendCommand (fd, 4, "ISIZ");
   KiiWaitAnswer (fd, "DONE");
   return (TRUE);
@@ -370,4 +377,16 @@
 }
 
+int KapaSetSectionByImage (int fd, KapaSection *section) {
+
+  KiiSendCommand (fd, 4, "ISEC");
+  KiiSendMessage (fd, "%s %6.3f %6.3f %3d", 
+		  section[0].name, 
+		  section[0].x,
+		  section[0].y,
+		  section[0].bg);
+  KiiWaitAnswer (fd, "DONE");
+  return (TRUE);
+}
+
 int KapaSectionBG (int fd, char *name, int bg) {
 
Index: /branches/eam_branches/ipp-20101103/Ohana/src/libkapa/src/bDrawFuncs.c
===================================================================
--- /branches/eam_branches/ipp-20101103/Ohana/src/libkapa/src/bDrawFuncs.c	(revision 29813)
+++ /branches/eam_branches/ipp-20101103/Ohana/src/libkapa/src/bDrawFuncs.c	(revision 29814)
@@ -1,33 +1,58 @@
 # include <kapa_internal.h>
-
-// XXX we can get rid of these static vars by making them elements of the bDrawBuffer
-// 
-
-
-static int bWeight;
-static int bType;
-static bDrawColor bColor;
-static bDrawBuffer *bBuffer;
-void bDrawCircleSingle (double xc, double yc, double radius);
-
-bDrawBuffer *bDrawBufferCreate (int Nx, int Ny) {
+# define myAssert(LOGIC,MSG) { if (!(LOGIC)) { fprintf (stderr, "%s\n", MSG); abort (); } }
+
+// move these to the bDrawBuffer type
+// static int bWeight;
+// static int bType;
+// static bDrawColor bColor;
+// static bDrawColor bColor_R;
+// static bDrawColor bColor_G;
+// static bDrawColor bColor_B;
+// static bDrawBuffer *bBuffer;
+
+void bDrawCircleSingle (bDrawBuffer *buffer, double xc, double yc, double radius);
+
+// create a drawing buffer with either 1 or 3 byte colors
+bDrawBuffer *bDrawBufferCreate (int Nx, int Ny, int Nbyte, png_color *palette, int Npalette) {
 
   int i, j;
-  bDrawColor white;
+  bDrawColor white, white_R, white_G, white_B;
   bDrawBuffer *buffer;
 
+  myAssert((Nbyte == 1) || (Nbyte == 3), "invalid depth");
+  myAssert(palette, "missing palette");
+
   white = KapaColorByName ("white");
+  white_R = palette[white].red;
+  white_G = palette[white].green;
+  white_B = palette[white].blue;
 
   ALLOCATE (buffer, bDrawBuffer, 1);
   buffer[0].Nx = Nx;
   buffer[0].Ny = Ny;
+  buffer[0].Nbyte = Nbyte;
+  buffer[0].palette = palette;
+  buffer[0].Npalette = Npalette;
 
   ALLOCATE (buffer[0].pixels, bDrawColor *, Ny);
   for (i = 0; i < Ny; i++) {
-    ALLOCATE (buffer[0].pixels[i], bDrawColor, Nx);
+    ALLOCATE (buffer[0].pixels[i], bDrawColor, Nbyte*Nx);
     for (j = 0; j < Nx; j++) {
-      buffer[0].pixels[i][j] = white;
-    }
-  }
+      if (Nbyte == 1) {
+	buffer[0].pixels[i][j] = white;
+      } else {
+	buffer[0].pixels[i][3*j+0] = white_R;
+	buffer[0].pixels[i][3*j+1] = white_G;
+	buffer[0].pixels[i][3*j+2] = white_B;
+      }
+    }
+  }
+
+  buffer[0].bWeight = 0;
+  buffer[0].bType = 0;
+  buffer[0].bColor = white;
+  buffer[0].bColor_R = white_R;
+  buffer[0].bColor_G = white_G;
+  buffer[0].bColor_B = white_B;
   return (buffer);
 }
@@ -41,48 +66,60 @@
   }
   free (buffer[0].pixels);
+  free (buffer[0].palette);
   free (buffer);
   return;
 }
 
-void bDrawSetBuffer (bDrawBuffer *buffer) {
-  bBuffer = buffer;
-  return;
-}
-
-void bDrawSetStyle (bDrawColor color, int lw, int lt) {
-  bColor = color;
-  bWeight = lw;
-  bType = lt;
+// void bDrawSetBuffer (bDrawBuffer *buffer) {
+//   myAssert(buffer[0].Nbyte == 1, "invalid depth");
+//   bBuffer = buffer;
+//   return;
+// }
+
+void bDrawSetStyle (bDrawBuffer *buffer, bDrawColor color, int lw, int lt) {
+  buffer->bColor = color;
+  buffer->bColor_R = buffer->palette[color].red;
+  buffer->bColor_G = buffer->palette[color].green;
+  buffer->bColor_B = buffer->palette[color].blue;
+  buffer->bWeight = lw;
+  buffer->bType = lt;
   return;
 }
 
 // draw a point in the current color 
-void bDrawPoint (int x, int y) {
-
+void bDrawPoint (bDrawBuffer *buffer, int x, int y) {
+
+  // myAssert(buffer[0].Nbyte == 1, "invalid depth");
   if (x < 0) return;
   if (y < 0) return;
-  if (x >= bBuffer[0].Nx) return;
-  if (y >= bBuffer[0].Ny) return;
-  bBuffer[0].pixels[y][x] = bColor;
+  if (x >= buffer[0].Nx) return;
+  if (y >= buffer[0].Ny) return;
+  if (buffer[0].Nbyte == 1) {
+    buffer[0].pixels[y][x] = buffer->bColor;
+  } else {
+    buffer[0].pixels[y][3*x+0] = buffer->bColor_R;
+    buffer[0].pixels[y][3*x+1] = buffer->bColor_G;
+    buffer[0].pixels[y][3*x+2] = buffer->bColor_B;
+  }
   return;
 }
 
 // draw a point in the current color 
-void bDrawPointf (float x, float y) {
-
-  bDrawPoint (ROUND(x), ROUND(y));
-  return;
-}
-
-void bDrawTriOpen (double x1, double y1, double x2, double y2, double x3, double y3) {
-
-  bDrawLine (x1, y1, x2, y2);
-  bDrawLine (x2, y2, x3, y3);
-  bDrawLine (x3, y3, x1, y1);
-
-  return;
-}
-
-void bDrawRectOpen (double x1, double y1, double x2, double y2) {
+void bDrawPointf (bDrawBuffer *buffer, float x, float y) {
+
+  bDrawPoint (buffer, ROUND(x), ROUND(y));
+  return;
+}
+
+void bDrawTriOpen (bDrawBuffer *buffer, double x1, double y1, double x2, double y2, double x3, double y3) {
+
+  bDrawLine (buffer, x1, y1, x2, y2);
+  bDrawLine (buffer, x2, y2, x3, y3);
+  bDrawLine (buffer, x3, y3, x1, y1);
+
+  return;
+}
+
+void bDrawRectOpen (bDrawBuffer *buffer, double x1, double y1, double x2, double y2) {
 
   int X1, Y1, X2, Y2;
@@ -91,18 +128,18 @@
   if (y1 > y2) SWAP (y1, y2);
 
-  X1 = MIN (MAX (ROUND (x1), 0), bBuffer[0].Nx - 1);
-  X2 = MIN (MAX (ROUND (x2), 1), bBuffer[0].Nx - 1);
-
-  Y1 = MIN (MAX (ROUND (y1), 0), bBuffer[0].Ny - 1);
-  Y2 = MIN (MAX (ROUND (y2), 1), bBuffer[0].Ny - 1);
-
-  bDrawLineHorizontal (X1, X2, Y1);
-  bDrawLineHorizontal (X1, X2, Y2);
-  bDrawLineVertical (X1, Y1, Y2);
-  bDrawLineVertical (X2, Y1, Y2);
-  return;
-}
-
-void bDrawRectFill (double x1, double y1, double x2, double y2) {
+  X1 = MIN (MAX (ROUND (x1), 0), buffer[0].Nx - 1);
+  X2 = MIN (MAX (ROUND (x2), 1), buffer[0].Nx - 1);
+
+  Y1 = MIN (MAX (ROUND (y1), 0), buffer[0].Ny - 1);
+  Y2 = MIN (MAX (ROUND (y2), 1), buffer[0].Ny - 1);
+
+  bDrawLineHorizontal (buffer, X1, X2, Y1);
+  bDrawLineHorizontal (buffer, X1, X2, Y2);
+  bDrawLineVertical   (buffer, X1, Y1, Y2);
+  bDrawLineVertical   (buffer, X2, Y1, Y2);
+  return;
+}
+
+void bDrawRectFill (bDrawBuffer *buffer, double x1, double y1, double x2, double y2) {
 
   int i;
@@ -112,12 +149,12 @@
   if (y1 > y2) SWAP (y1, y2);
 
-  X1 = MIN (MAX (ROUND (x1), 0), bBuffer[0].Nx - 1);
-  X2 = MIN (MAX (ROUND (x2), 1), bBuffer[0].Nx - 1);
-
-  Y1 = MIN (MAX (ROUND (y1), 0), bBuffer[0].Ny - 1);
-  Y2 = MIN (MAX (ROUND (y2), 0), bBuffer[0].Ny - 1);
+  X1 = MIN (MAX (ROUND (x1), 0), buffer[0].Nx - 1);
+  X2 = MIN (MAX (ROUND (x2), 1), buffer[0].Nx - 1);
+
+  Y1 = MIN (MAX (ROUND (y1), 0), buffer[0].Ny - 1);
+  Y2 = MIN (MAX (ROUND (y2), 0), buffer[0].Ny - 1);
 
   for (i = Y1; i < Y2; i++) {
-    bDrawLineHorizontal (X1, X2, i);
+    bDrawLineHorizontal (buffer, X1, X2, i);
   } 
   return;
@@ -125,5 +162,5 @@
 
 // identify the quadrant and draw the correct line
-void bDrawLine (double x1, double y1, double x2, double y2) {
+void bDrawLine (bDrawBuffer *buffer, double x1, double y1, double x2, double y2) {
 
   int FlipDirect, FlipCoords;
@@ -144,8 +181,8 @@
   FlipDirect = FlipCoords ? (y1 > y2) : (x1 > x2);
 
-  if (!FlipDirect && !FlipCoords) bDrawLineWeight (X1, Y1, X2, Y2, FALSE);
-  if ( FlipDirect && !FlipCoords) bDrawLineWeight (X2, Y2, X1, Y1, FALSE);
-  if (!FlipDirect &&  FlipCoords) bDrawLineWeight (Y1, X1, Y2, X2, TRUE);
-  if ( FlipDirect &&  FlipCoords) bDrawLineWeight (Y2, X2, Y1, X1, TRUE);
+  if (!FlipDirect && !FlipCoords) bDrawLineWeight (buffer, X1, Y1, X2, Y2, FALSE);
+  if ( FlipDirect && !FlipCoords) bDrawLineWeight (buffer, X2, Y2, X1, Y1, FALSE);
+  if (!FlipDirect &&  FlipCoords) bDrawLineWeight (buffer, Y1, X1, Y2, X2, TRUE);
+  if ( FlipDirect &&  FlipCoords) bDrawLineWeight (buffer, Y2, X2, Y1, X1, TRUE);
 
   return;
@@ -153,16 +190,16 @@
 
 // draw a series of lines to give the line weight
-void bDrawLineWeight (int X1, int Y1, int X2, int Y2, int swapcoords) {
+void bDrawLineWeight (bDrawBuffer *buffer, int X1, int Y1, int X2, int Y2, int swapcoords) {
 
   int dN, dNs, dNe;
 
-  dNs = -0.5*(bWeight - 1); 
+  dNs = -0.5*(buffer->bWeight - 1); 
   /* 0, 0, 0, -1, -1, -2, -2 */
 
-  dNe = +0.5*bWeight + 1; 
+  dNe = +0.5*buffer->bWeight + 1; 
   /* 1, 1, 2, 2, 2, 3, 3 */
 
   for (dN = dNs; dN < dNe; dN++) {
-    bDrawLineBresen (X1, Y1 + dN, X2, Y2 + dN, swapcoords);
+    bDrawLineBresen (buffer, X1, Y1 + dN, X2, Y2 + dN, swapcoords);
   }
   return;
@@ -171,5 +208,5 @@
 // use the Bresenham line drawing technique
 // integer-only Bresenham line-draw version which is fast
-void bDrawLineBresen (int X1, int Y1, int X2, int Y2, int swapcoords) {
+void bDrawLineBresen (bDrawBuffer *buffer, int X1, int Y1, int X2, int Y2, int swapcoords) {
 
   int X, Y, dX, dY;
@@ -185,10 +222,10 @@
   e = 0;
   for (X = X1, N = 0; X <= X2; X++, N++) {
-    if (bType == 1) { DashOn = (N % 10) < 5; }
-    if (bType == 2) { DashOn = (N % 6) < 3; }
+    if (buffer->bType == 1) { DashOn = (N % 10) < 5; }
+    if (buffer->bType == 2) { DashOn = (N % 6) < 3; }
     if (swapcoords) {
-      if (DashOn) bDrawPoint (Y,X);
+      if (DashOn) bDrawPoint (buffer, Y,X);
     } else {
-      if (DashOn) bDrawPoint (X,Y);
+      if (DashOn) bDrawPoint (buffer, X,Y);
     }
     e += dY;
@@ -206,31 +243,43 @@
 }
 
-void bDrawLineHorizontal (int X1, int X2, int Y) {
+void bDrawLineHorizontal (bDrawBuffer *buffer, int X1, int X2, int Y) {
   
   int i;
 
   for (i = X1; i < X2; i++) {
-    bBuffer[0].pixels[Y][i] = bColor;
-  }
-  return;
-}
-
-void bDrawLineVertical (int X, int Y1, int Y2) {
+    if (buffer[0].Nbyte == 1) {
+      buffer[0].pixels[Y][i] = buffer->bColor;
+    } else {
+      buffer[0].pixels[Y][3*i+0] = buffer->bColor_R;
+      buffer[0].pixels[Y][3*i+1] = buffer->bColor_G;
+      buffer[0].pixels[Y][3*i+2] = buffer->bColor_B;
+    }
+  }
+  return;
+}
+
+void bDrawLineVertical (bDrawBuffer *buffer, int X, int Y1, int Y2) {
   
   int i;
 
   for (i = Y1; i < Y2; i++) {
-    bBuffer[0].pixels[i][X] = bColor;
-  }
-  return;
-}
-
-void bDrawTriFill (double x1, double y1, double x2, double y2, double x3, double y3) {
-
-  bDrawTriOpen (x1, y1, x2, y2, x3, y3);
-  return;
-}
-
-void bDrawArc (double Xc, double Yc, double Xr, double Yr, double Ts, double Te) {
+    if (buffer[0].Nbyte == 1) {
+      buffer[0].pixels[i][X] = buffer->bColor;
+    } else {
+      buffer[0].pixels[i][3*X+0] = buffer->bColor_R;
+      buffer[0].pixels[i][3*X+1] = buffer->bColor_G;
+      buffer[0].pixels[i][3*X+2] = buffer->bColor_B;
+    }
+  }
+  return;
+}
+
+void bDrawTriFill (bDrawBuffer *buffer, double x1, double y1, double x2, double y2, double x3, double y3) {
+
+  bDrawTriOpen (buffer, x1, y1, x2, y2, x3, y3);
+  return;
+}
+
+void bDrawArc (bDrawBuffer *buffer, double Xc, double Yc, double Xr, double Yr, double Ts, double Te) {
 
   float t, dt;
@@ -258,5 +307,5 @@
 
     /* we could use the value of MAX(dy/dt,dx/dt) to set dt */
-    bDrawPoint (x,y);
+    bDrawPoint (buffer, x,y);
 
     dt = MAX (fabs(Xr * sin(t)), fabs(Yr * cos(t)));
@@ -267,16 +316,16 @@
 
 // draw a series of circles to give line weight
-void bDrawCircle (double xc, double yc, double radius) {
+void bDrawCircle (bDrawBuffer *buffer, double xc, double yc, double radius) {
 
   int dN, dNs, dNe;
 
-  dNs = -0.5*(bWeight - 1); 
+  dNs = -0.5*(buffer->bWeight - 1); 
   /* 0, 0, 0, -1, -1, -2, -2 */
 
-  dNe = +0.5*bWeight + 1; 
+  dNe = +0.5*buffer->bWeight + 1; 
   /* 1, 1, 2, 2, 2, 3, 3 */
 
   for (dN = dNs; dN < dNe; dN++) {
-    bDrawCircleSingle (xc, yc, radius + dN);
+    bDrawCircleSingle (buffer, xc, yc, radius + dN);
   }
   return;
@@ -284,5 +333,5 @@
 
 // draw a pure circle  
-void bDrawCircleSingle (double xc, double yc, double radius) {
+void bDrawCircleSingle (bDrawBuffer *buffer, double xc, double yc, double radius) {
 
   int Xc, Yc, Radius;
@@ -300,12 +349,12 @@
 
   while (x <= y) {
-    bDrawPoint (Xc+x, Yc+y);
-    bDrawPoint (Xc+x, Yc-y);
-    bDrawPoint (Xc-x, Yc+y);
-    bDrawPoint (Xc-x, Yc-y);
-    bDrawPoint (Xc+y, Yc+x);
-    bDrawPoint (Xc+y, Yc-x);
-    bDrawPoint (Xc-y, Yc+x);
-    bDrawPoint (Xc-y, Yc-x);
+    bDrawPoint (buffer, Xc+x, Yc+y);
+    bDrawPoint (buffer, Xc+x, Yc-y);
+    bDrawPoint (buffer, Xc-x, Yc+y);
+    bDrawPoint (buffer, Xc-x, Yc-y);
+    bDrawPoint (buffer, Xc+y, Yc+x);
+    bDrawPoint (buffer, Xc+y, Yc-x);
+    bDrawPoint (buffer, Xc-y, Yc+x);
+    bDrawPoint (buffer, Xc-y, Yc-x);
 
     if (d < 0) {
@@ -322,5 +371,5 @@
 
 // draw a pure circle  
-void bDrawCircleFill (double xc, double yc, double radius) {
+void bDrawCircleFill (bDrawBuffer *buffer, double xc, double yc, double radius) {
 
   int Xc, Yc, Radius;
@@ -338,8 +387,8 @@
 
   while (x <= y) {
-    bDrawLineHorizontal (Xc-x, Xc+x, Yc+y);
-    bDrawLineHorizontal (Xc-x, Xc+x, Yc-y);
-    bDrawLineHorizontal (Xc-y, Xc+y, Yc+x);
-    bDrawLineHorizontal (Xc-y, Xc+y, Yc-x);
+    bDrawLineHorizontal (buffer, Xc-x, Xc+x, Yc+y);
+    bDrawLineHorizontal (buffer, Xc-x, Xc+x, Yc-y);
+    bDrawLineHorizontal (buffer, Xc-y, Xc+y, Yc+x);
+    bDrawLineHorizontal (buffer, Xc-y, Xc+y, Yc-x);
 
     if (d < 0) {
Index: /branches/eam_branches/ipp-20101103/Ohana/src/libkapa/src/bDrawRotFont.c
===================================================================
--- /branches/eam_branches/ipp-20101103/Ohana/src/libkapa/src/bDrawRotFont.c	(revision 29813)
+++ /branches/eam_branches/ipp-20101103/Ohana/src/libkapa/src/bDrawRotFont.c	(revision 29814)
@@ -6,8 +6,9 @@
 # define NEARINT(x) ((x < 0) ? ((int)(x - 0.5)) : ((int)(x + 0.5)))
   
-static bDrawColor black;
-static bDrawColor white;
-
-int bDrawRotText (int x, int y, char *string, int pos, double angle) {
+// XXX need to pass the rot text color here
+// static bDrawColor black;
+// static bDrawColor white;
+
+int bDrawRotText (bDrawBuffer *buffer, int x, int y, char *string, int pos, double angle) {
 
   unsigned char *bitmap;
@@ -19,6 +20,6 @@
   RotFont *currentfont;
 
-  white = KapaColorByName ("white");
-  black = KapaColorByName ("black");
+  // white = KapaColorByName ("white");
+  // black = KapaColorByName ("black");
 
   currentname = GetRotFont (&currentsize);
@@ -111,5 +112,5 @@
     X = x + (int)(Xoff*cs - Yoff*sn) + (int)(currentscale*currentfont[N].ascent*sn);
     Y = y + (int)(Xoff*sn + Yoff*cs) - (int)(currentscale*currentfont[N].ascent*cs);
-    bDrawRotBitmap (X, Y, dx, dy, bitmap, TRUE, angle, currentscale);
+    bDrawRotBitmap (buffer, X, Y, dx, dy, bitmap, TRUE, angle, currentscale);
     Xoff += 1 + (int)(currentscale*dx + 0.5);
   }
@@ -118,17 +119,16 @@
 }
 
-int bDrawRotBitmap (int x, int y, int dx, int dy, unsigned char *bitmap, int mode, double angle, double scale) {
+int bDrawRotBitmap (bDrawBuffer *buffer, int x, int y, int dx, int dy, unsigned char *bitmap, int mode, double angle, double scale) {
 
   int ii, jj, byte_line, byte, bit, flag;
-  bDrawColor color;
   double i, j, cs, sn, rscale, tmp;
   int X, Y, X0, X1, X2, Y0, Y1, Y2, x0, y0;
 
   /* this mode option is nort actually used... */
-  if (mode) {
-    color = black;
-  } else {
-    color = white;
-  } 
+  // if (mode) {
+  //   color = black;
+  // } else {
+  //   color = white;
+  // } 
     
   byte_line = (int) ((dx + 7) / 8);
@@ -148,5 +148,5 @@
   Y = YPROC (dx,0);
 # ifdef DRAWBOXES
-  bDrawLine (x+X, y+Y, x+X1, y+Y1);
+  bDrawLine (buffer, x+X, y+Y, x+X1, y+Y1);
   Xt = X;
   Yt = Y;
@@ -160,5 +160,5 @@
   Y = YPROC (dx,dy);
 # ifdef DRAWBOXES
-  bDrawLine (x+X, y+Y, x+Xt, y+Yt);
+  bDrawLine (buffer, x+X, y+Y, x+Xt, y+Yt);
   Xt = X;
   Yt = Y;
@@ -172,5 +172,5 @@
   Y = YPROC (0,dy);
 # ifdef DRAWBOXES
-  bDrawLine (x+X, y+Y, x+Xt, y+Yt);
+  bDrawLine (buffer, x+X, y+Y, x+Xt, y+Yt);
   Xt = X;
   Yt = Y;
@@ -181,5 +181,5 @@
   X2 = MAX (X, X2);
 
-  bDrawSetStyle (color, 0, 0);
+  // bDrawSetStyle (color, 0, 0);
   if (scale > 1) {
     for (i = X1; i <= X2; i+=1) {
@@ -191,5 +191,5 @@
 	bit = ii % 8;
 	flag = 0x01 & (bitmap[byte] >> bit);
-	if (flag) bDrawPointf (x + i, y + j);
+	if (flag) bDrawPointf (buffer, x + i, y + j);
       }
     }
@@ -203,9 +203,9 @@
 	bit = ii % 8;
 	flag = 0x01 & (bitmap[byte] >> bit);
-	if (flag) bDrawPointf (x + i, y + j);
+	if (flag) bDrawPointf (buffer, x + i, y + j);
       }
     }
   }
-  bDrawSetStyle (black, 0, 0);
+  // bDrawSetStyle (black, 0, 0);
   return (TRUE);
 }
