void wdCanvasPutImageRectMap(cdCanvas* canvas, int iw, int ih, const unsigned char *index, const long *colors, double x, double y, double w, double h, int xmin, int xmax, int ymin, int ymax) { int xr, yr, wr, hr; _wWorld2Canvas(canvas, x, y, xr, yr); _wWorld2CanvasSize(canvas, w, h, wr, hr); cdCanvasPutImageRectMap(canvas, iw, ih, index, colors, xr, yr, wr, hr, xmin, xmax, ymin, ymax); }
void cdIupDrawImage(cdCanvas *canvas, Ihandle *image, int x, int y, int make_inactive, long bgcolor) { int size, plane_size, depth; int width = IupGetInt(image, "WIDTH"); int height = IupGetInt(image, "HEIGHT"); int bpp = IupGetInt(image, "BPP"); unsigned char* image_buffer; depth = 1; if (bpp==24) depth = 3; else if (bpp==32) depth = 4; if (depth!=1 && make_inactive) image_buffer = (unsigned char*)iupAttribGet(image, "_IUPIMAGE_CDIMAGE_INACTIVE"); else image_buffer = (unsigned char*)iupAttribGet(image, "_IUPIMAGE_CDIMAGE"); if (!image_buffer) { image_buffer = cdIupBuildImageBuffer(image, width, height, depth, make_inactive, bgcolor); if (depth!=1 && make_inactive) iupAttribSet(image, "_IUPIMAGE_CDIMAGE_INACTIVE", (char*)image_buffer); else iupAttribSet(image, "_IUPIMAGE_CDIMAGE", (char*)image_buffer); } if (!image_buffer) return; plane_size = width*height; size = plane_size*depth; if (depth==1) { long palette[256]; cdIupInitPalette(image, palette, bgcolor, make_inactive); cdCanvasPutImageRectMap(canvas, width, height, image_buffer, palette, x, y, width, height, 0, 0, 0, 0); } else if (depth==3) { cdCanvasPutImageRectRGB(canvas, width, height, image_buffer + 0*plane_size, image_buffer + 1*plane_size, image_buffer + 2*plane_size, x, y, width, height, 0, 0, 0, 0); } else /* depth==4 */ { cdCanvasPutImageRectRGBA(canvas, width, height, image_buffer + 0*plane_size, image_buffer + 1*plane_size, image_buffer + 2*plane_size, image_buffer + 3*plane_size, x, y, width, height, 0, 0, 0, 0); } }
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; }
/* %F cdPlay para Clipboard. Interpreta os dados do clipboard, seja metafile ou bitmap. */ static int cdplay(cdCanvas* canvas, int xmin, int xmax, int ymin, int ymax, void *data) { char filename[10240]; HANDLE hFile; DWORD dwSize, nBytesWrite; int err; unsigned char* buffer; (void)data; if (IsClipboardFormatAvailable(CF_TEXT)) { HANDLE Handle; if (!cdStrTmpFileName(filename)) return CD_ERROR; OpenClipboard(NULL); Handle = GetClipboardData(CF_TEXT); if (Handle == NULL) { CloseClipboard(); return CD_ERROR; } buffer = (unsigned char*)GlobalLock(Handle); dwSize = (DWORD)GlobalSize(Handle); hFile = CreateFile(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL); WriteFile(hFile, buffer, dwSize, &nBytesWrite, NULL); CloseHandle(hFile); GlobalUnlock(Handle); CloseClipboard(); err = cdCanvasPlay(canvas, CD_METAFILE, xmin, xmax, ymin, ymax, filename); DeleteFile(filename); if (err == CD_OK) return err; } if (IsClipboardFormatAvailable(CF_ENHMETAFILE)) { HENHMETAFILE Handle; if (!cdStrTmpFileName(filename)) return CD_ERROR; OpenClipboard(NULL); Handle = (HENHMETAFILE)GetClipboardData(CF_ENHMETAFILE); if (Handle == NULL) { CloseClipboard(); return CD_ERROR; } dwSize = GetEnhMetaFileBits(Handle, 0, NULL); buffer = (unsigned char*)malloc(dwSize); GetEnhMetaFileBits(Handle, dwSize, buffer); hFile = CreateFile(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL); WriteFile(hFile, buffer, dwSize, &nBytesWrite, NULL); CloseHandle(hFile); free(buffer); CloseClipboard(); err = cdCanvasPlay(canvas, CD_EMF, xmin, xmax, ymin, ymax, filename); DeleteFile(filename); return err; } if (IsClipboardFormatAvailable(CF_METAFILEPICT)) { HANDLE Handle; METAFILEPICT* lpMFP; if (!cdStrTmpFileName(filename)) return CD_ERROR; OpenClipboard(NULL); Handle = GetClipboardData(CF_METAFILEPICT); if (Handle == NULL) { CloseClipboard(); return CD_ERROR; } lpMFP = (METAFILEPICT*) GlobalLock(Handle); dwSize = GetMetaFileBitsEx(lpMFP->hMF, 0, NULL); buffer = (unsigned char*)malloc(dwSize); GetMetaFileBitsEx(lpMFP->hMF, dwSize, buffer); hFile = CreateFile(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL); wmfWritePlacebleFile(hFile, buffer, dwSize, lpMFP->mm, lpMFP->xExt, lpMFP->yExt); CloseHandle(hFile); GlobalUnlock(Handle); free(buffer); CloseClipboard(); err = cdCanvasPlay(canvas, CD_WMF, xmin, xmax, ymin, ymax, filename); DeleteFile(filename); return err; } if (IsClipboardFormatAvailable(CF_DIB)) { HANDLE Handle; int size; cdwDIB dib; OpenClipboard(NULL); Handle = GetClipboardData(CF_DIB); if (Handle == NULL) { CloseClipboard(); return CD_ERROR; } cdwDIBReference(&dib, (BYTE*) GlobalLock(Handle), NULL); if (dib.type == -1) { GlobalUnlock(Handle); CloseClipboard(); return CD_ERROR; } if (cdsizecb) { int err; err = cdsizecb(canvas, dib.w, dib.h, dib.w, dib.h); if (err) { GlobalUnlock(Handle); CloseClipboard(); return CD_ERROR; } } size = dib.w*dib.h; if (xmax == 0) xmax = dib.w + xmin - 1; if (ymax == 0) ymax = dib.h + ymin - 1; if (dib.type == 0) { unsigned char *r, *g, *b; r = (unsigned char*)malloc(size); g = (unsigned char*)malloc(size); b = (unsigned char*)malloc(size); cdwDIBDecodeRGB(&dib, r, g, b); cdCanvasPutImageRectRGB(canvas, dib.w, dib.h, r, g, b, xmin, ymin, xmax - xmin + 1, ymax - ymin + 1, 0, 0, 0, 0); free(r); free(g); free(b); } else { unsigned char *index; long *colors; index = (unsigned char*)malloc(size); colors = (long*)malloc(256*sizeof(long)); cdwDIBDecodeMap(&dib, index, colors); cdCanvasPutImageRectMap(canvas, dib.w, dib.h, index, colors, xmin, ymin, xmax - xmin + 1, ymax - ymin + 1, 0, 0, 0, 0); free(index); free(colors); } GlobalUnlock(Handle); CloseClipboard(); return CD_ERROR; } if (IsClipboardFormatAvailable(CF_BITMAP)) { HBITMAP Handle; int size, type; cdwDIB dib; HDC ScreenDC; SIZE sz; OpenClipboard(NULL); Handle = GetClipboardData(CF_BITMAP); if (Handle == NULL) { CloseClipboard(); return CD_ERROR; } GetBitmapDimensionEx(Handle, &sz); ScreenDC = GetDC(NULL); if (GetDeviceCaps(ScreenDC, BITSPIXEL) > 8) type = 0; else type = 1; dib.w = sz.cx; dib.h = sz.cy; dib.type = type; if (cdsizecb) { int err; err = cdsizecb(canvas, dib.w, dib.h, dib.w, dib.h); if (err) { ReleaseDC(NULL, ScreenDC); CloseClipboard(); return CD_ERROR; } } cdwCreateDIB(&dib); GetDIBits(ScreenDC, Handle, 0, sz.cy, dib.bits, dib.bmi, DIB_RGB_COLORS); ReleaseDC(NULL, ScreenDC); size = dib.w*dib.h; if (dib.type == 0) { unsigned char *r, *g, *b; r = (unsigned char*)malloc(size); g = (unsigned char*)malloc(size); b = (unsigned char*)malloc(size); cdwDIBDecodeRGB(&dib, r, g, b); cdCanvasPutImageRectRGB(canvas, dib.w, dib.h, r, g, b, 0, 0, dib.w, dib.h, 0, 0, 0, 0); free(r); free(g); free(b); } else { unsigned char *index; long *colors; index = (unsigned char*)malloc(size); colors = (long*)malloc(256*sizeof(long)); cdwDIBDecodeMap(&dib, index, colors); cdCanvasPutImageRectMap(canvas, dib.w, dib.h, index, colors, 0, 0, dib.w, dib.h, 0, 0, 0, 0); free(index); free(colors); } cdwKillDIB(&dib); CloseClipboard(); return CD_ERROR; } return CD_ERROR; }
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; }
void cdIupDrawImage(cdCanvas *canvas, Ihandle *image, int x, int y, int w, int h, int make_inactive, long bgcolor) { int plane_size, depth; int width = IupGetInt(image, "WIDTH"); int height = IupGetInt(image, "HEIGHT"); int bpp = IupGetInt(image, "BPP"); unsigned char* image_buffer; depth = 1; if (bpp==24) depth = 3; else if (bpp==32) depth = 4; if (w == 0) w = width; if (h == 0) h = height; /* The buffer will be destroyed in IupImage unmap */ if (depth!=1 && make_inactive) image_buffer = (unsigned char*)iupAttribGet(image, "_IUPIMAGE_BUFFER_INACTIVE"); else image_buffer = (unsigned char*)iupAttribGet(image, "_IUPIMAGE_BUFFER"); if (!image_buffer) { image_buffer = iUtilBuildImageBuffer(image, width, height, depth, make_inactive, bgcolor); if (depth!=1 && make_inactive) iupAttribSet(image, "_IUPIMAGE_BUFFER_INACTIVE", (char*)image_buffer); else iupAttribSet(image, "_IUPIMAGE_BUFFER", (char*)image_buffer); } if (!image_buffer) return; plane_size = width*height; if (depth==1) { long palette[256]; iUtilInitPalette(image, palette, bgcolor, make_inactive); cdCanvasPutImageRectMap(canvas, width, height, image_buffer, palette, x, y, w, h, 0, 0, 0, 0); } else if (depth==3) { cdCanvasPutImageRectRGB(canvas, width, height, image_buffer + 0*plane_size, image_buffer + 1*plane_size, image_buffer + 2*plane_size, x, y, w, h, 0, 0, 0, 0); } else /* depth==4 */ { cdCanvasPutImageRectRGBA(canvas, width, height, image_buffer + 0*plane_size, image_buffer + 1*plane_size, image_buffer + 2*plane_size, image_buffer + 3*plane_size, x, y, w, h, 0, 0, 0, 0); } }