home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 5
/
FreshFish_July-August1994.bin
/
bbs
/
gnu
/
gs-2.6.1.4-src.lha
/
src
/
amiga
/
gs-2.6.1.4
/
gdevxini.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-01-27
|
32KB
|
982 lines
/* Copyright (C) 1989, 1992, 1993 Aladdin Enterprises. All rights reserved.
This file is part of Ghostscript.
Ghostscript is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY. No author or distributor accepts responsibility
to anyone for the consequences of using it or for whether it serves any
particular purpose or works at all, unless he says so in writing. Refer
to the Ghostscript General Public License for full details.
Everyone is granted permission to copy, modify and redistribute
Ghostscript, but only under the conditions described in the Ghostscript
General Public License. A copy of this license is supposed to have been
given to you along with Ghostscript so you can know your rights and
responsibilities. It should be in a file named COPYING. Among other
things, the copyright notice and this notice must be preserved on all
copies. */
/* gdevxini.c */
/* X Windows driver initialization for Ghostscript library */
#include "gx.h" /* for gx_bitmap; includes std.h */
#include "memory_.h"
#include "math_.h"
#include "x_.h"
#include "gxdevice.h"
#include "gdevx.h"
extern char *getenv(P1(const char *));
private XtResource resources[] = {
{XtNbackground, XtCBackground, XtRPixel, sizeof(Pixel),
XtOffsetOf(gx_device_X, background),
XtRString, (XtPointer)"XtDefaultBackground"},
{XtNborderColor, XtCBorderColor, XtRPixel, sizeof(Pixel),
XtOffsetOf(gx_device_X, borderColor),
XtRString, (XtPointer)"XtDefaultForeground"},
{XtNborderWidth, XtCBorderWidth, XtRDimension, sizeof(Dimension),
XtOffsetOf(gx_device_X, borderWidth),
XtRImmediate, (XtPointer)1},
{"dingbatFonts", "DingbatFonts", XtRString, sizeof(String),
XtOffsetOf(gx_device_X, dingbatFonts),
XtRString, "ZapfDingbats: -Adobe-ITC Zapf Dingbats-Medium-R-Normal--"},
{XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel),
XtOffsetOf(gx_device_X, foreground),
XtRString, (XtPointer)"XtDefaultForeground"},
{XtNgeometry, XtCGeometry, XtRString, sizeof(String),
XtOffsetOf(gx_device_X, geometry),
XtRString, NULL},
{"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},
{"palette", "Palette", XtRString, sizeof(String),
XtOffsetOf(gx_device_X, palette),
XtRString, "Color"},
/* I had to compress the whitespace out of the default string to
* satisfy certain balky compilers.
*/
{"regularFonts", "RegularFonts", XtRString, sizeof(String),
XtOffsetOf(gx_device_X, regularFonts),
XtRString, "\
AvantGarde-Book:-Adobe-ITC Avant Garde Gothic-Book-R-Normal--\n\
AvantGarde-BookOblique:-Adobe-ITC Avant Garde Gothic-Book-O-Normal--\n\
AvantGarde-Demi:-Adobe-ITC Avant Garde Gothic-Demi-R-Normal--\n\
AvantGarde-DemiOblique:-Adobe-ITC Avant Garde Gothic-Demi-O-Normal--\n\
Bookman-Demi:-Adobe-ITC Bookman-Demi-R-Normal--\n\
Bookman-DemiItalic:-Adobe-ITC Bookman-Demi-I-Normal--\n\
Bookman-Light:-Adobe-ITC Bookman-Light-R-Normal--\n\
Bookman-LightItalic:-Adobe-ITC Bookman-Light-I-Normal--\n\
Courier:-Adobe-Courier-Medium-R-Normal--\n\
Courier-Bold:-Adobe-Courier-Bold-R-Normal--\n\
Courier-BoldOblique:-Adobe-Courier-Bold-O-Normal--\n\
Courier-Oblique:-Adobe-Courier-Medium-O-Normal--\n\
Helvetica:-Adobe-Helvetica-Medium-R-Normal--\n\
Helvetica-Bold:-Adobe-Helvetica-Bold-R-Normal--\n\
Helvetica-BoldOblique:-Adobe-Helvetica-Bold-O-Normal--\n\
Helvetica-Narrow:-Adobe-Helvetica-Medium-R-Narrow--\n\
Helvetica-Narrow-Bold:-Adobe-Helvetica-Bold-R-Narrow--\n\
Helvetica-Narrow-BoldOblique:-Adobe-Helvetica-Bold-O-Narrow--\n\
Helvetica-Narrow-Oblique:-Adobe-Helvetica-Medium-O-Narrow--\n\
Helvetica-Oblique:-Adobe-Helvetica-Medium-O-Normal--\n\
NewCenturySchlbk-Bold:-Adobe-New Century Schoolbook-Bold-R-Normal--\n\
NewCenturySchlbk-BoldItalic:-Adobe-New Century Schoolbook-Bold-I-Normal--\n\
NewCenturySchlbk-Italic:-Adobe-New Century Schoolbook-Medium-I-Normal--\n\
NewCenturySchlbk-Roman:-Adobe-New Century Schoolbook-Medium-R-Normal--\n\
Palatino-Bold:-Adobe-Palatino-Bold-R-Normal--\n\
Palatino-BoldItalic:-Adobe-Palatino-Bold-I-Normal--\n\
Palatino-Italic:-Adobe-Palatino-Medium-I-Normal--\n\
Palatino-Roman:-Adobe-Palatino-Medium-R-Normal--\n\
Times-Bold:-Adobe-Times-Bold-R-Normal--\n\
Times-BoldItalic:-Adobe-Times-Bold-I-Normal--\n\
Times-Italic:-Adobe-Times-Medium-I-Normal--\n\
Times-Roman:-Adobe-Times-Medium-R-Normal--\n\
ZapfChancery-MediumItalic:-Adobe-ITC Zapf Chancery-Medium-I-Normal--"},
{"symbolFonts", "SymbolFonts", XtRString, sizeof(String),
XtOffsetOf(gx_device_X, symbolFonts),
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},
{"useFontExtensions", "UseFontExtensions", XtRBoolean, sizeof(Boolean),
XtOffsetOf(gx_device_X, useFontExtensions),
XtRImmediate, (XtPointer)True},
{"useScalableFonts", "UseScalableFonts", XtRBoolean, sizeof(Boolean),
XtOffsetOf(gx_device_X, useScalableFonts),
XtRImmediate, (XtPointer)True},
{"useXPutImage", "UseXPutImage", XtRBoolean, sizeof(Boolean),
XtOffsetOf(gx_device_X, useXPutImage),
XtRImmediate, (XtPointer)True},
{"useXSetTile", "UseXSetTile", XtRBoolean, sizeof(Boolean),
XtOffsetOf(gx_device_X, useXSetTile),
XtRImmediate, (XtPointer)True},
{"xResolution", "Resolution", XtRFloat, sizeof(float),
XtOffsetOf(gx_device_X, xResolution),
XtRString, (XtPointer)"0.0"},
{"yResolution", "Resolution", XtRFloat, sizeof(float),
XtOffsetOf(gx_device_X, yResolution),
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 {
Portrait = 0, /* Normal portrait orientation */
Landscape = 90, /* Normal landscape orientation */
Upsidedown = 180, /* Don't think this will be used much */
Seascape = 270 /* Landscape rotated the wrong way */
} orientation;
/* Forward references */
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)
{
XSizeHints sizehints;
char *window_id;
XEvent event;
XVisualInfo xvinfo;
int nitems;
XtAppContext app_con;
Widget toplevel;
Display *dpy;
int zero = 0;
#ifdef DEBUG
if (gs_debug['X']) {
extern int _Xdebug;
_Xdebug = 1;
}
#endif
if (!(xdev->dpy = XOpenDisplay((char *)NULL))) {
char *dispname = getenv("DISPLAY");
eprintf1("gs: Cannot open X display `%s'.\n",
(dispname == NULL ? "(null)" : dispname));
exit(1);
}
xdev->dest = 0;
if ((window_id = getenv("GHOSTVIEW"))) {
if (!(xdev->ghostview = sscanf(window_id, "%d %d",
&(xdev->win), &(xdev->dest)))) {
eprintf("gs: Cannot get Window ID from ghostview.\n");
exit(1);
}
}
if (xdev->ghostvi