Wed Aug 4 04:41:40 PDT 1993 These are diffs between the stock gs 2.6.1p4 and the LBL version. Most of the important changes are in gdevx.[ch]& gdevxini.c to support the limits on colormap usage. Unfortunately these diffs also include gs patches 1-4 from ftp.cs.wisc.edu since those patches modified the same files. If you've already installed these patches, you'll have to do some hand-merging or back it out of the above three files then apply this diff (don't back out all of patch 1-5, just the three X files listed above). The other files in this diff are changed to fix bugs in the coordinate system & caching of large & rotated fonts and to get rid of an `optimization' that may or may not have made some small difference on Intel's braindead PC hardware but significantly slows things down & produces inaccurate results on any real computer. - Van Jacobson *** /tmp/,RCSt1a04163 Wed Aug 4 04:41:20 1993 --- gdevx.c Tue Jul 20 10:04:45 1993 *************** *** 153,164 **** 0, 0, /* dynamic_size, dynamic_number */ 0, 0, /* borderColor, borderWidth */ NULL, /* geometry */ ! 128, 5, /* maxGrayRamp, maxRGBRamp */ NULL, /* palette */ NULL, NULL, NULL, /* regularFonts, symbolFonts, dingbatFonts */ NULL, NULL, NULL, /* regular_fonts, symbol_fonts, dingbat_fonts */ ! 1, 1, 0, /* useXFonts, useScalableFonts, logXFonts */ ! 10.0, /* xFontTolerance */ 0.0, 0.0, /* xResolution, yResolution */ 1, /* useBackingPixmap */ 1, 1, /* useXPutImage, useXSetTile */ --- 153,165 ---- 0, 0, /* dynamic_size, dynamic_number */ 0, 0, /* borderColor, borderWidth */ NULL, /* geometry */ ! 32, 5, /* maxGrayRamp, maxRGBRamp */ ! 32, 125, /* maxGrays, maxColors */ NULL, /* palette */ NULL, NULL, NULL, /* regularFonts, symbolFonts, dingbatFonts */ NULL, NULL, NULL, /* regular_fonts, symbol_fonts, dingbat_fonts */ ! 1, 1, /* useXFonts, useFontExtensions */ ! 1, 0, /* useScalableFonts, logXFonts */ 0.0, 0.0, /* xResolution, yResolution */ 1, /* useBackingPixmap */ 1, 1, /* useXPutImage, useXSetTile */ *************** *** 191,206 **** if (xdev->ghostview) x_send_event(dev, xdev->done); if (xdev->vinfo) { ! XFree(xdev->vinfo); xdev->vinfo = NULL; } if (xdev->dither_colors) { if (gx_device_has_color(xdev)) gs_free((char *)xdev->dither_colors, sizeof(x_pixel), ! xdev->color_info.dither_gray, "gdev_x_gray_ramp"); else gs_free((char *)xdev->dither_colors, sizeof(x_pixel), ! xdev->color_info.dither_rgb, "gdev_x_rgb_cube"); xdev->dither_colors = NULL; } if (xdev->dynamic_colors) { --- 192,209 ---- if (xdev->ghostview) x_send_event(dev, xdev->done); if (xdev->vinfo) { ! XFree((char *)xdev->vinfo); xdev->vinfo = NULL; } if (xdev->dither_colors) { if (gx_device_has_color(xdev)) + #define cube(r) (r*r*r) gs_free((char *)xdev->dither_colors, sizeof(x_pixel), ! cube(xdev->color_info.dither_rgb), "gdev_x_rgb_cube"); ! #undef cube else gs_free((char *)xdev->dither_colors, sizeof(x_pixel), ! xdev->color_info.dither_gray, "gdev_x_gray_ramp"); xdev->dither_colors = NULL; } if (xdev->dynamic_colors) { *************** *** 470,475 **** --- 473,489 ---- /* on every operation, but there's no separate driver routine */ /* for erasepage (yet). */ if (x == 0 && y == 0 && w == xdev->width && h == xdev->height) { + if (color == xdev->foreground || color == xdev->background) { + int i; + XErrorHandler oldhandler = XSetErrorHandler(x_catch_free_colors); + for (i = 0; i < xdev->dynamic_number; i++) { + XFreeColors(xdev->dpy, xdev->cmap, + &xdev->dynamic_colors[i].pixel, 1, 0); + } + XSync(xdev->dpy, False); /* Force any errors */ + oldhandler = XSetErrorHandler(oldhandler); + xdev->dynamic_number = 0; + } xdev->colors_or = xdev->colors_and = color; } if (xdev->bpixmap != (Pixmap) 0) { *** /tmp/,RCSt1a04168 Wed Aug 4 04:41:22 1993 --- gdevx.h Tue Jul 20 10:04:46 1993 *************** *** 138,143 **** --- 138,144 ---- Dimension borderWidth; String geometry; int maxGrayRamp, maxRGBRamp; + int maxGrays, maxColors; String palette; String regularFonts; String symbolFonts; *************** *** 145,152 **** x11fontmap *regular_fonts; x11fontmap *symbol_fonts; x11fontmap *dingbat_fonts; ! Boolean useXFonts, useScalableFonts, logXFonts; ! float xFontTolerance; float xResolution, yResolution; /* Flags work around various X server problems. */ --- 146,152 ---- x11fontmap *regular_fonts; x11fontmap *symbol_fonts; x11fontmap *dingbat_fonts; ! Boolean useXFonts, useFontExtensions, useScalableFonts, logXFonts; float xResolution, yResolution; /* Flags work around various X server problems. */ *************** *** 159,164 **** --- 159,165 ---- /* function to keep track of screen updates */ void x_update_add(P5(gx_device *, int, int, int, int)); void gdev_x_clear_window(P1(gx_device_X *)); + int x_catch_free_colors(P2(Display *, XErrorEvent *)); /* Number used to distinguish when resoultion was set from the command line */ #define FAKE_RES (16*72) *** /tmp/,RCSt1a04173 Wed Aug 4 04:41:23 1993 --- gdevxini.c Mon Aug 2 00:58:37 1993 *************** *** 40,48 **** {"dingbatFonts", "DingbatFonts", XtRString, sizeof(String), XtOffsetOf(gx_device_X, dingbatFonts), XtRString, "ZapfDingbats: -Adobe-ITC Zapf Dingbats-Medium-R-Normal--"}, - {"externalFontTolerance", "ExternalFontTolerance", XtRFloat, sizeof(float), - XtOffsetOf(gx_device_X, xFontTolerance), - XtRString, (XtPointer)"10.0"}, {XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel), XtOffsetOf(gx_device_X, foreground), XtRString, (XtPointer)"XtDefaultForeground"}, --- 40,45 ---- *************** *** 52,60 **** {"logExternalFonts", "LogExternalFonts", XtRBoolean, sizeof(Boolean), XtOffsetOf(gx_device_X, logXFonts), XtRImmediate, (XtPointer)False}, {"maxGrayRamp", "MaxGrayRamp", XtRInt, sizeof(int), XtOffsetOf(gx_device_X, maxGrayRamp), ! XtRImmediate, (XtPointer)128}, {"maxRGBRamp", "MaxRGBRamp", XtRInt, sizeof(int), XtOffsetOf(gx_device_X, maxRGBRamp), XtRImmediate, (XtPointer)5}, --- 49,63 ---- {"logExternalFonts", "LogExternalFonts", XtRBoolean, sizeof(Boolean), XtOffsetOf(gx_device_X, logXFonts), XtRImmediate, (XtPointer)False}, + {"maxGrays", "MaxGrays", XtRInt, sizeof(int), + XtOffsetOf(gx_device_X, maxGrays), + XtRImmediate, (XtPointer)64}, {"maxGrayRamp", "MaxGrayRamp", XtRInt, sizeof(int), XtOffsetOf(gx_device_X, maxGrayRamp), ! XtRImmediate, (XtPointer)64}, ! {"maxColors", "MaxColors", XtRInt, sizeof(int), ! XtOffsetOf(gx_device_X, maxColors), ! XtRImmediate, (XtPointer)125}, {"maxRGBRamp", "MaxRGBRamp", XtRInt, sizeof(int), XtOffsetOf(gx_device_X, maxRGBRamp), XtRImmediate, (XtPointer)5}, *************** *** 106,114 **** XtRString, "Symbol: -Adobe-Symbol-Medium-R-Normal--"}, {"useBackingPixmap", "UseBackingPixmap", XtRBoolean, sizeof(Boolean), XtOffsetOf(gx_device_X, useBackingPixmap), ! XtRImmediate, (XtPointer)True}, {"useExternalFonts", "UseExternalFonts", XtRBoolean, sizeof(Boolean), XtOffsetOf(gx_device_X, useXFonts), XtRImmediate, (XtPointer)True}, {"useScalableFonts", "UseScalableFonts", XtRBoolean, sizeof(Boolean), XtOffsetOf(gx_device_X, useScalableFonts), --- 109,120 ---- XtRString, "Symbol: -Adobe-Symbol-Medium-R-Normal--"}, {"useBackingPixmap", "UseBackingPixmap", XtRBoolean, sizeof(Boolean), XtOffsetOf(gx_device_X, useBackingPixmap), ! XtRImmediate, (XtPointer)False}, {"useExternalFonts", "UseExternalFonts", XtRBoolean, sizeof(Boolean), XtOffsetOf(gx_device_X, useXFonts), + XtRImmediate, (XtPointer)False}, + {"useFontExtensions", "UseFontExtensions", XtRBoolean, sizeof(Boolean), + XtOffsetOf(gx_device_X, useFontExtensions), XtRImmediate, (XtPointer)True}, {"useScalableFonts", "UseScalableFonts", XtRBoolean, sizeof(Boolean), XtOffsetOf(gx_device_X, useScalableFonts), *************** *** 127,132 **** --- 133,145 ---- XtRString, (XtPointer)"0.0"}, }; + private String + fallback_resources[] = { + "Ghostscript*Background: white", + "Ghostscript*Foreground: black", + NULL + }; + /* Define constants for orientation from ghostview */ /* Number represents clockwise rotation of the paper in degrees */ typedef enum { *************** *** 140,145 **** --- 153,182 ---- private void gdev_x_setup_colors(P1(gx_device_X *)); private void gdev_x_setup_fontmap(P1(gx_device_X *)); + /* Catch the alloc error when there is not enough resources for the + * backing pixmap. Automatically shut off backing pixmap and let the + * user know when this happens. + */ + private Boolean alloc_error; + private XErrorHandler oldhandler; + + private int + x_catch_alloc(Display *dpy, XErrorEvent *err) + { + if (err->error_code == BadAlloc) + alloc_error = True; + if (alloc_error) + return 0; + return oldhandler(dpy, err); + } + + int + x_catch_free_colors(Display *dpy, XErrorEvent *err) + { + if (err->request_code == X_FreeColors) return 0; + return oldhandler(dpy, err); + } + /* Open the X device */ int gdev_x_open(register gx_device_X *xdev) *************** *** 289,296 **** xdev->scr = scr; xvinfo.visual = DefaultVisualOfScreen(scr); - xdev->cmap = DefaultColormapOfScreen(scr); } xvinfo.visualid = XVisualIDFromVisual(xvinfo.visual); xdev->vinfo = XGetVisualInfo(xdev->dpy, VisualIDMask, &xvinfo, &nitems); --- 326,333 ---- xdev->scr = scr; xvinfo.visual = DefaultVisualOfScreen(scr); } + xdev->cmap = DefaultColormapOfScreen(xdev->scr); xvinfo.visualid = XVisualIDFromVisual(xvinfo.visual); xdev->vinfo = XGetVisualInfo(xdev->dpy, VisualIDMask, &xvinfo, &nitems); *************** *** 299,306 **** --- 336,345 ---- exit(1); } /* Get X Resources. Use the toolkit for this. */ + oldhandler = XSetErrorHandler(x_catch_free_colors); XtToolkitInitialize(); app_con = XtCreateApplicationContext(); + XtAppSetFallbackResources(app_con, fallback_resources); dpy = XtOpenDisplay(app_con, NULL, "ghostscript", "Ghostscript", NULL, 0, &zero, NULL); toplevel = XtAppCreateShell(NULL, "Ghostscript", *************** *** 310,315 **** --- 349,355 ---- XtDestroyWidget(toplevel); XtCloseDisplay(dpy); XtDestroyApplicationContext(app_con); + oldhandler = XSetErrorHandler(oldhandler); gdev_x_setup_colors(xdev); gdev_x_setup_fontmap(xdev); *************** *** 388,393 **** --- 428,434 ---- xswa.background_pixel = xdev->background; xswa.border_pixel = xdev->borderColor; xswa.colormap = xdev->cmap; + xswa.backing_store = xdev->useBackingPixmap? NotUseful : Always; xdev->win = XCreateWindow(xdev->dpy, RootWindowOfScreen(xdev->scr), sizehints.x, sizehints.y, /* upper left */ xdev->width, xdev->height, *************** *** 396,401 **** --- 437,443 ---- InputOutput, /* class */ xdev->vinfo->visual, /* visual */ CWEventMask | CWBackPixel | + CWBackingStore | CWBorderPixel | CWColormap, &xswa); XStoreName(xdev->dpy, xdev->win, "ghostscript"); *************** *** 449,471 **** return 0; } - /* Catch the alloc error when there is not enough resources for the - * backing pixmap. Automatically shut off backing pixmap and let the - * user know when this happens. - */ - private Boolean alloc_error; - private XErrorHandler oldhandler; - - private int - x_catch_alloc(Display *dpy, XErrorEvent *err) - { - if (err->error_code == BadAlloc) - alloc_error = True; - if (alloc_error) - return 0; - oldhandler(dpy, err); - } - /* Allocate the backing pixmap, if any, and clear the window. */ void gdev_x_clear_window(gx_device_X *xdev) --- 491,496 ---- *************** *** 562,568 **** type == XA_STRING) { nitems = sscanf(buf, "%*s %d %d", &(xdev->foreground), &(xdev->background)); ! if (nitems != 2 || *buf != 'M' || *buf != 'G' || *buf != 'C') { eprintf("gs: Malformed ghostview color property.\n"); exit(1); } --- 587,593 ---- type == XA_STRING) { nitems = sscanf(buf, "%*s %d %d", &(xdev->foreground), &(xdev->background)); ! if (nitems != 2 || *buf != 'M' && *buf != 'G' && *buf != 'C') { eprintf("gs: Malformed ghostview color property.\n"); exit(1); } *************** *** 585,590 **** --- 610,617 ---- #endif xdev->dither_colors = NULL; xdev->dynamic_colors = NULL; + xdev->dynamic_size = 0; + xdev->dynamic_number = 0; xdev->color_info.depth = xdev->vinfo->depth; if (palette == 'C') { *************** *** 591,597 **** xdev->color_info.num_components = 3; xdev->color_info.max_gray = xdev->color_info.max_rgb = num_rgb - 1; - xdev->dither_colors = NULL; #if HaveStdCMap /* Get a standard color map if available */ if (xdev->vinfo->visual == DefaultVisualOfScreen(xdev->scr)) { --- 618,623 ---- *************** *** 614,636 **** #define cube(r) (r*r*r) #define cbrt(r) pow(r, 1.0/3.0) { ! int avail_colors = xdev->vinfo->colormap_size; ! while (!xdev->dither_colors && avail_colors) { ! int ramp_size = min((int)cbrt((double)avail_colors / 2.0), ! min(xdev->maxRGBRamp, num_rgb)); int max_rgb = ramp_size - 1; int r, g, b; - if (ramp_size < 2) { - avail_colors = 0; - goto no_cube; - } xdev->color_info.dither_gray = xdev->color_info.dither_rgb = ramp_size; xdev->dither_colors = (x_pixel *) gs_malloc(sizeof(x_pixel), cube(ramp_size), "gdev_x_rgb_cube"); for (r = 0; r < ramp_size; r++) { for (g = 0; g < ramp_size; g++) { for (b = 0; b < ramp_size; b++) { --- 640,662 ---- #define cube(r) (r*r*r) #define cbrt(r) pow(r, 1.0/3.0) { ! int ramp_size = ! min((int)cbrt((double)xdev->vinfo->colormap_size / 2.0), ! min(xdev->maxRGBRamp, num_rgb)); ! while (!xdev->dither_colors && ramp_size >= 2) { int max_rgb = ramp_size - 1; int r, g, b; xdev->color_info.dither_gray = xdev->color_info.dither_rgb = ramp_size; xdev->dither_colors = (x_pixel *) gs_malloc(sizeof(x_pixel), cube(ramp_size), "gdev_x_rgb_cube"); + if (xdev->dither_colors == NULL) { + ramp_size--; + goto no_cube; + } for (r = 0; r < ramp_size; r++) { for (g = 0; g < ramp_size; g++) { for (b = 0; b < ramp_size; b++) { *************** *** 653,665 **** xdev->dither_colors[cube_index(r, g, b)] = xc.pixel; } else { ! int i; ! ! avail_colors = cube_index(r, g, b) - 1; ! for (i = 1; i <= avail_colors; i++) { XFreeColors(xdev->dpy, xdev->cmap, ! &(xdev->dither_colors[i]), ! 1, 0); } gs_free((char *)xdev->dither_colors, sizeof(x_pixel), cube(ramp_size), --- 679,697 ---- xdev->dither_colors[cube_index(r, g, b)] = xc.pixel; } else { ! eprintf3("Warning: failed to allocate %dx%dx%d RGB cube.\n", ! ramp_size, ramp_size, ramp_size); ! ramp_size--; ! if (cube_index(r, g, b) - 1 > 0) { ! oldhandler = ! XSetErrorHandler(x_catch_free_colors); XFreeColors(xdev->dpy, xdev->cmap, ! xdev->dither_colors + 1, ! cube_index(r, g, b) - 1, 0); ! /* Force any errors */ ! XSync(xdev->dpy, False); ! oldhandler = ! XSetErrorHandler(oldhandler); } gs_free((char *)xdev->dither_colors, sizeof(x_pixel), cube(ramp_size), *************** *** 681,702 **** /* Allocate space for dynamic colors, do at most 256 */ /* If there are more avaiaible, we ask the X server */ ! xdev->dynamic_number = 0; ! xdev->dynamic_size = min(256, xdev->vinfo->colormap_size); ! xdev->dynamic_size -= cube(xdev->color_info.dither_rgb); ! if (xdev->dynamic_size) { xdev->dynamic_colors = (XColor *) gs_malloc(sizeof(XColor), xdev->dynamic_size, "gdev_x_dynamic_colors"); - } else { - xdev->dynamic_colors = NULL; } #undef cube } else if (palette == 'G') { grayscale: xdev->color_info.num_components = 1; xdev->color_info.max_gray = num_rgb - 1; - xdev->dither_colors = NULL; #if HaveStdCMap /* Get a standard color map if available */ if (xdev->std_cmap = x_get_std_cmap(xdev, XA_RGB_GRAY_MAP)) { --- 713,733 ---- /* Allocate space for dynamic colors, do at most 256 */ /* If there are more avaiaible, we ask the X server */ ! xdev->dynamic_size = min(xdev->maxColors, xdev->vinfo->colormap_size) - ! cube(xdev->color_info.dither_rgb); ! if (xdev->dynamic_size > 0) { xdev->dynamic_colors = (XColor *) gs_malloc(sizeof(XColor), xdev->dynamic_size, "gdev_x_dynamic_colors"); } + if (xdev->dynamic_colors == NULL) { + xdev->dynamic_size = 0; + } #undef cube } else if (palette == 'G') { grayscale: xdev->color_info.num_components = 1; xdev->color_info.max_gray = num_rgb - 1; #if HaveStdCMap /* Get a standard color map if available */ if (xdev->std_cmap = x_get_std_cmap(xdev, XA_RGB_GRAY_MAP)) { *************** *** 707,731 **** #endif /* Otherwise set up a gray ramp of our own */ /* The gray ramp is limited to about 1/2 of the available */ ! /* colormap, the user specified maxGrayRamp (usually 128), */ /* or the number of representable grays */ { ! int avail_colors = xdev->vinfo->colormap_size; ! while (!xdev->dither_colors && avail_colors) { ! int ramp_size = min(avail_colors / 2, ! min(xdev->maxGrayRamp, num_rgb)); int max_gray = ramp_size - 1; int i; - if (ramp_size < 2) { - avail_colors = 0; - goto no_ramp; - } xdev->color_info.dither_gray = ramp_size; xdev->dither_colors = (x_pixel *) gs_malloc(sizeof(x_pixel), ramp_size, "gdev_x_gray_ramp"); for (i = 0; i < ramp_size; i++) { XColor xc; --- 738,761 ---- #endif /* Otherwise set up a gray ramp of our own */ /* The gray ramp is limited to about 1/2 of the available */ ! /* colormap, the user specified maxGrayRamp (usually 64), */ /* or the number of representable grays */ { ! int ramp_size = min(xdev->vinfo->colormap_size / 2, ! min(xdev->maxGrayRamp, num_rgb)); ! while (!xdev->dither_colors && ramp_size >= 3) { int max_gray = ramp_size - 1; int i; xdev->color_info.dither_gray = ramp_size; xdev->dither_colors = (x_pixel *) gs_malloc(sizeof(x_pixel), ramp_size, "gdev_x_gray_ramp"); + if (xdev->dither_colors == NULL) { + ramp_size--; + goto no_ramp; + } for (i = 0; i < ramp_size; i++) { XColor xc; *************** *** 739,748 **** if (XAllocColor(xdev->dpy, xdev->cmap, &xc)) { xdev->dither_colors[i] = xc.pixel; } else { ! avail_colors = i - 1; ! for (i = 1; i <= avail_colors; i++) { XFreeColors(xdev->dpy, xdev->cmap, ! &(xdev->dither_colors[i]), 1, 0); } gs_free((char *)xdev->dither_colors, sizeof(x_pixel), ramp_size, --- 769,784 ---- if (XAllocColor(xdev->dpy, xdev->cmap, &xc)) { xdev->dither_colors[i] = xc.pixel; } else { ! eprintf1("Warning: failed to allocate %d level gray ramp.\n", ! ramp_size); ! ramp_size /= 2; ! if (i - 1 > 0) { ! oldhandler = ! XSetErrorHandler(x_catch_free_colors); XFreeColors(xdev->dpy, xdev->cmap, ! xdev->dither_colors + 1, i - 1, 0); ! XSync(xdev->dpy, False); /* Force any errors */ ! oldhandler = XSetErrorHandler(oldhandler); } gs_free((char *)xdev->dither_colors, sizeof(x_pixel), ramp_size, *************** *** 761,776 **** /* Allocate space for dynamic colors, do at most 256 */ /* If there are more avaiaible, we ask the X server */ ! xdev->dynamic_number = 0; ! xdev->dynamic_size = min(256, xdev->vinfo->colormap_size); ! xdev->dynamic_size -= xdev->color_info.dither_gray; ! if (xdev->dynamic_size) { xdev->dynamic_colors = (XColor *) gs_malloc(sizeof(XColor), xdev->dynamic_size, "gdev_x_dynamic_colors"); - } else { - xdev->dynamic_colors = NULL; } } else if (palette == 'M') { monochrome: xdev->color_info.num_components = 1; --- 797,812 ---- /* Allocate space for dynamic colors, do at most 256 */ /* If there are more avaiaible, we ask the X server */ ! xdev->dynamic_size = min(xdev->maxGrays, xdev->vinfo->colormap_size) - ! xdev->color_info.dither_gray; ! if (xdev->dynamic_size > 0) { xdev->dynamic_colors = (XColor *) gs_malloc(sizeof(XColor), xdev->dynamic_size, "gdev_x_dynamic_colors"); } + if (xdev->dynamic_colors == NULL) { + xdev->dynamic_size = 0; + } } else if (palette == 'M') { monochrome: xdev->color_info.num_components = 1; *************** *** 852,863 **** --- 888,910 ---- if (x11_name = get_x11_name(&cp, &x11_name_len)) { font = (x11fontmap *)gs_malloc(sizeof(x11fontmap), 1, "gdev_x_setup_fontmap"); + if (font == NULL) continue; font->ps_name = (char *)gs_malloc(sizeof(char), ps_name_len+1, "gdev_x_setup_fontmap"); + if (font->ps_name == NULL) { + gs_free((char *)font, sizeof(x11fontmap), 1, "gdev_x_fontmap"); + continue; + } strncpy(font->ps_name, ps_name, ps_name_len); font->ps_name[ps_name_len] = '\0'; font->x11_name = (char *)gs_malloc(sizeof(char), x11_name_len, "gdev_x_setup_fontmap"); + if (font->x11_name == NULL) { + gs_free(font->ps_name, sizeof(char), strlen(font->ps_name)+1, + "gdev_x_font_psname"); + gs_free((char *)font, sizeof(x11fontmap), 1, "gdev_x_fontmap"); + continue; + } strncpy(font->x11_name, x11_name, x11_name_len-1); font->x11_name[x11_name_len-1] = '\0'; font->std_names = NULL; *************** *** 874,885 **** --- 921,943 ---- if (x11_name = get_x11_name(&cp, &x11_name_len)) { font = (x11fontmap *)gs_malloc(sizeof(x11fontmap), 1, "gdev_x_setup_fontmap"); + if (font == NULL) continue; font->ps_name = (char *)gs_malloc(sizeof(char), ps_name_len+1, "gdev_x_setup_fontmap"); + if (font->ps_name == NULL) { + gs_free((char *)font, sizeof(x11fontmap), 1, "gdev_x_fontmap"); + continue; + } strncpy(font->ps_name, ps_name, ps_name_len); font->ps_name[ps_name_len] = '\0'; font->x11_name = (char *)gs_malloc(sizeof(char), x11_name_len, "gdev_x_setup_fontmap"); + if (font->x11_name == NULL) { + gs_free(font->ps_name, sizeof(char), strlen(font->ps_name)+1, + "gdev_x_font_psname"); + gs_free((char *)font, sizeof(x11fontmap), 1, "gdev_x_fontmap"); + continue; + } strncpy(font->x11_name, x11_name, x11_name_len-1); font->x11_name[x11_name_len-1] = '\0'; font->std_names = NULL; *************** *** 896,907 **** --- 954,976 ---- if (x11_name = get_x11_name(&cp, &x11_name_len)) { font = (x11fontmap *)gs_malloc(sizeof(x11fontmap), 1, "gdev_x_setup_fontmap"); + if (font == NULL) continue; font->ps_name = (char *)gs_malloc(sizeof(char), ps_name_len+1, "gdev_x_setup_fontmap"); + if (font->ps_name == NULL) { + gs_free((char *)font, sizeof(x11fontmap), 1, "gdev_x_fontmap"); + continue; + } strncpy(font->ps_name, ps_name, ps_name_len); font->ps_name[ps_name_len] = '\0'; font->x11_name = (char *)gs_malloc(sizeof(char), x11_name_len, "gdev_x_setup_fontmap"); + if (font->x11_name == NULL) { + gs_free(font->ps_name, sizeof(char), strlen(font->ps_name)+1, + "gdev_x_font_psname"); + gs_free((char *)font, sizeof(x11fontmap), 1, "gdev_x_fontmap"); + continue; + } strncpy(font->x11_name, x11_name, x11_name_len-1); font->x11_name[x11_name_len-1] = '\0'; font->std_names = NULL; *** /tmp/,RCSt1a04178 Wed Aug 4 04:41:23 1993 --- gsmatrix.c Tue Jun 29 02:51:56 1993 *************** *** 61,70 **** /* The angle is in degrees. */ int gs_make_rotation(floatp ang, register gs_matrix *pmat) ! { float theta = ang * (M_PI / 180.0); *pmat = gs_identity_matrix; ! pmat->xx = pmat->yy = cos(theta); ! pmat->yx = -(pmat->xy = sin(theta)); return 0; } --- 61,73 ---- /* The angle is in degrees. */ int gs_make_rotation(floatp ang, register gs_matrix *pmat) ! { *pmat = gs_identity_matrix; ! if (ang != 0.) { ! double theta = ang * (M_PI / 180.0); ! pmat->xx = pmat->yy = cos(theta); ! pmat->yx = -(pmat->xy = sin(theta)); ! } return 0; } *************** *** 75,94 **** /* Since this is used heavily, we check for shortcuts. */ int gs_matrix_multiply(const gs_matrix *pm1, const gs_matrix *pm2, register gs_matrix *pmr) ! { float xx1 = pm1->xx, yy1 = pm1->yy; ! float tx1 = pm1->tx, ty1 = pm1->ty; ! float xx2 = pm2->xx, yy2 = pm2->yy; ! float xy2 = pm2->xy, yx2 = pm2->yx; if ( !is_skewed(pm1) ) ! { pmr->tx = tx1 * xx2 + pm2->tx; ! pmr->ty = ty1 * yy2 + pm2->ty; ! if ( is_fzero(xy2) ) pmr->xy = 0; else pmr->xy = xx1 * xy2, pmr->ty += tx1 * xy2; pmr->xx = xx1 * xx2; ! if ( is_fzero(yx2) ) pmr->yx = 0; else pmr->yx = yy1 * yx2, --- 78,98 ---- /* Since this is used heavily, we check for shortcuts. */ int gs_matrix_multiply(const gs_matrix *pm1, const gs_matrix *pm2, register gs_matrix *pmr) ! { double xx1 = pm1->xx, yy1 = pm1->yy; ! double tx1 = pm1->tx, ty1 = pm1->ty; ! double xx2 = pm2->xx, yy2 = pm2->yy; ! double xy2 = pm2->xy, yx2 = pm2->yx; ! double tx2 = pm2->tx, ty2 = pm2->ty; if ( !is_skewed(pm1) ) ! { pmr->tx = tx1 * xx2 + tx2; ! pmr->ty = ty1 * yy2 + ty2; ! if ( xy2 == 0. ) pmr->xy = 0; else pmr->xy = xx1 * xy2, pmr->ty += tx1 * xy2; pmr->xx = xx1 * xx2; ! if ( yx2 == 0. ) pmr->yx = 0; else pmr->yx = yy1 * yx2, *************** *** 96,107 **** pmr->yy = yy1 * yy2; } else ! { pmr->xx = xx1 * xx2 + pm1->xy * yx2; ! pmr->xy = xx1 * xy2 + pm1->xy * yy2; ! pmr->yy = pm1->yx * xy2 + yy1 * yy2; ! pmr->yx = pm1->yx * xx2 + yy1 * yx2; ! pmr->tx = tx1 * xx2 + ty1 * yx2 + pm2->tx; ! pmr->ty = tx1 * xy2 + ty1 * yy2 + pm2->ty; } return 0; } --- 100,113 ---- pmr->yy = yy1 * yy2; } else ! { ! double yx1 = pm1->yx, xy1 = pm1->xy; ! pmr->xx = xx1 * xx2 + xy1 * yx2; ! pmr->xy = xx1 * xy2 + xy1 * yy2; ! pmr->yy = yx1 * xy2 + yy1 * yy2; ! pmr->yx = yx1 * xx2 + yy1 * yx2; ! pmr->tx = tx1 * xx2 + ty1 * yx2 + tx2; ! pmr->ty = tx1 * xy2 + ty1 * yy2 + ty2; } return 0; } *************** *** 121,127 **** } else { double det = pm->xx * pm->yy - pm->xy * pm->yx; ! float mxx = pm->xx, mtx = pm->tx; if ( det == 0 ) return_error(gs_error_undefinedresult); pmr->xx = pm->yy / det; pmr->xy = - pm->xy / det; --- 127,133 ---- } else { double det = pm->xx * pm->yy - pm->xy * pm->yx; ! double mxx = pm->xx, mtx = pm->tx; if ( det == 0 ) return_error(gs_error_undefinedresult); pmr->xx = pm->yy / det; pmr->xy = - pm->xy / det; *************** *** 136,144 **** /* Rotate a matrix, possibly in place. The angle is in degrees. */ int gs_matrix_rotate(register const gs_matrix *pm, floatp ang, register gs_matrix *pmr) ! { float mxx, mxy; int quads; ! float tsin, tcos; /* We do some special checking for multiples of 90, */ /* so we don't get any rounding errors. */ if ( ang >= -360 && ang <= 360 && --- 142,150 ---- /* Rotate a matrix, possibly in place. The angle is in degrees. */ int gs_matrix_rotate(register const gs_matrix *pm, floatp ang, register gs_matrix *pmr) ! { double mxx, mxy; int quads; ! double tsin, tcos; /* We do some special checking for multiples of 90, */ /* so we don't get any rounding errors. */ if ( ang >= -360 && ang <= 360 && *************** *** 150,156 **** tsin = isin, tcos = icos; } else ! { float theta = ang * (M_PI / 180.0); tsin = sin(theta); tcos = cos(theta); } --- 156,162 ---- tsin = isin, tcos = icos; } else ! { double theta = (double)ang * (M_PI / 180.0); tsin = sin(theta); tcos = cos(theta); } *** /tmp/,RCSt1a04183 Wed Aug 4 04:41:24 1993 --- gxarith.h Tue Jun 29 02:51:59 1993 *************** *** 23,29 **** #define any_abs(x) ((x) < 0 ? -(x) : (x)) /* Test floating point values against zero. */ ! #if arch_floats_are_IEEE && (arch_sizeof_float == arch_sizeof_int || arch_sizeof_float == arch_sizeof_long) # if arch_sizeof_float == arch_sizeof_int # define _f_as_int(f) *(int *)(&(f)) # else /* arch_sizeof_float == arch_sizeof_long */ --- 23,29 ---- #define any_abs(x) ((x) < 0 ? -(x) : (x)) /* Test floating point values against zero. */ ! #if notdef && arch_floats_are_IEEE && (arch_sizeof_float == arch_sizeof_int || arch_sizeof_float == arch_sizeof_long) # if arch_sizeof_float == arch_sizeof_int # define _f_as_int(f) *(int *)(&(f)) # else /* arch_sizeof_float == arch_sizeof_long */ *** /tmp/,RCSt1a04188 Wed Aug 4 04:41:24 1993 --- gxccman.c Tue Jun 29 02:52:02 1993 *************** *** 255,262 **** pdev->width = iwidth; pdev->height = iheight; iraster = gdev_mem_raster(pdev); ! if ( iraster != 0 && iheight > dir->ccache.upper / iraster ) return 0; /* too big */ isize = gdev_mem_bitmap_size(pdev); icdsize = isize + cached_char_sizeof; /* Try allocating at the current position first. */ --- 255,265 ---- pdev->width = iwidth; pdev->height = iheight; iraster = gdev_mem_raster(pdev); ! if ( iraster != 0 && iheight > dir->ccache.upper / iraster ) { ! if_debug3('k', "[k]too big: %u > %u/%u\n", ! iheight, dir->ccache.upper, iraster); return 0; /* too big */ + } isize = gdev_mem_bitmap_size(pdev); icdsize = isize + cached_char_sizeof; /* Try allocating at the current position first. */