1
/* $Xorg: PclInit.c,v 1.3 2000/08/17 19:48:08 cpqbld Exp $ */
2
/*******************************************************************
4
** *********************************************************
9
** * Initialization code of Pcl driver for the print server.
13
** *********************************************************
15
********************************************************************/
17
(c) Copyright 1996 Hewlett-Packard Company
18
(c) Copyright 1996 International Business Machines Corp.
19
(c) Copyright 1996 Sun Microsystems, Inc.
20
(c) Copyright 1996 Novell, Inc.
21
(c) Copyright 1996 Digital Equipment Corp.
22
(c) Copyright 1996 Fujitsu Limited
23
(c) Copyright 1996 Hitachi, Ltd.
25
Permission is hereby granted, free of charge, to any person obtaining a copy
26
of this software and associated documentation files (the "Software"), to deal
27
in the Software without restriction, including without limitation the rights
28
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
29
copies of the Software, and to permit persons to whom the Software is
30
furnished to do so, subject to the following conditions:
32
The above copyright notice and this permission notice shall be included in
33
all copies or substantial portions of the Software.
35
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
36
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
37
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
38
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
39
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
40
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
42
Except as contained in this notice, the names of the copyright holders shall
43
not be used in advertising or otherwise to promote the sale, use or other
44
dealings in this Software without prior written authorization from said
49
(c) Copyright 1996 Hewlett-Packard Company
50
(c) Copyright 1996 International Business Machines Corp.
51
(c) Copyright 1996 Sun Microsystems, Inc.
52
(c) Copyright 1996 Novell, Inc.
53
(c) Copyright 1996 Digital Equipment Corp.
54
(c) Copyright 1996 Fujitsu Limited
55
(c) Copyright 1996 Hitachi, Ltd.
57
Permission is hereby granted, free of charge, to any person obtaining a copy
58
of this software and associated documentation files (the "Software"), to deal
59
in the Software without restriction, including without limitation the rights
60
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
61
copies of the Software, and to permit persons to whom the Software is
62
furnished to do so, subject to the following conditions:
64
The above copyright notice and this permission notice shall be included in
65
all copies or substantial portions of the Software.
67
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
68
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
69
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
70
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
71
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
72
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
74
Except as contained in this notice, the names of the copyright holders shall
75
not be used in advertising or otherwise to promote the sale, use or other
76
dealings in this Software without prior written authorization from said
79
/* $XFree86: xc/programs/Xserver/Xprint/pcl/PclInit.c,v 1.11 2001/12/21 21:02:05 dawes Exp $ */
81
#ifdef HAVE_DIX_CONFIG_H
82
#include <dix-config.h>
87
#include <sys/types.h>
93
#include <X11/Xos.h> /* for unlink() */
95
#include "attributes.h"
98
#define MODELDIRNAME "/models"
100
static void AllocatePclPrivates(ScreenPtr pScreen);
101
static int PclInitContext(XpContextPtr pCon);
102
static Bool PclDestroyContext(XpContextPtr pCon);
104
int PclScreenPrivateIndex;
105
int PclContextPrivateIndex;
106
int PclPixmapPrivateIndex;
107
int PclWindowPrivateIndex;
108
int PclGCPrivateIndex;
112
* The supported visuals on this screen
114
static VisualRec Visuals[] =
116
{ 1, StaticGray, 1, 2, 1, 0, 0, 0, 0, 0, 0 },
117
{ 2, PseudoColor, 8, 256, 8, 0, 0, 0, 0, 0, 0 },
118
{ 3, TrueColor, 8, 256, 24, 0xFF0000, 0xFF00, 0xFF, 16, 8, 0 }
122
* The supported depths on this screen
124
static DepthRec Depths[] =
132
* The supported visuals on this screen
134
static VisualRec Visuals[] =
136
{ 1, StaticGray, 1, 2, 1, 0, 0, 0, 0, 0, 0}
140
* The supported depths on this screen
142
static DepthRec Depths[] =
146
#endif /* XP_PCL_COLOR */
149
#define NUM_VISUALS(visuals) (sizeof(visuals) / sizeof(VisualRec))
150
#define NUM_DEPTHS(depths) (sizeof(depths) / sizeof(DepthRec))
153
PclCloseScreen(int index,
156
PclScreenPrivPtr pPriv = pScreen->devPrivates[PclScreenPrivateIndex].ptr;
158
pScreen->CloseScreen = pPriv->CloseScreen;
161
return (*pScreen->CloseScreen)(index, pScreen);
171
int maxRes, xRes, yRes, maxDim;
173
PclScreenPrivPtr pPriv;
176
* Register this driver's InitContext function with the print
177
* extension. This is a bit sleazy, as the extension hasn't yet
178
* been initialized, but the extensionneeds to know this, and this
179
* seems the best time to provide the information.
182
XpRegisterInitFunc( pScreen, "XP-PCL-COLOR", PclInitContext );
184
XpRegisterInitFunc( pScreen, "XP-PCL-MONO", PclInitContext );
186
XpRegisterInitFunc( pScreen, "XP-PCL-LJ3", PclInitContext );
187
#endif /* XP_PCL_MONO */
190
* Create and fill in the devPrivate for the PCL driver.
192
AllocatePclPrivates(pScreen);
195
(PclScreenPrivPtr)pScreen->devPrivates[PclScreenPrivateIndex].ptr;
197
maxDim = MAX( pScreen->height, pScreen->width );
198
xRes = pScreen->width / ( pScreen->mmWidth / 25.4 );
199
yRes = pScreen->height / ( pScreen->mmHeight / 25.4 );
200
maxRes = MAX( xRes, yRes );
203
cfbScreenInit( pScreen, NULL, maxDim, maxDim, maxRes, maxRes,
206
* Clean up the fields that we stomp (code taken from cfbCloseScreen)
208
for( i = 0; (int) i < pScreen->numDepths; i++ )
209
xfree( pScreen->allowedDepths[i].vids );
210
xfree( pScreen->allowedDepths );
211
xfree( pScreen->visuals );
213
mfbScreenInit( pScreen, NULL, maxDim, maxDim, maxRes, maxRes,
215
#endif /* XP_PCL_COLOR */
217
miInitializeBackingStore ( pScreen );
219
pScreen->defColormap = FakeClientID(0);
220
pScreen->blackPixel = 1;
221
pScreen->whitePixel = 0;
223
pPriv->CloseScreen = pScreen->CloseScreen;
224
pScreen->CloseScreen = PclCloseScreen;
226
pScreen->QueryBestSize = (QueryBestSizeProcPtr)PclQueryBestSize;
227
pScreen->SaveScreen = (SaveScreenProcPtr)_XpBoolNoop;
228
pScreen->GetImage = (GetImageProcPtr)_XpVoidNoop;
229
pScreen->GetSpans = (GetSpansProcPtr)_XpVoidNoop;
230
pScreen->CreateWindow = PclCreateWindow;
231
pScreen->DestroyWindow = PclDestroyWindow;
233
pScreen->PositionWindow = PclPositionWindow;
235
pScreen->ChangeWindowAttributes = PclChangeWindowAttributes;
237
pScreen->RealizeWindow = PclMapWindow;
238
pScreen->UnrealizeWindow = PclUnmapWindow;
240
pScreen->PaintWindowBackground = PclPaintWindow;
241
pScreen->PaintWindowBorder = PclPaintWindow;
242
pScreen->CopyWindow = PclCopyWindow; /* XXX Hard routine to write! */
244
pScreen->CreatePixmap = PclCreatePixmap;
245
pScreen->DestroyPixmap = PclDestroyPixmap;
246
pScreen->RealizeFont = PclRealizeFont;
247
pScreen->UnrealizeFont = PclUnrealizeFont;
248
pScreen->CreateGC = PclCreateGC;
250
pScreen->CreateColormap = PclCreateColormap;
251
pScreen->DestroyColormap = PclDestroyColormap;
252
pScreen->InstallColormap = (InstallColormapProcPtr)NoopDDA;
253
pScreen->UninstallColormap = (UninstallColormapProcPtr)NoopDDA;
254
pScreen->ListInstalledColormaps = PclListInstalledColormaps;
255
pScreen->StoreColors = PclStoreColors;
257
pScreen->ResolveColor = PclResolveColor;
260
pScreen->BitmapToRegion = mfbPixmapToRegion;
262
pScreen->ConstrainCursor = PclConstrainCursor;
263
pScreen->CursorLimits = PclCursorLimits;
264
pScreen->DisplayCursor = PclDisplayCursor;
265
pScreen->RealizeCursor = PclRealizeCursor;
266
pScreen->UnrealizeCursor = PclUnrealizeCursor;
267
pScreen->RecolorCursor = PclRecolorCursor;
268
pScreen->SetCursorPosition = PclSetCursorPosition;
270
pScreen->visuals = Visuals;
271
pScreen->numVisuals = NUM_VISUALS( Visuals );
272
pScreen->allowedDepths = Depths;
273
pScreen->numDepths = NUM_DEPTHS( Depths );
275
for( i = 0; i < NUM_DEPTHS( Depths ); i++ )
277
pScreen->allowedDepths[i].vids =
278
(VisualID *)xalloc( sizeof(VisualID ) );
279
pScreen->allowedDepths[i].vids[0] = i + 1;
283
pScreen->rootVisual = 2;
284
pScreen->rootDepth = 8;
286
pScreen->rootVisual = 1;
287
pScreen->rootDepth = 1;
288
#endif /* XP_PCL_COLOR */
290
pPriv->colormaps = NULL;
291
PclCreateDefColormap( pScreen );
297
AllocatePclPrivates(ScreenPtr pScreen)
299
static unsigned long PclGeneration = 0;
301
if((unsigned long) PclGeneration != serverGeneration)
303
PclScreenPrivateIndex = AllocateScreenPrivateIndex();
305
PclWindowPrivateIndex = AllocateWindowPrivateIndex();
306
AllocateWindowPrivate( pScreen, PclWindowPrivateIndex,
307
sizeof( PclWindowPrivRec ) );
309
PclContextPrivateIndex = XpAllocateContextPrivateIndex();
310
XpAllocateContextPrivate( PclContextPrivateIndex,
311
sizeof( PclContextPrivRec ) );
313
PclGCPrivateIndex = AllocateGCPrivateIndex();
314
AllocateGCPrivate( pScreen, PclGCPrivateIndex,
315
sizeof( PclGCPrivRec ) );
317
PclPixmapPrivateIndex = AllocatePixmapPrivateIndex();
318
AllocatePixmapPrivate( pScreen, PclPixmapPrivateIndex,
319
sizeof( PclPixmapPrivRec ) );
321
PclGeneration = serverGeneration;
324
pScreen->devPrivates[PclScreenPrivateIndex].ptr = (pointer)xalloc(
325
sizeof(PclScreenPrivRec));
331
* Establish the appropriate values for a PrintContext used with the PCL
335
static char DOC_ATT_SUPP[]="document-attributes-supported";
336
static char DOC_ATT_VAL[]="document-format xp-listfonts-modes";
337
static char JOB_ATT_SUPP[]="job-attributes-supported";
338
static char JOB_ATT_VAL[]="";
339
static char PAGE_ATT_SUPP[]="xp-page-attributes-supported";
340
static char PAGE_ATT_VAL[]="content-orientation default-printer-resolution \
341
default-input-tray default-medium plex xp-listfonts-modes";
344
PclInitContext(XpContextPtr pCon)
346
XpDriverFuncsPtr pFuncs;
347
PclContextPrivPtr pConPriv;
348
char *server, *attrStr;
354
XpOidMediumDiscreteSizeList* ds_list;
360
* Initialize the attribute store for this printer.
362
XpInitAttributes( pCon );
365
* Initialize the function pointers
367
pFuncs = &( pCon->funcs );
368
pFuncs->StartJob = PclStartJob;
369
pFuncs->EndJob = PclEndJob;
370
pFuncs->StartDoc = PclStartDoc;
371
pFuncs->EndDoc = PclEndDoc;
372
pFuncs->StartPage = PclStartPage;
373
pFuncs->EndPage = PclEndPage;
374
pFuncs->PutDocumentData = PclDocumentData;
375
pFuncs->GetDocumentData = PclGetDocumentData;
376
pFuncs->GetAttributes = PclGetAttributes;
377
pFuncs->SetAttributes = PclSetAttributes;
378
pFuncs->AugmentAttributes = PclAugmentAttributes;
379
pFuncs->GetOneAttribute = PclGetOneAttribute;
380
pFuncs->DestroyContext = PclDestroyContext;
381
pFuncs->GetMediumDimensions = PclGetMediumDimensions;
382
pFuncs->GetReproducibleArea = PclGetReproducibleArea;
386
* Set up the context privates
389
(PclContextPrivPtr)pCon->devPrivates[PclContextPrivateIndex].ptr;
391
pConPriv->jobFileName = (char *)NULL;
392
pConPriv->pageFileName = (char *)NULL;
393
pConPriv->pJobFile = (FILE *)NULL;
394
pConPriv->pPageFile = (FILE *)NULL;
395
pConPriv->dash = NULL;
396
pConPriv->validGC = 0;
398
pConPriv->getDocClient = (ClientPtr)NULL;
399
pConPriv->getDocBufSize = 0;
400
modelID = XpGetOneAttribute(pCon, XPPrinterAttr, "xp-model-identifier");
401
if ( (configDir = XpGetConfigDir(False)) != (char *) NULL ) {
402
pathName = (char *)xalloc(strlen(configDir) + strlen(MODELDIRNAME) +
403
strlen(modelID) + strlen("color.map") + 4);
405
sprintf(pathName, "%s/%s/%s/%s", configDir, MODELDIRNAME, modelID,
407
pConPriv->ctbl = PclReadMap(pathName, &pConPriv->ctbldim);
411
pConPriv->ctbl = NULL;
413
pConPriv->ctbl = NULL;
417
* Initialize the spooling buffer for saving the figures temporary
418
* (LaserJet IIIs printers don't support the macro function which
419
* includes some HP-GL/2 commands.)
421
pConPriv->fcount = 0;
422
if ( !(pConPriv->figures = (char *)xalloc(1024)) )
423
pConPriv->fcount_max = 0;
425
pConPriv->fcount_max = 1024;
426
#endif /* XP_PCL_LJ3 */
429
* document-attributes-supported
431
server = XpGetOneAttribute( pCon, XPServerAttr, DOC_ATT_SUPP );
432
if( ( attrStr = (char *)xalloc(strlen(server) + strlen(DOC_ATT_SUPP)
433
+ strlen(DOC_ATT_VAL) +
434
strlen(PAGE_ATT_VAL) + 8 ) )
437
sprintf( attrStr, "*%s:\t%s %s %s", DOC_ATT_SUPP, server,
438
DOC_ATT_VAL, PAGE_ATT_VAL );
439
XpAugmentAttributes( pCon, XPPrinterAttr, attrStr );
443
* job-attributes-supported
445
server = XpGetOneAttribute( pCon, XPServerAttr, JOB_ATT_SUPP );
446
if( ( attrStr = (char *)xalloc(strlen(server) + strlen(JOB_ATT_SUPP)
447
+ strlen(JOB_ATT_VAL) + 8 ) )
450
sprintf( attrStr, "*%s:\t%s %s", JOB_ATT_SUPP, server, JOB_ATT_VAL );
451
XpAugmentAttributes( pCon, XPPrinterAttr, attrStr );
455
* xp-page-attributes-supported
457
server = XpGetOneAttribute( pCon, XPServerAttr, PAGE_ATT_SUPP );
458
if( ( attrStr = (char *)xalloc(strlen(server) + strlen(PAGE_ATT_SUPP)
459
+ strlen(PAGE_ATT_VAL) + 8 ) )
462
sprintf( attrStr, "*%s:\t%s %s", PAGE_ATT_SUPP, server, PAGE_ATT_VAL );
463
XpAugmentAttributes( pCon, XPPrinterAttr, attrStr );
467
* Validate the attribute pools
469
XpValidateAttributePool( pCon, XPPrinterAttr, &PclValidatePoolsRec );
472
* Munge the reproducible areas to reflect the fact that PCL will not let
473
* me move the right or left margins closer than .25" to the edge of the
476
m = XpGetMediumSSAttr( pCon, XPPrinterAttr,
477
xpoid_att_medium_source_sizes_supported,
478
(const XpOidList*) NULL,
479
(const XpOidList*) NULL );
480
for( i = 0; i < XpOidMediumSSCount( m ); i++ )
482
if( XpOidMediumSS_DISCRETE == (m->mss)[i].mstag )
484
ds_list = (m->mss)[i].ms.discrete;
485
for( j = 0; j < ds_list->count; j++ )
487
repro = &(ds_list->list)[j].assured_reproduction_area;
488
page_size = (ds_list->list)[j].page_size;
489
XpGetMediumMillimeters( page_size, &width, &height );
491
if( repro->minimum_x < 6.35 )
492
repro->minimum_x = 6.35;
493
if( width - repro->maximum_x < 6.35 )
494
repro->maximum_x = width - 6.35;
498
XpPutMediumSSAttr( pCon, XPPrinterAttr,
499
xpoid_att_medium_source_sizes_supported, m );
500
XpOidMediumSSDelete( m );
503
* Finish validating the attribute pools
506
XpValidateAttributePool( pCon, XPDocAttr, &PclValidatePoolsRec );
507
XpValidateAttributePool( pCon, XPJobAttr, &PclValidatePoolsRec );
508
XpValidateAttributePool( pCon, XPPageAttr, &PclValidatePoolsRec );
511
* Clear out the colormap storage
513
pConPriv->palettes = NULL;
519
PclDestroyContext(XpContextPtr pCon)
521
PclContextPrivPtr pConPriv = (PclContextPrivPtr)
522
pCon->devPrivates[PclContextPrivateIndex].ptr;
523
PclPaletteMapPtr p, t;
524
PclCmapToContexts *pCmap;
526
PclScreenPrivPtr sPriv;
527
PclContextListPtr con, prevCon, temp;
531
* Clean up the temporary files
533
if( pConPriv->pPageFile != (FILE *)NULL )
535
fclose( pConPriv->pPageFile );
536
pConPriv->pPageFile = (FILE *)NULL;
538
if( pConPriv->pageFileName != (char *)NULL )
540
unlink( pConPriv->pageFileName );
541
xfree( pConPriv->pageFileName );
542
pConPriv->pageFileName = (char *)NULL;
545
if( pConPriv->pJobFile != (FILE *)NULL )
547
fclose( pConPriv->pJobFile );
548
pConPriv->pJobFile = NULL;
550
if( pConPriv->jobFileName != (char *)NULL )
552
unlink( pConPriv->jobFileName );
553
xfree( pConPriv->jobFileName );
554
pConPriv->jobFileName = (char *)NULL;
557
xfree( pConPriv->dash );
558
xfree(pConPriv->ctbl);
559
pConPriv->ctbl = NULL;
561
xfree( pConPriv->figures );
562
#endif /* XP_PCL_LJ3 */
565
* Destroy the colormap<->palette mappings
567
p = pConPriv->palettes;
574
pConPriv->palettes = NULL;
577
* Remove the context from the screen-level colormap<->contexts mappings
579
screen = screenInfo.screens[pCon->screenNum];
580
sPriv = (PclScreenPrivPtr)screen->devPrivates[PclScreenPrivateIndex].ptr;
581
pCmap = sPriv->colormaps;
584
con = pCmap->contexts;
589
if( con->context->contextID == pCon->contextID )
594
prevCon->next = con = con->next;
598
temp = pCmap->contexts;
599
pCmap->contexts = con = con->next;
610
XpDestroyAttributes(pCon);
616
PclGetContextFromWindow(WindowPtr win)
618
PclWindowPrivPtr pPriv;
623
(PclWindowPrivPtr)win->devPrivates[PclWindowPrivateIndex].ptr;
624
if( pPriv->validContext )
625
return pPriv->context;