Esempio n. 1
0
static int cdactivate(cdCtxCanvas* ctxcanvas)
{
  int w, h;
  cdCanvas* canvas_dbuffer = ctxcanvas->canvas_dbuffer;

  /* this is done in the canvas_dbuffer context */
  /* this will update canvas size */
  cdCanvasActivate(canvas_dbuffer);
  w = canvas_dbuffer->w;
  h = canvas_dbuffer->h;
  if (w==0) w=1;
  if (h==0) h=1;

  /* check if the size changed */
  if (w != ctxcanvas->image_dbuffer->w ||
      h != ctxcanvas->image_dbuffer->h)
  {
    cdCanvas* canvas = ctxcanvas->canvas;
    /* save the current, if the rebuild fail */
    cdImage* old_image_dbuffer = ctxcanvas->image_dbuffer;
    cdCtxCanvas* old_ctxcanvas = ctxcanvas;

    /* if the image is rebuild, the canvas that uses the image must be also rebuild */

    /* rebuild the image and the canvas */
    canvas->ctxcanvas = NULL;
    canvas->context->cxCreateCanvas(canvas, canvas_dbuffer);
    if (!canvas->ctxcanvas)
    {
      canvas->ctxcanvas = old_ctxcanvas;
      return CD_ERROR;
    }

    /* remove the old image and canvas */
    cdKillImage(old_image_dbuffer);
    cdgdkKillCanvas(old_ctxcanvas);

    ctxcanvas = canvas->ctxcanvas;

    /* update canvas attributes */
    cdUpdateAttributes(canvas);
  }

  return CD_OK;
}
Esempio n. 2
0
cdCanvas *cdCreateCanvas(cdContext* context, void *data_str)
{
  cdCanvas *canvas;

  /* usefull for NULL drivers, that do nothing and exist only for portability */
  if (!context)
    return NULL;

  {
    static int first = 1;
    char* env = getenv("CD_QUIET");
    if (first && env && strcmp(env, "NO") == 0)  /* default is quiet */
    {
      printf("CD  " CD_VERSION CD_VERSION_FIX " " CD_COPYRIGHT "\n");
      first = 0;
    }
  }

  /* alocates and initialize everything with 0s */
  canvas = (cdCanvas*)malloc(sizeof(cdCanvas));
  memset(canvas, 0, sizeof(cdCanvas));

  canvas->signature[0] = 'C';
  canvas->signature[1] = 'D';

  canvas->vector_font = cdCreateVectorFont(canvas);
  canvas->simulation = cdCreateSimulation(canvas);

  canvas->context = context;

  /* initialize default attributes, must be before creating the canvas */
  cd_setdefaultattrib(canvas);

  context->cxCreateCanvas(canvas, data_str);
  if (!canvas->ctxcanvas)
  {
    cdKillVectorFont(canvas->vector_font);
    cdKillSimulation(canvas->simulation);
    memset(canvas, 0, sizeof(cdCanvas));
    free(canvas);
    return NULL;
  }

  /* default simulation functions */
  cd_setdefaultfunc(canvas);

  /* initialize canvas table */
  context->cxInitTable(canvas);

  /* update the default atributes, must be after InitTable */
  cdCanvasActivate(canvas);
  cdUpdateAttributes(canvas);

  /* must be after creating the canvas, so that we know canvas width and height */
  canvas->clip_rect.xmax = canvas->w-1;
  canvas->clip_rect.ymax = canvas->h-1;

  wdSetDefaults(canvas);

  return canvas;
}