diff options
Diffstat (limited to 'src/drv')
-rw-r--r-- | src/drv/cddebug.c | 7 | ||||
-rw-r--r-- | src/drv/cdirgb.c | 1 | ||||
-rw-r--r-- | src/drv/cdpdf.c | 83 | ||||
-rw-r--r-- | src/drv/cdps.c | 47 |
4 files changed, 30 insertions, 108 deletions
diff --git a/src/drv/cddebug.c b/src/drv/cddebug.c index 23d8446..0c5fd0d 100644 --- a/src/drv/cddebug.c +++ b/src/drv/cddebug.c @@ -68,7 +68,6 @@ struct _cdCtxCanvas { cdCanvas* canvas; - char* filename; FILE* file; int last_line_style; int last_fill_mode; @@ -601,7 +600,6 @@ static void cdgettextsize(cdCtxCanvas* ctxcanvas, const char *s, int len, int *w static void cdkillcanvas(cdCtxCanvas *ctxcanvas) { fprintf(ctxcanvas->file, "KillCanvas()\n"); - free(ctxcanvas->filename); fclose(ctxcanvas->file); memset(ctxcanvas, 0, sizeof(cdCtxCanvas)); free(ctxcanvas); @@ -613,7 +611,6 @@ static void cdcreatecanvas(cdCanvas *canvas, void *data) char* strdata = (char*)data; double w_mm = INT_MAX*3.78, h_mm = INT_MAX*3.78, res = 3.78; cdCtxCanvas* ctxcanvas; - int size; strdata += cdGetFileName(strdata, filename); if (filename[0] == 0) @@ -631,10 +628,6 @@ static void cdcreatecanvas(cdCanvas *canvas, void *data) return; } - size = strlen(filename); - ctxcanvas->filename = malloc(size+1); - memcpy(ctxcanvas->filename, filename, size+1); - ctxcanvas->canvas = canvas; /* update canvas context */ diff --git a/src/drv/cdirgb.c b/src/drv/cdirgb.c index 8baef1e..8135fa1 100644 --- a/src/drv/cdirgb.c +++ b/src/drv/cdirgb.c @@ -1781,6 +1781,7 @@ static void set_rotate_attrib(cdCtxCanvas* ctxcanvas, char* data) { if (data) { + /* use this configuration when there is NO native tranformation support */ sscanf(data, "%g %d %d", &ctxcanvas->rotate_angle, &ctxcanvas->rotate_center_x, &ctxcanvas->rotate_center_y); diff --git a/src/drv/cdpdf.c b/src/drv/cdpdf.c index a5d91d4..6a20748 100644 --- a/src/drv/cdpdf.c +++ b/src/drv/cdpdf.c @@ -56,36 +56,6 @@ struct _cdCtxCanvas /* -%F Ajusta o tamanho do papel em points. -*/ -static void setpdfpapersize(cdCtxCanvas* ctxcanvas, int size) -{ - static struct - { - int width; - int height; - } paper[] = - { - { 2393, 3391 }, /* A0 */ - { 1689, 2393 }, /* A1 */ - { 1192, 1689 }, /* A2 */ - { 842, 1192 }, /* A3 */ - { 595, 842 }, /* A4 */ - { 420, 595 }, /* A5 */ - { 612, 792 }, /* LETTER */ - { 612, 1008 } /* LEGAL */ - }; - - if (size<CD_A0 || size>CD_LEGAL) - return; - - ctxcanvas->width_pt = paper[size].width; - ctxcanvas->height_pt = paper[size].height; - ctxcanvas->width_mm = ctxcanvas->width_pt/CD_MM2PT; - ctxcanvas->height_mm = ctxcanvas->height_pt/CD_MM2PT; -} - -/* %F Registra os valores default para impressao. */ static void setpdfdefaultvalues(cdCtxCanvas* ctxcanvas) @@ -93,7 +63,9 @@ static void setpdfdefaultvalues(cdCtxCanvas* ctxcanvas) int i; /* all the other values are set to 0 */ - setpdfpapersize(ctxcanvas, CD_A4); + cdSetPaperSize(CD_A4, &ctxcanvas->width_pt, &ctxcanvas->height_pt); + ctxcanvas->width_mm = ctxcanvas->width_pt/CD_MM2PT; + ctxcanvas->height_mm = ctxcanvas->height_pt/CD_MM2PT; ctxcanvas->res = 300; ctxcanvas->hatchboxsize = 8; ctxcanvas->opacity = 255; /* full opaque */ @@ -361,7 +333,7 @@ static void cdfarc(cdCtxCanvas *ctxcanvas, double xc, double yc, double w, doubl PDF_arc(ctxcanvas->pdf, xc, yc, 0.5*w, a1, a2); PDF_stroke(ctxcanvas->pdf); } - else /* Elipse: mudar a escala p/ criar a partir do circulo */ + else /* Ellipse: change the scale to create from the circle */ { PDF_save(ctxcanvas->pdf); /* save to use the local transform */ @@ -487,8 +459,8 @@ static void cdftext(cdCtxCanvas *ctxcanvas, double x, double y, const char *s, i char temp[200], options[200]; PDF_setcolor(ctxcanvas->pdf, "fill", "rgb", get_red(ctxcanvas->canvas->foreground), - get_green(ctxcanvas->canvas->foreground), - get_blue(ctxcanvas->canvas->foreground), 0); + get_green(ctxcanvas->canvas->foreground), + get_blue(ctxcanvas->canvas->foreground), 0); strcpy(options, ""); @@ -768,7 +740,6 @@ static void make_pattern(cdCtxCanvas *ctxcanvas, int n, int m, void* data, int ( PDF_suspend_page(ctxcanvas->pdf, ""); ctxcanvas->pattern = PDF_begin_pattern(ctxcanvas->pdf, n, m, ((double)n)*ctxcanvas->scale, ((double)m)*ctxcanvas->scale, 1); - PDF_scale(ctxcanvas->pdf, ctxcanvas->scale, ctxcanvas->scale); for (j=0; j<m; j++) @@ -802,21 +773,18 @@ static void cdpattern(cdCtxCanvas *ctxcanvas, int n, int m, const long int *patt static int uchar2rgb(cdCtxCanvas *ctxcanvas, int n, int i, int j, void* data, unsigned char*r, unsigned char*g, unsigned char*b) { - int ret = 1; unsigned char* uchar_data = (unsigned char*)data; if (uchar_data[j*n+i]) - { cdDecodeColor(ctxcanvas->canvas->foreground, r, g, b); - ret = 1; - } else { - cdDecodeColor(ctxcanvas->canvas->background, r, g, b); if (ctxcanvas->canvas->back_opacity==CD_TRANSPARENT) - ret = -1; + return -1; + else + cdDecodeColor(ctxcanvas->canvas->background, r, g, b); } - return ret; + return 1; } static void cdstipple(cdCtxCanvas *ctxcanvas, int n, int m, const unsigned char *stipple) @@ -824,14 +792,14 @@ static void cdstipple(cdCtxCanvas *ctxcanvas, int n, int m, const unsigned char make_pattern(ctxcanvas, n, m, (void*)stipple, uchar2rgb); } -static void make_hatch(cdCtxCanvas *ctxcanvas, int style) +static int cdhatch(cdCtxCanvas *ctxcanvas, int style) { unsigned char r, g, b; int hsize = ctxcanvas->hatchboxsize - 1; int hhalf = hsize / 2; PDF_suspend_page(ctxcanvas->pdf, ""); - ctxcanvas->pattern = PDF_begin_pattern(ctxcanvas->pdf, hsize + 1, hsize + 1, + ctxcanvas->pattern = PDF_begin_pattern(ctxcanvas->pdf, hsize+1, hsize+1, ((double)hsize)*ctxcanvas->scale, ((double)hsize)*ctxcanvas->scale, 1); PDF_scale(ctxcanvas->pdf, ctxcanvas->scale, ctxcanvas->scale); @@ -883,11 +851,6 @@ static void make_hatch(cdCtxCanvas *ctxcanvas, int style) PDF_end_pattern(ctxcanvas->pdf); PDF_resume_page(ctxcanvas->pdf, ""); -} - -static int cdhatch(cdCtxCanvas *ctxcanvas, int style) -{ - make_hatch(ctxcanvas, style); return style; } @@ -976,6 +939,7 @@ static int cdfont(cdCtxCanvas *ctxcanvas, const char *type_face, int style, int static void cdtransform(cdCtxCanvas *ctxcanvas, const double* matrix) { + /* reset to identity */ PDF_setmatrix(ctxcanvas->pdf, 1, 0, 0, 1, 0, 0); /* default coordinate system is in points, change it to pixels. */ @@ -1202,7 +1166,8 @@ static cdAttribute hatchboxsize_attrib = static void set_rotate_attrib(cdCtxCanvas *ctxcanvas, char* data) { - /* ignore ROTATE if transform is set */ + /* ignore ROTATE if transform is set, + because there is native support for transformations */ if (ctxcanvas->canvas->use_matrix) return; @@ -1219,15 +1184,7 @@ static void set_rotate_attrib(cdCtxCanvas *ctxcanvas, char* data) ctxcanvas->rotate_center_y = 0; } - PDF_setmatrix(ctxcanvas->pdf, 1, 0, 0, 1, 0, 0); - - if (ctxcanvas->rotate_angle) - { - /* rotation = translate to point + rotation + translate back */ - PDF_translate(ctxcanvas->pdf, ctxcanvas->rotate_center_x, ctxcanvas->rotate_center_y); - PDF_rotate(ctxcanvas->pdf, (double)ctxcanvas->rotate_angle); - PDF_translate(ctxcanvas->pdf, -ctxcanvas->rotate_center_x, -ctxcanvas->rotate_center_y); - } + cdtransform(ctxcanvas, NULL); } static char* get_rotate_attrib(cdCtxCanvas *ctxcanvas) @@ -1469,7 +1426,9 @@ static void cdcreatecanvas(cdCanvas* canvas, void *data) { int paper; sscanf(line, "%d", &paper); - setpdfpapersize(ctxcanvas, paper); + cdSetPaperSize(paper, &ctxcanvas->width_pt, &ctxcanvas->height_pt); + ctxcanvas->width_mm = ctxcanvas->width_pt/CD_MM2PT; + ctxcanvas->height_mm = ctxcanvas->height_pt/CD_MM2PT; break; } case 'w': @@ -1513,7 +1472,9 @@ static void cdcreatecanvas(cdCanvas* canvas, void *data) static void cdinittable(cdCanvas* canvas) { canvas->cxFlush = cdflush; + canvas->cxPixel = cdpixel; + canvas->cxLine = cdline; canvas->cxPoly = cdpoly; canvas->cxRect = cdrect; @@ -1522,6 +1483,7 @@ static void cdinittable(cdCanvas* canvas) canvas->cxSector = cdsector; canvas->cxChord = cdchord; canvas->cxText = cdtext; + canvas->cxFLine = cdfline; canvas->cxFPoly = cdfpoly; canvas->cxFRect = cdfrect; @@ -1530,6 +1492,7 @@ static void cdinittable(cdCanvas* canvas) canvas->cxFSector = cdfsector; canvas->cxFChord = cdfchord; canvas->cxFText = cdftext; + canvas->cxGetFontDim = cdgetfontdim; canvas->cxGetTextSize = cdgettextsize; canvas->cxPutImageRectRGB = cdputimagerectrgb; diff --git a/src/drv/cdps.c b/src/drv/cdps.c index ef77c4d..c54c95a 100644 --- a/src/drv/cdps.c +++ b/src/drv/cdps.c @@ -76,42 +76,13 @@ struct _cdCtxCanvas }; - -/* -%F Ajusta o tamanho do papel em points. -*/ -static void setpspapersize(cdCtxCanvas *ctxcanvas, int size) -{ - static struct - { - int width; - int height; - } paper[] = - { - { 2393, 3391 }, /* A0 */ - { 1689, 2393 }, /* A1 */ - { 1192, 1689 }, /* A2 */ - { 842, 1192 }, /* A3 */ - { 595, 842 }, /* A4 */ - { 420, 595 }, /* A5 */ - { 612, 792 }, /* LETTER */ - { 612, 1008 } /* LEGAL */ - }; - - if (size<CD_A0 || size>CD_LEGAL) - return; - - ctxcanvas->width = (double)paper[size].width; - ctxcanvas->height = (double)paper[size].height; -} - /* %F Registra os valores default para impressao. */ static void setpsdefaultvalues(cdCtxCanvas *ctxcanvas) { /* all the other values are set to 0 */ - setpspapersize(ctxcanvas, CD_A4); + cdSetPaperSize(CD_A4, &ctxcanvas->width, &ctxcanvas->height); ctxcanvas->xmin = 25.4; /* ainda em mm, sera' convertido para points na init_ps */ ctxcanvas->xmax = 25.4; ctxcanvas->ymin = 25.4; @@ -1379,6 +1350,7 @@ static int cdfont(cdCtxCanvas *ctxcanvas, const char *type_face, int style, int static void cdtransform(cdCtxCanvas *ctxcanvas, const double* matrix) { + /* reset to identity */ set_default_matrix(ctxcanvas); if (matrix) @@ -1568,7 +1540,8 @@ static void cdpixel(cdCtxCanvas *ctxcanvas, int x, int y, long int color) static void set_rotate_attrib(cdCtxCanvas *ctxcanvas, char* data) { - /* ignore ROTATE if transform is set */ + /* ignore ROTATE if transform is set, + because there is native support for transformations */ if (ctxcanvas->canvas->use_matrix) return; @@ -1585,15 +1558,7 @@ static void set_rotate_attrib(cdCtxCanvas *ctxcanvas, char* data) ctxcanvas->rotate_center_y = 0; } - set_default_matrix(ctxcanvas); - - if (ctxcanvas->rotate_angle) - { - /* rotation = translate to point + rotation + translate back */ - fprintf(ctxcanvas->file, "%d %d translate\n", ctxcanvas->rotate_center_x, ctxcanvas->rotate_center_y); - fprintf(ctxcanvas->file, "%g rotate\n", (double)ctxcanvas->rotate_angle); - fprintf(ctxcanvas->file, "%d %d translate\n", -ctxcanvas->rotate_center_x, -ctxcanvas->rotate_center_y); - } + cdtransform(ctxcanvas, NULL); } static char* get_rotate_attrib(cdCtxCanvas *ctxcanvas) @@ -1715,7 +1680,7 @@ static void cdcreatecanvas(cdCanvas* canvas, void *data) { int paper; sscanf(line, "%d", &paper); - setpspapersize(ctxcanvas, paper); + cdSetPaperSize(paper, &ctxcanvas->width, &ctxcanvas->height); break; } case 'w': |