コード例 #1
0
static void cdcgm_PolyLine(int n, cgmPoint* pt, cdCGM* cd_cgm)
{
  int i;
  for (i=1; i<n; i+=2)
    cdfCanvasLine(cd_cgm->canvas, sScaleX(pt[i-1].x), sScaleY(pt[i-1].y), 
                                  sScaleX(pt[i].x),   sScaleY(pt[i].y));
}
コード例 #2
0
static void cdcgm_CircularArc(cgmPoint center, double radius, double angle1, double angle2, int arc, cdCGM* cd_cgm)
{
  fix_angles(cd_cgm, &angle1, &angle2);

  if (arc==CGM_OPENARC)
    cdfCanvasArc(cd_cgm->canvas, sScaleX(center.x), sScaleY(center.y), sScaleW(2*radius), sScaleH(2*radius), angle1, angle2);
  else
  {
    if (arc==CGM_PIE)
      cdfCanvasSector(cd_cgm->canvas, sScaleX(center.x), sScaleY(center.y), sScaleW(2*radius), sScaleH(2*radius), angle1, angle2);
    else  /* CGM_CHORD */
      cdfCanvasChord(cd_cgm->canvas, sScaleX(center.x), sScaleY(center.y), sScaleW(2*radius), sScaleH(2*radius), angle1, angle2);
  }
}
コード例 #3
0
static void cdcgm_PolyMarker(int n, cgmPoint* pt, cdCGM* cd_cgm)
{
  int i;

  if (cdCanvasMarkType(cd_cgm->canvas, CD_QUERY)==CD_BOX)
  {
    long color = cdCanvasForeground(cd_cgm->canvas, CD_QUERY);
    for (i=0; i<n; i++)
      cdCanvasPixel(cd_cgm->canvas, sRound(sScaleX(pt[i].x)), sRound(sScaleY(pt[i].y)), color);
  }
  else
  {
    for (i=0; i<n; i++)
      cdCanvasMark(cd_cgm->canvas, sRound(sScaleX(pt[i].x)), sRound(sScaleY(pt[i].y)));
  }
}
コード例 #4
0
static void cdcgm_EllipticalArc(cgmPoint center, cgmPoint first, cgmPoint second, double angle1, double angle2, int arc, cdCGM* cd_cgm)
{
  /* oriented ellipsis are not supported in CD */
  double w = 2*sScaleW(second.x-first.x);
  double h = 2*sScaleH(second.y-first.y);

  fix_angles(cd_cgm, &angle1, &angle2);

  if (arc==CGM_OPENARC)
    cdfCanvasArc(cd_cgm->canvas, sScaleX(center.x), sScaleY(center.y), w, h, angle1, angle2);
  else
  {
    if (arc==CGM_PIE)
      cdfCanvasSector(cd_cgm->canvas, sScaleX(center.x), sScaleY(center.y), w, h, angle1, angle2);
    else  /* CGM_CHORD */
      cdfCanvasChord(cd_cgm->canvas, sScaleX(center.x), sScaleY(center.y), w, h, angle1, angle2);
  }
}
コード例 #5
0
static void cdcgm_Polygon(int n, cgmPoint* pt, int fill, cdCGM* cd_cgm)
{
  int i, style;

  style = CD_FILL;
  if (fill==CGM_FILL)
    style = CD_FILL;
  else if (fill==CGM_CLOSEDLINES)
    style = CD_CLOSED_LINES;
  else if (fill==CGM_LINES)
    style = CD_OPEN_LINES;
  else if (fill==CGM_BEZIER)
    style = CD_BEZIER;

  cdCanvasBegin(cd_cgm->canvas, style);

  for (i=0; i<n; i++)
   cdfCanvasVertex(cd_cgm->canvas, sScaleX(pt[i].x), sScaleY(pt[i].y));

  cdCanvasEnd(cd_cgm->canvas);
}
コード例 #6
0
static void cdcgm_Text(const char* text, cgmPoint pos, cdCGM* cd_cgm)
{
  cdfCanvasText(cd_cgm->canvas, sScaleX(pos.x), sScaleY(pos.y), text);
}
コード例 #7
0
static void cdcgm_CellArray(cgmPoint corner1, cgmPoint corner2, cgmPoint corner3, int w, int h, unsigned char* rgb, cdCGM* cd_cgm)
{
  int cx1, cy1, cx2, cy2, cx3, cy3, 
      tmp, i, j, count, off, rgb_off;
  unsigned char *r, *g, *b;

  count = w*h;
  r = (unsigned char *) malloc (3*count*sizeof(unsigned char));
  if (!r) return;
  g = r + count;
  b = g + count;

  cx1 = sRound(sScaleX(corner1.x));
  cy1 = sRound(sScaleY(corner1.y));
  cx2 = sRound(sScaleX(corner2.x));
  cy2 = sRound(sScaleY(corner2.y));
  cx3 = sRound(sScaleX(corner3.x));
  cy3 = sRound(sScaleY(corner3.y));

  if ( cx1<cx3 && cy1==cy3 && cx2==cx3 && cy2>cy3 )
  {
    for ( i=0; i<h; i++ )
      for ( j=0; j<w; j++ )
      {
        off = w*i + j;
        rgb_off = 3*(w*i + j);
        r[off] = rgb[rgb_off+0];
        g[off] = rgb[rgb_off+1];
        b[off] = rgb[rgb_off+2];
      }
  }
  else if ( cx1==cx3 && cy1<cy3 && cx2>cx3 && cy2==cy3 )
  {
    tmp = w;   w = h;    h = tmp;
    for ( i=0; i<h; i++ )
      for ( j=0; j<w; j++ )
      {
        off = w*i + j;
        rgb_off = 3*(h*j + i);
        r[off] = rgb[rgb_off+0];
        g[off] = rgb[rgb_off+1];
        b[off] = rgb[rgb_off+2];
      }
  }
  else if ( cx1<cx3 && cy1==cy3 && cx2==cx3 && cy2<cy3 )
  {
    for ( i=0; i<h; i++ )
      for ( j=0; j<w; j++ )
      {
        off = w*i + j;
        rgb_off = 3*(w*(h-1 - i) + j);
        r[off] = rgb[rgb_off+0];
        g[off] = rgb[rgb_off+1];
        b[off] = rgb[rgb_off+2];
      }
  }
  else if ( cx1==cx3 && cy1>cy3 && cx2>cx3 && cy2==cy3 )
  {
    tmp = w;   w = h;    h = tmp;
    for ( i=0; i<h; i++ )
      for ( j=0; j<w; j++ )
      {
        off = w*i + j;
        rgb_off = h*j + (h-1 - i);
        r[off] = rgb[rgb_off+0];
        g[off] = rgb[rgb_off+1];
        b[off] = rgb[rgb_off+2];
      }
  }
  else if ( cx1>cx3 && cy1==cy3 && cx2==cx3 && cy2>cy3 )
  {
    for ( i=0; i<h; i++ )
      for ( j=0; j<w; j++ )
      {
        off = w*i + j;
        rgb_off = w*i + (w-1 - j);
        r[off] = rgb[rgb_off+0];
        g[off] = rgb[rgb_off+1];
        b[off] = rgb[rgb_off+2];
      }
  }
  else if ( cx1==cx3 && cy1>cy3 && cx2<cx3 && cy2==cy3 )
  {
    tmp = w;   w = h;    h = tmp;
    for ( i=0; i<h; i++ )
      for ( j=0; j<w; j++ )
      {
        off = w*i + j;
        rgb_off = h*(w-1 - j) + (h-1 - i);
        r[off] = rgb[rgb_off+0];
        g[off] = rgb[rgb_off+1];
        b[off] = rgb[rgb_off+2];
      }
  }
  else if ( cx1>cx3 && cy1==cy3 && cx2==cx3 && cy2<cy3 )
  {
    for ( i=0; i<h; i++ )
      for ( j=0; j<w; j++ )
      {
        off = w*i + j;
        rgb_off = w*(h-1 - i) + (w-1 - j);
        r[off] = rgb[rgb_off+0];
        g[off] = rgb[rgb_off+1];
        b[off] = rgb[rgb_off+2];
      }
  }
  else if ( cx1==cx3 && cy1<cy3 && cx2<cx3 && cy2==cy3 )
  {
    tmp = w;   w = h;    h = tmp;
    for ( i=0; i<h; i++ )
      for ( j=0; j<w; j++ )
      {
        off = w*i + j;
        rgb_off = h*(w-1 - j) + i;
        r[off] = rgb[rgb_off+0];
        g[off] = rgb[rgb_off+1];
        b[off] = rgb[rgb_off+2];
      }
  }

  if (cx1>cx2)
  {
    tmp = cx1;
    cx1 = cx2;
    cx2 = tmp;
  }

  if (cy1>cy2)
  {
    tmp = cy1;
    cy1 = cy2;
    cy2 = tmp;
  }

  cdCanvasPutImageRectRGB(cd_cgm->canvas, w, h, r, g, b, cx1, cy1, cx2-cx1+1, cy2-cy1+1,0,0,0,0);

  free(r);
}
コード例 #8
0
static void cdcgm_Ellipse(cgmPoint center, cgmPoint first, cgmPoint second, cdCGM* cd_cgm)
{
  double w = 2*sScaleW(second.x-first.x);
  double h = 2*sScaleH(second.y-first.y);
  cdfCanvasSector(cd_cgm->canvas, sScaleX(center.x), sScaleY(center.y), w, h, 0, 360);
}
コード例 #9
0
static void cdcgm_Circle(cgmPoint center, double radius, cdCGM* cd_cgm)
{
  cdfCanvasSector(cd_cgm->canvas, sScaleX(center.x), sScaleY(center.y), sScaleW(2*radius), sScaleH(2*radius), 0, 360);
}
コード例 #10
0
static void cdcgm_Rectangle(cgmPoint first, cgmPoint second, cdCGM* cd_cgm)
{
  cdfCanvasBox(cd_cgm->canvas, sScaleX(first.x), sScaleX(second.x),
                               sScaleY(first.y), sScaleY(second.y));
}
コード例 #11
0
ファイル: cdpicture.c プロジェクト: salmito/leda-image
static int cdplay(cdCanvas* canvas, int xmin, int xmax, int ymin, int ymax, void *data)
{
  tPrimNode *prim;
  cdCanvas* pic_canvas = (cdCanvas*)data;
  cdCtxCanvas* ctxcanvas = pic_canvas->ctxcanvas;
  int p, i, n, scale = 0, 
      pic_xmin = ctxcanvas->xmin,
      pic_ymin = ctxcanvas->ymin;
  double factorX = 1, factorY = 1;
  
  if ((ctxcanvas->xmax-ctxcanvas->xmin+1)>1 && 
      (ctxcanvas->ymax-ctxcanvas->ymin+1)>1 && 
      (xmax-xmin+1)>1 && 
      (ymax-ymin+1)>1)
  {
    scale = 1;
    factorX = ((double)(xmax-xmin+1)) / ((double)(ctxcanvas->xmax-ctxcanvas->xmin+1));
    factorY = ((double)(ymax-ymin+1)) / ((double)(ctxcanvas->ymax-ctxcanvas->ymin+1));
  }

  if (cdsizecb)
  {
    int err;
    err = cdsizecb(canvas, pic_canvas->w, pic_canvas->h, pic_canvas->w_mm, pic_canvas->h_mm);
    if (err)
      return CD_ERROR;
  }

  prim = ctxcanvas->prim_first;
  for (i = 0; i < ctxcanvas->prim_n; i++)
  { 
    switch (prim->type)
    {
    case CDPIC_LINE:
      primUpdateAttrib_Line(prim, canvas);
      cdCanvasLine(canvas, sScaleX(prim->param.lineboxrect.x1), sScaleY(prim->param.lineboxrect.y1), sScaleX(prim->param.lineboxrect.x2), sScaleY(prim->param.lineboxrect.y2));
      break;
    case CDPIC_FLINE:
      primUpdateAttrib_Line(prim, canvas);
      cdfCanvasLine(canvas, sfScaleX(prim->param.lineboxrectf.x1), sfScaleY(prim->param.lineboxrectf.y1), sfScaleX(prim->param.lineboxrectf.x2), sfScaleY(prim->param.lineboxrectf.y2));
      break;
    case CDPIC_RECT:
      primUpdateAttrib_Line(prim, canvas);
      cdCanvasRect(canvas, sScaleX(prim->param.lineboxrect.x1), sScaleX(prim->param.lineboxrect.x2), sScaleY(prim->param.lineboxrect.y1), sScaleY(prim->param.lineboxrect.y2));
      break;
    case CDPIC_FRECT:
      primUpdateAttrib_Line(prim, canvas);
      cdfCanvasRect(canvas, sfScaleX(prim->param.lineboxrectf.x1), sfScaleX(prim->param.lineboxrectf.x2), sfScaleY(prim->param.lineboxrectf.y1), sfScaleY(prim->param.lineboxrectf.y2));
      break;
    case CDPIC_BOX:
      primUpdateAttrib_Fill(prim, canvas);
      cdCanvasBox(canvas, sScaleX(prim->param.lineboxrect.x1), sScaleX(prim->param.lineboxrect.x2), sScaleY(prim->param.lineboxrect.y1), sScaleY(prim->param.lineboxrect.y2));
      break;
    case CDPIC_FBOX:
      primUpdateAttrib_Fill(prim, canvas);
      cdfCanvasBox(canvas, sfScaleX(prim->param.lineboxrectf.x1), sfScaleX(prim->param.lineboxrectf.x2), sfScaleY(prim->param.lineboxrectf.y1), sfScaleY(prim->param.lineboxrectf.y2));
      break;
    case CDPIC_ARC:
      primUpdateAttrib_Line(prim, canvas);
      cdCanvasArc(canvas, sScaleX(prim->param.arcsectorchord.xc), sScaleY(prim->param.arcsectorchord.yc), sScaleW(prim->param.arcsectorchord.w), sScaleH(prim->param.arcsectorchord.h), prim->param.arcsectorchord.angle1, prim->param.arcsectorchord.angle2);
      break;
    case CDPIC_FARC:
      primUpdateAttrib_Line(prim, canvas);
      cdfCanvasArc(canvas, sfScaleX(prim->param.arcsectorchordf.xc), sfScaleY(prim->param.arcsectorchordf.yc), sfScaleW(prim->param.arcsectorchordf.w), sfScaleH(prim->param.arcsectorchordf.h), prim->param.arcsectorchord.angle1, prim->param.arcsectorchord.angle2);
      break;
    case CDPIC_SECTOR:
      primUpdateAttrib_Fill(prim, canvas);
      cdCanvasSector(canvas, sScaleX(prim->param.arcsectorchord.xc), sScaleY(prim->param.arcsectorchord.yc), sScaleW(prim->param.arcsectorchord.w), sScaleH(prim->param.arcsectorchord.h), prim->param.arcsectorchord.angle1, prim->param.arcsectorchord.angle2);
      break;
    case CDPIC_FSECTOR:
      primUpdateAttrib_Fill(prim, canvas);
      cdfCanvasSector(canvas, sfScaleX(prim->param.arcsectorchordf.xc), sfScaleY(prim->param.arcsectorchordf.yc), sfScaleW(prim->param.arcsectorchordf.w), sfScaleH(prim->param.arcsectorchordf.h), prim->param.arcsectorchord.angle1, prim->param.arcsectorchord.angle2);
      break;
    case CDPIC_CHORD:
      primUpdateAttrib_Fill(prim, canvas);
      cdCanvasChord(canvas, sScaleX(prim->param.arcsectorchord.xc), sScaleY(prim->param.arcsectorchord.yc), sScaleW(prim->param.arcsectorchord.w), sScaleH(prim->param.arcsectorchord.h), prim->param.arcsectorchord.angle1, prim->param.arcsectorchord.angle2);
      break;
    case CDPIC_FCHORD:
      primUpdateAttrib_Fill(prim, canvas);
      cdfCanvasChord(canvas, sfScaleX(prim->param.arcsectorchordf.xc), sfScaleY(prim->param.arcsectorchordf.yc), sfScaleW(prim->param.arcsectorchordf.w), sfScaleH(prim->param.arcsectorchordf.h), prim->param.arcsectorchord.angle1, prim->param.arcsectorchord.angle2);
      break;
    case CDPIC_TEXT:
      primUpdateAttrib_Text(prim, canvas);
      cdCanvasText(canvas, sScaleX(prim->param.text.x), sScaleY(prim->param.text.y), prim->param.text.s);
      break;
    case CDPIC_FTEXT:
      primUpdateAttrib_Text(prim, canvas);
      cdfCanvasText(canvas, sfScaleX(prim->param.textf.x), sfScaleY(prim->param.textf.y), prim->param.text.s);
      break;
    case CDPIC_POLY:
      if (prim->param.poly.mode == CD_FILL)
        primUpdateAttrib_Fill(prim, canvas);
      else
        primUpdateAttrib_Line(prim, canvas);
      cdCanvasBegin(canvas, prim->param.poly.mode);
      for (p = 0; p < prim->param.poly.n; p++)
        cdCanvasVertex(canvas, sScaleX(prim->param.poly.points[p].x), sScaleY(prim->param.poly.points[p].y));
      cdCanvasEnd(canvas);
      break;
    case CDPIC_FPOLY:
      if (prim->param.poly.mode == CD_FILL)
        primUpdateAttrib_Fill(prim, canvas);
      else
        primUpdateAttrib_Line(prim, canvas);
      cdCanvasBegin(canvas, prim->param.polyf.mode);
      for (p = 0; p < prim->param.polyf.n; p++)
        cdfCanvasVertex(canvas, sfScaleX(prim->param.polyf.points[p].x), sfScaleY(prim->param.polyf.points[p].y));
      cdCanvasEnd(canvas);
      break;
    case CDPIC_PATH:
      if (prim->param.path.fill)
        primUpdateAttrib_Fill(prim, canvas);
      else
        primUpdateAttrib_Line(prim, canvas);
      cdCanvasBegin(canvas, CD_PATH);
      n = 0;
      for (p=0; p<prim->param.path.path_n; p++)
      {
        cdCanvasPathSet(canvas, prim->param.path.path[p]);

        switch(prim->param.path.path[p])
        {
        case CD_PATH_MOVETO:
        case CD_PATH_LINETO:
          cdCanvasVertex(canvas, sScaleX(prim->param.path.points[n].x), sScaleY(prim->param.path.points[n].y));
          n++;
          break;
        case CD_PATH_CURVETO:
        case CD_PATH_ARC:
          {
            cdCanvasVertex(canvas, sScaleX(prim->param.path.points[n].x), sScaleY(prim->param.path.points[n].y));
            cdCanvasVertex(canvas, sScaleX(prim->param.path.points[n+1].x), sScaleY(prim->param.path.points[n+1].y));
            cdCanvasVertex(canvas, sScaleX(prim->param.path.points[n+2].x), sScaleY(prim->param.path.points[n+2].y));
            n += 3;
          }
          break;
        }
      }
      cdCanvasEnd(canvas);
      break;
    case CDPIC_FPATH:
      if (prim->param.path.fill)
        primUpdateAttrib_Fill(prim, canvas);
      else
        primUpdateAttrib_Line(prim, canvas);
      cdCanvasBegin(canvas, CD_PATH);
      n = 0;
      for (p=0; p<prim->param.pathf.path_n; p++)
      {
        cdCanvasPathSet(canvas, prim->param.pathf.path[p]);

        switch(prim->param.pathf.path[p])
        {
        case CD_PATH_MOVETO:
        case CD_PATH_LINETO:
          cdfCanvasVertex(canvas, sfScaleX(prim->param.pathf.points[n].x), sfScaleY(prim->param.pathf.points[n].y));
          n++;
          break;
        case CD_PATH_CURVETO:
        case CD_PATH_ARC:
          {
            cdfCanvasVertex(canvas, sfScaleX(prim->param.pathf.points[n].x), sfScaleY(prim->param.pathf.points[n].y));
            cdfCanvasVertex(canvas, sfScaleX(prim->param.pathf.points[n+1].x), sfScaleY(prim->param.pathf.points[n+1].y));
            cdfCanvasVertex(canvas, sfScaleX(prim->param.pathf.points[n+2].x), sfScaleY(prim->param.pathf.points[n+2].y));
            n += 3;
          }
          break;
        }
      }
      cdCanvasEnd(canvas);
      break;
    case CDPIC_IMAGERGB:
      cdCanvasPutImageRectRGB(canvas, prim->param.imagergba.iw, prim->param.imagergba.ih, prim->param.imagergba.r, prim->param.imagergba.g, prim->param.imagergba.b, sScaleX(prim->param.imagergba.x), sScaleY(prim->param.imagergba.y), sScaleW(prim->param.imagergba.w), sScaleH(prim->param.imagergba.h), 0, 0, 0, 0);
      break;
    case CDPIC_IMAGERGBA:
      cdCanvasPutImageRectRGBA(canvas, prim->param.imagergba.iw, prim->param.imagergba.ih, prim->param.imagergba.r, prim->param.imagergba.g, prim->param.imagergba.b, prim->param.imagergba.a, sScaleX(prim->param.imagergba.x), sScaleY(prim->param.imagergba.y), sScaleW(prim->param.imagergba.w), sScaleH(prim->param.imagergba.h), 0, 0, 0, 0);
      break;
    case CDPIC_IMAGEMAP:
      cdCanvasPutImageRectMap(canvas, prim->param.imagemap.iw, prim->param.imagemap.ih, prim->param.imagemap.index, prim->param.imagemap.colors, sScaleX(prim->param.imagemap.x), sScaleY(prim->param.imagemap.y), sScaleW(prim->param.imagemap.w), sScaleH(prim->param.imagemap.h), 0, 0, 0, 0);
      break;
    case CDPIC_PIXEL:
      cdCanvasPixel(canvas, sScaleX(prim->param.pixel.x), sScaleY(prim->param.pixel.y), prim->param.pixel.color);
      break;
    }

    prim = prim->next;
  }

  return CD_OK;
}
コード例 #12
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;
}