static void cdcreatecanvas(cdCanvas* canvas, void *data) { char tmpPath[10240]; char* str_data = (char*)data; GtkClipboard* clp = NULL; /* Init parameters */ if (str_data == NULL) return; sscanf(str_data, "%p", &clp); if (!clp) return; str_data = strstr(str_data, " "); if (!str_data) return; str_data++; if (!cdStrTmpFileName(tmpPath)) return; strcat(tmpPath, " "); strcat(tmpPath, str_data); cdcreatecanvasMF(canvas, tmpPath); if (!canvas->ctxcanvas) return; { cdCanvasMF* mfcanvas = (cdCanvasMF*)canvas->ctxcanvas; mfcanvas->data = clp; } }
/* %F cdCreateCanvas para Clipboard O DC pode ser um WMF ou um BITMAP. */ static void cdcreatecanvas(cdCanvas* canvas, void *data) { char* str_data = (char*)data; int w = 0, h = 0, wtype = CDW_EMF; /* default clipboard type */ double res = 0; Metafile* metafile = NULL; Bitmap* bitmap = NULL; Graphics* graphics = NULL; /* Inicializa parametros */ if (str_data == NULL) return; if (strstr(str_data, "-b") != NULL) wtype = CDW_BMP; else if (strstr(str_data, "-m") != NULL) wtype = -1; /* CD METAFILE */ if (wtype != -1) { sscanf(str_data,"%dx%d %lg",&w, &h, &res); if (w == 0 || h == 0) return; } if (wtype == CDW_EMF) { HDC ScreenDC = GetDC(NULL); if (res) { canvas->xres = res; canvas->yres = res; } else { /* LOGPIXELS can not be used for EMF */ canvas->xres = (double)GetDeviceCaps(ScreenDC, HORZRES) / (double)GetDeviceCaps(ScreenDC, HORZSIZE); canvas->yres = (double)GetDeviceCaps(ScreenDC, VERTRES) / (double)GetDeviceCaps(ScreenDC, VERTSIZE); } Rect frameRect(0, 0, (int)(100 * w / canvas->xres), (int)(100 * h / canvas->yres)); metafile = new Metafile(ScreenDC, frameRect, MetafileFrameUnitGdi, EmfTypeEmfPlusDual, NULL); ReleaseDC(NULL, ScreenDC); if (!metafile) return; graphics = new Graphics(metafile); } else if (wtype == CDW_BMP) { if (res) { canvas->xres = res; canvas->yres = res; } else { HDC ScreenDC = GetDC(NULL); canvas->xres = (double)GetDeviceCaps(ScreenDC, HORZRES) / (double)GetDeviceCaps(ScreenDC, HORZSIZE); canvas->yres = (double)GetDeviceCaps(ScreenDC, VERTRES) / (double)GetDeviceCaps(ScreenDC, VERTSIZE); ReleaseDC(NULL, ScreenDC); } bitmap = new Bitmap(w, h, PixelFormat24bppRGB); if (!bitmap) return; bitmap->SetResolution((REAL)(canvas->xres*25.4), (REAL)(canvas->xres*25.4)); graphics = new Graphics(bitmap); } if (wtype == -1) { char tmpPath[10240]; if (!cdStrTmpFileName(tmpPath)) return; strcat(tmpPath, " "); strcat(tmpPath, str_data); cdcreatecanvasMF(canvas, tmpPath); } else { cdCtxCanvas* ctxcanvas = cdwpCreateCanvas(canvas, graphics, wtype); canvas->w = w; canvas->h = h; canvas->bpp = 24; if (wtype == CDW_BMP) ctxcanvas->bitmap = bitmap; else ctxcanvas->metafile = metafile; } }
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; } } }