static void _wdHdcpyDoit(cdCanvas *canvas, cdCanvas *canvas_copy, void (*draw_func)(cdCanvas *canvas_copy)) { cdCanvas *old_active; double left, right, bottom, top; /* canvas visualization window */ int canvas_hsize, canvas_vsize; /* canvas sizes in pixels */ int hdcpy_hsize, hdcpy_vsize; /* paper sizes in points */ double canvas_vpr; /* canvas viewport distortion ratio */ double hdcpy_vpr; /* paper viewport distortion ratio */ int xc, yc; /* paper center in pixels */ int xmin, xmax, ymin, ymax; /* paper viewport */ /* Activate canvas visualization surface. */ if (cdCanvasActivate(canvas) != CD_OK) return; /* Get current canvas window parameters and sizes. */ wdCanvasGetWindow(canvas, &left, &right, &bottom, &top); cdCanvasGetSize(canvas, &canvas_hsize, &canvas_vsize, 0L, 0L); /* Activate hardcopy visualization surface. */ if (cdCanvasActivate(canvas_copy) != CD_OK) return; /* Set window parameters on hardcopy surface. */ wdCanvasWindow(canvas_copy, left, right, bottom, top); /* Adjust paper viewport, centralized, matching canvas viewport. */ canvas_vpr = (double)canvas_vsize / (double)canvas_hsize; cdCanvasGetSize(canvas_copy, &hdcpy_hsize, &hdcpy_vsize, 0L, 0L); hdcpy_vpr = (double)hdcpy_vsize / (double)hdcpy_hsize; xc = (int)((double)hdcpy_hsize/2.0); yc = (int)((double)hdcpy_vsize/2.0); if (canvas_vpr < hdcpy_vpr) { xmin = 0; xmax = hdcpy_hsize; ymin = yc - (int)((double)hdcpy_hsize*(double)canvas_vpr/2.0); ymax = yc + (int)((double)hdcpy_hsize*(double)canvas_vpr/2.0); } else { xmin = xc - (int)((double)hdcpy_vsize/(double)canvas_vpr/2.0); xmax = xc + (int)((double)hdcpy_vsize/(double)canvas_vpr/2.0); ymin = 0; ymax = hdcpy_vsize; } cdCanvasClipArea(canvas_copy, xmin, xmax, ymin, ymax); cdCanvasClip(canvas_copy, CD_CLIPAREA); wdCanvasViewport(canvas_copy, xmin, xmax, ymin, ymax); /* for backward compatibility */ old_active = cdActiveCanvas(); cdActivate(canvas_copy); /* Draw on hardcopy surface. */ draw_func(canvas_copy); if (old_active) cdActivate(old_active); }
static int iDialResize_CB(Ihandle* ih) { /* update size */ cdCanvasActivate(ih->data->cd_canvas); cdCanvasGetSize(ih->data->cd_canvas, &ih->data->w, &ih->data->h, NULL, NULL); /* update number of divisions */ switch(ih->data->orientation) { case IDIAL_VERTICAL: ih->data->num_div = (int)((ih->data->h-2 * IDIAL_SPACE-2) * ih->data->density); break; case IDIAL_HORIZONTAL: ih->data->num_div = (int)((ih->data->w-2 * IDIAL_SPACE-2) * ih->data->density); break; case IDIAL_CIRCULAR: ih->data->num_div = (int)((dialmin(ih->data->w, ih->data->h)-2 * IDIAL_SPACE-2) * ih->data->density); break; } if (ih->data->num_div < 3) ih->data->num_div = 3; /* update render */ cdCanvasBackground(ih->data->cd_canvas, ih->data->bgcolor); cdCanvasClear(ih->data->cd_canvas); ih->data->Draw(ih); return IUP_DEFAULT; }
static int iColorBrowserDlgColorCnvButton_CB(Ihandle* ih, int b, int press, int x, int y) { IcolorDlgData* colordlg_data = (IcolorDlgData*)iupAttribGetInherit(ih, "_IUP_GC_DATA"); int width; (void)y; if (b != IUP_BUTTON1 || !press || !colordlg_data->cd_canvas_color) return IUP_DEFAULT; cdCanvasGetSize(colordlg_data->cd_canvas_color, &width, NULL, NULL, NULL); if (x < width/2) { /* reset color to previous */ colordlg_data->red = cdRed(colordlg_data->previous_color); colordlg_data->green = cdGreen(colordlg_data->previous_color); colordlg_data->blue = cdBlue(colordlg_data->previous_color); colordlg_data->alpha = cdAlpha(colordlg_data->previous_color); IupSetInt(colordlg_data->alpha_txt, "VALUE", (int)colordlg_data->alpha); IupSetInt(colordlg_data->alpha_val, "VALUE", (int)colordlg_data->alpha); iColorBrowserDlgRGB_TXT_Update(colordlg_data); iColorBrowserDlgRGBChanged(colordlg_data); } return IUP_DEFAULT; }
static int wheel_cb(Ihandle *ih,float delta,int x,int y,char* status) { int canvas_w, canvas_h; cdCanvas *canvas = (cdCanvas*)IupGetAttribute(ih, "_CD_CANVAS"); (void)x; (void)y; (void)status; if (scale+delta==0) /* skip 0 */ { if (scale > 0) scale = -1; else scale = 1; } else scale += (int)delta; cdCanvasActivate(canvas); cdCanvasGetSize(canvas, &canvas_w, &canvas_h, NULL, NULL); update_scrollbar(ih, canvas_w, canvas_h); update_viewport(ih, canvas, IupGetFloat(ih, "POSX"), IupGetFloat(ih, "POSY")); IupRedraw(ih, 0); return IUP_DEFAULT; }
static int iColorbarResize_CB(Ihandle* ih) { if (!ih->data->cddbuffer) { /* update canvas size */ cdCanvasActivate(ih->data->cdcanvas); /* this can fail if canvas size is zero */ ih->data->cddbuffer = cdCreateCanvas(CD_DBUFFER, ih->data->cdcanvas); } if (!ih->data->cddbuffer) return IUP_DEFAULT; /* update size */ cdCanvasActivate(ih->data->cddbuffer); cdCanvasGetSize(ih->data->cddbuffer, &ih->data->w, &ih->data->h, NULL, NULL); /* update render */ cdCanvasBackground(ih->data->cddbuffer, ih->data->bgcolor); cdCanvasClear(ih->data->cddbuffer); iColorbarRenderPreview(ih); iColorbarRenderCells(ih); return IUP_DEFAULT; }
static int iMatrixResize_CB(Ihandle* ih) { if (!ih->data->cddbuffer) { /* update canvas size */ cdCanvasActivate(ih->data->cdcanvas); /* this can fail if canvas size is zero */ ih->data->cddbuffer = cdCreateCanvas(CD_DBUFFER, ih->data->cdcanvas); } if (!ih->data->cddbuffer) return IUP_DEFAULT; /* update size */ cdCanvasActivate(ih->data->cddbuffer); cdCanvasGetSize(ih->data->cddbuffer, &ih->data->w, &ih->data->h, NULL, NULL); iupMatrixEditForceHidden(ih); ih->data->need_calcsize = 1; iupMatrixDraw(ih, 0); return IUP_DEFAULT; }
static double get_size_mode(cdCanvas* canvas, double size, const char* mode, double current_size) { if (strcmp(mode, "SCALED")==0) { /* scale factor to be applied by the interpreter to a device-dependent "nominal" measure */ return size*current_size; } else if (strcmp(mode, "FRACTIONAL")==0) { /* fraction of the horizontal dimension of the default device viewport */ int width; cdCanvasGetSize(canvas, &width, NULL, NULL, NULL); return size*width; } else if (strcmp(mode, "MM")==0) { /* millimetres */ cdfCanvasMM2Pixel(canvas, size, 0, &size, NULL); return size; } else /* "ABSOLUTE" */ { /* pixels */ return size; } }
void DrawCanvasDriverSizeParam(cdContext* ctx, char* param) { char StrData[100]; int w, h; cdCanvasGetSize(curCanvas, &w, &h, 0, 0); sprintf(StrData, "%dx%d %s", w, h, param); DrawCanvasDriver(ctx, StrData); }
void PlayCanvasDriver(cdContext* ctx, char* StrData) { int w, h; cdCanvasActivate(curCanvas); cdCanvasBackground(curCanvas, CD_WHITE); cdCanvasClear(curCanvas); cdCanvasGetSize(curCanvas, &w, &h, 0, 0); cdCanvasPlay(curCanvas, ctx, 100, w-100, 100, h-100, StrData); // cdCanvasPlay(curCanvas, ctx, 0, 0, 0, 0, StrData); }
void DrawCanvasDriverSize(cdContext* ctx, char* name, int pixels) { char StrData[100]; int w, h; double w_mm, h_mm; cdCanvasGetSize(curCanvas, &w, &h, &w_mm, &h_mm); if (pixels == 1) sprintf(StrData, "%s %dx%d", name, w, h); else if (pixels == 2) sprintf(StrData, "%s -w%g -h%g -s%g", name, w_mm, h_mm, ((double)w/w_mm)*25.4); else sprintf(StrData, "%s %gx%g %g", name, w_mm, h_mm, (double)w/w_mm); DrawCanvasDriver(ctx, StrData); }
static int iTreeInitTree(Ihandle* ih) { int w, h; cdCanvasBackground(ih->data->cddbuffer, ITREE_TREE_BGCOLOR); cdCanvasGetSize(ih->data->cddbuffer, &w, &h, NULL, NULL); ih->data->XmaxC = w - 1; ih->data->YmaxC = h - 1; IupSetAttribute(ih, "BGCOLOR", ITREE_TREE_BGCOLORSTRING); IupSetAttribute(ih, "DX", "1.0"); IupSetAttribute(ih, "DY", "1.0"); return 0; }
int item_print_action_cb(Ihandle* item_print) { Ihandle* canvas = IupGetDialogChild(item_print, "CANVAS"); unsigned int ri, gi, bi; imImage* image; char* title = IupGetAttribute(IupGetDialog(item_print), "TITLE"); Ihandle* config = (Ihandle*)IupGetAttribute(canvas, "CONFIG"); const char* background = IupConfigGetVariableStrDef(config, "MainWindow", "Background", "255 255 255"); cdCanvas* cd_canvas = cdCreateCanvasf(CD_PRINTER, "%s -d", title); if (!cd_canvas) return IUP_DEFAULT; /* draw the background */ sscanf(background, "%u %u %u", &ri, &gi, &bi); cdCanvasBackground(cd_canvas, cdEncodeColor((unsigned char)ri, (unsigned char)gi, (unsigned char)bi)); cdCanvasClear(cd_canvas); /* draw the image at the center of the canvas */ image = (imImage*)IupGetAttribute(canvas, "IMAGE"); if (image) { int x, y, canvas_width, canvas_height, view_width, view_height; double canvas_width_mm, canvas_height_mm; Ihandle* config = (Ihandle*)IupGetAttribute(canvas, "CONFIG"); int margin_width = IupConfigGetVariableIntDef(config, "Print", "MarginWidth", 20); int margin_height = IupConfigGetVariableIntDef(config, "Print", "MarginHeight", 20); cdCanvasGetSize(cd_canvas, &canvas_width, &canvas_height, &canvas_width_mm, &canvas_height_mm); /* convert to pixels */ margin_width = (int)((margin_width * canvas_width) / canvas_width_mm); margin_height = (int)((margin_height * canvas_height) / canvas_height_mm); view_fit_rect(canvas_width - 2 * margin_width, canvas_height - 2 * margin_height, image->width, image->height, &view_width, &view_height); x = (canvas_width - view_width) / 2; y = (canvas_height - view_height) / 2; imcdCanvasPutImage(cd_canvas, image, x, y, view_width, view_height, 0, 0, 0, 0); } cdKillCanvas(cd_canvas); return IUP_DEFAULT; }
static void iColorBrowserDlgColorCnvRepaint(IcolorDlgData* colordlg_data) { int x, y, w, h, width, height, box_size = 10; if (!colordlg_data->cd_canvas_color) return; cdCanvasActivate(colordlg_data->cd_canvas_color); cdCanvasGetSize(colordlg_data->cd_canvas_color, &width, &height, NULL, NULL); cdCanvasBackground(colordlg_data->cd_canvas_color, CD_WHITE); cdCanvasClear(colordlg_data->cd_canvas_color); w = (width+box_size-1)/box_size; h = (height+box_size-1)/box_size; cdCanvasForeground(colordlg_data->cd_canvas_color, CD_GRAY); for (y = 0; y < h; y++) { for (x = 0; x < w; x++) { if (((x%2) && (y%2)) || (((x+1)%2) && ((y+1)%2))) { int xmin, xmax, ymin, ymax; xmin = x*box_size; xmax = xmin+box_size; ymin = y*box_size; ymax = ymin+box_size; cdCanvasBox(colordlg_data->cd_canvas_color, xmin, xmax, ymin, ymax); } } } cdCanvasForeground(colordlg_data->cd_canvas_color, colordlg_data->previous_color); cdCanvasBox(colordlg_data->cd_canvas_color, 0, width/2, 0, height); cdCanvasForeground(colordlg_data->cd_canvas_color, colordlg_data->color); cdCanvasBox(colordlg_data->cd_canvas_color, width/2+1, width, 0, height); cdCanvasFlush(colordlg_data->cd_canvas_color); }
static void iColorBrowserUpdateSize(Ihandle* ih) { int T, D; /* update canvas size */ cdCanvasActivate(ih->data->cddbuffer); cdCanvasGetSize(ih->data->cddbuffer, &ih->data->w, &ih->data->h, NULL, NULL); ih->data->R = min(ih->data->w, ih->data->h)/2; ih->data->xc = ih->data->w/2; ih->data->yc = ih->data->h/2; T = ih->data->R-ICB_SPACE-ICB_HUEWIDTH-ICB_SPACE; ih->data->Ix = ih->data->xc - T/2; /* cos(60)=0.5 */ D = (int)(2*T*0.866); /* sin(60)=0.866 */ ih->data->Iy1 = ih->data->yc - D/2; ih->data->Iy2 = ih->data->Iy1 + D; ih->data->SxMax = ih->data->xc + T; }
static int redraw_cb(Ihandle *ih) { int width, height; cdCanvas *cdcanvas = (cdCanvas*)IupGetAttribute(ih, "_APP_CDCANVAS"); cdCanvasActivate(cdcanvas); cdCanvasBackground(cdcanvas, CD_WHITE); cdCanvasClear(cdcanvas); cdCanvasForeground(cdcanvas, CD_RED); cdCanvasGetSize(cdcanvas, &width, &height, NULL, NULL); cdCanvasLine(cdcanvas, 0, 0, width-1, height-1); cdCanvasLine(cdcanvas, 0, height-1, width-1, 0); cdCanvasFlush(cdcanvas); return IUP_DEFAULT; }
/** * IUP canvas callback for resize */ static int cells_resize(Ihandle *h) { /* Getting cell struct pointer saved in iup handle */ TCells* obj = (TCells*) iupGetEnv(h, "_IUPCELLS_DATA"); if (!obj) return IUP_DEFAULT; if (!obj->cddbuffer) cells_createcanvas(obj, h); if (!obj->cddbuffer) return IUP_DEFAULT; cdCanvasActivate(obj->cddbuffer); cdCanvasGetSize(obj->cddbuffer,&obj->width, &obj->height, NULL, NULL); /* As the size has changed, we need to recalculate scrollbars * positions and size */ adjust_scrolls(obj); return IUP_DEFAULT; }
static int iCellsResize_CB(Ihandle* ih, int w, int h) { /* recalculate scrollbars limits */ iCellsAdjustScroll(ih, w, h); /* This could have changed the scrollbar visibility, so the canvas client size can change, so updated it twice. */ IupGetIntInt(ih, "DRAWSIZE", &w, &h); IupSetInt(ih, "DX", w); IupSetInt(ih, "DY", h); /* update canvas size */ cdCanvasActivate(ih->data->cd_canvas); cdCanvasGetSize(ih->data->cd_canvas, &ih->data->w, &ih->data->h, NULL, NULL); /* update render */ iCellsRenderCells(ih); return IUP_DEFAULT; }
static void cdcgm_BeginPicture(const char* name, cdCGM* cd_cgm) { int width, height; if (cd_cgm->first_pic) cd_cgm->first_pic = 0; else cdCanvasFlush(cd_cgm->canvas); /* do it only if it has more than one picture */ /* default clipping is ON */ cdCanvasGetSize(cd_cgm->canvas, &width, &height, NULL, NULL); cdCanvasClipArea(cd_cgm->canvas, 0, width-1, 0, height-1); cdCanvasClip(cd_cgm->canvas, CD_CLIPAREA); if (cdcgmbegpictcb) { int ret = cdcgmbegpictcb(cd_cgm->canvas, name); if (ret == CD_ABORT) cd_cgm->abort = 1; } }
int SimpleDrawGL(void) { char StrData[100]; int w, h; double w_mm, h_mm; if (use_opengl) return 0; cdCanvasGetSize(curCanvas, &w, &h, &w_mm, &h_mm); sprintf(StrData, "%dx%d %g", w, h, ((double)w/w_mm)); if (dbCanvas) cdKillCanvas(dbCanvas); dbCanvas = cdCreateCanvas(CD_GL, StrData); curCanvas = dbCanvas; use_opengl = 1; SimpleDraw(curCanvas); return 0; }
static int iGaugeResize_CB(Ihandle* ih) { if (!ih->data->cddbuffer) { /* update canvas size */ cdCanvasActivate(ih->data->cdcanvas); /* this can fail if canvas size is zero */ ih->data->cddbuffer = cdCreateCanvas(CD_DBUFFER, ih->data->cdcanvas); } if (!ih->data->cddbuffer) return IUP_DEFAULT; /* update size */ cdCanvasActivate(ih->data->cddbuffer); cdCanvasGetSize(ih->data->cddbuffer,&ih->data->w,&ih->data->h,NULL,NULL); /* update render */ iGaugeDrawGauge(ih); return IUP_DEFAULT; }
void SimpleDrawTextAlign(cdCanvas* canvas) { int w, h, i, xoff, yoff, use_vector; int text_aligment[] = { CD_NORTH, CD_SOUTH, CD_EAST, CD_WEST, CD_NORTH_EAST, CD_NORTH_WEST, CD_SOUTH_EAST, CD_SOUTH_WEST, CD_CENTER, CD_BASE_CENTER, CD_BASE_RIGHT, CD_BASE_LEFT }; #if 1 char* text_aligment_str[] = { "North (Ãyj)\nSecond Line (Ãyj)\nThird Line", "South (Ãyj)\nSecond Line (Ãyj)\nThird Line", "East (Ãyj)\nSecond Line (Ãyj)\nThird Line", "West (Ãyj)\nSecond Line (Ãyj)\nThird Line", "North East (Ãyj)\nSecond Line (Ãyj)\nThird Line", "North West (Ãyj)\nSecond Line (Ãyj)\nThird Line", "South East (Ãyj)\nSecond Line (Ãyj)\nThird Line", "South West (Ãyj)\nSecond Line (Ãyj)\nThird Line", "Center (Ãyj)\nSecond Line (Ãyj)\nThird Line", "Base Center (Ãyj)\nSecond Line (Ãyj)\nThird Line", "Base Right (Ãyj)\nSecond Line (Ãyj)\nThird Line", "Base Left (Ãyj)\nSecond Line (Ãyj)\nThird Line" }; #else char* text_aligment_str[] = { "North (Ãyj)", "South (Ãyj)", "East (Ãyj)", "West (Ãyj)", "North East (Ãyj)", "North West (Ãyj)", "South East (Ãyj)", "South West (Ãyj)", "Center (Ãyj)", "Base Center (Ãyj)", "Base Right (Ãyj)", "Base Left (Ãyj)" }; #endif cdCanvasGetSize(canvas, &w, &h, 0, 0); cdCanvasBackground(canvas, CD_WHITE); cdCanvasClear(canvas); use_vector = 0; #if 0 if (use_vector) cdCanvasVectorTextDirection(canvas, 0, 0, 1, 1); else cdCanvasTextOrientation(canvas, 45); #endif xoff = w/4; yoff = h/7; if (use_vector) cdCanvasVectorCharSize(canvas, 30); else { //cdCanvasFont(canvas, "Times", CD_PLAIN, 14); cdCanvasFont(canvas, "Helvetica", CD_PLAIN, 24); } for (i = 0; i < 12; i++) { cdCanvasTextAlignment(canvas, text_aligment[i]); if (i < 6) { if (use_vector) DrawVectorTextBox(canvas, xoff, yoff*(i+1), text_aligment_str[i]); else DrawTextBox(canvas, xoff, yoff*(i+1), text_aligment_str[i]); } else { if (use_vector) DrawVectorTextBox(canvas, 3*xoff, yoff*(i-5), text_aligment_str[i]); else DrawTextBox(canvas, 3*xoff, yoff*(i-5), text_aligment_str[i]); } } }
void SimpleDrawAll(cdCanvas* canvas) { int w, h; cdCanvasGetSize(canvas, &w, &h, NULL, NULL); /* Clear the background to be white */ cdCanvasBackground(canvas, CD_WHITE); // cdBackground(CD_GREEN); cdCanvasClear(canvas); /* Draw a reactangle and a polyline at the bottom-left area, using a thick line with transparency. Observe that transparency is only supported in a few drivers, and line join is not supported in the IMAGERGB driver. */ cdCanvasLineWidth(canvas, 3); cdCanvasLineStyle(canvas, CD_CONTINUOUS); cdCanvasForeground(canvas, cdEncodeAlpha(CD_DARK_MAGENTA, 128)); cdCanvasRect(canvas, 100, 200, 100, 200); cdCanvasBegin(canvas, CD_OPEN_LINES); cdCanvasVertex(canvas, 300, 250); cdCanvasVertex(canvas, 320, 270); cdCanvasVertex(canvas, 350, 260); cdCanvasVertex(canvas, 340, 200); cdCanvasVertex(canvas, 310, 210); cdCanvasEnd(canvas); /* Draw the red diagonal line with a custom line style. Observe that line styles are not supported in the IMAGERGB driver. */ cdCanvasForeground(canvas, CD_RED); cdCanvasLineWidth(canvas, 3); { int dashes[] = {20, 15, 5, 5}; cdCanvasLineStyleDashes(canvas, dashes, 4); } cdCanvasLineStyle(canvas, CD_CUSTOM); cdCanvasLine(canvas, 0, 0, w-1, h-1); /* Draw the blue diagonal line with a pre-defined line style. Observe that the pre-defined line style is dependent on the driver. */ cdCanvasForeground(canvas, CD_BLUE); cdCanvasLineWidth(canvas, 10); cdCanvasLineStyle(canvas, CD_DOTTED); cdCanvasLine(canvas, 0, h-1, w-1, 0); switch(clipping) { case CD_CLIPOFF: cdCanvasClip(canvas, CD_CLIPOFF); break; case CD_CLIPAREA: /* Defines the clipping area equals the canvas area minus a 100 pixels margin. */ cdCanvasClipArea(canvas, 100, w - 100, 100, h - 100); cdCanvasClip(canvas, CD_CLIPAREA); break; case CD_CLIPPOLYGON: cdCanvasBegin(canvas, CD_CLIP); cdCanvasVertex(canvas, 100, 100); cdCanvasVertex(canvas, w - 100, 100); cdCanvasVertex(canvas, w / 2, h - 100); cdCanvasEnd(canvas); cdCanvasClip(canvas, CD_CLIPPOLYGON); break; case CD_CLIPREGION: cdCanvasTextAlignment(canvas, CD_CENTER); cdCanvasFont(canvas, "Times", CD_BOLD, 50); cdCanvasBegin(canvas, CD_REGION); cdCanvasRegionCombineMode(canvas, CD_UNION); cdCanvasBox(canvas, 100, 200, 100, 200); cdCanvasSector(canvas, w/2-50, h/2+50, 150, 150, 0, 360); cdCanvasSector(canvas, w/2-50, h/2-50, 150, 150, 0, 360); cdCanvasSector(canvas, w/2+50, h/2+50, 150, 150, 0, 360); cdCanvasSector(canvas, w/2+50, h/2-50, 150, 150, 0, 360); cdCanvasRegionCombineMode(canvas, CD_DIFFERENCE); cdCanvasText(canvas, w/2, h/2, "TEXT"); cdCanvasEnd(canvas); // cdCanvasOffsetRegion(canvas, -50, 50); cdCanvasClip(canvas, CD_CLIPREGION); cdCanvasForeground(canvas, CD_DARK_RED); cdCanvasBox(canvas, 0,w,0,h); break; } switch(write_mode) { case CD_REPLACE: cdCanvasWriteMode(canvas, CD_REPLACE); break; case CD_XOR: cdCanvasWriteMode(canvas, CD_XOR); break; case CD_NOT_XOR: cdCanvasWriteMode(canvas, CD_NOT_XOR); break; } if (use_transform) { cdCanvasTransform(canvas, NULL); cdCanvasTransformTranslate(canvas, w/2, h/2); cdCanvasTransformRotate(canvas, 30); cdCanvasTransformScale(canvas, 0.5, 0.5); cdCanvasTransformTranslate(canvas, -w/2, -h/2); } // cdSetfAttribute("ROTATE", "15 %d %d", w/2, h/2); /* Reset line style and width */ cdCanvasLineStyle(canvas, CD_CONTINUOUS); cdCanvasLineWidth(canvas, 1); // cdBackOpacity(CD_TRANSPARENT); /* Draw an arc at bottom-left, and a sector at bottom-right. Notice that counter-clockwise orientation of both. */ cdCanvasInteriorStyle(canvas, CD_SOLID); cdCanvasForeground(canvas, CD_MAGENTA); cdCanvasSector(canvas, w-100, 100, 100, 100, 50, 180); cdCanvasForeground(canvas, CD_RED); cdCanvasArc(canvas, 100, 100, 100, 100, 50, 180); /* Draw a solid filled rectangle at center. */ cdCanvasForeground(canvas, CD_YELLOW); cdCanvasBox(canvas, w/2 - 100, w/2 + 100, h/2 - 100, h/2 + 100); /* Prepare font for text. */ cdCanvasTextAlignment(canvas, CD_CENTER); cdCanvasTextOrientation(canvas, 70); cdCanvasFont(canvas, "Times", CD_BOLD, 24); /* Draw text at center, with orientation, and draw its bounding box. Notice that in some drivers the bounding box is not precise. */ { int rect[8]; cdCanvasGetTextBounds(canvas, w/2, h/2, "Simple Draw (pçãí)", rect); cdCanvasForeground(canvas, CD_RED); cdCanvasBegin(canvas, CD_CLOSED_LINES); cdCanvasVertex(canvas, rect[0], rect[1]); cdCanvasVertex(canvas, rect[2], rect[3]); cdCanvasVertex(canvas, rect[4], rect[5]); cdCanvasVertex(canvas, rect[6], rect[7]); cdCanvasEnd(canvas); } cdCanvasForeground(canvas, CD_BLUE); cdCanvasText(canvas, w/2, h/2, "Simple Draw (pçãí)"); cdCanvasTextOrientation(canvas, 0); /* Prepare World Coordinates */ wdCanvasViewport(canvas, 0,w-1,0,h-1); if (w>h) wdCanvasWindow(canvas, 0,(double)w/(double)h,0,1); else wdCanvasWindow(canvas, 0,1,0,(double)h/(double)w); /* Draw a filled blue rectangle in WC */ wdCanvasBox(canvas, 0.20, 0.30, 0.40, 0.50); cdCanvasForeground(canvas, CD_RED); /* Draw the diagonal of that rectangle in WC */ wdCanvasLine(canvas, 0.20, 0.40, 0.30, 0.50); // wdVectorTextDirection(0, 0, 1, 1); /* Prepare Vector Text in WC. */ wdCanvasVectorCharSize(canvas, 0.07); // wdVectorText(0.1, 0.4, "ñç áéíóú àèìòù âêîôû äëïöü"); // wdVectorText(0.1, 0.2, "ÑÇ ÁÉÍÓÚ ÀÈÌÒÙ ÂÊÎÔÛ ÄËÏÖÜ"); //{ // int i; // char t[2]; // char s[10]; // int x = 20; // int y = 0; // t[1] = 0; // for (i = 0; i < 256; i++) // { // int dx = 90; // t[0] = (char)i; // sprintf(s, "%d", i); // cdText(x, y, s); // cdText(x+dx, y, t); // cdVectorText(x+2*dx, y, t); // // x += 3*dx + 2*dx/3; // if ((i+1) % 7 == 0) // { // x = 20; // y += 90; // } // } //} /* Draw vector text, and draw its bounding box. We also use this text to show when we are using a contextplus driver. */ { double rect[8]; cdCanvasForeground(canvas, CD_RED); if (contextplus) wdCanvasGetVectorTextBounds(canvas, "WDj-Plus", 0.25, 0.35, rect); else wdCanvasGetVectorTextBounds(canvas, "WDj", 0.25, 0.35, rect); cdCanvasBegin(canvas, CD_CLOSED_LINES); wdCanvasVertex(canvas, rect[0], rect[1]); wdCanvasVertex(canvas, rect[2], rect[3]); wdCanvasVertex(canvas, rect[4], rect[5]); wdCanvasVertex(canvas, rect[6], rect[7]); cdCanvasEnd(canvas); cdCanvasLineWidth(canvas, 2); cdCanvasLineStyle(canvas, CD_CONTINUOUS); if (contextplus) wdCanvasVectorText(canvas, 0.25, 0.35, "WDj-Plus"); else wdCanvasVectorText(canvas, 0.25, 0.35, "WDj"); cdCanvasLineWidth(canvas, 1); } /* Draw a filled path at center-right (looks like a weird fish). Notice that in PDF the arc is necessarily a circle arc, and not an ellipse. */ cdCanvasForeground(canvas, CD_GREEN); cdCanvasBegin(canvas, CD_PATH); cdCanvasPathSet(canvas, CD_PATH_MOVETO); cdCanvasVertex(canvas, w/2 + 200, h/2); cdCanvasPathSet(canvas, CD_PATH_LINETO); cdCanvasVertex(canvas, w/2 + 230, h/2 + 50); cdCanvasPathSet(canvas, CD_PATH_LINETO); cdCanvasVertex(canvas, w/2 + 250, h/2 + 50); cdCanvasPathSet(canvas, CD_PATH_CURVETO); cdCanvasVertex(canvas, w/2+150+150, h/2+200-50); /* control point for start */ cdCanvasVertex(canvas, w/2+150+180, h/2+250-50); /* control point for end */ cdCanvasVertex(canvas, w/2+150+180, h/2+200-50); /* end point */ cdCanvasPathSet(canvas, CD_PATH_CURVETO); cdCanvasVertex(canvas, w/2+150+180, h/2+150-50); cdCanvasVertex(canvas, w/2+150+150, h/2+100-50); cdCanvasVertex(canvas, w/2+150+300, h/2+100-50); cdCanvasPathSet(canvas, CD_PATH_LINETO); cdCanvasVertex(canvas, w/2+150+300, h/2-50); cdCanvasPathSet(canvas, CD_PATH_ARC); cdCanvasVertex(canvas, w/2+300, h/2); /* center */ cdCanvasVertex(canvas, 200, 100); /* width, height */ cdCanvasVertex(canvas, -30*1000, -170*1000); /* start angle, end angle (degrees / 1000) */ // cdCanvasPathSet(canvas, CD_PATH_CLOSE); // cdCanvasPathSet(canvas, CD_PATH_STROKE); cdCanvasPathSet(canvas, CD_PATH_FILL); // cdCanvasPathSet(canvas, CD_PATH_FILLSTROKE); cdCanvasEnd(canvas); /* Draw 3 pixels at center left. */ cdCanvasPixel(canvas, 10, h/2+0, CD_RED); cdCanvasPixel(canvas, 11, h/2+1, CD_GREEN); cdCanvasPixel(canvas, 12, h/2+2, CD_BLUE); /* Draw 4 mark types, distributed near each corner. */ cdCanvasForeground(canvas, CD_RED); cdCanvasMarkSize(canvas, 30); cdCanvasMarkType(canvas, CD_PLUS); cdCanvasMark(canvas, 200, 200); cdCanvasMarkType(canvas, CD_CIRCLE); cdCanvasMark(canvas, w - 200, 200); cdCanvasMarkType(canvas, CD_HOLLOW_CIRCLE); cdCanvasMark(canvas, 200, h - 200); cdCanvasMarkType(canvas, CD_DIAMOND); cdCanvasMark(canvas, w - 200, h - 200); /* Draw all the line style possibilities at bottom. Notice that they have some small differences between drivers. */ cdCanvasLineWidth(canvas, 1); cdCanvasLineStyle(canvas, CD_CONTINUOUS); cdCanvasLine(canvas, 0, 10, w, 10); cdCanvasLineStyle(canvas, CD_DASHED); cdCanvasLine(canvas, 0, 20, w, 20); cdCanvasLineStyle(canvas, CD_DOTTED); cdCanvasLine(canvas, 0, 30, w, 30); cdCanvasLineStyle(canvas, CD_DASH_DOT); cdCanvasLine(canvas, 0, 40, w, 40); cdCanvasLineStyle(canvas, CD_DASH_DOT_DOT); cdCanvasLine(canvas, 0, 50, w, 50); /* Draw all the hatch style possibilities in the top-left corner. Notice that they have some small differences between drivers. */ cdCanvasHatch(canvas, CD_VERTICAL); cdCanvasBox(canvas, 0, 50, h - 60, h); cdCanvasHatch(canvas, CD_FDIAGONAL); cdCanvasBox(canvas, 50, 100, h - 60, h); cdCanvasHatch(canvas, CD_BDIAGONAL); cdCanvasBox(canvas, 100, 150, h - 60, h); cdCanvasHatch(canvas, CD_CROSS); cdCanvasBox(canvas, 150, 200, h - 60, h); cdCanvasHatch(canvas, CD_HORIZONTAL); cdCanvasBox(canvas, 200, 250, h - 60, h); cdCanvasHatch(canvas, CD_DIAGCROSS); cdCanvasBox(canvas, 250, 300, h - 60, h); /* Draw 4 regions, in diamond shape, at top, bottom, left, right, using different interior styles. */ /* At top, not filled polygon, notice that the last line style is used. */ cdCanvasBegin(canvas, CD_CLOSED_LINES); cdCanvasVertex(canvas, w/2, h - 100); cdCanvasVertex(canvas, w/2 + 50, h - 150); cdCanvasVertex(canvas, w/2, h - 200); cdCanvasVertex(canvas, w/2 - 50, h - 150); cdCanvasEnd(canvas); /* At left, hatch filled polygon */ cdCanvasHatch(canvas, CD_DIAGCROSS); cdCanvasBegin(canvas, CD_FILL); cdCanvasVertex(canvas, 100, h/2); cdCanvasVertex(canvas, 150, h/2 + 50); cdCanvasVertex(canvas, 200, h/2); cdCanvasVertex(canvas, 150, h/2 - 50); cdCanvasEnd(canvas); /* At right, pattern filled polygon */ cdCanvasPattern(canvas, STYLE_SIZE, STYLE_SIZE, pattern); cdCanvasBegin(canvas, CD_FILL); cdCanvasVertex(canvas, w - 100, h/2); cdCanvasVertex(canvas, w - 150, h/2 + 50); cdCanvasVertex(canvas, w - 200, h/2); cdCanvasVertex(canvas, w - 150, h/2 - 50); cdCanvasEnd(canvas); /* At bottom, stipple filled polygon */ cdCanvasStipple(canvas, STYLE_SIZE, STYLE_SIZE, stipple); cdCanvasBegin(canvas, CD_FILL); cdCanvasVertex(canvas, w/2, 100); cdCanvasVertex(canvas, w/2 + 50, 150); cdCanvasVertex(canvas, w/2, 200); cdCanvasVertex(canvas, w/2 - 50, 150); cdCanvasEnd(canvas); /* Draw two beziers at bottom-left */ cdCanvasBegin(canvas, CD_BEZIER); cdCanvasVertex(canvas, 100, 100); cdCanvasVertex(canvas, 150, 200); cdCanvasVertex(canvas, 180, 250); cdCanvasVertex(canvas, 180, 200); cdCanvasVertex(canvas, 180, 150); cdCanvasVertex(canvas, 150, 100); cdCanvasVertex(canvas, 300, 100); cdCanvasEnd(canvas); /* Initialize the image buffer contents */ //#define IMAGE_SIZE 16 memset(red, 0xFF, IMAGE_SIZE*IMAGE_SIZE/2); memset(green, 0x5F, IMAGE_SIZE*IMAGE_SIZE/2); memset(blue, 0x5F, IMAGE_SIZE*IMAGE_SIZE/2); memset(red+IMAGE_SIZE*IMAGE_SIZE/2, 0x5F, IMAGE_SIZE*IMAGE_SIZE/2); memset(green+IMAGE_SIZE*IMAGE_SIZE/2, 0x8F, IMAGE_SIZE*IMAGE_SIZE/2); memset(blue+IMAGE_SIZE*IMAGE_SIZE/2, 0x5F, IMAGE_SIZE*IMAGE_SIZE/2); memset(red+IMAGE_SIZE*(IMAGE_SIZE-1), 0, IMAGE_SIZE); memset(green+IMAGE_SIZE*(IMAGE_SIZE-1), 0, IMAGE_SIZE); memset(blue+IMAGE_SIZE*(IMAGE_SIZE-1), 0, IMAGE_SIZE); memset(red, 0, IMAGE_SIZE); memset(green, 0, IMAGE_SIZE); memset(blue, 0, IMAGE_SIZE); { int i, offset; for (i = 0; i < IMAGE_SIZE; i++) { offset = i*IMAGE_SIZE; red[offset] = 0; green[offset] = 0; blue[offset] = 0; red[offset+IMAGE_SIZE-1] = 0; green[offset+IMAGE_SIZE-1] = 0; blue[offset+IMAGE_SIZE-1] = 0; } } //cdSetAttribute("ANTIALIAS", "0"); // cdGetImageRGB(red, green, blue, w/2 - 50, h/2-50, 100, 100); // cdPutImageRectRGB(14, 13, red, green, blue, -20, -15, 649, 603, 0, 13, 0, 12); // cdPutImageRectRGB(16, 16, red, green, blue, 10, 10, 608, 608, 5, 10, 5, 10); // cdPutImageRectRGB(16, 16, red, green, blue, 10, 10, 64, 64, 5, 10, 5, 10); // cdPutImageRGB(IMAGE_SIZE, IMAGE_SIZE, red, green, blue, 100, h - 200, IMAGE_SIZE, IMAGE_SIZE); // cdPutImageRGBA(IMAGE_SIZE, IMAGE_SIZE, red, green, blue, alpha, 100, h - 200, IMAGE_SIZE, IMAGE_SIZE); // cdPutImageRGB(IMAGE_SIZE, IMAGE_SIZE, red, green, blue, w - 400, h - 310, 3*IMAGE_SIZE, 3*IMAGE_SIZE); /* Draw the image on the top-right corner but increasing its actual size, and uses its full area */ cdCanvasPutImageRectRGBA(canvas, IMAGE_SIZE, IMAGE_SIZE, red, green, blue, alpha, w - 400, h - 310, 3*IMAGE_SIZE, 3*IMAGE_SIZE, 0, 0, 0, 0); cdCanvasSetAttribute(canvas, "ROTATE", NULL); if (use_transform) cdCanvasTransform(canvas, NULL); cdCanvasClip(canvas, CD_CLIPOFF); }
void SimpleDrawTest(cdCanvas* canvas) //void SimpleDrawMainTest(cdCanvas* canvas) { long pattern[16]; /* 4x4 pattern */ int w, h; int xmin, xmax, ymin, ymax; /* notice that if we are not using world coordinates it is harder to position all the objetcs we want. */ cdCanvasGetSize(canvas, &w, &h, 0, 0); cdCanvasBackground(canvas, CD_WHITE); cdCanvasClear(canvas); /* pattern initialization */ pattern[0] = CD_RED; pattern[1] = CD_RED; /* first line */ pattern[2] = CD_YELLOW; pattern[3] = CD_YELLOW; pattern[4] = CD_RED; pattern[5] = CD_RED; /* second line */ pattern[6] = CD_YELLOW; pattern[7] = CD_YELLOW; pattern[8] = CD_YELLOW; pattern[9] = CD_YELLOW; /* third line */ pattern[10] = CD_YELLOW; pattern[11] = CD_YELLOW; pattern[12] = CD_YELLOW; pattern[13] = CD_YELLOW; /* fourth line */ pattern[14] = CD_YELLOW; pattern[15] = CD_YELLOW; /* set the line attributes */ cdCanvasLineWidth(canvas, 4); cdCanvasLineStyle(canvas, CD_CONTINUOUS); /* in the center draw a pattern pizza with a slice mising */ cdCanvasPattern(canvas, 4, 4, pattern); cdCanvasSector(canvas, w/2, h/2, w/2, h/2, 45, 0); /* draws a dark red border */ cdCanvasForeground(canvas, CD_DARK_RED); cdCanvasInteriorStyle(canvas, CD_HOLLOW); cdCanvasSector(canvas, w/2, h/2, w/2, h/2, 45, 0); /* on the left a red hash diamond */ /* notice the the default back opacity is transparent and the pattern of the sector will still be visible inside the hatch where the two objects intersect */ cdCanvasForeground(canvas, CD_RED); cdCanvasHatch(canvas, CD_DIAGCROSS); cdCanvasBegin(canvas, CD_FILL); cdCanvasVertex(canvas, w/4, h/4); cdCanvasVertex(canvas, w/2-w/8, h/2); cdCanvasVertex(canvas, w/4, 3*h/4); cdCanvasVertex(canvas, w/8, h/2); cdCanvasEnd(canvas); /* draws a blue roof.*/ cdCanvasForeground(canvas, CD_BLUE); cdCanvasLine(canvas, w/8, h/2, w/4, 3*h/4); cdCanvasLine(canvas, w/4, 3*h/4, w/2-w/8, h/2); /* draws a dashed ribbon on the right with a custom color */ cdCanvasForeground(canvas, cdEncodeColor(100, 25, 200)); cdCanvasLineStyle(canvas, CD_DASH_DOT); cdCanvasBegin(canvas, CD_BEZIER); cdCanvasVertex(canvas, 3*w/4-20, h/2-50); cdCanvasVertex(canvas, 3*w/4+150, 3*h/4-50); cdCanvasVertex(canvas, 3*w/4-150, 3*h/4-50); cdCanvasVertex(canvas, 3*w/4+20, h/2-50); cdCanvasEnd(canvas); cdCanvasFont(canvas, "Helvetica", CD_BOLD, 40); cdCanvasTextAlignment(canvas, CD_CENTER); cdCanvasText(canvas, w/2, h/4-50, "Canvas Draw"); cdCanvasGetTextBox(canvas, w/2, h/4-50, "Canvas Draw", &xmin, &xmax, &ymin, &ymax); cdCanvasRect(canvas, xmin, xmax, ymin, ymax); }