1 /*******************************************************************
3 ** *********************************************************
8 ** * Initialization code of Pcl driver for the print server.
12 ** *********************************************************
14 ********************************************************************/
16 (c) Copyright 1996 Hewlett-Packard Company
17 (c) Copyright 1996 International Business Machines Corp.
18 (c) Copyright 1996 Sun Microsystems, Inc.
19 (c) Copyright 1996 Novell, Inc.
20 (c) Copyright 1996 Digital Equipment Corp.
21 (c) Copyright 1996 Fujitsu Limited
22 (c) Copyright 1996 Hitachi, Ltd.
24 Permission is hereby granted, free of charge, to any person obtaining a copy
25 of this software and associated documentation files (the "Software"), to deal
26 in the Software without restriction, including without limitation the rights
27 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
28 copies of the Software, and to permit persons to whom the Software is
29 furnished to do so, subject to the following conditions:
31 The above copyright notice and this permission notice shall be included in
32 all copies or substantial portions of the Software.
34 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
35 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
36 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
37 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
38 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
39 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
41 Except as contained in this notice, the names of the copyright holders shall
42 not be used in advertising or otherwise to promote the sale, use or other
43 dealings in this Software without prior written authorization from said
47 #ifdef HAVE_DIX_CONFIG_H
48 #include <dix-config.h>
53 #include <sys/types.h>
59 #include <X11/Xos.h> /* for unlink() */
61 #include "attributes.h"
64 #define MODELDIRNAME "/models"
66 static void AllocatePclPrivates(ScreenPtr pScreen
);
67 static int PclInitContext(XpContextPtr pCon
);
68 static Bool
PclDestroyContext(XpContextPtr pCon
);
70 int PclScreenPrivateIndex
;
71 int PclContextPrivateIndex
;
72 int PclPixmapPrivateIndex
;
73 int PclWindowPrivateIndex
;
74 int PclGCPrivateIndex
;
78 * The supported visuals on this screen
80 static VisualRec Visuals
[] =
82 { 1, StaticGray
, 1, 2, 1, 0, 0, 0, 0, 0, 0 },
83 { 2, PseudoColor
, 8, 256, 8, 0, 0, 0, 0, 0, 0 },
84 { 3, TrueColor
, 8, 256, 24, 0xFF0000, 0xFF00, 0xFF, 16, 8, 0 }
88 * The supported depths on this screen
90 static DepthRec Depths
[] =
98 * The supported visuals on this screen
100 static VisualRec Visuals
[] =
102 { 1, StaticGray
, 1, 2, 1, 0, 0, 0, 0, 0, 0}
106 * The supported depths on this screen
108 static DepthRec Depths
[] =
112 #endif /* XP_PCL_COLOR */
115 #define NUM_VISUALS(visuals) (sizeof(visuals) / sizeof(VisualRec))
116 #define NUM_DEPTHS(depths) (sizeof(depths) / sizeof(DepthRec))
119 PclCloseScreen(int index
,
122 PclScreenPrivPtr pPriv
= pScreen
->devPrivates
[PclScreenPrivateIndex
].ptr
;
124 pScreen
->CloseScreen
= pPriv
->CloseScreen
;
127 return (*pScreen
->CloseScreen
)(index
, pScreen
);
137 int maxRes
, xRes
, yRes
, maxDim
;
139 PclScreenPrivPtr pPriv
;
142 * Register this driver's InitContext function with the print
143 * extension. This is a bit sleazy, as the extension hasn't yet
144 * been initialized, but the extensionneeds to know this, and this
145 * seems the best time to provide the information.
148 XpRegisterInitFunc( pScreen
, "XP-PCL-COLOR", PclInitContext
);
150 XpRegisterInitFunc( pScreen
, "XP-PCL-MONO", PclInitContext
);
152 XpRegisterInitFunc( pScreen
, "XP-PCL-LJ3", PclInitContext
);
153 #endif /* XP_PCL_MONO */
156 * Create and fill in the devPrivate for the PCL driver.
158 AllocatePclPrivates(pScreen
);
161 (PclScreenPrivPtr
)pScreen
->devPrivates
[PclScreenPrivateIndex
].ptr
;
163 maxDim
= MAX( pScreen
->height
, pScreen
->width
);
164 xRes
= pScreen
->width
/ ( pScreen
->mmWidth
/ 25.4 );
165 yRes
= pScreen
->height
/ ( pScreen
->mmHeight
/ 25.4 );
166 maxRes
= MAX( xRes
, yRes
);
169 fbScreenInit( pScreen
, NULL
, maxDim
, maxDim
, maxRes
, maxRes
,
170 maxRes
, 8 ); /* XXX what's the depth here? */
171 /* Clean up the fields that we stomp (code taken from fbCloseScreen) */
172 for( i
= 0; (int) i
< pScreen
->numDepths
; i
++ )
173 xfree( pScreen
->allowedDepths
[i
].vids
);
174 xfree( pScreen
->allowedDepths
);
175 xfree( pScreen
->visuals
);
177 fbScreenInit( pScreen
, NULL
, maxDim
, maxDim
, maxRes
, maxRes
,
179 #endif /* XP_PCL_COLOR */
181 miInitializeBackingStore ( pScreen
);
183 pScreen
->defColormap
= FakeClientID(0);
184 pScreen
->blackPixel
= 1;
185 pScreen
->whitePixel
= 0;
187 pPriv
->CloseScreen
= pScreen
->CloseScreen
;
188 pScreen
->CloseScreen
= PclCloseScreen
;
190 pScreen
->QueryBestSize
= (QueryBestSizeProcPtr
)PclQueryBestSize
;
191 pScreen
->SaveScreen
= (SaveScreenProcPtr
)_XpBoolNoop
;
192 pScreen
->GetImage
= (GetImageProcPtr
)_XpVoidNoop
;
193 pScreen
->GetSpans
= (GetSpansProcPtr
)_XpVoidNoop
;
194 pScreen
->CreateWindow
= PclCreateWindow
;
195 pScreen
->DestroyWindow
= PclDestroyWindow
;
197 pScreen->PositionWindow = PclPositionWindow;
199 pScreen
->ChangeWindowAttributes
= PclChangeWindowAttributes
;
201 pScreen->RealizeWindow = PclMapWindow;
202 pScreen->UnrealizeWindow = PclUnmapWindow;
204 pScreen
->PaintWindowBackground
= PclPaintWindow
;
205 pScreen
->PaintWindowBorder
= PclPaintWindow
;
206 pScreen
->CopyWindow
= PclCopyWindow
; /* XXX Hard routine to write! */
208 pScreen
->CreatePixmap
= fbCreatePixmap
;
209 pScreen
->DestroyPixmap
= fbDestroyPixmap
;
210 pScreen
->RealizeFont
= PclRealizeFont
;
211 pScreen
->UnrealizeFont
= PclUnrealizeFont
;
212 pScreen
->CreateGC
= PclCreateGC
;
214 pScreen
->CreateColormap
= PclCreateColormap
;
215 pScreen
->DestroyColormap
= PclDestroyColormap
;
216 pScreen
->InstallColormap
= (InstallColormapProcPtr
)NoopDDA
;
217 pScreen
->UninstallColormap
= (UninstallColormapProcPtr
)NoopDDA
;
218 pScreen
->ListInstalledColormaps
= PclListInstalledColormaps
;
219 pScreen
->StoreColors
= PclStoreColors
;
221 pScreen->ResolveColor = PclResolveColor;
224 pScreen
->BitmapToRegion
= fbPixmapToRegion
;
226 pScreen
->ConstrainCursor
= PclConstrainCursor
;
227 pScreen
->CursorLimits
= PclCursorLimits
;
228 pScreen
->DisplayCursor
= PclDisplayCursor
;
229 pScreen
->RealizeCursor
= PclRealizeCursor
;
230 pScreen
->UnrealizeCursor
= PclUnrealizeCursor
;
231 pScreen
->RecolorCursor
= PclRecolorCursor
;
232 pScreen
->SetCursorPosition
= PclSetCursorPosition
;
234 pScreen
->visuals
= Visuals
;
235 pScreen
->numVisuals
= NUM_VISUALS( Visuals
);
236 pScreen
->allowedDepths
= Depths
;
237 pScreen
->numDepths
= NUM_DEPTHS( Depths
);
239 for( i
= 0; i
< NUM_DEPTHS( Depths
); i
++ )
241 pScreen
->allowedDepths
[i
].vids
=
242 (VisualID
*)xalloc( sizeof(VisualID
) );
243 pScreen
->allowedDepths
[i
].vids
[0] = i
+ 1;
247 pScreen
->rootVisual
= 2;
248 pScreen
->rootDepth
= 8;
250 pScreen
->rootVisual
= 1;
251 pScreen
->rootDepth
= 1;
252 #endif /* XP_PCL_COLOR */
254 pPriv
->colormaps
= NULL
;
255 PclCreateDefColormap( pScreen
);
261 AllocatePclPrivates(ScreenPtr pScreen
)
263 static unsigned long PclGeneration
= 0;
265 if((unsigned long) PclGeneration
!= serverGeneration
)
267 PclScreenPrivateIndex
= AllocateScreenPrivateIndex();
269 PclWindowPrivateIndex
= AllocateWindowPrivateIndex();
270 AllocateWindowPrivate( pScreen
, PclWindowPrivateIndex
,
271 sizeof( PclWindowPrivRec
) );
273 PclContextPrivateIndex
= XpAllocateContextPrivateIndex();
274 XpAllocateContextPrivate( PclContextPrivateIndex
,
275 sizeof( PclContextPrivRec
) );
277 PclGCPrivateIndex
= AllocateGCPrivateIndex();
278 AllocateGCPrivate( pScreen
, PclGCPrivateIndex
,
279 sizeof( PclGCPrivRec
) );
281 PclPixmapPrivateIndex
= AllocatePixmapPrivateIndex();
282 AllocatePixmapPrivate( pScreen
, PclPixmapPrivateIndex
,
283 sizeof( PclPixmapPrivRec
) );
285 PclGeneration
= serverGeneration
;
288 pScreen
->devPrivates
[PclScreenPrivateIndex
].ptr
= (pointer
)xalloc(
289 sizeof(PclScreenPrivRec
));
295 * Establish the appropriate values for a PrintContext used with the PCL
299 static char DOC_ATT_SUPP
[]="document-attributes-supported";
300 static char DOC_ATT_VAL
[]="document-format xp-listfonts-modes";
301 static char JOB_ATT_SUPP
[]="job-attributes-supported";
302 static char JOB_ATT_VAL
[]="";
303 static char PAGE_ATT_SUPP
[]="xp-page-attributes-supported";
304 static char PAGE_ATT_VAL
[]="content-orientation default-printer-resolution \
305 default-input-tray default-medium plex xp-listfonts-modes";
308 PclInitContext(XpContextPtr pCon
)
310 XpDriverFuncsPtr pFuncs
;
311 PclContextPrivPtr pConPriv
;
312 char *server
, *attrStr
;
318 XpOidMediumDiscreteSizeList
* ds_list
;
324 * Initialize the attribute store for this printer.
326 XpInitAttributes( pCon
);
329 * Initialize the function pointers
331 pFuncs
= &( pCon
->funcs
);
332 pFuncs
->StartJob
= PclStartJob
;
333 pFuncs
->EndJob
= PclEndJob
;
334 pFuncs
->StartDoc
= PclStartDoc
;
335 pFuncs
->EndDoc
= PclEndDoc
;
336 pFuncs
->StartPage
= PclStartPage
;
337 pFuncs
->EndPage
= PclEndPage
;
338 pFuncs
->PutDocumentData
= PclDocumentData
;
339 pFuncs
->GetDocumentData
= PclGetDocumentData
;
340 pFuncs
->GetAttributes
= PclGetAttributes
;
341 pFuncs
->SetAttributes
= PclSetAttributes
;
342 pFuncs
->AugmentAttributes
= PclAugmentAttributes
;
343 pFuncs
->GetOneAttribute
= PclGetOneAttribute
;
344 pFuncs
->DestroyContext
= PclDestroyContext
;
345 pFuncs
->GetMediumDimensions
= PclGetMediumDimensions
;
346 pFuncs
->GetReproducibleArea
= PclGetReproducibleArea
;
350 * Set up the context privates
353 (PclContextPrivPtr
)pCon
->devPrivates
[PclContextPrivateIndex
].ptr
;
355 pConPriv
->jobFileName
= (char *)NULL
;
356 pConPriv
->pageFileName
= (char *)NULL
;
357 pConPriv
->pJobFile
= (FILE *)NULL
;
358 pConPriv
->pPageFile
= (FILE *)NULL
;
359 pConPriv
->dash
= NULL
;
360 pConPriv
->validGC
= 0;
362 pConPriv
->getDocClient
= (ClientPtr
)NULL
;
363 pConPriv
->getDocBufSize
= 0;
364 modelID
= XpGetOneAttribute(pCon
, XPPrinterAttr
, "xp-model-identifier");
365 if ( (configDir
= XpGetConfigDir(False
)) != (char *) NULL
) {
366 pathName
= (char *)xalloc(strlen(configDir
) + strlen(MODELDIRNAME
) +
367 strlen(modelID
) + strlen("color.map") + 4);
369 sprintf(pathName
, "%s/%s/%s/%s", configDir
, MODELDIRNAME
, modelID
,
371 pConPriv
->ctbl
= PclReadMap(pathName
, &pConPriv
->ctbldim
);
375 pConPriv
->ctbl
= NULL
;
377 pConPriv
->ctbl
= NULL
;
381 * Initialize the spooling buffer for saving the figures temporary
382 * (LaserJet IIIs printers don't support the macro function which
383 * includes some HP-GL/2 commands.)
385 pConPriv
->fcount
= 0;
386 if ( !(pConPriv
->figures
= (char *)xalloc(1024)) )
387 pConPriv
->fcount_max
= 0;
389 pConPriv
->fcount_max
= 1024;
390 #endif /* XP_PCL_LJ3 */
393 * document-attributes-supported
395 server
= XpGetOneAttribute( pCon
, XPServerAttr
, DOC_ATT_SUPP
);
396 if( ( attrStr
= (char *)xalloc(strlen(server
) + strlen(DOC_ATT_SUPP
)
397 + strlen(DOC_ATT_VAL
) +
398 strlen(PAGE_ATT_VAL
) + 8 ) )
401 sprintf( attrStr
, "*%s:\t%s %s %s", DOC_ATT_SUPP
, server
,
402 DOC_ATT_VAL
, PAGE_ATT_VAL
);
403 XpAugmentAttributes( pCon
, XPPrinterAttr
, attrStr
);
407 * job-attributes-supported
409 server
= XpGetOneAttribute( pCon
, XPServerAttr
, JOB_ATT_SUPP
);
410 if( ( attrStr
= (char *)xalloc(strlen(server
) + strlen(JOB_ATT_SUPP
)
411 + strlen(JOB_ATT_VAL
) + 8 ) )
414 sprintf( attrStr
, "*%s:\t%s %s", JOB_ATT_SUPP
, server
, JOB_ATT_VAL
);
415 XpAugmentAttributes( pCon
, XPPrinterAttr
, attrStr
);
419 * xp-page-attributes-supported
421 server
= XpGetOneAttribute( pCon
, XPServerAttr
, PAGE_ATT_SUPP
);
422 if( ( attrStr
= (char *)xalloc(strlen(server
) + strlen(PAGE_ATT_SUPP
)
423 + strlen(PAGE_ATT_VAL
) + 8 ) )
426 sprintf( attrStr
, "*%s:\t%s %s", PAGE_ATT_SUPP
, server
, PAGE_ATT_VAL
);
427 XpAugmentAttributes( pCon
, XPPrinterAttr
, attrStr
);
431 * Validate the attribute pools
433 XpValidateAttributePool( pCon
, XPPrinterAttr
, &PclValidatePoolsRec
);
436 * Munge the reproducible areas to reflect the fact that PCL will not let
437 * me move the right or left margins closer than .25" to the edge of the
440 m
= XpGetMediumSSAttr( pCon
, XPPrinterAttr
,
441 xpoid_att_medium_source_sizes_supported
,
442 (const XpOidList
*) NULL
,
443 (const XpOidList
*) NULL
);
444 for( i
= 0; i
< XpOidMediumSSCount( m
); i
++ )
446 if( XpOidMediumSS_DISCRETE
== (m
->mss
)[i
].mstag
)
448 ds_list
= (m
->mss
)[i
].ms
.discrete
;
449 for( j
= 0; j
< ds_list
->count
; j
++ )
451 repro
= &(ds_list
->list
)[j
].assured_reproduction_area
;
452 page_size
= (ds_list
->list
)[j
].page_size
;
453 XpGetMediumMillimeters( page_size
, &width
, &height
);
455 if( repro
->minimum_x
< 6.35 )
456 repro
->minimum_x
= 6.35;
457 if( width
- repro
->maximum_x
< 6.35 )
458 repro
->maximum_x
= width
- 6.35;
462 XpPutMediumSSAttr( pCon
, XPPrinterAttr
,
463 xpoid_att_medium_source_sizes_supported
, m
);
464 XpOidMediumSSDelete( m
);
467 * Finish validating the attribute pools
470 XpValidateAttributePool( pCon
, XPDocAttr
, &PclValidatePoolsRec
);
471 XpValidateAttributePool( pCon
, XPJobAttr
, &PclValidatePoolsRec
);
472 XpValidateAttributePool( pCon
, XPPageAttr
, &PclValidatePoolsRec
);
475 * Clear out the colormap storage
477 pConPriv
->palettes
= NULL
;
483 PclDestroyContext(XpContextPtr pCon
)
485 PclContextPrivPtr pConPriv
= (PclContextPrivPtr
)
486 pCon
->devPrivates
[PclContextPrivateIndex
].ptr
;
487 PclPaletteMapPtr p
, t
;
488 PclCmapToContexts
*pCmap
;
490 PclScreenPrivPtr sPriv
;
491 PclContextListPtr con
, prevCon
, temp
;
495 * Clean up the temporary files
497 if( pConPriv
->pPageFile
!= (FILE *)NULL
)
499 fclose( pConPriv
->pPageFile
);
500 pConPriv
->pPageFile
= (FILE *)NULL
;
502 if( pConPriv
->pageFileName
!= (char *)NULL
)
504 unlink( pConPriv
->pageFileName
);
505 xfree( pConPriv
->pageFileName
);
506 pConPriv
->pageFileName
= (char *)NULL
;
509 if( pConPriv
->pJobFile
!= (FILE *)NULL
)
511 fclose( pConPriv
->pJobFile
);
512 pConPriv
->pJobFile
= NULL
;
514 if( pConPriv
->jobFileName
!= (char *)NULL
)
516 unlink( pConPriv
->jobFileName
);
517 xfree( pConPriv
->jobFileName
);
518 pConPriv
->jobFileName
= (char *)NULL
;
521 xfree( pConPriv
->dash
);
522 xfree(pConPriv
->ctbl
);
523 pConPriv
->ctbl
= NULL
;
525 xfree( pConPriv
->figures
);
526 #endif /* XP_PCL_LJ3 */
529 * Destroy the colormap<->palette mappings
531 p
= pConPriv
->palettes
;
538 pConPriv
->palettes
= NULL
;
541 * Remove the context from the screen-level colormap<->contexts mappings
543 screen
= screenInfo
.screens
[pCon
->screenNum
];
544 sPriv
= (PclScreenPrivPtr
)screen
->devPrivates
[PclScreenPrivateIndex
].ptr
;
545 pCmap
= sPriv
->colormaps
;
548 con
= pCmap
->contexts
;
553 if( con
->context
->contextID
== pCon
->contextID
)
558 prevCon
->next
= con
= con
->next
;
562 temp
= pCmap
->contexts
;
563 pCmap
->contexts
= con
= con
->next
;
574 XpDestroyAttributes(pCon
);
580 PclGetContextFromWindow(WindowPtr win
)
582 PclWindowPrivPtr pPriv
;
587 (PclWindowPrivPtr
)win
->devPrivates
[PclWindowPrivateIndex
].ptr
;
588 if( pPriv
->validContext
)
589 return pPriv
->context
;