diff options
Diffstat (limited to 'cd/test/simple/simple.c')
-rwxr-xr-x | cd/test/simple/simple.c | 1061 |
1 files changed, 591 insertions, 470 deletions
diff --git a/cd/test/simple/simple.c b/cd/test/simple/simple.c index d04b96c..c47812e 100755 --- a/cd/test/simple/simple.c +++ b/cd/test/simple/simple.c @@ -29,6 +29,7 @@ #include "cddebug.h" #include "wd.h" #include "cdgdiplus.h" +#include "cdgl.h" #include "simple.h" @@ -46,10 +47,11 @@ cdCanvas *curCanvas = NULL; /* The current canvas */ int clipping = CD_CLIPOFF; /* Clipping flag, same as the CD */ int write_mode = CD_REPLACE; /* Write Mode flag, same as the CD */ -int gdpiplus = 0; +int contextplus = 0; int simple_draw = 0; int use_transform = 0; int simulate = 0; +int use_opengl = 0; enum {DRAW_ALL, DRAW_TEXTFONTS, DRAW_TEXTALIGN, DRAW_TEST}; @@ -65,7 +67,7 @@ unsigned char alpha[IMAGE_SIZE*IMAGE_SIZE]; /* Alpha image buffer */ /* Prototype of the function that makes the drawing independent of canvas. */ -void SimpleDraw(void); +void SimpleDraw(cdCanvas* canvas); void SimpleInitAlpha(int width, int height, unsigned char* _alpha) { @@ -79,9 +81,9 @@ void SimpleInitAlpha(int width, int height, unsigned char* _alpha) void SimpleCreateCanvasWindow(void) { /* creates the canvas based in an existing window */ - if (gdpiplus) cdUseContextPlus(1); + if (contextplus) cdUseContextPlus(1); winCanvas = cdCreateCanvas(CD_IUP, winData); - if (gdpiplus) cdUseContextPlus(0); + if (contextplus) cdUseContextPlus(0); curCanvas = winCanvas; } @@ -144,17 +146,17 @@ void SimpleCreateCanvas(char* data) int SimpleTransform(void) { use_transform = !use_transform; - SimpleDrawRepaint(); + SimpleDraw(curCanvas); return 0; } int SimpleContextPlus(void) { #ifdef USE_CONTEXTPLUS - gdpiplus = !gdpiplus; + contextplus = !contextplus; SimpleKillCanvas(); SimpleCreateCanvasWindow(); - SimpleDrawRepaint(); + SimpleDraw(curCanvas); #endif return 0; } @@ -162,12 +164,12 @@ int SimpleContextPlus(void) void PlayCanvasDriver(cdContext* ctx, char* StrData) { int w, h; - cdActivate(curCanvas); - cdBackground(CD_WHITE); - cdClear(); - cdGetCanvasSize(&w, &h, 0, 0); - cdPlay(ctx, 100, w-100, 100, h-100, StrData); -// cdPlay(ctx, 0, 0, 0, 0, StrData); + 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); } int SimplePlayClipboard(void) @@ -206,28 +208,32 @@ int SimplePlayEMF(void) return 0; } -int SimpleDrawRepaint(void) +int SimpleRepaint(void) { - cdActivate(curCanvas); - SimpleDraw(); - cdFlush(); + SimpleDraw(curCanvas); return 0; } int SimpleDrawWindow(void) { + use_opengl = 0; curCanvas = winCanvas; - return SimpleDrawRepaint(); + SimpleDraw(curCanvas); + return 0; } void DrawCanvasDriver(cdContext* ctx, char* StrData) { cdCanvas* tmpCanvas = cdCreateCanvas(ctx, StrData); - if (tmpCanvas == NULL) return; - cdActivate(tmpCanvas); - SimpleDraw(); + if (tmpCanvas == NULL) + { + printf("CreateCanvas(%s) - Failed!\n", StrData); + return; + } + printf("CreateCanvas(%s)\n", StrData); + SimpleDraw(tmpCanvas); cdKillCanvas(tmpCanvas); - cdActivate(curCanvas); + printf("KillCanvas()\n"); } void DrawCanvasDriverSize(cdContext* ctx, char* name, int pixels) @@ -235,12 +241,13 @@ void DrawCanvasDriverSize(cdContext* ctx, char* name, int pixels) char StrData[100]; int w, h; double w_mm, h_mm; - cdActivate(curCanvas); - cdGetCanvasSize(&w, &h, &w_mm, &h_mm); - if (pixels) + 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", name, w_mm, h_mm); + sprintf(StrData, "%s %gx%g %g", name, w_mm, h_mm, (double)w/w_mm); DrawCanvasDriver(ctx, StrData); } @@ -248,8 +255,7 @@ void DrawCanvasDriverSizeParam(cdContext* ctx, char* param) { char StrData[100]; int w, h; - cdActivate(curCanvas); - cdGetCanvasSize(&w, &h, 0, 0); + cdCanvasGetSize(curCanvas, &w, &h, 0, 0); sprintf(StrData, "%dx%d %s", w, h, param); DrawCanvasDriver(ctx, StrData); } @@ -262,7 +268,7 @@ int SimpleDrawDebug(void) int SimpleDrawCGMText(void) { - DrawCanvasDriverSize(CD_CGM, "simple_t.cgm - t", 0); + DrawCanvasDriverSize(CD_CGM, "simple_t.cgm -t", 0); return 0; } @@ -286,9 +292,9 @@ int SimpleDrawDGN(void) int SimpleDrawEMF(void) { - if (gdpiplus) cdUseContextPlus(1); + if (contextplus) cdUseContextPlus(1); DrawCanvasDriverSize(CD_EMF, "simple.emf", 1); - if (gdpiplus) cdUseContextPlus(0); + if (contextplus) cdUseContextPlus(0); return 0; } @@ -300,7 +306,7 @@ int SimpleDrawMetafile(void) int SimpleDrawPS(void) { - DrawCanvasDriver(CD_PS, "simple.ps"); + DrawCanvasDriverSize(CD_PS, "simple.ps -l0 -r0 -t0 -b0", 2); return 0; } @@ -312,13 +318,13 @@ int SimpleDrawSVG(void) int SimpleDrawPDF(void) { - DrawCanvasDriver(CD_PDF, "simple.pdf"); + DrawCanvasDriverSize(CD_PDF, "simple.pdf", 2); return 0; } int SimpleDrawEPS(void) { - DrawCanvasDriver(CD_PS, "simple.eps -e"); + DrawCanvasDriverSize(CD_PS, "simple.eps -e", 2); return 0; } @@ -330,97 +336,118 @@ int SimpleDrawWMF(void) int SimpleDrawPrint(void) { - if (gdpiplus) cdUseContextPlus(1); + if (contextplus) cdUseContextPlus(1); DrawCanvasDriver(CD_PRINTER, "simple print"); - if (gdpiplus) cdUseContextPlus(0); + if (contextplus) cdUseContextPlus(0); return 0; } int SimpleDrawPrintDialog(void) { - if (gdpiplus) cdUseContextPlus(1); - DrawCanvasDriver(CD_PRINTER, "simple -d"); - if (gdpiplus) cdUseContextPlus(0); + if (contextplus) cdUseContextPlus(1); + DrawCanvasDriver(CD_PRINTER, "simple -d"); /* show dialog */ + if (contextplus) cdUseContextPlus(0); return 0; } int SimpleDrawClipboardBitmap(void) { - if (gdpiplus) cdUseContextPlus(1); + if (contextplus) cdUseContextPlus(1); DrawCanvasDriverSizeParam(CD_CLIPBOARD, "-b"); - if (gdpiplus) cdUseContextPlus(0); + if (contextplus) cdUseContextPlus(0); return 0; } int SimpleDrawClipboardMetafile(void) { - if (gdpiplus) cdUseContextPlus(1); + if (contextplus) cdUseContextPlus(1); DrawCanvasDriverSizeParam(CD_CLIPBOARD, "-m"); - if (gdpiplus) cdUseContextPlus(0); + if (contextplus) cdUseContextPlus(0); return 0; } int SimpleDrawClipboardEMF(void) { - if (gdpiplus) cdUseContextPlus(1); + if (contextplus) cdUseContextPlus(1); DrawCanvasDriverSizeParam(CD_CLIPBOARD, ""); - if (gdpiplus) cdUseContextPlus(0); + if (contextplus) cdUseContextPlus(0); return 0; } int SimpleReplace(void) { write_mode = CD_REPLACE; - cdActivate(curCanvas); - SimpleDrawAll(); + SimpleDraw(curCanvas); return 0; } int SimpleXor(void) { write_mode = CD_XOR; - cdActivate(curCanvas); - SimpleDrawAll(); + SimpleDraw(curCanvas); return 0; } int SimpleNotXor(void) { write_mode = CD_NOT_XOR; - cdActivate(curCanvas); - SimpleDrawAll(); + SimpleDraw(curCanvas); return 0; } int SimpleClippingOff(void) { clipping = CD_CLIPOFF; - cdActivate(curCanvas); - SimpleDrawAll(); + SimpleDraw(curCanvas); return 0; } int SimpleClippingArea(void) { clipping = CD_CLIPAREA; - cdActivate(curCanvas); - SimpleDrawAll(); + SimpleDraw(curCanvas); return 0; } int SimpleClippingPolygon(void) { clipping = CD_CLIPPOLYGON; - cdActivate(curCanvas); - SimpleDrawAll(); + SimpleDraw(curCanvas); return 0; } int SimpleClippingRegion(void) { clipping = CD_CLIPREGION; - cdActivate(curCanvas); - SimpleDrawAll(); + SimpleDraw(curCanvas); + return 0; +} + +int SimpleAll(void) +{ + simple_draw = DRAW_ALL; + SimpleDraw(curCanvas); + return 0; +} + +int SimpleTextAlign(void) +{ + simple_draw = DRAW_TEXTALIGN; + SimpleDraw(curCanvas); + return 0; +} + +int SimpleTextFonts(void) +{ + simple_draw = DRAW_TEXTFONTS; + SimpleDraw(curCanvas); + return 0; +} + +int SimpleTest(void) +{ + simple_draw = DRAW_TEST; + SimpleDraw(curCanvas); return 0; } @@ -429,53 +456,79 @@ void* CreateImageRGBA(int w, int h) void* myImage; unsigned char * _alpha = malloc(w * h); SimpleInitAlpha(w, h, _alpha); - cdSetAttribute("IMAGEALPHA", (char*)_alpha); - cdSetAttribute("IMAGEFORMAT", "32"); // afetara´ o proximo cdCreateImage - myImage = cdCreateImage(w, h); - cdSetAttribute("IMAGEFORMAT", NULL); // remove o atributo para nao afetar outros cdCreateImage + cdCanvasSetAttribute(curCanvas, "IMAGEALPHA", (char*)_alpha); + cdCanvasSetAttribute(curCanvas, "IMAGEFORMAT", "32"); // afetara´ o proximo cdCreateImage + myImage = cdCanvasCreateImage(curCanvas, w, h); + cdCanvasSetAttribute(curCanvas, "IMAGEFORMAT", NULL); // remove o atributo para nao afetar outros cdCreateImage return myImage; } int SimpleDrawImage(void) { + use_opengl = 0; if (dbCanvas) cdKillCanvas(dbCanvas); - if (gdpiplus) cdUseContextPlus(1); + if (contextplus) cdUseContextPlus(1); dbCanvas = cdCreateCanvas(CD_DBUFFER, winCanvas); - if (gdpiplus) cdUseContextPlus(0); + if (contextplus) cdUseContextPlus(0); curCanvas = dbCanvas; - SimpleDrawRepaint(); + SimpleDraw(curCanvas); return 0; } int SimpleDrawImageRGB(void) { + use_opengl = 0; if (dbCanvas) cdKillCanvas(dbCanvas); - if (gdpiplus) cdUseContextPlus(1); + if (contextplus) cdUseContextPlus(1); dbCanvas = cdCreateCanvas(CD_DBUFFERRGB, winCanvas); - if (gdpiplus) cdUseContextPlus(0); + if (contextplus) cdUseContextPlus(0); curCanvas = dbCanvas; - SimpleDrawRepaint(); + SimpleDraw(curCanvas); return 0; } -int SimpleDrawSimulate(void) +#ifdef USE_OPENGL +int SimpleDrawGL(void) { - cdActivate(curCanvas); + 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; +} +#endif + +int SimpleDrawSimulate(void) +{ simulate = !simulate; if (simulate) - cdSimulate(CD_SIM_ALL); + cdCanvasSimulate(curCanvas, CD_SIM_ALL); else - cdSimulate(CD_SIM_NONE); + cdCanvasSimulate(curCanvas, CD_SIM_NONE); - SimpleDrawRepaint(); + SimpleDraw(curCanvas); return 0; } @@ -494,167 +547,207 @@ void SimpleKillCanvas(void) } } -void SimpleDraw(void) +void SimpleDrawTextFonts(cdCanvas* canvas); +void SimpleDrawTextAlign(cdCanvas* canvas); +void SimpleDrawAll(cdCanvas* canvas); +void SimpleDrawTest(cdCanvas* canvas); + +void SimpleDraw(cdCanvas* canvas) { +#ifdef USE_OPENGL + if (use_opengl) + SimpleUpdateSize(canvas); +#endif + + /* refresh CD canvas size, when window size has changed */ + cdCanvasActivate(canvas); + if (simple_draw == DRAW_TEXTFONTS) - SimpleDrawTextFonts(); + SimpleDrawTextFonts(canvas); else if (simple_draw == DRAW_TEXTALIGN) - SimpleDrawTextAlign(); + SimpleDrawTextAlign(canvas); else if (simple_draw == DRAW_TEST) - SimpleDrawTest(); + SimpleDrawTest(canvas); else - SimpleDrawAll(); + SimpleDrawAll(canvas); + + /* Adds a new page, or + flushes the file, or + flushes the screen, or + swap the double buffer. */ + cdCanvasFlush(canvas); + +#ifdef USE_OPENGL + if (use_opengl) + SimpleFlush(); +#endif } -int SimpleDrawAll(void) +void SimpleDrawAll(cdCanvas* canvas) { int w, h; - cdGetCanvasSize(&w, &h, 0, 0); + cdCanvasGetSize(canvas, &w, &h, NULL, NULL); - simple_draw = DRAW_ALL; - - wdViewport(0,w-1,0,h-1); - if (w>h) - wdWindow(0,(double)w/(double)h,0,1); - else - wdWindow(0,1,0,(double)h/(double)w); - /* Clear the background to be white */ - cdBackground(CD_WHITE); + cdCanvasBackground(canvas, CD_WHITE); // cdBackground(CD_GREEN); - cdClear(); - - cdLineWidth(3); - cdForeground(cdEncodeAlpha(CD_DARK_MAGENTA, 128)); - cdRect(100, 200, 100, 200); - - cdBegin(CD_OPEN_LINES); - cdVertex(300, 250); - cdVertex(320, 270); - cdVertex(350, 260); - cdVertex(340, 200); - cdVertex(310, 210); - cdEnd(); + 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); - cdInteriorStyle(CD_SOLID); - - cdForeground(CD_RED); - cdLineWidth(3); + /* 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}; - cdLineStyleDashes(dashes, 4); + cdCanvasLineStyleDashes(canvas, dashes, 4); } - cdLineStyle(CD_CUSTOM); - cdLine(0, 0, w-1, h-1); + cdCanvasLineStyle(canvas, CD_CUSTOM); + cdCanvasLine(canvas, 0, 0, w-1, h-1); - cdForeground(CD_BLUE); - cdLineWidth(10); - cdLineStyle(CD_DOTTED); - //cdLine(0, 0, 500, 500); -// wdLine(0, 1, 1, 0); - cdLine(0, h-1, w-1, 0); + /* 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: - cdClip(CD_CLIPOFF); + cdCanvasClip(canvas, CD_CLIPOFF); break; case CD_CLIPAREA: /* Defines the clipping area equals the canvas area minus a 100 pixels margin. */ - cdClipArea(100, w - 100, 100, h - 100); - cdClip(CD_CLIPAREA); + cdCanvasClipArea(canvas, 100, w - 100, 100, h - 100); + cdCanvasClip(canvas, CD_CLIPAREA); break; case CD_CLIPPOLYGON: - cdBegin(CD_CLIP); - cdVertex(100, 100); - cdVertex(w - 100, 100); - cdVertex(w / 2, h - 100); - cdEnd(); - cdClip(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: - cdTextAlignment(CD_CENTER); - cdFont(CD_TIMES_ROMAN, CD_BOLD, 50); - - cdBegin(CD_REGION); - cdRegionCombineMode(CD_UNION); - cdBox(100, 200, 100, 200); - cdSector(w/2-50, h/2+50, 150, 150, 0, 360); - cdSector(w/2-50, h/2-50, 150, 150, 0, 360); - cdSector(w/2+50, h/2+50, 150, 150, 0, 360); - cdSector(w/2+50, h/2-50, 150, 150, 0, 360); - cdRegionCombineMode(CD_DIFFERENCE); - cdText(w/2, h/2, "TEXT"); - cdEnd(); -// cdOffsetRegion(-50, 50); - cdClip(CD_CLIPREGION); - - cdForeground(CD_DARK_RED); - cdBox(0,w,0,h); + 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: - cdWriteMode(CD_REPLACE); + cdCanvasWriteMode(canvas, CD_REPLACE); break; case CD_XOR: - cdWriteMode(CD_XOR); + cdCanvasWriteMode(canvas, CD_XOR); break; case CD_NOT_XOR: - cdWriteMode(CD_NOT_XOR); + cdCanvasWriteMode(canvas, CD_NOT_XOR); break; } if (use_transform) { - cdCanvasTransform(cdActiveCanvas(), NULL); - cdCanvasTransformTranslate(cdActiveCanvas(), w/2, h/2); - cdCanvasTransformRotate(cdActiveCanvas(), 30); - cdCanvasTransformScale(cdActiveCanvas(), 0.5, 0.5); - cdCanvasTransformTranslate(cdActiveCanvas(), -w/2, -h/2); + 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); - cdLineStyle(CD_CONTINUOUS); - cdLineWidth(1); - cdBackOpacity(CD_TRANSPARENT); - - cdForeground(CD_MAGENTA); - cdSector(w-100, 100, 100, 100, 50, 180); - cdForeground(CD_RED); - cdArc(100, 100, 100, 100, 50, 180); - - cdForeground(CD_YELLOW); - cdBox(w/2 - 100, w/2 + 100, h/2 - 100, h/2 + 100); - - cdTextAlignment(CD_CENTER); - cdTextOrientation(70); - cdFont(CD_TIMES_ROMAN, CD_BOLD, 24); - + /* 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]; - cdTextBounds(w/2, h/2, "cdMin Draw (çãí)", rect); - cdForeground(CD_RED); - cdBegin(CD_CLOSED_LINES); - cdVertex(rect[0], rect[1]); - cdVertex(rect[2], rect[3]); - cdVertex(rect[4], rect[5]); - cdVertex(rect[6], rect[7]); - cdEnd(); + 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); } - cdForeground(CD_BLUE); - cdText(w/2, h/2, "cdMin Draw (çãí)"); - cdTextOrientation(0); + cdCanvasForeground(canvas, CD_BLUE); + cdCanvasText(canvas, w/2, h/2, "Simple Draw (pçãí)"); + cdCanvasTextOrientation(canvas, 0); - wdBox(0.20, 0.30, 0.40, 0.50); - cdForeground(CD_RED); - wdLine(0.20, 0.40, 0.30, 0.50); + /* 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); - wdVectorCharSize(0.07); + /* Prepare Vector Text in WC. */ + wdCanvasVectorCharSize(canvas, 0.07); // wdVectorText(0.1, 0.4, "ñç áéíóú àèìòù âêîôû äëïöü"); // wdVectorText(0.1, 0.2, "ÑÇ ÁÉÍÓÚ ÀÈÌÒÙ ÂÊÎÔÛ ÄËÏÖÜ"); @@ -684,115 +777,158 @@ int SimpleDrawAll(void) // } //} + /* 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]; - cdForeground(CD_RED); - if (gdpiplus) - wdGetVectorTextBounds("WDj-Plus", 0.25, 0.35, rect); + 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 - wdGetVectorTextBounds("WDj", 0.25, 0.35, rect); - cdBegin(CD_CLOSED_LINES); - wdVertex(rect[0], rect[1]); - wdVertex(rect[2], rect[3]); - wdVertex(rect[4], rect[5]); - wdVertex(rect[6], rect[7]); - cdEnd(); + wdCanvasVectorText(canvas, 0.25, 0.35, "WDj"); + cdCanvasLineWidth(canvas, 1); } - cdPixel(10, h/2+0, CD_RED); - cdPixel(11, h/2+1, CD_GREEN); - cdPixel(12, h/2+2, CD_BLUE); - - /* draws all the mark type possibilities */ - cdForeground(CD_RED); - cdMarkSize(30); - cdMarkType(CD_PLUS); - cdMark(200, 200); - cdMarkType(CD_CIRCLE); - cdMark(w - 200, 200); - cdMarkType(CD_HOLLOW_CIRCLE); - cdMark(200, h - 200); - cdMarkType(CD_DIAMOND); - cdMark(w - 200, h - 200); - - /* draws all the line style possibilities */ - cdLineWidth(1); - cdLineStyle(CD_CONTINUOUS); - cdLine(0, 10, w, 10); - cdLineStyle(CD_DASHED); - cdLine(0, 20, w, 20); - cdLineStyle(CD_DASH_DOT); - cdLine(0, 30, w, 30); - cdLineStyle(CD_DASH_DOT_DOT); - cdLine(0, 40, w, 40); - - /* draws all the hatch style possibilities */ - cdHatch(CD_VERTICAL); - cdBox(0, 50, h - 60, h); - cdHatch(CD_FDIAGONAL); - cdBox(50, 100, h - 60, h); - cdHatch(CD_BDIAGONAL); - cdBox(100, 150, h - 60, h); - cdHatch(CD_CROSS); - cdBox(150, 200, h - 60, h); - cdHatch(CD_HORIZONTAL); - cdBox(200, 250, h - 60, h); - cdHatch(CD_DIAGCROSS); - cdBox(250, 300, h - 60, h); - - /* closed polygon */ - cdBegin(CD_CLOSED_LINES); - cdVertex(w/2, h - 100); - cdVertex(w/2 + 50, h - 150); - cdVertex(w/2, h - 200); - cdVertex(w/2 - 50, h - 150); - cdEnd(); - - /* hatch filled polygon */ - cdHatch(CD_DIAGCROSS); - cdBegin(CD_FILL); - cdVertex(100, h/2); - cdVertex(150, h/2 + 50); - cdVertex(200, h/2); - cdVertex(150, h/2 - 50); - cdEnd(); - - /* pattern filled polygon */ - cdPattern(STYLE_SIZE, STYLE_SIZE, pattern); - cdBegin(CD_FILL); - cdVertex(w - 100, h/2); - cdVertex(w - 150, h/2 + 50); - cdVertex(w - 200, h/2); - cdVertex(w - 150, h/2 - 50); - cdEnd(); + /* 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); - /* stipple filled polygon */ - cdStipple(STYLE_SIZE, STYLE_SIZE, stipple); - cdBegin(CD_FILL); - cdVertex(w/2, 100); - cdVertex(w/2 + 50, 150); - cdVertex(w/2, 200); - cdVertex(w/2 - 50, 150); - cdEnd(); - - cdBegin(CD_BEZIER); - cdVertex(100, 100); - cdVertex(150, 200); - cdVertex(180, 250); - cdVertex(180, 200); - cdVertex(180, 150); - cdVertex(150, 100); - cdVertex(300, 100); - cdEnd(); - - cdLineWidth(2); - cdLineStyle(CD_CONTINUOUS); - if (gdpiplus) - wdVectorText(0.25, 0.35, "WDj-Plus"); - else - wdVectorText(0.25, 0.35, "WDj"); - - /* always clear the image buffer contents */ + /* 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); @@ -828,138 +964,136 @@ int SimpleDrawAll(void) // 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); -// cdPutImageRGBA(IMAGE_SIZE, IMAGE_SIZE, red, green, blue, alpha, w - 400, h - 310, 3*IMAGE_SIZE, 3*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); - cdSetAttribute("ROTATE", NULL); + cdCanvasSetAttribute(canvas, "ROTATE", NULL); if (use_transform) - cdCanvasTransform(cdActiveCanvas(), NULL); - cdClip(CD_CLIPOFF); - cdFlush(); - - return 0; + cdCanvasTransform(canvas, NULL); + cdCanvasClip(canvas, CD_CLIPOFF); } -void DrawVectorTextBox(int x, int y, char* text) +void DrawVectorTextBox(cdCanvas* canvas, int x, int y, char* text) { int rect[8], draw_box; - cdLineWidth(1); - cdLineStyle(CD_CONTINUOUS); + cdCanvasLineWidth(canvas, 1); + cdCanvasLineStyle(canvas, CD_CONTINUOUS); draw_box = 0; if (draw_box) { int xmin, xmax, ymin, ymax; - cdCanvasGetVectorTextBox(cdActiveCanvas(), x, y, text, &xmin, &xmax, &ymin, &ymax); - cdForeground(CD_GREEN); - cdRect(xmin, xmax, ymin, ymax); + cdCanvasGetVectorTextBox(canvas, x, y, text, &xmin, &xmax, &ymin, &ymax); + cdCanvasForeground(canvas, CD_GREEN); + cdCanvasRect(canvas, xmin, xmax, ymin, ymax); - if (cdTextOrientation(CD_QUERY) == 0) + if (cdCanvasTextOrientation(canvas, CD_QUERY) == 0) { - cdForeground(CD_RED); - cdLine(xmin, y, xmax, y); + cdCanvasForeground(canvas, CD_RED); + cdCanvasLine(canvas, xmin, y, xmax, y); } } else { /* bounding box */ - cdGetVectorTextBounds(text, x, y, rect); - cdForeground(CD_GREEN); - cdBegin(CD_CLOSED_LINES); - cdVertex(rect[0], rect[1]); - cdVertex(rect[2], rect[3]); - cdVertex(rect[4], rect[5]); - cdVertex(rect[6], rect[7]); - cdEnd(); + cdCanvasGetVectorTextBounds(canvas, text, x, y, rect); + cdCanvasForeground(canvas, CD_GREEN); + 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); } /* reference point */ - cdForeground(CD_BLUE); - cdMarkType(CD_PLUS); - cdMarkSize(30); - cdMark(x, y); + cdCanvasForeground(canvas, CD_BLUE); + cdCanvasMarkType(canvas, CD_PLUS); + cdCanvasMarkSize(canvas, 30); + cdCanvasMark(canvas, x, y); - cdForeground(CD_BLACK); - cdVectorText(x, y, text); + cdCanvasForeground(canvas, CD_BLACK); + cdCanvasVectorText(canvas, x, y, text); } -void DrawTextBox(int x, int y, char* text) +void DrawTextBox(cdCanvas* canvas, int x, int y, char* text) { int rect[8], draw_box; - cdLineWidth(1); - cdLineStyle(CD_CONTINUOUS); + cdCanvasLineWidth(canvas, 1); + cdCanvasLineStyle(canvas, CD_CONTINUOUS); draw_box = 0; if (draw_box) { int xmin, xmax, ymin, ymax; - cdTextBox(x, y, text, &xmin, &xmax, &ymin, &ymax); - cdRect(xmin, xmax, ymin, ymax); + cdCanvasGetTextBox(canvas, x, y, text, &xmin, &xmax, &ymin, &ymax); + cdCanvasRect(canvas, xmin, xmax, ymin, ymax); - if (cdTextOrientation(CD_QUERY) == 0) + if (cdCanvasTextOrientation(canvas, CD_QUERY) == 0) { - cdForeground(CD_RED); - cdLine(xmin, y, xmax, y); + cdCanvasForeground(canvas, CD_RED); + cdCanvasLine(canvas, xmin, y, xmax, y); } } else { /* bounding box */ - cdTextBounds(x, y, text, rect); - cdForeground(CD_GREEN); - cdBegin(CD_CLOSED_LINES); - cdVertex(rect[0], rect[1]); - cdVertex(rect[2], rect[3]); - cdVertex(rect[4], rect[5]); - cdVertex(rect[6], rect[7]); - cdEnd(); + cdCanvasGetTextBounds(canvas, x, y, text, rect); + cdCanvasForeground(canvas, CD_GREEN); + 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); } /* reference point */ - cdForeground(CD_BLUE); - cdMarkType(CD_PLUS); - cdMarkSize(30); - cdMark(x, y); + cdCanvasForeground(canvas, CD_BLUE); + cdCanvasMarkType(canvas, CD_PLUS); + cdCanvasMarkSize(canvas, 30); + cdCanvasMark(canvas, x, y); - cdForeground(CD_BLACK); - cdText(x, y, text); + cdCanvasForeground(canvas, CD_BLACK); + cdCanvasText(canvas, x, y, text); } -int SimpleDrawTextAlign(void) +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 + 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)", - "South (Ãyj)\nSecond Line (Ãyj)", - "East (Ãyj)\nSecond Line (Ãyj)", - "West (Ãyj)\nSecond Line (Ãyj)", - "North East (Ãyj)\nSecond Line (Ãyj)", - "North West (Ãyj)\nSecond Line (Ãyj)", - "South East (Ãyj)\nSecond Line (Ãyj)", - "South West (Ãyj)\nSecond Line (Ãyj)", - "Center (Ãyj)\nSecond Line (Ãyj)", - "Base Center (Ãyj)\nSecond Line (Ãyj)", - "Base Right (Ãyj)\nSecond Line (Ãyj)", - "Base Left (Ãyj)\nSecond Line (Ãyj)" + "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[] = { @@ -978,90 +1112,83 @@ int SimpleDrawTextAlign(void) }; #endif - cdGetCanvasSize(&w, &h, 0, 0); - - cdBackground(CD_WHITE); - cdClear(); + cdCanvasGetSize(canvas, &w, &h, 0, 0); - simple_draw = DRAW_TEXTALIGN; + cdCanvasBackground(canvas, CD_WHITE); + cdCanvasClear(canvas); use_vector = 0; #if 0 if (use_vector) - cdVectorTextDirection(0, 0, 1, 1); + cdCanvasVectorTextDirection(canvas, 0, 0, 1, 1); else - cdTextOrientation(45); + cdCanvasTextOrientation(canvas, 45); #endif xoff = w/4; yoff = h/7; if (use_vector) - cdVectorCharSize(30); + cdCanvasVectorCharSize(canvas, 30); else { - //cdFont(CD_TIMES_ROMAN, CD_PLAIN, 14); - cdFont(CD_HELVETICA, CD_PLAIN, 24); + //cdCanvasFont(canvas, "Times", CD_PLAIN, 14); + cdCanvasFont(canvas, "Helvetica", CD_PLAIN, 24); } for (i = 0; i < 12; i++) { - cdTextAlignment(text_aligment[i]); + cdCanvasTextAlignment(canvas, text_aligment[i]); if (i < 6) { if (use_vector) - DrawVectorTextBox(xoff, yoff*(i+1), text_aligment_str[i]); + DrawVectorTextBox(canvas, xoff, yoff*(i+1), text_aligment_str[i]); else - DrawTextBox(xoff, yoff*(i+1), text_aligment_str[i]); + DrawTextBox(canvas, xoff, yoff*(i+1), text_aligment_str[i]); } else { if (use_vector) - DrawVectorTextBox(3*xoff, yoff*(i-5), text_aligment_str[i]); + DrawVectorTextBox(canvas, 3*xoff, yoff*(i-5), text_aligment_str[i]); else - DrawTextBox(3*xoff, yoff*(i-5), text_aligment_str[i]); + DrawTextBox(canvas, 3*xoff, yoff*(i-5), text_aligment_str[i]); } } - - cdFlush(); - return 0; } -void DrawTextFont(int font, int size, int xoff, int yoff, char* text) +void DrawTextFont(cdCanvas* canvas, const char* font, int size, int xoff, int yoff, char* text) { - cdFont(font, CD_PLAIN, size); - DrawTextBox(xoff, yoff, text); + cdCanvasFont(canvas, font, CD_PLAIN, size); + DrawTextBox(canvas, xoff, yoff, text); - cdFont(font, CD_BOLD, size); - DrawTextBox(2*xoff, yoff, text); + cdCanvasFont(canvas, font, CD_BOLD, size); + DrawTextBox(canvas, 2*xoff, yoff, text); - cdFont(font, CD_ITALIC, size); - DrawTextBox(3*xoff, yoff, text); + cdCanvasFont(canvas, font, CD_ITALIC, size); + DrawTextBox(canvas, 3*xoff, yoff, text); - cdFont(font, CD_BOLD_ITALIC, size); - DrawTextBox(4*xoff, yoff, text); + cdCanvasFont(canvas, font, CD_BOLD_ITALIC, size); + DrawTextBox(canvas, 4*xoff, yoff, text); } -int SimpleDrawTextFonts(void) +void SimpleDrawTextFonts(cdCanvas* canvas) { int xoff, yoff, size; - cdBackground(CD_WHITE); - cdClear(); - - simple_draw = DRAW_TEXTFONTS; + cdCanvasBackground(canvas, CD_WHITE); + cdCanvasClear(canvas); xoff = 470; yoff = 150; size = -30; - cdTextAlignment(CD_CENTER); + cdCanvasTextAlignment(canvas, CD_CENTER); - DrawTextFont(CD_COURIER, size, xoff, yoff, "Courier"); - DrawTextFont(CD_TIMES_ROMAN, size, xoff, 2*yoff, "Times Roman"); - DrawTextFont(CD_HELVETICA, size, xoff, 3*yoff, "Helvetica"); - DrawTextFont(CD_SYSTEM, size, xoff, 4*yoff, "System"); + DrawTextFont(canvas, "Courier", size, xoff, yoff, "Courier"); + DrawTextFont(canvas, "Times", size, xoff, 2*yoff, "Times Roman"); + DrawTextFont(canvas, "Helvetica", size, xoff, 3*yoff, "Helvetica"); + DrawTextFont(canvas, "System", size, xoff, 4*yoff, "System"); { // static char native[50] = "Tecmedia, -60"; @@ -1094,26 +1221,21 @@ int SimpleDrawTextFonts(void) //cdText(10, 160, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); //cdText(10, 260, "1234567890"); //cdText(500, 360, "'\"!@#$%¨&*()_+-=[]^/;.,"); - - cdFlush(); - return 0; } -//void SimpleDrawTest(void) -void SimpleDrawMainTest(void) +void SimpleDrawTest(cdCanvas* canvas) +//void SimpleDrawMainTest(cdCanvas* canvas) { long pattern[16]; /* 4x4 pattern */ int w, h; int xmin, xmax, ymin, ymax; - simple_draw = DRAW_TEST; - /* notice that if we are not using world coordinates it is harder to position all the objetcs we want. */ - cdGetCanvasSize(&w, &h, 0, 0); + cdCanvasGetSize(canvas, &w, &h, 0, 0); - cdBackground(CD_WHITE); - cdClear(); + cdCanvasBackground(canvas, CD_WHITE); + cdCanvasClear(canvas); /* pattern initialization */ pattern[0] = CD_RED; pattern[1] = CD_RED; /* first line */ @@ -1126,55 +1248,55 @@ void SimpleDrawMainTest(void) pattern[14] = CD_YELLOW; pattern[15] = CD_YELLOW; /* set the line attributes */ - cdLineWidth(4); - cdLineStyle(CD_CONTINUOUS); + cdCanvasLineWidth(canvas, 4); + cdCanvasLineStyle(canvas, CD_CONTINUOUS); /* in the center draw a pattern pizza with a slice mising */ - cdPattern(4, 4, pattern); - cdSector(w/2, h/2, w/2, h/2, 45, 0); + cdCanvasPattern(canvas, 4, 4, pattern); + cdCanvasSector(canvas, w/2, h/2, w/2, h/2, 45, 0); /* draws a dark red border */ - cdForeground(CD_DARK_RED); - cdInteriorStyle(CD_HOLLOW); - cdSector(w/2, h/2, w/2, h/2, 45, 0); + 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 */ - cdForeground(CD_RED); - cdHatch(CD_DIAGCROSS); - cdBegin(CD_FILL); - cdVertex(w/4, h/4); - cdVertex(w/2-w/8, h/2); - cdVertex(w/4, 3*h/4); - cdVertex(w/8, h/2); - cdEnd(); + 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.*/ - cdForeground(CD_BLUE); - cdLine(w/8, h/2, w/4, 3*h/4); - cdLine(w/4, 3*h/4, w/2-w/8, h/2); + 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 */ - cdForeground(cdEncodeColor(100, 25, 200)); - cdLineStyle(CD_DASH_DOT); - cdBegin(CD_BEZIER); - cdVertex(3*w/4-20, h/2-50); - cdVertex(3*w/4+150, 3*h/4-50); - cdVertex(3*w/4-150, 3*h/4-50); - cdVertex(3*w/4+20, h/2-50); - cdEnd(); - - cdFont(CD_HELVETICA, CD_BOLD, 40); - cdTextAlignment(CD_CENTER); - cdText(w/2, h/4-50, "Canvas Draw"); - cdTextBox(w/2, h/4-50, "Canvas Draw", &xmin, &xmax, &ymin, &ymax); - cdRect(xmin, xmax, ymin, ymax); - cdFlush(); + 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); } +#if 0 void draw_wd(void) { char* text; @@ -1214,18 +1336,14 @@ void draw_wd(void) wdVertex(rect[4], rect[5]); wdVertex(rect[6], rect[7]); cdEnd(); - - cdFlush(); } -//void SimpleDrawTest(void) -void SimpleDrawTestHardCopy(void) +//void SimpleDrawTest(cdCanvas* canvas) +void SimpleDrawTestHardCopy(cdCanvas* canvas) { int w, h; cdGetCanvasSize(&w, &h, 0, 0); - simple_draw = DRAW_ALL; - wdViewport(0,w-1,0,h-1); if (w>h) wdWindow(0,(double)w/(double)h,0,1); @@ -1235,19 +1353,16 @@ void SimpleDrawTestHardCopy(void) draw_wd(); //wdHardcopy(CD_CLIPBOARD, "800x600", cdActiveCanvas(), draw_wd ); - //cdFlush(); } -//void SimpleDrawTest(void) -void SimpleDrawTestImageRGB(void) +//void SimpleDrawTest(cdCanvas* canvas) +void SimpleDrawTestImageRGB(cdCanvas* canvas) { int size = 2048*2048; unsigned char *red, *green, *blue; cdCanvas* canvas = cdCreateCanvas(CD_IMAGERGB, "2048x2048"); cdActivate(canvas); - simple_draw = DRAW_TEST; - red = calloc(size, 1); green = calloc(size, 1); blue = calloc(size, 1); @@ -1259,14 +1374,11 @@ void SimpleDrawTestImageRGB(void) free(blue); cdKillCanvas(canvas); - cdFlush(); } -//void SimpleDrawTest(void) -void SimpleDrawVectorFont(void) +//void SimpleDrawTest(cdCanvas* canvas) +void SimpleDrawVectorFont(cdCanvas* canvas) { - simple_draw = DRAW_TEST; - cdBackground(CD_WHITE); cdClear(); cdLineStyle(CD_CONTINUOUS); @@ -1321,26 +1433,35 @@ void SimpleDrawVectorFont(void) // } // } } - cdFlush(); } -void SimpleDrawTest(void) -//void SimpleDrawPoly(void) +//void SimpleDrawTest(cdCanvas* canvas) +void SimpleDrawPoly(cdCanvas* canvas) { int w, h; cdGetCanvasSize(&w, &h, 0, 0); - simple_draw = DRAW_TEST; - cdBackground(CD_WHITE); cdClear(); - cdInteriorStyle(CD_SOLID); - cdBegin(CD_FILL); - cdVertex(w/4, h/4); - cdVertex(w/2-w/8, h/4); - cdVertex(w/2, h/2); - cdVertex(w/2-w/8, h/2); + //cdSetAttribute("ANTIALIAS", "0"); + cdForeground(cdEncodeAlpha(cdEncodeColor(255, 0, 0), 100)); + + cdfCanvasArc(cdActiveCanvas(), 255, 255, 100, 100, 0, 360); + + cdLine(0, 0, 200, 200); + + cdBegin(CD_BEZIER); + cdVertex(100, 100); + cdVertex(150, 200); + cdVertex(180, 250); + cdVertex(180, 200); + cdVertex(180, 150); + cdVertex(150, 100); + cdVertex(300, 100); + cdEnd(); + cdEnd(); } +#endif |