Esempio n. 1
0
File: cdwimg.c Progetto: LuaDist/cd
/*
%F cdCreateCanvas para Image.
O DC é um BITMAP em memoria.
*/
static void cdcreatecanvas(cdCanvas* canvas, void *data)
{
  cdCtxCanvas* ctxcanvas;
  cdCtxImage* ctximage;
  
  if (data == NULL)
    return;

  ctximage = ((cdImage*)data)->ctximage;

  /* Inicializa parametros */
  if (ctximage == NULL) 
    return;
  
  /* Inicializa driver Image */
  ctxcanvas = cdwCreateCanvas(canvas, NULL, ctximage->hDC, CDW_BMP);

  canvas->w = ctximage->w;
  canvas->h = ctximage->h;
  canvas->w_mm = ctximage->w_mm;
  canvas->h_mm = ctximage->h_mm;
  canvas->bpp = ctximage->bpp;
  canvas->xres = ctximage->xres;
  canvas->yres = ctximage->yres;
  ctxcanvas->clip_pnt[2].x = ctxcanvas->clip_pnt[1].x = canvas->w - 1;
  ctxcanvas->clip_pnt[3].y = ctxcanvas->clip_pnt[2].y = canvas->h - 1;
}
Esempio n. 2
0
static void cdcreatecanvas(cdCanvas* canvas, void* data)
{
  cdCtxCanvas* ctxcanvas;
  char* strdata = (char*)data;
  int w = 0, h = 0;
  double res = 0, xres, yres;
  FILE* fh;
  char filename[10240] = "";
  
  /* Inicializa parametros */
  if (strdata == NULL) 
    return;


  strdata += cdGetFileName(strdata, filename);
  if (filename[0] == 0)
    return;
  
  sscanf(strdata,"%dx%d %lg", &w, &h, &res); 
  if (w == 0 || h == 0)
    return;

  if (res)
  {
    xres = res;
    yres = res;
  }
  else
  {
    HDC ScreenDC = GetDC(NULL);
    xres = ((double)GetDeviceCaps(ScreenDC, LOGPIXELSX)) / 25.4;
    yres = ((double)GetDeviceCaps(ScreenDC, LOGPIXELSY)) / 25.4;
    ReleaseDC(NULL, ScreenDC);
  }
  
  /* Verifica se o arquivo pode ser aberto para escrita */
  fh = fopen(filename, "w");
  if (fh == 0)
    return;
  
  fclose(fh);
  
  /* Inicializa driver WIN32 */
  ctxcanvas = cdwCreateCanvas(canvas, NULL, CreateMetaFile(NULL), CDW_WMF);

  canvas->w = w;
  canvas->h = h;
  canvas->xres = xres;
  canvas->yres = yres;
  canvas->w_mm = ((double)w) / res;
  canvas->h_mm = ((double)h) / res;
  canvas->bpp = 24;
  ctxcanvas->clip_pnt[2].x = ctxcanvas->clip_pnt[1].x = canvas->w - 1;
  ctxcanvas->clip_pnt[3].y = ctxcanvas->clip_pnt[2].y = canvas->h - 1;
  
  /* Inicializacao de variaveis particulares para o WMF */
  ctxcanvas->filename = cdStrDup(filename);
}
Esempio n. 3
0
File: cdwemf.c Progetto: LuaDist/cd
/*
%F cdCreateCanvas para EMF.
O DC é um EMF em memoria.
*/
static void cdcreatecanvas(cdCanvas* canvas, void* data)
{
  cdCtxCanvas* ctxcanvas;
  char* strdata = (char*)data;
  int w = 0, h = 0;
  double xres, yres;
  FILE* file;
  char filename[10240] = "";
  HDC ScreenDC, hDC;
  RECT rect;
  
  /* Inicializa parametros */
  if (strdata == NULL) 
    return;

  strdata += cdGetFileName(strdata, filename);
  if (filename[0] == 0)
    return;
 
  sscanf(strdata,"%dx%d", &w, &h); 
  if (w == 0 || h == 0)
    return;
  
  /* Verifica se o arquivo pode ser aberto para escrita */
  file = fopen(filename, "wb");
  if (file == NULL) return;
  fclose(file);
  
  ScreenDC = GetDC(NULL);
  /* LOGPIXELS can not be used for EMF */
  xres = (double)GetDeviceCaps(ScreenDC, HORZRES) / (double)GetDeviceCaps(ScreenDC, HORZSIZE);
  yres = (double)GetDeviceCaps(ScreenDC, VERTRES) / (double)GetDeviceCaps(ScreenDC, VERTSIZE);
  rect.left = 0;
  rect.top = 0;
  rect.right = (int)(100. * w / xres);
  rect.bottom = (int)(100. * h / yres);
  hDC = CreateEnhMetaFile(ScreenDC,filename,&rect,NULL);
  ReleaseDC(NULL, ScreenDC);
  
  if(!hDC)
    return;
  
  /* Inicializa driver WIN32 */
  ctxcanvas = cdwCreateCanvas(canvas, NULL, hDC, CDW_EMF);

  canvas->w = w;
  canvas->h = h;
  canvas->xres = xres;
  canvas->yres = yres;
  canvas->w_mm = ((double)w) / xres;
  canvas->h_mm = ((double)h) / yres;
  canvas->bpp = 24;
  ctxcanvas->clip_pnt[2].x = ctxcanvas->clip_pnt[1].x = canvas->w - 1;
  ctxcanvas->clip_pnt[3].y = ctxcanvas->clip_pnt[2].y = canvas->h - 1;
}
Esempio n. 4
0
static void cdcreatecanvas(cdCanvas* canvas, cdCanvas* canvas_dbuffer)
{
  int w, h;
  cdCtxCanvas* ctxcanvas;
  cdImage* image_dbuffer;
  cdCtxImage* ctximage;

  cdCanvasActivate(canvas_dbuffer);
  w = canvas_dbuffer->w;
  h = canvas_dbuffer->h;
  if (w==0) w=1;
  if (h==0) h=1;

  /* this is done in the canvas_dbuffer context */
  image_dbuffer = cdCanvasCreateImage(canvas_dbuffer, w, h);
  if (!image_dbuffer) 
    return;

  ctximage = image_dbuffer->ctximage;
  
  /* Inicializa driver DBuffer */
  ctxcanvas = cdwCreateCanvas(canvas, NULL, ctximage->hDC, CDW_BMP);

  ctxcanvas->image_dbuffer = image_dbuffer;
  ctxcanvas->canvas_dbuffer = canvas_dbuffer;

  canvas->w = ctximage->w;
  canvas->h = ctximage->h;
  canvas->w_mm = ctximage->w_mm;
  canvas->h_mm = ctximage->h_mm;
  canvas->bpp = ctximage->bpp;
  canvas->xres = ctximage->xres;
  canvas->yres = ctximage->yres;
  ctxcanvas->clip_pnt[2].x = ctxcanvas->clip_pnt[1].x = ctximage->w - 1;
  ctxcanvas->clip_pnt[3].y = ctxcanvas->clip_pnt[2].y = ctximage->h - 1;
}
Esempio n. 5
0
/*
%F cdCreateCanvas para Impresora.
Usa a impressora default.
*/
static void cdcreatecanvas(cdCanvas* canvas, void *data)
{
  cdCtxCanvas* ctxcanvas;
  char *data_str = (char*) data;
  char docname[256] = "CD - Canvas Draw Document";
  DOCINFO di;
  HDC hDC;
  int dialog = 0, wtype;
  PRINTDLG pd;

  /* Inicializa parametros */
  if (data_str == NULL) 
    return;
  
  if (data_str[0] != 0)
  {
    char *ptr = strstr(data_str, "-d");

    if (ptr != NULL)
      dialog = 1;

    if (data_str[0] != '-')
    {
      strcpy(docname, data_str);

      if (dialog)
        docname[ptr - data_str - 1] = 0;
    }
  }
  
  ZeroMemory(&pd, sizeof(PRINTDLG));
  pd.lStructSize = sizeof(PRINTDLG);
  pd.nCopies = 1;

  if (dialog)
  {
    pd.Flags = PD_RETURNDC | PD_USEDEVMODECOPIES | PD_COLLATE | PD_NOPAGENUMS | PD_NOSELECTION;
    pd.hwndOwner = GetForegroundWindow();
  }
  else
  {
    pd.Flags = PD_RETURNDC | PD_RETURNDEFAULT;
  }
  
  if (!PrintDlg(&pd))
  {
    if(pd.hDevMode) 
      GlobalFree(pd.hDevMode);
    if(pd.hDevNames) 
      GlobalFree(pd.hDevNames);
    return;
  }

  hDC = pd.hDC; 

  /* Inicializa documento */
  di.cbSize = sizeof(DOCINFO);
  di.lpszDocName = docname;
  di.lpszOutput = (LPTSTR) NULL;
  di.lpszDatatype = (LPTSTR) NULL; 
  di.fwType = 0; 

  StartDoc(hDC, &di);
  
  StartPage(hDC);
  
  wtype = CDW_EMF;
  
  /* Inicializa driver WIN32 */
  ctxcanvas = cdwCreateCanvas(canvas, NULL, hDC, wtype);
  
  canvas->w = GetDeviceCaps(hDC, HORZRES);
  canvas->h = GetDeviceCaps(hDC, VERTRES);
  canvas->w_mm = (double) GetDeviceCaps(hDC, HORZSIZE);
  canvas->h_mm = (double) GetDeviceCaps(hDC, VERTSIZE);
  canvas->bpp = GetDeviceCaps(hDC, BITSPIXEL);
  canvas->xres = canvas->w / canvas->w_mm;
  canvas->yres = canvas->h / canvas->h_mm;
  ctxcanvas->clip_pnt[2].x = ctxcanvas->clip_pnt[1].x = canvas->w - 1;
  ctxcanvas->clip_pnt[3].y = ctxcanvas->clip_pnt[2].y = canvas->h - 1;

  /* PDF Writer returns bpp=1, so we check if color is supported and overwrite this value */
  if (canvas->bpp==1 && pd.hDevNames)
  {
    unsigned char* devnames = (unsigned char*)GlobalLock(pd.hDevNames);
    DEVNAMES* dn = (DEVNAMES*)devnames;
    char* name = (char*)(devnames + dn->wDeviceOffset);
    char* port = (char*)(devnames + dn->wOutputOffset);

    if (DeviceCapabilities(name, port, DC_COLORDEVICE, NULL, NULL))
      canvas->bpp = 24;

    GlobalUnlock(pd.hDevNames);
  }

  if(pd.hDevMode) 
    GlobalFree(pd.hDevMode);
  if(pd.hDevNames) 
    GlobalFree(pd.hDevNames);
}
Esempio n. 6
0
File: cdwclp.c Progetto: LuaDist/cd
static void cdcreatecanvas(cdCanvas* canvas, void *data)
{
  char* strsize = (char*)data;
  int w = 0, h = 0, wtype = CDW_EMF; /* default clipboard type */
  double xres=0, yres=0;
  HDC hDC;
  BITMAPINFO bmi;
  BYTE* bits;
  HBITMAP hBitmapClip, hOldBitmapClip;
  
  /* Inicializa parametros */
  if (strsize == NULL) 
    return;
  
  if (strstr(strsize, "-b") != NULL)
    wtype = CDW_BMP;
  else if (strstr(strsize, "-m") != NULL)
    wtype = -1; /* CD METAFILE */
  
  if (wtype != -1)
  {
    sscanf(strsize,"%dx%d",&w, &h); 
    if (w == 0 || h == 0)
      return;
  }

  if (wtype == CDW_EMF)
  {
    HDC ScreenDC = GetDC(NULL);
    RECT rect;
    /* LOGPIXELS can not be used for EMF */
    xres = (double)GetDeviceCaps(ScreenDC, HORZRES) / (double)GetDeviceCaps(ScreenDC, HORZSIZE);
    yres = (double)GetDeviceCaps(ScreenDC, VERTRES) / (double)GetDeviceCaps(ScreenDC, VERTSIZE);
    rect.left = 0;
    rect.top = 0;
    rect.right = (int)(100. * w / xres);
    rect.bottom = (int)(100. * h / yres);
    hDC = CreateEnhMetaFile(ScreenDC,NULL,&rect,NULL);
    ReleaseDC(NULL, ScreenDC);
  }
  else if (wtype == CDW_BMP)
  {
    HDC ScreenDC = GetDC(NULL);
    hDC = CreateCompatibleDC(ScreenDC);
    xres = (double)GetDeviceCaps(ScreenDC, HORZRES) / (double)GetDeviceCaps(ScreenDC, HORZSIZE);
    yres = (double)GetDeviceCaps(ScreenDC, VERTRES) / (double)GetDeviceCaps(ScreenDC, VERTSIZE);
    
    bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    bmi.bmiHeader.biWidth = w;
    bmi.bmiHeader.biHeight = h;
    bmi.bmiHeader.biPlanes = 1;
    bmi.bmiHeader.biBitCount = 24;
    bmi.bmiHeader.biCompression = BI_RGB;
    bmi.bmiHeader.biSizeImage = 0;
    bmi.bmiHeader.biXPelsPerMeter = (long)(GetDeviceCaps(ScreenDC, LOGPIXELSX) / 0.0254);
    bmi.bmiHeader.biYPelsPerMeter = (long)(GetDeviceCaps(ScreenDC, LOGPIXELSY) / 0.0254);
    bmi.bmiHeader.biClrUsed = 0;
    bmi.bmiHeader.biClrImportant = 0;
    
    hBitmapClip = CreateDIBSection(hDC, &bmi, DIB_RGB_COLORS, &bits, NULL, 0);
    
    ReleaseDC(NULL, ScreenDC);

    if (!hBitmapClip)
      return;

    hOldBitmapClip = SelectObject(hDC, hBitmapClip);
  }
  
  if (wtype == -1)
  {
    char filename[10240]; 
    char str[10240];
    
    if (!cdStrTmpFileName(filename))
      return;
    
    sprintf(str, "%s %s", filename, strsize);
    cdcreatecanvasMF(canvas, str);
  }                    
  else
  {
    cdCtxCanvas* ctxcanvas;

    /* Inicializa driver WIN32 */
    ctxcanvas = cdwCreateCanvas(canvas, NULL, hDC, wtype);
  
    canvas->w = w;
    canvas->h = h;
    canvas->xres = xres;
    canvas->yres = yres;
    canvas->w_mm = ((double)w) / xres;
    canvas->h_mm = ((double)h) / yres;
    canvas->bpp = 24;
    ctxcanvas->clip_pnt[2].x = ctxcanvas->clip_pnt[1].x = canvas->w - 1;
    ctxcanvas->clip_pnt[3].y = ctxcanvas->clip_pnt[2].y = canvas->h - 1;

    if (wtype == CDW_BMP)
    {
      ctxcanvas->hBitmapClip = hBitmapClip;
      ctxcanvas->hOldBitmapClip = hOldBitmapClip;
      ctxcanvas->bmiClip = bmi;
      ctxcanvas->bitsClip = bits;
    }
  }
}