From 483f59d3a55720c8c140aef863f4d34a0d90cca8 Mon Sep 17 00:00:00 2001
From: scuri
"filename [widthxheight resolution]" or in C use "%s %gx%g %g"+
"filename [widthxheight] [resolution]" or in C use "%s %gx%g %g"
Only the parameter filename is required. The filename must be inside double quotes (") if it has spaces. Width and height are provided in millimeters diff --git a/html/en/drv/svg.html b/html/en/drv/svg.html index 31a5f4a..7f242d5 100644 --- a/html/en/drv/svg.html +++ b/html/en/drv/svg.html @@ -25,7 +25,7 @@ Data). The Data parameter is a string that must contain the filename and the canvas dimensions, in the following format:
-"filename [widthxheight resolution]" or in C "%s %gx%g %g"+
"filename [widthxheight] [resolution]" or in C "%s %gx%g %g"
Only the parameter filename is required. The filename must be inside double quotes (")
if it has spaces. Width and height are provided in millimeters
diff --git a/include/cd_private.h b/include/cd_private.h
index 1410126..e6adef5 100644
--- a/include/cd_private.h
+++ b/include/cd_private.h
@@ -360,6 +360,7 @@ void cdSimGetTextSizeFT(cdCtxCanvas* ctxcanvas, const char *s, int len, int *wid
/* Simulation functions that are >> independent << of the simulation base driver. */
void cdSimMark(cdCanvas* canvas, int x, int y);
void cdSimPutImageRectRGBA(cdCanvas* canvas, 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);
+void cdSimPutImageRectRGB(cdCanvas* canvas, 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);
/* Simulation functions that are >> independent << of the simulation base driver.
All use the polygon method ->cxPoly only. */
diff --git a/src/cd_image.c b/src/cd_image.c
index 002d288..df79af6 100644
--- a/src/cd_image.c
+++ b/src/cd_image.c
@@ -86,26 +86,9 @@ void cdCanvasPutImageRectRGB(cdCanvas* canvas, int iw, int ih, const unsigned ch
if (canvas->invert_yaxis)
y = _cdInvertYAxis(canvas, y);
- if (canvas->bpp <= 8)
- {
- int height = ymax-ymin+1;
- unsigned char* map = (unsigned char*)malloc(iw * height);
- int pal_size = 1L << canvas->bpp;
- long colors[256];
-
- if (!map)
- return;
-
- if (pal_size == 2) /* probably a laser printer, use a gray image for better results */
- cdRGB2Gray(iw, height, r+ymin*iw, g+ymin*iw, b+ymin*iw, map, colors);
- else
- cdRGB2Map(iw, height, r+ymin*iw, g+ymin*iw, b+ymin*iw, map, pal_size, colors);
-
- canvas->cxPutImageRectMap(canvas->ctxcanvas, iw, height, map, colors, x, y, w, h, xmin, xmax, 0, height-1);
-
- free(map);
- }
- else
+ if (canvas->cxPutImageRectMap && (canvas->bpp <= 8 || !canvas->cxPutImageRectRGB))
+ cdSimPutImageRectRGB(canvas, iw, ih, r, g, b, x, y, w, h, xmin, xmax, ymin, ymax);
+ else if (canvas->cxPutImageRectRGB)
canvas->cxPutImageRectRGB(canvas->ctxcanvas, iw, ih, r, g, b, x, y, w, h, xmin, xmax, ymin, ymax);
}
@@ -142,6 +125,11 @@ void cdCanvasPutImageRectRGBA(cdCanvas* canvas, int iw, int ih, const unsigned c
{
if (canvas->cxGetImageRGB)
cdSimPutImageRectRGBA(canvas, iw, ih, r, g, b, a, x, y, w, h, xmin, xmax, ymin, ymax);
+ else if (!canvas->cxPutImageRectRGB)
+ {
+ if (canvas->cxPutImageRectMap)
+ cdSimPutImageRectRGB(canvas, iw, ih, r, g, b, x, y, w, h, xmin, xmax, ymin, ymax);
+ }
else
canvas->cxPutImageRectRGB(canvas->ctxcanvas, iw, ih, r, g, b, x, y, w, h, xmin, xmax, ymin, ymax);
}
diff --git a/src/drv/cdpdf.c b/src/drv/cdpdf.c
index e2482b7..58cf474 100644
--- a/src/drv/cdpdf.c
+++ b/src/drv/cdpdf.c
@@ -111,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);
}
@@ -1675,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);
diff --git a/src/drv/cdps.c b/src/drv/cdps.c
index abd061c..37bdef6 100644
--- a/src/drv/cdps.c
+++ b/src/drv/cdps.c
@@ -49,11 +49,11 @@ struct _cdCtxCanvas
{
cdCanvas* canvas;
- FILE *file; /* Arquivo PS */
+ FILE *file; /* Arquivo PS */
int res; /* Resolucao */
int pages; /* Numero total de paginas */
- double width; /* Largura do papel (points) */
- double height; /* Altura do papel (points) */
+ double width_pt; /* Largura do papel (points) */
+ double height_pt; /* Altura do papel (points) */
double xmin, ymin; /* Definem as margens esquerda e inferior (points) */
double xmax, ymax; /* Definem as margens direita e superior (points) */
double bbxmin, bbymin; /* Definem a bounding box */
@@ -82,7 +82,8 @@ struct _cdCtxCanvas
static void setpsdefaultvalues(cdCtxCanvas *ctxcanvas)
{
/* all the other values are set to 0 */
- cdSetPaperSize(CD_A4, &ctxcanvas->width, &ctxcanvas->height);
+ cdSetPaperSize(CD_A4, &ctxcanvas->width_pt, &ctxcanvas->height_pt);
+
ctxcanvas->xmin = 25.4; /* ainda em mm, sera' convertido para points na init_ps */
ctxcanvas->xmax = 25.4;
ctxcanvas->ymin = 25.4;
@@ -249,8 +250,10 @@ static void set_default_matrix(cdCtxCanvas *ctxcanvas)
fprintf(ctxcanvas->file, "setmatrix\n");
}
- /* margin and scale */
+ /* margin */
fprintf(ctxcanvas->file, "%g %g translate\n", ctxcanvas->xmin, ctxcanvas->ymin);
+
+ /* default coordinate system is in points, change it to pixels. */
fprintf(ctxcanvas->file, "%g %g scale\n", ctxcanvas->scale, ctxcanvas->scale);
}
@@ -259,15 +262,15 @@ static void set_default_matrix(cdCtxCanvas *ctxcanvas)
*/
static void init_ps(cdCtxCanvas *ctxcanvas)
{
- double w, h;
+ double w_pt, h_pt;
time_t now = time(NULL);
- ctxcanvas->scale = 72.0/ctxcanvas->res;
+ /* convert margin values to actual limits */
ctxcanvas->xmin = mm2pt(ctxcanvas->xmin);
- ctxcanvas->xmax = ctxcanvas->width - mm2pt(ctxcanvas->xmax);
+ ctxcanvas->xmax = ctxcanvas->width_pt - mm2pt(ctxcanvas->xmax);
ctxcanvas->ymin = mm2pt(ctxcanvas->ymin);
- ctxcanvas->ymax = ctxcanvas->height - mm2pt(ctxcanvas->ymax);
+ ctxcanvas->ymax = ctxcanvas->height_pt - mm2pt(ctxcanvas->ymax);
ctxcanvas->bbmargin = mm2pt(ctxcanvas->bbmargin);
fprintf(ctxcanvas->file, "%%!PS-Adobe-3.0 %s\n", ctxcanvas->eps ? "EPSF-3.0":"");
@@ -309,9 +312,10 @@ static void init_ps(cdCtxCanvas *ctxcanvas)
if (!ctxcanvas->eps && !ctxcanvas->level1)
{
+ /* setpagedevice not allowed in EPS */
fprintf(ctxcanvas->file, "%%%%IncludeFeature: *Resolution %d\n", ctxcanvas->res);
fprintf(ctxcanvas->file, "%%%%BeginFeature: *PageSize\n");
- fprintf(ctxcanvas->file, "<< /PageSize [%g %g] >> setpagedevice\n", ctxcanvas->width, ctxcanvas->height); /* setpagedevice not allowed in EPS */
+ fprintf(ctxcanvas->file, "<< /PageSize [%g %g] >> setpagedevice\n", ctxcanvas->width_pt, ctxcanvas->height_pt);
fprintf(ctxcanvas->file, "%%%%EndFeature\n");
}
@@ -321,16 +325,20 @@ static void init_ps(cdCtxCanvas *ctxcanvas)
fputs(change_font, ctxcanvas->file);
fputs(re_encode, ctxcanvas->file);
- w = ctxcanvas->xmax - ctxcanvas->xmin;
- h = ctxcanvas->ymax - ctxcanvas->ymin;
+ ctxcanvas->scale = 72.0/ctxcanvas->res;
+ ctxcanvas->canvas->xres = ctxcanvas->res/25.4;
+ ctxcanvas->canvas->yres = ctxcanvas->canvas->xres;
+
+ w_pt = ctxcanvas->xmax - ctxcanvas->xmin;
+ h_pt = ctxcanvas->ymax - ctxcanvas->ymin;
+
+ ctxcanvas->canvas->w_mm = w_pt/CD_MM2PT; /* Converte p/ milimetros */
+ ctxcanvas->canvas->h_mm = h_pt/CD_MM2PT; /* Converte p/ milimetros */
+
+ ctxcanvas->canvas->w = cdRound(ctxcanvas->canvas->xres*ctxcanvas->canvas->w_mm);
+ ctxcanvas->canvas->h = cdRound(ctxcanvas->canvas->yres*ctxcanvas->canvas->h_mm);
- ctxcanvas->canvas->w = (int)(w/ctxcanvas->scale + 0.5); /* Converte p/ unidades do usuario */
- ctxcanvas->canvas->h = (int)(h/ctxcanvas->scale + 0.5); /* Converte p/ unidades do usuario */
- ctxcanvas->canvas->w_mm = w/CD_MM2PT; /* Converte p/ milimetros */
- ctxcanvas->canvas->h_mm = h/CD_MM2PT; /* Converte p/ milimetros */
ctxcanvas->canvas->bpp = 24;
- ctxcanvas->canvas->xres = ctxcanvas->canvas->w / ctxcanvas->canvas->w_mm;
- ctxcanvas->canvas->yres = ctxcanvas->canvas->h / ctxcanvas->canvas->h_mm;
fprintf(ctxcanvas->file, "%%%%Page: 1 1\n");
ctxcanvas->pages = 1;
@@ -1989,16 +1997,16 @@ static void cdcreatecanvas(cdCanvas* canvas, void *data)
{
int paper;
sscanf(line, "%d", &paper);
- cdSetPaperSize(paper, &ctxcanvas->width, &ctxcanvas->height);
+ cdSetPaperSize(paper, &ctxcanvas->width_pt, &ctxcanvas->height_pt);
break;
}
case 'w':
sscanf(line, "%g", &num);
- ctxcanvas->width = mm2pt(num);
+ ctxcanvas->width_pt = mm2pt(num);
break;
case 'h':
sscanf(line, "%g", &num);
- ctxcanvas->height = mm2pt(num);
+ ctxcanvas->height_pt = mm2pt(num);
break;
case 'l':
sscanf(line, "%g", &num);
@@ -2048,9 +2056,9 @@ static void cdcreatecanvas(cdCanvas* canvas, void *data)
/* update canvas context */
canvas->ctxcanvas = ctxcanvas;
- if (ctxcanvas->landscape == 1)
+ if (ctxcanvas->landscape)
{
- _cdSwapDouble(ctxcanvas->width, ctxcanvas->height);
+ _cdSwapDouble(ctxcanvas->width_pt, ctxcanvas->height_pt);
_cdSwapDouble(ctxcanvas->xmin, ctxcanvas->ymin);
_cdSwapDouble(ctxcanvas->xmax, ctxcanvas->ymax);
}
diff --git a/src/drv/cgm.c b/src/drv/cgm.c
index e86baaf..ea4d930 100644
--- a/src/drv/cgm.c
+++ b/src/drv/cgm.c
@@ -743,7 +743,7 @@ static void cgmb_s ( CGM *cgm, const char *s, int len )
else
cgmb_putu8(cgm,l);
- for ( i=0; i