Exemplo n.º 1
0
void iupPlotDataSet::DrawSelection(const iupPlotTrafoBase *inTrafoX, const iupPlotTrafoBase *inTrafoY, cdCanvas* canvas, const iupPlotSampleNotify* inNotify) const
{
  int theCount = mDataX->GetCount();

  cdCanvasMarkSize(canvas, 7);

  for (int i = 0; i < theCount; i++)
  {
    if (mSelection->GetSampleBool(i))
    {
      double theX = mDataX->GetSample(i);
      double theY = mDataY->GetSample(i);
      double theScreenX = inTrafoX->Transform(theX);
      double theScreenY = inTrafoY->Transform(theY);

      if (inNotify->cb)
      {
        int ret = inNotify->cb(inNotify->ih, inNotify->ds, i, theX, theY, (int)mSelection->GetSampleBool(i));
        if (ret == IUP_IGNORE)
          continue;
      }

      cdCanvasMarkType(canvas, CD_BOX);
      cdCanvasSetForeground(canvas, cdEncodeAlpha(CD_GRAY, 128));
      cdfCanvasMark(canvas, theScreenX, theScreenY);

      cdCanvasMarkType(canvas, CD_HOLLOW_BOX);
      cdCanvasSetForeground(canvas, cdEncodeAlpha(CD_BLACK, 128));
      cdfCanvasMark(canvas, theScreenX, theScreenY);
    }
  }
}
Exemplo n.º 2
0
void iupPlotDataSet::DrawDataHorizontalBar(const iupPlotTrafoBase *inTrafoX, const iupPlotTrafoBase *inTrafoY, cdCanvas* canvas, const iupPlotSampleNotify* inNotify) const
{
  int theCount = mDataX->GetCount();
  double theScreenX0 = inTrafoX->Transform(0);


  double theMinY = mDataY->GetSample(0);
  double theScreenMinY = inTrafoY->Transform(theMinY);
  double theMaxY = mDataY->GetSample(theCount - 1);
  double theScreenMaxY = inTrafoY->Transform(theMaxY);

  double theBarHeight = (theScreenMaxY - theScreenMinY) / (theCount - 1);
  theBarHeight *= 1 - (double)mBarSpacingPercent / 100.0;

  for (int i = 0; i < theCount; i++)
  {
    double theX = mDataX->GetSample(i);
    double theY = mDataY->GetSample(i);
    double theScreenX = inTrafoX->Transform(theX);
    double theScreenY = inTrafoY->Transform(theY);

    double theBarY = theScreenY - theBarHeight / 2;
    double theBarWidth = theScreenX - theScreenX0;

    if (inNotify->cb)
      inNotify->cb(inNotify->ih, inNotify->ds, i, theX, theY, (int)mSelection->GetSampleBool(i));

    if (theBarWidth == 0)
      continue;

    if (mBarMulticolor)
      cdCanvasSetForeground(canvas, iPlotGetSampleColorTable(inNotify->ih, i));

    iPlotDrawBox(canvas, theScreenX0, theBarY, theBarWidth, theBarHeight);

    if (mBarShowOutline)
    {
      cdCanvasSetForeground(canvas, mBarOutlineColor);
      iPlotDrawRect(canvas, theScreenX0, theBarY, theBarWidth, theBarHeight);
    }

    if (i == mHighlightedSample)
      iPlotDrawHighlightedBar(canvas, theScreenX0, theBarY, theBarWidth, theBarHeight);

    if (mBarShowOutline && !mBarMulticolor)
      cdCanvasSetForeground(canvas, mColor); // restore curve color
  }
}
Exemplo n.º 3
0
bool iupPlotGrid::DrawX(iupPlotTickIterBase* inTickIter, iupPlotTrafoBase* inTrafo, const iupPlotRect &inRect, cdCanvas* canvas) const
{
  if (mShowX)
  {
    if (!inTickIter->Init())
      return false;

    double theX;
    bool theIsMajorTick;

    cdCanvasSetForeground(canvas, mColor);
    iPlotSetLine(canvas, mLineStyle, mLineWidth);

    while (inTickIter->GetNextTick(theX, theIsMajorTick, NULL))
    {
      if ((theIsMajorTick && mMajor) || (!theIsMajorTick && !mMajor))
      {
        double theScreenX = inTrafo->Transform(theX);
        cdfCanvasLine(canvas, theScreenX, inRect.mY, theScreenX, inRect.mY + inRect.mHeight - 1);
      }
    }
  }

  return true;
}
Exemplo n.º 4
0
bool iupPlotGrid::DrawY(iupPlotTickIterBase* inTickIter, iupPlotTrafoBase* inTrafo, const iupPlotRect &inRect, cdCanvas* canvas) const
{
  if (mShowY)
  {
    if (!inTickIter->Init())
      return false;

    double theY;
    bool theIsMajorTick;
    iupPlotRect theTickRect;

    cdCanvasSetForeground(canvas, mColor);
    iPlotSetLine(canvas, mLineStyle, mLineWidth);

    while (inTickIter->GetNextTick(theY, theIsMajorTick, NULL))
    {
      if ((theIsMajorTick && mMajor) || (!theIsMajorTick && !mMajor))
      {
        double theScreenY = inTrafo->Transform(theY);
        cdfCanvasLine(canvas, inRect.mX, theScreenY, inRect.mX + inRect.mWidth - 1, theScreenY);
      }
    }
  }

  return true;
}
Exemplo n.º 5
0
void iupPlot::DrawBackground(cdCanvas* canvas) const
{
  cdCanvasOrigin(canvas, 0, 0);
  cdCanvasClip(canvas, CD_CLIPOFF);
  cdCanvasSetForeground(canvas, mBack.mColor);
  cdCanvasBox(canvas, mViewportBack.mX, mViewportBack.mX + mViewportBack.mWidth - 1, mViewportBack.mY, mViewportBack.mY + mViewportBack.mHeight - 1);
}
Exemplo n.º 6
0
void iupPlotBox::Draw(const iupPlotRect &inRect, cdCanvas* canvas) const
{
  cdCanvasSetForeground(canvas, mColor);
  iPlotSetLine(canvas, mLineStyle, mLineWidth);

  iPlotDrawRectI(canvas, inRect.mX, inRect.mY, inRect.mWidth, inRect.mHeight);
}
Exemplo n.º 7
0
static void iPlotDrawHighlightedArc(cdCanvas *canvas, double xc, double yc, double w, double h, double startAngle, double endAngle)
{
  int foreground = cdCanvasForeground(canvas, CD_QUERY);
  int highlightColor = cdEncodeAlpha(foreground, HIGHTLIGHT_ALPHA);
  int width = cdCanvasLineWidth(canvas, CD_QUERY);
  int style = cdCanvasLineStyle(canvas, CD_QUERY);

  cdCanvasLineStyle(canvas, CD_CONTINUOUS);
  cdCanvasLineWidth(canvas, width + HIGHTLIGHT_OFFSET);
  cdCanvasSetForeground(canvas, highlightColor);

  cdfCanvasArc(canvas, xc, yc, w, h, startAngle, endAngle);

  cdCanvasLineStyle(canvas, style);
  cdCanvasLineWidth(canvas, width);
  cdCanvasSetForeground(canvas, foreground);
}
Exemplo n.º 8
0
static void iPlotDrawHighlightedLine(cdCanvas *canvas, double x1, double y1, double x2, double y2)
{
  int foreground = cdCanvasForeground(canvas, CD_QUERY);
  int highlightColor = cdEncodeAlpha(foreground, HIGHTLIGHT_ALPHA);
  int width = cdCanvasLineWidth(canvas, CD_QUERY);
  int style = cdCanvasLineStyle(canvas, CD_QUERY);

  cdCanvasLineStyle(canvas, CD_CONTINUOUS);
  cdCanvasLineWidth(canvas, width + HIGHTLIGHT_OFFSET);
  cdCanvasSetForeground(canvas, highlightColor);

  cdfCanvasLine(canvas, x1, y1, x2, y2);

  cdCanvasSetForeground(canvas, foreground);
  cdCanvasLineStyle(canvas, style);
  cdCanvasLineWidth(canvas, width);
}
Exemplo n.º 9
0
static void iPlotDrawHighlightedMark(cdCanvas *canvas, double x, double y)
{
  int foreground = cdCanvasForeground(canvas, CD_QUERY);
  int highlightColor = cdEncodeAlpha(foreground, HIGHTLIGHT_ALPHA);
  int size = cdCanvasMarkSize(canvas, CD_QUERY);
  int type = cdCanvasMarkType(canvas, CD_QUERY);

  cdCanvasMarkSize(canvas, size + HIGHTLIGHT_OFFSET);
  cdCanvasMarkType(canvas, CD_CIRCLE);
  cdCanvasSetForeground(canvas, highlightColor);

  cdfCanvasMark(canvas, x, y);

  cdCanvasSetForeground(canvas, foreground);
  cdCanvasMarkSize(canvas, size);
  cdCanvasMarkType(canvas, type);
}
Exemplo n.º 10
0
void iupPlot::DrawInactive(cdCanvas* canvas) const
{
  cdCanvasOrigin(canvas, 0, 0);
  cdCanvasClip(canvas, CD_CLIPOFF);
  long inactive_color = cdEncodeAlpha(CD_GRAY, 96);
  cdCanvasSetForeground(canvas, inactive_color);
  cdCanvasBox(canvas, mViewportBack.mX, mViewportBack.mX + mViewportBack.mWidth - 1, mViewportBack.mY, mViewportBack.mY + mViewportBack.mHeight - 1);
}
Exemplo n.º 11
0
static void iPlotDrawHighlightedBar(cdCanvas *canvas, double x, double y, double barWidth, double barHeight)
{
  int foreground = cdCanvasForeground(canvas, CD_QUERY);
  int highlightColor = cdEncodeAlpha(foreground, HIGHTLIGHT_ALPHA);
  int width = cdCanvasLineWidth(canvas, CD_QUERY);
  int style = cdCanvasLineStyle(canvas, CD_QUERY);

  cdCanvasLineStyle(canvas, CD_CONTINUOUS);
  cdCanvasLineWidth(canvas, width + HIGHTLIGHT_OFFSET);
  cdCanvasSetForeground(canvas, highlightColor);

  iPlotDrawRect(canvas, x, y, barWidth, barHeight);

  cdCanvasLineStyle(canvas, style);
  cdCanvasLineWidth(canvas, width);
  cdCanvasSetForeground(canvas, foreground);
}
Exemplo n.º 12
0
void iupPlotDataSet::DrawDataMultiBar(const iupPlotTrafoBase *inTrafoX, const iupPlotTrafoBase *inTrafoY, cdCanvas* canvas, const iupPlotSampleNotify* inNotify) const
{
  int theCount = mDataX->GetCount();
  double theScreenY0 = inTrafoY->Transform(0);

  double theMinX = mDataX->GetSample(0);
  double theScreenMinX = inTrafoX->Transform(theMinX);
  double theMaxX = mDataX->GetSample(theCount - 1);
  double theScreenMaxX = inTrafoX->Transform(theMaxX);

  double theTotalBarWidth = (theScreenMaxX - theScreenMinX) / (theCount - 1);
  theTotalBarWidth *= 1 - (double)mBarSpacingPercent / 100.0;
  double theBarWidth = theTotalBarWidth / mMultibarCount;

  for (int i = 0; i < theCount; i++)
  {
    double theX = mDataX->GetSample(i);
    double theY = mDataY->GetSample(i);
    double theScreenX = inTrafoX->Transform(theX);
    double theScreenY = inTrafoY->Transform(theY);

    double theBarX = (theScreenX - theTotalBarWidth / 2) + (mMultibarIndex*theBarWidth);
    double theBarHeight = theScreenY - theScreenY0;

    if (inNotify->cb)
      inNotify->cb(inNotify->ih, inNotify->ds, i, theX, theY, (int)mSelection->GetSampleBool(i));

    if (theBarHeight == 0)
      continue;

    iPlotDrawBox(canvas, theBarX, theScreenY0, theBarWidth, theBarHeight);

    if (mBarShowOutline)
    {
      cdCanvasSetForeground(canvas, mBarOutlineColor);
      iPlotDrawRect(canvas, theBarX, theScreenY0, theBarWidth, theBarHeight);
    }

    if (i == mHighlightedSample)
      iPlotDrawHighlightedBar(canvas, theBarX, theScreenY0, theBarWidth, theBarHeight);

    if (mBarShowOutline)
      cdCanvasSetForeground(canvas, mColor); // restore curve color
  }
}
Exemplo n.º 13
0
void iupPlotDataSet::DrawData(const iupPlotTrafoBase *inTrafoX, const iupPlotTrafoBase *inTrafoY, cdCanvas* canvas, const iupPlotSampleNotify* inNotify) const
{
  int theXCount = mDataX->GetCount();
  int theYCount = mDataY->GetCount();

  if ((theXCount == 0) || (theYCount == 0))
    return;

  if (theXCount != theYCount)
    return;

  cdCanvasSetForeground(canvas, mColor);
  iPlotSetLine(canvas, mLineStyle, mLineWidth);
  iPlotSetMark(canvas, mMarkStyle, mMarkSize);

  switch (mMode)
  {
  case IUP_PLOT_LINE:
    DrawDataLine(inTrafoX, inTrafoY, canvas, inNotify, false, false);
    break;
  case IUP_PLOT_MARK:
    DrawDataMark(inTrafoX, inTrafoY, canvas, inNotify);
    break;
  case IUP_PLOT_STEM:
    DrawDataStem(inTrafoX, inTrafoY, canvas, inNotify, false);
    break;
  case IUP_PLOT_MARKSTEM:
    DrawDataStem(inTrafoX, inTrafoY, canvas, inNotify, true);
    break;
  case IUP_PLOT_MARKLINE:
    DrawDataLine(inTrafoX, inTrafoY, canvas, inNotify, true, false);
    break;
  case IUP_PLOT_AREA:
    DrawDataArea(inTrafoX, inTrafoY, canvas, inNotify);
    break;
  case IUP_PLOT_BAR:
    DrawDataBar(inTrafoX, inTrafoY, canvas, inNotify);
    break;
  case IUP_PLOT_PIE: /* handled outside DrawData */
    break;
  case IUP_PLOT_HORIZONTALBAR:
    DrawDataHorizontalBar(inTrafoX, inTrafoY, canvas, inNotify);
    break;
  case IUP_PLOT_MULTIBAR:
    DrawDataMultiBar(inTrafoX, inTrafoY, canvas, inNotify);
    break;
  case IUP_PLOT_ERRORBAR:
    DrawDataLine(inTrafoX, inTrafoY, canvas, inNotify, true, true);
    break;
  case IUP_PLOT_STEP:
    DrawDataStep(inTrafoX, inTrafoY, canvas, inNotify);
    break;
  }

  if (mHasSelected)
    DrawSelection(inTrafoX, inTrafoY, canvas, inNotify);
}
Exemplo n.º 14
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);
}
Exemplo n.º 15
0
void iupPlot::DrawCrossHairV(const iupPlotRect &inRect, cdCanvas* canvas) const
{
  cdCanvasSetForeground(canvas, mAxisX.mColor);
  iPlotSetLine(canvas, CD_CONTINUOUS, 1);

  // Draw an horizontal line at cursor Y coordinate
  cdCanvasLine(canvas, inRect.mX, mCrossHairY, inRect.mX + inRect.mWidth - 1, mCrossHairY);

  for (int ds = 0; ds < mDataSetListCount; ds++)
  {
    iupPlotDataSet* dataset = mDataSetList[ds];

    const iupPlotDataBase *theXData = dataset->GetDataX();
    const iupPlotDataBase *theYData = dataset->GetDataY();

    cdCanvasSetForeground(canvas, dataset->mColor);

    DrawCrossSamplesV(inRect, theXData, theYData, canvas);
  }
}
Exemplo n.º 16
0
void iupPlot::DrawCrossHairH(const iupPlotRect &inRect, cdCanvas* canvas) const
{
  cdCanvasSetForeground(canvas, mAxisY.mColor);
  iPlotSetLine(canvas, CD_CONTINUOUS, 1);

  // Draw a vertical line at cursor X coordinate
  cdCanvasLine(canvas, mCrossHairX, inRect.mY, mCrossHairX, inRect.mY + inRect.mHeight - 1);

  for (int ds = 0; ds < mDataSetListCount; ds++)
  {
    iupPlotDataSet* dataset = mDataSetList[ds];

    const iupPlotDataBase *theXData = dataset->GetDataX();
    const iupPlotDataBase *theYData = dataset->GetDataY();

    cdCanvasSetForeground(canvas, dataset->mColor);

    DrawCrossSamplesH(inRect, theXData, theYData, canvas);
  }
}
Exemplo n.º 17
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());
  }
}
Exemplo n.º 18
0
static void primUpdateAttrib_Line(tPrimNode *prim, cdCanvas *canvas)
{
  cdCanvasSetBackground(canvas, prim->attrib.line.background);
  cdCanvasSetForeground(canvas, prim->attrib.line.foreground);
  cdCanvasBackOpacity(canvas, prim->attrib.line.back_opacity);
  cdCanvasLineStyle(canvas, prim->attrib.line.line_style); 
  cdCanvasLineWidth(canvas, sMin1(prim->attrib.line.line_width));
  cdCanvasLineCap(canvas, prim->attrib.line.line_cap);
  cdCanvasLineJoin(canvas, prim->attrib.line.line_join);

  if (prim->attrib.line.line_style==CD_CUSTOM && prim->attrib.line.line_dashes)
    cdCanvasLineStyleDashes(canvas, prim->attrib.line.line_dashes, prim->attrib.line.line_dashes_count);
}
Exemplo n.º 19
0
void primUpdateAttrib_Fill(tPrimNode *prim, cdCanvas *canvas)
{
  cdCanvasSetBackground(canvas, prim->attrib.fill.background);
  cdCanvasSetForeground(canvas, prim->attrib.fill.foreground);
  cdCanvasBackOpacity(canvas, prim->attrib.fill.back_opacity);
  cdCanvasFillMode(canvas, prim->attrib.fill.fill_mode);

  if (prim->attrib.fill.interior_style==CD_HATCH)
    cdCanvasHatch(canvas, prim->attrib.fill.hatch_style);
  else if (prim->attrib.fill.interior_style==CD_PATTERN && prim->attrib.fill.pattern)
    cdCanvasPattern(canvas, prim->attrib.fill.pattern_w, prim->attrib.fill.pattern_h, prim->attrib.fill.pattern);
  else if (prim->attrib.fill.interior_style==CD_STIPPLE && prim->attrib.fill.stipple)
    cdCanvasStipple(canvas, prim->attrib.fill.stipple_w, prim->attrib.fill.stipple_h, prim->attrib.fill.stipple);

  cdCanvasInteriorStyle(canvas, prim->attrib.fill.interior_style);
}
Exemplo n.º 20
0
void iupPlotDataSet::DrawDataLine(const iupPlotTrafoBase *inTrafoX, const iupPlotTrafoBase *inTrafoY, cdCanvas* canvas, const iupPlotSampleNotify* inNotify, bool inShowMark, bool inErrorBar) const
{
  int theCount = mDataX->GetCount();
  cdCanvasBegin(canvas, CD_OPEN_LINES);

  for (int i = 0; i < theCount; i++)
  {
    double theX = mDataX->GetSample(i);
    double theY = mDataY->GetSample(i);
    double theScreenX = inTrafoX->Transform(theX);
    double theScreenY = inTrafoY->Transform(theY);

    if (inNotify->cb)
      inNotify->cb(inNotify->ih, inNotify->ds, i, theX, theY, (int)mSelection->GetSampleBool(i));

    if (inShowMark)
    {
      if (mExtra)
      {
        if (inErrorBar)
          DrawErrorBar(inTrafoY, canvas, i, theY, theScreenX);
        else
          SetSampleExtraMarkSize(inTrafoY, canvas, i);
      }

      // No problem that will be drawn before the polygon, they both should have the same color
      cdfCanvasMark(canvas, theScreenX, theScreenY);
    }

    if (i == mHighlightedSample)
      iPlotDrawHighlightedMark(canvas, theScreenX, theScreenY);

    if (i > 0 && mSegment && mSegment->GetSampleBool(i))
    {
      cdCanvasEnd(canvas);
      cdCanvasBegin(canvas, CD_OPEN_LINES);
    }

    cdfCanvasVertex(canvas, theScreenX, theScreenY);
  }

  cdCanvasEnd(canvas);

  if (mHighlightedCurve)
  {
    int foreground = cdCanvasForeground(canvas, CD_QUERY);
    int highlightColor = cdEncodeAlpha(foreground, HIGHTLIGHT_ALPHA);
    int width = cdCanvasLineWidth(canvas, CD_QUERY);
    int style = cdCanvasLineStyle(canvas, CD_QUERY);

    cdCanvasLineStyle(canvas, CD_CONTINUOUS);
    cdCanvasLineWidth(canvas, width + HIGHTLIGHT_OFFSET);
    cdCanvasSetForeground(canvas, highlightColor);

    cdCanvasBegin(canvas, CD_OPEN_LINES);

    for (int i = 0; i < theCount; i++)
    {
      double theX = mDataX->GetSample(i);
      double theY = mDataY->GetSample(i);
      double theScreenX = inTrafoX->Transform(theX);
      double theScreenY = inTrafoY->Transform(theY);

      if (i > 0 && mSegment && mSegment->GetSampleBool(i))
      {
        cdCanvasEnd(canvas);
        cdCanvasBegin(canvas, CD_OPEN_LINES);
      }

      cdfCanvasVertex(canvas, theScreenX, theScreenY);
    }

    cdCanvasEnd(canvas);

    cdCanvasSetForeground(canvas, foreground);
    cdCanvasLineStyle(canvas, style);
    cdCanvasLineWidth(canvas, width);
  }
}
Exemplo n.º 21
0
bool iupPlot::DrawSampleColorLegend(iupPlotDataSet *dataset, const iupPlotRect &inRect, cdCanvas* canvas, iupPlotRect &ioPos) const
{
  if (mLegend.mShow)
  {
    int theFontHeight;

    SetFont(canvas, mLegend.mFontStyle, mLegend.mFontSize);
    cdCanvasGetFontDim(canvas, NULL, &theFontHeight, NULL, NULL);

    int theMargin = theFontHeight / 2;
    if (mLegend.mPosition == IUP_PLOT_BOTTOMCENTER)
      theMargin = 0;
    int theCount = dataset->GetCount();
    int theTotalHeight = theCount*theFontHeight + 2 * theMargin;
    int theLineSpace = theFontHeight / 2 + 3;

    int theWidth, theMaxWidth = 0;
    for (int i = 0; i < theCount; i++)
    {
      cdCanvasGetTextSize(canvas, ((iupPlotDataString *)dataset->GetDataX())->GetSampleString(i), &theWidth, NULL);

      theWidth += theLineSpace;

      if (theWidth > theMaxWidth)
        theMaxWidth = theWidth;
    }

    if (theMaxWidth == 0)
      return false;

    theMaxWidth += 2 * theMargin;

    if (mLegend.mPosition != IUP_PLOT_XY)
    {
      int theScreenX = inRect.mX;
      int theScreenY = inRect.mY;

      switch (mLegend.mPosition)
      {
      case IUP_PLOT_TOPLEFT:
        theScreenX += 2;
        theScreenY += inRect.mHeight - theTotalHeight - 2;
        break;
      case IUP_PLOT_BOTTOMLEFT:
        theScreenX += 2;
        theScreenY += 2;
        break;
      case IUP_PLOT_BOTTOMRIGHT:
        theScreenX += inRect.mWidth - theMaxWidth - 2;
        theScreenY += 2;
        break;
      case IUP_PLOT_BOTTOMCENTER:
        theScreenX += (inRect.mWidth - theMaxWidth) / 2;
        theScreenY = theFontHeight / 4;
        break;
      default: // IUP_PLOT_TOPRIGHT
        theScreenX += inRect.mWidth - theMaxWidth - 2;
        theScreenY += inRect.mHeight - theTotalHeight - 2;
        break;
      }

      ioPos.mX = theScreenX;
      ioPos.mY = theScreenY;
    }

    ioPos.mWidth = theMaxWidth;
    ioPos.mHeight = theTotalHeight;

    // Clip to the legend box
    cdCanvasClipArea(canvas, ioPos.mX, ioPos.mX + ioPos.mWidth - 1,
                             ioPos.mY, ioPos.mY + ioPos.mHeight - 1);

    if (mLegend.mBoxShow)
    {
      cdCanvasSetForeground(canvas, mLegend.mBoxBackColor);
      iPlotDrawBox(canvas, ioPos.mX + 1, ioPos.mY + 1, ioPos.mWidth - 2, ioPos.mHeight - 2);

      cdCanvasSetForeground(canvas, mLegend.mBoxColor);
      iPlotSetLine(canvas, mLegend.mBoxLineStyle, mLegend.mBoxLineWidth);
      iPlotDrawRectI(canvas, ioPos.mX, ioPos.mY, ioPos.mWidth, ioPos.mHeight);
    }

    for (int i = 0; i < theCount; i++)
    {
      cdCanvasSetForeground(canvas, iPlotGetSampleColorTable(ih, i));

      int theLegendX = ioPos.mX + theMargin;
      int theLegendY = ioPos.mY + (theCount - 1 - i)*theFontHeight + theMargin;

      int boxSize = theLineSpace - 3;

      cdCanvasBox(canvas, theLegendX, theLegendX + boxSize, theLegendY, theLegendY + boxSize);

      iPlotDrawText(canvas, theLegendX + theLineSpace, theLegendY + boxSize / 2, CD_WEST, ((iupPlotDataString *)dataset->GetDataX())->GetSampleString(i));
    }
  }

  return true;
}
Exemplo n.º 22
0
bool iupPlot::DrawLegend(const iupPlotRect &inRect, cdCanvas* canvas, iupPlotRect &ioPos) const
{
  if (mLegend.mShow)
  {
    int ds;
    int theFontHeight;

    SetFont(canvas, mLegend.mFontStyle, mLegend.mFontSize);
    cdCanvasGetFontDim(canvas, NULL, &theFontHeight, NULL, NULL);

    int theMargin = theFontHeight / 2;
    if (mLegend.mPosition == IUP_PLOT_BOTTOMCENTER)
      theMargin = 0;
    int theTotalHeight = mDataSetListCount*theFontHeight + 2 * theMargin;
    int theLineSpace = 20;

    int theWidth, theMaxWidth = 0;
    for (ds = 0; ds < mDataSetListCount; ds++)
    {
      iupPlotDataSet* dataset = mDataSetList[ds];

      cdCanvasGetTextSize(canvas, dataset->GetName(), &theWidth, NULL);

      if (dataset->mMode == IUP_PLOT_MARK || dataset->mMode == IUP_PLOT_MARKLINE)
      {
        if (dataset->mMarkSize + 6 > theLineSpace)
          theLineSpace = dataset->mMarkSize + 6;
      }

      theWidth += theLineSpace;

      if (theWidth > theMaxWidth)
        theMaxWidth = theWidth;
    }

    if (theMaxWidth == 0)
      return false;

    theMaxWidth += 2 * theMargin;

    if (mLegend.mPosition != IUP_PLOT_XY)
    {
      int theScreenX = inRect.mX;
      int theScreenY = inRect.mY;

      switch (mLegend.mPosition)
      {
      case IUP_PLOT_TOPLEFT:
        theScreenX += 2;
        theScreenY += inRect.mHeight - theTotalHeight - 2;
        break;
      case IUP_PLOT_BOTTOMLEFT:
        theScreenX += 2;
        theScreenY += 2;
        break;
      case IUP_PLOT_BOTTOMRIGHT:
        theScreenX += inRect.mWidth - theMaxWidth - 2;
        theScreenY += 2;
        break;
      case IUP_PLOT_BOTTOMCENTER:
        theScreenX += (inRect.mWidth - theMaxWidth) / 2;
        theScreenY = theFontHeight / 4;
        break;
      default: // IUP_PLOT_TOPRIGHT
        theScreenX += inRect.mWidth - theMaxWidth - 2;
        theScreenY += inRect.mHeight - theTotalHeight - 2;
        break;
      }

      ioPos.mX = theScreenX;
      ioPos.mY = theScreenY;
    }

    ioPos.mWidth = theMaxWidth;
    ioPos.mHeight = theTotalHeight;

    // Clip to the legend box
    cdCanvasClipArea(canvas, ioPos.mX, ioPos.mX + ioPos.mWidth - 1,
                             ioPos.mY, ioPos.mY + ioPos.mHeight - 1);

    if (mLegend.mBoxShow)
    {
      cdCanvasSetForeground(canvas, mLegend.mBoxBackColor);
      iPlotDrawBox(canvas, ioPos.mX + 1, ioPos.mY + 1, ioPos.mWidth - 2, ioPos.mHeight - 2);

      cdCanvasSetForeground(canvas, mLegend.mBoxColor);
      iPlotSetLine(canvas, mLegend.mBoxLineStyle, mLegend.mBoxLineWidth);
      iPlotDrawRectI(canvas, ioPos.mX, ioPos.mY, ioPos.mWidth, ioPos.mHeight);
    }

    for (ds = 0; ds < mDataSetListCount; ds++)
    {
      iupPlotDataSet* dataset = mDataSetList[ds];

      cdCanvasSetForeground(canvas, dataset->mColor);

      int theLegendX = ioPos.mX + theMargin;
      int theLegendY = ioPos.mY + (mDataSetListCount - 1 - ds)*theFontHeight + theMargin;

      theLegendY += theFontHeight / 2;

      if (dataset->mMode == IUP_PLOT_MARK || dataset->mMode == IUP_PLOT_MARKLINE)
      {
        iPlotSetMark(canvas, dataset->mMarkStyle, dataset->mMarkSize);
        cdCanvasMark(canvas, theLegendX + (theLineSpace - 3) / 2, theLegendY - theFontHeight / 8);
      }
      if (dataset->mMode != IUP_PLOT_MARK)
      {
        iPlotSetLine(canvas, dataset->mLineStyle, dataset->mLineWidth);
        cdCanvasLine(canvas, theLegendX, theLegendY - theFontHeight / 8,
                             theLegendX + theLineSpace - 3, theLegendY - theFontHeight / 8);
      }

      iPlotDrawText(canvas, theLegendX + theLineSpace, theLegendY, CD_WEST, dataset->GetName());
    }
  }

  return true;
}
Exemplo n.º 23
0
bool iupPlotAxis::DrawY(const iupPlotRect &inRect, cdCanvas* canvas, const iupPlotAxis& inAxisX) const
{
  if (!mShow)
    return true;

  cdCanvasSetForeground(canvas, mColor);
  iPlotSetLine(canvas, CD_CONTINUOUS, mLineWidth);

  double theScreenX = GetScreenXOriginY(inAxisX);
  double theScreenY1 = inRect.mY;
  double theScreenY2 = theScreenY1 + inRect.mHeight;

  cdfCanvasLine(canvas, theScreenX, theScreenY1, theScreenX, theScreenY2);

  if (mShowArrow)
  {
    if (!mReverse)
      iPlotDrawArrow(canvas, theScreenX, theScreenY2, 1, 1, mTick.mMinorSize);
    else
      iPlotDrawArrow(canvas, theScreenX, theScreenY1, 1, -1, mTick.mMinorSize);
  }

  if (mTick.mShow)
  {
    if (!mTickIter->Init())
      return false;

    double theY;
    bool theIsMajorTick;
    char theFormatString[30];
    strcpy(theFormatString, mTick.mFormatString);

    if (mTick.mShowNumber)
      SetFont(canvas, mTick.mFontStyle, mTick.mFontSize);

    while (mTickIter->GetNextTick(theY, theIsMajorTick, theFormatString))
    {
      if (!DrawYTick(theY, theScreenX, theIsMajorTick, theFormatString, canvas))
        return false;
    }

    theScreenX -= mTick.mMajorSize;  // skip major tick
    if (mTick.mShowNumber)
    {
      if (mTick.mRotateNumber)
      {
        int theYTickNumberHeight;
        GetTickNumberSize(canvas, NULL, &theYTickNumberHeight);
        theScreenX -= theYTickNumberHeight;
      }
      else
      {
        int theYTickNumberWidth;
        GetTickNumberSize(canvas, &theYTickNumberWidth, NULL);
        theScreenX -= theYTickNumberWidth;
      }
    }
  }

  if (GetLabel())
  {
    SetFont(canvas, mFontStyle, mFontSize);

    if (mLabelSpacing == -1)
    {
      int theYFontHeight;
      cdCanvasGetFontDim(canvas, NULL, &theYFontHeight, NULL, NULL);
      theScreenX -= theYFontHeight / 10;  // default spacing
    }
    else
      theScreenX -= mLabelSpacing;

    if (mLabelCentered)
    {
      double theScreenY = theScreenY1 + inRect.mHeight / 2;
      iPlotDrawRotatedText(canvas, theScreenX, theScreenY, 90, CD_SOUTH, GetLabel());
    }
    else
    {
      double theScreenY = theScreenY2;
      iPlotDrawRotatedText(canvas, theScreenX, theScreenY, 90, CD_SOUTH_EAST, GetLabel());
    }
  }

  return true;
}
Exemplo n.º 24
0
void iupPlotDataSet::DrawDataStep(const iupPlotTrafoBase *inTrafoX, const iupPlotTrafoBase *inTrafoY, cdCanvas* canvas, const iupPlotSampleNotify* inNotify) const
{
  int theCount = mDataX->GetCount();
  cdCanvasBegin(canvas, CD_OPEN_LINES);
  double theLastScreenX = 0.;

  for (int i = 0; i < theCount; i++)
  {
    double theX = mDataX->GetSample(i);
    double theY = mDataY->GetSample(i);
    double theScreenX = inTrafoX->Transform(theX);
    double theScreenY = inTrafoY->Transform(theY);

    if (inNotify->cb)
      inNotify->cb(inNotify->ih, inNotify->ds, i, theX, theY, (int)mSelection->GetSampleBool(i));

    if (i > 0 && mSegment && mSegment->GetSampleBool(i))
    {
      cdCanvasEnd(canvas);
      cdCanvasBegin(canvas, CD_OPEN_LINES);
    }

    if (i > 0)
      cdfCanvasVertex(canvas, theLastScreenX, theScreenY);

    cdfCanvasVertex(canvas, theScreenX, theScreenY);

    if (i == mHighlightedSample)
      iPlotDrawHighlightedMark(canvas, theScreenX, theScreenY);

    theLastScreenX = theScreenX;
  }

  cdCanvasEnd(canvas);


  if (mHighlightedCurve)
  {
    int foreground = cdCanvasForeground(canvas, CD_QUERY);
    int highlightColor = cdEncodeAlpha(foreground, HIGHTLIGHT_ALPHA);
    int width = cdCanvasLineWidth(canvas, CD_QUERY);
    int style = cdCanvasLineStyle(canvas, CD_QUERY);

    cdCanvasLineStyle(canvas, CD_CONTINUOUS);
    cdCanvasLineWidth(canvas, width + HIGHTLIGHT_OFFSET);
    cdCanvasSetForeground(canvas, highlightColor);

    cdCanvasBegin(canvas, CD_OPEN_LINES);

    for (int i = 0; i < theCount; i++)
    {
      double theX = mDataX->GetSample(i);
      double theY = mDataY->GetSample(i);
      double theScreenX = inTrafoX->Transform(theX);
      double theScreenY = inTrafoY->Transform(theY);

      if (i > 0 && mSegment && mSegment->GetSampleBool(i))
      {
        cdCanvasEnd(canvas);
        cdCanvasBegin(canvas, CD_OPEN_LINES);
      }

      if (i > 0)
        cdfCanvasVertex(canvas, theLastScreenX, theScreenY);

      cdfCanvasVertex(canvas, theScreenX, theScreenY);

      theLastScreenX = theScreenX;
    }

    cdCanvasEnd(canvas);

    cdCanvasSetForeground(canvas, foreground);
    cdCanvasLineStyle(canvas, style);
    cdCanvasLineWidth(canvas, width);
  }
}
Exemplo n.º 25
0
void iupPlotDataSet::DrawDataPie(const iupPlotTrafoBase *inTrafoX, const iupPlotTrafoBase *inTrafoY, cdCanvas* canvas, const iupPlotSampleNotify* inNotify, const iupPlotAxis& inAxisY, long inBackColor) const
{
  int theXCount = mDataX->GetCount();
  int theYCount = mDataY->GetCount();

  if ((theXCount == 0) || (theYCount == 0))
    return;

  if (theXCount != theYCount)
    return;

  double xc, yc, w, h;

  int theCount = mDataX->GetCount();
  double sum = 0;

  for (int i = 0; i < theCount; i++)
  {
    double theY = mDataY->GetSample(i);

    if (theY <= 0)
      continue;

    sum += theY;
  }

  xc = 0;
  yc = 0;
  xc = inTrafoX->Transform(xc);
  yc = inTrafoY->Transform(yc);

  w = 2.0 * mPieRadius;
  h = 2.0 * mPieRadius;
  w *= ((iupPlotTrafoLinear *)inTrafoX)->mSlope;
  h *= ((iupPlotTrafoLinear *)inTrafoY)->mSlope;

  double w1 = 2.0 * (mPieRadius*1.01);
  double h1 = 2.0 * (mPieRadius*1.01);
  w1 *= ((iupPlotTrafoLinear *)inTrafoX)->mSlope;
  h1 *= ((iupPlotTrafoLinear *)inTrafoY)->mSlope;

  double startAngle = mPieStartAngle;

  if (mPieContour)
    iPlotSetLine(canvas, mLineStyle, mLineWidth);

  if (mPieSliceLabel != IUP_PLOT_NONE)
    inAxisY.SetFont(canvas, inAxisY.mFontStyle, inAxisY.mFontSize);

  for (int i = 0; i < theCount; i++)
  {
    double theX = mDataX->GetSample(i);
    double theY = mDataY->GetSample(i);

    if (theY <= 0)
      continue;

    double angle = (theY*360.) / sum;

    if (inNotify->cb)
      inNotify->cb(inNotify->ih, inNotify->ds, i, theX, theY, (int)mSelection->GetSampleBool(i));

    cdCanvasSetForeground(canvas, iPlotGetSampleColorTable(inNotify->ih, i));

    cdfCanvasSector(canvas, xc, yc, w, h, startAngle, startAngle + angle);

    if (mPieContour)
    {
      int foreground = cdCanvasForeground(canvas, mColor);

      cdCanvasInteriorStyle(canvas, CD_HOLLOW);
      cdfCanvasSector(canvas, xc, yc, w, h, startAngle, startAngle + angle);
      cdCanvasInteriorStyle(canvas, CD_SOLID);

      cdCanvasForeground(canvas, foreground);
    }

    if (i == mHighlightedSample)
      iPlotDrawHighlightedArc(canvas, xc, yc, w1, h1, startAngle, startAngle + angle);

    if (mPieSliceLabel != IUP_PLOT_NONE)
    {
      double bisectrix = (startAngle + startAngle + angle) / 2;

      int text_alignment = iPlotGetPieTextAligment(bisectrix, mPieSliceLabelPos);

      double px = xc + (((w / 2.)*fabs(mPieSliceLabelPos)) * cos(bisectrix * CD_DEG2RAD));
      double py = yc + (((h / 2.)*fabs(mPieSliceLabelPos)) * sin(bisectrix * CD_DEG2RAD));

      cdCanvasSetForeground(canvas, inAxisY.mColor);

      char theBuf[128];
      switch (mPieSliceLabel)
      {
      case IUP_PLOT_X:
        if (mDataX->IsString())
          iPlotDrawText(canvas, px, py, text_alignment, ((iupPlotDataString *)mDataX)->GetSampleString(i));
        else
        {
          sprintf(theBuf, "%d", i);
          iPlotDrawText(canvas, px, py, text_alignment, theBuf);
        }
        break;
      case IUP_PLOT_Y:
        iupStrPrintfDoubleLocale(theBuf, inAxisY.mTick.mFormatString, theY, IupGetGlobal("DEFAULTDECIMALSYMBOL"));
        iPlotDrawText(canvas, px, py, text_alignment, theBuf);
        break;
      case IUP_PLOT_PERCENT:
      {
        double percent = (theY*100.) / sum;
        iupStrPrintfDoubleLocale(theBuf, inAxisY.mTick.mFormatString, percent, IupGetGlobal("DEFAULTDECIMALSYMBOL"));
        strcat(theBuf, " %");
        iPlotDrawText(canvas, px, py, text_alignment, theBuf);
        break;
      }
      default:  /* IUP_PLOT_NONE */
        break;
      }
    }

    startAngle += angle;
  }

  if (mPieHole > 0)
  {
    double hw = mPieHole * 2.0 * mPieRadius;
    double hh = mPieHole * 2.0 * mPieRadius;
    hw *= ((iupPlotTrafoLinear *)inTrafoX)->mSlope;
    hh *= ((iupPlotTrafoLinear *)inTrafoY)->mSlope;

    cdCanvasSetForeground(canvas, inBackColor);

    cdfCanvasSector(canvas, xc, yc, hw, hh, 0., 360.);

    if (mPieContour)
    {
      cdCanvasSetForeground(canvas, mColor);

      cdCanvasInteriorStyle(canvas, CD_HOLLOW);
      cdfCanvasSector(canvas, xc, yc, hw, hh, 0., 360.);
      cdCanvasInteriorStyle(canvas, CD_SOLID);
    }
  }
}
Exemplo n.º 26
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 */
}
Exemplo n.º 27
0
Arquivo: cdmf.c Projeto: 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;
}