home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / g / gs252src.zip / GS252 / GDEVXINI.C < prev    next >
C/C++ Source or Header  |  1992-09-09  |  18KB  |  546 lines

  1. /* Copyright (C) 1989, 1992 Aladdin Enterprises.  All rights reserved.
  2.    Distributed by Free Software Foundation, Inc.
  3.  
  4. This file is part of Ghostscript.
  5.  
  6. Ghostscript is distributed in the hope that it will be useful, but
  7. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  8. to anyone for the consequences of using it or for whether it serves any
  9. particular purpose or works at all, unless he says so in writing.  Refer
  10. to the Ghostscript General Public License for full details.
  11.  
  12. Everyone is granted permission to copy, modify and redistribute
  13. Ghostscript, but only under the conditions described in the Ghostscript
  14. General Public License.  A copy of this license is supposed to have been
  15. given to you along with Ghostscript so you can know your rights and
  16. responsibilities.  It should be in a file named COPYING.  Among other
  17. things, the copyright notice and this notice must be preserved on all
  18. copies.  */
  19.  
  20. /* gdevxini.c */
  21. /* X Windows driver initialization for Ghostscript library */
  22. #include "gx.h"            /* for gx_bitmap; includes std.h */
  23. #include "memory_.h"
  24. #include "x_.h"
  25. #include "gxdevice.h"
  26. #include "gdevx.h"
  27.  
  28. extern char *getenv(P1(const char *));
  29. extern double atof(P1(const char *));
  30.  
  31. /* Define whether to use a backing pixmap to handle expose events. */
  32. /* Note that this is a variable rather than a #define. */
  33. /* Note also that it is consulted each time we open an X device. */
  34. private int use_backing = 1;
  35.  
  36. /* Define default window parameters. */
  37. /* Some of these can be set in the makefile. */
  38.  
  39. #ifndef PROGRAM_NAME
  40. #  define PROGRAM_NAME "Ghostscript"
  41. #endif
  42.  
  43. #define ARG_BORDER_WIDTH "borderWidth"
  44. #define DEFAULT_BORDER_WIDTH 1
  45.  
  46. #define ARG_BORDER_COLOR "borderColor"
  47. #define DEFAULT_BORDER_COLOR  pixel_black
  48.  
  49. #define ARG_GEOMETRY "geometry"
  50.  
  51. #define DEFAULT_X_POSITION 0
  52. #define DEFAULT_Y_POSITION 0
  53.  
  54. #define ARG_X_RESOLUTION "xResolution"
  55. #define ARG_Y_RESOLUTION "yResolution"
  56.  
  57. /* Define constants for orientation from ghostview */
  58. /* Number represents clockwise rotation of the paper in degrees */
  59. typedef enum {
  60.   Portrait = 0,        /* Normal portrait orientation */
  61.   Landscape = 90,    /* Normal landscape orientation */
  62.   Upsidedown = 180,    /* Don't think this will be used much */
  63.   Seascape = 270    /* Landscape rotated the wrong way */
  64. } orientation;
  65.  
  66. /* Forward references */
  67. void gdev_x_clear_window(P1(gx_device_X *));
  68.  
  69. /* Open the X device */
  70. int
  71. gdev_x_open(register gx_device_X *xdev)
  72. {       XSizeHints sizehints;
  73.     static XWMHints wm_hints = {InputHint,0};    /*<--- Avoid input focus*/
  74.     int border_width;
  75.     char *border_width_str, *border_color_str;
  76.     unsigned long border_color;
  77.     char *geometry;
  78.     char *window_id;
  79.     XColor screen_color, exact_color;
  80.     XSetWindowAttributes xswa;
  81.     XEvent event;
  82.     XVisualInfo xvinfo;
  83.     int nitems;
  84. #if HaveStdCMap
  85.         XStandardColormap *scmap, *sp;
  86.         Atom prop;
  87. #endif
  88. #ifdef DEBUG
  89. if ( gs_debug['X'] )
  90.     { extern int _Xdebug;
  91.       _Xdebug = 1;
  92.     }
  93. #endif
  94.     if ( !(xdev->dpy = XOpenDisplay((char *)NULL)) )
  95.       { char *dispname = getenv("DISPLAY");
  96.         eprintf1("gs: Cannot open X display `%s'.\n",
  97.              (dispname == NULL ? "(null)" : dispname));
  98.         exit(1);
  99.       }
  100.     xdev->dest = 0;
  101.     if ( (window_id = getenv("GHOSTVIEW")) )
  102.       { if ( !(xdev->ghostview = sscanf(window_id, "%d %d",
  103.                         &(xdev->win), &(xdev->dest))) )
  104.           { eprintf("gs: Cannot get Window from ghostview.\n");
  105.             exit(1);
  106.           }
  107.       }
  108.     if ( xdev->ghostview )
  109.       { XWindowAttributes attrib;
  110.         Atom type;
  111.         int format;
  112.         unsigned long nitems, bytes_after;
  113.         char *buf;
  114.         Atom ghostview_atom = XInternAtom(xdev->dpy, "GHOSTVIEW", False);
  115.         if ( XGetWindowAttributes(xdev->dpy, xdev->win, &attrib) )
  116.           { xdev->scr = attrib.screen;
  117.             xvinfo.visual = attrib.visual;
  118.         xdev->cmap = attrib.colormap;
  119.             xdev->width = attrib.width;
  120.         xdev->height = attrib.height;
  121.           }
  122.         /* Delete property if explicit dest is given */
  123.         if ( XGetWindowProperty(xdev->dpy, xdev->win, ghostview_atom, 0, 
  124.                     256, (xdev->dest != 0), XA_STRING,
  125.                     &type, &format, &nitems, &bytes_after,
  126.                     (unsigned char **)&buf) == 0 )
  127.           { int llx, lly, urx, ury;
  128.         int left_margin = 0, bottom_margin = 0;
  129.         int right_margin = 0, top_margin = 0;
  130.         /* We declare page_orientation as an int so that we can */
  131.         /* use an int * to reference it for sscanf; compilers */
  132.         /* might be tempted to use less space to hold it if */
  133.         /* it were declared as an orientation. */
  134.         int /*orientation*/ page_orientation;
  135.         float xppp, yppp;    /* pixels per point */
  136.         nitems = sscanf(buf,
  137.                 "%d %d %d %d %d %d %f %f %d %d %d %d %d %d",
  138.                         &(xdev->bpixmap), &page_orientation,
  139.                         &llx, &lly, &urx, &ury,
  140.                         &(xdev->x_pixels_per_inch),
  141.                 &(xdev->y_pixels_per_inch),
  142.                 &left_margin, &bottom_margin,
  143.                 &right_margin, &top_margin,
  144.                 &(xdev->width), &(xdev->height));
  145.         if ( (!xdev->dest && !(nitems == 8 || nitems == 12)) ||
  146.              (xdev->dest && nitems != 14) )
  147.           { eprintf("gs: Cannot get ghostview property.\n");
  148.             exit(1);
  149.           }
  150.         if ( xdev->dest && xdev->bpixmap )
  151.           { eprintf("gs: Both destination and backing pixmap specified.\n");
  152.             exit(1);
  153.           }
  154.         xppp = xdev->x_pixels_per_inch / 72.0;
  155.         yppp = xdev->y_pixels_per_inch / 72.0;
  156.         switch (page_orientation)
  157.           {
  158.           case Portrait:
  159.             xdev->initial_matrix.xx = xppp;
  160.             xdev->initial_matrix.xy = 0.0;
  161.             xdev->initial_matrix.yx = 0.0;
  162.             xdev->initial_matrix.yy = -yppp;
  163.             xdev->initial_matrix.tx = -llx * xppp;
  164.             xdev->initial_matrix.ty = ury * yppp;
  165.             break;
  166.           case Landscape:
  167.             xdev->initial_matrix.xx = 0.0;
  168.             xdev->initial_matrix.xy = yppp;
  169.             xdev->initial_matrix.yx = xppp;
  170.             xdev->initial_matrix.yy = 0.0;
  171.             xdev->initial_matrix.tx = -lly * xppp;
  172.             xdev->initial_matrix.ty = -llx * yppp;
  173.             break;
  174.           case Upsidedown:
  175.             xdev->initial_matrix.xx = -xppp;
  176.             xdev->initial_matrix.xy = 0.0;
  177.             xdev->initial_matrix.yx = 0.0;
  178.             xdev->initial_matrix.yy = yppp;
  179.             xdev->initial_matrix.tx = urx * xppp;
  180.             xdev->initial_matrix.ty = -lly * yppp;
  181.             break;
  182.           case Seascape:
  183.             xdev->initial_matrix.xx = 0.0;
  184.             xdev->initial_matrix.xy = -yppp;
  185.             xdev->initial_matrix.yx = -xppp;
  186.             xdev->initial_matrix.yy = 0.0;
  187.             xdev->initial_matrix.tx = ury * xppp;
  188.             xdev->initial_matrix.ty = urx * yppp;
  189.             break;
  190.         }
  191.  
  192.         /* The following sets the imageable area according to the */
  193.         /* bounding box and margins sent by ghostview.            */
  194.         xdev->l_margin = (llx - left_margin) / 72.0;
  195.         xdev->b_margin = (lly - bottom_margin) / 72.0;
  196.         xdev->r_margin = xdev->width / xdev->x_pixels_per_inch -
  197.                  (urx + right_margin) / 72.0;
  198.         xdev->t_margin = xdev->height / xdev->y_pixels_per_inch -
  199.                  (ury + top_margin) / 72.0;
  200.           }
  201.         else
  202.           { eprintf("gs: Cannot get ghostview property.\n");
  203.         exit(1);
  204.           }
  205.       }
  206.     else
  207.       { Screen *scr = DefaultScreenOfDisplay(xdev->dpy);
  208.         xdev->scr = scr;
  209.         xvinfo.visual = DefaultVisualOfScreen(scr);
  210.         xdev->cmap = DefaultColormapOfScreen(scr);
  211.       }
  212.  
  213.     xvinfo.visualid = XVisualIDFromVisual(xvinfo.visual);
  214.     xdev->vinfo = XGetVisualInfo(xdev->dpy, VisualIDMask, &xvinfo, &nitems);
  215.     if ( xdev->vinfo == NULL )
  216.       { eprintf("gs: Cannot get XVisualInfo.\n");
  217.         exit(1);
  218.       }
  219.     xdev->color_info.num_components =
  220.       ((xdev->vinfo->class != StaticGray) &&
  221.        (xdev->vinfo->class != GrayScale) ? 3 : 1);
  222.  
  223. #if HaveStdCMap
  224.     if ( gx_device_has_color(xdev) )
  225.       { if ( xvinfo.visual == DefaultVisualOfScreen(xdev->scr) )
  226.           prop = XA_RGB_DEFAULT_MAP;
  227.         else
  228.           prop = XA_RGB_BEST_MAP;
  229.       }
  230.     else
  231.       prop = XA_RGB_GRAY_MAP;
  232.  
  233.     if ( XGetRGBColormaps(xdev->dpy, RootWindowOfScreen(xdev->scr),
  234.                   &scmap, &nitems, prop) )
  235.       { int i;
  236.         for (i = 0, sp = scmap; i < nitems; i++, sp++)
  237.           { if ( (xdev->ghostview && (xdev->cmap == sp->colormap)) ||
  238.              (!xdev->ghostview && (xdev->vinfo->visualid ==
  239.                         sp->visualid)) )
  240.           { xdev->std_cmap = sp;
  241.             break;
  242.           }
  243.           }
  244.       }
  245.  
  246.     if ( xdev->std_cmap )
  247.       { xdev->cmap = xdev->std_cmap->colormap;
  248.         /* Acquire white and black pixel values. */
  249.         if ( xdev->cmap == DefaultColormapOfScreen(xdev->scr) )
  250.          { pixel_black = BlackPixelOfScreen(xdev->scr);
  251.            pixel_white = WhitePixelOfScreen(xdev->scr);
  252.          }
  253.         else
  254.          {
  255. #define pixv(v)\
  256.   color_index_to_pixel((*xdev->procs->map_rgb_color)((gx_device *)xdev,\
  257.                               v, v, v))
  258.            pixel_black = pixv(0);
  259.            pixel_white = pixv(gx_max_color_value);
  260. #undef pixv
  261.          }
  262.         if ( gx_device_has_color(xdev) )
  263.           { /* Set the color_info in the device structure. */
  264.         xdev->color_info.max_gray =
  265.           xdev->color_info.max_rgb =
  266.             min(xdev->std_cmap->red_max,
  267.             min(xdev->std_cmap->green_max,
  268.                 xdev->std_cmap->blue_max));
  269.         xdev->color_info.depth = 8;    /* arbitrary */
  270.         xdev->color_info.dither_gray =
  271.           xdev->color_info.dither_rgb =
  272.             xdev->color_info.max_rgb + 1;
  273.           }
  274.         else
  275.           { xdev->color_info.max_gray = xdev->std_cmap->red_max +
  276.           xdev->std_cmap->green_max + xdev->std_cmap->blue_max;
  277.         xdev->color_info.depth = 8;    /* arbitrary */
  278.         xdev->color_info.dither_gray = xdev->color_info.max_gray + 1;
  279.           }
  280.       }
  281.     else
  282. #endif
  283.       { if ( xdev->cmap == DefaultColormapOfScreen(xdev->scr) )
  284.           { pixel_black = BlackPixelOfScreen(xdev->scr);
  285.         pixel_white = WhitePixelOfScreen(xdev->scr);
  286.           }
  287.         else
  288.           { XColor xc;
  289.         xc.red = xc.green = xc.blue = 0;
  290.             XAllocColor(xdev->dpy, xdev->cmap, &xc);
  291.         pixel_black = xc.pixel;
  292.         xc.red = xc.green = xc.blue = ~(ushort)0;
  293.             XAllocColor(xdev->dpy, xdev->cmap, &xc);
  294.         pixel_white = xc.pixel;
  295.           }
  296.  
  297.         /* Figure out monochrome vs. color */
  298.         if ( gx_device_has_color(xdev) )
  299.           /* Just do primary colors for now */
  300.           { XColor xc;
  301.         int i;
  302.         for ( i = 1; i < 7; i++ )
  303.           { xc.red = (i & 4 ? ~(ushort)0 : 0);
  304.             xc.green = (i & 2 ? ~(ushort)0 : 0);
  305.             xc.blue = (i & 1 ? ~(ushort)0 : 0);
  306.             XAllocColor(xdev->dpy, xdev->cmap, &xc);
  307.             xdev->colors[i] = xc.pixel;
  308.           }
  309.         xdev->color_info.max_rgb = 1;
  310.         xdev->color_info.dither_rgb = 2;
  311.         xdev->color_info.depth = 8;
  312.           }
  313.         else
  314.           { int i;
  315.             for ( i = 1; i < 7; i++ )
  316.           xdev->colors[i] = pixel_white;
  317.           }
  318.       }
  319.  
  320.     /* Check for a pixel value equal to gx_no_color_index. */
  321.     if (
  322. #if HaveStdCMap
  323.         !xdev->std_cmap &&
  324. #endif
  325.         (pixel_black == gx_no_color_index ||
  326.          pixel_white == gx_no_color_index)
  327.         )
  328.       { /* Pick a non-zero value guaranteed not to map any primary */
  329.         /* color to gx_no_color_index. */
  330.         xdev->pixel_fix = 0x100000ff ^
  331.           (xdev->colors[1] & 2) ^ (xdev->colors[2] & 4) ^
  332.           (xdev->colors[3] & 8) ^ (xdev->colors[4] & 16) ^
  333.           (xdev->colors[5] & 32) ^ (xdev->colors[6] & 64);
  334.       }
  335.     else
  336.       { xdev->pixel_fix = 0;
  337.       }
  338.  
  339.     if ( !xdev->ghostview )
  340.       { /*
  341.          * Figure out the resolution of our screen; 25.4 is the
  342.          * number of millimeters in an inch.  The only reason for
  343.          * allowing the user to specify the resolution is that
  344.          * X servers commonly lie about it (and about the screen size).
  345.          * We assume that the server is more likely to lie about
  346.          * the resolution than about the pixel size of the screen.
  347.          * Don't do any of this if the resolution was set from the
  348.          * command line (detected by resolution != FAKE_RES).
  349.          */
  350.  
  351.         if ( xdev->x_pixels_per_inch == FAKE_RES )
  352.           { char *x_res_str = XGetDefault(xdev->dpy, PROGRAM_NAME,
  353.                           ARG_X_RESOLUTION);
  354.         char *y_res_str = XGetDefault(xdev->dpy, PROGRAM_NAME,
  355.                           ARG_Y_RESOLUTION);
  356.         float x_res, y_res;
  357.         if ( x_res_str != NULL && y_res_str != NULL )
  358.           { x_res = atof(x_res_str);
  359.             y_res = atof(y_res_str);
  360.           }
  361.         else
  362.           { int screen_width = WidthOfScreen(xdev->scr);
  363.             int screen_height = HeightOfScreen(xdev->scr);
  364.             x_res = 25.4 * screen_width / WidthMMOfScreen(xdev->scr);
  365.             y_res = 25.4 * screen_height / HeightMMOfScreen(xdev->scr);
  366.             if ( x_res * DEFAULT_WIDTH_INCHES > screen_width ||
  367.             y_res * DEFAULT_HEIGHT_INCHES > screen_height
  368.             )
  369.               { /* Force a full page to fit on the screen */
  370.             /* by adjusting the server's claimed resolution. */
  371.             x_res = (screen_width - 32) / (float)DEFAULT_WIDTH_INCHES;
  372.             y_res = (screen_height - 32) / (float)DEFAULT_HEIGHT_INCHES;
  373.             x_res = y_res = min(x_res, y_res);
  374.               }
  375.           }
  376.         xdev->x_pixels_per_inch = x_res;
  377.         xdev->y_pixels_per_inch = y_res;
  378.           }
  379.  
  380.         /* Get defaults from the database. */
  381.         border_width_str = XGetDefault(xdev->dpy, PROGRAM_NAME,
  382.                        ARG_BORDER_WIDTH);
  383.  
  384.         border_width = (border_width_str == NULL ? DEFAULT_BORDER_WIDTH :
  385.                 atoi(border_width_str));
  386.  
  387.         border_color_str = XGetDefault(xdev->dpy, PROGRAM_NAME,
  388.                        ARG_BORDER_COLOR);
  389.  
  390.         border_color = (border_color_str == NULL ||
  391.                  !XAllocNamedColor(xdev->dpy, xdev->cmap, 
  392.                            border_color_str, 
  393.                            &screen_color, &exact_color) ?
  394.                 DEFAULT_BORDER_COLOR :
  395.                 screen_color.pixel);
  396.  
  397.         sizehints.x = DEFAULT_X_POSITION;
  398.         sizehints.y = DEFAULT_Y_POSITION;
  399.         sizehints.width =
  400.                   (int)(xdev->x_pixels_per_inch * DEFAULT_WIDTH_INCHES);
  401.         sizehints.height =
  402.                   (int)(xdev->y_pixels_per_inch * DEFAULT_HEIGHT_INCHES);
  403.         sizehints.flags = 0;
  404.  
  405.         geometry = XGetDefault(xdev->dpy, PROGRAM_NAME, ARG_GEOMETRY);
  406.  
  407.         if (geometry != NULL)
  408.            {    /*
  409.              * Note that border_width must be set first.  We can't use
  410.              * scr, because that is a Screen*, and XGeometry wants
  411.              * the screen number.
  412.              */
  413.             char gstr[40];
  414.             int bitmask;
  415.             sprintf(gstr, "%dx%d+%d+%d", sizehints.width,
  416.                 sizehints.height, sizehints.x, sizehints.y);
  417.             bitmask = XGeometry(xdev->dpy, DefaultScreen(xdev->dpy),
  418.                     geometry, gstr, border_width,
  419.                     1, 1, /* ``Font'' width and height. */
  420.                     0, 0, /* Interior padding. */
  421.                     &sizehints.x, &sizehints.y,
  422.                     &sizehints.width, &sizehints.height);
  423.  
  424.             if (bitmask & (XValue | YValue))
  425.                 sizehints.flags |= USPosition;
  426.  
  427.             if (bitmask & (WidthValue | HeightValue))
  428.                 sizehints.flags |= USSize;
  429.            }
  430.  
  431.         if ( xdev->width == (int)(FAKE_RES*DEFAULT_WIDTH_INCHES) )
  432.           xdev->width = sizehints.width,
  433.           xdev->height = sizehints.height;
  434.         else            /* set from command line */
  435.           sizehints.width = xdev->width,
  436.           sizehints.height = xdev->height;
  437.  
  438.         gx_default_get_initial_matrix((gx_device *)xdev,
  439.                       &(xdev->initial_matrix));
  440.  
  441.         xswa.event_mask = ExposureMask;
  442.         xswa.background_pixel = pixel_black;
  443.         xswa.border_pixel = border_color;
  444.         xswa.colormap = xdev->cmap;
  445.         xdev->win = XCreateWindow(xdev->dpy, RootWindowOfScreen(xdev->scr),
  446.                       sizehints.x, sizehints.y, /* upper left */
  447.                       sizehints.width, sizehints.height,
  448.                       border_width,
  449.                       xdev->vinfo->depth,
  450.                       InputOutput, /* class */
  451.                       xdev->vinfo->visual, /* visual */
  452.                       CWEventMask | CWBackPixel |
  453.                       CWBorderPixel | CWColormap,
  454.                       &xswa);
  455.         XChangeProperty(xdev->dpy, xdev->win, XA_WM_NAME, XA_STRING, 8,
  456.                 PropModeReplace, (const unsigned char *)PROGRAM_NAME,
  457.                 strlen(PROGRAM_NAME));
  458.         XSetNormalHints(xdev->dpy, xdev->win, &sizehints);
  459.         XSetWMHints(xdev->dpy, xdev->win, &wm_hints); /*<--- Avoid input focus*/
  460.     }
  461.  
  462.     xdev->ht.pixmap = (Pixmap)0;
  463.     xdev->ht.id = gx_no_bitmap_id;;
  464.     xdev->fill_style = FillSolid;
  465.     xdev->function = GXcopy;
  466.  
  467.     /* Set up a graphics context */
  468.     xdev->gc = XCreateGC(xdev->dpy, xdev->win, 0, (XGCValues *)NULL);
  469.     XSetFunction(xdev->dpy, xdev->gc, GXcopy);
  470.     XSetLineAttributes(xdev->dpy, xdev->gc, 0,
  471.                LineSolid, CapButt, JoinMiter);
  472.  
  473.     gdev_x_clear_window(xdev);
  474.  
  475.     if ( !xdev->ghostview )
  476.       { /* Make the window appear. */
  477.         XMapWindow(xdev->dpy, xdev->win);
  478.  
  479.         /* Before anything else, do a flush and wait for */
  480.         /* an exposure event. */
  481.         XFlush(xdev->dpy);
  482.         XNextEvent(xdev->dpy, &event);
  483.       }
  484.     else
  485.       { /* Create an unmapped window, that the window manager will ignore.
  486.          * This invisible window will be used to receive "next page"
  487.          * events from ghostview */
  488.         XSetWindowAttributes attributes;
  489.         attributes.override_redirect = True;
  490.         xdev->mwin = XCreateWindow(xdev->dpy, RootWindowOfScreen(xdev->scr),
  491.                        0, 0, 1, 1, 0, CopyFromParent,
  492.                        CopyFromParent, CopyFromParent,
  493.                        CWOverrideRedirect, &attributes);
  494.         xdev->next = XInternAtom(xdev->dpy, "NEXT", False);
  495.         xdev->page = XInternAtom(xdev->dpy, "PAGE", False);
  496.         xdev->done = XInternAtom(xdev->dpy, "DONE", False);
  497.       }
  498.  
  499.     xdev->ht.no_pixmap = XCreatePixmap(xdev->dpy, xdev->win, 1, 1,
  500.                        xdev->vinfo->depth);
  501.  
  502.     XSync(xdev->dpy, 0);
  503.     return 0;
  504. }
  505.  
  506. /* Allocate the backing pixmap, if any, and clear the window. */
  507. void
  508. gdev_x_clear_window(gx_device_X *xdev)
  509. {    if ( !xdev->ghostview )
  510.       { if ( use_backing )
  511.           xdev->bpixmap =
  512.         XCreatePixmap(xdev->dpy, xdev->win,
  513.                   xdev->width, xdev->height,
  514.                   xdev->vinfo->depth);
  515.         else
  516.           xdev->bpixmap = (Pixmap)0;
  517.       }
  518.  
  519.     /* Clear the destination pixmap to avoid initializing with garbage. */
  520.     if ( xdev->dest != (Pixmap)0 )
  521.       { XSetForeground(xdev->dpy, xdev->gc, pixel_white);
  522.         XFillRectangle(xdev->dpy, xdev->dest, xdev->gc,
  523.                0, 0, xdev->width, xdev->height);
  524.       }
  525.     else
  526.       { xdev->dest = (xdev->bpixmap != (Pixmap)0 ?
  527.               xdev->bpixmap : (Pixmap)xdev->win);
  528.       }
  529.  
  530.     /* Clear the background pixmap to avoid initializing with garbage. */
  531.     if ( xdev->bpixmap != (Pixmap)0 )
  532.       { if ( !xdev->ghostview )
  533.           XSetWindowBackgroundPixmap(xdev->dpy, xdev->win, xdev->bpixmap);
  534.         XSetForeground(xdev->dpy, xdev->gc, pixel_white);
  535.         XFillRectangle(xdev->dpy, xdev->bpixmap, xdev->gc,
  536.                0, 0, xdev->width, xdev->height);
  537.       }
  538.  
  539.     /* Initialize foreground and background colors */
  540.     xdev->back_color = pixel_white;
  541.     XSetBackground(xdev->dpy, xdev->gc, pixel_white);
  542.     xdev->fore_color = pixel_white;
  543.     XSetForeground(xdev->dpy, xdev->gc, pixel_white);
  544.     xdev->colors_or = xdev->colors_and = pixel_white;
  545. }
  546.