Пример #1
0
static inline void iPlotDrawRotatedText(cdCanvas* canvas, double inX, double inY, double inDegrees, int inAlignment, const char *inString)
{
  cdCanvasTextAlignment(canvas, inAlignment);
  double theOldOrientation = cdCanvasTextOrientation(canvas, inDegrees);
  cdfCanvasText(canvas, inX, inY, inString);
  cdCanvasTextOrientation(canvas, theOldOrientation);
}
Пример #2
0
static int draw_cb(Ihandle* h, int i, int j, int xmin, int xmax, int ymin, int ymax, cdCanvas* canvas)
{
    int xm = (xmax + xmin) / 2;
    int ym = (ymax + ymin) / 2;
    static char buffer[64];

    if (i == 1 && j == 2) return IUP_DEFAULT;
    if (i == 2 && j == 1) return IUP_DEFAULT;
    if (i == 2 && j == 2) return IUP_DEFAULT;
    if (i == 5 && j == 6) return IUP_DEFAULT;
    if (i == 6 && j == 5) return IUP_DEFAULT;
    if (i == 6 && j == 6) return IUP_DEFAULT;

    if (i == 1 && j == 1)
        cdCanvasForeground(canvas, CD_WHITE);
    else
        cdCanvasForeground(canvas, cdEncodeColor(
                               (unsigned char)(i*20),
                               (unsigned char)(j*100),
                               (unsigned char)(i+100)));
    cdCanvasBox(canvas, xmin, xmax, ymin, ymax);
    cdCanvasTextAlignment(canvas, CD_CENTER);
    cdCanvasForeground(canvas, CD_BLACK);
    sprintf(buffer, "(%02d, %02d)", i, j);
    cdCanvasText(canvas, xm, ym, buffer);

    return IUP_DEFAULT;
}
Пример #3
0
int postdraw_cb(Ihandle* ih, cdCanvas* cnv)
{
  int ix, iy;
  IupPPlotTransform(ih, 0.003f, 0.02f, &ix, &iy);
  cdCanvasFont(cnv, NULL, CD_BOLD, 10);
  cdCanvasTextAlignment(cnv, CD_SOUTH);
  cdCanvasText(cnv, ix, iy, "My Inline Legend");
  printf("POSTDRAW_CB()\n");
  return IUP_DEFAULT;
}
Пример #4
0
void primUpdateAttrib_Text(tPrimNode *prim, cdCanvas *canvas)
{
  cdCanvasSetForeground(canvas, prim->attrib.text.foreground);
  cdCanvasTextAlignment(canvas, prim->attrib.text.text_alignment);
  cdCanvasTextOrientation(canvas, prim->attrib.text.text_orientation);

  if (canvas->native_font[0])
    cdCanvasNativeFont(canvas, prim->attrib.text.native_font);
  else
    cdCanvasFont(canvas, prim->attrib.text.font_type_face, prim->attrib.text.font_style, prim->attrib.text.font_size);
}
Пример #5
0
void iupPlot::DrawTitle(cdCanvas* canvas) const
{
  if (mTitle.GetText())
  {
    cdCanvasSetForeground(canvas, mTitle.mColor);

    SetTitleFont(canvas);

    cdCanvasTextAlignment(canvas, CD_NORTH);
    cdCanvasText(canvas, mTitle.mPosX, mTitle.mPosY, mTitle.GetText());
  }
}
Пример #6
0
void SimpleDrawTextFonts(cdCanvas* canvas)
{
  int xoff, yoff, size;

  cdCanvasBackground(canvas, CD_WHITE);
  cdCanvasClear(canvas);

  xoff = 470;
  yoff = 150;
  size = -30;

  cdCanvasTextAlignment(canvas, CD_CENTER);

  DrawTextFont(canvas, "Courier", size, xoff, yoff, "Courier");
  DrawTextFont(canvas, "Times", size, xoff, 2*yoff, "Times Roman");
  DrawTextFont(canvas, "Helvetica", size, xoff, 3*yoff, "Helvetica");
  DrawTextFont(canvas, "System", size, xoff, 4*yoff, "System");

  {
//    static char native[50] = "Tecmedia, -60";
//    static char native[50] = "-*-helvetica-medium-r-*-*-8-*";
//    static char native[50] = "Edwardian Script ITC, 24";
//    cdSetAttribute("ADDFONTMAP","Edwardian Script ITC=ITCEDSCR");

//    char native[50] = "Book Antiqua, 24";
//    cdSetAttribute("ADDFONTMAP", "Book Antiqua=BKANT");

//    cdNativeFont("-d");
//    cdNativeFont(native);
//    DrawTextBox(xoff, yoff, native);
//    DrawTextBox(xoff, yoff, "The quick brown fox.");
  }

  //cdNativeFont("Tecmedia, 36");

  //cdSetAttribute("ADDFONTMAP", "WingDings=WingDing");
  //cdNativeFont("WingDings, 36");

  //cdText(500, 50, "X");
  //cdText(500, 50, "abcdefghijklmnopqrstuvwxyz");
  //cdText(500, 150, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
  //cdText(500, 250, "1234567890");
  //cdText(500, 350, "'\"!@#$%¨&*()_+-=[]^/;.,");

  //cdFont(CD_COURIER, 0, 22);
  //cdText(10, 60, "abcdefghijklmnopqrstuvwxyz");
  //cdText(10, 160, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
  //cdText(10, 260, "1234567890");
  //cdText(500, 360, "'\"!@#$%¨&*()_+-=[]^/;.,");
}
Пример #7
0
static void iGaugeDrawText(Ihandle* ih, int xmid)
{
  int x, y, xmin, xmax, ymin, ymax;
  char* text = ih->data->text;

  cdIupSetFont(ih, ih->data->cddbuffer, IupGetAttribute(ih, "FONT"));
  cdCanvasTextAlignment(ih->data->cddbuffer, CD_CENTER);
  cdCanvasBackOpacity(ih->data->cddbuffer, CD_TRANSPARENT);

  x = (int)(0.5 * ih->data->w);
  y = (int)(0.5 * ih->data->h);

  if(text == NULL)
  {
    char* m = iupStrGetMemory(30);
    sprintf(m, "%.1f%%", 100 * (ih->data->value - ih->data->vmin) / (ih->data->vmax - ih->data->vmin));
    text = m;
  }

  cdCanvasGetTextBox(ih->data->cddbuffer, x, y, text, &xmin, &xmax, &ymin, &ymax);

  if(xmid < xmin)
  {
    cdCanvasForeground(ih->data->cddbuffer, ih->data->fgcolor);
    cdCanvasText(ih->data->cddbuffer, x, y, text);
  }
  else if(xmid > xmax)
  {
    cdCanvasForeground(ih->data->cddbuffer, ih->data->bgcolor);
    cdCanvasText(ih->data->cddbuffer, x, y, text);
  }
  else
  {
    cdCanvasClip(ih->data->cddbuffer, CD_CLIPAREA);
    cdCanvasClipArea(ih->data->cddbuffer, xmin, xmid, ymin, ymax);
    cdCanvasForeground(ih->data->cddbuffer, ih->data->bgcolor);
    cdCanvasText(ih->data->cddbuffer, x, y, text);

    cdCanvasClipArea(ih->data->cddbuffer, xmid, xmax, ymin, ymax);
    cdCanvasForeground(ih->data->cddbuffer, ih->data->fgcolor);
    cdCanvasText(ih->data->cddbuffer, x, y, text);
    cdCanvasClip(ih->data->cddbuffer, CD_CLIPOFF);
  }
}
Пример #8
0
bool iupPlot::CheckInsideTitle(cdCanvas* canvas, int x, int y)
{
  // it does not depend on theMargin
  if (mTitle.GetText())
  {
    SetTitleFont(canvas);

    cdCanvasTextAlignment(canvas, CD_NORTH);

    int xmin, xmax, ymin, ymax;
    cdCanvasGetTextBox(canvas, mTitle.mPosX, mTitle.mPosY, mTitle.GetText(), &xmin, &xmax, &ymin, &ymax);

    if (x >= xmin && x <= xmax && 
        y >= ymin && y <= ymax)
      return true;
  }

  return false;
}
Пример #9
0
static void iMatrixDrawFill(Ihandle* ih, int x1, int x2, int y1, int y2, int marked, int active, int lin, int col, const char* value, long framecolor)
{    
  int empty, fill=0;

  iupStrToInt(value, &fill);
  if (fill < 0) fill = 0;
  if (fill > 100) fill = 100;

  /* Create an space between text and cell frame */
  x1 += IMAT_PADDING_W/2;       x2 -= IMAT_PADDING_W/2;
  y1 += IMAT_PADDING_H/2;       y2 -= IMAT_PADDING_H/2;

  empty = ((x2-x1)*(100-fill))/100;

  /* Fill the box with the color */
  iMatrixDrawSetFgColor(ih, lin, col, marked, active);
  iupMATRIX_BOX(ih, x1, x2 - empty, y1, y2);

  if (ih->data->show_fill_value)
  {
    int y = (int)((y1 + y2) / 2.0 - 0.5);
    int empty1 = ((x2-x1)*fill)/100;
    char text[50];
    sprintf(text, "%d%%", fill);
    IupCdSetFont(ih, ih->data->cd_canvas, iupMatrixGetFont(ih, lin, col));
    cdCanvasTextAlignment(ih->data->cd_canvas, CD_CENTER);

    iMatrixDrawSetCellClipping(ih, x1 + empty1, x2, y1, y2);
    iupMATRIX_TEXT(ih, (x1 + x2) / 2, y, text);
    iMatrixDrawResetCellClipping(ih);

    iMatrixDrawSetBgColor(ih, lin, col, marked, active);
    iMatrixDrawSetCellClipping(ih, x1, x2 - empty, y1, y2);
    iupMATRIX_TEXT(ih, (x1 + x2) / 2, y, text);
    iMatrixDrawResetCellClipping(ih);
  }


  /* Draw the frame */
  cdCanvasForeground(ih->data->cd_canvas, framecolor);
  iupMATRIX_RECT(ih, x1, x2, y1, y2);
}
Пример #10
0
static void cdcgm_TextAttrib(const char* horiz_align, const char* vert_align, const char* font, double height, cgmRGB color, cgmPoint base_dir, cdCGM* cd_cgm)
{
  char* str, type_face[256];
  double angle;

  int style = CD_BASE_LEFT;
  if (strcmp(horiz_align, "LEFT")==0)
  {
    if (strcmp(vert_align, "TOP")==0 ||
        strcmp(vert_align, "CAP")==0)     /* no CAP support in CD */
      style = CD_NORTH_WEST;
    else if (strcmp(vert_align, "CENTER")==0)
      style = CD_WEST;
    else if (strcmp(vert_align, "BASELINE")==0)
      style = CD_BASE_LEFT;
    else if (strcmp(vert_align, "BOTTOM")==0)
      style = CD_SOUTH_WEST;
  }
  else if (strcmp(horiz_align, "CENTER")==0)
  {
    if (strcmp(vert_align, "TOP")==0 ||
        strcmp(vert_align, "CAP")==0)     /* no CAP support in CD */
      style = CD_NORTH;
    else if (strcmp(vert_align, "CENTER")==0)
      style = CD_CENTER;
    else if (strcmp(vert_align, "BASELINE")==0)
      style = CD_BASE_CENTER;
    else if (strcmp(vert_align, "BOTTOM")==0)
      style = CD_SOUTH;
  }
  else if (strcmp(horiz_align, "RIGHT")==0)
  {
    if (strcmp(vert_align, "TOP")==0 ||
        strcmp(vert_align, "CAP")==0)     /* no CAP support in CD */
      style = CD_NORTH_EAST;
    else if (strcmp(vert_align, "CENTER")==0)
      style = CD_EAST;
    else if (strcmp(vert_align, "BASELINE")==0)
      style = CD_BASE_RIGHT;
    else if (strcmp(vert_align, "BOTTOM")==0)
      style = CD_SOUTH_EAST;
  }

  cdCanvasTextAlignment(cd_cgm->canvas, style);

  angle = atan2(sScaleH(base_dir.y), sScaleW(base_dir.x))*CD_RAD2DEG;
  cdCanvasTextOrientation(cd_cgm->canvas, angle);

  style = CD_PLAIN;
  str = strstr(font, "BOLD");
  if (!str) str = strstr(font, "Bold");
  if (str)
    style |= CD_BOLD;
  str = strstr(font, "ITALIC");
  if (!str) str = strstr(font, "Italic");
  if (!str) str = strstr(font, "OBLIQUE");
  if (!str) str = strstr(font, "Oblique");
  if (str)
    style |= CD_ITALIC;

  str = strstr(font, "_");
  if (!str) str = strstr(font, "-");
  if (str)
    strncpy(type_face, font, str-font);
  else
    strcpy(type_face, font);

  height = sScaleH(height);
  if (height < 5) height = 5;

  cdCanvasFont(cd_cgm->canvas, type_face, style, sRound(-height));  /* always in vdc (pixels) */

  cdCanvasForeground(cd_cgm->canvas, cdEncodeColor(color.red, color.green, color.blue));
}
Пример #11
0
void SimpleDrawTest(cdCanvas* canvas)
//void SimpleDrawMainTest(cdCanvas* canvas)
{
  long pattern[16];  /* 4x4 pattern */
  int w, h;
  int xmin, xmax, ymin, ymax;

/* notice that if we are not using world coordinates 
   it is harder to position all the objetcs we want. */
  cdCanvasGetSize(canvas, &w, &h, 0, 0);

  cdCanvasBackground(canvas, CD_WHITE);
  cdCanvasClear(canvas);

/* pattern initialization */
  pattern[0]  = CD_RED;    pattern[1]  = CD_RED;    /* first line */
  pattern[2]  = CD_YELLOW; pattern[3]  = CD_YELLOW;
  pattern[4]  = CD_RED;    pattern[5]  = CD_RED;    /* second line */
  pattern[6]  = CD_YELLOW; pattern[7]  = CD_YELLOW;
  pattern[8]  = CD_YELLOW; pattern[9]  = CD_YELLOW; /* third line */
  pattern[10] = CD_YELLOW; pattern[11] = CD_YELLOW;
  pattern[12] = CD_YELLOW; pattern[13] = CD_YELLOW; /* fourth line */
  pattern[14] = CD_YELLOW; pattern[15] = CD_YELLOW;

/* set the line attributes */
  cdCanvasLineWidth(canvas, 4);
  cdCanvasLineStyle(canvas, CD_CONTINUOUS);

/* in the center draw a pattern pizza 
   with a slice mising */
  cdCanvasPattern(canvas, 4, 4, pattern);
  cdCanvasSector(canvas, w/2, h/2, w/2, h/2, 45, 0);
/* draws a dark red border */
  cdCanvasForeground(canvas, CD_DARK_RED);
  cdCanvasInteriorStyle(canvas, CD_HOLLOW);
  cdCanvasSector(canvas, w/2, h/2, w/2, h/2, 45, 0);

/* on the left a red hash diamond */
/* notice the the default back opacity is transparent
   and the pattern of the sector will still be visible
   inside the hatch where the two objects intersect */
  cdCanvasForeground(canvas, CD_RED);
  cdCanvasHatch(canvas, CD_DIAGCROSS); 
  cdCanvasBegin(canvas, CD_FILL);
  cdCanvasVertex(canvas, w/4, h/4); 
  cdCanvasVertex(canvas, w/2-w/8, h/2); 
  cdCanvasVertex(canvas, w/4, 3*h/4); 
  cdCanvasVertex(canvas, w/8, h/2); 
  cdCanvasEnd(canvas);

/* draws a blue roof.*/
  cdCanvasForeground(canvas, CD_BLUE);
  cdCanvasLine(canvas, w/8, h/2, w/4, 3*h/4);
  cdCanvasLine(canvas, w/4, 3*h/4, w/2-w/8, h/2);

/* draws a dashed ribbon on the right 
   with a custom color */
  cdCanvasForeground(canvas, cdEncodeColor(100, 25, 200));
  cdCanvasLineStyle(canvas, CD_DASH_DOT);
  cdCanvasBegin(canvas, CD_BEZIER);
  cdCanvasVertex(canvas, 3*w/4-20, h/2-50); 
  cdCanvasVertex(canvas, 3*w/4+150, 3*h/4-50); 
  cdCanvasVertex(canvas, 3*w/4-150, 3*h/4-50); 
  cdCanvasVertex(canvas, 3*w/4+20, h/2-50); 
  cdCanvasEnd(canvas);

  cdCanvasFont(canvas, "Helvetica", CD_BOLD, 40);
  cdCanvasTextAlignment(canvas, CD_CENTER);
  cdCanvasText(canvas, w/2, h/4-50, "Canvas Draw");
  cdCanvasGetTextBox(canvas, w/2, h/4-50, "Canvas Draw", &xmin, &xmax, &ymin, &ymax);
  cdCanvasRect(canvas, xmin, xmax, ymin, ymax);
}
Пример #12
0
static void iMatrixDrawText(Ihandle* ih, int x1, int x2, int y1, int y2, int alignment, int marked, int active, int lin, int col, const char* text)
{
  int num_line, line_height, total_height;
  int charheight, y, hidden_text_marks = 0;

  num_line = iupStrLineCount(text);
  iupdrvFontGetCharSize(ih, NULL, &charheight);

  line_height  = charheight;
  total_height = (line_height + IMAT_PADDING_H/2) * num_line - IMAT_PADDING_H/2 - IMAT_FRAME_H/2;

  if (lin==0 || ih->data->hidden_text_marks)
  {
    int text_w;
    iupdrvFontGetMultiLineStringSize(ih, text, &text_w, NULL);
    if (text_w > x2 - x1 + 1 - IMAT_PADDING_W - IMAT_FRAME_W)
    {
      if (lin == 0)
        alignment = IMAT_ALIGN_LEFT;

      if (ih->data->hidden_text_marks)
        hidden_text_marks = 1;
    }
  }

  /* Set the color used to draw the text */
  iMatrixDrawSetFgColor(ih, lin, col, marked, active);

  /* Set the clip area to the cell region informed, the text maybe greatter than the cell */
  if (hidden_text_marks)
  {
    int crop = iupdrvFontGetStringWidth(ih, "...") + 2;
    iMatrixDrawSetCellClipping(ih, x1, x2-crop, y1, y2);
  }
  else
    iMatrixDrawSetCellClipping(ih, x1, x2, y1, y2);

  IupCdSetFont(ih, ih->data->cd_canvas, iupMatrixGetFont(ih, lin, col));

  /* Create an space between text and cell frame */
  x1 += IMAT_PADDING_W/2;       x2 -= IMAT_PADDING_W/2;
  y1 += IMAT_PADDING_H/2;       y2 -= IMAT_PADDING_H/2;

  if (alignment == IMAT_ALIGN_CENTER)
    cdCanvasTextAlignment(ih->data->cd_canvas, CD_CENTER);
  else if(alignment == IMAT_ALIGN_LEFT)
    cdCanvasTextAlignment(ih->data->cd_canvas, CD_WEST);
  else  /* RIGHT */
    cdCanvasTextAlignment(ih->data->cd_canvas, CD_EAST);

  if (num_line == 1)
  {
    y = (int)((y1 + y2) / 2.0 - 0.5);

    /* Put the text */
    if (alignment == IMAT_ALIGN_CENTER)
      iupMATRIX_TEXT(ih, (x1 + x2) / 2, y, text);
    else if(alignment == IMAT_ALIGN_LEFT)
      iupMATRIX_TEXT(ih, x1, y, text);
    else  /* RIGHT */
      iupMATRIX_TEXT(ih, x2, y, text);
  }
  else
  {
    int i;
    char *p, *q, *newtext;

    newtext = iupStrDup(text);
    p = newtext;

    /* Get the position of the first text to be put in the screen */
    y = (int)( (y1 + y2) / 2.0 - 0.5) - total_height/2 + line_height/2;

    for(i = 0; i < num_line; i++)
    {
      q = strchr(p, '\n');
      if (q) *q = 0;  /* Cut the string to contain only one line */

      /* Draw the text */
      if(alignment == IMAT_ALIGN_CENTER)
        iupMATRIX_TEXT(ih, (x1 + x2) / 2, y, p);
      else if(alignment == IMAT_ALIGN_LEFT)
        iupMATRIX_TEXT(ih, x1, y, p);
      else  /* RIGHT */
        iupMATRIX_TEXT(ih, x2, y, p);

      /* Advance the string */
      if (q) p = q + 1;

      /* Advance a line */
      y += line_height + IMAT_PADDING_H/2;
    }

    free(newtext);
  }

  iMatrixDrawResetCellClipping(ih);

  if (hidden_text_marks)
  {
    cdCanvasTextAlignment(ih->data->cd_canvas, CD_EAST);
    y = (int)((y1 + y2) / 2.0 - 0.5);
    iupMATRIX_TEXT(ih, x2+IMAT_PADDING_W/2, y, "...");
  }
}
Пример #13
0
void SimpleDrawAll(cdCanvas* canvas)
{
  int w, h;
  cdCanvasGetSize(canvas, &w, &h, NULL, NULL);
  
  /* Clear the background to be white */
  cdCanvasBackground(canvas, CD_WHITE);
//  cdBackground(CD_GREEN);
  cdCanvasClear(canvas);

  /* Draw a reactangle and a polyline at the bottom-left area,
     using a thick line with transparency.
     Observe that transparency is only supported in a few drivers,
     and line join is not supported in the IMAGERGB driver. */
  cdCanvasLineWidth(canvas, 3);
  cdCanvasLineStyle(canvas, CD_CONTINUOUS);
  cdCanvasForeground(canvas, cdEncodeAlpha(CD_DARK_MAGENTA, 128));
  cdCanvasRect(canvas, 100, 200, 100, 200);

  cdCanvasBegin(canvas, CD_OPEN_LINES);
  cdCanvasVertex(canvas, 300, 250);
  cdCanvasVertex(canvas, 320, 270);
  cdCanvasVertex(canvas, 350, 260);
  cdCanvasVertex(canvas, 340, 200);
  cdCanvasVertex(canvas, 310, 210);
  cdCanvasEnd(canvas);
  
  /* Draw the red diagonal line with a custom line style. 
     Observe that line styles are not supported in the IMAGERGB driver. */
  cdCanvasForeground(canvas, CD_RED);
  cdCanvasLineWidth(canvas, 3);
  {
    int dashes[] = {20, 15, 5, 5};
    cdCanvasLineStyleDashes(canvas, dashes, 4);
  }
  cdCanvasLineStyle(canvas, CD_CUSTOM);
  cdCanvasLine(canvas, 0, 0, w-1, h-1);

  /* Draw the blue diagonal line with a pre-defined line style.
     Observe that the pre-defined line style is dependent on the driver. */
  cdCanvasForeground(canvas, CD_BLUE);
  cdCanvasLineWidth(canvas, 10);
  cdCanvasLineStyle(canvas, CD_DOTTED);
  cdCanvasLine(canvas, 0, h-1, w-1, 0);

  switch(clipping)
  {
  case CD_CLIPOFF:
    cdCanvasClip(canvas, CD_CLIPOFF);
    break;
  case CD_CLIPAREA:
    /* Defines the clipping area equals the canvas area minus a 100 pixels margin. */
    cdCanvasClipArea(canvas, 100, w - 100, 100, h - 100);
    cdCanvasClip(canvas, CD_CLIPAREA);
    break;
  case CD_CLIPPOLYGON:
    cdCanvasBegin(canvas, CD_CLIP);
    cdCanvasVertex(canvas, 100, 100);
    cdCanvasVertex(canvas, w - 100, 100);
    cdCanvasVertex(canvas, w / 2, h - 100);
    cdCanvasEnd(canvas);
    cdCanvasClip(canvas, CD_CLIPPOLYGON);
    break;
  case CD_CLIPREGION:
    cdCanvasTextAlignment(canvas, CD_CENTER);
    cdCanvasFont(canvas, "Times", CD_BOLD, 50);

    cdCanvasBegin(canvas, CD_REGION);
    cdCanvasRegionCombineMode(canvas, CD_UNION);
    cdCanvasBox(canvas, 100, 200, 100, 200);
    cdCanvasSector(canvas, w/2-50, h/2+50, 150, 150, 0, 360);
    cdCanvasSector(canvas, w/2-50, h/2-50, 150, 150, 0, 360);
    cdCanvasSector(canvas, w/2+50, h/2+50, 150, 150, 0, 360);
    cdCanvasSector(canvas, w/2+50, h/2-50, 150, 150, 0, 360);
    cdCanvasRegionCombineMode(canvas, CD_DIFFERENCE); 
    cdCanvasText(canvas, w/2, h/2, "TEXT");
    cdCanvasEnd(canvas);
//    cdCanvasOffsetRegion(canvas, -50, 50);
    cdCanvasClip(canvas, CD_CLIPREGION);

    cdCanvasForeground(canvas, CD_DARK_RED);
    cdCanvasBox(canvas, 0,w,0,h);
    break;
  }

  switch(write_mode)
  {
  case CD_REPLACE:
    cdCanvasWriteMode(canvas, CD_REPLACE);
    break;
  case CD_XOR:
    cdCanvasWriteMode(canvas, CD_XOR);
    break;
  case CD_NOT_XOR:
    cdCanvasWriteMode(canvas, CD_NOT_XOR);
    break;
  }

  if (use_transform)
  {
    cdCanvasTransform(canvas, NULL);
    cdCanvasTransformTranslate(canvas, w/2, h/2);
    cdCanvasTransformRotate(canvas, 30);
    cdCanvasTransformScale(canvas, 0.5, 0.5);
    cdCanvasTransformTranslate(canvas, -w/2, -h/2);
  }

//  cdSetfAttribute("ROTATE", "15 %d %d", w/2, h/2);

  /* Reset line style and width */
  cdCanvasLineStyle(canvas, CD_CONTINUOUS);
  cdCanvasLineWidth(canvas, 1);
//  cdBackOpacity(CD_TRANSPARENT); 
                   
  /* Draw an arc at bottom-left, and a sector at bottom-right.
     Notice that counter-clockwise orientation of both. */
  cdCanvasInteriorStyle(canvas, CD_SOLID);
  cdCanvasForeground(canvas, CD_MAGENTA);
  cdCanvasSector(canvas, w-100, 100, 100, 100, 50, 180);
  cdCanvasForeground(canvas, CD_RED);
  cdCanvasArc(canvas, 100, 100, 100, 100, 50, 180);

  /* Draw a solid filled rectangle at center. */
  cdCanvasForeground(canvas, CD_YELLOW);
  cdCanvasBox(canvas, w/2 - 100, w/2 + 100, h/2 - 100, h/2 + 100); 

  /* Prepare font for text. */
  cdCanvasTextAlignment(canvas, CD_CENTER);
  cdCanvasTextOrientation(canvas, 70);
  cdCanvasFont(canvas, "Times", CD_BOLD, 24);

  /* Draw text at center, with orientation, 
     and draw its bounding box. 
     Notice that in some drivers the bounding box is not precise. */
  {
    int rect[8];
    cdCanvasGetTextBounds(canvas, w/2, h/2, "Simple Draw (pçãí)", rect);
    cdCanvasForeground(canvas, CD_RED);
    cdCanvasBegin(canvas, CD_CLOSED_LINES);
    cdCanvasVertex(canvas, rect[0], rect[1]);
    cdCanvasVertex(canvas, rect[2], rect[3]);
    cdCanvasVertex(canvas, rect[4], rect[5]);
    cdCanvasVertex(canvas, rect[6], rect[7]);
    cdCanvasEnd(canvas);
  }
  cdCanvasForeground(canvas, CD_BLUE);
  cdCanvasText(canvas, w/2, h/2, "Simple Draw (pçãí)");
  cdCanvasTextOrientation(canvas, 0);

  /* Prepare World Coordinates */
  wdCanvasViewport(canvas, 0,w-1,0,h-1);
  if (w>h)
    wdCanvasWindow(canvas, 0,(double)w/(double)h,0,1);
  else
    wdCanvasWindow(canvas, 0,1,0,(double)h/(double)w);

  /* Draw a filled blue rectangle in WC */
  wdCanvasBox(canvas, 0.20, 0.30, 0.40, 0.50);
  cdCanvasForeground(canvas, CD_RED);
  /* Draw the diagonal of that rectangle in WC */
  wdCanvasLine(canvas, 0.20, 0.40, 0.30, 0.50);

//  wdVectorTextDirection(0, 0, 1, 1);
  /* Prepare Vector Text in WC. */
  wdCanvasVectorCharSize(canvas, 0.07);

//  wdVectorText(0.1, 0.4, "ñç áéíóú àèìòù âêîôû äëïöü");
//  wdVectorText(0.1, 0.2, "ÑÇ ÁÉÍÓÚ ÀÈÌÒÙ ÂÊÎÔÛ ÄËÏÖÜ");
  //{
  //  int i;
  //  char t[2];
  //  char s[10];
  //  int x = 20;
  //  int y = 0;
  //  t[1] = 0;
  //  for (i = 0; i < 256; i++)
  //  {
  //    int dx = 90;
  //    t[0] = (char)i;
  //    sprintf(s, "%d", i);
  //    cdText(x, y, s);
  //    cdText(x+dx, y, t);
  //    cdVectorText(x+2*dx, y, t);
  //    
  //    x += 3*dx + 2*dx/3;
  //    if ((i+1) % 7 == 0)
  //    {
  //      x = 20;
  //      y += 90;
  //    }

  //  }
  //}

  /* Draw vector text, and draw its bounding box. 
     We also use this text to show when we are using a contextplus driver. */
  {
    double rect[8];
    cdCanvasForeground(canvas, CD_RED);
    if (contextplus)
      wdCanvasGetVectorTextBounds(canvas, "WDj-Plus", 0.25, 0.35, rect);
    else
      wdCanvasGetVectorTextBounds(canvas, "WDj", 0.25, 0.35, rect);
    cdCanvasBegin(canvas, CD_CLOSED_LINES);
    wdCanvasVertex(canvas, rect[0], rect[1]);
    wdCanvasVertex(canvas, rect[2], rect[3]);
    wdCanvasVertex(canvas, rect[4], rect[5]);
    wdCanvasVertex(canvas, rect[6], rect[7]);
    cdCanvasEnd(canvas);

    cdCanvasLineWidth(canvas, 2);
    cdCanvasLineStyle(canvas, CD_CONTINUOUS);
    if (contextplus)
      wdCanvasVectorText(canvas, 0.25, 0.35, "WDj-Plus");
    else
      wdCanvasVectorText(canvas, 0.25, 0.35, "WDj");
    cdCanvasLineWidth(canvas, 1);
  }

  /* Draw a filled path at center-right (looks like a weird fish). 
     Notice that in PDF the arc is necessarily a circle arc, and not an ellipse. */
  cdCanvasForeground(canvas, CD_GREEN);
  cdCanvasBegin(canvas, CD_PATH);
  cdCanvasPathSet(canvas, CD_PATH_MOVETO);
  cdCanvasVertex(canvas, w/2 + 200, h/2);
  cdCanvasPathSet(canvas, CD_PATH_LINETO);
  cdCanvasVertex(canvas, w/2 + 230, h/2 + 50);
  cdCanvasPathSet(canvas, CD_PATH_LINETO);
  cdCanvasVertex(canvas, w/2 + 250, h/2 + 50);
  cdCanvasPathSet(canvas, CD_PATH_CURVETO);
  cdCanvasVertex(canvas, w/2+150+150, h/2+200-50); /* control point for start */
  cdCanvasVertex(canvas, w/2+150+180, h/2+250-50); /* control point for end */
  cdCanvasVertex(canvas, w/2+150+180, h/2+200-50); /* end point */
  cdCanvasPathSet(canvas, CD_PATH_CURVETO);
  cdCanvasVertex(canvas, w/2+150+180, h/2+150-50); 
  cdCanvasVertex(canvas, w/2+150+150, h/2+100-50); 
  cdCanvasVertex(canvas, w/2+150+300, h/2+100-50); 
  cdCanvasPathSet(canvas, CD_PATH_LINETO);
  cdCanvasVertex(canvas, w/2+150+300, h/2-50);
  cdCanvasPathSet(canvas, CD_PATH_ARC);
  cdCanvasVertex(canvas, w/2+300, h/2);  /* center */
  cdCanvasVertex(canvas, 200, 100);  /* width, height */
  cdCanvasVertex(canvas, -30*1000, -170*1000);  /* start angle, end angle (degrees / 1000) */
//  cdCanvasPathSet(canvas, CD_PATH_CLOSE);
//  cdCanvasPathSet(canvas, CD_PATH_STROKE);
  cdCanvasPathSet(canvas, CD_PATH_FILL);
//  cdCanvasPathSet(canvas, CD_PATH_FILLSTROKE);
  cdCanvasEnd(canvas);

  /* Draw 3 pixels at center left. */
  cdCanvasPixel(canvas, 10, h/2+0, CD_RED);
  cdCanvasPixel(canvas, 11, h/2+1, CD_GREEN);
  cdCanvasPixel(canvas, 12, h/2+2, CD_BLUE);

  /* Draw 4 mark types, distributed near each corner.  */
  cdCanvasForeground(canvas, CD_RED);
  cdCanvasMarkSize(canvas, 30);
  cdCanvasMarkType(canvas, CD_PLUS);
  cdCanvasMark(canvas, 200, 200);
  cdCanvasMarkType(canvas, CD_CIRCLE);
  cdCanvasMark(canvas, w - 200, 200);
  cdCanvasMarkType(canvas, CD_HOLLOW_CIRCLE);
  cdCanvasMark(canvas, 200, h - 200);
  cdCanvasMarkType(canvas, CD_DIAMOND);
  cdCanvasMark(canvas, w - 200, h - 200);

  /* Draw all the line style possibilities at bottom. 
     Notice that they have some small differences between drivers. */
  cdCanvasLineWidth(canvas, 1);
  cdCanvasLineStyle(canvas, CD_CONTINUOUS);
  cdCanvasLine(canvas, 0, 10, w, 10);
  cdCanvasLineStyle(canvas, CD_DASHED);
  cdCanvasLine(canvas, 0, 20, w, 20);
  cdCanvasLineStyle(canvas, CD_DOTTED);
  cdCanvasLine(canvas, 0, 30, w, 30);
  cdCanvasLineStyle(canvas, CD_DASH_DOT);
  cdCanvasLine(canvas, 0, 40, w, 40);
  cdCanvasLineStyle(canvas, CD_DASH_DOT_DOT);
  cdCanvasLine(canvas, 0, 50, w, 50);

  /* Draw all the hatch style possibilities in the top-left corner.
     Notice that they have some small differences between drivers. */
  cdCanvasHatch(canvas, CD_VERTICAL); 
  cdCanvasBox(canvas, 0, 50, h - 60, h);
  cdCanvasHatch(canvas, CD_FDIAGONAL); 
  cdCanvasBox(canvas, 50, 100, h - 60, h);
  cdCanvasHatch(canvas, CD_BDIAGONAL); 
  cdCanvasBox(canvas, 100, 150, h - 60, h);
  cdCanvasHatch(canvas, CD_CROSS); 
  cdCanvasBox(canvas, 150, 200, h - 60, h);
  cdCanvasHatch(canvas, CD_HORIZONTAL); 
  cdCanvasBox(canvas, 200, 250, h - 60, h);
  cdCanvasHatch(canvas, CD_DIAGCROSS); 
  cdCanvasBox(canvas, 250, 300, h - 60, h);

  /* Draw 4 regions, in diamond shape,
     at top, bottom, left, right, 
     using different interior styles. */

  /* At top, not filled polygon, notice that the last line style is used. */
  cdCanvasBegin(canvas, CD_CLOSED_LINES);
  cdCanvasVertex(canvas, w/2, h - 100); 
  cdCanvasVertex(canvas, w/2 + 50, h - 150); 
  cdCanvasVertex(canvas, w/2, h - 200); 
  cdCanvasVertex(canvas, w/2 - 50, h - 150); 
  cdCanvasEnd(canvas);

  /* At left, hatch filled polygon */
  cdCanvasHatch(canvas, CD_DIAGCROSS); 
  cdCanvasBegin(canvas, CD_FILL);
  cdCanvasVertex(canvas, 100, h/2); 
  cdCanvasVertex(canvas, 150, h/2 + 50); 
  cdCanvasVertex(canvas, 200, h/2); 
  cdCanvasVertex(canvas, 150, h/2 - 50); 
  cdCanvasEnd(canvas);

  /* At right, pattern filled polygon */
  cdCanvasPattern(canvas, STYLE_SIZE, STYLE_SIZE, pattern);
  cdCanvasBegin(canvas, CD_FILL);
  cdCanvasVertex(canvas, w - 100, h/2); 
  cdCanvasVertex(canvas, w - 150, h/2 + 50); 
  cdCanvasVertex(canvas, w - 200, h/2); 
  cdCanvasVertex(canvas, w - 150, h/2 - 50); 
  cdCanvasEnd(canvas);
  
  /* At bottom, stipple filled polygon */
  cdCanvasStipple(canvas, STYLE_SIZE, STYLE_SIZE, stipple);
  cdCanvasBegin(canvas, CD_FILL);
  cdCanvasVertex(canvas, w/2, 100); 
  cdCanvasVertex(canvas, w/2 + 50, 150); 
  cdCanvasVertex(canvas, w/2, 200); 
  cdCanvasVertex(canvas, w/2 - 50, 150); 
  cdCanvasEnd(canvas);

  /* Draw two beziers at bottom-left */
  cdCanvasBegin(canvas, CD_BEZIER);
  cdCanvasVertex(canvas, 100, 100); 
  cdCanvasVertex(canvas, 150, 200); 
  cdCanvasVertex(canvas, 180, 250); 
  cdCanvasVertex(canvas, 180, 200); 
  cdCanvasVertex(canvas, 180, 150); 
  cdCanvasVertex(canvas, 150, 100); 
  cdCanvasVertex(canvas, 300, 100); 
  cdCanvasEnd(canvas);

  /* Initialize the image buffer contents */
//#define IMAGE_SIZE 16
  memset(red, 0xFF, IMAGE_SIZE*IMAGE_SIZE/2);
  memset(green, 0x5F, IMAGE_SIZE*IMAGE_SIZE/2);
  memset(blue, 0x5F, IMAGE_SIZE*IMAGE_SIZE/2);
  memset(red+IMAGE_SIZE*IMAGE_SIZE/2, 0x5F, IMAGE_SIZE*IMAGE_SIZE/2);
  memset(green+IMAGE_SIZE*IMAGE_SIZE/2, 0x8F, IMAGE_SIZE*IMAGE_SIZE/2);
  memset(blue+IMAGE_SIZE*IMAGE_SIZE/2, 0x5F, IMAGE_SIZE*IMAGE_SIZE/2);
  memset(red+IMAGE_SIZE*(IMAGE_SIZE-1), 0, IMAGE_SIZE);
  memset(green+IMAGE_SIZE*(IMAGE_SIZE-1), 0, IMAGE_SIZE);
  memset(blue+IMAGE_SIZE*(IMAGE_SIZE-1), 0, IMAGE_SIZE);
  memset(red, 0, IMAGE_SIZE);
  memset(green, 0, IMAGE_SIZE);
  memset(blue, 0, IMAGE_SIZE);
  {
    int i, offset;
    for (i = 0; i < IMAGE_SIZE; i++)
    {
      offset = i*IMAGE_SIZE;
      red[offset] = 0;
      green[offset] = 0;
      blue[offset] = 0;
      red[offset+IMAGE_SIZE-1] = 0;
      green[offset+IMAGE_SIZE-1] = 0;
      blue[offset+IMAGE_SIZE-1] = 0;
    }
  }

  //cdSetAttribute("ANTIALIAS", "0");
//  cdGetImageRGB(red, green, blue, w/2 - 50, h/2-50, 100, 100);
//  cdPutImageRectRGB(14, 13, red, green, blue, -20, -15, 649, 603, 0, 13, 0, 12);
//  cdPutImageRectRGB(16, 16, red, green, blue, 10, 10, 608, 608, 5, 10, 5, 10);
//  cdPutImageRectRGB(16, 16, red, green, blue, 10, 10, 64, 64, 5, 10, 5, 10);

//  cdPutImageRGB(IMAGE_SIZE, IMAGE_SIZE, red, green, blue, 100, h - 200, IMAGE_SIZE, IMAGE_SIZE);
//  cdPutImageRGBA(IMAGE_SIZE, IMAGE_SIZE, red, green, blue, alpha, 100, h - 200, IMAGE_SIZE, IMAGE_SIZE);
//  cdPutImageRGB(IMAGE_SIZE, IMAGE_SIZE, red, green, blue, w - 400, h - 310, 3*IMAGE_SIZE, 3*IMAGE_SIZE);
  /* Draw the image on the top-right corner but increasing its actual size, and uses its full area */
  cdCanvasPutImageRectRGBA(canvas, IMAGE_SIZE, IMAGE_SIZE, red, green, blue, alpha, w - 400, h - 310, 3*IMAGE_SIZE, 3*IMAGE_SIZE, 0, 0, 0, 0);

  cdCanvasSetAttribute(canvas, "ROTATE", NULL);
  if (use_transform)
    cdCanvasTransform(canvas, NULL);
  cdCanvasClip(canvas, CD_CLIPOFF);
}
Пример #14
0
static inline void iPlotDrawText(cdCanvas* canvas, double inX, double inY, int inAlignment, const char* inString)
{
  cdCanvasTextAlignment(canvas, inAlignment);
  cdfCanvasText(canvas, inX, inY, inString);
}
Пример #15
0
/* Put the cell contents in the screen, using the specified color and alignment.
   -> y1, y2 : vertical limits of the cell
   -> x1, x2 : horizontal limits of the complete cell
   -> alignment : alignment type (horizontal) assigned to the text. The options are:
                  [IMAT_T_CENTER,IMAT_T_LEFT,IMAT_T_RIGHT]
   -> marked : mark state
   -> lin, col - cell coordinates */
static void iMatrixDrawCellValue(Ihandle* ih, int x1, int x2, int y1, int y2, int alignment, int marked, int active, int lin, int col, IFniiiiiiC draw_cb)
{
    char *text;

    /* avoid drawing over the frame of the next cell */
    x2 -= IMAT_FRAME_W/2;
    y2 -= IMAT_FRAME_H/2;

    /* avoid drawing over the frame of the cell */
    x2 -= IMAT_FRAME_W/2;
    y2 -= IMAT_FRAME_H/2;

    if (lin==0 || col==0)
    {
        /* avoid drawing over the frame of the cell */
        x1 += IMAT_FRAME_W/2;
        y1 += IMAT_FRAME_H/2;

        if (col==0) x1 += IMAT_FRAME_W/2;
        if (lin==0) y1 += IMAT_FRAME_H/2;
    }
    else if ((col==1 && ih->data->columns.sizes[0] == 0) || (lin==1 && ih->data->lines.sizes[0] == 0))
    {
        /* avoid drawing over the frame of the cell */
        x1 += IMAT_FRAME_W/2;
        y1 += IMAT_FRAME_H/2;
    }

    if (draw_cb && !iMatrixDrawCallDrawCB(ih, lin, col, x1, x2, y1, y2, draw_cb))
        return;

    text = iupMatrixCellGetValue(ih, lin, col);

    /* Put the text */
    if (text && *text)
    {
        int num_line, line_height, total_height;
        int charheight, ypos, hidden_text_marks = 0;

        num_line = iupStrLineCount(text);
        iupdrvFontGetCharSize(ih, NULL, &charheight);

        line_height  = charheight;
        total_height = (line_height + IMAT_PADDING_H/2) * num_line - IMAT_PADDING_H/2 - IMAT_FRAME_H/2;

        if (lin==0 || ih->data->hidden_text_marks)
        {
            int text_w;
            iupdrvFontGetMultiLineStringSize(ih, text, &text_w, NULL);
            if (text_w > x2 - x1 + 1 - IMAT_PADDING_W - IMAT_FRAME_W)
            {
                if (lin == 0)
                    alignment = IMAT_T_LEFT;

                if (ih->data->hidden_text_marks)
                    hidden_text_marks = 1;
            }
        }

        /* Set the color used to draw the text */
        if (!active)
            cdCanvasForeground(ih->data->cddbuffer, IMAT_CD_INACTIVE_FGCOLOR);
        else
            iMatrixDrawSetFgColor(ih, lin, col, marked);

        /* Set the clip area to the cell region informed, the text maybe greatter than the cell */
        if (hidden_text_marks)
        {
            int crop = iupdrvFontGetStringWidth(ih, "...") + 2;
            iMatrixDrawSetCellClipping(ih, x1, x2-crop, y1, y2);
        }
        else
            iMatrixDrawSetCellClipping(ih, x1, x2, y1, y2);

        cdCanvasNativeFont(ih->data->cddbuffer, iupMatrixGetFont(ih, lin, col));

        /* Create an space between text and cell frame */
        x1 += IMAT_PADDING_W/2;
        x2 -= IMAT_PADDING_W/2;
        y1 += IMAT_PADDING_H/2;
        y2 -= IMAT_PADDING_H/2;

        if (alignment == IMAT_T_CENTER)
            cdCanvasTextAlignment(ih->data->cddbuffer, CD_CENTER);
        else if(alignment == IMAT_T_LEFT)
            cdCanvasTextAlignment(ih->data->cddbuffer, CD_WEST);
        else
            cdCanvasTextAlignment(ih->data->cddbuffer, CD_EAST);

        if (num_line == 1)
        {
            ypos = (int)((y1 + y2) / 2.0 - 0.5);

            /* Put the text */
            if (alignment == IMAT_T_CENTER)
                iupMATRIX_TEXT(ih, (x1 + x2) / 2, ypos, text);
            else if(alignment == IMAT_T_LEFT)
                iupMATRIX_TEXT(ih, x1, ypos, text);
            else
                iupMATRIX_TEXT(ih, x2, ypos, text);
        }
        else
        {
            int i;
            char *p, *q, *newtext;

            newtext = iupStrDup(text);
            p = newtext;

            /* Get the position of the first text to be put in the screen */
            ypos = (int)( (y1 + y2) / 2.0 - 0.5) - total_height/2 + line_height/2;

            for(i = 0; i < num_line; i++)
            {
                q = strchr(p, '\n');
                if (q) *q = 0;  /* Cut the string to contain only one line */

                /* Draw the text */
                if(alignment == IMAT_T_CENTER)
                    iupMATRIX_TEXT(ih, (x1 + x2) / 2, ypos, p);
                else if(alignment == IMAT_T_LEFT)
                    iupMATRIX_TEXT(ih, x1, ypos, p);
                else
                    iupMATRIX_TEXT(ih, x2, ypos, p);

                /* Advance the string */
                if (q) p = q + 1;

                /* Advance a line */
                ypos += line_height + IMAT_PADDING_H/2;
            }

            free(newtext);
        }

        iMatrixDrawResetCellClipping(ih);

        if (hidden_text_marks)
        {
            cdCanvasTextAlignment(ih->data->cddbuffer, CD_EAST);
            ypos = (int)((y1 + y2) / 2.0 - 0.5);
            iupMATRIX_TEXT(ih, x2+IMAT_PADDING_W/2, ypos, "...");
        }
    }
}
Пример #16
0
void SimpleDrawTextAlign(cdCanvas* canvas)
{
  int w, h, i, xoff, yoff, use_vector;

  int text_aligment[] = {
    CD_NORTH,
    CD_SOUTH,
    CD_EAST,
    CD_WEST,
    CD_NORTH_EAST,
    CD_NORTH_WEST,
    CD_SOUTH_EAST,
    CD_SOUTH_WEST,
    CD_CENTER,
    CD_BASE_CENTER,
    CD_BASE_RIGHT,
    CD_BASE_LEFT
  };

#if 1
  char* text_aligment_str[] = {
  "North (Ãyj)\nSecond Line (Ãyj)\nThird Line",
  "South (Ãyj)\nSecond Line (Ãyj)\nThird Line",
  "East (Ãyj)\nSecond Line (Ãyj)\nThird Line",
  "West (Ãyj)\nSecond Line (Ãyj)\nThird Line",
  "North East (Ãyj)\nSecond Line (Ãyj)\nThird Line",
  "North West (Ãyj)\nSecond Line (Ãyj)\nThird Line",
  "South East (Ãyj)\nSecond Line (Ãyj)\nThird Line",
  "South West (Ãyj)\nSecond Line (Ãyj)\nThird Line",
  "Center (Ãyj)\nSecond Line (Ãyj)\nThird Line",
  "Base Center (Ãyj)\nSecond Line (Ãyj)\nThird Line",
  "Base Right (Ãyj)\nSecond Line (Ãyj)\nThird Line",
  "Base Left (Ãyj)\nSecond Line (Ãyj)\nThird Line"
  };
#else
  char* text_aligment_str[] = {
  "North (Ãyj)",
  "South (Ãyj)",
  "East (Ãyj)",
  "West (Ãyj)",
  "North East (Ãyj)",
  "North West (Ãyj)",
  "South East (Ãyj)",
  "South West (Ãyj)",
  "Center (Ãyj)",
  "Base Center (Ãyj)",
  "Base Right (Ãyj)",
  "Base Left (Ãyj)"
  };
#endif

  cdCanvasGetSize(canvas, &w, &h, 0, 0);

  cdCanvasBackground(canvas, CD_WHITE);
  cdCanvasClear(canvas);

  use_vector = 0;

#if 0
  if (use_vector)
    cdCanvasVectorTextDirection(canvas, 0, 0, 1, 1);
  else
    cdCanvasTextOrientation(canvas, 45);
#endif

  xoff = w/4;
  yoff = h/7;

  if (use_vector)
    cdCanvasVectorCharSize(canvas, 30);
  else
  {
    //cdCanvasFont(canvas, "Times", CD_PLAIN, 14);
    cdCanvasFont(canvas, "Helvetica", CD_PLAIN, 24);
  }

  for (i = 0; i < 12; i++)
  {
    cdCanvasTextAlignment(canvas, text_aligment[i]);
    if (i < 6)
    {
      if (use_vector)
        DrawVectorTextBox(canvas, xoff, yoff*(i+1), text_aligment_str[i]);
      else
        DrawTextBox(canvas, xoff, yoff*(i+1), text_aligment_str[i]);
    }
    else
    {
      if (use_vector)
        DrawVectorTextBox(canvas, 3*xoff, yoff*(i-5), text_aligment_str[i]);
      else
        DrawTextBox(canvas, 3*xoff, yoff*(i-5), text_aligment_str[i]);
    }
  }
}
Пример #17
0
static void iMatrixDrawText(Ihandle* ih, int x1, int x2, int y1, int y2, int col_alignment, int lin_alignment, int marked, int active, int lin, int col, const char* text)
{
  int text_alignment;
  int charheight, x, y, hidden_text_marks = 0;

  iupdrvFontGetCharSize(ih, NULL, &charheight);

  if (lin==0 || ih->data->hidden_text_marks)
  {
    int text_w;
    iupdrvFontGetMultiLineStringSize(ih, text, &text_w, NULL);
    if (text_w > x2 - x1 + 1 - IMAT_PADDING_W - IMAT_FRAME_W)
    {
      if (lin == 0)
        col_alignment = IMAT_ALIGN_START;

      if (ih->data->hidden_text_marks)
        hidden_text_marks = 1;
    }
  }

  /* Set the color used to draw the text */
  iMatrixDrawSetFgColor(ih, lin, col, marked, active);

  /* Set the clip area to the cell region informed, the text maybe greater than the cell */
  if (hidden_text_marks)
  {
    int crop = iupdrvFontGetStringWidth(ih, "...") + 2;
    iMatrixDrawSetCellClipping(ih, x1, x2-crop, y1, y2);
  }
  else
    iMatrixDrawSetCellClipping(ih, x1, x2, y1, y2);

  IupCdSetFont(ih, ih->data->cd_canvas, iupMatrixGetFont(ih, lin, col));

  /* Create an space between text and cell frame */
  x1 += IMAT_PADDING_W/2;       x2 -= IMAT_PADDING_W/2;
  y1 += IMAT_PADDING_H/2;       y2 -= IMAT_PADDING_H/2;

  iMatrixGetCellAlign(ih, lin, col, &col_alignment, &lin_alignment);

  if (lin_alignment == IMAT_ALIGN_CENTER)
  {
    y = iupROUND((y1 + y2) / 2.0);

    if (col_alignment == IMAT_ALIGN_CENTER)
    {
      x = iupROUND((x1 + x2) / 2.0);
      text_alignment = CD_CENTER;
    }
    else if (col_alignment == IMAT_ALIGN_START)
    {
      x = x1;
      text_alignment = CD_WEST;
    }
    else  /* RIGHT */
    {
      x = x2;
      text_alignment = CD_EAST;
    }
  }
  else if (lin_alignment == IMAT_ALIGN_START)
  {
    y = y1;

    if (col_alignment == IMAT_ALIGN_CENTER)
    {
      x = iupROUND((x1 + x2) / 2.0);
      text_alignment = CD_NORTH;
    }
    else if (col_alignment == IMAT_ALIGN_START)
    {
      x = x1;
      text_alignment = CD_NORTH_WEST;
    }
    else  /* RIGHT */
    {
      x = x2;
      text_alignment = CD_NORTH_EAST;
    }
  }
  else /* lin_alignment == IMAT_ALIGN_END */
  {
    y = y2;

    if (col_alignment == IMAT_ALIGN_CENTER)
    {
      x = iupROUND((x1 + x2) / 2.0);
      text_alignment = CD_SOUTH;
    }
    else if (col_alignment == IMAT_ALIGN_START)
    {
      x = x1;
      text_alignment = CD_SOUTH_WEST;
    }
    else  /* RIGHT */
    {
      x = x2;
      text_alignment = CD_SOUTH_EAST;
    }
  }

  cdCanvasTextAlignment(ih->data->cd_canvas, text_alignment);
  iupMATRIX_TEXT(ih, x, y, text);

  iMatrixDrawResetCellClipping(ih);

  if (hidden_text_marks)
  {
    cdCanvasTextAlignment(ih->data->cd_canvas, CD_EAST);
    y = (int)((y1 + y2) / 2.0 - 0.5);
    x = x2 + IMAT_PADDING_W / 2;
    iupMATRIX_TEXT(ih, x, y, "...");
  }
}
Пример #18
0
void cdCanvasRestoreState(cdCanvas* canvas, cdState* state)
{
  assert(canvas);
  assert(state);
  if (!state || !_cdCheckCanvas(canvas)) return;

  /* clippling must be done in low level because origin and invert y axis */
  canvas->clip_poly_n = state->clip_poly_n;

  if (canvas->clip_poly) 
  {
    free(canvas->clip_poly);
    canvas->clip_poly = NULL;
  }

  if (canvas->clip_fpoly) 
  {
    free(canvas->clip_fpoly);
    canvas->clip_fpoly = NULL;
  }

  if (state->clip_poly) 
  {
    int size = state->clip_poly_n*sizeof(cdPoint);
    canvas->clip_poly = (cdPoint*)malloc(size);
    memcpy(canvas->clip_poly, state->clip_poly, size);
  }

  if (state->clip_fpoly) 
  {
    int size = state->clip_poly_n*sizeof(cdfPoint);
    canvas->clip_fpoly = (cdfPoint*)malloc(size);
    memcpy(canvas->clip_fpoly, state->clip_fpoly, size);
  }

  cdCanvasClip(canvas, CD_CLIPOFF);
  if (canvas->clip_fpoly)
    canvas->cxFPoly(canvas->ctxcanvas, CD_CLIP, state->clip_fpoly, state->clip_poly_n);
  else if (canvas->clip_poly)
    canvas->cxPoly(canvas->ctxcanvas, CD_CLIP, state->clip_poly, state->clip_poly_n);
  cdCanvasClipArea(canvas, state->clip_rect.xmin, state->clip_rect.xmax, state->clip_rect.ymin, state->clip_rect.ymax);
  if (canvas->cxFClipArea)
    canvas->cxFClipArea(canvas->ctxcanvas, state->clip_frect.xmin, state->clip_frect.xmax, state->clip_frect.ymin, state->clip_frect.ymax);
  else if (canvas->cxClipArea)
    canvas->cxClipArea(canvas->ctxcanvas, state->clip_rect.xmin, state->clip_rect.xmax, state->clip_rect.ymin, state->clip_rect.ymax);
  cdCanvasClip(canvas, state->clip_mode);

  /* regular attributes */
  cdCanvasSetBackground(canvas, state->background);
  cdCanvasSetForeground(canvas, state->foreground);
  cdCanvasBackOpacity(canvas, state->back_opacity);
  cdCanvasWriteMode(canvas, state->write_mode);
  cdCanvasLineStyle(canvas, state->line_style);
  cdCanvasLineWidth(canvas, state->line_width);
  cdCanvasLineCap(canvas, state->line_cap);
  cdCanvasLineJoin(canvas, state->line_join);
  cdCanvasFillMode(canvas, state->fill_mode);
  cdCanvasLineStyleDashes(canvas, state->line_dashes, state->line_dashes_count);
  cdCanvasHatch(canvas, state->hatch_style);
  if (state->stipple) cdCanvasStipple(canvas, state->stipple_w, state->stipple_h, state->stipple);
  if (state->pattern) cdCanvasPattern(canvas, state->pattern_w, state->pattern_h, state->pattern);
  cdCanvasInteriorStyle(canvas, state->interior_style);
  if (state->native_font[0])
    cdCanvasNativeFont(canvas, state->native_font);
  else
    cdCanvasFont(canvas, state->font_type_face, state->font_style, state->font_size);
  cdCanvasTextAlignment(canvas, state->text_alignment);
  cdCanvasTextOrientation(canvas, state->text_orientation);
  cdCanvasMarkType(canvas, state->mark_type);
  cdCanvasMarkSize(canvas, state->mark_size);
  cdCanvasOrigin(canvas, state->origin.x, state->origin.y);
  if (state->use_matrix)
    cdCanvasTransform(canvas, state->matrix);
  wdCanvasWindow(canvas, state->window.xmin, state->window.xmax, state->window.ymin, state->window.ymax);
  wdCanvasViewport(canvas, state->viewport.xmin, state->viewport.xmax, state->viewport.ymin, state->viewport.ymax);
  cdCanvasSimulate(canvas, state->sim_mode);

  /* complex clipping regions are not saved */
  /* driver internal attributes are not saved */
}
Пример #19
0
Файл: cdmf.c Проект: LuaDist/cd
static int cdplay(cdCanvas* canvas, int xmin, int xmax, int ymin, int ymax, void *data)
{
  char* filename = (char*)data;
  FILE* file;
  char TextBuffer[512];
  int iparam1, iparam2, iparam3, iparam4, iparam5, iparam6, iparam7, iparam8, iparam9, iparam10;
  int c, t, n, w, h, func;
  double dparam1, dparam2, dparam3, dparam4, dparam5, dparam6;
  unsigned char* stipple, * _stipple, *red, *green, *blue, *_red, *_green, *_blue, *index, *_index, *_alpha, *alpha;
  long int *pattern, *palette, *_pattern, *_palette, *colors, *_colors;
  int* dashes;
  double matrix[6];
  const char * font_family[] = 
  {
    "System",       /* CD_SYSTEM */
    "Courier",      /* CD_COURIER */
    "Times",        /* CD_TIMES_ROMAN */
    "Helvetica"     /* CD_HELVETICA */
  };
  
  file = fopen(filename, "r");
  if (!file)
    return CD_ERROR;

  func = -1;
  w = 0;
  h = 0;

  factorX = 1;
  factorY = 1;
  offsetX = 0;
  offsetY = 0;
  factorS = 1;

  fscanf(file, "%s %d %d", TextBuffer, &w, &h);

  if (strcmp(TextBuffer, "CDMF") != 0)
  {
    fclose(file);
    return CD_ERROR;
  }

  if (w>1 && h>1 && xmax!=0 && ymax!=0)
  {
    offsetX = xmin;
    offsetY = ymin;
    factorX = ((double)(xmax-xmin)) / (w-1);
    factorY = ((double)(ymax-ymin)) / (h-1);

    if (factorX < factorY)
      factorS = factorX;
    else
      factorS = factorY;
  }

  if (cdsizecb)
  {
    int err;
    err = cdsizecb(canvas, w, h, w, h);
    if (err)
      return CD_ERROR;
  }

  while (!feof(file))
  {
    fscanf(file, "%d", &func);
    if (feof(file))
      break;

    switch (func)
    {
    case CDMF_FLUSH:
      cdCanvasFlush(canvas);
      break;
    case CDMF_CLEAR:
      cdCanvasClear(canvas);
      break;
    case CDMF_CLIP:
      fscanf(file, "%d", &iparam1);
      cdCanvasClip(canvas, iparam1);
      break;
    case CDMF_CLIPAREA:
      fscanf(file, "%d %d %d %d", &iparam1, &iparam2, &iparam3, &iparam4);
      cdCanvasClipArea(canvas, sScaleX(iparam1), sScaleX(iparam2), sScaleY(iparam3), sScaleY(iparam4));
      break;
    case CDMF_FCLIPAREA:
      fscanf(file, "%lg %lg %lg %lg", &dparam1, &dparam2, &dparam3, &dparam4);
      cdfCanvasClipArea(canvas, sfScaleX(dparam1), sfScaleX(dparam2), sfScaleY(dparam3), sfScaleY(dparam4));
      break;
    case CDMF_MATRIX:
      fscanf(file, "%lg %lg %lg %lg %lg %lg", &matrix[0], &matrix[1], &matrix[2], &matrix[3], &matrix[4], &matrix[5]);
      cdCanvasTransform(canvas, matrix);
      break;
    case CDMF_RESETMATRIX:
      cdCanvasTransform(canvas, NULL);
      break;
    case CDMF_WCLIPAREA:
      fscanf(file, "%lg %lg %lg %lg", &dparam1, &dparam2, &dparam3, &dparam4);
      wdCanvasClipArea(canvas, dparam1, dparam2, dparam3, dparam4);
      break;
    case CDMF_LINE:
      fscanf(file, "%d %d %d %d", &iparam1, &iparam2, &iparam3, &iparam4);
      cdCanvasLine(canvas, sScaleX(iparam1), sScaleY(iparam2), sScaleX(iparam3), sScaleY(iparam4));
      break;
    case CDMF_FLINE:
      fscanf(file, "%lg %lg %lg %lg", &dparam1, &dparam2, &dparam3, &dparam4);
      cdfCanvasLine(canvas, sfScaleX(dparam1), sfScaleY(dparam2), sfScaleX(dparam3), sfScaleY(dparam4));
      break;
    case CDMF_WLINE:
      fscanf(file, "%lg %lg %lg %lg", &dparam1, &dparam2, &dparam3, &dparam4);
      wdCanvasLine(canvas, dparam1, dparam2, dparam3, dparam4);
      break;
    case CDMF_RECT:
      fscanf(file, "%d %d %d %d", &iparam1, &iparam2, &iparam3, &iparam4);
      cdCanvasRect(canvas, sScaleX(iparam1), sScaleX(iparam2), sScaleY(iparam3), sScaleY(iparam4));
      break;
    case CDMF_FRECT:
      fscanf(file, "%lg %lg %lg %lg", &dparam1, &dparam2, &dparam3, &dparam4);
      cdfCanvasRect(canvas, sfScaleX(dparam1), sfScaleX(dparam2), sfScaleY(dparam3), sfScaleY(dparam4));
      break;
    case CDMF_WRECT:
      fscanf(file, "%lg %lg %lg %lg", &dparam1, &dparam2, &dparam3, &dparam4);
      wdCanvasRect(canvas, dparam1, dparam2, dparam3, dparam4);
      break;
    case CDMF_BOX:
      fscanf(file, "%d %d %d %d", &iparam1, &iparam2, &iparam3, &iparam4);
      cdCanvasBox(canvas, sScaleX(iparam1), sScaleX(iparam2), sScaleY(iparam3), sScaleY(iparam4));
      break;
    case CDMF_WBOX:
      fscanf(file, "%lg %lg %lg %lg", &dparam1, &dparam2, &dparam3, &dparam4);
      wdCanvasBox(canvas, dparam1, dparam2, dparam3, dparam4);
      break;
    case CDMF_FBOX:
      fscanf(file, "%lg %lg %lg %lg", &dparam1, &dparam2, &dparam3, &dparam4);
      cdfCanvasBox(canvas, sfScaleX(dparam1), sfScaleX(dparam2), sfScaleY(dparam3), sfScaleY(dparam4));
      break;
    case CDMF_ARC:
      fscanf(file, "%d %d %d %d %lg %lg", &iparam1, &iparam2, &iparam3, &iparam4, &dparam1, &dparam2);
      cdCanvasArc(canvas, sScaleX(iparam1), sScaleY(iparam2), sScaleW(iparam3), sScaleH(iparam4), dparam1, dparam2);
      break;
    case CDMF_FARC:
      fscanf(file, "%lg %lg %lg %lg %lg %lg", &dparam1, &dparam2, &dparam3, &dparam4, &dparam5, &dparam6);
      cdfCanvasArc(canvas, sfScaleX(dparam1), sfScaleY(dparam2), sfScaleW(dparam3), sfScaleH(dparam4), dparam5, dparam6);
      break;
    case CDMF_WARC:
      fscanf(file, "%lg %lg %lg %lg %lg %lg", &dparam1, &dparam2, &dparam3, &dparam4, &dparam5, &dparam6);
      wdCanvasArc(canvas, dparam1, dparam2, dparam3, dparam4, dparam5, dparam6);
      break;
    case CDMF_SECTOR:
      fscanf(file, "%d %d %d %d %lg %lg", &iparam1, &iparam2, &iparam3, &iparam4, &dparam1, &dparam2);
      cdCanvasSector(canvas, sScaleX(iparam1), sScaleY(iparam2), sScaleW(iparam3), sScaleH(iparam4), dparam1, dparam2);
      break;
    case CDMF_FSECTOR:
      fscanf(file, "%lg %lg %lg %lg %lg %lg", &dparam1, &dparam2, &dparam3, &dparam4, &dparam5, &dparam6);
      cdfCanvasSector(canvas, sfScaleX(dparam1), sfScaleY(dparam2), sfScaleW(dparam3), sfScaleH(dparam4), dparam5, dparam6);
      break;
    case CDMF_WSECTOR:
      fscanf(file, "%lg %lg %lg %lg %lg %lg", &dparam1, &dparam2, &dparam3, &dparam4, &dparam5, &dparam6);
      wdCanvasSector(canvas, dparam1, dparam2, dparam3, dparam4, dparam5, dparam6);
      break;
    case CDMF_CHORD:
      fscanf(file, "%d %d %d %d %lg %lg", &iparam1, &iparam2, &iparam3, &iparam4, &dparam1, &dparam2);
      cdCanvasChord(canvas, sScaleX(iparam1), sScaleY(iparam2), sScaleW(iparam3), sScaleH(iparam4), dparam1, dparam2);
      break;
    case CDMF_FCHORD:
      fscanf(file, "%lg %lg %lg %lg %lg %lg", &dparam1, &dparam2, &dparam3, &dparam4, &dparam5, &dparam6);
      cdfCanvasChord(canvas, sfScaleX(dparam1), sfScaleY(dparam2), sfScaleW(dparam3), sfScaleH(dparam4), dparam5, dparam6);
      break;
    case CDMF_WCHORD:
      fscanf(file, "%lg %lg %lg %lg %lg %lg", &dparam1, &dparam2, &dparam3, &dparam4, &dparam5, &dparam6);
      wdCanvasChord(canvas, dparam1, dparam2, dparam3, dparam4, dparam5, dparam6);
      break;
    case CDMF_TEXT:
      fscanf(file, "%d %d %[^\n\r]", &iparam1, &iparam2, TextBuffer);
      cdCanvasText(canvas, sScaleX(iparam1), sScaleY(iparam2), TextBuffer);
      break;
    case CDMF_FTEXT:
      fscanf(file, "%lg %lg %[^\n\r]", &dparam1, &dparam2, TextBuffer);
      cdfCanvasText(canvas, sfScaleX(dparam1), sfScaleY(dparam2), TextBuffer);
      break;
    case CDMF_WTEXT:
      fscanf(file, "%lg %lg %[^\n\r]", &dparam1, &dparam2, TextBuffer);
      wdCanvasText(canvas, dparam1, dparam2, TextBuffer);
      break;
    case CDMF_BEGIN:
      fscanf(file, "%d", &iparam1);
      cdCanvasBegin(canvas, iparam1);
      break;
    case CDMF_VERTEX:
      fscanf(file, "%d %d", &iparam1, &iparam2);
      cdCanvasVertex(canvas, sScaleX(iparam1), sScaleY(iparam2));
      break;
    case CDMF_FVERTEX:
      fscanf(file, "%lg %lg", &dparam1, &dparam2);
      cdfCanvasVertex(canvas, sfScaleX(dparam1), sfScaleY(dparam2));
      break;
    case CDMF_WVERTEX:
      fscanf(file, "%lg %lg", &dparam1, &dparam2);
      wdCanvasVertex(canvas, dparam1, dparam2);
      break;
    case CDMF_END:
      cdCanvasEnd(canvas);
      break;
    case CDMF_MARK:
      fscanf(file, "%d %d", &iparam1, &iparam2);
      cdCanvasMark(canvas, sScaleX(iparam1), sScaleY(iparam2));
      break;
    case CDMF_WMARK:
      fscanf(file, "%lg %lg", &dparam1, &dparam2);
      wdCanvasMark(canvas, dparam1, dparam2);
      break;
    case CDMF_BACKOPACITY:
      fscanf(file, "%d", &iparam1);
      cdCanvasBackOpacity(canvas, iparam1);
      break;
    case CDMF_WRITEMODE:
      fscanf(file, "%d", &iparam1);
      cdCanvasWriteMode(canvas, iparam1);
      break;
    case CDMF_LINESTYLE:
      fscanf(file, "%d", &iparam1);
      cdCanvasLineStyle(canvas, iparam1);
      break;
    case CDMF_LINEWIDTH:
      fscanf(file, "%d", &iparam1);
      cdCanvasLineWidth(canvas, sScaleS(iparam1));
      break;
    case CDMF_LINECAP:
      fscanf(file, "%d", &iparam1);
      cdCanvasLineCap(canvas, iparam1);
      break;
    case CDMF_LINEJOIN:
      fscanf(file, "%d", &iparam1);
      cdCanvasLineJoin(canvas, iparam1);
      break;
    case CDMF_LINESTYLEDASHES:
      fscanf(file, "%d", &iparam1);
      dashes = (int*)malloc(iparam1*sizeof(int));
      for (c = 0; c < iparam1; c++)
        fscanf(file, "%d", &dashes[c]);
      cdCanvasLineStyleDashes(canvas, dashes, iparam1);
      free(dashes);
      break;
    case CDMF_FILLMODE:
      fscanf(file, "%d", &iparam1);
      cdCanvasFillMode(canvas, iparam1);
      break;
    case CDMF_INTERIORSTYLE:
      fscanf(file, "%d", &iparam1);
      cdCanvasInteriorStyle(canvas, iparam1);
      break;
    case CDMF_HATCH:
      fscanf(file, "%d", &iparam1);
      cdCanvasHatch(canvas, iparam1);
      break;
    case CDMF_STIPPLE:
      fscanf(file, "%d %d", &iparam1, &iparam2);
      t = iparam1 * iparam2;
      stipple = (unsigned char*)malloc(t);
      _stipple = stipple;
      for (c = 0; c < t; c++)
      {
        fscanf(file, "%d", &iparam3);
        *_stipple++ = (unsigned char)iparam3;
      }
      cdCanvasStipple(canvas, iparam1, iparam2, stipple);
      free(stipple);
      break;
    case CDMF_PATTERN:
      fscanf(file, "%d %d", &iparam1, &iparam2);
      t = iparam1 * iparam2;
      pattern = (long int*)malloc(t * sizeof(long));
      _pattern = pattern;
      for (c = 0; c < t; c++)
      {
        fscanf(file, "%d %d %d", &iparam3, &iparam4, &iparam5);
        *_pattern++ = cdEncodeColor((unsigned char)iparam3, (unsigned char)iparam4, (unsigned char)iparam5);
      }
      cdCanvasPattern(canvas, iparam1, iparam2, pattern);
      free(pattern);
      break;
    case CDMF_OLDFONT:
      fscanf(file, "%d %d %d", &iparam1, &iparam2, &iparam3);
      if (iparam1 < 0 || iparam1 > 3) break;
      if (iparam3 < 0)
      {
        iparam3 = -sScaleH(abs(iparam3));
        if (iparam3 > -5) iparam3 = -5;
      }
      else
      {
        iparam3 = sScaleH(abs(iparam3));
        if (iparam3 < 5) iparam3 = 5;
      }
      cdCanvasFont(canvas, font_family[iparam1], iparam2, iparam3);
      break;
    case CDMF_FONT:
      fscanf(file, "%d %d %[^\n\r]", &iparam2, &iparam3, TextBuffer);
      if (iparam3 < 0)
      {
        iparam3 = -sScaleH(abs(iparam3));
        if (iparam3 > -5) iparam3 = -5;
      }
      else
      {
        iparam3 = sScaleH(abs(iparam3));
        if (iparam3 < 5) iparam3 = 5;
      }
      cdCanvasFont(canvas, TextBuffer, iparam2, iparam3);
      break;
    case CDMF_NATIVEFONT:
      fscanf(file, "%[^\n\r]", TextBuffer);
      cdCanvasNativeFont(canvas, TextBuffer);
      break;
    case CDMF_TEXTALIGNMENT:
      fscanf(file, "%d", &iparam1);
      cdCanvasTextAlignment(canvas, iparam1);
      break;
    case CDMF_TEXTORIENTATION:
      fscanf(file, "%lg", &dparam1);
      cdCanvasTextOrientation(canvas, dparam1);
      break;
    case CDMF_MARKTYPE:
      fscanf(file, "%d", &iparam1);
      cdCanvasMarkType(canvas, iparam1);
      break;
    case CDMF_MARKSIZE:
      fscanf(file, "%d", &iparam1);
      cdCanvasMarkSize(canvas, sScaleS(iparam1));
      break;
    case CDMF_PALETTE:
      fscanf(file, "%d %d", &iparam1, &iparam2);
      _palette = palette = (long int*)malloc(iparam1);
      for (c = 0; c < iparam1; c++)
      {
        fscanf(file, "%d %d %d", &iparam3, &iparam4, &iparam5);
        *_palette++ = cdEncodeColor((unsigned char)iparam3, (unsigned char)iparam4, (unsigned char)iparam5);
      }
      cdCanvasPalette(canvas, iparam1, palette, iparam2);
      free(palette);
      break;
    case CDMF_BACKGROUND:
      fscanf(file, "%d %d %d", &iparam1, &iparam2, &iparam3);
      cdCanvasSetBackground(canvas, cdEncodeColor((unsigned char)iparam1, (unsigned char)iparam2, (unsigned char)iparam3));
      break;
    case CDMF_FOREGROUND:
      fscanf(file, "%d %d %d", &iparam1, &iparam2, &iparam3);
      cdCanvasSetForeground(canvas, cdEncodeColor((unsigned char)iparam1, (unsigned char)iparam2, (unsigned char)iparam3));
      break;
    case CDMF_PUTIMAGERGB:
      fscanf(file, "%d %d %d %d %d %d", &iparam1, &iparam2, &iparam3, &iparam4, &iparam5, &iparam6);
      t = iparam1 * iparam2;
      _red = red = (unsigned char*) malloc(t);
      _green = green = (unsigned char*) malloc(t);
      _blue = blue = (unsigned char*) malloc(t);
      for (c = 0; c < t; c++)
      {
        fscanf(file, "%d %d %d", &iparam7, &iparam8, &iparam9);
        *_red++ = (unsigned char)iparam7;
        *_green++ = (unsigned char)iparam8;
        *_blue++ = (unsigned char)iparam9;
      }
      cdCanvasPutImageRectRGB(canvas, iparam1, iparam2, red, green, blue, sScaleX(iparam3), sScaleY(iparam4), sScaleW(iparam5), sScaleH(iparam6), 0, 0, 0, 0);
      free(red);
      free(green);
      free(blue);
      break;
    case CDMF_PUTIMAGERGBA:
      fscanf(file, "%d %d %d %d %d %d", &iparam1, &iparam2, &iparam3, &iparam4, &iparam5, &iparam6);
      t = iparam1 * iparam2;
      _red = red = (unsigned char*) malloc(t);
      _green = green = (unsigned char*) malloc(t);
      _blue = blue = (unsigned char*) malloc(t);
      _alpha = alpha = (unsigned char*) malloc(t);
      for (c = 0; c < t; c++)
      {
        fscanf(file, "%d %d %d %d", &iparam7, &iparam8, &iparam9, &iparam10);
        *_red++ = (unsigned char)iparam7;
        *_green++ = (unsigned char)iparam8;
        *_blue++ = (unsigned char)iparam9;
        *_alpha++ = (unsigned char)iparam10;
      }
      cdCanvasPutImageRectRGBA(canvas, iparam1, iparam2, red, green, blue, alpha, sScaleX(iparam3), sScaleY(iparam4), sScaleW(iparam5), sScaleH(iparam6), 0, 0, 0, 0);
      free(red);
      free(green);
      free(blue);
      free(alpha);
      break;
    case CDMF_PUTIMAGEMAP:
      fscanf(file, "%d %d %d %d %d %d", &iparam1, &iparam2, &iparam3, &iparam4, &iparam5, &iparam6);
      t = iparam1 * iparam2;
      n = 0;
      _index = index = (unsigned char*) malloc(t);
      for (c = 0; c < t; c++)
      {
        fscanf(file, "%d", &iparam7);
        *_index++ = (unsigned char)iparam7;
        if (iparam7 > n)
          n = iparam7;
      }
      _colors = colors = (long int*)malloc(n);
      for (c = 0; c < n; c++)
      {
        fscanf(file, "%d %d %d", &iparam7, &iparam8, &iparam9);
        *_colors++ = cdEncodeColor((unsigned char)iparam7, (unsigned char)iparam8, (unsigned char)iparam9);
      }
      cdCanvasPutImageRectMap(canvas, iparam1, iparam2, index, colors, sScaleX(iparam3), sScaleY(iparam4), sScaleW(iparam5), sScaleH(iparam6), 0, 0, 0, 0);
      free(index);
      free(colors);
      break;
    case CDMF_PIXEL:
      fscanf(file, "%d %d %d %d %d", &iparam1, &iparam2, &iparam3, &iparam4, &iparam5);
      cdCanvasPixel(canvas, sScaleX(iparam1), sScaleY(iparam2), cdEncodeColor((unsigned char)iparam3, (unsigned char)iparam4, (unsigned char)iparam5));
      break;
    case CDMF_SCROLLAREA:
      fscanf(file, "%d %d %d %d %d %d", &iparam1, &iparam2, &iparam3, &iparam4, &iparam5, &iparam6);
      cdCanvasScrollArea(canvas, sScaleX(iparam1), sScaleX(iparam2), sScaleY(iparam3), sScaleY(iparam4), sScaleX(iparam5), sScaleY(iparam6));
      break;
    case CDMF_WVECTORTEXT:
      fscanf(file, "%lg %lg %[^\n\r]", &dparam1, &dparam2, TextBuffer);
      wdCanvasVectorText(canvas, dparam1, dparam2, TextBuffer);
      break;
    case CDMF_WMULTILINEVECTORTEXT:
      fscanf(file, "%lg %lg %[^\n\r]", &dparam1, &dparam2, TextBuffer);
      wdCanvasVectorText(canvas, dparam1, dparam2, TextBuffer);
      break;
    case CDMF_VECTORTEXT:
      fscanf(file, "%d %d %[^\n\r]", &iparam1, &iparam2, TextBuffer);
      cdCanvasVectorText(canvas, iparam1, iparam2, TextBuffer);
      break;
    case CDMF_MULTILINEVECTORTEXT:
      fscanf(file, "%d %d %[^\n\r]", &iparam1, &iparam2, TextBuffer);
      cdCanvasVectorText(canvas, iparam1, iparam2, TextBuffer);
      break;
    case CDMF_WVECTORCHARSIZE:
      fscanf(file, "%lg", &dparam1);
      wdCanvasVectorCharSize(canvas, dparam1);
      break;
    case CDMF_WVECTORTEXTSIZE:
      fscanf(file, "%lg %lg %[^\n\r]", &dparam1, &dparam2, TextBuffer);
      wdCanvasVectorTextSize(canvas, dparam1, dparam2, TextBuffer);
      break;
    case CDMF_WVECTORTEXTDIRECTION:
      fscanf(file, "%lg %lg %lg %lg", &dparam1, &dparam2, &dparam3, &dparam4);
      wdCanvasVectorTextDirection(canvas, dparam1, dparam2, dparam3, dparam4);
      break;
    case CDMF_VECTORCHARSIZE:
      fscanf(file, "%d", &iparam1);
      cdCanvasVectorCharSize(canvas, iparam1);
      break;
    case CDMF_VECTORTEXTSIZE:
      fscanf(file, "%d %d %[^\n\r]", &iparam1, &iparam2, TextBuffer);
      cdCanvasVectorTextSize(canvas, iparam1, iparam2, TextBuffer);
      break;
    case CDMF_VECTORTEXTDIRECTION:
      fscanf(file, "%d %d %d %d", &iparam1, &iparam2, &iparam3, &iparam4);
      cdCanvasVectorTextDirection(canvas, iparam1, iparam2, iparam3, iparam4);
      break;
    case CDMF_VECTORFONT:
      fscanf(file, "%[^\n\r]", TextBuffer);
      cdCanvasVectorFont(canvas, TextBuffer);
      break;
    case CDMF_VECTORTEXTTRANSFORM:
      fscanf(file, "%lg %lg %lg %lg %lg %lg", &matrix[0], &matrix[1], &matrix[2], &matrix[3], &matrix[4], &matrix[5]);
      cdCanvasVectorTextTransform(canvas, matrix);
      break;
    case CDMF_WINDOW:
      fscanf(file, "%lg %lg %lg %lg", &dparam1, &dparam2, &dparam3, &dparam4);
      wdCanvasWindow(canvas, dparam1, dparam2, dparam3, dparam4);
      break;
    default:
      fclose(file);
      return CD_ERROR;
    }
  }

  fclose(file);

  return CD_OK;
}