summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorscuri <scuri>2010-06-16 21:09:54 +0000
committerscuri <scuri>2010-06-16 21:09:54 +0000
commit483f59d3a55720c8c140aef863f4d34a0d90cca8 (patch)
tree914494291b1870c2b50e7c252c156c91133e9a62 /src
parent72857b1207600b10bd73e9b1fee479438aae3ac9 (diff)
*** empty log message ***
Diffstat (limited to 'src')
-rw-r--r--src/cd_image.c28
-rw-r--r--src/drv/cdpdf.c14
-rw-r--r--src/drv/cdps.c54
-rw-r--r--src/drv/cgm.c4
-rw-r--r--src/gdiplus/cdwinp.cpp15
-rw-r--r--src/sim/sim_primitives.c23
-rw-r--r--src/svg/cdsvg.c2
7 files changed, 80 insertions, 60 deletions
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<len; s++ )
+ for ( i=0; i<l; i++, s++ )
{
if ( (i + bc) == 32766 )
{
@@ -756,7 +756,7 @@ static void cgmb_s ( CGM *cgm, const char *s, int len )
else
cgmb_putu16 ( cgm, l );
}
- cgmb_putc ( cgm, s[i] );
+ cgmb_putc ( cgm, *s );
}
}
diff --git a/src/gdiplus/cdwinp.cpp b/src/gdiplus/cdwinp.cpp
index 6827f53..013cc9a 100644
--- a/src/gdiplus/cdwinp.cpp
+++ b/src/gdiplus/cdwinp.cpp
@@ -2560,19 +2560,22 @@ static cdAttribute img_points_attrib =
get_img_points_attrib
};
-static BOOL Is_WinXP_or_Later(void)
+static BOOL Is_WinXP_or_WinSrv03(void)
{
OSVERSIONINFO osvi;
ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx (&osvi);
- BOOL bIsWindowsXPorLater =
+ BOOL bIsWindowsXP =
(osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) &&
- ( (osvi.dwMajorVersion > 5) || ( (osvi.dwMajorVersion == 5) &&
- (osvi.dwMinorVersion >= 1)));
+ ((osvi.dwMajorVersion == 5) && (osvi.dwMinorVersion == 1));
- return bIsWindowsXPorLater;
+ BOOL bIsWindowsServer2003 =
+ (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) &&
+ ((osvi.dwMajorVersion == 5) && (osvi.dwMinorVersion == 2));
+
+ return bIsWindowsXP || bIsWindowsServer2003;
}
static void set_aa_attrib(cdCtxCanvas* ctxcanvas, char* data)
@@ -2588,7 +2591,7 @@ static void set_aa_attrib(cdCtxCanvas* ctxcanvas, char* data)
{
ctxcanvas->graphics->SetInterpolationMode(InterpolationModeBilinear);
ctxcanvas->graphics->SetSmoothingMode(SmoothingModeAntiAlias);
- if (Is_WinXP_or_Later())
+ if (Is_WinXP_or_WinSrv03())
ctxcanvas->graphics->SetTextRenderingHint(TextRenderingHintClearTypeGridFit);
else
ctxcanvas->graphics->SetTextRenderingHint(TextRenderingHintAntiAliasGridFit);
diff --git a/src/sim/sim_primitives.c b/src/sim/sim_primitives.c
index 4b3ebf3..29fc6af 100644
--- a/src/sim/sim_primitives.c
+++ b/src/sim/sim_primitives.c
@@ -1316,6 +1316,29 @@ void cdSimPutImageRectRGBA(cdCanvas* canvas, int iw, int ih, const unsigned char
free(fy);
}
+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)
+{
+ int height = ymax-ymin+1;
+ unsigned char* map;
+ int pal_size = 1L << canvas->bpp;
+ long colors[256];
+ (void)ih;
+
+ map = (unsigned char*)malloc(iw * height);
+ 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);
+}
+
+
/************************************************************************/
#include "cd_truetype.h"
diff --git a/src/svg/cdsvg.c b/src/svg/cdsvg.c
index a1fdf8e..0510919 100644
--- a/src/svg/cdsvg.c
+++ b/src/svg/cdsvg.c
@@ -1274,7 +1274,7 @@ static void cdcreatecanvas(cdCanvas *canvas, void *data)
cdRegisterAttribute(canvas, &opacity_attrib);
fprintf(ctxcanvas->file, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
- fprintf(ctxcanvas->file, "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"%dpt\" height=\"%dpt\" viewBox=\"0 0 %d %d\" version=\"1.1\">\n", canvas->w, canvas->h, canvas->w, canvas->h);
+ fprintf(ctxcanvas->file, "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"%gpt\" height=\"%gpt\" viewBox=\"0 0 %d %d\" version=\"1.1\">\n", CD_MM2PT*canvas->w_mm, CD_MM2PT*canvas->h_mm, canvas->w, canvas->h);
fprintf(ctxcanvas->file, "<g>\n"); /* open global container */
}