diff options
author | Nicolas "Pixel" Noble <pixel@nobis-crew.org> | 2010-09-09 01:48:52 +0200 |
---|---|---|
committer | Nicolas "Pixel" Noble <pixel@nobis-crew.org> | 2010-09-09 01:50:25 +0200 |
commit | e9a184546b18cf3b796bd560561f312934004c54 (patch) | |
tree | aa785af9a8d03f8ce276c9e9ecec78397005ec22 /cd/src/drv/cdpdf.c | |
parent | 92efe73791d0998536042bfab5a1babc67d168c7 (diff) |
Upgrading to CD 5.4 - and cleaning up.
Diffstat (limited to 'cd/src/drv/cdpdf.c')
-rwxr-xr-x | cd/src/drv/cdpdf.c | 399 |
1 files changed, 287 insertions, 112 deletions
diff --git a/cd/src/drv/cdpdf.c b/cd/src/drv/cdpdf.c index a5d91d4..3211cba 100755 --- a/cd/src/drv/cdpdf.c +++ b/cd/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 */ @@ -139,18 +111,16 @@ static void begin_page(cdCtxCanvas *ctxcanvas) static void init_pdf(cdCtxCanvas *ctxcanvas) { ctxcanvas->scale = 72.0/ctxcanvas->res; + ctxcanvas->canvas->xres = ctxcanvas->res/25.4; + ctxcanvas->canvas->yres = ctxcanvas->canvas->xres; - /* Converte p/ unidades do usuario */ - ctxcanvas->canvas->w = (int)(ctxcanvas->width_pt/ctxcanvas->scale + 0.5); - ctxcanvas->canvas->h = (int)(ctxcanvas->height_pt/ctxcanvas->scale + 0.5); - - /* Passa o valor em milimetros para o canvas CD */ ctxcanvas->canvas->w_mm = ctxcanvas->width_mm; ctxcanvas->canvas->h_mm = ctxcanvas->height_mm; + ctxcanvas->canvas->w = cdRound(ctxcanvas->canvas->xres*ctxcanvas->canvas->w_mm); + ctxcanvas->canvas->h = cdRound(ctxcanvas->canvas->yres*ctxcanvas->canvas->h_mm); + ctxcanvas->canvas->bpp = 24; - ctxcanvas->canvas->xres = ctxcanvas->canvas->w / ctxcanvas->canvas->w_mm; - ctxcanvas->canvas->yres = ctxcanvas->canvas->h / ctxcanvas->canvas->h_mm; begin_page(ctxcanvas); } @@ -166,7 +136,7 @@ static void cdkillcanvas(cdCtxCanvas *ctxcanvas) free(ctxcanvas); } -static void update_fill(cdCtxCanvas *ctxcanvas, int fill) +static void sUpdateFill(cdCtxCanvas *ctxcanvas, int fill) { if (fill == 0) { @@ -311,7 +281,7 @@ static int cdclip(cdCtxCanvas *ctxcanvas, int mode) static void cdfline(cdCtxCanvas *ctxcanvas, double x1, double y1, double x2, double y2) { - update_fill(ctxcanvas, 0); + sUpdateFill(ctxcanvas, 0); PDF_moveto(ctxcanvas->pdf, x1, y1); PDF_lineto(ctxcanvas->pdf, x2, y2); @@ -325,7 +295,7 @@ static void cdline(cdCtxCanvas *ctxcanvas, int x1, int y1, int x2, int y2) static void cdfrect(cdCtxCanvas *ctxcanvas, double xmin, double xmax, double ymin, double ymax) { - update_fill(ctxcanvas, 0); + sUpdateFill(ctxcanvas, 0); PDF_rect(ctxcanvas->pdf, xmin, ymin, xmax-xmin, ymax-ymin); PDF_stroke(ctxcanvas->pdf); @@ -338,7 +308,7 @@ static void cdrect(cdCtxCanvas *ctxcanvas, int xmin, int xmax, int ymin, int yma static void cdfbox(cdCtxCanvas *ctxcanvas, double xmin, double xmax, double ymin, double ymax) { - update_fill(ctxcanvas, 1); + sUpdateFill(ctxcanvas, 1); PDF_moveto(ctxcanvas->pdf, xmin, ymin); PDF_lineto(ctxcanvas->pdf, xmax, ymin); @@ -354,14 +324,16 @@ static void cdbox(cdCtxCanvas *ctxcanvas, int xmin, int xmax, int ymin, int ymax static void cdfarc(cdCtxCanvas *ctxcanvas, double xc, double yc, double w, double h, double a1, double a2) { - update_fill(ctxcanvas, 0); + sUpdateFill(ctxcanvas, 0); + + /* angles in degrees counterclockwise, same as CD */ if (w==h) { 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 */ @@ -383,12 +355,12 @@ static void cdarc(cdCtxCanvas *ctxcanvas, int xc, int yc, int w, int h, double a static void cdfsector(cdCtxCanvas *ctxcanvas, double xc, double yc, double w, double h, double a1, double a2) { - update_fill(ctxcanvas, 1); + sUpdateFill(ctxcanvas, 1); if (w==h) { PDF_moveto(ctxcanvas->pdf, xc, yc); - PDF_arc(ctxcanvas->pdf, xc, yc, 0.5*w, a1, a2); + PDF_arc(ctxcanvas->pdf, xc, yc, 0.5*h, a1, a2); PDF_fill(ctxcanvas->pdf); } else /* Elipse: mudar a escala p/ criar a partir do circulo */ @@ -401,15 +373,7 @@ static void cdfsector(cdCtxCanvas *ctxcanvas, double xc, double yc, double w, do PDF_moveto(ctxcanvas->pdf, xc, yc); PDF_arc(ctxcanvas->pdf, xc, yc, 0.5*h, a1, a2); - - if (ctxcanvas->canvas->interior_style == CD_SOLID || - ctxcanvas->canvas->interior_style == CD_PATTERN) - PDF_fill(ctxcanvas->pdf); - else - { - PDF_lineto(ctxcanvas->pdf, xc, yc); - PDF_stroke(ctxcanvas->pdf); - } + PDF_fill(ctxcanvas->pdf); PDF_restore(ctxcanvas->pdf); /* restore from local */ } @@ -422,12 +386,12 @@ static void cdsector(cdCtxCanvas *ctxcanvas, int xc, int yc, int w, int h, doubl static void cdfchord(cdCtxCanvas *ctxcanvas, double xc, double yc, double w, double h, double a1, double a2) { - update_fill(ctxcanvas, 1); + sUpdateFill(ctxcanvas, 1); if (w==h) { - PDF_arc(ctxcanvas->pdf, xc, yc, 0.5*w, a1, a2); - PDF_fill_stroke(ctxcanvas->pdf); + PDF_arc(ctxcanvas->pdf, xc, yc, 0.5*h, a1, a2); + PDF_fill(ctxcanvas->pdf); } else /* Elipse: mudar a escala p/ criar a partir do circulo */ { @@ -435,10 +399,11 @@ static void cdfchord(cdCtxCanvas *ctxcanvas, double xc, double yc, double w, dou /* local transform */ PDF_translate(ctxcanvas->pdf, xc, yc); - PDF_scale(ctxcanvas->pdf, 1, w/h); + PDF_scale(ctxcanvas->pdf, w/h, 1); + PDF_translate(ctxcanvas->pdf, -xc, -yc); - PDF_arc(ctxcanvas->pdf, xc, yc, 0.5*w, a1, a2); - PDF_fill_stroke(ctxcanvas->pdf); + PDF_arc(ctxcanvas->pdf, xc, yc, 0.5*h, a1, a2); + PDF_fill(ctxcanvas->pdf); PDF_restore(ctxcanvas->pdf); /* restore from local */ } @@ -487,8 +452,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, ""); @@ -572,13 +537,121 @@ static void cdpoly(cdCtxCanvas *ctxcanvas, int mode, cdPoint* poly, int n) if (mode == CD_CLIP) return; + if (mode == CD_PATH) + { + int p, fill = 0; + + /* if there is any current path, remove it */ + /* Don't use PDF_endpath because here usually there will be no path scope */ + + for (p=0; p<ctxcanvas->canvas->path_n; p++) + { + if (ctxcanvas->canvas->path[p] == CD_PATH_FILL || + ctxcanvas->canvas->path[p] == CD_PATH_FILLSTROKE) + { + fill = 1; + break; + } + } + + /* must be set before starting path scope */ + sUpdateFill(ctxcanvas, 0); /* set always */ + if (fill) + { + PDF_set_parameter(ctxcanvas->pdf, "fillrule", ctxcanvas->canvas->fill_mode==CD_EVENODD? "evenodd": "winding"); + sUpdateFill(ctxcanvas, fill); + } + + i = 0; + for (p=0; p<ctxcanvas->canvas->path_n; p++) + { + switch(ctxcanvas->canvas->path[p]) + { + case CD_PATH_NEW: + /* Don't use PDF_endpath because here usually there will be no path scope */ + break; + case CD_PATH_MOVETO: + if (i+1 > n) return; + PDF_moveto(ctxcanvas->pdf, poly[i].x, poly[i].y); + i++; + break; + case CD_PATH_LINETO: + if (i+1 > n) return; + PDF_lineto(ctxcanvas->pdf, poly[i].x, poly[i].y); + i++; + break; + case CD_PATH_ARC: + { + double xc, yc, w, h, a1, a2; + + if (i+3 > n) return; + + if (!cdCanvasGetArcPathF(ctxcanvas->canvas, poly+i, &xc, &yc, &w, &h, &a1, &a2)) + return; + + if (w==h) + { + if ((a2-a1)<0) + PDF_arcn(ctxcanvas->pdf, xc, yc, 0.5*w, a1, a2); + else + PDF_arc(ctxcanvas->pdf, xc, yc, 0.5*w, a1, a2); + } + else /* Ellipse: change the scale to create from the circle */ + { + /* NOT SUPPORTED IN PATH SCOPE!!!! + PDF_save(ctxcanvas->pdf); + + PDF_translate(ctxcanvas->pdf, xc, yc); + PDF_scale(ctxcanvas->pdf, w/h, 1); + PDF_translate(ctxcanvas->pdf, -xc, -yc); */ + double s = h; + if (w > h) + s = w; + + if ((a2-a1)<0) + PDF_arcn(ctxcanvas->pdf, xc, yc, 0.5*s, a1, a2); + else + PDF_arc(ctxcanvas->pdf, xc, yc, 0.5*s, a1, a2); + + /* PDF_restore(ctxcanvas->pdf); */ + } + + i += 3; + } + break; + case CD_PATH_CURVETO: + if (i+3 > n) return; + PDF_curveto(ctxcanvas->pdf, poly[i].x, poly[i].y, poly[i+1].x, poly[i+1].y, poly[i+2].x, poly[i+2].y); + i += 3; + break; + case CD_PATH_CLOSE: + PDF_closepath(ctxcanvas->pdf); + break; + case CD_PATH_FILL: + PDF_fill(ctxcanvas->pdf); + break; + case CD_PATH_STROKE: + PDF_stroke(ctxcanvas->pdf); + break; + case CD_PATH_FILLSTROKE: + PDF_fill_stroke(ctxcanvas->pdf); + break; + case CD_PATH_CLIP: + PDF_clip(ctxcanvas->pdf); + break; + } + } + return; + } + if (mode == CD_FILL) - update_fill(ctxcanvas, 1); + sUpdateFill(ctxcanvas, 1); else - update_fill(ctxcanvas, 0); + sUpdateFill(ctxcanvas, 0); if (mode==CD_FILL) { + /* must be set before starting path scope */ if (ctxcanvas->holes || ctxcanvas->canvas->fill_mode==CD_EVENODD) PDF_set_parameter(ctxcanvas->pdf, "fillrule", "evenodd"); else @@ -634,13 +707,121 @@ static void cdfpoly(cdCtxCanvas *ctxcanvas, int mode, cdfPoint* poly, int n) if (mode == CD_CLIP) return; + if (mode == CD_PATH) + { + int p, fill = 0; + + /* if there is any current path, remove it */ + /* Don't use PDF_endpath because here usually there will be no path scope */ + + for (p=0; p<ctxcanvas->canvas->path_n; p++) + { + if (ctxcanvas->canvas->path[p] == CD_PATH_FILL || + ctxcanvas->canvas->path[p] == CD_PATH_FILLSTROKE) + { + fill = 1; + break; + } + } + + /* must be set before starting path scope */ + sUpdateFill(ctxcanvas, 0); /* set always */ + if (fill) + { + PDF_set_parameter(ctxcanvas->pdf, "fillrule", ctxcanvas->canvas->fill_mode==CD_EVENODD? "evenodd": "winding"); + sUpdateFill(ctxcanvas, fill); + } + + i = 0; + for (p=0; p<ctxcanvas->canvas->path_n; p++) + { + switch(ctxcanvas->canvas->path[p]) + { + case CD_PATH_NEW: + /* Don't use PDF_endpath because here usually there will be no path scope */ + break; + case CD_PATH_MOVETO: + if (i+1 > n) return; + PDF_moveto(ctxcanvas->pdf, poly[i].x, poly[i].y); + i++; + break; + case CD_PATH_LINETO: + if (i+1 > n) return; + PDF_lineto(ctxcanvas->pdf, poly[i].x, poly[i].y); + i++; + break; + case CD_PATH_ARC: + { + double xc, yc, w, h, a1, a2; + + if (i+3 > n) return; + + if (!cdfCanvasGetArcPath(ctxcanvas->canvas, poly+i, &xc, &yc, &w, &h, &a1, &a2)) + return; + + if (w==h) + { + if ((a2-a1)<0) + PDF_arcn(ctxcanvas->pdf, xc, yc, 0.5*w, a1, a2); + else + PDF_arc(ctxcanvas->pdf, xc, yc, 0.5*w, a1, a2); + } + else /* Ellipse: change the scale to create from the circle */ + { + /* NOT SUPPORTED IN PATH SCOPE!!!! + PDF_save(ctxcanvas->pdf); + + PDF_translate(ctxcanvas->pdf, xc, yc); + PDF_scale(ctxcanvas->pdf, w/h, 1); + PDF_translate(ctxcanvas->pdf, -xc, -yc); */ + double s = h; + if (w > h) + s = w; + + if ((a2-a1)<0) + PDF_arcn(ctxcanvas->pdf, xc, yc, 0.5*s, a1, a2); + else + PDF_arc(ctxcanvas->pdf, xc, yc, 0.5*s, a1, a2); + + /* PDF_restore(ctxcanvas->pdf); */ + } + + i += 3; + } + break; + case CD_PATH_CURVETO: + if (i+3 > n) return; + PDF_curveto(ctxcanvas->pdf, poly[i].x, poly[i].y, poly[i+1].x, poly[i+1].y, poly[i+2].x, poly[i+2].y); + i += 3; + break; + case CD_PATH_CLOSE: + PDF_closepath(ctxcanvas->pdf); + break; + case CD_PATH_FILL: + PDF_fill(ctxcanvas->pdf); + break; + case CD_PATH_STROKE: + PDF_stroke(ctxcanvas->pdf); + break; + case CD_PATH_FILLSTROKE: + PDF_fill_stroke(ctxcanvas->pdf); + break; + case CD_PATH_CLIP: + PDF_clip(ctxcanvas->pdf); + break; + } + } + return; + } + if (mode == CD_FILL) - update_fill(ctxcanvas, 1); + sUpdateFill(ctxcanvas, 1); else - update_fill(ctxcanvas, 0); + sUpdateFill(ctxcanvas, 0); if (mode==CD_FILL) { + /* must be set before starting path scope */ if (ctxcanvas->holes || ctxcanvas->canvas->fill_mode==CD_EVENODD) PDF_set_parameter(ctxcanvas->pdf, "fillrule", "evenodd"); else @@ -695,8 +876,8 @@ static void cdfpoly(cdCtxCanvas *ctxcanvas, int mode, cdfPoint* poly, int n) static int cdlinestyle(cdCtxCanvas *ctxcanvas, int style) { - double mm = (72.0/25.4) / ctxcanvas->scale; - char options[80]; + double mm = ctxcanvas->canvas->xres; + char options[200]; switch (style) { @@ -720,12 +901,12 @@ static int cdlinestyle(cdCtxCanvas *ctxcanvas, int style) case CD_CUSTOM : { int i; - + /* size here is in pixels, do not use mm */ strcpy(options, "dasharray={"); for (i = 0; i < ctxcanvas->canvas->line_dashes_count; i++) { char tmp[80]; - sprintf(tmp, "%g ", ctxcanvas->canvas->line_dashes[i]*mm); + sprintf(tmp, "%g ", (double)ctxcanvas->canvas->line_dashes[i]); strcat(options, tmp); } strcat(options, "}"); @@ -768,7 +949,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 +982,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 +1001,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, hsize, ((double)hsize)*ctxcanvas->scale, ((double)hsize)*ctxcanvas->scale, 1); PDF_scale(ctxcanvas->pdf, ctxcanvas->scale, ctxcanvas->scale); @@ -883,11 +1060,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 +1148,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. */ @@ -1000,7 +1173,7 @@ static void cdtransform(cdCtxCanvas *ctxcanvas, const double* matrix) static void cdputimagerectrgb(cdCtxCanvas *ctxcanvas, int iw, int ih, const unsigned char *r, const unsigned char *g, const unsigned char *b, int x, int y, int w, int h, int xmin, int xmax, int ymin, int ymax) { - int i, j, d, image, rw, rh, rgb_size; + int i, j, d, image, rw, rh, rgb_size, pos; char options[80]; unsigned char* rgb_data; @@ -1017,9 +1190,10 @@ static void cdputimagerectrgb(cdCtxCanvas *ctxcanvas, int iw, int ih, const unsi for (i=ymax; i>=ymin; i--) for (j=xmin; j<=xmax; j++) { - rgb_data[d] = r[i*iw+j]; d++; - rgb_data[d] = g[i*iw+j]; d++; - rgb_data[d] = b[i*iw+j]; d++; + pos = i*iw+j; + rgb_data[d] = r[pos]; d++; + rgb_data[d] = g[pos]; d++; + rgb_data[d] = b[pos]; d++; } PDF_create_pvf(ctxcanvas->pdf, "cd_raw_rgb", 0, rgb_data, rgb_size, ""); @@ -1036,7 +1210,7 @@ static void cdputimagerectrgb(cdCtxCanvas *ctxcanvas, int iw, int ih, const unsi static void cdputimagerectrgba(cdCtxCanvas *ctxcanvas, int iw, int ih, const unsigned char *r, const unsigned char *g, const unsigned char *b, const unsigned char *a, int x, int y, int w, int h, int xmin, int xmax, int ymin, int ymax) { - int i, j, d, image, image_mask, rw, rh, alpha_size, rgb_size; + int i, j, d, image, image_mask, rw, rh, alpha_size, rgb_size, pos; char options[80]; unsigned char *rgb_data, *alpha_data; @@ -1053,9 +1227,10 @@ static void cdputimagerectrgba(cdCtxCanvas *ctxcanvas, int iw, int ih, const uns for (i=ymax; i>=ymin; i--) for (j=xmin; j<=xmax; j++) { - rgb_data[d] = r[i*iw+j]; d++; - rgb_data[d] = g[i*iw+j]; d++; - rgb_data[d] = b[i*iw+j]; d++; + pos = i*iw+j; + rgb_data[d] = r[pos]; d++; + rgb_data[d] = g[pos]; d++; + rgb_data[d] = b[pos]; d++; } alpha_size = rw*rh; @@ -1066,7 +1241,8 @@ static void cdputimagerectrgba(cdCtxCanvas *ctxcanvas, int iw, int ih, const uns for (i=ymax; i>=ymin; i--) for (j=xmin; j<=xmax; j++) { - alpha_data[d] = a[i*iw+j]; d++; + pos = i*iw+j; + alpha_data[d] = a[pos]; d++; } PDF_create_pvf(ctxcanvas->pdf, "cd_raw_rgb", 0, rgb_data, rgb_size, ""); @@ -1089,9 +1265,10 @@ static void cdputimagerectrgba(cdCtxCanvas *ctxcanvas, int iw, int ih, const uns static void cdputimagerectmap(cdCtxCanvas *ctxcanvas, int iw, int ih, const unsigned char *index, const long int *colors, int x, int y, int w, int h, int xmin, int xmax, int ymin, int ymax) { - int i, j, d, rw, rh, image, rgb_size; + int i, j, d, rw, rh, image, rgb_size, pos; char options[80]; unsigned char* rgb_data; + unsigned char r, g, b; if (xmin<0 || ymin<0 || xmax-xmin+1>iw || ymax-ymin+1>ih) return; @@ -1106,8 +1283,8 @@ static void cdputimagerectmap(cdCtxCanvas *ctxcanvas, int iw, int ih, const unsi for (i=ymax; i>=ymin; i--) for (j=xmin; j<=xmax; j++) { - unsigned char r, g, b; - cdDecodeColor(colors[index[i*iw+j]], &r, &g, &b); + pos = i*iw+j; + cdDecodeColor(colors[index[pos]], &r, &g, &b); rgb_data[d] = r; d++; rgb_data[d] = g; d++; rgb_data[d] = b; d++; @@ -1202,7 +1379,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 +1397,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 +1639,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': @@ -1501,7 +1673,7 @@ static void cdcreatecanvas(cdCanvas* canvas, void *data) /* update canvas context */ canvas->ctxcanvas = ctxcanvas; - if (ctxcanvas->landscape == 1) + if (ctxcanvas->landscape) { _cdSwapDouble(ctxcanvas->width_pt, ctxcanvas->height_pt); _cdSwapDouble(ctxcanvas->width_mm, ctxcanvas->height_mm); @@ -1513,7 +1685,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 +1696,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 +1705,7 @@ static void cdinittable(cdCanvas* canvas) canvas->cxFSector = cdfsector; canvas->cxFChord = cdfchord; canvas->cxFText = cdftext; + canvas->cxGetFontDim = cdgetfontdim; canvas->cxGetTextSize = cdgettextsize; canvas->cxPutImageRectRGB = cdputimagerectrgb; @@ -1556,8 +1732,7 @@ static cdContext cdPDFContext = { CD_CAP_ALL & ~(CD_CAP_CLEAR | CD_CAP_PLAY | CD_CAP_PALETTE | CD_CAP_REGION | CD_CAP_IMAGESRV | CD_CAP_TEXTSIZE | - CD_CAP_BACKGROUND | CD_CAP_BACKOPACITY | CD_CAP_WRITEMODE | - CD_CAP_GETIMAGERGB), + CD_CAP_WRITEMODE | CD_CAP_GETIMAGERGB), 0, cdcreatecanvas, cdinittable, |