#ifdef HAVE_DIX_CONFIG_H
#include <dix-config.h>
#endif
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include "Ps.h"
#include "mi.h"
#include "micmap.h"
#include "AttrValid.h"
#include "fb.h"
#include "windowstr.h"
#include "DiPrint.h"
static void AllocatePsPrivates(ScreenPtr pScreen);
static int PsInitContext(XpContextPtr pCon);
static int PsDestroyContext(XpContextPtr pCon);
int PsScreenPrivateIndex;
int PsContextPrivateIndex;
int PsPixmapPrivateIndex;
int PsWindowPrivateIndex;
#ifdef GLXEXT
extern void GlxWrapInitVisuals(miInitVisualsProcPtr *);
#endif
Bool
InitializePsDriver(ndx, pScreen, argc, argv)
int ndx;
ScreenPtr pScreen;
int argc;
char **argv;
{
#if 0
int maxXres, maxYres, maxWidth, maxHeight;
int maxRes, maxDim, numBytes;
PsScreenPrivPtr pPriv;
#endif
int nv,
nv_1bit,
nv_8bit,
nv_12bit,
nv_14bit,
nv_16bit,
nv_24bit,
nv_30bit;
int nd;
int defaultVisualIndex = -1;
VisualID *vids_1bit,
*vids_8bit,
*vids_12bit,
*vids_14bit,
*vids_16bit,
*vids_24bit,
*vids_30bit;
VisualPtr visuals;
DepthPtr depths;
VisualID defaultVisual;
int rootDepth;
XpRegisterInitFunc(pScreen, "XP-POSTSCRIPT", PsInitContext);
AllocatePsPrivates(pScreen);
#if 0
pPriv = (PsScreenPrivPtr)pScreen->devPrivates[PsScreenPrivateIndex].ptr;
pPriv->resDB = rmdb;
#endif
pScreen->defColormap = (Colormap) FakeClientID(0);
pScreen->blackPixel = 1;
pScreen->whitePixel = 0;
pScreen->QueryBestSize = (QueryBestSizeProcPtr)PsQueryBestSize;
pScreen->SaveScreen = (SaveScreenProcPtr)_XpBoolNoop;
pScreen->GetImage = (GetImageProcPtr)_XpVoidNoop;
pScreen->GetSpans = (GetSpansProcPtr)_XpVoidNoop;
pScreen->CreateWindow = PsCreateWindow;
pScreen->DestroyWindow = PsDestroyWindow;
pScreen->PositionWindow = PsPositionWindow;
pScreen->ChangeWindowAttributes = PsChangeWindowAttributes;
pScreen->RealizeWindow = PsMapWindow;
pScreen->UnrealizeWindow = PsUnmapWindow;
pScreen->PaintWindowBackground = PsPaintWindow;
pScreen->PaintWindowBorder = PsPaintWindow;
pScreen->CloseScreen = PsCloseScreen;
pScreen->CopyWindow = PsCopyWindow;
pScreen->CreatePixmap = PsCreatePixmap;
pScreen->DestroyPixmap = PsDestroyPixmap;
pScreen->RealizeFont = PsRealizeFont;
pScreen->UnrealizeFont = PsUnrealizeFont;
pScreen->CreateGC = PsCreateGC;
pScreen->CreateColormap = PsCreateColormap;
pScreen->DestroyColormap = PsDestroyColormap;
pScreen->InstallColormap = PsInstallColormap;
pScreen->UninstallColormap = PsUninstallColormap;
pScreen->ListInstalledColormaps = PsListInstalledColormaps;
pScreen->StoreColors = PsStoreColors;
pScreen->ResolveColor = PsResolveColor;
pScreen->BitmapToRegion = fbPixmapToRegion;
visuals = (VisualPtr) xalloc(16*sizeof(VisualRec));
depths = (DepthPtr) xalloc(16*sizeof(DepthRec));
vids_1bit = (VisualID *)xalloc(16*sizeof(VisualID));
vids_8bit = (VisualID *)xalloc(16*sizeof(VisualID));
vids_12bit = (VisualID *)xalloc(16*sizeof(VisualID));
vids_14bit = (VisualID *)xalloc(16*sizeof(VisualID));
vids_16bit = (VisualID *)xalloc(16*sizeof(VisualID));
vids_24bit = (VisualID *)xalloc(16*sizeof(VisualID));
vids_30bit = (VisualID *)xalloc(16*sizeof(VisualID));
nv = nv_1bit = nv_8bit = nv_12bit = nv_14bit = nv_16bit = nv_24bit = nv_30bit = nd = 0;
#ifdef PSOUT_USE_DEEPCOLOR
#ifdef DISABLED_FOR_NOW
visuals[nv].vid = FakeClientID(0);
visuals[nv].class = TrueColor;
visuals[nv].bitsPerRGBValue = 10;
visuals[nv].ColormapEntries = 1024;
visuals[nv].nplanes = 30;
visuals[nv].redMask = 0X3FF00000;
visuals[nv].greenMask = 0X000FFC00;
visuals[nv].blueMask = 0X000003FF;
visuals[nv].offsetRed = 20;
visuals[nv].offsetGreen = 10;
visuals[nv].offsetBlue = 0;
vids_30bit[nv_30bit] = visuals[nv].vid;
nv++; nv_30bit++;
#endif
#endif
visuals[nv].vid = FakeClientID(0);
visuals[nv].class = TrueColor;
visuals[nv].bitsPerRGBValue = 8;
visuals[nv].ColormapEntries = 256;
visuals[nv].nplanes = 24;
visuals[nv].redMask = 0X00FF0000;
visuals[nv].greenMask = 0X0000FF00;
visuals[nv].blueMask = 0X000000FF;
visuals[nv].offsetRed = 16;
visuals[nv].offsetGreen = 8;
visuals[nv].offsetBlue = 0;
vids_24bit[nv_24bit] = visuals[nv].vid;
nv++; nv_24bit++;
visuals[nv].vid = FakeClientID(0);
visuals[nv].class = TrueColor;
visuals[nv].bitsPerRGBValue = 6;
visuals[nv].ColormapEntries = 64;
visuals[nv].nplanes = 16;
visuals[nv].redMask = 0x0000f800;
visuals[nv].greenMask = 0x000007e0;
visuals[nv].blueMask = 0x0000001f;
visuals[nv].offsetRed = 11;
visuals[nv].offsetGreen = 5;
visuals[nv].offsetBlue = 0;
vids_16bit[nv_16bit] = visuals[nv].vid;
nv++; nv_16bit++;
#ifdef PSOUT_USE_DEEPCOLOR
visuals[nv].vid = FakeClientID(0);
visuals[nv].class = PseudoColor;
visuals[nv].bitsPerRGBValue = 12;
visuals[nv].ColormapEntries = 16384;
visuals[nv].nplanes = 14;
visuals[nv].redMask = 0x0;
visuals[nv].greenMask = 0x0;
visuals[nv].blueMask = 0x0;
visuals[nv].offsetRed = 0x0;
visuals[nv].offsetGreen = 0x0;
visuals[nv].offsetBlue = 0x0;
vids_14bit[nv_14bit] = visuals[nv].vid;
nv++; nv_14bit++;
visuals[nv].vid = FakeClientID(0);
visuals[nv].class = PseudoColor;
visuals[nv].bitsPerRGBValue = 12;
visuals[nv].ColormapEntries = 4096;
visuals[nv].nplanes = 12;
visuals[nv].redMask = 0x0;
visuals[nv].greenMask = 0x0;
visuals[nv].blueMask = 0x0;
visuals[nv].offsetRed = 0x0;
visuals[nv].offsetGreen = 0x0;
visuals[nv].offsetBlue = 0x0;
vids_12bit[nv_12bit] = visuals[nv].vid;
defaultVisualIndex = nv;
nv++; nv_12bit++;
visuals[nv].vid = FakeClientID(0);
visuals[nv].class = GrayScale;
visuals[nv].bitsPerRGBValue = 12;
visuals[nv].ColormapEntries = 4096;
visuals[nv].nplanes = 12;
visuals[nv].redMask = 0x0;
visuals[nv].greenMask = 0x0;
visuals[nv].blueMask = 0x0;
visuals[nv].offsetRed = 0x0;
visuals[nv].offsetGreen = 0x0;
visuals[nv].offsetBlue = 0x0;
vids_12bit[nv_12bit] = visuals[nv].vid;
nv++; nv_12bit++;
visuals[nv].vid = FakeClientID(0);
visuals[nv].class = StaticGray;
visuals[nv].bitsPerRGBValue = 12;
visuals[nv].ColormapEntries = 4096;
visuals[nv].nplanes = 12;
visuals[nv].redMask = 0x0;
visuals[nv].greenMask = 0x0;
visuals[nv].blueMask = 0x0;
visuals[nv].offsetRed = 0x0;
visuals[nv].offsetGreen = 0x0;
visuals[nv].offsetBlue = 0x0;
vids_12bit[nv_12bit] = visuals[nv].vid;
nv++; nv_12bit++;
#endif
visuals[nv].vid = FakeClientID(0);
visuals[nv].class = PseudoColor;
visuals[nv].bitsPerRGBValue = 8;
visuals[nv].ColormapEntries = 256;
visuals[nv].nplanes = 8;
visuals[nv].redMask = 0x0;
visuals[nv].greenMask = 0x0;
visuals[nv].blueMask = 0x0;
visuals[nv].offsetRed = 0x0;
visuals[nv].offsetGreen = 0x0;
visuals[nv].offsetBlue = 0x0;
vids_8bit[nv_8bit] = visuals[nv].vid;
#ifndef PSOUT_USE_DEEPCOLOR
defaultVisualIndex = nv;
#endif
nv++; nv_8bit++;
visuals[nv].vid = FakeClientID(0);
visuals[nv].class = GrayScale;
visuals[nv].bitsPerRGBValue = 8;
visuals[nv].ColormapEntries = 256;
visuals[nv].nplanes = 8;
visuals[nv].redMask = 0x0;
visuals[nv].greenMask = 0x0;
visuals[nv].blueMask = 0x0;
visuals[nv].offsetRed = 0x0;
visuals[nv].offsetGreen = 0x0;
visuals[nv].offsetBlue = 0x0;
vids_8bit[nv_8bit] = visuals[nv].vid;
nv++; nv_8bit++;
visuals[nv].vid = FakeClientID(0);
visuals[nv].class = StaticGray;
visuals[nv].bitsPerRGBValue = 8;
visuals[nv].ColormapEntries = 256;
visuals[nv].nplanes = 8;
visuals[nv].redMask = 0x0;
visuals[nv].greenMask = 0x0;
visuals[nv].blueMask = 0x0;
visuals[nv].offsetRed = 0x0;
visuals[nv].offsetGreen = 0x0;
visuals[nv].offsetBlue = 0x0;
vids_8bit[nv_8bit] = visuals[nv].vid;
nv++; nv_8bit++;
visuals[nv].vid = FakeClientID(0);
visuals[nv].class = StaticGray;
visuals[nv].bitsPerRGBValue = 1;
visuals[nv].ColormapEntries = 2;
visuals[nv].nplanes = 1;
visuals[nv].redMask = 0x0;
visuals[nv].greenMask = 0x0;
visuals[nv].blueMask = 0x0;
visuals[nv].offsetRed = 0x0;
visuals[nv].offsetGreen = 0x0;
visuals[nv].offsetBlue = 0x0;
vids_1bit[nv_1bit] = visuals[nv].vid;
nv++; nv_1bit++;
if( nv_30bit > 0 )
{
depths[nd].depth = 30;
depths[nd].numVids = nv_30bit;
depths[nd].vids = vids_30bit;
nd++;
}
if( nv_24bit > 0 )
{
depths[nd].depth = 24;
depths[nd].numVids = nv_24bit;
depths[nd].vids = vids_24bit;
nd++;
}
if( nv_16bit > 0 )
{
depths[nd].depth = 16;
depths[nd].numVids = nv_16bit;
depths[nd].vids = vids_16bit;
nd++;
}
if( nv_14bit > 0 )
{
depths[nd].depth = 14;
depths[nd].numVids = nv_14bit;
depths[nd].vids = vids_14bit;
nd++;
}
if( nv_12bit > 0 )
{
depths[nd].depth = 12;
depths[nd].numVids = nv_12bit;
depths[nd].vids = vids_12bit;
nd++;
}
if( nv_8bit > 0 )
{
depths[nd].depth = 8;
depths[nd].numVids = nv_8bit;
depths[nd].vids = vids_8bit;
nd++;
}
if( nv_1bit > 0 )
{
depths[nd].depth = 1;
depths[nd].numVids = nv_1bit;
depths[nd].vids = vids_1bit;
nd++;
}
defaultVisual = visuals[defaultVisualIndex].vid;
rootDepth = visuals[defaultVisualIndex].nplanes;
#ifdef GLXEXT
{
miInitVisualsProcPtr proc = NULL;
GlxWrapInitVisuals(&proc);
proc(&visuals, &depths, &nv, &nd,
&rootDepth, &defaultVisual, 0, 0, 0);
}
#endif
miScreenInit(pScreen, (pointer)0,
pScreen->width, pScreen->height,
(int) (pScreen->width / (pScreen->mmWidth / 25.40)),
(int) (pScreen->height / (pScreen->mmHeight / 25.40)),
0, rootDepth, nd,
depths, defaultVisual, nv, visuals);
if( miCreateDefColormap(pScreen)==FALSE ) return FALSE;
return TRUE;
}
static void
AllocatePsPrivates(ScreenPtr pScreen)
{
static unsigned long PsGeneration = 0;
if((unsigned long)PsGeneration != serverGeneration)
{
PsScreenPrivateIndex = AllocateScreenPrivateIndex();
PsWindowPrivateIndex = AllocateWindowPrivateIndex();
AllocateWindowPrivate(pScreen, PsWindowPrivateIndex,
sizeof(PsWindowPrivRec));
PsContextPrivateIndex = XpAllocateContextPrivateIndex();
XpAllocateContextPrivate(PsContextPrivateIndex,
sizeof(PsContextPrivRec));
PsPixmapPrivateIndex = AllocatePixmapPrivateIndex();
AllocatePixmapPrivate(pScreen, PsPixmapPrivateIndex,
sizeof(PsPixmapPrivRec));
PsGeneration = serverGeneration;
}
pScreen->devPrivates[PsScreenPrivateIndex].ptr =
(pointer)xalloc(sizeof(PsScreenPrivRec));
}
static char DOC_ATT_SUPP[]="document-attributes-supported";
static char DOC_ATT_VAL[]="document-format xp-listfonts-modes";
static char JOB_ATT_SUPP[]="job-attributes-supported";
static char JOB_ATT_VAL[]="";
static char PAGE_ATT_SUPP[]="xp-page-attributes-supported";
static char PAGE_ATT_VAL[]="content-orientation default-printer-resolution \
default-input-tray default-medium plex xp-listfonts-modes";
static int
PsInitContext(pCon)
XpContextPtr pCon;
{
XpDriverFuncsPtr pFuncs;
PsContextPrivPtr pConPriv;
char *server, *attrStr;
XpInitAttributes(pCon);
pFuncs = &(pCon->funcs);
pFuncs->StartJob = PsStartJob;
pFuncs->EndJob = PsEndJob;
pFuncs->StartDoc = PsStartDoc;
pFuncs->EndDoc = PsEndDoc;
pFuncs->StartPage = PsStartPage;
pFuncs->EndPage = PsEndPage;
pFuncs->PutDocumentData = PsDocumentData;
pFuncs->GetDocumentData = PsGetDocumentData;
pFuncs->GetAttributes = PsGetAttributes;
pFuncs->SetAttributes = PsSetAttributes;
pFuncs->AugmentAttributes = PsAugmentAttributes;
pFuncs->GetOneAttribute = PsGetOneAttribute;
pFuncs->DestroyContext = PsDestroyContext;
pFuncs->GetMediumDimensions = PsGetMediumDimensions;
pFuncs->GetReproducibleArea = PsGetReproducibleArea;
pFuncs->SetImageResolution = PsSetImageResolution;
pConPriv =
(PsContextPrivPtr)pCon->devPrivates[PsContextPrivateIndex].ptr;
memset(pConPriv, 0, sizeof(PsContextPrivRec));
pConPriv->jobFileName = (char *)NULL;
pConPriv->pJobFile = (FILE *)NULL;
pConPriv->dash = (unsigned char *)NULL;
pConPriv->validGC = 0;
pConPriv->getDocClient = (ClientPtr)NULL;
pConPriv->getDocBufSize = 0;
pConPriv->pPsOut = NULL;
pConPriv->fontInfoRecords = NULL;
pConPriv->fontTypeInfoRecords = NULL;
server = XpGetOneAttribute( pCon, XPServerAttr, DOC_ATT_SUPP );
if ((attrStr = (char *) xalloc(strlen(server) +
strlen(DOC_ATT_SUPP) + strlen(DOC_ATT_VAL)
+ strlen(PAGE_ATT_VAL) + 8)) == NULL)
{
return BadAlloc;
}
sprintf(attrStr, "*%s:\t%s %s %s",
DOC_ATT_SUPP, server, DOC_ATT_VAL, PAGE_ATT_VAL);
XpAugmentAttributes( pCon, XPPrinterAttr, attrStr);
xfree(attrStr);
server = XpGetOneAttribute( pCon, XPServerAttr, JOB_ATT_SUPP );
if ((attrStr = (char *) xalloc(strlen(server) + strlen(JOB_ATT_SUPP) +
strlen(JOB_ATT_VAL) + 8)) == NULL)
{
return BadAlloc;
}
sprintf(attrStr, "*%s:\t%s %s", JOB_ATT_SUPP, server, JOB_ATT_VAL);
XpAugmentAttributes(pCon, XPPrinterAttr, attrStr);
xfree(attrStr);
server = XpGetOneAttribute( pCon, XPServerAttr, PAGE_ATT_SUPP );
if ((attrStr = (char *) xalloc(strlen(server) + strlen(PAGE_ATT_SUPP) +
strlen(PAGE_ATT_VAL) + 8)) == NULL)
{
return BadAlloc;
}
sprintf(attrStr, "*%s:\t%s %s", PAGE_ATT_SUPP, server, PAGE_ATT_VAL);
XpAugmentAttributes(pCon, XPPrinterAttr, attrStr);
xfree(attrStr);
XpValidateAttributePool(pCon, XPPrinterAttr, &PsValidatePoolsRec);
XpValidateAttributePool(pCon, XPDocAttr, &PsValidatePoolsRec);
XpValidateAttributePool(pCon, XPJobAttr, &PsValidatePoolsRec);
XpValidateAttributePool(pCon, XPPageAttr, &PsValidatePoolsRec);
return Success;
}
static Bool
PsDestroyContext(pCon)
XpContextPtr pCon;
{
PsContextPrivPtr pConPriv =
(PsContextPrivPtr)pCon->devPrivates[PsContextPrivateIndex].ptr;
if( pConPriv->pJobFile!=(FILE *)NULL )
{
fclose(pConPriv->pJobFile);
pConPriv->pJobFile = NULL;
}
if( pConPriv->jobFileName!=(char *)NULL )
{
unlink(pConPriv->jobFileName);
xfree(pConPriv->jobFileName);
pConPriv->jobFileName = (char *)NULL;
}
PsFreeFontInfoRecords(pConPriv);
memset(pConPriv, 0, sizeof(PsContextPrivRec));
return Success;
}
XpContextPtr
PsGetContextFromWindow(win)
WindowPtr win;
{
PsWindowPrivPtr pPriv;
while( win )
{
pPriv = (PsWindowPrivPtr)win->devPrivates[PsWindowPrivateIndex].ptr;
if( pPriv->validContext ) return pPriv->context;
win = win->parent;
}
return NULL;
}