From 483f59d3a55720c8c140aef863f4d34a0d90cca8 Mon Sep 17 00:00:00 2001 From: scuri Date: Wed, 16 Jun 2010 21:09:54 +0000 Subject: *** empty log message *** --- src/cd_image.c | 28 +++++++------------------ src/drv/cdpdf.c | 14 ++++++------- src/drv/cdps.c | 54 +++++++++++++++++++++++++++--------------------- src/drv/cgm.c | 4 ++-- src/gdiplus/cdwinp.cpp | 15 ++++++++------ src/sim/sim_primitives.c | 23 +++++++++++++++++++++ src/svg/cdsvg.c | 2 +- 7 files changed, 80 insertions(+), 60 deletions(-) (limited to 'src') 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 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, "\n"); - fprintf(ctxcanvas->file, "\n", canvas->w, canvas->h, canvas->w, canvas->h); + fprintf(ctxcanvas->file, "\n", CD_MM2PT*canvas->w_mm, CD_MM2PT*canvas->h_mm, canvas->w, canvas->h); fprintf(ctxcanvas->file, "\n"); /* open global container */ } -- cgit v1.2.3