aboutsummaryrefslogtreecommitdiff
path: root/nx-X11/programs/Xserver/Xprint/ps
diff options
context:
space:
mode:
authorReinhard Tartler <siretart@tauware.de>2011-10-10 17:43:39 +0200
committerReinhard Tartler <siretart@tauware.de>2011-10-10 17:43:39 +0200
commitf4092abdf94af6a99aff944d6264bc1284e8bdd4 (patch)
tree2ac1c9cc16ceb93edb2c4382c088dac5aeafdf0f /nx-X11/programs/Xserver/Xprint/ps
parenta840692edc9c6d19cd7c057f68e39c7d95eb767d (diff)
downloadnx-libs-f4092abdf94af6a99aff944d6264bc1284e8bdd4.tar.gz
nx-libs-f4092abdf94af6a99aff944d6264bc1284e8bdd4.tar.bz2
nx-libs-f4092abdf94af6a99aff944d6264bc1284e8bdd4.zip
Imported nx-X11-3.1.0-1.tar.gznx-X11/3.1.0-1
Summary: Imported nx-X11-3.1.0-1.tar.gz Keywords: Imported nx-X11-3.1.0-1.tar.gz into Git repository
Diffstat (limited to 'nx-X11/programs/Xserver/Xprint/ps')
-rw-r--r--nx-X11/programs/Xserver/Xprint/ps/Imakefile89
-rw-r--r--nx-X11/programs/Xserver/Xprint/ps/Ps.h590
-rw-r--r--nx-X11/programs/Xserver/Xprint/ps/PsArc.c182
-rw-r--r--nx-X11/programs/Xserver/Xprint/ps/PsArea.c393
-rw-r--r--nx-X11/programs/Xserver/Xprint/ps/PsAttVal.c290
-rw-r--r--nx-X11/programs/Xserver/Xprint/ps/PsAttr.c117
-rw-r--r--nx-X11/programs/Xserver/Xprint/ps/PsCache.c328
-rw-r--r--nx-X11/programs/Xserver/Xprint/ps/PsColor.c258
-rw-r--r--nx-X11/programs/Xserver/Xprint/ps/PsDef.h97
-rw-r--r--nx-X11/programs/Xserver/Xprint/ps/PsFTFonts.c85
-rw-r--r--nx-X11/programs/Xserver/Xprint/ps/PsFonts.c876
-rw-r--r--nx-X11/programs/Xserver/Xprint/ps/PsGC.c419
-rw-r--r--nx-X11/programs/Xserver/Xprint/ps/PsImageUtil.c329
-rw-r--r--nx-X11/programs/Xserver/Xprint/ps/PsInit.c667
-rw-r--r--nx-X11/programs/Xserver/Xprint/ps/PsLine.c192
-rw-r--r--nx-X11/programs/Xserver/Xprint/ps/PsMisc.c324
-rw-r--r--nx-X11/programs/Xserver/Xprint/ps/PsPixel.c157
-rw-r--r--nx-X11/programs/Xserver/Xprint/ps/PsPixmap.c617
-rw-r--r--nx-X11/programs/Xserver/Xprint/ps/PsPolygon.c262
-rw-r--r--nx-X11/programs/Xserver/Xprint/ps/PsPrint.c462
-rw-r--r--nx-X11/programs/Xserver/Xprint/ps/PsSpans.c166
-rw-r--r--nx-X11/programs/Xserver/Xprint/ps/PsText.c586
-rw-r--r--nx-X11/programs/Xserver/Xprint/ps/PsWindow.c462
-rw-r--r--nx-X11/programs/Xserver/Xprint/ps/psout.c1792
-rw-r--r--nx-X11/programs/Xserver/Xprint/ps/psout.h335
-rw-r--r--nx-X11/programs/Xserver/Xprint/ps/psout_ft.c335
-rw-r--r--nx-X11/programs/Xserver/Xprint/ps/psout_ftpstype1.c185
-rw-r--r--nx-X11/programs/Xserver/Xprint/ps/psout_ftpstype3.c468
-rw-r--r--nx-X11/programs/Xserver/Xprint/ps/ttf2pt1wrap.c14
29 files changed, 11077 insertions, 0 deletions
diff --git a/nx-X11/programs/Xserver/Xprint/ps/Imakefile b/nx-X11/programs/Xserver/Xprint/ps/Imakefile
new file mode 100644
index 000000000..c73466fe4
--- /dev/null
+++ b/nx-X11/programs/Xserver/Xprint/ps/Imakefile
@@ -0,0 +1,89 @@
+XCOMM $Xorg: Imakefile,v 1.5 2001/03/14 18:26:56 pookie Exp $
+
+#include <Server.tmpl>
+
+#if BuildFreeType || BuildFreetype2Library
+FT2SOURCEDIR = $(TOP)/extras/freetype2/src
+FT2INCDIR = $(TOP)/extras/freetype2/include
+FT2INCS = -I$(FT2INCDIR) \
+ -I$(FT2SOURCEDIR)/type42
+TTF2PT1OURCEDIR = $(TOP)/extras/ttf2pt1
+FT_DEFINES = -DXP_USE_FREETYPE
+FTSRCS = psout_ft.c psout_ftpstype1.c psout_ftpstype3.c PsFTFonts.c
+FTOBJS = psout_ft.o psout_ftpstype1.o psout_ftpstype3.o PsFTFonts.o
+
+#if !defined (LynxOSArchitecture)
+TTF2PT1SRCFILE = ttf2pt1.c
+TTF2PT1OBJFILE = ttf2pt1.o
+#else
+TTF2PT1SRCFILE = ttf2pt1wrap.c
+TTF2PT1OBJFILE = ttf2pt1wrap.o
+#endif
+
+#if defined(SCOArchitecture)
+XTRA_SYS_DEFINES = SCOBuildFlags
+#endif
+
+TTF2PT1SRCS = ft.c pt1.c runt1asm.c $(TTF2PT1SRCFILE)
+TTF2PT1OBJS = ft.o pt1.o runt1asm.o $(TTF2PT1OBJFILE)
+TTF2PT1_DEFINES = -DUSE_FREETYPE -DXP_ONLY_BLOCKS
+#endif /* BuildFreeType || BuildFreetype2Library */
+
+SRCS1 = PsInit.c PsPrint.c PsGC.c PsMisc.c PsSpans.c PsArea.c PsPixel.c \
+ PsLine.c PsPolygon.c PsArc.c PsText.c PsWindow.c PsFonts.c \
+ PsAttr.c PsAttVal.c PsColor.c PsPixmap.c psout.c PsCache.c PsImageUtil.c
+
+OBJS1 = PsInit.o PsPrint.o PsGC.o PsMisc.o PsSpans.o PsArea.o PsPixel.o \
+ PsLine.o PsPolygon.o PsArc.o PsText.o PsWindow.o PsFonts.o \
+ PsAttr.o PsAttVal.o PsColor.o PsPixmap.o psout.o PsCache.o PsImageUtil.o
+
+SRCS = $(SRCS1) $(TTF2PT1SRCS) $(FTSRCS)
+
+OBJS = $(OBJS1) $(TTF2PT1OBJS) $(FTOBJS)
+
+#if BuildFreeType || BuildFreetype2Library
+LinkSourceFile(ttf2pt1.c,$(TTF2PT1OURCEDIR)/)
+LinkSourceFile(pt1.c,$(TTF2PT1OURCEDIR)/)
+LinkSourceFile(pt1.h,$(TTF2PT1OURCEDIR)/)
+LinkSourceFile(ft.c,$(TTF2PT1OURCEDIR)/)
+LinkSourceFile(runt1asm.c,$(TTF2PT1OURCEDIR)/)
+LinkSourceFile(t1asm.c,$(TTF2PT1OURCEDIR)/)
+LinkSourceFile(ttf.h,$(TTF2PT1OURCEDIR)/)
+LinkSourceFile(global.h,$(TTF2PT1OURCEDIR)/)
+LinkSourceFile(version.h,$(TTF2PT1OURCEDIR)/)
+#endif /* BuildFreeType || BuildFreetype2Library */
+
+#ifdef XVendorString
+VENDORSTRING = XVendorString
+ VENDOR_STRING = -DVENDOR_STRING=\"$(VENDORSTRING)\"
+#endif
+
+#ifdef XVendorRelease
+VENDORRELEASE = XVendorRelease
+ VENDOR_RELEASE = -DVENDOR_RELEASE="$(VENDORRELEASE)"
+#endif
+
+VENDOR_DEFINES = $(VENDOR_STRING) $(VENDOR_RELEASE)
+
+XCOMM DEFINES = -DPIXPRIV
+
+XCOMM BM_CACHE disabled because it causes PostScript errors
+XCOMM (see http://xprint.mozdev.org/bugs/show_bug.cgi?id=1489)
+XCOMM DEFINES = -DPSOUT_USE_DEEPCOLOR -DXP_PSTEXT -DBM_CACHE $(VENDOR_DEFINES) $(TTF2PT1_DEFINES) $(FT_DEFINES)
+ DEFINES = -UXFree86LOADER -DPSOUT_USE_DEEPCOLOR -DXP_PSTEXT -D_XP_PRINT_SERVER_ $(VENDOR_DEFINES) $(TTF2PT1_DEFINES) $(FT_DEFINES) $(EXT_DEFINES) $(XTRA_SYS_DEFINES)
+
+ INCLUDES = -I. -I../../mi -I../../mfb -I$(LIBSRC) \
+ -I$(XINCLUDESRC) -I../../include -I.. -I$(TOP)/include \
+ -I$(EXTINCSRC) -I$(FONTINCSRC) -I$(FONTLIBSRC)/include \
+ $(FT2INCS) -I../../../../lib/font/FreeType
+
+ LINTLIBS = $(TOP)/server/dix/llib-ldix.ln $(TOP)/server/os/llib-los.ln \
+ $(TOP)/server/ddx/mfb/llib-lmfb.ln \
+ $(TOP)/server/ddx/mi/llib-lmi.ln
+
+NormalLibraryObjectRule()
+
+NormalLibraryTarget(ps,$(OBJS))
+NormalLintTarget($(SRCS1) $(SRCS2))
+
+DependTarget()
diff --git a/nx-X11/programs/Xserver/Xprint/ps/Ps.h b/nx-X11/programs/Xserver/Xprint/ps/Ps.h
new file mode 100644
index 000000000..781161d8a
--- /dev/null
+++ b/nx-X11/programs/Xserver/Xprint/ps/Ps.h
@@ -0,0 +1,590 @@
+/* $Xorg: Ps.h,v 1.5 2001/02/09 02:04:35 xorgcvs Exp $ */
+/*
+
+Copyright 1996, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+/*
+ * (c) Copyright 1996 Hewlett-Packard Company
+ * (c) Copyright 1996 International Business Machines Corp.
+ * (c) Copyright 1996 Sun Microsystems, Inc.
+ * (c) Copyright 1996 Novell, Inc.
+ * (c) Copyright 1996 Digital Equipment Corp.
+ * (c) Copyright 1996 Fujitsu Limited
+ * (c) Copyright 1996 Hitachi, Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject
+ * to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the names of the copyright holders
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * from said copyright holders.
+ */
+
+/*******************************************************************
+**
+** *********************************************************
+** *
+** * File: Ps.h
+** *
+** * Contents: defines and includes for the Ps driver
+** * for a printing X server.
+** *
+** * Created By: Roger Helmendach (Liberty Systems)
+** *
+** * Copyright: Copyright 1996 The Open Group, Inc.
+** *
+** *********************************************************
+**
+********************************************************************/
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#ifndef _PS_H_
+#define _PS_H_
+
+#include <stdio.h>
+
+#ifdef abs
+#undef abs /* this is because of a non-Spec1170ness in misc.h */
+#endif
+#include <stdlib.h>
+#include "scrnintstr.h"
+#include "dix.h"
+
+#include "PsDef.h"
+#include "psout.h"
+
+#include <X11/extensions/Print.h>
+#include <X11/extensions/Printstr.h>
+
+#include "regionstr.h"
+#include <X11/fonts/fontstruct.h>
+#include "dixfontstr.h"
+#include "gcstruct.h"
+
+/*
+ * Some sleazes to force the XrmDB stuff into the server
+ */
+#ifndef HAVE_XPointer
+typedef char *XPointer;
+#define Status int
+#define True 1
+#define False 0
+#endif
+
+#include "misc.h"
+#include <X11/Xfuncproto.h>
+#include <X11/Xresource.h>
+#include "attributes.h"
+
+
+/*
+ * Public index variables from PsInit.c
+ */
+
+extern int PsScreenPrivateIndex;
+extern int PsWindowPrivateIndex;
+extern int PsContextPrivateIndex;
+extern int PsPixmapPrivateIndex;
+extern XpValidatePoolsRec PsValidatePoolsRec;
+
+/*
+ * Display list structures
+ */
+
+#define DPY_BLOCKSIZE 4096
+
+typedef struct
+{
+ int mode;
+ int nPoints;
+ xPoint *pPoints;
+} PsPolyPointsRec;
+
+typedef struct
+{
+ int nSegments;
+ xSegment *pSegments;
+} PsSegmentsRec;
+
+typedef struct
+{
+ int nRects;
+ xRectangle *pRects;
+} PsRectanglesRec;
+
+typedef struct
+{
+ int nArcs;
+ xArc *pArcs;
+} PsArcsRec;
+
+typedef struct
+{
+ int x;
+ int y;
+ int count;
+ char *string;
+} PsText8Rec;
+
+typedef struct
+{
+ int x;
+ int y;
+ int count;
+ unsigned short *string;
+} PsText16Rec;
+
+typedef struct
+{
+ int depth;
+ int x;
+ int y;
+ int w;
+ int h;
+ int leftPad;
+ int format;
+ int res; /* image resolution */
+ char *pData;
+} PsImageRec;
+
+typedef struct
+{
+ int x;
+ int y;
+ int w;
+ int h;
+} PsFrameRec;
+
+typedef enum
+{
+ PolyPointCmd,
+ PolyLineCmd,
+ PolySegmentCmd,
+ PolyRectangleCmd,
+ FillPolygonCmd,
+ PolyFillRectCmd,
+ PolyArcCmd,
+ PolyFillArcCmd,
+ Text8Cmd,
+ Text16Cmd,
+ TextI8Cmd,
+ TextI16Cmd,
+ PutImageCmd,
+ BeginFrameCmd,
+ EndFrameCmd
+} DisplayElmType;
+
+typedef struct _DisplayElmRec
+{
+ DisplayElmType type;
+ GCPtr gc;
+ union
+ {
+ PsPolyPointsRec polyPts;
+ PsSegmentsRec segments;
+ PsRectanglesRec rects;
+ PsArcsRec arcs;
+ PsText8Rec text8;
+ PsText16Rec text16;
+ PsImageRec image;
+ PsFrameRec frame;
+ } c;
+} DisplayElmRec;
+
+typedef DisplayElmRec *DisplayElmPtr;
+
+typedef struct _DisplayListRec
+{
+ struct _DisplayListRec *next;
+ int nelms;
+ DisplayElmRec elms[DPY_BLOCKSIZE];
+} DisplayListRec;
+
+typedef DisplayListRec *DisplayListPtr;
+
+/*
+ * Private structures
+ */
+
+typedef struct
+{
+ XrmDatabase resDB;
+ Bool (*DestroyWindow)(WindowPtr);
+} PsScreenPrivRec, *PsScreenPrivPtr;
+
+typedef struct PsFontTypeInfoRec PsFontTypeInfoRec;
+
+/* Structure to hold information about one font on disk
+ * Notes:
+ * - multiple XLFD names can refer to the same |PsFontTypeInfoRec| (if
+ * they all use the same font on the disk)
+ * - the FreeType font download code uses multiple |PsFontTypeInfoRec|
+ * records for one font on disk if they differ in the encoding being
+ * used (this is an exception from the
+ * 'one-|PsFontTypeInfoRec|-per-font-on-disk'-design; maybe it it is better
+ * to rework that in a later step and add a new per-encoding structure).
+ */
+struct PsFontTypeInfoRec
+{
+ PsFontTypeInfoRec *next; /* Next record in list... */
+ char *adobe_ps_name; /* PostScript font name (from the
+ * "_ADOBE_POSTSCRIPT_FONTNAME" atom) */
+ char *download_ps_name; /* PostScript font name used for font download */
+ char *filename; /* File name of font */
+#ifdef XP_USE_FREETYPE
+ char *ft_download_encoding; /* encoding used for download */
+ PsFTDownloadFontType ft_download_font_type; /* PS font type used for download (e.g. Type1/Type3/CID/etc.) */
+#endif /* XP_USE_FREETYPE */
+ int is_iso_encoding; /* Is this font encoded in ISO Latin 1 ? */
+ int font_type; /* See PSFTI_FONT_TYPE_* below... */
+ Bool downloadableFont; /* Font can be downloaded */
+ Bool alreadyDownloaded[256]; /* Font has been downloaded (for 256 8bit "sub"-font) */
+};
+
+#define PSFTI_FONT_TYPE_OTHER (0)
+#define PSFTI_FONT_TYPE_PMF (1)
+#define PSFTI_FONT_TYPE_PS_TYPE1_PFA (2)
+#define PSFTI_FONT_TYPE_PS_TYPE1_PFB (3)
+#define PSFTI_FONT_TYPE_TRUETYPE (4)
+/* PSFTI_FONT_TYPE_FREETYPE is means the font is handled by the freetype engine */
+#define PSFTI_FONT_TYPE_FREETYPE (5)
+
+typedef struct PsFontInfoRec PsFontInfoRec;
+
+/* Structure which represents our context info for a single XLFD font
+ * Note that multiple |PsFontInfoRec| records can share the same
+ * |PsFontTypeInfoRec| record - the |PsFontInfoRec| records represent
+ * different appearances of the same font on disk(=|PsFontTypeInfoRec|)).
+ */
+struct PsFontInfoRec
+{
+ PsFontInfoRec *next; /* Next record in list... */
+ /* |font| and |font_fontPrivate| are used by |PsFindFontInfoRec()| to
+ * identify a font */
+ FontPtr font; /* The font this record is for */
+ pointer font_fontPrivate;
+ PsFontTypeInfoRec *ftir; /* Record about the font file on disk */
+ const char *dfl_name; /* XLFD for this font */
+ int size; /* Font size. Use |mtx| if |size==0| */
+ float mtx[4]; /* Transformation matrix (see |size|) */
+};
+
+typedef struct
+{
+ char *jobFileName;
+ FILE *pJobFile;
+ GC lastGC;
+ unsigned char *dash;
+ int validGC;
+ ClientPtr getDocClient;
+ int getDocBufSize;
+ PsOutPtr pPsOut;
+ PsFontTypeInfoRec *fontTypeInfoRecords;
+ PsFontInfoRec *fontInfoRecords;
+} PsContextPrivRec, *PsContextPrivPtr;
+
+typedef struct
+{
+ int validContext;
+ XpContextPtr context;
+} PsWindowPrivRec, *PsWindowPrivPtr;
+
+typedef struct
+{
+ XpContextPtr context;
+ GC lastGC;
+ int validGC;
+ DisplayListPtr dispList;
+} PsPixmapPrivRec, *PsPixmapPrivPtr;
+
+/*
+ * Macro functions
+ */
+
+#define SEND_PS(f,c) fwrite( c, sizeof( char ), strlen( c ), f )
+#define MIN(a,b) (((a)<(b))?(a):(b))
+#ifndef MAX
+#define MAX(a,b) (((a)>(b))?(a):(b))
+#endif
+
+/*
+ * Functions in PsInit.c
+ */
+
+extern Bool InitializePsDriver(int ndx, ScreenPtr pScreen, int argc,
+ char **argv);
+extern XpContextPtr PsGetContextFromWindow(WindowPtr win);
+
+/*
+ * Functions in PsPrint.c
+ */
+
+extern int PsStartJob(XpContextPtr pCon, Bool sendClientData, ClientPtr client);
+extern int PsEndJob(XpContextPtr pCon, Bool cancel);
+extern int PsStartPage(XpContextPtr pCon, WindowPtr pWin);
+extern int PsEndPage(XpContextPtr pCon, WindowPtr pWin);
+extern int PsStartDoc(XpContextPtr pCon, XPDocumentType type);
+extern int PsEndDoc(XpContextPtr pCon, Bool cancel);
+extern int PsDocumentData(XpContextPtr pCon, DrawablePtr pDraw, char *pData,
+ int len_data, char *pFmt, int len_fmt, char *pOpt, int len_opt,
+ ClientPtr client);
+extern int PsGetDocumentData(XpContextPtr pCon, ClientPtr client,
+ int maxBufferSize);
+
+/*
+ * Functions in PsGC.c
+ */
+
+extern Bool PsCreateGC(GCPtr pGC);
+extern PsContextPrivPtr PsGetPsContextPriv( DrawablePtr pDrawable );
+extern int PsUpdateDrawableGC(GCPtr pGC, DrawablePtr pDrawable,
+ PsOutPtr *psOut, ColormapPtr *cMap);
+extern void PsValidateGC(GCPtr pGC, unsigned long changes, DrawablePtr pDrawable);
+extern void PsChangeGC(GCPtr pGC, unsigned long changes);
+extern void PsCopyGC(GCPtr pGCSrc, unsigned long mask, GCPtr pGCDst);
+extern void PsDestroyGC(GCPtr pGC);
+extern void PsChangeClip(GCPtr pGC, int type, pointer pValue, int nrects);
+extern void PsDestroyClip(GCPtr pGC);
+extern void PsCopyClip(GCPtr pgcDst, GCPtr pgcSrc);
+
+extern GCPtr PsCreateAndCopyGC(DrawablePtr pDrawable, GCPtr pSrc);
+
+/*
+ * Functions in PsMisc.c
+ */
+
+extern void PsQueryBestSize(int type, short *pwidth, short *pheight,
+ ScreenPtr pScreen);
+extern Bool PsCloseScreen(int index, ScreenPtr pScreen);
+extern void PsLineAttrs(PsOutPtr psOut, GCPtr pGC, ColormapPtr cMap);
+extern int PsGetMediumDimensions(
+ XpContextPtr pCon,
+ CARD16 *pWidth,
+ CARD16 *pHeight);
+extern int PsGetReproducibleArea(
+ XpContextPtr pCon,
+ xRectangle *pRect);
+extern int PsSetImageResolution(
+ XpContextPtr pCon,
+ int imageRes,
+ Bool *status);
+
+/*
+ * Functions in PsSpans.c
+ */
+
+extern void PsFillSpans(DrawablePtr pDrawable, GCPtr pGC, int nSpans,
+ DDXPointPtr pPoints, int *pWidths, int fSorted);
+extern void PsSetSpans(DrawablePtr pDrawable, GCPtr pGC, char *pSrc,
+ DDXPointPtr pPoints, int *pWidths, int nSpans,
+ int fSorted);
+
+/*
+ * Functions in PsArea.c
+ */
+
+extern void PsPutScaledImage(DrawablePtr pDrawable, GCPtr pGC, int depth,
+ int x, int y, int w, int h, int leftPad, int format,
+ int imageRes, char *pImage);
+extern void PsPutImage(DrawablePtr pDrawable, GCPtr pGC, int depth,
+ int x, int y, int w, int h, int leftPad, int format,
+ char *pImage);
+extern void PsPutImageMask(DrawablePtr pDrawable, GCPtr pGC, int depth, int x, int y,
+ int w, int h, int leftPad, int format, char *pImage);
+extern RegionPtr PsCopyArea(DrawablePtr pSrc, DrawablePtr pDst, GCPtr pGC,
+ int srcx, int srcy, int width, int height,
+ int dstx, int dsty);
+extern RegionPtr PsCopyPlane(DrawablePtr pSrc, DrawablePtr pDst, GCPtr pGC,
+ int srcx, int srcy, int width, int height,
+ int dstx, int dsty, unsigned long plane);
+
+/*
+ * Functions in PsPixel.c
+ */
+
+extern void PsPolyPoint(DrawablePtr pDrawable, GCPtr pGC, int mode,
+ int nPoints, xPoint *pPoints);
+extern void PsPushPixels(GCPtr pGC, PixmapPtr pBitmap, DrawablePtr pDrawable,
+ int width, int height, int x, int y);
+
+/*
+ * Functions in PsLine.c
+ */
+
+extern void PsPolyLine(DrawablePtr pDrawable, GCPtr pGC, int mode,
+ int nPoints, xPoint *pPoints);
+extern void PsPolySegment(DrawablePtr pDrawable, GCPtr pGC, int nSegments,
+ xSegment *pSegments);
+
+/*
+ * Functions in PsPolygon.c
+ */
+
+extern void PsPolyRectangle(DrawablePtr pDrawable, GCPtr pGC, int nRects,
+ xRectangle *pRects);
+extern void PsFillPolygon(DrawablePtr pDrawable, GCPtr pGC, int shape,
+ int mode, int nPoints, DDXPointPtr pPoints);
+extern void PsPolyFillRect(DrawablePtr pDrawable, GCPtr pGC, int nRects,
+ xRectangle *pRects);
+
+/*
+ * Functions in PsPolygon.c
+ */
+
+extern void PsPolyArc(DrawablePtr pDrawable, GCPtr pGC, int nArcs,
+ xArc *pArcs);
+extern void PsPolyFillArc(DrawablePtr pDrawable, GCPtr pGC, int nArcs,
+ xArc *pArcs);
+
+/*
+ * Functions in PsText.c
+ */
+
+extern int PsPolyText8(DrawablePtr pDrawable, GCPtr pGC, int x, int y,
+ int count, char *string);
+extern int PsPolyText16(DrawablePtr pDrawable, GCPtr pGC, int x, int y,
+ int count, unsigned short *string);
+extern void PsImageText8(DrawablePtr pDrawable, GCPtr pGC, int x, int y,
+ int count, char *string);
+extern void PsImageText16(DrawablePtr pDrawable, GCPtr pGC, int x, int y,
+ int count, unsigned short *string);
+extern void PsImageGlyphBlt(DrawablePtr pDrawable, GCPtr pGC, int x, int y,
+ unsigned int nGlyphs, CharInfoPtr *pCharInfo,
+ pointer pGlyphBase);
+extern void PsPolyGlyphBlt(DrawablePtr pDrawable, GCPtr pGC, int x, int y,
+ unsigned int nGlyphs, CharInfoPtr *pCharInfo,
+ pointer pGlyphBase);
+
+/*
+ * Functions in PsWindow.c
+ */
+
+extern Bool PsCreateWindow(WindowPtr pWin);
+extern Bool PsMapWindow(WindowPtr pWin);
+extern Bool PsPositionWindow(WindowPtr pWin, int x, int y);
+extern Bool PsUnmapWindow(WindowPtr pWin);
+extern void PsCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg,
+ RegionPtr prgnSrc);
+extern Bool PsChangeWindowAttributes(WindowPtr pWin, unsigned long mask);
+extern void PsPaintWindow(WindowPtr pWin, RegionPtr pRegion, int what);
+extern Bool PsDestroyWindow(WindowPtr pWin);
+
+/*
+ * Functions in PsFonts.c
+ */
+
+extern Bool PsRealizeFont(ScreenPtr pscr, FontPtr pFont);
+extern Bool PsUnrealizeFont(ScreenPtr pscr, FontPtr pFont);
+extern char *PsGetFontName(FontPtr pFont);
+extern int PsGetFontSize(FontPtr pFont, float *mtx);
+extern char *PsGetPSFontName(FontPtr pFont);
+extern char *PsGetPSFaceOrFontName(FontPtr pFont);
+extern int PsIsISOLatin1Encoding(FontPtr pFont);
+extern char *PsGetEncodingName(FontPtr pFont);
+extern PsFontInfoRec *PsGetFontInfoRec(DrawablePtr pDrawable, FontPtr pFont);
+extern void PsFreeFontInfoRecords(PsContextPrivPtr priv);
+extern PsFTDownloadFontType PsGetFTDownloadFontType(void);
+
+/*
+ * Functions in PsFTFonts.c
+ */
+
+extern char *PsGetFTFontFileName(FontPtr pFont);
+extern Bool PsIsFreeTypeFont(FontPtr pFont);
+
+/*
+ * Functions in PsAttr.c
+ */
+
+extern char *PsGetAttributes(XpContextPtr pCon, XPAttributes pool);
+extern char *PsGetOneAttribute(XpContextPtr pCon, XPAttributes pool,
+ char *attr);
+extern int PsAugmentAttributes(XpContextPtr pCon, XPAttributes pool,
+ char *attrs);
+extern int PsSetAttributes(XpContextPtr pCon, XPAttributes pool, char *attrs);
+
+/*
+ * Functions in PsColor.c
+ */
+
+extern Bool PsCreateColormap(ColormapPtr pColor);
+extern void PsDestroyColormap(ColormapPtr pColor);
+extern void PsInstallColormap(ColormapPtr pColor);
+extern void PsUninstallColormap(ColormapPtr pColor);
+extern int PsListInstalledColormaps(ScreenPtr pScreen, XID *pCmapList);
+extern void PsStoreColors(ColormapPtr pColor, int ndef, xColorItem *pdefs);
+extern void PsResolveColor(unsigned short *pRed, unsigned short *pGreen,
+ unsigned short *pBlue, VisualPtr pVisual);
+extern PsOutColor PsGetPixelColor(ColormapPtr cMap, int pixval);
+extern void PsSetFillColor(DrawablePtr pDrawable, GCPtr pGC, PsOutPtr psOut,
+ ColormapPtr cMap);
+
+/*
+ * Functions in PsPixmap.c
+ */
+
+extern PixmapPtr PsCreatePixmap(ScreenPtr pScreen, int width, int height,
+ int depth);
+extern void PsScrubPixmap(PixmapPtr pPixmap);
+extern Bool PsDestroyPixmap(PixmapPtr pPixmap);
+extern DisplayListPtr PsGetFreeDisplayBlock(PsPixmapPrivPtr priv);
+extern void PsReplayPixmap(PixmapPtr pix, DrawablePtr pDrawable);
+extern int PsCloneDisplayElm(PixmapPtr dst,
+ DisplayElmPtr elm, DisplayElmPtr newElm,
+ int xoff, int yoff);
+extern void PsCopyDisplayList(PixmapPtr src, PixmapPtr dst, int xoff,
+ int yoff, int x, int y, int w, int h);
+extern PsElmPtr PsCreateFillElementList(PixmapPtr pix, int *nElms);
+extern PsElmPtr PsCloneFillElementList(int nElms, PsElmPtr elms);
+extern void PsDestroyFillElementList(int nElms, PsElmPtr elms);
+
+/*
+ * Functions in PsImageUtil.c
+ */
+
+extern unsigned long
+PsGetImagePixel(char *pImage, int depth, int w, int h, int leftPad, int format,
+ int px, int py);
+
+#endif /* _PS_H_ */
diff --git a/nx-X11/programs/Xserver/Xprint/ps/PsArc.c b/nx-X11/programs/Xserver/Xprint/ps/PsArc.c
new file mode 100644
index 000000000..511971e7a
--- /dev/null
+++ b/nx-X11/programs/Xserver/Xprint/ps/PsArc.c
@@ -0,0 +1,182 @@
+/* $Xorg: PsArc.c,v 1.4 2001/02/09 02:04:35 xorgcvs Exp $ */
+/*
+
+Copyright 1996, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+/*
+ * (c) Copyright 1996 Hewlett-Packard Company
+ * (c) Copyright 1996 International Business Machines Corp.
+ * (c) Copyright 1996 Sun Microsystems, Inc.
+ * (c) Copyright 1996 Novell, Inc.
+ * (c) Copyright 1996 Digital Equipment Corp.
+ * (c) Copyright 1996 Fujitsu Limited
+ * (c) Copyright 1996 Hitachi, Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject
+ * to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the names of the copyright holders
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * from said copyright holders.
+ */
+
+/*******************************************************************
+**
+** *********************************************************
+** *
+** * File: PsArc.c
+** *
+** * Contents: Arc-drawing code for the PS DDX driver
+** *
+** * Created By: Roger Helmendach (Liberty Systems)
+** *
+** * Copyright: Copyright 1996 The Open Group, Inc.
+** *
+** *********************************************************
+**
+********************************************************************/
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include <stdio.h>
+
+#include "Ps.h"
+#include "gcstruct.h"
+#include "windowstr.h"
+
+void
+PsPolyArc(
+ DrawablePtr pDrawable,
+ GCPtr pGC,
+ int nArcs,
+ xArc *pArcs)
+{
+ if( pDrawable->type==DRAWABLE_PIXMAP )
+ {
+ DisplayElmPtr elm;
+ PixmapPtr pix = (PixmapPtr)pDrawable;
+ PsPixmapPrivPtr priv = (PsPixmapPrivPtr)pix->devPrivate.ptr;
+ DisplayListPtr disp;
+ GCPtr gc;
+
+ if ((gc = PsCreateAndCopyGC(pDrawable, pGC)) == NULL) return;
+
+ disp = PsGetFreeDisplayBlock(priv);
+
+ elm = &disp->elms[disp->nelms];
+ elm->type = PolyArcCmd;
+ elm->gc = gc;
+ elm->c.arcs.nArcs = nArcs;
+ elm->c.arcs.pArcs = (xArc *)xalloc(nArcs*sizeof(xArc));
+ memcpy(elm->c.arcs.pArcs, pArcs, nArcs*sizeof(xArc));
+ disp->nelms += 1;
+ }
+ else
+ {
+ int i;
+ PsOutPtr psOut;
+ ColormapPtr cMap;
+
+ if( PsUpdateDrawableGC(pGC, pDrawable, &psOut, &cMap)==FALSE ) return;
+ PsOut_Offset(psOut, pDrawable->x, pDrawable->y);
+ PsOut_Color(psOut, PsGetPixelColor(cMap, pGC->fgPixel));
+ PsLineAttrs(psOut, pGC, cMap);
+ for( i=0 ; i<nArcs ; i++ )
+ {
+ PsOut_DrawArc(psOut, (int)pArcs[i].x, (int)pArcs[i].y,
+ (int)pArcs[i].width, (int)pArcs[i].height,
+ (float)pArcs[i].angle1/64.,
+ (float)pArcs[i].angle2/64.);
+ }
+ }
+}
+
+void
+PsPolyFillArc(
+ DrawablePtr pDrawable,
+ GCPtr pGC,
+ int nArcs,
+ xArc *pArcs)
+{
+ if( pDrawable->type==DRAWABLE_PIXMAP )
+ {
+ DisplayElmPtr elm;
+ PixmapPtr pix = (PixmapPtr)pDrawable;
+ PsPixmapPrivPtr priv = (PsPixmapPrivPtr)pix->devPrivate.ptr;
+ DisplayListPtr disp;
+ GCPtr gc;
+
+ if ((gc = PsCreateAndCopyGC(pDrawable, pGC)) == NULL) return;
+
+ disp = PsGetFreeDisplayBlock(priv);
+
+ elm = &disp->elms[disp->nelms];
+ elm->type = PolyFillArcCmd;
+ elm->gc = gc;
+ elm->c.arcs.nArcs = nArcs;
+ elm->c.arcs.pArcs = (xArc *)xalloc(nArcs*sizeof(xArc));
+ memcpy(elm->c.arcs.pArcs, pArcs, nArcs*sizeof(xArc));
+ disp->nelms += 1;
+ }
+ else
+ {
+ int i;
+ PsOutPtr psOut;
+ PsArcEnum styl;
+ ColormapPtr cMap;
+
+ if( PsUpdateDrawableGC(pGC, pDrawable, &psOut, &cMap)==FALSE ) return;
+ PsOut_Offset(psOut, pDrawable->x, pDrawable->y);
+ PsSetFillColor(pDrawable, pGC, psOut, cMap);
+ PsLineAttrs(psOut, pGC, cMap);
+ if( pGC->arcMode==ArcChord ) styl = PsChord;
+ else styl = PsPieSlice;
+ for( i=0 ; i<nArcs ; i++ )
+ {
+ PsOut_FillArc(psOut, (int)pArcs[i].x, (int)pArcs[i].y,
+ (int)pArcs[i].width, (int)pArcs[i].height,
+ (float)pArcs[i].angle1/64.,
+ (float)pArcs[i].angle2/64., styl);
+ }
+ }
+}
diff --git a/nx-X11/programs/Xserver/Xprint/ps/PsArea.c b/nx-X11/programs/Xserver/Xprint/ps/PsArea.c
new file mode 100644
index 000000000..32a4d5cf4
--- /dev/null
+++ b/nx-X11/programs/Xserver/Xprint/ps/PsArea.c
@@ -0,0 +1,393 @@
+/* $Xorg: PsArea.c,v 1.6 2001/03/14 18:27:44 pookie Exp $ */
+/*
+
+Copyright 1996, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+/*
+ * (c) Copyright 1996 Hewlett-Packard Company
+ * (c) Copyright 1996 International Business Machines Corp.
+ * (c) Copyright 1996, 2000 Sun Microsystems, Inc.
+ * (c) Copyright 1996 Novell, Inc.
+ * (c) Copyright 1996 Digital Equipment Corp.
+ * (c) Copyright 1996 Fujitsu Limited
+ * (c) Copyright 1996 Hitachi, Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject
+ * to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the names of the copyright holders
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * from said copyright holders.
+ */
+
+/*******************************************************************
+**
+** *********************************************************
+** *
+** * File: PsArea.c
+** *
+** * Contents: Image and Area functions for the PS DDX driver
+** *
+** * Created By: Roger Helmendach (Liberty Systems)
+** *
+** * Copyright: Copyright 1996 The Open Group, Inc.
+** *
+** *********************************************************
+**
+********************************************************************/
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include "Ps.h"
+#include "gcstruct.h"
+#include "windowstr.h"
+
+
+void
+PsPutScaledImage(DrawablePtr pDrawable, GCPtr pGC, int depth, int x, int y,
+ int w, int h, int leftPad, int format, int imageRes, char *pImage)
+{
+ if( pDrawable->type==DRAWABLE_PIXMAP )
+ {
+ int size = PixmapBytePad(w, depth)*h;
+ DisplayElmPtr elm;
+ PixmapPtr pix = (PixmapPtr)pDrawable;
+ PsPixmapPrivPtr priv = (PsPixmapPrivPtr)pix->devPrivate.ptr;
+ DisplayListPtr disp;
+ GCPtr gc;
+
+ if ((gc = PsCreateAndCopyGC(pDrawable, pGC)) == NULL) return;
+
+ disp = PsGetFreeDisplayBlock(priv);
+ elm = &disp->elms[disp->nelms];
+ elm->type = PutImageCmd;
+ elm->gc = gc;
+ elm->c.image.depth = depth;
+ elm->c.image.x = x;
+ elm->c.image.y = y;
+ elm->c.image.w = w;
+ elm->c.image.h = h;
+ elm->c.image.leftPad = leftPad;
+ elm->c.image.format = format;
+ elm->c.image.res = imageRes;
+ elm->c.image.pData = (char *)xalloc(size);
+ memcpy(elm->c.image.pData, pImage, size);
+ disp->nelms += 1;
+ }
+ else
+ {
+ int i, j;
+ int r, c;
+ char *pt;
+ PsOutPtr psOut;
+ ColormapPtr cMap;
+ int pageRes, sw, sh;
+
+ if( PsUpdateDrawableGC(pGC, pDrawable, &psOut, &cMap)==FALSE ) return;
+ if (!imageRes) {
+ sw = w;
+ sh = h;
+ } else {
+ pageRes = XpGetResolution(XpGetPrintContext(requestingClient));
+ sw = (float)w * (float)pageRes / (float)imageRes + 0.5;
+ sh = (float)h * (float)pageRes / (float)imageRes + 0.5;
+ }
+ PsOut_Offset(psOut, pDrawable->x, pDrawable->y);
+
+ if( depth!=1 )
+ {
+ PsOut_BeginImage(psOut, 0, 0, x, y, w, h, sw, sh, 3);
+
+ for( r=0 ; r<h ; r++ )
+ {
+ for( c=0 ; c<w ; c++ )
+ {
+ unsigned long pv = PsGetImagePixel(pImage, depth, w, h, leftPad, format, c, r);
+ PsOutColor clr = PsGetPixelColor(cMap, pv);
+ /* XXX: This needs to be fixed for endian swapping and to support
+ * depths deeper than 8bit per R-,G-,B-gun... */
+ unsigned long val = PSOUTCOLOR_TO_RGB24BIT(clr);
+ char *ipt = (char *)&val;
+/* XXX: Is this the right way to detect the platform endianess ? */
+#if IMAGE_BYTE_ORDER == LSBFirst
+ {
+ long l;
+ swapl(&val, l);
+ }
+#elif IMAGE_BYTE_ORDER == MSBFirst
+#else
+#error Unsupported byte order
+#endif
+ PsOut_OutImageBytes(psOut, 3, &ipt[1]);
+ }
+ }
+
+ PsOut_EndImage(psOut);
+ }
+ else
+ {
+ int rowsiz = BitmapBytePad(w);
+ int psrsiz = (w+7)/8;
+ PsOut_BeginImage(psOut, PsGetPixelColor(cMap, pGC->bgPixel),
+ PsGetPixelColor(cMap, pGC->fgPixel),
+ x, y, w, h, sw, sh, 1);
+ for( r=0 ; r<h ; r++ )
+ {
+ char *pt = &pImage[rowsiz*r];
+ for( i=0 ; i<psrsiz ; i++ )
+ {
+ int iv_, iv = (int)pt[i]&0xFF;
+ char c;
+/* XXX: Is this the right way to detect the platform endianess ? */
+#if IMAGE_BYTE_ORDER == LSBFirst
+ { for( j=0,iv_=0 ; j<8 ; j++ ) iv_ |= (((iv>>j)&1)<<(7-j)); }
+#elif IMAGE_BYTE_ORDER == MSBFirst
+ iv_ = iv;
+#else
+#error Unsupported byte order
+#endif
+ c = iv_;
+ PsOut_OutImageBytes(psOut, 1, &c);
+ }
+ }
+ PsOut_EndImage(psOut);
+ }
+ }
+}
+
+void
+PsPutScaledImageIM(DrawablePtr pDrawable, GCPtr pGC, int depth, int x, int y,
+ int w, int h, int leftPad, int format, int imageRes, char *pImage)
+{
+ if( pDrawable->type==DRAWABLE_PIXMAP )
+ {
+ int size = PixmapBytePad(w, depth)*h;
+ DisplayElmPtr elm;
+ PixmapPtr pix = (PixmapPtr)pDrawable;
+ PsPixmapPrivPtr priv = (PsPixmapPrivPtr)pix->devPrivate.ptr;
+ DisplayListPtr disp;
+ GCPtr gc;
+
+ if ((gc = PsCreateAndCopyGC(pDrawable, pGC)) == NULL) return;
+
+ disp = PsGetFreeDisplayBlock(priv);
+ elm = &disp->elms[disp->nelms];
+ elm->type = PutImageCmd;
+ elm->gc = gc;
+ elm->c.image.depth = depth;
+ elm->c.image.x = x;
+ elm->c.image.y = y;
+ elm->c.image.w = w;
+ elm->c.image.h = h;
+ elm->c.image.leftPad = leftPad;
+ elm->c.image.format = format;
+ elm->c.image.res = imageRes;
+ elm->c.image.pData = (char *)xalloc(size);
+ memcpy(elm->c.image.pData, pImage, size);
+ disp->nelms += 1;
+ }
+ else
+ {
+ int i, j;
+ int r, c;
+ char *pt;
+ PsOutPtr psOut;
+ ColormapPtr cMap;
+ int pageRes, sw, sh;
+#ifdef BM_CACHE
+ long cache_id = 0;
+#endif
+
+ if( PsUpdateDrawableGC(pGC, pDrawable, &psOut, &cMap)==FALSE ) return;
+ if (!imageRes) {
+ sw = w;
+ sh = h;
+ } else {
+ pageRes = XpGetResolution(XpGetPrintContext(requestingClient));
+ sw = (float)w * (float)pageRes / (float)imageRes + 0.5;
+ sh = (float)h * (float)pageRes / (float)imageRes + 0.5;
+ }
+ PsOut_Offset(psOut, pDrawable->x, pDrawable->y);
+
+#ifdef BM_CACHE
+ cache_id = PsBmIsImageCached(w, h, pImage);
+
+ if(!cache_id)
+ {
+ cache_id = PsBmPutImageInCache(w, h, pImage);
+
+ if(!cache_id)
+ return;
+
+ PsOut_BeginImageCache(psOut, cache_id);
+#endif
+ if( depth!=1 )
+ {
+ PsOut_BeginImageIM(psOut, 0, 0, x, y, w, h, sw, sh, 3);
+
+ for( r=0 ; r<h ; r++ )
+ {
+ for( c=0 ; c<w ; c++ )
+ {
+ unsigned long pv = PsGetImagePixel(pImage, depth, w, h, leftPad, format, c, r);
+ PsOutColor clr = PsGetPixelColor(cMap, pv);
+ /* XXX: This needs to be fixed for endian swapping and to support
+ * depths deeper than 8bit per R-,G-,B-gun... */
+ unsigned long val = PSOUTCOLOR_TO_RGB24BIT(clr);
+ char *ipt = (char *)&val;
+/* XXX: Is this the right way to detect the platform endianess ? */
+#if IMAGE_BYTE_ORDER == LSBFirst
+ {
+ long l;
+ swapl(&val, l);
+ }
+#elif IMAGE_BYTE_ORDER == MSBFirst
+#else
+#error Unsupported byte order
+#endif
+ PsOut_OutImageBytes(psOut, 3, &ipt[1]);
+ }
+ }
+
+ PsOut_EndImage(psOut);
+ }
+ else
+ {
+ int rowsiz = BitmapBytePad(w);
+ int psrsiz = (w+7)/8;
+ PsOut_BeginImageIM(psOut, PsGetPixelColor(cMap, pGC->bgPixel),
+ PsGetPixelColor(cMap, pGC->fgPixel),
+ x, y, w, h, sw, sh, 1);
+ for( r=0 ; r<h ; r++ )
+ {
+ char *pt = &pImage[rowsiz*r];
+ for( i=0 ; i<psrsiz ; i++ )
+ {
+ int iv_, iv = (int)pt[i]&0xFF;
+ char c;
+/* XXX: Is this the right way to detect the platform endianess ? */
+#if IMAGE_BYTE_ORDER == LSBFirst
+ { for( j=0,iv_=0 ; j<8 ; j++ ) iv_ |= (((iv>>j)&1)<<(7-j)); }
+#elif IMAGE_BYTE_ORDER == MSBFirst
+ iv_ = iv;
+#else
+#error Unsupported byte order
+#endif
+ c = iv_;
+ PsOut_OutImageBytes(psOut, 1, &c);
+ }
+ }
+ PsOut_EndImage(psOut);
+ }
+#ifdef BM_CACHE
+ PsOut_EndImageCache(psOut);
+ }
+ PsOut_ImageCache(psOut, x, y, cache_id, PsGetPixelColor(cMap, pGC->bgPixel),
+ PsGetPixelColor(cMap, pGC->fgPixel));
+#endif
+ }
+}
+void
+PsPutImage(DrawablePtr pDrawable, GCPtr pGC, int depth, int x, int y,
+ int w, int h, int leftPad, int format, char *pImage)
+{
+ XpContextPtr pcon;
+ if (requestingClient && (pcon = XpGetPrintContext(requestingClient)))
+ PsPutScaledImage(pDrawable, pGC, depth, x, y, w, h, leftPad, format,
+ pcon->imageRes, pImage);
+}
+void
+PsPutImageMask(DrawablePtr pDrawable, GCPtr pGC, int depth, int x, int y,
+ int w, int h, int leftPad, int format, char *pImage)
+{
+ XpContextPtr pcon;
+ if (requestingClient && (pcon = XpGetPrintContext(requestingClient)))
+ PsPutScaledImageIM(pDrawable, pGC, depth, x, y, w, h, leftPad, format,
+ pcon->imageRes, pImage);
+}
+
+RegionPtr
+PsCopyArea(DrawablePtr pSrc, DrawablePtr pDst, GCPtr pGC, int srcx, int srcy,
+ int width, int height, int dstx, int dsty)
+{
+ PixmapPtr src = (PixmapPtr)pSrc;
+ PixmapPtr dst = (PixmapPtr)pDst;
+
+ if( pSrc->type!=DRAWABLE_PIXMAP ) return NULL;
+ if( pDst->type!=DRAWABLE_PIXMAP )
+ {
+ PsOutPtr psOut;
+ ColormapPtr cMap;
+ if( PsUpdateDrawableGC(pGC, pDst, &psOut, &cMap)==FALSE ) return NULL;
+ PsOut_Offset(psOut, pDst->x, pDst->y);
+ PsOut_BeginFrame(psOut, dstx-srcx, dsty-srcy, dstx, dsty, width, height);
+ PsReplayPixmap(src, pDst);
+ PsOut_EndFrame(psOut);
+ }
+ else PsCopyDisplayList(src, dst, dstx-srcx, dsty-srcy, dstx, dsty,
+ width, height);
+ return NULL;
+}
+
+RegionPtr
+PsCopyPlane(DrawablePtr pSrc, DrawablePtr pDst, GCPtr pGC, int srcx, int srcy,
+ int width, int height, int dstx, int dsty, unsigned long plane)
+{
+ PixmapPtr src = (PixmapPtr)pSrc;
+ PixmapPtr dst = (PixmapPtr)pDst;
+
+ if( pSrc->type!=DRAWABLE_PIXMAP ) return NULL;
+ if( pDst->type!=DRAWABLE_PIXMAP )
+ {
+ PsOutPtr psOut;
+ ColormapPtr cMap;
+ if( PsUpdateDrawableGC(pGC, pDst, &psOut, &cMap)==FALSE ) return NULL;
+ PsOut_Offset(psOut, pDst->x, pDst->y);
+ PsOut_BeginFrame(psOut, dstx-srcx, dsty-srcy, dstx, dsty, width, height);
+ PsReplayPixmap(src, pDst);
+ PsOut_EndFrame(psOut);
+ }
+ else PsCopyDisplayList(src, dst, dstx-srcx, dsty-srcy, dstx, dsty,
+ width, height);
+ return NULL;
+}
diff --git a/nx-X11/programs/Xserver/Xprint/ps/PsAttVal.c b/nx-X11/programs/Xserver/Xprint/ps/PsAttVal.c
new file mode 100644
index 000000000..fc23ffef5
--- /dev/null
+++ b/nx-X11/programs/Xserver/Xprint/ps/PsAttVal.c
@@ -0,0 +1,290 @@
+/*
+ * $Xorg: PsAttVal.c,v 1.5 2001/03/13 18:45:31 pookie Exp $
+ */
+/*
+(c) Copyright 1996 Hewlett-Packard Company
+(c) Copyright 1996 International Business Machines Corp.
+(c) Copyright 1996 Sun Microsystems, Inc.
+(c) Copyright 1996 Novell, Inc.
+(c) Copyright 1996 Digital Equipment Corp.
+(c) Copyright 1996 Fujitsu Limited
+(c) Copyright 1996 Hitachi, Ltd.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the names of the copyright holders shall
+not be used in advertising or otherwise to promote the sale, use or other
+dealings in this Software without prior written authorization from said
+copyright holders.
+*/
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include "Ps.h"
+#include "AttrValid.h"
+
+/*
+ * define valid values and defaults for Printer pool
+ */
+static XpOid ValidContentOrientationsOids[] = {
+ xpoid_val_content_orientation_portrait,
+ xpoid_val_content_orientation_landscape,
+ xpoid_val_content_orientation_reverse_portrait,
+ xpoid_val_content_orientation_reverse_landscape
+};
+static XpOidList ValidContentOrientations = {
+ ValidContentOrientationsOids, XpNumber(ValidContentOrientationsOids)
+};
+
+static XpOid DefaultContentOrientationsOids[] = {
+ xpoid_val_content_orientation_portrait,
+ xpoid_val_content_orientation_landscape
+};
+static XpOidList DefaultContentOrientations = {
+ DefaultContentOrientationsOids, XpNumber(DefaultContentOrientationsOids)
+};
+
+static XpOid ValidPlexesOids[] = {
+ xpoid_val_plex_simplex, xpoid_val_plex_duplex, xpoid_val_plex_tumble
+};
+static XpOidList ValidPlexes = {
+ ValidPlexesOids, XpNumber(ValidPlexesOids)
+};
+
+static XpOid DefaultPlexesOids[] = {
+ xpoid_val_plex_simplex
+};
+static XpOidList DefaultPlexes = {
+ DefaultPlexesOids, XpNumber(DefaultPlexesOids)
+};
+
+static unsigned long ValidPrinterResolutionsCards[] = {
+ 75,
+ 100,
+ 120,
+ 150,
+ 180,
+ 200,
+ 240,
+ 300,
+ 360,
+ 400,
+ 600,
+ 720,
+ 940,
+ 1200,
+ 1440,
+ 2400
+};
+static XpOidCardList ValidPrinterResolutions = {
+ ValidPrinterResolutionsCards, XpNumber(ValidPrinterResolutionsCards)
+};
+
+static unsigned long DefaultPrinterResolutionsCards[] = {
+ 75,
+ 100,
+ 120,
+ 150,
+ 180,
+ 200,
+ 240,
+ 300,
+ 360,
+ 400,
+ 600,
+ 720,
+ 940,
+ 1200
+};
+static XpOidCardList DefaultPrinterResolutions = {
+ DefaultPrinterResolutionsCards, XpNumber(DefaultPrinterResolutionsCards)
+};
+
+static XpOid ValidListfontsModesOids[] = {
+ xpoid_val_xp_list_internal_printer_fonts, xpoid_val_xp_list_glyph_fonts
+};
+static XpOidList ValidListfontsModes = {
+ ValidListfontsModesOids, XpNumber(ValidListfontsModesOids)
+};
+
+static XpOid DefaultListfontsModesOids[] = {
+ xpoid_val_xp_list_glyph_fonts
+};
+static XpOidList DefaultListfontsModes = {
+ DefaultListfontsModesOids, XpNumber(DefaultListfontsModesOids)
+};
+
+static XpOid ValidSetupProvisoOids[] = {
+ xpoid_val_xp_setup_mandatory, xpoid_val_xp_setup_optional
+};
+static XpOidList ValidSetupProviso = {
+
+
+ ValidSetupProvisoOids, XpNumber(ValidSetupProvisoOids)
+};
+
+static XpOidDocFmt ValidDocFormatsSupportedFmts[] = {
+ { "Postscript", "2", NULL }
+};
+static XpOidDocFmtList ValidDocFormatsSupported = {
+ ValidDocFormatsSupportedFmts, XpNumber(ValidDocFormatsSupportedFmts)
+};
+
+static XpOidDocFmt DefaultDocFormatsSupportedFmts[] = {
+ { "Postscript", "2", NULL }
+};
+static XpOidDocFmtList DefaultDocFormatsSupported = {
+ DefaultDocFormatsSupportedFmts, XpNumber(DefaultDocFormatsSupportedFmts)
+};
+
+static XpOidDocFmt ValidEmbeddedFormatsSupportedFmts[] = {
+ { "Postscript", "2", NULL }
+};
+static XpOidDocFmtList ValidEmbeddedFormatsSupported = {
+ ValidEmbeddedFormatsSupportedFmts, XpNumber(ValidEmbeddedFormatsSupportedFmts)
+};
+
+static XpOidDocFmt DefaultEmbeddedFormatsSupportedFmts[] = {
+ { "Postscript", "2", NULL }
+};
+static XpOidDocFmtList DefaultEmbeddedFormatsSupported = {
+ DefaultEmbeddedFormatsSupportedFmts, XpNumber(DefaultEmbeddedFormatsSupportedFmts)
+};
+
+static XpOidDocFmt ValidRawFormatsSupportedFmts[] = {
+ { "Postscript", "2", NULL }
+
+};
+static XpOidDocFmtList ValidRawFormatsSupported = {
+ ValidRawFormatsSupportedFmts, XpNumber(ValidRawFormatsSupportedFmts)
+};
+
+static XpOidDocFmt DefaultRawFormatsSupportedFmts[] = {
+ { "Postscript", "2", NULL }
+};
+static XpOidDocFmtList DefaultRawFormatsSupported = {
+ DefaultRawFormatsSupportedFmts, XpNumber(DefaultRawFormatsSupportedFmts)
+};
+
+static XpOid ValidInputTraysOids[] = {
+ xpoid_val_input_tray_manual,
+ xpoid_val_input_tray_main,
+ xpoid_val_input_tray_envelope,
+ xpoid_val_input_tray_large_capacity,
+ xpoid_val_input_tray_bottom
+};
+static XpOidList ValidInputTrays = {
+ ValidInputTraysOids, XpNumber(ValidInputTraysOids)
+};
+
+static XpOid ValidMediumSizesOids[] = {
+ xpoid_val_medium_size_iso_a0,
+ xpoid_val_medium_size_iso_a1,
+ xpoid_val_medium_size_iso_a2,
+ xpoid_val_medium_size_iso_a3,
+ xpoid_val_medium_size_iso_a4,
+ xpoid_val_medium_size_iso_a5,
+ xpoid_val_medium_size_iso_a6,
+ xpoid_val_medium_size_iso_a7,
+ xpoid_val_medium_size_iso_a8,
+ xpoid_val_medium_size_iso_a9,
+ xpoid_val_medium_size_iso_a10,
+ xpoid_val_medium_size_iso_b0,
+ xpoid_val_medium_size_iso_b1,
+ xpoid_val_medium_size_iso_b2,
+ xpoid_val_medium_size_iso_b3,
+ xpoid_val_medium_size_iso_b4,
+ xpoid_val_medium_size_iso_b5,
+ xpoid_val_medium_size_iso_b6,
+ xpoid_val_medium_size_iso_b7,
+ xpoid_val_medium_size_iso_b8,
+ xpoid_val_medium_size_iso_b9,
+ xpoid_val_medium_size_iso_b10,
+ xpoid_val_medium_size_na_letter,
+ xpoid_val_medium_size_na_legal,
+ xpoid_val_medium_size_executive,
+ xpoid_val_medium_size_folio,
+ xpoid_val_medium_size_invoice,
+ xpoid_val_medium_size_ledger,
+ xpoid_val_medium_size_quarto,
+ xpoid_val_medium_size_iso_c3,
+ xpoid_val_medium_size_iso_c4,
+ xpoid_val_medium_size_iso_c5,
+ xpoid_val_medium_size_iso_c6,
+ xpoid_val_medium_size_iso_designated_long,
+ xpoid_val_medium_size_na_10x13_envelope,
+ xpoid_val_medium_size_na_9x12_envelope,
+ xpoid_val_medium_size_na_number_10_envelope,
+ xpoid_val_medium_size_na_7x9_envelope,
+ xpoid_val_medium_size_na_9x11_envelope,
+ xpoid_val_medium_size_na_10x14_envelope,
+ xpoid_val_medium_size_na_number_9_envelope,
+ xpoid_val_medium_size_na_6x9_envelope,
+ xpoid_val_medium_size_na_10x15_envelope,
+ xpoid_val_medium_size_monarch_envelope,
+ xpoid_val_medium_size_a,
+ xpoid_val_medium_size_b,
+ xpoid_val_medium_size_c,
+ xpoid_val_medium_size_d,
+ xpoid_val_medium_size_e,
+ xpoid_val_medium_size_jis_b0,
+ xpoid_val_medium_size_jis_b1,
+ xpoid_val_medium_size_jis_b2,
+ xpoid_val_medium_size_jis_b3,
+ xpoid_val_medium_size_jis_b4,
+ xpoid_val_medium_size_jis_b5,
+ xpoid_val_medium_size_jis_b6,
+ xpoid_val_medium_size_jis_b7,
+ xpoid_val_medium_size_jis_b8,
+ xpoid_val_medium_size_jis_b9,
+ xpoid_val_medium_size_jis_b10,
+ xpoid_val_medium_size_hp_2x_postcard,
+ xpoid_val_medium_size_hp_european_edp,
+ xpoid_val_medium_size_hp_mini,
+ xpoid_val_medium_size_hp_postcard,
+ xpoid_val_medium_size_hp_tabloid,
+ xpoid_val_medium_size_hp_us_edp,
+ xpoid_val_medium_size_hp_us_government_legal,
+ xpoid_val_medium_size_hp_us_government_letter,
+};
+static XpOidList ValidMediumSizes = {
+ ValidMediumSizesOids, XpNumber(ValidMediumSizesOids)
+};
+
+static XpOidDocFmt DefaultDocumentFormat = {
+ "Postscript", "2", NULL
+};
+
+
+/*
+ * init struct for XpValidate*Pool
+ */
+XpValidatePoolsRec PsValidatePoolsRec = {
+ &ValidContentOrientations, &DefaultContentOrientations,
+ &ValidDocFormatsSupported, &DefaultDocFormatsSupported,
+ &ValidInputTrays, &ValidMediumSizes,
+ &ValidPlexes, &DefaultPlexes,
+ &ValidPrinterResolutions, &DefaultPrinterResolutions,
+ &ValidEmbeddedFormatsSupported, &DefaultEmbeddedFormatsSupported,
+ &ValidListfontsModes, &DefaultListfontsModes,
+ &ValidRawFormatsSupported, &DefaultRawFormatsSupported,
+ &ValidSetupProviso,
+ &DefaultDocumentFormat
+};
diff --git a/nx-X11/programs/Xserver/Xprint/ps/PsAttr.c b/nx-X11/programs/Xserver/Xprint/ps/PsAttr.c
new file mode 100644
index 000000000..74da5a0e1
--- /dev/null
+++ b/nx-X11/programs/Xserver/Xprint/ps/PsAttr.c
@@ -0,0 +1,117 @@
+/* $Xorg: PsAttr.c,v 1.4 2001/02/09 02:04:35 xorgcvs Exp $ */
+/*
+
+Copyright 1996, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+/*
+ * (c) Copyright 1996 Hewlett-Packard Company
+ * (c) Copyright 1996 International Business Machines Corp.
+ * (c) Copyright 1996 Sun Microsystems, Inc.
+ * (c) Copyright 1996 Novell, Inc.
+ * (c) Copyright 1996 Digital Equipment Corp.
+ * (c) Copyright 1996 Fujitsu Limited
+ * (c) Copyright 1996 Hitachi, Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject
+ * to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the names of the copyright holders
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * from said copyright holders.
+ */
+
+/*******************************************************************
+**
+** *********************************************************
+** *
+** * File: PsAttr.c
+** *
+** * Contents: Attribute-handling functions for the PS driver
+** *
+** * Created By: Roger Helmendach (Liberty Systems)
+** *
+** * Copyright: Copyright 1996 The Open Group, Inc.
+** *
+** *********************************************************
+**
+********************************************************************/
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include "Ps.h"
+#include "attributes.h"
+
+char *
+PsGetAttributes(
+ XpContextPtr pCon,
+ XPAttributes pool)
+{
+ return XpGetAttributes(pCon, pool);
+}
+
+char *
+PsGetOneAttribute(
+ XpContextPtr pCon,
+ XPAttributes pool,
+ char *attr)
+{
+ return XpGetOneAttribute(pCon, pool, attr);
+}
+
+int
+PsAugmentAttributes(
+ XpContextPtr pCon,
+ XPAttributes pool,
+ char *attrs)
+{
+ return XpAugmentAttributes(pCon, pool, attrs);
+}
+
+int
+PsSetAttributes(
+ XpContextPtr pCon,
+ XPAttributes pool,
+ char *attrs)
+{
+ return XpSetAttributes(pCon, pool, attrs);
+}
diff --git a/nx-X11/programs/Xserver/Xprint/ps/PsCache.c b/nx-X11/programs/Xserver/Xprint/ps/PsCache.c
new file mode 100644
index 000000000..e69aa2eb7
--- /dev/null
+++ b/nx-X11/programs/Xserver/Xprint/ps/PsCache.c
@@ -0,0 +1,328 @@
+/*
+
+Copyright 1996, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+/*
+ * (c) Copyright 1996 Hewlett-Packard Company
+ * (c) Copyright 1996 International Business Machines Corp.
+ * (c) Copyright 1996, 2000 Sun Microsystems, Inc. All Rights Reserved.
+ * (c) Copyright 1996 Novell, Inc.
+ * (c) Copyright 1996 Digital Equipment Corp.
+ * (c) Copyright 1996 Fujitsu Limited
+ * (c) Copyright 1996 Hitachi, Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject
+ * to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the names of the copyright holders
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * from said copyright holders.
+ */
+
+/*******************************************************************
+**
+** *********************************************************
+** *
+** * File: PsCache.c
+** *
+** * Contents: Character-caching routines
+** *
+** * Created By: Jay Hobson (Sun MicroSystems)
+** *
+** * Copyright: Copyright 1996 The Open Group, Inc.
+** *
+** *********************************************************
+**
+********************************************************************/
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include "Ps.h"
+#include "gcstruct.h"
+#include "windowstr.h"
+#include <X11/fonts/fntfil.h>
+#include <X11/fonts/fntfilst.h>
+
+#define GET 0
+#define RESET 1
+
+struct bm_cache_list {
+ struct bm_cache_list *next;
+ struct bm_cache_list *prev;
+ int height;
+ long id;
+ char *pBuffer;
+};
+
+struct bm_cache_head {
+ struct bm_cache_list *head;
+ int width;
+ struct bm_cache_head *next;
+ struct bm_cache_head *prev;
+};
+
+static struct bm_cache_head *bm_cache = NULL;
+
+static long
+PsBmUniqueId(int func)
+{
+ static long unique_id = 0;
+
+ if(func == RESET)
+ {
+ unique_id = 0;
+ return 0;
+ }
+ else
+ return ++unique_id;
+}
+
+int
+PsBmIsImageCached(
+ int gWidth,
+ int gHeight,
+ char *pBuffer)
+{
+ int return_val = 0;
+ struct bm_cache_head *pList = bm_cache;
+
+ while(pList != NULL && !return_val)
+ {
+ if(pList->width == gWidth)
+ {
+ struct bm_cache_list *pItem = pList->head;
+
+ while(pItem != NULL)
+ {
+ if(pItem->height == gHeight)
+ {
+ int length = 4*(gWidth/32+(gWidth%32!=0))*gHeight;
+
+ if(!memcmp(pItem->pBuffer, pBuffer, sizeof(char)*length))
+ {
+ return_val = pItem->id;
+ break;
+ }
+ }
+ else if(pItem->height > gHeight)
+ break;
+
+ pItem = pItem->next;
+ }
+ }
+ else if(pList->width > gWidth)
+ break;
+
+ pList = pList->next;
+ }
+ return return_val;
+}
+
+int
+PsBmPutImageInCache(
+ int gWidth,
+ int gHeight,
+ char *pBuffer)
+{
+ int return_val = 0;
+ struct bm_cache_head *pList = bm_cache;
+ struct bm_cache_list *pNew;
+ int length = 4*(gWidth/32+(gWidth%32!=0))*gHeight;
+
+ if(gWidth == 1 && gHeight == 1 && pBuffer[0] == 0)
+ return return_val;
+
+ pNew = (struct bm_cache_list *)malloc(sizeof(struct bm_cache_list));
+ pNew->next = NULL;
+ pNew->prev = NULL;
+ pNew->height = gHeight;
+ pNew->id = PsBmUniqueId(GET);
+ pNew->pBuffer = (char *)malloc(sizeof(char)*length);
+
+ memcpy(pNew->pBuffer, pBuffer, length);
+
+ while(pList != NULL)
+ {
+ if(pList->width == gWidth)
+ {
+ struct bm_cache_list *pItem = pList->head;
+
+ while(pItem != NULL)
+ {
+ if(pItem->height >= gHeight)
+ {
+ pNew->next = pItem;
+ pNew->prev = pItem->prev;
+ if(pItem->prev != NULL)
+ pItem->prev->next = pNew;
+ else
+ pList->head = pNew;
+ pItem->prev = pNew;
+
+ return_val = pNew->id;
+
+ break;
+ }
+ else if(pItem->next == NULL)
+ {
+ pNew->prev = pItem;
+ pItem->next = pNew;
+
+ return_val = pNew->id;
+
+ break;
+ }
+
+ pItem = pItem->next;
+ }
+
+ break;
+ }
+
+ pList = pList->next;
+ }
+
+ if(pList == NULL)
+ {
+ struct bm_cache_head *pNewList;
+
+ pNewList = (struct bm_cache_head *)malloc(sizeof(struct bm_cache_head));
+
+ pNewList->next = NULL;
+ pNewList->prev = NULL;
+ pNewList->width = gWidth;
+ pNewList->head = pNew;
+
+ if(bm_cache == NULL)
+ {
+ bm_cache = pNewList;
+ return_val = pNew->id;
+ }
+ else
+ {
+ pList = bm_cache;
+
+ while(pList != NULL)
+ {
+ if(pList->width > gWidth)
+ {
+ pNewList->next = pList;
+ pNewList->prev = pList->prev;
+
+ if(pList->prev != NULL)
+ pList->prev->next = pNewList;
+ else
+ bm_cache = pNewList;
+ pList->prev = pNewList;
+
+ return_val = pNew->id;
+
+ break;
+ }
+ else if(pList->next == NULL)
+ {
+ pNewList->prev = pList;
+ pList->next = pNewList;
+
+ return_val = pNew->id;
+
+ break;
+ }
+
+ pList = pList->next;
+ }
+ }
+ }
+
+ return return_val;
+}
+
+
+static void
+PsBmClearImageCacheItem(
+ struct bm_cache_list *pItem)
+{
+ if(pItem != NULL)
+ {
+ if(pItem->pBuffer != NULL)
+ free(pItem->pBuffer);
+ pItem->pBuffer = NULL;
+
+ if(pItem->next)
+ PsBmClearImageCacheItem(pItem->next);
+ pItem->next = NULL;
+
+ free(pItem);
+ pItem = NULL;
+ }
+}
+
+static void
+PsBmClearImageCacheList(
+ struct bm_cache_head *pList)
+{
+ if(pList != NULL)
+ {
+ if(pList->head)
+ PsBmClearImageCacheItem(pList->head);
+ pList->head = NULL;
+
+ if(pList->next)
+ PsBmClearImageCacheList(pList->next);
+ pList->next = NULL;
+
+ free(pList);
+ pList = NULL;
+ }
+}
+
+void
+PsBmClearImageCache()
+{
+ PsBmClearImageCacheList(bm_cache);
+
+ bm_cache = NULL;
+
+ PsBmUniqueId(RESET);
+}
+
diff --git a/nx-X11/programs/Xserver/Xprint/ps/PsColor.c b/nx-X11/programs/Xserver/Xprint/ps/PsColor.c
new file mode 100644
index 000000000..91a44f85a
--- /dev/null
+++ b/nx-X11/programs/Xserver/Xprint/ps/PsColor.c
@@ -0,0 +1,258 @@
+/* $Xorg: PsColor.c,v 1.4 2001/02/09 02:04:36 xorgcvs Exp $ */
+/*
+
+Copyright 1996, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+/*
+ * (c) Copyright 1996 Hewlett-Packard Company
+ * (c) Copyright 1996 International Business Machines Corp.
+ * (c) Copyright 1996 Sun Microsystems, Inc.
+ * (c) Copyright 1996 Novell, Inc.
+ * (c) Copyright 1996 Digital Equipment Corp.
+ * (c) Copyright 1996 Fujitsu Limited
+ * (c) Copyright 1996 Hitachi, Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject
+ * to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the names of the copyright holders
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * from said copyright holders.
+ */
+
+/*******************************************************************
+**
+** *********************************************************
+** *
+** * File: PsColor.c
+** *
+** * Contents: Color routines for the PS driver
+** *
+** * Created By: Roger Helmendach (Liberty Systems)
+** *
+** * Copyright: Copyright 1996 The Open Group, Inc.
+** *
+** *********************************************************
+**
+********************************************************************/
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include "Ps.h"
+#include "mi.h"
+#include "micmap.h"
+#include "gcstruct.h"
+#include "windowstr.h"
+#include "colormapst.h"
+
+Bool
+PsCreateColormap(ColormapPtr pColor)
+{
+ return miInitializeColormap(pColor);
+}
+
+void
+PsDestroyColormap(ColormapPtr pColor)
+{
+ /* NO-OP */
+}
+
+void
+PsInstallColormap(ColormapPtr pColor)
+{
+ miInstallColormap(pColor);
+}
+
+void
+PsUninstallColormap(ColormapPtr pColor)
+{
+ miUninstallColormap(pColor);
+}
+
+int
+PsListInstalledColormaps(
+ ScreenPtr pScreen,
+ XID *pCmapList)
+{
+ return miListInstalledColormaps(pScreen, pCmapList);
+}
+
+void
+PsStoreColors(
+ ColormapPtr pColor,
+ int ndef,
+ xColorItem *pdefs)
+{
+ int i;
+ for( i=0 ; i<ndef ; i++ )
+ {
+ if( pdefs[i].flags&DoRed )
+ pColor->red[pdefs[i].pixel].co.local.red = pdefs[i].red;
+ if( pdefs[i].flags&DoGreen )
+ pColor->red[pdefs[i].pixel].co.local.green = pdefs[i].green;
+ if( pdefs[i].flags&DoBlue )
+ pColor->red[pdefs[i].pixel].co.local.blue = pdefs[i].blue;
+ }
+}
+
+void
+PsResolveColor(
+ unsigned short *pRed,
+ unsigned short *pGreen,
+ unsigned short *pBlue,
+ VisualPtr pVisual)
+{
+ miResolveColor(pRed, pGreen, pBlue, pVisual);
+}
+
+PsOutColor
+PsGetPixelColor(ColormapPtr cMap, int pixval)
+{
+ VisualPtr v = cMap->pVisual;
+ switch( v->class )
+ {
+ case TrueColor:
+ {
+ PsOutColor p = pixval;
+ PsOutColor r, g, b;
+
+ r = (p & v->redMask) >> v->offsetRed;
+ g = (p & v->greenMask) >> v->offsetGreen;
+ b = (p & v->blueMask) >> v->offsetBlue;
+
+ r = cMap->red[r].co.local.red;
+ g = cMap->green[g].co.local.green;
+ b = cMap->blue[b].co.local.blue;
+
+#ifdef PSOUT_USE_DEEPCOLOR
+ return((r<<32)|(g<<16)|b);
+#else
+ r >>= 8;
+ g >>= 8;
+ b >>= 8;
+
+ return((r<<16)|(g<<8)|b);
+#endif /* PSOUT_USE_DEEPCOLOR */
+ }
+ case PseudoColor:
+ case GrayScale:
+ case StaticGray:
+ {
+ PsOutColor r, g, b;
+
+ if( pixval < 0 || pixval > v->ColormapEntries)
+ return(0);
+
+ r = cMap->red[pixval].co.local.red;
+ g = cMap->red[pixval].co.local.green;
+ b = cMap->red[pixval].co.local.blue;
+
+ if ((v->class | DynamicClass) == GrayScale)
+ {
+ /* rescale to gray (see |miResolveColor()|) */
+ r = g = b = (30L*r + 59L*g + 11L*b) / 100L;
+ }
+
+#ifdef PSOUT_USE_DEEPCOLOR
+ return((r<<32)|(g<<16)|b);
+#else
+ r >>= 8;
+ g >>= 8;
+ b >>= 8;
+
+ return((r<<16)|(g<<8)|b);
+#endif /* PSOUT_USE_DEEPCOLOR */
+ }
+ default:
+ FatalError("PsGetPixelColor: Unsupported visual %x\n",
+ (int)cMap->pVisual->class);
+ break;
+ }
+
+ return 0; /* NO-OP*/
+}
+
+void
+PsSetFillColor(DrawablePtr pDrawable, GCPtr pGC, PsOutPtr psOut,
+ ColormapPtr cMap)
+{
+ switch(pGC->fillStyle)
+ {
+ case FillSolid:
+ PsOut_Color(psOut, PsGetPixelColor(cMap, pGC->fgPixel));
+ break;
+ case FillTiled:
+ if( !PsOut_BeginPattern(psOut, pGC->tile.pixmap,
+ pGC->tile.pixmap->drawable.width,
+ pGC->tile.pixmap->drawable.height, PsTile, 0, 0) )
+ {
+ PsReplayPixmap(pGC->tile.pixmap, pDrawable);
+ PsOut_EndPattern(psOut);
+ }
+ PsOut_SetPattern(psOut, pGC->tile.pixmap, PsTile);
+ break;
+ case FillStippled:
+ if( !PsOut_BeginPattern(psOut, pGC->stipple,
+ pGC->stipple->drawable.width,
+ pGC->stipple->drawable.height, PsStip, 0,
+ PsGetPixelColor(cMap, pGC->fgPixel)) )
+ {
+ PsReplayPixmap(pGC->stipple, pDrawable);
+ PsOut_EndPattern(psOut);
+ }
+ PsOut_SetPattern(psOut, pGC->stipple, PsStip);
+ break;
+ case FillOpaqueStippled:
+ if( !PsOut_BeginPattern(psOut, pGC->stipple,
+ pGC->stipple->drawable.width,
+ pGC->stipple->drawable.height, PsOpStip,
+ PsGetPixelColor(cMap, pGC->bgPixel),
+ PsGetPixelColor(cMap, pGC->fgPixel)) )
+ {
+ PsReplayPixmap(pGC->stipple, pDrawable);
+ PsOut_EndPattern(psOut);
+ }
+ PsOut_SetPattern(psOut, pGC->stipple, PsOpStip);
+ break;
+ }
+}
diff --git a/nx-X11/programs/Xserver/Xprint/ps/PsDef.h b/nx-X11/programs/Xserver/Xprint/ps/PsDef.h
new file mode 100644
index 000000000..cf45c8516
--- /dev/null
+++ b/nx-X11/programs/Xserver/Xprint/ps/PsDef.h
@@ -0,0 +1,97 @@
+/* $Xorg: PsDef.h,v 1.4 2001/02/09 02:04:36 xorgcvs Exp $ */
+/*
+
+Copyright 1996, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+/*
+ * (c) Copyright 1996 Hewlett-Packard Company
+ * (c) Copyright 1996 International Business Machines Corp.
+ * (c) Copyright 1996 Sun Microsystems, Inc.
+ * (c) Copyright 1996 Novell, Inc.
+ * (c) Copyright 1996 Digital Equipment Corp.
+ * (c) Copyright 1996 Fujitsu Limited
+ * (c) Copyright 1996 Hitachi, Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject
+ * to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the names of the copyright holders
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * from said copyright holders.
+ */
+
+/*******************************************************************
+**
+** *********************************************************
+** *
+** * File: PsDef.h
+** *
+** * Contents: extran defines and includes for the Ps driver
+** * for a printing X server.
+** *
+** * Created By: Roger Helmendach (Liberty Systems)
+** *
+** * Copyright: Copyright 1996 The Open Group, Inc.
+** *
+** *********************************************************
+**
+********************************************************************/
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#ifndef _PSDEF_H_
+#define _PSDEF_H_
+
+#define DT_PRINT_JOB_HEADER "DT_PRINT_JOB_HEADER"
+#define DT_PRINT_JOB_TRAILER "DT_PRINT_JOB_TRAILER"
+#define DT_PRINT_JOB_COMMAND "DT_PRINT_JOB_COMMAND"
+#define DT_PRINT_JOB_EXEC_COMMAND "DT_PRINT_JOB_EXEC_COMMAND"
+#define DT_PRINT_JOB_EXEC_OPTIONS "DT_PRINT_JOB_EXEC_OPTION"
+#define DT_PRINT_PAGE_HEADER "DT_PRINT_PAGE_HEADER"
+#define DT_PRINT_PAGE_TRAILER "DT_PRINT_PAGE_TRAILER"
+#define DT_PRINT_PAGE_COMMAND "DT_PRINT_PAGE_COMMAND"
+
+#define DT_IN_FILE_STRING "%(InFile)%"
+#define DT_OUT_FILE_STRING "%(OutFile)%"
+#define DT_ALLOWED_COMMANDS_FILE "printCommands"
+
+#endif /* _PSDEF_H_ */
diff --git a/nx-X11/programs/Xserver/Xprint/ps/PsFTFonts.c b/nx-X11/programs/Xserver/Xprint/ps/PsFTFonts.c
new file mode 100644
index 000000000..c992987d4
--- /dev/null
+++ b/nx-X11/programs/Xserver/Xprint/ps/PsFTFonts.c
@@ -0,0 +1,85 @@
+
+/*
+Copyright (c) 2003-2004 Roland Mainz <roland.mainz@nrubsig.org>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include <ctype.h>
+#include <limits.h>
+#include <sys/stat.h>
+
+#include "regionstr.h"
+#include <X11/fonts/fontstruct.h>
+#include "dixfontstr.h"
+#include "scrnintstr.h"
+#include <X11/fonts/fontxlfd.h>
+#include <X11/fonts/fntfil.h>
+#include <X11/fonts/fntfilst.h>
+
+#include "Ps.h"
+
+#include <ft2build.h>
+#include FT_FREETYPE_H
+
+#include "ft.h"
+#define NOT_IN_FTFUNCS
+#include "ftfuncs.h"
+
+char *
+PsGetFTFontFileName(FontPtr pFont)
+{
+ FTFontPtr tf = (FTFontPtr)pFont->fontPrivate;
+ return tf->instance->face->filename;
+}
+
+Bool
+PsIsFreeTypeFont(FontPtr pFont)
+{
+ int i;
+ int nprops = pFont->info.nprops;
+ FontPropPtr props = pFont->info.props;
+ /* "RASTERIZER_NAME" must match the rasterizer name set in
+ * xc/lib/font/FreeType/ftfuncs.c */
+ Atom name = MakeAtom("RASTERIZER_NAME", 15, True);
+ Atom value = (Atom)0;
+ char *rv;
+
+ for( i=0 ; i<nprops ; i++ )
+ {
+ if( props[i].name==name )
+ { value = props[i].value; break; }
+ }
+ if( !value )
+ return False;
+
+ rv = NameForAtom(value);
+ if( !rv )
+ return False;
+
+ if( memcmp(rv, "FreeType", 8) == 0 )
+ return True;
+
+ return False;
+}
+
diff --git a/nx-X11/programs/Xserver/Xprint/ps/PsFonts.c b/nx-X11/programs/Xserver/Xprint/ps/PsFonts.c
new file mode 100644
index 000000000..515a31884
--- /dev/null
+++ b/nx-X11/programs/Xserver/Xprint/ps/PsFonts.c
@@ -0,0 +1,876 @@
+/* $Xorg: PsFonts.c,v 1.6 2001/03/06 16:30:15 pookie Exp $ */
+/*
+
+Copyright 1996, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+/*
+ * (c) Copyright 1996 Hewlett-Packard Company
+ * (c) Copyright 1996 International Business Machines Corp.
+ * (c) Copyright 1996 Sun Microsystems, Inc.
+ * (c) Copyright 1996 Novell, Inc.
+ * (c) Copyright 1996 Digital Equipment Corp.
+ * (c) Copyright 1996 Fujitsu Limited
+ * (c) Copyright 1996 Hitachi, Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject
+ * to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the names of the copyright holders
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * from said copyright holders.
+ */
+
+/*******************************************************************
+**
+** *********************************************************
+** *
+** * File: PsFonts.c
+** *
+** * Contents: Font code for PS driver.
+** *
+** * Created By: Roger Helmendach (Liberty Systems)
+** *
+** * Copyright: Copyright 1996 The Open Group, Inc.
+** *
+** *********************************************************
+**
+********************************************************************/
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include "regionstr.h"
+#include <X11/fonts/fontstruct.h>
+#include "dixfontstr.h"
+#include "scrnintstr.h"
+#include <X11/fonts/fontxlfd.h>
+#include <X11/fonts/fntfil.h>
+#include <X11/fonts/fntfilst.h>
+
+#include "Ps.h"
+
+#include <ctype.h>
+#include <limits.h>
+#include <sys/stat.h>
+
+Bool
+PsRealizeFont(
+ ScreenPtr pscr,
+ FontPtr pFont)
+{
+ return TRUE;
+}
+
+Bool
+PsUnrealizeFont(
+ ScreenPtr pscr,
+ FontPtr pFont)
+{
+ return TRUE;
+}
+
+char *
+PsGetFontName(FontPtr pFont)
+{
+ int i;
+ int nprops = pFont->info.nprops;
+ FontPropPtr props = pFont->info.props;
+ Atom name = MakeAtom("FONT", 4, True);
+ Atom value = (Atom)0;
+
+ for( i=0 ; i<nprops ; i++ )
+ {
+ if( (Atom)props[i].name==name )
+ { value = props[i].value; break; }
+ }
+ if( !value ) return (char *)0;
+ return NameForAtom(value);
+}
+
+int
+PsGetFontSize(FontPtr pFont, float *mtx)
+{
+ FontScalableRec vals;
+ char *name = PsGetFontName(pFont);
+ int value = 0;
+
+ FontParseXLFDName(name, &vals, FONT_XLFD_REPLACE_NONE);
+ if( vals.values_supplied&PIXELSIZE_ARRAY )
+ {
+ int i;
+ for( i=0 ; i<4 ; i++ )
+ mtx[i] = (float)vals.pixel_matrix[i];
+ }
+ else
+ {
+ value = vals.pixel;
+ if( !value ) value = 20;
+ }
+ return value;
+}
+
+char *
+PsGetPSFontName(FontPtr pFont)
+{
+ int i;
+ int nprops = pFont->info.nprops;
+ FontPropPtr props = pFont->info.props;
+ /* "_ADOBE_POSTSCRIPT_FONTNAME" maps directly to a PMF OBJ_NAME attribute
+ * name - changing the name will break printer-builtin fonts. */
+ Atom name = MakeAtom("_ADOBE_POSTSCRIPT_FONTNAME", 26, True);
+ Atom value = (Atom)0;
+
+ for( i=0 ; i<nprops ; i++ )
+ {
+ if( (Atom)props[i].name==name )
+ { value = props[i].value; break; }
+ }
+ if( !value ) return (char *)0;
+ return NameForAtom(value);
+}
+
+int
+PsIsISOLatin1Encoding(FontPtr pFont)
+{
+ int i;
+ int nprops = pFont->info.nprops;
+ FontPropPtr props = pFont->info.props;
+ Atom reg = MakeAtom("CHARSET_REGISTRY", 16, True);
+ Atom enc = MakeAtom("CHARSET_ENCODING", 16, True);
+ Atom rv = 0, ev = 0;
+ char *rp = 0;
+ char *ep = 0;
+
+ for( i=0 ; i<nprops ; i++ )
+ {
+ if( (Atom)props[i].name==reg ) rv = props[i].value;
+ if( (Atom)props[i].name==enc ) ev = props[i].value;
+ }
+ if( rv ) rp = NameForAtom(rv);
+ if( ev ) ep = NameForAtom(ev);
+ if( (!rp) || (!ep) ) return(0);
+ if( (char)tolower(rp[0])!='i' ||
+ (char)tolower(rp[1])!='s' ||
+ (char)tolower(rp[2])!='o' ||
+ memcmp(&rp[3], "8859", 4)!=0 ||
+ ep[0]!='1' ) return(0);
+ return(1);
+}
+
+/* Return the encoding part of the XLFD (e.g. "*-iso8859-6.8x" etc.)*/
+char *PsGetEncodingName(FontPtr pFont)
+{
+ int i;
+ int nprops = pFont->info.nprops;
+ FontPropPtr props = pFont->info.props;
+ Atom fnt = MakeAtom("FONT", 4, True);
+ Atom reg = MakeAtom("CHARSET_REGISTRY", 16, True);
+ Atom enc = MakeAtom("CHARSET_ENCODING", 16, True);
+ Atom fv = 0, rv = 0, ev = 0;
+ char *fp = 0;
+ char *rp = 0;
+ char *ep = 0;
+ char *encname;
+
+ for( i=0 ; i<nprops ; i++ )
+ {
+ if( props[i].name==fnt ) fv = props[i].value;
+ if( props[i].name==reg ) rv = props[i].value;
+ if( props[i].name==enc ) ev = props[i].value;
+ }
+ if( fv ) fp = NameForAtom(fv);
+ if( rv ) rp = NameForAtom(rv);
+ if( ev ) ep = NameForAtom(ev);
+
+ if( (!rp) || (!ep) || (!fp))
+ return(0);
+
+ encname = fp;
+ encname += strlen(encname) - (strlen(rp) + strlen(ep) + 1);
+
+ return encname;
+}
+
+/* strstr(), case-insensitive */
+static
+char *str_case_str(const char *s, const char *find)
+{
+ size_t len;
+ char c,
+ sc;
+
+ if ((c = tolower(*find++)) != '\0')
+ {
+ len = strlen(find);
+ do
+ {
+ do
+ {
+ if ((sc = tolower(*s++)) == '\0')
+ return NULL;
+ } while (sc != c);
+ } while (strncasecmp(s, find, len) != 0);
+ s--;
+ }
+ return ((char *)s);
+}
+
+/* Check if the font path element is a directory which can be examined
+ * (for example the font may be from a font server
+ * (e.g. pFont->fpe->name == "tcp/:7100"))
+ */
+static
+Bool IsFPEaReadableDir(FontPtr pFont)
+{
+ const char *fpe_name = pFont->fpe->name;
+ if (!fpe_name)
+ return False;
+
+#define MODEL_FONTPATH_PREFIX "PRINTER:"
+#define MODEL_FONTPATH_PREFIX_LEN 8
+ /* Strip model-specific font path prefix if there is one... */
+ if (!strncmp(fpe_name, MODEL_FONTPATH_PREFIX, MODEL_FONTPATH_PREFIX_LEN))
+ fpe_name += MODEL_FONTPATH_PREFIX_LEN;
+
+ if (access(fpe_name, F_OK) == 0)
+ {
+ return True;
+ }
+
+ return False;
+}
+
+static
+char *getFontFilename(FontPtr pFont)
+{
+ FontDirectoryPtr dir;
+ const char *dlfnam;
+ FILE *file;
+ struct stat statb;
+ int count, i, status;
+ char buf[512];
+ char *front, *end, *fn;
+ char font_dir_fname[PATH_MAX], /* Full path of fonts.dir */
+ font_file_fname[PATH_MAX]; /* Name of font file (excluding path) */
+
+#ifdef XP_USE_FREETYPE
+ if( PsIsFreeTypeFont(pFont) )
+ {
+ const char *fontname = PsGetFTFontFileName(pFont);
+
+#ifdef DEBUG_gisburn
+ fprintf(stderr, "getFontFilename: freetype font, file='%s'\n", fontname?fontname:"<NULL>");
+#endif /* DEBUG_gisburn */
+
+ if( !fontname )
+ return NULL;
+
+ return strdup(fontname);
+ }
+#endif /* XP_USE_FREETYPE */
+
+ if (!IsFPEaReadableDir(pFont))
+ {
+#ifdef DEBUG_gisburn
+ fprintf(stderr, "getFontFilename: '%s' no valid font path on disk\n", pFont->fpe->name);
+#endif /* DEBUG_gisburn */
+ return NULL;
+ }
+
+ dir = pFont->fpe->private;
+ sprintf(font_dir_fname, "%s%s", dir->directory, "fonts.dir");
+
+ if (!(dlfnam = PsGetFontName(pFont)))
+ return NULL;
+
+ file = fopen(font_dir_fname, "r");
+ if (file)
+ {
+ if (fstat (fileno(file), &statb) == -1)
+ return NULL;
+
+ while( fgets(buf, sizeof(buf)-1, file) )
+ {
+ if ((fn = strstr(buf, " -")))
+ {
+ strcpy(font_file_fname, buf);
+ font_file_fname[fn - buf] = '\0';
+ fn++;
+ if ((front = str_case_str(fn, "normal-")))
+ {
+ fn[front - fn] = '\0';
+ if (str_case_str(dlfnam, fn))
+ {
+ char full_font_file_path[PATH_MAX];
+
+ fclose(file);
+
+ sprintf(full_font_file_path, "%s%s", dir->directory, font_file_fname);
+
+#ifdef xDEBUG_gisburn
+ fprintf(stderr, "getFontFilename: returning '%s'\n", full_font_file_path);
+#endif /* DEBUG_gisburn */
+ return strdup(full_font_file_path);
+ }
+ }
+ }
+ }
+ }
+ font_file_fname[0] = '\0';
+ fclose(file);
+
+#ifdef DEBUG_gisburn
+ fprintf(stderr, "getFontFilename: returning NULL\n");
+#endif /* DEBUG_gisburn */
+
+ return NULL;
+}
+
+static
+PsFontTypeInfoRec *PsFindFontTypeInfoRec(DrawablePtr pDrawable, FontPtr pFont)
+{
+ PsContextPrivRec *cPriv = PsGetPsContextPriv(pDrawable);
+ PsFontTypeInfoRec *rec;
+ const char *psname;
+ char *font_filename;
+ char *encname;
+#ifdef XP_USE_FREETYPE
+ Bool is_freetypefont;
+#endif /* XP_USE_FREETYPE */
+
+#ifdef XP_USE_FREETYPE
+ is_freetypefont = PsIsFreeTypeFont(pFont);
+#endif /* XP_USE_FREETYPE */
+ encname = PsGetEncodingName(pFont);
+
+ /* First try: Search by PostScript font name */
+ psname = PsGetPSFontName(pFont);
+ if (psname)
+ {
+ for( rec = cPriv->fontTypeInfoRecords ; rec != NULL ; rec = rec->next )
+ {
+#ifdef XP_USE_FREETYPE
+ if (is_freetypefont)
+ {
+ if (rec->adobe_ps_name)
+ {
+ if ((rec->font_type == PSFTI_FONT_TYPE_FREETYPE) &&
+ (!strcmp(rec->adobe_ps_name, psname)) &&
+ (!strcmp(rec->ft_download_encoding, encname)))
+ {
+ return rec;
+ }
+ }
+ }
+ else
+#endif /* XP_USE_FREETYPE */
+ {
+ if (rec->adobe_ps_name)
+ {
+ if ((rec->font_type != PSFTI_FONT_TYPE_FREETYPE) &&
+ (!strcmp(rec->adobe_ps_name, psname)))
+ {
+ return rec;
+ }
+ }
+ }
+ }
+ }
+
+ /* Last attempt: Search by filename */
+ font_filename = getFontFilename(pFont);
+ if (font_filename)
+ {
+ for( rec = cPriv->fontTypeInfoRecords ; rec != NULL ; rec = rec->next )
+ {
+ if (rec->filename)
+ {
+#ifdef XP_USE_FREETYPE
+ if (is_freetypefont)
+ {
+ if ( (rec->font_type == PSFTI_FONT_TYPE_FREETYPE) &&
+ (!strcasecmp(rec->filename, font_filename)) &&
+ (!strcasecmp(rec->ft_download_encoding, encname)) )
+ {
+ free(font_filename);
+ return rec;
+ }
+ }
+ else
+#endif /* XP_USE_FREETYPE */
+ {
+ if ( (rec->font_type != PSFTI_FONT_TYPE_FREETYPE) &&
+ (!strcasecmp(rec->filename, font_filename)) )
+ {
+ free(font_filename);
+ return rec;
+ }
+ }
+ }
+ }
+
+ free(font_filename);
+ }
+
+ return NULL;
+}
+
+static
+void PsAddFontTypeInfoRec(DrawablePtr pDrawable, PsFontTypeInfoRec *add_rec)
+{
+ PsContextPrivRec *cPriv = PsGetPsContextPriv(pDrawable);
+
+ /* ToDO: Always move the last used entry to the top that the list get's
+ * sorted in an efficient order... :-) */
+ add_rec->next = cPriv->fontTypeInfoRecords;
+ cPriv->fontTypeInfoRecords = add_rec;
+}
+
+static
+Bool strcaseendswith(const char *str, const char *suffix)
+{
+ const char *s;
+
+ s = str + strlen(str) - strlen(suffix);
+
+ if (!strcasecmp(s, suffix))
+ return True;
+
+ return False;
+}
+
+
+static
+int getFontFileType( const char *filename )
+{
+ int type;
+
+ /* Is this a Adobe PostScript Type 1 binary font (PFB) ? */
+ if( strcaseendswith(filename, ".pfb") )
+ {
+ type = PSFTI_FONT_TYPE_PS_TYPE1_PFB;
+ }
+ /* Is this a Adobe PostScript ASCII font (PFA) ? */
+ else if( strcaseendswith(filename, ".pfa") )
+ {
+ type = PSFTI_FONT_TYPE_PS_TYPE1_PFA;
+ }
+ /* Is this a PMF(=Printer Metrics File) ? */
+ else if( strcaseendswith(filename, ".pmf") )
+ {
+ type = PSFTI_FONT_TYPE_PMF;
+ }
+ /* Is this a TrueType font file ? */
+ else if( strcaseendswith(filename, ".ttf") ||
+ strcaseendswith(filename, ".ttc") ||
+ strcaseendswith(filename, ".otf") ||
+ strcaseendswith(filename, ".otc") )
+ {
+ type = PSFTI_FONT_TYPE_TRUETYPE;
+ }
+ else
+ {
+ type = PSFTI_FONT_TYPE_OTHER;
+ }
+
+#ifdef XP_USE_FREETYPE
+ {
+ XpContextPtr pCon;
+ char *downloadfonts;
+ pCon = XpGetPrintContext(requestingClient);
+ downloadfonts = XpGetOneAttribute(pCon, XPPrinterAttr, "xp-psddx-download-fonts");
+ if( downloadfonts )
+ {
+ /* Should we download PS Type1 fonts as PS Type1||Type3 ? */
+ if( (type == PSFTI_FONT_TYPE_PS_TYPE1_PFA) &&
+ (strstr(downloadfonts, "pfa") != NULL) )
+ {
+ type = PSFTI_FONT_TYPE_FREETYPE;
+ }
+
+ if( (type == PSFTI_FONT_TYPE_PS_TYPE1_PFB) &&
+ (strstr(downloadfonts, "pfb") != NULL) )
+ {
+ type = PSFTI_FONT_TYPE_FREETYPE;
+ }
+
+ /* Should we download TrueType fonts as PS Type1||Type3 ? */
+ if( (type == PSFTI_FONT_TYPE_TRUETYPE) &&
+ ((strstr(downloadfonts, "ttf") != NULL) ||
+ (strstr(downloadfonts, "ttc") != NULL) ||
+ (strstr(downloadfonts, "otf") != NULL) ||
+ (strstr(downloadfonts, "otc") != NULL)) )
+ {
+ type = PSFTI_FONT_TYPE_FREETYPE;
+ }
+ }
+ }
+#endif /* XP_USE_FREETYPE */
+
+#ifdef DEBUG_gisburn
+ fprintf(stderr, "getFontFileType: '%s' is %d\n", filename, (int)type);
+#endif /* DEBUG_gisburn */
+ return type;
+}
+
+PsFTDownloadFontType PsGetFTDownloadFontType(void)
+{
+ PsFTDownloadFontType downloadfonttype;
+ XpContextPtr pCon;
+ char *psfonttype;
+
+ pCon = XpGetPrintContext(requestingClient);
+ psfonttype = XpGetOneAttribute(pCon, XPPrinterAttr, "xp-psddx-download-font-type");
+
+ if( !psfonttype || !strlen(psfonttype) )
+ {
+ return PsFontType1; /* Default download font type is PS Type1 */
+ }
+
+ if( !strcmp(psfonttype, "bitmap") )
+ {
+ downloadfonttype = PsFontBitmap;
+ }
+ else if( !strcmp(psfonttype, "pstype3") )
+ {
+ downloadfonttype = PsFontType3;
+ }
+ else if( !strcmp(psfonttype, "pstype1") )
+ {
+ downloadfonttype = PsFontType1;
+ }
+ else
+ {
+ FatalError("PS DDX: XPPrinterAttr/xp-psddx-download-freetype-font-type='%s' not implemented\n", psfonttype);
+ return 0; /* NO-OP, FatalError() will call |exit()| */
+ }
+
+ return downloadfonttype;
+}
+
+static
+PsFontTypeInfoRec *PsCreateFontTypeInfoRec(DrawablePtr pDrawable, FontPtr pFont)
+{
+ char *dlfnam;
+ PsFontTypeInfoRec *rec;
+ char *psname;
+
+ if (!(dlfnam = PsGetFontName(pFont)))
+ return NULL;
+
+ if (!(rec = (PsFontTypeInfoRec *)xalloc(sizeof(PsFontTypeInfoRec))))
+ return NULL;
+ memset(rec, 0, sizeof(PsFontTypeInfoRec));
+
+ rec->next = NULL;
+
+ if ((rec->filename = getFontFilename(pFont)))
+ {
+ rec->font_type = getFontFileType(rec->filename);
+ }
+ else
+ {
+ rec->filename = NULL;
+ rec->font_type = PSFTI_FONT_TYPE_OTHER;
+ }
+
+ rec->adobe_ps_name = PsGetPSFontName(pFont);
+#ifdef XP_USE_FREETYPE
+ rec->ft_download_encoding = PsGetEncodingName(pFont);
+ rec->ft_download_font_type = PsGetFTDownloadFontType();
+#endif /* XP_USE_FREETYPE */
+ rec->download_ps_name = NULL;
+
+#define SET_FONT_DOWNLOAD_STATUS(rec, downloaded) { int i; for (i = 0 ; i < 256 ; i++) { (rec)->alreadyDownloaded[i]=(downloaded); } }
+
+ /* Set some flags based on the font type */
+ switch( rec->font_type )
+ {
+ case PSFTI_FONT_TYPE_PS_TYPE1_PFA:
+ case PSFTI_FONT_TYPE_PS_TYPE1_PFB:
+ rec->downloadableFont = True;
+ SET_FONT_DOWNLOAD_STATUS(rec, False);
+ rec->is_iso_encoding = PsIsISOLatin1Encoding(pFont);
+ break;
+
+ case PSFTI_FONT_TYPE_PMF:
+ rec->downloadableFont = True; /* This font is in printer's ROM */
+ SET_FONT_DOWNLOAD_STATUS(rec, True);
+ rec->is_iso_encoding = PsIsISOLatin1Encoding(pFont);
+ break;
+
+ case PSFTI_FONT_TYPE_TRUETYPE:
+ /* Note: TrueType font download not implemented */
+ rec->downloadableFont = False;
+ SET_FONT_DOWNLOAD_STATUS(rec, False);
+ rec->is_iso_encoding = PsIsISOLatin1Encoding(pFont);
+ break;
+
+#ifdef XP_USE_FREETYPE
+ case PSFTI_FONT_TYPE_FREETYPE:
+ if( rec->ft_download_font_type == PsFontType1 ||
+ rec->ft_download_font_type == PsFontType3 )
+ {
+ rec->downloadableFont = True;
+ }
+ else
+ {
+ rec->downloadableFont = False;
+ }
+
+ SET_FONT_DOWNLOAD_STATUS(rec, False);
+ rec->is_iso_encoding = False; /* Freetype--->PS Type1/Type3 uses always non-iso PS encoding for now */
+ break;
+#endif /* XP_USE_FREETYPE */
+
+ case PSFTI_FONT_TYPE_OTHER:
+ default:
+ rec->downloadableFont = False;
+ SET_FONT_DOWNLOAD_STATUS(rec, False);
+ rec->is_iso_encoding = PsIsISOLatin1Encoding(pFont);
+ break;
+ }
+
+#ifdef XP_USE_FREETYPE
+ if( (rec->font_type == PSFTI_FONT_TYPE_FREETYPE) )
+ {
+ char *s;
+ register int c;
+
+ if( rec->adobe_ps_name )
+ {
+ rec->download_ps_name = malloc(strlen(rec->adobe_ps_name) + strlen(rec->ft_download_encoding) + 2);
+ sprintf(rec->download_ps_name, "%s_%s", rec->adobe_ps_name, rec->ft_download_encoding);
+ }
+ else
+ {
+ /* Unfortunately not all TTF fonts have a PostScript font name (like
+ * Solaris TTF fonts in /usr/openwin/lib/locale/ko.UTF-8/X11/fonts/TrueType,
+ * /usr/openwin/lib/locale/ko/X11/fonts/TrueType) - in this case we
+ * have to generate a font name
+ */
+ char ftfontname[64];
+ static long myfontindex = 0L;
+ sprintf(ftfontname, "psfont_%lx", myfontindex++);
+
+ rec->download_ps_name = malloc(strlen(ftfontname) + strlen(rec->ft_download_encoding) + 2);
+ sprintf(rec->download_ps_name, "%s_%s", ftfontname, rec->ft_download_encoding);
+
+ fprintf(stderr, "PsCreateFontTypeInfoRec: Note: '%s' has no PS font name, using '%s' for now.\n", dlfnam, rec->download_ps_name);
+ }
+
+ /* Make sure the font name we use for download is a valid PS font name */
+ for( s = rec->download_ps_name ; *s != '\0'; s++ )
+ {
+ c = *s;
+
+ /* Check for allowed chars, invalid ones are replaced with a '_'
+ * (and check that the first char is not a digit) */
+ if( !(isalnum(c) || c == '.' || c == '_' || c == '-') || (s==rec->download_ps_name && isdigit(c)) )
+ {
+ *s = '_';
+ }
+ }
+ }
+ else
+#endif /* XP_USE_FREETYPE */
+ {
+ if( rec->adobe_ps_name )
+ {
+ rec->download_ps_name = strdup(rec->adobe_ps_name);
+ }
+ else
+ {
+ rec->download_ps_name = NULL;
+ }
+ }
+
+ /* Safeguard - only treat font as downloadable when we have a PS font name!! */
+ if (!rec->download_ps_name && rec->downloadableFont)
+ {
+ /* XXX: Log this message to the log when the logging service has been hook'ed up */
+ fprintf(stderr, "PsCreateFontTypeInfoRec: Safeguard: No PS font name for '%s'!\n", dlfnam);
+ rec->downloadableFont = False;
+ }
+
+#ifdef DEBUG_gisburn
+ fprintf(stderr, "PsCreateFontTypeInfoRec: Created PsFontTypeInfoRec '%s' ('%s'/'%s')\n",
+ ((rec->filename) ?(rec->filename) :("<null>")),
+ ((rec->adobe_ps_name) ?(rec->adobe_ps_name):("<null>")),
+ ((rec->download_ps_name)?(rec->download_ps_name):("<null>")));
+#endif /* DEBUG_gisburn */
+
+ return rec;
+}
+
+static
+PsFontTypeInfoRec *PsGetFontTypeInfoRec(DrawablePtr pDrawable, FontPtr pFont)
+{
+ PsFontTypeInfoRec *rec;
+ char *dlfnam;
+
+ if(!(dlfnam = PsGetFontName(pFont)))
+ return NULL;
+
+ rec = PsFindFontTypeInfoRec(pDrawable, pFont);
+ if (rec)
+ return rec;
+
+ rec = PsCreateFontTypeInfoRec(pDrawable, pFont);
+ if (!rec)
+ return NULL;
+
+ PsAddFontTypeInfoRec(pDrawable, rec);
+
+ return rec;
+}
+
+static
+void PsFreeFontTypeInfoRecords( PsContextPrivPtr priv )
+{
+ PsFontTypeInfoRec *curr, *next;
+ curr = priv->fontTypeInfoRecords;
+ while( curr != NULL )
+ {
+ if (curr->filename)
+ free(curr->filename); /* Free memory allocated by |strdup()| */
+
+ if (curr->download_ps_name)
+ free(curr->download_ps_name);
+
+ next = curr->next;
+ xfree(curr);
+ curr = next;
+ }
+}
+
+static
+PsFontInfoRec *PsFindFontInfoRec(DrawablePtr pDrawable, FontPtr pFont)
+{
+ PsContextPrivRec *cPriv = PsGetPsContextPriv(pDrawable);
+ PsFontInfoRec *rec;
+
+ if (!pFont)
+ return NULL;
+
+ for( rec = cPriv->fontInfoRecords ; rec != NULL ; rec = rec->next )
+ {
+ if ((rec->font == pFont) &&
+ (rec->font_fontPrivate == pFont->fontPrivate))
+ return rec;
+ }
+
+ return NULL;
+}
+
+static
+void PsAddFontInfoRec(DrawablePtr pDrawable, PsFontInfoRec *add_rec)
+{
+ PsContextPrivRec *cPriv = PsGetPsContextPriv(pDrawable);
+
+ /* ToDO: Always move the last used entry to the top that the list get's
+ * sorted in an efficient order... :-) */
+ add_rec->next = cPriv->fontInfoRecords;
+ cPriv->fontInfoRecords = add_rec;
+}
+
+static
+PsFontInfoRec *PsCreateFontInfoRec(DrawablePtr pDrawable, FontPtr pFont)
+{
+ PsFontInfoRec *rec;
+ PsFontTypeInfoRec *ftir;
+
+ if (!(ftir = PsGetFontTypeInfoRec(pDrawable, pFont)))
+ return NULL;
+
+ if (!(rec = (PsFontInfoRec *)xalloc(sizeof(PsFontInfoRec))))
+ return NULL;
+ memset(rec, 0, sizeof(PsFontInfoRec));
+
+ rec->font = pFont;
+ rec->font_fontPrivate = pFont->fontPrivate;
+ rec->ftir = ftir;
+ rec->next = NULL;
+ rec->dfl_name = PsGetFontName(pFont);
+ rec->size = PsGetFontSize(pFont, rec->mtx);
+
+#ifdef DEBUG_gisburn
+ fprintf(stderr, "PsCreateFontInfoRec: Created PsFontInfoRec '%s'\n",
+ ((rec->dfl_name)?(rec->dfl_name):("<null>")));
+#endif /* DEBUG_gisburn */
+
+ return rec;
+}
+
+PsFontInfoRec *PsGetFontInfoRec(DrawablePtr pDrawable, FontPtr pFont)
+{
+ PsFontInfoRec *rec;
+
+ rec = PsFindFontInfoRec(pDrawable, pFont);
+ if (rec)
+ return rec;
+
+ rec = PsCreateFontInfoRec(pDrawable, pFont);
+ if (!rec)
+ return NULL;
+
+ PsAddFontInfoRec(pDrawable, rec);
+
+ return rec;
+}
+
+void PsFreeFontInfoRecords( PsContextPrivPtr priv )
+{
+ PsFontInfoRec *curr, *next;
+ curr = priv->fontInfoRecords;
+ while( curr != NULL )
+ {
+ next = curr->next;
+ xfree(curr);
+ curr = next;
+ }
+
+ PsFreeFontTypeInfoRecords(priv);
+
+ priv->fontTypeInfoRecords = NULL;
+ priv->fontInfoRecords = NULL;
+}
diff --git a/nx-X11/programs/Xserver/Xprint/ps/PsGC.c b/nx-X11/programs/Xserver/Xprint/ps/PsGC.c
new file mode 100644
index 000000000..56ff5cdae
--- /dev/null
+++ b/nx-X11/programs/Xserver/Xprint/ps/PsGC.c
@@ -0,0 +1,419 @@
+/* $Xorg: PsGC.c,v 1.4 2001/02/09 02:04:36 xorgcvs Exp $ */
+/*
+
+Copyright 1996, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+/*
+ * (c) Copyright 1996 Hewlett-Packard Company
+ * (c) Copyright 1996 International Business Machines Corp.
+ * (c) Copyright 1996 Sun Microsystems, Inc.
+ * (c) Copyright 1996 Novell, Inc.
+ * (c) Copyright 1996 Digital Equipment Corp.
+ * (c) Copyright 1996 Fujitsu Limited
+ * (c) Copyright 1996 Hitachi, Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject
+ * to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the names of the copyright holders
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * from said copyright holders.
+ */
+
+/*******************************************************************
+**
+** *********************************************************
+** *
+** * File: PsGC.c
+** *
+** * Contents: Graphics Context handling for the PS driver
+** *
+** * Created By: Roger Helmendach (Liberty Systems)
+** *
+** * Copyright: Copyright 1996 The Open Group, Inc.
+** *
+** *********************************************************
+**
+********************************************************************/
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include "Ps.h"
+#include "gcstruct.h"
+#include "pixmapstr.h"
+#include "windowstr.h"
+#include "migc.h"
+#include "scrnintstr.h"
+
+static GCOps PsGCOps =
+{
+ PsFillSpans,
+ PsSetSpans,
+ PsPutImage,
+ PsCopyArea,
+ PsCopyPlane,
+ PsPolyPoint,
+ PsPolyLine,
+ PsPolySegment,
+ PsPolyRectangle,
+ PsPolyArc,
+ PsFillPolygon,
+ PsPolyFillRect,
+ PsPolyFillArc,
+ PsPolyText8,
+ PsPolyText16,
+ PsImageText8,
+ PsImageText16,
+ PsImageGlyphBlt,
+ PsPolyGlyphBlt,
+ PsPushPixels
+#ifdef NEED_LINEHELPER
+ ,NULL
+#endif
+};
+
+
+static GCFuncs PsGCFuncs =
+{
+ PsValidateGC,
+ PsChangeGC,
+ PsCopyGC,
+ PsDestroyGC,
+ PsChangeClip,
+ PsDestroyClip,
+ PsCopyClip
+};
+
+Bool
+PsCreateGC(pGC)
+ GCPtr pGC;
+{
+ pGC->clientClip = NULL;
+ pGC->clientClipType = CT_NONE;
+
+ pGC->ops = &PsGCOps;
+ pGC->funcs = &PsGCFuncs;
+
+ pGC->clientClip = (pointer)xalloc(sizeof(PsClipRec));
+ memset(pGC->clientClip, 0, sizeof(PsClipRec));
+ return TRUE;
+}
+
+static int
+PsGetDrawablePrivateStuff(
+ DrawablePtr pDrawable,
+ GC *gc,
+ unsigned long *valid,
+ PsOutPtr *psOut,
+ ColormapPtr *cMap)
+{
+ XpContextPtr pCon;
+ PsContextPrivPtr cPriv;
+ PsScreenPrivPtr sPriv;
+
+ switch(pDrawable->type)
+ {
+ case DRAWABLE_PIXMAP:
+ return FALSE;
+ case DRAWABLE_WINDOW:
+ pCon = PsGetContextFromWindow((WindowPtr)pDrawable);
+ if( pCon==NULL ) return FALSE;
+ else
+ {
+ Colormap c;
+ ColormapPtr cmap;
+
+ c = wColormap((WindowPtr)pDrawable);
+ cmap = (ColormapPtr)LookupIDByType(c, RT_COLORMAP);
+
+ cPriv = pCon->devPrivates[PsContextPrivateIndex].ptr;
+ sPriv = (PsScreenPrivPtr)
+ pDrawable->pScreen->devPrivates[PsScreenPrivateIndex].ptr;
+ *gc = cPriv->lastGC;
+ *valid = cPriv->validGC;
+ *psOut = cPriv->pPsOut;
+ *cMap = cmap;
+ return TRUE;
+ }
+ default:
+ return FALSE;
+ }
+}
+
+PsContextPrivPtr
+PsGetPsContextPriv( DrawablePtr pDrawable )
+{
+ XpContextPtr pCon;
+ PsContextPrivPtr cPriv;
+
+ switch(pDrawable->type)
+ {
+ case DRAWABLE_PIXMAP:
+ return FALSE;
+ case DRAWABLE_WINDOW:
+ pCon = PsGetContextFromWindow((WindowPtr)pDrawable);
+ if (pCon != NULL)
+ {
+ return pCon->devPrivates[PsContextPrivateIndex].ptr;
+ }
+ }
+ return NULL;
+}
+
+int
+PsUpdateDrawableGC(
+ GCPtr pGC,
+ DrawablePtr pDrawable,
+ PsOutPtr *psOut,
+ ColormapPtr *cMap)
+{
+ GC dGC;
+ unsigned long valid;
+ int i;
+ PsContextPrivPtr cPriv;
+ BoxPtr boxes;
+
+ if (!PsGetDrawablePrivateStuff(pDrawable, &dGC, &valid, psOut, cMap))
+ return FALSE;
+
+ switch (pDrawable->type) {
+
+ case DRAWABLE_PIXMAP:
+ /* we don't support pixmaps yet! */
+ return FALSE;
+ break;
+ case DRAWABLE_WINDOW:
+ if( pGC )
+ {
+ RegionPtr pReg;
+ WindowPtr pWin = (WindowPtr)pDrawable;
+ Bool freeClip;
+ PsClipPtr clp = (PsClipPtr)pGC->clientClip;
+ if( clp->outterClips )
+ { xfree(clp->outterClips); clp->outterClips = 0; }
+ clp->nOutterClips = 0;
+ if( pGC->subWindowMode==IncludeInferiors )
+ {
+ pReg = NotClippedByChildren(pWin);
+ freeClip = TRUE;
+ }
+ else
+ {
+ pReg = &pWin->clipList;
+ freeClip = FALSE;
+ }
+
+ if( pReg->data )
+ {
+ boxes = (BoxPtr)((char *)pReg->data+sizeof(long)*2);
+ clp->nOutterClips = pReg->data->numRects;
+ clp->outterClips =
+ (PsRectPtr)xalloc(clp->nOutterClips*sizeof(PsRectRec));
+ for( i=0 ; i<clp->nOutterClips ; i++ )
+ {
+ clp->outterClips[i].x = boxes[i].x1;
+ clp->outterClips[i].y = boxes[i].y1;
+ clp->outterClips[i].w = (boxes[i].x2-boxes[i].x1)+1;
+ clp->outterClips[i].h = (boxes[i].y2-boxes[i].y1)+1;
+ }
+ }
+
+ if( freeClip ) REGION_DESTROY(pGC->pScreen, pReg);
+ PsOut_Offset(*psOut, pDrawable->x, pDrawable->y);
+ PsOut_Clip(*psOut, pGC->clientClipType, (PsClipPtr)pGC->clientClip);
+ }
+ cPriv = ( PsGetContextFromWindow( (WindowPtr)pDrawable ) )
+ ->devPrivates[PsContextPrivateIndex].ptr;
+ break;
+ }
+ return TRUE;
+}
+
+void
+PsValidateGC(GCPtr pGC, unsigned long changes, DrawablePtr pDrawable)
+{
+ pGC->ops = &PsGCOps;
+}
+
+void
+PsChangeGC(GCPtr pGC, unsigned long changes)
+{
+}
+
+void
+PsCopyGC(GCPtr pGCSrc, unsigned long mask, GCPtr pGCDst)
+{
+}
+
+void
+PsDestroyGC(GCPtr pGC)
+{
+ PsDestroyClip(pGC);
+ xfree(pGC->clientClip);
+}
+
+void
+PsChangeClip(GCPtr pGC, int type, pointer pValue, int nrects)
+{
+ int i;
+ PsClipPtr clp = (PsClipPtr)pGC->clientClip;
+ RegionPtr rgn;
+ BoxPtr boxes;
+ xRectangle *rects;
+
+ PsDestroyClip(pGC);
+ pGC->clientClipType = type;
+ switch(type)
+ {
+ case CT_NONE: break;
+ case CT_PIXMAP:
+ clp->elms = PsCreateFillElementList((PixmapPtr)pValue, &clp->nElms);
+ (*pGC->pScreen->DestroyPixmap)((PixmapPtr)pValue);
+ break;
+ case CT_REGION:
+ rgn = (RegionPtr)pValue;
+ boxes = (BoxPtr)((char *)rgn->data+sizeof(long)*2);
+ clp->nRects = rgn->data->numRects;
+ clp->rects = (PsRectPtr)xalloc(clp->nRects*sizeof(PsRectRec));
+ for( i=0 ; i<clp->nRects ; i++ )
+ {
+ clp->rects[i].x = boxes[i].x1;
+ clp->rects[i].y = boxes[i].y1;
+ clp->rects[i].w = (boxes[i].x2-boxes[i].x1)+1;
+ clp->rects[i].h = (boxes[i].y2-boxes[i].y1)+1;
+ }
+ REGION_DESTROY(pGC->pScreen, (RegionPtr)pValue);
+ break;
+ case CT_UNSORTED:
+ case CT_YSORTED:
+ case CT_YXSORTED:
+ case CT_YXBANDED:
+ rects = (xRectangle *)pValue;
+ clp->nRects = nrects;
+ clp->rects = (PsRectPtr)xalloc(clp->nRects*sizeof(PsRectRec));
+ for( i=0 ; i<clp->nRects ; i++ )
+ {
+ clp->rects[i].x = rects[i].x;
+ clp->rects[i].y = rects[i].y;
+ clp->rects[i].w = rects[i].width;
+ clp->rects[i].h = rects[i].height;
+ }
+ xfree(pValue);
+ break;
+ }
+}
+
+void
+PsDestroyClip(GCPtr pGC)
+{
+ PsClipPtr clp = (PsClipPtr)pGC->clientClip;
+
+ if( clp->rects ) xfree(clp->rects);
+ if( clp->outterClips ) xfree(clp->outterClips);
+ clp->rects = (PsRectPtr)0;
+ clp->outterClips = (PsRectPtr)0;
+ clp->nRects = 0;
+ clp->nOutterClips = 0;
+ if( clp->elms ) PsDestroyFillElementList(clp->nElms, clp->elms);
+ clp->elms = (PsElmPtr)0;
+ clp->nElms = 0;
+ pGC->clientClipType = CT_NONE;
+}
+
+void
+PsCopyClip(GCPtr pDst, GCPtr pSrc)
+{
+ PsClipPtr src = (PsClipPtr)pSrc->clientClip;
+ PsClipPtr dst = (PsClipPtr)pDst->clientClip;
+
+ PsDestroyClip(pDst);
+ pDst->clientClipType = pSrc->clientClipType;
+ *dst = *src;
+ if( src->rects )
+ {
+ dst->rects = (PsRectPtr)xalloc(src->nRects*sizeof(PsRectRec));
+ memcpy(dst->rects, src->rects, src->nRects*sizeof(PsRectRec));
+ }
+ if( src->elms )
+ dst->elms = PsCloneFillElementList(src->nElms, src->elms);
+}
+
+
+GCPtr
+PsCreateAndCopyGC(DrawablePtr pDrawable, GCPtr pSrc)
+{
+ GCPtr pDst;
+
+ if (pSrc == NULL) {
+ /* https://freedesktop.org/bugzilla/show_bug.cgi?id=1416 ("'x11perf
+ * -copypixpix500' crashes Xprt's PostScript DDX [PsCreateAndCopyGC"):
+ * I have no clue whether this is the real fix or just wallpapering
+ * over the crash (that's why we warn here loudly when this
+ * happens) ... */
+ fprintf(stderr, "PsCreateAndCopyGC: pSrc == NULL\n");
+ return NULL;
+ }
+
+ if ((pDst =
+ CreateScratchGC(pDrawable->pScreen, pDrawable->depth)) == NULL)
+ {
+ return NULL;
+ }
+
+ if (CopyGC(pSrc, pDst,
+ GCFunction | GCPlaneMask | GCForeground | GCBackground |
+ GCLineWidth | GCLineStyle | GCCapStyle | GCJoinStyle |
+ GCFillStyle | GCFillRule | GCTile | GCStipple |
+ GCTileStipXOrigin | GCTileStipYOrigin | GCFont |
+ GCSubwindowMode | GCGraphicsExposures | GCClipXOrigin |
+ GCClipYOrigin | GCClipMask | GCDashOffset | GCDashList |
+ GCArcMode) != Success)
+ {
+ (void)FreeGC(pDst, (GContext)0);
+
+ return NULL;
+ }
+
+ return pDst;
+}
+
diff --git a/nx-X11/programs/Xserver/Xprint/ps/PsImageUtil.c b/nx-X11/programs/Xserver/Xprint/ps/PsImageUtil.c
new file mode 100644
index 000000000..282786564
--- /dev/null
+++ b/nx-X11/programs/Xserver/Xprint/ps/PsImageUtil.c
@@ -0,0 +1,329 @@
+
+/* $Xorg: PsImageUtil.c,v 1.1 2005/03/25 1:19:56 gisburn Exp $ */
+/*
+Copyright (c) 2005 Roland Mainz <roland.mainz@nrubsig.org>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the names of the copyright holders shall
+not be used in advertising or otherwise to promote the sale, use or other
+dealings in this Software without prior written authorization from said
+copyright holders.
+*/
+
+/* Please do not beat me for this ugly code - most of it has been stolen from
+ * xc/lib/X11/ImUtil.c */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include "gcstruct.h"
+#include "windowstr.h"
+#include "servermd.h"
+#include "attributes.h"
+
+static unsigned char const _reverse_byte[0x100] = {
+ 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
+ 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
+ 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
+ 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
+ 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4,
+ 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
+ 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec,
+ 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,
+ 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,
+ 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,
+ 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,
+ 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
+ 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6,
+ 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,
+ 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,
+ 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe,
+ 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1,
+ 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,
+ 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9,
+ 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9,
+ 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5,
+ 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,
+ 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed,
+ 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,
+ 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3,
+ 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3,
+ 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb,
+ 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb,
+ 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7,
+ 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
+ 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef,
+ 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff
+};
+
+static
+int XReverse_Bytes(
+ register unsigned char *bpt,
+ register int nb)
+{
+ do {
+ *bpt = _reverse_byte[*bpt];
+ bpt++;
+ } while (--nb > 0);
+ return 0;
+}
+
+/*
+ * Data structure for "image" data, used by image manipulation routines.
+ */
+typedef struct {
+ int width, height; /* size of image */
+ int xoffset; /* number of pixels offset in X direction */
+ int format; /* XYBitmap, XYPixmap, ZPixmap */
+ char *data; /* pointer to image data */
+ int byte_order; /* data byte order, LSBFirst, MSBFirst */
+ int bitmap_unit; /* quant. of scanline 8, 16, 32 */
+ int bitmap_bit_order; /* LSBFirst, MSBFirst */
+ int depth; /* depth of image */
+ int bytes_per_line; /* accelarator to next line */
+ int bits_per_pixel; /* bits per pixel (ZPixmap) */
+} TmpImage;
+
+
+static void xynormalizeimagebits (
+ register unsigned char *bp,
+ register TmpImage *img)
+{
+ register unsigned char c;
+
+ if (img->byte_order != img->bitmap_bit_order) {
+ switch (img->bitmap_unit) {
+
+ case 16:
+ c = *bp;
+ *bp = *(bp + 1);
+ *(bp + 1) = c;
+ break;
+
+ case 32:
+ c = *(bp + 3);
+ *(bp + 3) = *bp;
+ *bp = c;
+ c = *(bp + 2);
+ *(bp + 2) = *(bp + 1);
+ *(bp + 1) = c;
+ break;
+ }
+ }
+ if (img->bitmap_bit_order == MSBFirst)
+ XReverse_Bytes (bp, img->bitmap_unit >> 3);
+}
+
+static void znormalizeimagebits (
+ register unsigned char *bp,
+ register TmpImage *img)
+{
+ register unsigned char c;
+ switch (img->bits_per_pixel) {
+
+ case 4:
+ *bp = ((*bp >> 4) & 0xF) | ((*bp << 4) & ~0xF);
+ break;
+
+ case 16:
+ c = *bp;
+ *bp = *(bp + 1);
+ *(bp + 1) = c;
+ break;
+
+ case 24:
+ c = *(bp + 2);
+ *(bp + 2) = *bp;
+ *bp = c;
+ break;
+
+ case 32:
+ c = *(bp + 3);
+ *(bp + 3) = *bp;
+ *bp = c;
+ c = *(bp + 2);
+ *(bp + 2) = *(bp + 1);
+ *(bp + 1) = c;
+ break;
+ }
+}
+
+/*
+ * Macros
+ *
+ * The ROUNDUP macro rounds up a quantity to the specified boundary,
+ * then truncates to bytes.
+ *
+ * The XYNORMALIZE macro determines whether XY format data requires
+ * normalization and calls a routine to do so if needed. The logic in
+ * this module is designed for LSBFirst byte and bit order, so
+ * normalization is done as required to present the data in this order.
+ *
+ * The ZNORMALIZE macro performs byte and nibble order normalization if
+ * required for Z format data.
+ *
+ * The XYINDEX macro computes the index to the starting byte (char) boundary
+ * for a bitmap_unit containing a pixel with coordinates x and y for image
+ * data in XY format.
+ *
+ * The ZINDEX macro computes the index to the starting byte (char) boundary
+ * for a pixel with coordinates x and y for image data in ZPixmap format.
+ *
+ */
+
+#if defined(Lynx) && defined(ROUNDUP)
+#undef ROUNDUP
+#endif
+
+#define ROUNDUP(nbytes, pad) ((((nbytes) + ((pad)-1)) / (pad)) * ((pad)>>3))
+
+#define XYNORMALIZE(bp, img) \
+ if ((img->byte_order == MSBFirst) || (img->bitmap_bit_order == MSBFirst)) \
+ xynormalizeimagebits((unsigned char *)(bp), img)
+
+#define ZNORMALIZE(bp, img) \
+ if (img->byte_order == MSBFirst) \
+ znormalizeimagebits((unsigned char *)(bp), img)
+
+#define XYINDEX(x, y, img) \
+ ((y) * img->bytes_per_line) + \
+ (((x) + img->xoffset) / img->bitmap_unit) * (img->bitmap_unit >> 3)
+
+#define ZINDEX(x, y, img) ((y) * img->bytes_per_line) + \
+ (((x) * img->bits_per_pixel) >> 3)
+
+/*
+ * GetPixel
+ *
+ * Returns the specified pixel. The X and Y coordinates are relative to
+ * the origin (upper left [0,0]) of the image. The pixel value is returned
+ * in normalized format, i.e. the LSB of the long is the LSB of the pixel.
+ * The algorithm used is:
+ *
+ * copy the source bitmap_unit or Zpixel into temp
+ * normalize temp if needed
+ * extract the pixel bits into return value
+ *
+ */
+
+static unsigned long const low_bits_table[] = {
+ 0x00000000, 0x00000001, 0x00000003, 0x00000007,
+ 0x0000000f, 0x0000001f, 0x0000003f, 0x0000007f,
+ 0x000000ff, 0x000001ff, 0x000003ff, 0x000007ff,
+ 0x00000fff, 0x00001fff, 0x00003fff, 0x00007fff,
+ 0x0000ffff, 0x0001ffff, 0x0003ffff, 0x0007ffff,
+ 0x000fffff, 0x001fffff, 0x003fffff, 0x007fffff,
+ 0x00ffffff, 0x01ffffff, 0x03ffffff, 0x07ffffff,
+ 0x0fffffff, 0x1fffffff, 0x3fffffff, 0x7fffffff,
+ 0xffffffff
+};
+
+static unsigned long XGetPixel (TmpImage *ximage, int x, int y)
+{
+ unsigned long pixel, px;
+ register char *src;
+ register char *dst;
+ register int i, j;
+ int bits, nbytes;
+ long plane;
+
+ if ((ximage->bits_per_pixel | ximage->depth) == 1) {
+ src = &ximage->data[XYINDEX(x, y, ximage)];
+ dst = (char *)&pixel;
+ pixel = 0;
+ for (i = ximage->bitmap_unit >> 3; --i >= 0; ) *dst++ = *src++;
+ XYNORMALIZE(&pixel, ximage);
+ bits = (x + ximage->xoffset) % ximage->bitmap_unit;
+ pixel = ((((char *)&pixel)[bits>>3])>>(bits&7)) & 1;
+ } else if (ximage->format == XYPixmap) {
+ pixel = 0;
+ plane = 0;
+ nbytes = ximage->bitmap_unit >> 3;
+ for (i = ximage->depth; --i >= 0; ) {
+ src = &ximage->data[XYINDEX(x, y, ximage)+ plane];
+ dst = (char *)&px;
+ px = 0;
+ for (j = nbytes; --j >= 0; ) *dst++ = *src++;
+ XYNORMALIZE(&px, ximage);
+ bits = (x + ximage->xoffset) % ximage->bitmap_unit;
+ pixel = (pixel << 1) |
+ (((((char *)&px)[bits>>3])>>(bits&7)) & 1);
+ plane = plane + (ximage->bytes_per_line * ximage->height);
+ }
+ } else if (ximage->format == ZPixmap) {
+ src = &ximage->data[ZINDEX(x, y, ximage)];
+ dst = (char *)&px;
+ px = 0;
+ for (i = (ximage->bits_per_pixel + 7) >> 3; --i >= 0; )
+ *dst++ = *src++;
+ ZNORMALIZE(&px, ximage);
+ pixel = 0;
+ for (i=sizeof(unsigned long); --i >= 0; )
+ pixel = (pixel << 8) | ((unsigned char *)&px)[i];
+ if (ximage->bits_per_pixel == 4) {
+ if (x & 1)
+ pixel >>= 4;
+ else
+ pixel &= 0xf;
+ }
+ } else {
+ return 0; /* bad image */
+ }
+ if (ximage->bits_per_pixel == ximage->depth)
+ return pixel;
+ else
+ return (pixel & low_bits_table[ximage->depth]);
+}
+
+unsigned long
+PsGetImagePixel(char *pImage, int depth, int w, int h, int leftPad, int format,
+ int px, int py)
+{
+ TmpImage xi = {0};
+
+ xi.width = w;
+ xi.height = h;
+ xi.xoffset = 0/*leftPad*/;
+ xi.format = format;
+ xi.data = pImage;
+ xi.byte_order = IMAGE_BYTE_ORDER;
+ xi.bitmap_bit_order = BITMAP_BIT_ORDER;
+ xi.bitmap_unit = ((depth > 16)?(32):
+ ((depth > 8)?(16):
+ ((depth > 1)? (8):
+ (1))));
+ xi.depth = depth;
+ xi.bits_per_pixel = xi.bitmap_unit;
+
+ /*
+ * compute per line accelerator.
+ */
+ if (format == ZPixmap)
+ xi.bytes_per_line =
+ ROUNDUP((xi.bits_per_pixel * xi.width), 32);
+ else
+ xi.bytes_per_line =
+ ROUNDUP((xi.width + xi.xoffset), 32);
+
+ return XGetPixel(&xi, px, py);
+}
+
+
+
diff --git a/nx-X11/programs/Xserver/Xprint/ps/PsInit.c b/nx-X11/programs/Xserver/Xprint/ps/PsInit.c
new file mode 100644
index 000000000..a11a61ae4
--- /dev/null
+++ b/nx-X11/programs/Xserver/Xprint/ps/PsInit.c
@@ -0,0 +1,667 @@
+/* $Xorg: PsInit.c,v 1.4 2001/02/09 02:04:36 xorgcvs Exp $ */
+/*
+
+Copyright 1996, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+/*
+ * (c) Copyright 1996 Hewlett-Packard Company
+ * (c) Copyright 1996 International Business Machines Corp.
+ * (c) Copyright 1996 Sun Microsystems, Inc.
+ * (c) Copyright 1996 Novell, Inc.
+ * (c) Copyright 1996 Digital Equipment Corp.
+ * (c) Copyright 1996 Fujitsu Limited
+ * (c) Copyright 1996 Hitachi, Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject
+ * to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the names of the copyright holders
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * from said copyright holders.
+ */
+
+/*******************************************************************
+**
+** *********************************************************
+** *
+** * File: PsInit.c
+** *
+** * Contents: Initialization code of Ps driver for the print server.
+** *
+** * Created By: Roger Helmendach (Liberty Systems)
+** *
+** * Copyright: Copyright 1996 The Open Group, Inc.
+** *
+** *********************************************************
+**
+********************************************************************/
+
+#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 "mfb.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 /* GLXEXT */
+
+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
+ char **printerNames;
+ int numPrinters;
+ int nv, /* total number of visuals */
+ nv_1bit, /* number of 8bit visuals */
+ nv_8bit, /* number of 8bit visuals */
+ nv_12bit, /* number of 12bit visuals */
+ nv_14bit, /* number of 14bit visuals */
+ nv_16bit, /* number of 16bit visuals */
+ nv_24bit, /* number of 24bit visuals*/
+ nv_30bit; /* number of 30bit visuals*/
+ int nd; /* number of depths */
+ 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;
+
+/*
+ * Register this driver's InitContext function with the print
+ * extension.
+ */
+ XpRegisterInitFunc(pScreen, "XP-POSTSCRIPT", PsInitContext);
+
+/*
+ * Create and fill in the devPrivate for the PS driver.
+ */
+ 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;
+ /* XXX Hard routine to write! */
+
+/*
+ * These two are going to be VERY different...
+ */
+ 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;
+ /* Will BitmapToRegion make any difference at all? */
+ pScreen->BitmapToRegion = mfbPixmapToRegion;
+
+ 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
+/* gisburn: 30bit TrueColor has been disabled for now since it causes problems
+ * with GLX - see https://bugs.freedesktop.org/show_bug.cgi?id=2868 ("Mesa
+ * seems to be unable to handle 30bit TrueColor visuals") for details...
+ */
+#ifdef DISABLED_FOR_NOW
+ /* TrueColor, 30bit, 10bit per R-,G-,B-gun */
+ 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 /* DISABLED_FOR_NOW */
+#endif /* PSOUT_USE_DEEPCOLOR */
+
+ /* TrueColor, 24bit */
+ 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++;
+
+ /* TrueColor, 16bit */
+ 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
+ /* PostScript Level 2 and above, colors can have 12 bits per component
+ * (36 bit for RGB) */
+
+ /* PseudoColor, 14bit (15bit won't work as |ColormapEntries==32768|
+ * is too large for a |signed short|... xx@@!!!... ;-( ) */
+ 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++;
+
+ /* PseudoColor, 12bit */
+ 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++;
+
+ /* GrayScale, 12bit, 12bit per R-,G-,B-gun */
+ 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++;
+
+ /* StaticGray, 12bit, 12bit per R-,G-,B-gun */
+ 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 /* PSOUT_USE_DEEPCOLOR */
+
+ /* PseudoColor, 8bit */
+ 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 /* !PSOUT_USE_DEEPCOLOR */
+ nv++; nv_8bit++;
+
+ /* GrayScale, 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++;
+
+ /* StaticGray, 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++;
+
+ /* StaticGray, 1bit */
+ 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++;
+ }
+
+ /* Defaul visual is 12bit PseudoColor */
+ defaultVisual = visuals[defaultVisualIndex].vid;
+ rootDepth = visuals[defaultVisualIndex].nplanes;
+
+#ifdef GLXEXT
+ {
+ miInitVisualsProcPtr proc = NULL;
+
+ GlxWrapInitVisuals(&proc);
+ /* GlxInitVisuals ignores the last three arguments. */
+ proc(&visuals, &depths, &nv, &nd,
+ &rootDepth, &defaultVisual, 0, 0, 0);
+ }
+#endif /* GLXEXT */
+
+ 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;
+
+/*scalingScreenInit(pScreen);*/
+
+ 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));
+}
+
+/*
+ * PsInitContext
+ *
+ * Establish the appropriate values for a PrintContext used with the PS
+ * driver.
+ */
+
+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;
+
+ /*
+ * Initialize the attribute store for this printer.
+ */
+ XpInitAttributes(pCon);
+
+ /*
+ * Initialize the function pointers
+ */
+ 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;
+
+ /*
+ * Set up the context privates
+ */
+ 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;
+
+ /*
+ * document-attributes-supported
+ */
+ 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);
+
+ /*
+ * job-attributes-supported
+ */
+ 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);
+
+ /*
+ * xp-page-attributes-supported
+ */
+ 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);
+
+ /*
+ * Validate the attribute pools
+ */
+ 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);
+
+ /* Reset context to make sure we do not use any stale/invalid/obsolete data */
+ memset(pConPriv, 0, sizeof(PsContextPrivRec));
+
+/*### free up visuals/depths ###*/
+
+ 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;
+}
diff --git a/nx-X11/programs/Xserver/Xprint/ps/PsLine.c b/nx-X11/programs/Xserver/Xprint/ps/PsLine.c
new file mode 100644
index 000000000..2524769c8
--- /dev/null
+++ b/nx-X11/programs/Xserver/Xprint/ps/PsLine.c
@@ -0,0 +1,192 @@
+/* $Xorg: PsLine.c,v 1.4 2001/02/09 02:04:36 xorgcvs Exp $ */
+/*
+
+Copyright 1996, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+/*
+ * (c) Copyright 1996 Hewlett-Packard Company
+ * (c) Copyright 1996 International Business Machines Corp.
+ * (c) Copyright 1996 Sun Microsystems, Inc.
+ * (c) Copyright 1996 Novell, Inc.
+ * (c) Copyright 1996 Digital Equipment Corp.
+ * (c) Copyright 1996 Fujitsu Limited
+ * (c) Copyright 1996 Hitachi, Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject
+ * to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the names of the copyright holders
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * from said copyright holders.
+ */
+
+/*******************************************************************
+**
+** *********************************************************
+** *
+** * File: PsLine.c
+** *
+** * Contents: Line drawing routines for the PS driver
+** *
+** * Created By: Roger Helmendach (Liberty Systems)
+** *
+** * Copyright: Copyright 1996 The Open Group, Inc.
+** *
+** *********************************************************
+**
+********************************************************************/
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include "Ps.h"
+#include "gcstruct.h"
+#include "windowstr.h"
+
+void
+PsPolyLine(
+ DrawablePtr pDrawable,
+ GCPtr pGC,
+ int mode,
+ int nPoints,
+ xPoint *pPoints)
+{
+ if( pDrawable->type==DRAWABLE_PIXMAP )
+ {
+ DisplayElmPtr elm;
+ PixmapPtr pix = (PixmapPtr)pDrawable;
+ PsPixmapPrivPtr priv = (PsPixmapPrivPtr)pix->devPrivate.ptr;
+ DisplayListPtr disp;
+ GCPtr gc;
+
+ if ((gc = PsCreateAndCopyGC(pDrawable, pGC)) == NULL) return;
+
+ disp = PsGetFreeDisplayBlock(priv);
+
+ elm = &disp->elms[disp->nelms];
+ elm->type = PolyLineCmd;
+ elm->gc = gc;
+ elm->c.polyPts.mode = mode;
+ elm->c.polyPts.nPoints = nPoints;
+ elm->c.polyPts.pPoints = (xPoint *)xalloc(nPoints*sizeof(xPoint));
+ memcpy(elm->c.polyPts.pPoints, pPoints, nPoints*sizeof(xPoint));
+ disp->nelms += 1;
+ }
+ else
+ {
+ int i;
+ PsOutPtr psOut;
+ PsPointPtr pts;
+ ColormapPtr cMap;
+
+ if( PsUpdateDrawableGC(pGC, pDrawable, &psOut, &cMap)==FALSE ) return;
+ PsOut_Offset(psOut, pDrawable->x, pDrawable->y);
+ PsOut_Color(psOut, PsGetPixelColor(cMap, pGC->fgPixel));
+ PsLineAttrs(psOut, pGC, cMap);
+ pts = (PsPointPtr)xalloc(sizeof(PsPointRec)*nPoints);
+ if( mode==CoordModeOrigin )
+ {
+ for( i=0 ; i<nPoints ; i++ )
+ { pts[i].x = pPoints[i].x; pts[i].y = pPoints[i].y; }
+ }
+ else
+ {
+ pts[0].x = pPoints[0].x; pts[0].y = pPoints[0].y;
+ for( i=1 ; i<nPoints ; i++ )
+ {
+ pts[i].x = pts[i-1].x+pPoints[i].x;
+ pts[i].y = pts[i-1].y+pPoints[i].y;
+ }
+ }
+ PsOut_Lines(psOut, nPoints, pts);
+ xfree(pts);
+ }
+}
+
+void
+PsPolySegment(
+ DrawablePtr pDrawable,
+ GCPtr pGC,
+ int nSegments,
+ xSegment *pSegments)
+{
+ if( pDrawable->type==DRAWABLE_PIXMAP )
+ {
+ DisplayElmPtr elm;
+ PixmapPtr pix = (PixmapPtr)pDrawable;
+ PsPixmapPrivPtr priv = (PsPixmapPrivPtr)pix->devPrivate.ptr;
+ DisplayListPtr disp;
+ GCPtr gc;
+
+ if ((gc = PsCreateAndCopyGC(pDrawable, pGC)) == NULL) return;
+
+ disp = PsGetFreeDisplayBlock(priv);
+
+ elm = &disp->elms[disp->nelms];
+ elm->type = PolySegmentCmd;
+ elm->gc = gc;
+ elm->c.segments.nSegments = nSegments;
+ elm->c.segments.pSegments = (xSegment *)xalloc(nSegments*sizeof(xSegment));
+ memcpy(elm->c.segments.pSegments, pSegments, nSegments*sizeof(xSegment));
+ disp->nelms += 1;
+ }
+ else
+ {
+ int i;
+ PsOutPtr psOut;
+ PsPointRec pts[2];
+ ColormapPtr cMap;
+
+ if( PsUpdateDrawableGC(pGC, pDrawable, &psOut, &cMap)==FALSE ) return;
+ PsOut_Offset(psOut, pDrawable->x, pDrawable->y);
+ PsOut_Color(psOut, PsGetPixelColor(cMap, pGC->fgPixel));
+ PsLineAttrs(psOut, pGC, cMap);
+ for( i=0 ; i<nSegments ; i++ )
+ {
+ pts[0].x = pSegments[i].x1;
+ pts[0].y = pSegments[i].y1;
+ pts[1].x = pSegments[i].x2;
+ pts[1].y = pSegments[i].y2;
+ PsOut_Lines(psOut, 2, pts);
+ }
+ }
+}
diff --git a/nx-X11/programs/Xserver/Xprint/ps/PsMisc.c b/nx-X11/programs/Xserver/Xprint/ps/PsMisc.c
new file mode 100644
index 000000000..b8a3ba854
--- /dev/null
+++ b/nx-X11/programs/Xserver/Xprint/ps/PsMisc.c
@@ -0,0 +1,324 @@
+/* $Xorg: PsMisc.c,v 1.4 2001/02/09 02:04:36 xorgcvs Exp $ */
+/*
+
+Copyright 1996, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+/*
+ * (c) Copyright 1996 Hewlett-Packard Company
+ * (c) Copyright 1996 International Business Machines Corp.
+ * (c) Copyright 1996 Sun Microsystems, Inc.
+ * (c) Copyright 1996 Novell, Inc.
+ * (c) Copyright 1996 Digital Equipment Corp.
+ * (c) Copyright 1996 Fujitsu Limited
+ * (c) Copyright 1996 Hitachi, Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject
+ * to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the names of the copyright holders
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * from said copyright holders.
+ */
+
+/*******************************************************************
+**
+** *********************************************************
+** *
+** * File: PsMisc.c
+** *
+** * Contents: Miscellaneous code for Ps driver.
+** *
+** * Created By: Roger Helmendach (Liberty Systems)
+** *
+** * Copyright: Copyright 1996 The Open Group, Inc.
+** *
+** *********************************************************
+**
+********************************************************************/
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include <X11/Xos.h> /* for SIGCLD on pre-POSIX systems */
+#include <stdio.h>
+#include "Ps.h"
+
+#include "cursor.h"
+#include "resource.h"
+
+#include "windowstr.h"
+#include "propertyst.h"
+
+
+/*ARGSUSED*/
+void
+PsQueryBestSize(
+ int type,
+ short *pwidth,
+ short *pheight,
+ ScreenPtr pScreen)
+{
+ unsigned width, highBit;
+
+ switch(type)
+ {
+ case CursorShape:
+ *pwidth = 0;
+ *pheight = 0;
+ break;
+ case TileShape:
+ case StippleShape:
+ width = *pwidth;
+ if (!width) break;
+ /* Return the nearest power of two >= what they gave us */
+ highBit = 0x80000000;
+ /* Find the highest 1 bit in the given width */
+ while(!(highBit & width))
+ highBit >>= 1;
+ /* If greater than that then return the next power of two */
+ if((highBit - 1) & width)
+ highBit <<= 1;
+ *pwidth = highBit;
+ /* height is a don't-care */
+ break;
+ }
+}
+
+/*
+ * PsGetMediumDimensions is installed in the GetMediumDimensions field
+ * of each Ps-initialized context.
+ */
+int
+PsGetMediumDimensions(XpContextPtr pCon, CARD16 *width, CARD16 *height)
+{
+ XpGetMediumDimensions(pCon, width, height);
+ return Success;
+}
+
+/*
+ * PsGetReproducibleArea is installed in the GetReproducibleArea field
+ * of each Ps-initialized context.
+ */
+int
+PsGetReproducibleArea(XpContextPtr pCon, xRectangle *pRect)
+{
+ XpGetReproductionArea(pCon, pRect);
+ return Success;
+}
+
+/*
+ * PsSetImageResolution is installed in the SetImageResolution field
+ * of each Ps-initialized context.
+ */
+int
+PsSetImageResolution(XpContextPtr pCon, int imageRes, Bool *status)
+{
+ pCon->imageRes = imageRes;
+ *status = True;
+ return Success;
+}
+
+/*
+ * GetPropString searches the window heirarchy from pWin up looking for
+ * a property by the name of propName. If found, returns the property's
+ * value. If not, it returns NULL.
+ */
+/*
+char *
+GetPropString(
+ WindowPtr pWin,
+ char *propName)
+{
+ Atom atom;
+ PropertyPtr pProp = (PropertyPtr)NULL;
+ char *retVal;
+
+ atom = MakeAtom(propName, strlen(propName), FALSE);
+ if(atom != BAD_RESOURCE)
+ {
+ WindowPtr pPropWin;
+ int n;
+*/
+
+ /*
+ * The atom has been defined, but it might only exist as a
+ * property on an unrelated window.
+ */
+/*
+ for(pPropWin = pWin; pPropWin != (WindowPtr)NULL;
+ pPropWin = pPropWin->parent)
+ {
+ for(pProp = (PropertyPtr)(wUserProps(pPropWin));
+ pProp != (PropertyPtr)NULL;
+ pProp = pProp->next)
+ {
+ if (pProp->propertyName == atom)
+ break;
+ }
+ if(pProp != (PropertyPtr)NULL)
+ break;
+ }
+ if(pProp == (PropertyPtr)NULL)
+ return (char *)NULL;
+
+ n = (pProp->format/8) * pProp->size; *//* size (bytes) of prop */
+/*
+ retVal = (char *)xalloc(n + 1);
+ (void)memcpy((void *)retVal, (void *)pProp->data, n);
+ retVal[n] = '\0';
+
+ return retVal;
+ }
+
+ return (char *)NULL;
+}
+
+#include <signal.h>
+
+*/
+/* ARGSUSED */
+/*
+static void SigchldHndlr (int dummy)
+{
+ int status, w;
+ struct sigaction act;
+ sigfillset(&act.sa_mask);
+ act.sa_flags = 0;
+ act.sa_handler = SigchldHndlr;
+
+ w = wait (&status);
+
+*/
+ /*
+ * Is this really necessary?
+ */
+/*
+ sigaction(SIGCHLD, &act, (struct sigaction *)NULL);
+}
+*/
+
+/*
+ * SystemCmd provides a wrapper for the 'system' library call. The call
+ * appears to be sensitive to the handling of SIGCHLD, so this wrapper
+ * sets the status to SIG_DFL, and then resets the established handler
+ * after system returns.
+ */
+/*
+int
+SystemCmd(char *cmdStr)
+{
+ int status;
+ struct sigaction newAct, oldAct;
+ sigfillset(&newAct.sa_mask);
+ newAct.sa_flags = 0;
+ newAct.sa_handler = SIG_DFL;
+ sigfillset(&oldAct.sa_mask);
+ oldAct.sa_flags = 0;
+ oldAct.sa_handler = SigchldHndlr;
+
+*/
+ /*
+ * get the old handler, and set the action to IGN
+ */
+/*
+ sigaction(SIGCHLD, &newAct, &oldAct);
+
+ status = system (cmdStr);
+
+ sigaction(SIGCHLD, &oldAct, (struct sigaction *)NULL);
+ return status;
+}
+*/
+
+Bool
+PsCloseScreen(
+ int index,
+ ScreenPtr pScreen)
+{
+ return TRUE;
+}
+
+void
+PsLineAttrs(
+ PsOutPtr psOut,
+ GCPtr pGC,
+ ColormapPtr cMap)
+{
+ int i;
+ int nDsh;
+ int dshOff;
+ int *dsh;
+ PsCapEnum cap;
+ PsJoinEnum join;
+
+ switch(pGC->capStyle) {
+ case CapButt: cap = PsCButt; break;
+ case CapRound: cap = PsCRound; break;
+ case CapProjecting: cap = PsCSquare; break;
+ default: cap = PsCButt; break; }
+ switch(pGC->joinStyle) {
+ case JoinMiter: join = PsJMiter; break;
+ case JoinRound: join = PsJRound; break;
+ case JoinBevel: join = PsJBevel; break;
+ default: join = PsJBevel; break; }
+ if( pGC->lineStyle==LineSolid ) { nDsh = dshOff = 0; dsh = (int *)0; }
+ else
+ {
+ nDsh = pGC->numInDashList;
+ dshOff = pGC->dashOffset;
+ if( !nDsh ) dsh = (int *)0;
+ else
+ {
+ dsh = (int *)xalloc(sizeof(int)*nDsh);
+ for( i=0 ; i<nDsh ; i++ ) dsh[i] = (int)pGC->dash[i]&0xFF;
+ }
+ }
+
+ if( pGC->lineStyle!=LineDoubleDash )
+ PsOut_LineAttrs(psOut, (int)pGC->lineWidth,
+ cap, join, nDsh, dsh, dshOff, -1);
+ else
+ PsOut_LineAttrs(psOut, (int)pGC->lineWidth,
+ cap, join, nDsh, dsh, dshOff,
+ PsGetPixelColor(cMap, pGC->bgPixel));
+ if( nDsh && dsh ) xfree(dsh);
+}
diff --git a/nx-X11/programs/Xserver/Xprint/ps/PsPixel.c b/nx-X11/programs/Xserver/Xprint/ps/PsPixel.c
new file mode 100644
index 000000000..2197f0ab9
--- /dev/null
+++ b/nx-X11/programs/Xserver/Xprint/ps/PsPixel.c
@@ -0,0 +1,157 @@
+/* $Xorg: PsPixel.c,v 1.4 2001/02/09 02:04:36 xorgcvs Exp $ */
+/*
+
+Copyright 1996, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+/*
+ * (c) Copyright 1996 Hewlett-Packard Company
+ * (c) Copyright 1996 International Business Machines Corp.
+ * (c) Copyright 1996 Sun Microsystems, Inc.
+ * (c) Copyright 1996 Novell, Inc.
+ * (c) Copyright 1996 Digital Equipment Corp.
+ * (c) Copyright 1996 Fujitsu Limited
+ * (c) Copyright 1996 Hitachi, Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject
+ * to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the names of the copyright holders
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * from said copyright holders.
+ */
+
+/*******************************************************************
+**
+** *********************************************************
+** *
+** * File: PsPixel.c
+** *
+** * Contents: Pixel-drawing code for the PS DDX driver
+** *
+** * Created By: Roger Helmendach (Liberty Systems)
+** *
+** * Copyright: Copyright 1995 The Open Group, Inc.
+** *
+** *********************************************************
+**
+********************************************************************/
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include <stdio.h>
+
+#include "windowstr.h"
+#include "gcstruct.h"
+
+#include "Ps.h"
+
+void
+PsPolyPoint(
+ DrawablePtr pDrawable,
+ GCPtr pGC,
+ int mode,
+ int nPoints,
+ xPoint *pPoints)
+{
+ if( pDrawable->type==DRAWABLE_PIXMAP )
+ {
+ DisplayElmPtr elm;
+ PixmapPtr pix = (PixmapPtr)pDrawable;
+ PsPixmapPrivPtr priv = (PsPixmapPrivPtr)pix->devPrivate.ptr;
+ DisplayListPtr disp;
+ GCPtr gc;
+
+ if ((gc = PsCreateAndCopyGC(pDrawable, pGC)) == NULL) return;
+
+ disp = PsGetFreeDisplayBlock(priv);
+
+ elm = &disp->elms[disp->nelms];
+ elm->type = PolyPointCmd;
+ elm->gc = gc;
+ elm->c.polyPts.mode = mode;
+ elm->c.polyPts.nPoints = nPoints;
+ elm->c.polyPts.pPoints = (xPoint *)xalloc(nPoints*sizeof(xPoint));
+ memcpy(elm->c.polyPts.pPoints, pPoints, nPoints*sizeof(xPoint));
+ disp->nelms += 1;
+ }
+ else
+ {
+ int i;
+ PsOutPtr psOut;
+ PsPointPtr pts;
+ ColormapPtr cMap;
+
+ if( PsUpdateDrawableGC(pGC, pDrawable, &psOut, &cMap)==FALSE ) return;
+ PsOut_Offset(psOut, pDrawable->x, pDrawable->y);
+ PsOut_Color(psOut, PsGetPixelColor(cMap, pGC->fgPixel));
+ pts = (PsPointPtr)xalloc(sizeof(PsPointRec)*nPoints);
+ if( mode==CoordModeOrigin )
+ {
+ for( i=0 ; i<nPoints ; i++ )
+ { pts[i].x = pPoints[i].x; pts[i].y = pPoints[i].y; }
+ }
+ else
+ {
+ pts[0].x = pPoints[0].x; pts[0].y = pPoints[0].y;
+ for( i=1 ; i<nPoints ; i++ )
+ {
+ pts[i].x = pts[i-1].x+pPoints[i].x;
+ pts[i].y = pts[i-1].y+pPoints[i].y;
+ }
+ }
+ PsOut_Points(psOut, nPoints, pts);
+ xfree(pts);
+ }
+}
+
+void
+PsPushPixels(
+ GCPtr pGC,
+ PixmapPtr pBitmap,
+ DrawablePtr pDrawable,
+ int width,
+ int height,
+ int x,
+ int y)
+{
+}
diff --git a/nx-X11/programs/Xserver/Xprint/ps/PsPixmap.c b/nx-X11/programs/Xserver/Xprint/ps/PsPixmap.c
new file mode 100644
index 000000000..a698b375e
--- /dev/null
+++ b/nx-X11/programs/Xserver/Xprint/ps/PsPixmap.c
@@ -0,0 +1,617 @@
+/* $Xorg: PsPixmap.c,v 1.4 2001/02/09 02:04:36 xorgcvs Exp $ */
+/*
+
+Copyright 1996, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+/*
+ * (c) Copyright 1996 Hewlett-Packard Company
+ * (c) Copyright 1996 International Business Machines Corp.
+ * (c) Copyright 1996 Sun Microsystems, Inc.
+ * (c) Copyright 1996 Novell, Inc.
+ * (c) Copyright 1996 Digital Equipment Corp.
+ * (c) Copyright 1996 Fujitsu Limited
+ * (c) Copyright 1996 Hitachi, Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject
+ * to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the names of the copyright holders
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * from said copyright holders.
+ */
+
+/*******************************************************************
+**
+** *********************************************************
+** *
+** * File: PsPixmap.c
+** *
+** * Contents: Pixmap functions for the PS DDX driver
+** *
+** * Created By: Roger Helmendach (Liberty Systems)
+** *
+** * Copyright: Copyright 1995 The Open Group, Inc.
+** *
+** *********************************************************
+**
+********************************************************************/
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include "windowstr.h"
+#include "gcstruct.h"
+
+#include "Ps.h"
+
+#define _BitsPerPixel(d) (\
+ (1 << PixmapWidthPaddingInfo[d].padBytesLog2) * 8 / \
+ (PixmapWidthPaddingInfo[d].padRoundUp+1))
+
+PixmapPtr
+PsCreatePixmap(
+ ScreenPtr pScreen,
+ int width,
+ int height,
+ int depth)
+{
+ PixmapPtr pPixmap;
+
+ pPixmap = (PixmapPtr)xcalloc(1, sizeof(PixmapRec));
+ if( !pPixmap) return NullPixmap;
+ pPixmap->drawable.type = DRAWABLE_PIXMAP;
+ pPixmap->drawable.class = 0;
+ pPixmap->drawable.pScreen = pScreen;
+ pPixmap->drawable.depth = depth;
+ pPixmap->drawable.bitsPerPixel = _BitsPerPixel(depth);
+ pPixmap->drawable.id = 0;
+ pPixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
+ pPixmap->drawable.x = 0;
+ pPixmap->drawable.y = 0;
+ pPixmap->drawable.width = width;
+ pPixmap->drawable.height = height;
+ pPixmap->devKind = 0;
+ pPixmap->refcnt = 1;
+
+ pPixmap->devPrivate.ptr = (PsPixmapPrivPtr)xcalloc(1, sizeof(PsPixmapPrivRec));
+ if( !pPixmap->devPrivate.ptr )
+ { xfree(pPixmap); return NullPixmap; }
+ return pPixmap;
+}
+
+/* PsScrubPixmap: Remove all content from a pixmap (used by
+ * |PsPolyFillRect()| when the "solid fill" operation covers
+ * the whole pixmap) */
+void
+PsScrubPixmap(PixmapPtr pPixmap)
+{
+ PsPixmapPrivPtr priv = (PsPixmapPrivPtr)pPixmap->devPrivate.ptr;
+ DisplayListPtr disp = priv->dispList;
+
+ while( disp )
+ {
+ int i;
+ DisplayListPtr oldDisp = disp;
+ disp = disp->next;
+ for( i=0 ; i<oldDisp->nelms ; i++ )
+ {
+ DisplayElmPtr elm = &oldDisp->elms[i];
+
+ switch(elm->type)
+ {
+ case PolyPointCmd:
+ case PolyLineCmd:
+ if( elm->c.polyPts.pPoints ) xfree(elm->c.polyPts.pPoints);
+ break;
+ case PolySegmentCmd:
+ if( elm->c.segments.pSegments ) xfree(elm->c.segments.pSegments);
+ break;
+ case PolyRectangleCmd:
+ if( elm->c.rects.pRects ) xfree(elm->c.rects.pRects);
+ break;
+ case FillPolygonCmd:
+ if( elm->c.polyPts.pPoints ) xfree(elm->c.polyPts.pPoints);
+ break;
+ case PolyFillRectCmd:
+ if( elm->c.rects.pRects ) xfree(elm->c.rects.pRects);
+ break;
+ case PolyArcCmd:
+ if( elm->c.arcs.pArcs ) xfree(elm->c.arcs.pArcs);
+ break;
+ case PolyFillArcCmd:
+ if( elm->c.arcs.pArcs ) xfree(elm->c.arcs.pArcs);
+ break;
+ case Text8Cmd:
+ case TextI8Cmd:
+ if( elm->c.text8.string ) xfree(elm->c.text8.string);
+ break;
+ case Text16Cmd:
+ case TextI16Cmd:
+ if( elm->c.text16.string ) xfree(elm->c.text16.string);
+ break;
+ case PutImageCmd:
+ if( elm->c.image.pData ) xfree(elm->c.image.pData);
+ break;
+ case BeginFrameCmd:
+ break;
+ case EndFrameCmd:
+ break;
+ }
+
+ if (elm->type != BeginFrameCmd && elm->type != EndFrameCmd) {
+ (void) FreeGC(elm->gc, (GContext) 0);
+ }
+ }
+ xfree(oldDisp);
+ }
+
+ priv->dispList = NULL;
+}
+
+Bool
+PsDestroyPixmap(PixmapPtr pPixmap)
+{
+ PsPixmapPrivPtr priv = (PsPixmapPrivPtr)pPixmap->devPrivate.ptr;
+ DisplayListPtr disp = priv->dispList;
+
+ if( --pPixmap->refcnt ) return TRUE;
+
+ PsScrubPixmap(pPixmap);
+
+ xfree(priv);
+ xfree(pPixmap);
+ return TRUE;
+}
+
+DisplayListPtr
+PsGetFreeDisplayBlock(PsPixmapPrivPtr priv)
+{
+ DisplayListPtr disp = priv->dispList;
+
+ for(; disp ; disp=disp->next )
+ {
+ if( disp->nelms>=DPY_BLOCKSIZE && disp->next ) continue;
+ if( disp->nelms<DPY_BLOCKSIZE ) return(disp);
+ disp->next = (DisplayListPtr)xcalloc(1, sizeof(DisplayListRec));
+ disp->next->next = (DisplayListPtr)0;
+ disp->next->nelms = 0;
+ }
+ disp = (DisplayListPtr)xcalloc(1, sizeof(DisplayListRec));
+ disp->next = (DisplayListPtr)0;
+ disp->nelms = 0;
+ priv->dispList = disp;
+ return(disp);
+}
+
+void
+PsReplay(DisplayElmPtr elm, DrawablePtr pDrawable)
+{
+ switch(elm->type)
+ {
+ case PolyPointCmd:
+ PsPolyPoint(pDrawable, elm->gc, elm->c.polyPts.mode,
+ elm->c.polyPts.nPoints, elm->c.polyPts.pPoints);
+ break;
+ case PolyLineCmd:
+ PsPolyLine(pDrawable, elm->gc, elm->c.polyPts.mode,
+ elm->c.polyPts.nPoints, elm->c.polyPts.pPoints);
+ break;
+ case PolySegmentCmd:
+ PsPolySegment(pDrawable, elm->gc, elm->c.segments.nSegments,
+ elm->c.segments.pSegments);
+ break;
+ case PolyRectangleCmd:
+ PsPolyRectangle(pDrawable, elm->gc, elm->c.rects.nRects,
+ elm->c.rects.pRects);
+ break;
+ case FillPolygonCmd:
+ PsFillPolygon(pDrawable, elm->gc, 0, elm->c.polyPts.mode,
+ elm->c.polyPts.nPoints, elm->c.polyPts.pPoints);
+ break;
+ case PolyFillRectCmd:
+ PsPolyFillRect(pDrawable, elm->gc, elm->c.rects.nRects,
+ elm->c.rects.pRects);
+ break;
+ case PolyArcCmd:
+ PsPolyArc(pDrawable, elm->gc, elm->c.arcs.nArcs, elm->c.arcs.pArcs);
+ break;
+ case PolyFillArcCmd:
+ PsPolyFillArc(pDrawable, elm->gc, elm->c.arcs.nArcs, elm->c.arcs.pArcs);
+ break;
+ case Text8Cmd:
+ PsPolyText8(pDrawable, elm->gc, elm->c.text8.x, elm->c.text8.y,
+ elm->c.text8.count, elm->c.text8.string);
+ break;
+ case Text16Cmd:
+ PsPolyText16(pDrawable, elm->gc, elm->c.text16.x, elm->c.text16.y,
+ elm->c.text16.count, elm->c.text16.string);
+ break;
+ case TextI8Cmd:
+ PsImageText8(pDrawable, elm->gc, elm->c.text8.x, elm->c.text8.y,
+ elm->c.text8.count, elm->c.text8.string);
+ break;
+ case TextI16Cmd:
+ PsImageText16(pDrawable, elm->gc, elm->c.text16.x, elm->c.text16.y,
+ elm->c.text16.count, elm->c.text16.string);
+ break;
+ case PutImageCmd:
+ PsPutScaledImage(pDrawable, elm->gc, elm->c.image.depth,
+ elm->c.image.x, elm->c.image.y,
+ elm->c.image.w, elm->c.image.h, elm->c.image.leftPad,
+ elm->c.image.format, elm->c.image.res,
+ elm->c.image.pData);
+ break;
+ case BeginFrameCmd:
+ {
+ PsOutPtr psOut;
+ ColormapPtr cMap;
+ if( PsUpdateDrawableGC(NULL, pDrawable, &psOut, &cMap)==FALSE ) return;
+ PsOut_BeginFrame(psOut, 0, 0, elm->c.frame.x, elm->c.frame.y,
+ elm->c.frame.w, elm->c.frame.h);
+ }
+ break;
+ case EndFrameCmd:
+ {
+ PsOutPtr psOut;
+ ColormapPtr cMap;
+ if( PsUpdateDrawableGC(NULL, pDrawable, &psOut, &cMap)==FALSE ) return;
+ PsOut_EndFrame(psOut);
+ }
+ break;
+ }
+}
+
+void
+PsReplayPixmap(PixmapPtr pix, DrawablePtr pDrawable)
+{
+ PsPixmapPrivPtr priv = (PsPixmapPrivPtr)pix->devPrivate.ptr;
+ DisplayListPtr disp = priv->dispList;
+ DisplayElmPtr elm;
+
+ for(; disp ; disp=disp->next )
+ {
+ int i;
+ for( i=0,elm=disp->elms ; i<disp->nelms ; i++,elm++ )
+ PsReplay(elm, pDrawable);
+ }
+}
+
+int
+PsCloneDisplayElm(PixmapPtr dst, DisplayElmPtr elm, DisplayElmPtr newElm,
+ int xoff, int yoff)
+{
+ int i;
+ int size;
+ int status = 0;
+
+ *newElm = *elm;
+
+ /* I think this is the correct return value */
+ if ((newElm->gc = PsCreateAndCopyGC(&dst->drawable, elm->gc)) == NULL) {
+ return 1;
+ }
+
+ switch(elm->type)
+ {
+ case PolyPointCmd:
+ case PolyLineCmd:
+ newElm->c.polyPts.pPoints =
+ (xPoint *)xalloc(elm->c.polyPts.nPoints*sizeof(xPoint));
+ for( i=0 ; i<elm->c.polyPts.nPoints ; i++ )
+ {
+ newElm->c.polyPts.pPoints[i].x = elm->c.polyPts.pPoints[i].x+xoff;
+ newElm->c.polyPts.pPoints[i].y = elm->c.polyPts.pPoints[i].y+yoff;
+ }
+ break;
+ case PolySegmentCmd:
+ newElm->c.segments.pSegments =
+ (xSegment *)xalloc(elm->c.segments.nSegments*sizeof(xSegment));
+ for( i=0 ; i<elm->c.segments.nSegments ; i++ )
+ {
+ newElm->c.segments.pSegments[i].x1 =
+ elm->c.segments.pSegments[i].x1+xoff;
+ newElm->c.segments.pSegments[i].y1 =
+ elm->c.segments.pSegments[i].y1+yoff;
+ newElm->c.segments.pSegments[i].x2 =
+ elm->c.segments.pSegments[i].x2+xoff;
+ newElm->c.segments.pSegments[i].y2 =
+ elm->c.segments.pSegments[i].y2+yoff;
+ }
+ break;
+ case PolyRectangleCmd:
+ newElm->c.rects.pRects =
+ (xRectangle *)xalloc(elm->c.rects.nRects*sizeof(xRectangle));
+ for( i=0 ; i<elm->c.rects.nRects ; i++ )
+ {
+ newElm->c.rects.pRects[i].x = elm->c.rects.pRects[i].x+xoff;
+ newElm->c.rects.pRects[i].y = elm->c.rects.pRects[i].y+yoff;
+ newElm->c.rects.pRects[i].width = elm->c.rects.pRects[i].width;
+ newElm->c.rects.pRects[i].height = elm->c.rects.pRects[i].height;
+ }
+ break;
+ case FillPolygonCmd:
+ newElm->c.polyPts.pPoints =
+ (xPoint *)xalloc(elm->c.polyPts.nPoints*sizeof(xPoint));
+ for( i=0 ; i<elm->c.polyPts.nPoints ; i++ )
+ {
+ newElm->c.polyPts.pPoints[i].x = elm->c.polyPts.pPoints[i].x+xoff;
+ newElm->c.polyPts.pPoints[i].y = elm->c.polyPts.pPoints[i].y+yoff;
+ }
+ break;
+ case PolyFillRectCmd:
+ newElm->c.rects.pRects =
+ (xRectangle *)xalloc(elm->c.rects.nRects*sizeof(xRectangle));
+ for( i=0 ; i<elm->c.rects.nRects ; i++ )
+ {
+ newElm->c.rects.pRects[i].x = elm->c.rects.pRects[i].x+xoff;
+ newElm->c.rects.pRects[i].y = elm->c.rects.pRects[i].y+yoff;
+ newElm->c.rects.pRects[i].width = elm->c.rects.pRects[i].width;
+ newElm->c.rects.pRects[i].height = elm->c.rects.pRects[i].height;
+ }
+ break;
+ case PolyArcCmd:
+ newElm->c.arcs.pArcs =
+ (xArc *)xalloc(elm->c.arcs.nArcs*sizeof(xArc));
+ for( i=0 ; i<elm->c.arcs.nArcs ; i++ )
+ {
+ newElm->c.arcs.pArcs[i].x = elm->c.arcs.pArcs[i].x+xoff;
+ newElm->c.arcs.pArcs[i].y = elm->c.arcs.pArcs[i].y+yoff;
+ newElm->c.arcs.pArcs[i].width = elm->c.arcs.pArcs[i].width;
+ newElm->c.arcs.pArcs[i].height = elm->c.arcs.pArcs[i].height;
+ newElm->c.arcs.pArcs[i].angle1 = elm->c.arcs.pArcs[i].angle1;
+ newElm->c.arcs.pArcs[i].angle2 = elm->c.arcs.pArcs[i].angle2;
+ }
+ break;
+ case PolyFillArcCmd:
+ newElm->c.arcs.pArcs =
+ (xArc *)xalloc(elm->c.arcs.nArcs*sizeof(xArc));
+ for( i=0 ; i<elm->c.arcs.nArcs ; i++ )
+ {
+ newElm->c.arcs.pArcs[i].x = elm->c.arcs.pArcs[i].x+xoff;
+ newElm->c.arcs.pArcs[i].y = elm->c.arcs.pArcs[i].y+yoff;
+ newElm->c.arcs.pArcs[i].width = elm->c.arcs.pArcs[i].width;
+ newElm->c.arcs.pArcs[i].height = elm->c.arcs.pArcs[i].height;
+ newElm->c.arcs.pArcs[i].angle1 = elm->c.arcs.pArcs[i].angle1;
+ newElm->c.arcs.pArcs[i].angle2 = elm->c.arcs.pArcs[i].angle2;
+ }
+ break;
+ case Text8Cmd:
+ case TextI8Cmd:
+ newElm->c.text8.string = (char *)xalloc(elm->c.text8.count);
+ memcpy(newElm->c.text8.string, elm->c.text8.string, elm->c.text8.count);
+ newElm->c.text8.x += xoff;
+ newElm->c.text8.y += yoff;
+ break;
+ case Text16Cmd:
+ case TextI16Cmd:
+ newElm->c.text16.string =
+ (unsigned short *)xalloc(elm->c.text16.count*sizeof(unsigned short));
+ memcpy(newElm->c.text16.string, elm->c.text16.string,
+ elm->c.text16.count*sizeof(unsigned short));
+ newElm->c.text16.x += xoff;
+ newElm->c.text16.y += yoff;
+ break;
+ case PutImageCmd:
+ size = PixmapBytePad(elm->c.image.w, elm->c.image.depth)*elm->c.image.h;
+ newElm->c.image.pData = (char *)xalloc(size);
+ memcpy(newElm->c.image.pData, elm->c.image.pData, size);
+ newElm->c.image.x += xoff;
+ newElm->c.image.y += yoff;
+ break;
+ case BeginFrameCmd:
+ case EndFrameCmd:
+ status = 1;
+ break;
+ }
+ return(status);
+}
+
+void
+PsCopyDisplayList(PixmapPtr src, PixmapPtr dst, int xoff, int yoff,
+ int x, int y, int w, int h)
+{
+ PsPixmapPrivPtr sPriv = (PsPixmapPrivPtr)src->devPrivate.ptr;
+ PsPixmapPrivPtr dPriv = (PsPixmapPrivPtr)dst->devPrivate.ptr;
+ DisplayListPtr sDisp;
+ DisplayListPtr dDisp = PsGetFreeDisplayBlock(dPriv);
+ DisplayElmPtr elm = &dDisp->elms[dDisp->nelms];
+
+ elm->type = BeginFrameCmd;
+ elm->c.frame.x = x;
+ elm->c.frame.y = y;
+ elm->c.frame.w = w;
+ elm->c.frame.h = h;
+ dDisp->nelms += 1;
+
+ sDisp = sPriv->dispList;
+ for(; sDisp ; sDisp=sDisp->next )
+ {
+ int i;
+ for( i=0,elm=sDisp->elms ; i<sDisp->nelms ; i++,elm++ )
+ {
+ dDisp = PsGetFreeDisplayBlock(dPriv);
+ if (PsCloneDisplayElm(dst, elm, &dDisp->elms[dDisp->nelms],
+ xoff, yoff)==0)
+ {
+ dDisp->nelms += 1;
+ }
+ }
+ }
+
+ dDisp = PsGetFreeDisplayBlock(dPriv);
+ elm = &dDisp->elms[dDisp->nelms];
+ elm->type = EndFrameCmd;
+ dDisp->nelms += 1;
+}
+
+PsElmPtr
+PsCreateFillElementList(PixmapPtr pix, int *nElms)
+{
+ PsElmPtr elms = (PsElmPtr)0;
+ PsPixmapPrivPtr priv = (PsPixmapPrivPtr)pix->devPrivate.ptr;
+ DisplayListPtr disp = priv->dispList;
+ PsArcEnum styl;
+
+ *nElms = 0;
+ for(; disp ; disp=disp->next )
+ {
+ int i;
+ DisplayElmPtr elm = disp->elms;
+
+ for( i=0 ; i<disp->nelms ; i++,elm++ )
+ {
+ if( !elm->gc ) continue; /* workaround for https://freedesktop.org/bugzilla/show_bug.cgi?id=1416 */
+ if( !elm->gc->fgPixel ) continue;
+ switch(elm->type)
+ {
+ case FillPolygonCmd:
+ *nElms += 1;
+ break;
+ case PolyFillRectCmd:
+ *nElms += elm->c.rects.nRects;
+ break;
+ case PolyFillArcCmd:
+ *nElms += elm->c.arcs.nArcs;
+ break;
+ }
+ }
+ }
+
+ if( (*nElms) )
+ {
+ elms = (PsElmPtr)xcalloc(1, (*nElms)*sizeof(PsElmRec));
+ if( elms )
+ {
+ disp = priv->dispList;
+ *nElms = 0;
+ for(; disp ; disp=disp->next )
+ {
+ int i, k;
+ DisplayElmPtr elm = disp->elms;
+
+ for( i=0 ; i<disp->nelms ; i++,elm++ )
+ {
+ if( !elm->gc->fgPixel ) continue;
+ switch(elm->type)
+ {
+ case FillPolygonCmd:
+ elms[*nElms].type = PSOUT_POINTS;
+ elms[*nElms].nPoints = elm->c.polyPts.nPoints;
+ elms[*nElms].c.points =
+ (PsPointPtr)xalloc(elms[*nElms].nPoints*sizeof(PsPointRec));
+ for( k=0 ; k<elms[*nElms].nPoints ; k++ )
+ {
+ elms[*nElms].c.points[k].x = elm->c.polyPts.pPoints[k].x;
+ elms[*nElms].c.points[k].y = elm->c.polyPts.pPoints[k].y;
+ }
+ *nElms += 1;
+ break;
+ case PolyFillRectCmd:
+ for( k=0 ; k<elm->c.rects.nRects ; k++ )
+ {
+ elms[*nElms].type = PSOUT_RECT;
+ elms[*nElms].nPoints = 0;
+ elms[*nElms].c.rect.x = elm->c.rects.pRects[k].x;
+ elms[*nElms].c.rect.y = elm->c.rects.pRects[k].y;
+ elms[*nElms].c.rect.w = elm->c.rects.pRects[k].width;
+ elms[*nElms].c.rect.h = elm->c.rects.pRects[k].height;
+ *nElms += 1;
+ }
+ break;
+ case PolyFillArcCmd:
+ if( elm->gc->arcMode==ArcChord ) styl = PsChord;
+ else styl = PsPieSlice;
+ for( k=0 ; k<elm->c.rects.nRects ; k++ )
+ {
+ elms[*nElms].type = PSOUT_ARC;
+ elms[*nElms].nPoints = 0;
+ elms[*nElms].c.arc.x = elm->c.arcs.pArcs[k].x;
+ elms[*nElms].c.arc.y = elm->c.arcs.pArcs[k].y;
+ elms[*nElms].c.arc.w = elm->c.arcs.pArcs[k].width;
+ elms[*nElms].c.arc.h = elm->c.arcs.pArcs[k].height;
+ elms[*nElms].c.arc.a1 = elm->c.arcs.pArcs[k].angle1;
+ elms[*nElms].c.arc.a2 = elm->c.arcs.pArcs[k].angle2;
+ elms[*nElms].c.arc.style = styl;
+ *nElms += 1;
+ }
+ break;
+ }
+ }
+ }
+ }
+ }
+ return(elms);
+}
+
+PsElmPtr
+PsCloneFillElementList(int nElms, PsElmPtr elms)
+{
+ int i;
+ PsElmPtr newElms;
+
+ newElms = (PsElmPtr)xcalloc(1, nElms*sizeof(PsElmRec));
+ if( !newElms ) return(newElms);
+ for( i=0 ; i<nElms ; i++ )
+ {
+ newElms[i] = elms[i];
+
+ if( elms[i].type==PSOUT_POINTS )
+ {
+ newElms[i].c.points =
+ (PsPointPtr)xalloc(elms[i].nPoints*sizeof(PsElmRec));
+ memcpy(newElms[i].c.points, elms[i].c.points,
+ elms[i].nPoints*sizeof(PsPointRec));
+ }
+ }
+ return(newElms);
+}
+
+void
+PsDestroyFillElementList(int nElms, PsElmPtr elms)
+{
+ int i;
+
+ for( i=0 ; i<nElms ; i++ )
+ { if( elms[i].type==PSOUT_POINTS ) xfree(elms[i].c.points); }
+
+ xfree(elms);
+}
diff --git a/nx-X11/programs/Xserver/Xprint/ps/PsPolygon.c b/nx-X11/programs/Xserver/Xprint/ps/PsPolygon.c
new file mode 100644
index 000000000..a1ae67f8d
--- /dev/null
+++ b/nx-X11/programs/Xserver/Xprint/ps/PsPolygon.c
@@ -0,0 +1,262 @@
+/* $Xorg: PsPolygon.c,v 1.4 2001/02/09 02:04:36 xorgcvs Exp $ */
+/*
+
+Copyright 1996, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+/*
+ * (c) Copyright 1996 Hewlett-Packard Company
+ * (c) Copyright 1996 International Business Machines Corp.
+ * (c) Copyright 1996 Sun Microsystems, Inc.
+ * (c) Copyright 1996 Novell, Inc.
+ * (c) Copyright 1996 Digital Equipment Corp.
+ * (c) Copyright 1996 Fujitsu Limited
+ * (c) Copyright 1996 Hitachi, Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject
+ * to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the names of the copyright holders
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * from said copyright holders.
+ */
+
+/*******************************************************************
+**
+** *********************************************************
+** *
+** * File: PsPolygon.c
+** *
+** * Contents: Draws Polygons and Rectangles for the PS DDX
+** *
+** * Created By: Roger Helmendach (Liberty Systems)
+** *
+** * Copyright: Copyright 1996 The Open Group, Inc.
+** *
+** *********************************************************
+**
+********************************************************************/
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include "Ps.h"
+#include "gcstruct.h"
+#include "windowstr.h"
+
+void
+PsPolyRectangle(
+ DrawablePtr pDrawable,
+ GCPtr pGC,
+ int nRects,
+ xRectangle *pRects)
+{
+ if( pDrawable->type==DRAWABLE_PIXMAP )
+ {
+ DisplayElmPtr elm;
+ PixmapPtr pix = (PixmapPtr)pDrawable;
+ PsPixmapPrivPtr priv = (PsPixmapPrivPtr)pix->devPrivate.ptr;
+ DisplayListPtr disp;
+ GCPtr gc;
+
+ if ((gc = PsCreateAndCopyGC(pDrawable, pGC)) == NULL) return;
+
+ disp = PsGetFreeDisplayBlock(priv);
+
+ elm = &disp->elms[disp->nelms];
+ elm->type = PolyRectangleCmd;
+ elm->gc = gc;
+ elm->c.rects.nRects = nRects;
+ elm->c.rects.pRects = (xRectangle *)xalloc(nRects*sizeof(xRectangle));
+ memcpy(elm->c.rects.pRects, pRects, nRects*sizeof(xRectangle));
+ disp->nelms += 1;
+ }
+ else
+ {
+ int i;
+ PsOutPtr psOut;
+ ColormapPtr cMap;
+
+ if( PsUpdateDrawableGC(pGC, pDrawable, &psOut, &cMap)==FALSE ) return;
+ PsOut_Offset(psOut, pDrawable->x, pDrawable->y);
+ PsOut_Color(psOut, PsGetPixelColor(cMap, pGC->fgPixel));
+ PsLineAttrs(psOut, pGC, cMap);
+ for( i=0 ; i<nRects ; i++ )
+ {
+ PsOut_DrawRect(psOut, (int)pRects[i].x, (int)pRects[i].y,
+ (int)pRects[i].width, (int)pRects[i].height);
+ }
+ }
+}
+
+void
+PsFillPolygon(
+ DrawablePtr pDrawable,
+ GCPtr pGC,
+ int shape,
+ int mode,
+ int nPoints,
+ DDXPointPtr pPoints)
+{
+ if( pDrawable->type==DRAWABLE_PIXMAP )
+ {
+ DisplayElmPtr elm;
+ PixmapPtr pix = (PixmapPtr)pDrawable;
+ PsPixmapPrivPtr priv = (PsPixmapPrivPtr)pix->devPrivate.ptr;
+ DisplayListPtr disp;
+ GCPtr gc;
+
+ if ((gc = PsCreateAndCopyGC(pDrawable, pGC)) == NULL) return;
+
+ disp = PsGetFreeDisplayBlock(priv);
+
+ elm = &disp->elms[disp->nelms];
+ elm->type = FillPolygonCmd;
+ elm->gc = gc;
+ elm->c.polyPts.mode = mode;
+ elm->c.polyPts.nPoints = nPoints;
+ elm->c.polyPts.pPoints = (xPoint *)xalloc(nPoints*sizeof(xPoint));
+ memcpy(elm->c.polyPts.pPoints, pPoints, nPoints*sizeof(xPoint));
+ disp->nelms += 1;
+ }
+ else
+ {
+ int i;
+ PsOutPtr psOut;
+ PsPointPtr pts;
+ PsRuleEnum rule;
+ ColormapPtr cMap;
+
+ if( PsUpdateDrawableGC(pGC, pDrawable, &psOut, &cMap)==FALSE ) return;
+ PsOut_Offset(psOut, pDrawable->x, pDrawable->y);
+ PsSetFillColor(pDrawable, pGC, psOut, cMap);
+ if( pGC->fillRule==EvenOddRule ) rule = PsEvenOdd;
+ else rule = PsNZWinding;
+ PsOut_FillRule(psOut, rule);
+ pts = (PsPointPtr)xalloc(sizeof(PsPointRec)*nPoints);
+ if( mode==CoordModeOrigin )
+ {
+ for( i=0 ; i<nPoints ; i++ )
+ { pts[i].x = pPoints[i].x; pts[i].y = pPoints[i].y; }
+ }
+ else
+ {
+ i = 0;
+ pts[0].x = pPoints[i].x; pts[0].y = pPoints[i].y;
+ for( i=1 ; i<nPoints ; i++ )
+ {
+ pts[i].x = pts[i-1].x+pPoints[i].x;
+ pts[i].y = pts[i-1].y+pPoints[i].y;
+ }
+ }
+ PsOut_Polygon(psOut, nPoints, pts);
+ xfree(pts);
+ }
+}
+
+void
+PsPolyFillRect(
+ DrawablePtr pDrawable,
+ GCPtr pGC,
+ int nRects,
+ xRectangle *pRects)
+{
+ if( pDrawable->type==DRAWABLE_PIXMAP )
+ {
+ DisplayElmPtr elm;
+ PixmapPtr pix = (PixmapPtr)pDrawable;
+ PsPixmapPrivPtr priv = (PsPixmapPrivPtr)pix->devPrivate.ptr;
+ DisplayListPtr disp;
+ GCPtr gc;
+
+#ifdef DBE
+ /* Remove previous pixmap content if we render one single rect which
+ * covers the whole pixmap surface (this optimisation was added for
+ * the double-buffer extension ("DBE") which uses |PolyFillRect()|
+ * to clear the buffer - but it makes sense in other cases, too).
+ */
+ if (nRects == 1)
+ {
+ extern Bool noDbeExtension;
+
+ if ( (pRects[0].x==0) && (pRects[0].y==0) &&
+ (pRects[0].width==pDrawable->width) && (pRects[0].height==pDrawable->height) &&
+ (pGC->fillStyle == FillSolid) &&
+ (noDbeExtension == False))
+ {
+#ifdef DEBUG_gismobile
+ ErrorF("PsPolyFillRect: scrubbing pixmap...\n");
+#endif /* DEBUG_gismobile */
+ /* Remove all content from the pixmap as it would be covered
+ * by the whole rect anyway */
+ PsScrubPixmap(pDrawable);
+ }
+ }
+#endif /* DBE */
+
+ if ((gc = PsCreateAndCopyGC(pDrawable, pGC)) == NULL) return;
+
+ disp = PsGetFreeDisplayBlock(priv);
+
+ elm = &disp->elms[disp->nelms];
+ elm->type = PolyFillRectCmd;
+ elm->gc = gc;
+ elm->c.rects.nRects = nRects;
+ elm->c.rects.pRects = (xRectangle *)xalloc(nRects*sizeof(xRectangle));
+ memcpy(elm->c.rects.pRects, pRects, nRects*sizeof(xRectangle));
+ disp->nelms += 1;
+ }
+ else
+ {
+ int i;
+ PsOutPtr psOut;
+ ColormapPtr cMap;
+
+ if( PsUpdateDrawableGC(pGC, pDrawable, &psOut, &cMap)==FALSE ) return;
+ PsOut_Offset(psOut, pDrawable->x, pDrawable->y);
+ PsSetFillColor(pDrawable, pGC, psOut, cMap);
+ for( i=0 ; i<nRects ; i++ )
+ {
+ PsOut_FillRect(psOut, (int)pRects[i].x, (int)pRects[i].y,
+ (int)pRects[i].width, (int)pRects[i].height);
+ }
+ }
+}
diff --git a/nx-X11/programs/Xserver/Xprint/ps/PsPrint.c b/nx-X11/programs/Xserver/Xprint/ps/PsPrint.c
new file mode 100644
index 000000000..05e8e2588
--- /dev/null
+++ b/nx-X11/programs/Xserver/Xprint/ps/PsPrint.c
@@ -0,0 +1,462 @@
+/* $Xorg: PsPrint.c,v 1.7 2001/03/14 18:28:18 pookie Exp $ */
+/*
+
+Copyright 1996, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+/*
+ * (c) Copyright 1996 Hewlett-Packard Company
+ * (c) Copyright 1996 International Business Machines Corp.
+ * (c) Copyright 1996, 2000 Sun Microsystems, Inc. All rights reserved.
+ * (c) Copyright 1996 Novell, Inc.
+ * (c) Copyright 1996 Digital Equipment Corp.
+ * (c) Copyright 1996 Fujitsu Limited
+ * (c) Copyright 1996 Hitachi, Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject
+ * to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the names of the copyright holders
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * from said copyright holders.
+ */
+
+/*******************************************************************
+**
+** *********************************************************
+** *
+** * File: PsPrint.c
+** *
+** * Contents: Print extension code of Ps driver
+** *
+** * Created By: Roger Helmendach (Liberty Systems)
+** *
+** * Copyright: Copyright 1996 The Open Group, Inc.
+** *
+** *********************************************************
+**
+********************************************************************/
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <unistd.h>
+#include <errno.h>
+#include <X11/Xprotostr.h>
+
+#define NEED_EVENTS
+#include <X11/Xproto.h>
+#undef NEED_EVENTS
+
+#include "Ps.h"
+
+#include "windowstr.h"
+#include "attributes.h"
+#include "Oid.h"
+
+/* static utility function to get document/page attributes */
+static void
+S_GetPageAttributes(XpContextPtr pCon,int *iorient,int *icount, int *iplex,
+ int *ires, unsigned short *iwd, unsigned short *iht)
+{
+ char *count;
+ XpOid orient, plex;
+ /*
+ * Get the orientation
+ */
+ orient = XpGetContentOrientation(pCon);
+ switch (orient) {
+ case xpoid_val_content_orientation_landscape:
+ *iorient = 1;
+ break;
+ case xpoid_val_content_orientation_reverse_portrait:
+ *iorient = 2;
+ break;
+ case xpoid_val_content_orientation_reverse_landscape:
+ *iorient = 3;
+ break;
+ case xpoid_val_content_orientation_portrait:
+ default:
+ *iorient = 0;
+ break;
+ }
+
+ /*
+ * Get the count
+ */
+ count = XpGetOneAttribute(pCon, XPDocAttr, "copy-count");
+ if( count )
+ {
+ int ii = sscanf(count, "%d", icount);
+ if( ii!=1 ) *icount = 1;
+ }
+ else *icount = 1;
+
+ /*
+ * Get the plex
+ */
+ plex = XpGetPlex(pCon);
+ switch(plex)
+ {
+ case xpoid_val_plex_duplex:
+ *iplex = 1;
+ break;
+ case xpoid_val_plex_tumble:
+ *iplex = 2;
+ break;
+ default:
+ *iplex = 0;
+ break;
+ }
+
+ /*
+ * Get the resolution and media size
+ */
+ *ires = XpGetResolution(pCon);
+ XpGetMediumDimensions(pCon, iwd, iht);
+}
+
+
+int
+PsStartJob(
+ XpContextPtr pCon,
+ Bool sendClientData,
+ ClientPtr client)
+{
+ PsContextPrivPtr pConPriv =
+ (PsContextPrivPtr)pCon->devPrivates[PsContextPrivateIndex].ptr;
+
+ /*
+ * Create a temporary file to store the printer output.
+ */
+ if (!XpOpenTmpFile("w", &pConPriv->jobFileName, &pConPriv->pJobFile))
+ return BadAlloc;
+
+ return Success;
+}
+
+
+
+/* I thought about making this following code into a set of routines
+ or using a goto, or something, but in the end decided not to,
+ because the plain old listing here makes the logic clearer. */
+int
+PsEndJob(
+ XpContextPtr pCon,
+ Bool cancel)
+{
+ int r;
+ struct stat buffer;
+ int error;
+
+ PsContextPrivPtr priv =
+ (PsContextPrivPtr)pCon->devPrivates[PsContextPrivateIndex].ptr;
+
+ if (cancel == True) {
+ if (priv->getDocClient != (ClientPtr) NULL) {
+ (void) XpFinishDocData( priv->getDocClient );
+
+ priv->getDocClient = NULL;
+ priv->getDocBufSize = 0;
+ }
+
+ /* job is cancelled - do we really care if we're out of space? */
+ (void) fclose(priv->pJobFile);
+ priv->pJobFile = NULL;
+
+ unlink(priv->jobFileName);
+ xfree(priv->jobFileName);
+ priv->jobFileName = (char *)NULL;
+
+ PsFreeFontInfoRecords(priv);
+
+ return Success;
+ }
+
+ /*
+ * Append any trailing information here
+ */
+ PsOut_EndFile(priv->pPsOut, 0);
+ priv->pPsOut = NULL;
+
+ /* this is where we find out if we're out of space */
+ error = (fclose(priv->pJobFile) == EOF);
+ priv->pJobFile = NULL;
+
+ /* status to the client if we have ran out of space on the disk or
+ some other resource problem with the temporary file... */
+ if (error) {
+ if (priv->getDocClient != (ClientPtr) NULL) {
+ (void) XpFinishDocData( priv->getDocClient );
+
+ priv->getDocClient = NULL;
+ priv->getDocBufSize = 0;
+ }
+
+ unlink(priv->jobFileName);
+ xfree(priv->jobFileName);
+ priv->jobFileName = (char *)NULL;
+
+ PsFreeFontInfoRecords(priv);
+
+ return BadAlloc;
+ }
+
+ /* we have finished without incident & no cancel */
+
+ if (priv->getDocClient != NULL && priv->getDocBufSize > 0) {
+ FILE *file;
+
+ file = fopen(priv->jobFileName, "r");
+ if (!file || (fstat(fileno(file), &buffer) < 0))
+ r = BadAlloc;
+ else
+ r = XpSendDocumentData(priv->getDocClient, file, buffer.st_size,
+ priv->getDocBufSize);
+ if (file)
+ fclose(file);
+
+ (void) XpFinishDocData(priv->getDocClient);
+
+ priv->getDocClient = NULL;
+ priv->getDocBufSize = 0;
+ }
+ else {
+ XpSubmitJob(priv->jobFileName, pCon);
+
+ r = Success;
+ }
+
+ unlink(priv->jobFileName);
+ xfree(priv->jobFileName);
+ priv->jobFileName = (char *)NULL;
+
+ PsFreeFontInfoRecords(priv);
+
+#ifdef BM_CACHE
+ PsBmClearImageCache();
+#endif
+
+ return r;
+}
+
+/* StartPage
+ */
+int
+PsStartPage(
+ XpContextPtr pCon,
+ WindowPtr pWin)
+{
+ int iorient, iplex, icount, ires;
+ unsigned short iwd, iht;
+ register WindowPtr pChild;
+ PsContextPrivPtr pConPriv =
+ (PsContextPrivPtr)pCon->devPrivates[PsContextPrivateIndex].ptr;
+ PsWindowPrivPtr pWinPriv =
+ (PsWindowPrivPtr)pWin->devPrivates[PsWindowPrivateIndex].ptr;
+ char s[80];
+ xEvent event;
+
+/*
+ * Put a pointer to the context in the window private structure
+ */
+ pWinPriv->validContext = 1;
+ pWinPriv->context = pCon;
+
+ /* get page level attributes */
+ S_GetPageAttributes(pCon,&iorient,&icount,&iplex,&ires,&iwd,&iht);
+ /*
+ * Start the page
+ */
+ if (pConPriv->pPsOut == NULL) {
+ char *title;
+
+ /* get job level attributes */
+ title = XpGetOneAttribute(pCon, XPJobAttr, "job-name");
+
+ pConPriv->pPsOut = PsOut_BeginFile(pConPriv->pJobFile,
+ title, iorient, icount, iplex, ires,
+ (int)iwd, (int)iht, False);
+ pConPriv->fontInfoRecords = NULL;
+ pConPriv->fontTypeInfoRecords = NULL;
+ }
+ PsOut_BeginPage(pConPriv->pPsOut, iorient, icount, iplex, ires,
+ (int)iwd, (int)iht);
+
+ return Success;
+}
+
+
+/*
+ * EndPage:
+ *
+ * Write page trailer to page file
+ * Write page file to job file
+ */
+int
+PsEndPage(
+ XpContextPtr pCon,
+ WindowPtr pWin)
+{
+ PsWindowPrivPtr pWinPriv =
+ (PsWindowPrivPtr)pWin->devPrivates[PsWindowPrivateIndex].ptr;
+ PsContextPrivPtr pConPriv =
+ (PsContextPrivPtr)pCon->devPrivates[PsContextPrivateIndex].ptr;
+
+ PsOut_EndPage(pConPriv->pPsOut);
+
+ pWinPriv->validContext = 0;
+ pWinPriv->context = NULL;
+
+ /* status to the client if we have ran out of space on the disk or
+ some other resource problem with the temporary file... */
+/* if (ferror(pConPriv->pJobFile)) return BadAlloc; */
+
+ return Success;
+}
+
+/*
+ * The PsStartDoc() and PsEndDoc() functions serve basically as NOOP
+ * placeholders. This driver doesn't deal with the notion of multiple
+ * documents per page.
+ */
+
+int
+PsStartDoc(XpContextPtr pCon, XPDocumentType type)
+{
+ int iorient, iplex, icount, ires;
+ unsigned short iwd, iht;
+ char *title;
+ PsContextPrivPtr pConPriv =
+ (PsContextPrivPtr)pCon->devPrivates[PsContextPrivateIndex].ptr;
+
+ /* get job level attributes */
+ title = XpGetOneAttribute(pCon, XPJobAttr, "job-name");
+
+ /* get document level attributes */
+ S_GetPageAttributes(pCon,&iorient,&icount,&iplex,&ires,&iwd,&iht);
+
+ pConPriv->pPsOut = PsOut_BeginFile(pConPriv->pJobFile,
+ title, iorient, icount, iplex, ires,
+ (int)iwd, (int)iht, (Bool)(type == XPDocRaw));
+
+ pConPriv->fontInfoRecords = NULL;
+ pConPriv->fontTypeInfoRecords = NULL;
+
+ return Success;
+}
+
+int
+PsEndDoc(
+ XpContextPtr pCon,
+ Bool cancel)
+{
+ return Success;
+}
+
+/*
+ * PsDocumentData()
+ *
+ * Hand any pre-generated PDL down to the spool files, formatting it
+ * as necessary to fit the given window.
+ */
+
+int
+PsDocumentData(
+ XpContextPtr pCon,
+ DrawablePtr pDraw,
+ char *pData,
+ int len_data,
+ char *pFmt,
+ int len_fmt,
+ char *pOpt,
+ int len_opt,
+ ClientPtr client)
+{
+ PsContextPrivPtr cPriv;
+ PsOutPtr psOut;
+
+ if (len_fmt != 12 ||
+ strncasecmp(pFmt, "PostScript 2", len_fmt) != 0 ||
+ len_opt)
+ return BadValue;
+
+ cPriv = pCon->devPrivates[PsContextPrivateIndex].ptr;
+ psOut = cPriv->pPsOut;
+
+ if (pDraw)
+ PsOut_BeginFrame(psOut, 0, 0, pDraw->x, pDraw->y,
+ pDraw->width, pDraw->height);
+ PsOut_RawData(psOut, pData, len_data);
+ if (pDraw)
+ PsOut_EndFrame(psOut);
+
+ return Success;
+}
+
+/*
+ *
+ * PsGetDocumentData()
+ *
+ * This function allows the driver to send the generated PS back to
+ * the client.
+ */
+
+int
+PsGetDocumentData(
+ XpContextPtr pCon,
+ ClientPtr client,
+ int maxBufferSize)
+{
+ PsContextPrivPtr pPriv = (PsContextPrivPtr)
+ pCon->devPrivates[PsContextPrivateIndex].ptr;
+
+ pPriv->getDocClient = client;
+ pPriv->getDocBufSize = maxBufferSize;
+
+ return Success;
+}
+
diff --git a/nx-X11/programs/Xserver/Xprint/ps/PsSpans.c b/nx-X11/programs/Xserver/Xprint/ps/PsSpans.c
new file mode 100644
index 000000000..d7652f8fb
--- /dev/null
+++ b/nx-X11/programs/Xserver/Xprint/ps/PsSpans.c
@@ -0,0 +1,166 @@
+/* $Xorg: PsSpans.c,v 1.4 2001/02/09 02:04:36 xorgcvs Exp $ */
+/*
+
+Copyright 1996, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+/*
+ * (c) Copyright 1996 Hewlett-Packard Company
+ * (c) Copyright 1996 International Business Machines Corp.
+ * (c) Copyright 1996 Sun Microsystems, Inc.
+ * (c) Copyright 1996 Novell, Inc.
+ * (c) Copyright 1996 Digital Equipment Corp.
+ * (c) Copyright 1996 Fujitsu Limited
+ * (c) Copyright 1996 Hitachi, Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject
+ * to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the names of the copyright holders
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * from said copyright holders.
+ */
+
+/*******************************************************************
+**
+** *********************************************************
+** *
+** * File: PsSpans.c
+** *
+** * Contents: Code to set and fill spans in the PS DDX
+** *
+** * Created By: Roger Helmendach (Liberty Systems)
+** *
+** * Copyright: Copyright 1996 The Open Group, Inc.
+** *
+** *********************************************************
+**
+********************************************************************/
+/* $XFree86: xc/programs/Xserver/Xprint/ps/PsSpans.c,v 1.8 2001/10/28 03:32:56 tsi Exp $ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include "Ps.h"
+#include "gcstruct.h"
+#include "windowstr.h"
+
+void
+PsFillSpans(
+ DrawablePtr pDrawable,
+ GCPtr pGC,
+ int nSpans,
+ DDXPointPtr pPoints,
+ int *pWidths,
+ int fSorted)
+{
+ PsOutPtr psOut;
+ int xoffset, yoffset;
+ xRectangle *rects, *r;
+ RegionPtr fillRegion, region = 0;
+ int i;
+ int nbox;
+ BoxPtr pbox;
+ ColormapPtr cMap;
+
+ if( PsUpdateDrawableGC(pGC, pDrawable, &psOut, &cMap)==FALSE ) return;
+
+ /*
+ * Build a region out of the spans
+ */
+ rects = (xRectangle *)xalloc(nSpans*sizeof(xRectangle));
+ xoffset = pDrawable->x;
+ yoffset = pDrawable->y;
+
+ for( i = 0, r = rects; i < nSpans; i++, r++ )
+ {
+ r->x = pPoints[i].x + xoffset;
+ r->y = pPoints[i].y + yoffset;
+ r->width = pWidths[i];
+ r->height = 1;
+ }
+ fillRegion = RECTS_TO_REGION(pGC->pScreen, nSpans, rects,
+ (fSorted)?CT_YSORTED:CT_UNSORTED);
+
+ /*
+ * Intersect this region with the clip region. Whatever's left,
+ * should be filled.
+ */
+/*REGION_INTERSECT(pGC->pScreen, region, fillRegion, pGC->clientClip);*/
+
+ pbox = REGION_RECTS(region);
+ nbox = REGION_NUM_RECTS(region);
+
+ /* Enter HP-GL/2 */
+ /*###SEND_PCL( outFile, "\27%0B" );*/
+
+ while( nbox )
+ {
+/*###
+ sprintf( t, "PU%d,%d;RR%d,%d;", pbox->x1, pbox->y1, pbox->x2, pbox->y2);
+ SEND_PCL( outFile, t );
+*/
+ nbox--;
+ pbox++;
+ }
+
+ /* Go back to PCL */
+ /*###SEND_PCL( outFile, "\27%0A" );*/
+
+ /*
+ * Clean up the temporary regions
+ */
+ REGION_DESTROY(pGC->pScreen, fillRegion);
+ REGION_DESTROY(pGC->pScreen, region);
+ xfree(rects);
+}
+
+void
+PsSetSpans(
+ DrawablePtr pDrawable,
+ GCPtr pGC,
+ char *pSrc,
+ DDXPointPtr pPoints,
+ int *pWidths,
+ int nSpans,
+ int fSorted)
+{
+}
diff --git a/nx-X11/programs/Xserver/Xprint/ps/PsText.c b/nx-X11/programs/Xserver/Xprint/ps/PsText.c
new file mode 100644
index 000000000..228e407dc
--- /dev/null
+++ b/nx-X11/programs/Xserver/Xprint/ps/PsText.c
@@ -0,0 +1,586 @@
+/* $Xorg: PsText.c,v 1.7 2001/02/09 02:04:36 xorgcvs Exp $ */
+/*
+
+Copyright 1996, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+/*
+ * (c) Copyright 1996 Hewlett-Packard Company
+ * (c) Copyright 1996 International Business Machines Corp.
+ * (c) Copyright 1996 Sun Microsystems, Inc.
+ * (c) Copyright 1996 Novell, Inc.
+ * (c) Copyright 1996 Digital Equipment Corp.
+ * (c) Copyright 1996 Fujitsu Limited
+ * (c) Copyright 1996 Hitachi, Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject
+ * to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the names of the copyright holders
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * from said copyright holders.
+ */
+
+/*******************************************************************
+**
+** *********************************************************
+** *
+** * File: PsText.c
+** *
+** * Contents: Character-drawing routines for the PS DDX
+** *
+** * Created By: Roger Helmendach (Liberty Systems)
+** *
+** * Copyright: Copyright 1996 The Open Group, Inc.
+** *
+** *********************************************************
+**
+********************************************************************/
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include "Ps.h"
+#include "gcstruct.h"
+#include "windowstr.h"
+#include <X11/fonts/fntfil.h>
+#include <X11/fonts/fntfilst.h>
+#include <limits.h>
+
+int
+PsPolyText8(
+ DrawablePtr pDrawable,
+ GCPtr pGC,
+ int x,
+ int y,
+ int count,
+ char *string)
+{
+ if( pDrawable->type==DRAWABLE_PIXMAP )
+ {
+ DisplayElmPtr elm;
+ PixmapPtr pix = (PixmapPtr)pDrawable;
+ PsPixmapPrivPtr priv = (PsPixmapPrivPtr)pix->devPrivate.ptr;
+ DisplayListPtr disp;
+ GCPtr gc;
+
+ if ((gc = PsCreateAndCopyGC(pDrawable, pGC)) == NULL) return x;
+
+ disp = PsGetFreeDisplayBlock(priv);
+
+ elm = &disp->elms[disp->nelms];
+ elm->type = Text8Cmd;
+ elm->gc = gc;
+ elm->c.text8.x = x;
+ elm->c.text8.y = y;
+ elm->c.text8.count = count;
+ elm->c.text8.string = (char *)xalloc(count);
+ memcpy(elm->c.text8.string, string, count);
+ disp->nelms += 1;
+
+ return x;
+ }
+ else
+ {
+ PsFontInfoRec *firec;
+
+ /* We need a context for rendering... */
+ if (PsGetPsContextPriv(pDrawable) == NULL)
+ return x;
+
+ firec = PsGetFontInfoRec(pDrawable, pGC->font);
+ if (!firec)
+ return x;
+
+#ifdef XP_USE_FREETYPE
+ if (firec->ftir->downloadableFont &&
+ (firec->ftir->font_type == PSFTI_FONT_TYPE_FREETYPE))
+ {
+ PsOutPtr psOut;
+ ColormapPtr cMap;
+
+ if( PsUpdateDrawableGC(pGC, pDrawable, &psOut, &cMap)==FALSE )
+ return x;
+
+ if (firec->ftir->alreadyDownloaded[0] == False)
+ {
+ PsOut_DownloadFreeType(psOut,
+ firec->ftir->ft_download_font_type,
+ firec->ftir->download_ps_name, pGC->font, 0);
+ firec->ftir->alreadyDownloaded[0] = True;
+ }
+
+ PsOut_Offset(psOut, pDrawable->x, pDrawable->y);
+ PsOut_Color(psOut, PsGetPixelColor(cMap, pGC->fgPixel));
+ if (!firec->size)
+ PsOut_TextAttrsMtx(psOut, firec->ftir->download_ps_name, firec->mtx, firec->ftir->is_iso_encoding);
+ else
+ PsOut_TextAttrs(psOut, firec->ftir->download_ps_name, firec->size, firec->ftir->is_iso_encoding);
+ PsOut_FreeType_Text(pGC->font, psOut, x, y, string, count);
+
+ return x;
+ }
+ else
+#endif /* XP_USE_FREETYPE */
+ if (firec->ftir->downloadableFont &&
+ (firec->ftir->font_type != PSFTI_FONT_TYPE_FREETYPE))
+ {
+ PsOutPtr psOut;
+ ColormapPtr cMap;
+
+ if( PsUpdateDrawableGC(pGC, pDrawable, &psOut, &cMap)==FALSE )
+ return x;
+
+ if (firec->ftir->alreadyDownloaded[0] == False)
+ {
+ PsOut_DownloadType1(psOut, "PsPolyText8",
+ firec->ftir->download_ps_name, firec->ftir->filename);
+ firec->ftir->alreadyDownloaded[0] = True;
+ }
+
+ PsOut_Offset(psOut, pDrawable->x, pDrawable->y);
+ PsOut_Color(psOut, PsGetPixelColor(cMap, pGC->fgPixel));
+ if (!firec->size)
+ PsOut_TextAttrsMtx(psOut, firec->ftir->download_ps_name, firec->mtx, firec->ftir->is_iso_encoding);
+ else
+ PsOut_TextAttrs(psOut, firec->ftir->download_ps_name, firec->size, firec->ftir->is_iso_encoding);
+ PsOut_Text(psOut, x, y, string, count, -1);
+
+ return x;
+ }
+
+ /* Render glyphs as bitmaps */
+ {
+ unsigned long n, i;
+ int w;
+ CharInfoPtr charinfo[255];
+
+ GetGlyphs(pGC->font, (unsigned long)count,
+ (unsigned char *)string, Linear8Bit, &n, charinfo);
+ w = 0;
+ for (i=0; i < n; i++)
+ w += charinfo[i]->metrics.characterWidth;
+
+ if (n != 0)
+ PsPolyGlyphBlt(pDrawable, pGC, x, y, n,
+ charinfo, FONTGLYPHS(pGC->font));
+ x += w;
+
+ return x;
+ }
+ }
+ return x;
+}
+
+int
+PsPolyText16(
+ DrawablePtr pDrawable,
+ GCPtr pGC,
+ int x,
+ int y,
+ int count,
+ unsigned short *string)
+{
+ if( pDrawable->type==DRAWABLE_PIXMAP )
+ {
+ DisplayElmPtr elm;
+ PixmapPtr pix = (PixmapPtr)pDrawable;
+ PsPixmapPrivPtr priv = (PsPixmapPrivPtr)pix->devPrivate.ptr;
+ DisplayListPtr disp;
+ GCPtr gc;
+
+ if ((gc = PsCreateAndCopyGC(pDrawable, pGC)) == NULL) return x;
+
+ disp = PsGetFreeDisplayBlock(priv);
+
+ elm = &disp->elms[disp->nelms];
+ elm->type = Text16Cmd;
+ elm->gc = gc;
+ elm->c.text16.x = x;
+ elm->c.text16.y = y;
+ elm->c.text16.count = count;
+ elm->c.text16.string =
+ (unsigned short *)xalloc(count*sizeof(unsigned short));
+ memcpy(elm->c.text16.string, string, count*sizeof(unsigned short));
+ disp->nelms += 1;
+
+ return x;
+ }
+ else
+ {
+ PsFontInfoRec *firec;
+
+ /* We need a context for rendering... */
+ if (PsGetPsContextPriv(pDrawable) == NULL)
+ return x;
+
+ firec = PsGetFontInfoRec(pDrawable, pGC->font);
+ if (!firec)
+ return x;
+
+#ifdef XP_USE_FREETYPE
+ if (firec->ftir->downloadableFont &&
+ (firec->ftir->font_type == PSFTI_FONT_TYPE_FREETYPE))
+ {
+ PsOutPtr psOut;
+ ColormapPtr cMap;
+ unsigned short c,
+ c_hiByte,
+ c_lowByte,
+ fontPage;
+ int i;
+
+ if( PsUpdateDrawableGC(pGC, pDrawable, &psOut, &cMap)==FALSE )
+ return x;
+
+ /* Scan the string we want to render and download all neccesary parts
+ * of the font (one part(="font page") has 256 glyphs)
+ */
+ for( i = 0 ; i < count ; i++ )
+ {
+ c = string[i];
+#if IMAGE_BYTE_ORDER == LSBFirst
+ c_hiByte = c & 0x00FF;
+ c_lowByte = (c >> 8) & 0x00FF;
+#elif IMAGE_BYTE_ORDER == MSBFirst
+ c_hiByte = (c >> 8) & 0x00FF;
+ c_lowByte = c & 0x00FF;
+#else
+#error Unsupported byte order
+#endif
+ fontPage = c_hiByte;
+
+ if (firec->ftir->alreadyDownloaded[fontPage] == False)
+ {
+ char buffer[256];
+ const char *ps_name;
+
+ if (fontPage > 0)
+ {
+ sprintf(buffer, "%s_%x", firec->ftir->download_ps_name, (int)fontPage);
+ ps_name = buffer;
+ }
+ else
+ {
+ ps_name = firec->ftir->download_ps_name;
+ }
+
+ PsOut_DownloadFreeType(psOut,
+ firec->ftir->ft_download_font_type,
+ ps_name, pGC->font, (fontPage * 0x100)); /* same as (fontPage << 8) */
+
+ firec->ftir->alreadyDownloaded[fontPage] = True;
+ }
+ }
+
+
+ PsOut_Offset(psOut, pDrawable->x, pDrawable->y);
+ PsOut_Color(psOut, PsGetPixelColor(cMap, pGC->fgPixel));
+ if (!firec->size)
+ PsOut_FreeType_TextAttrsMtx16(psOut, firec->ftir->download_ps_name, firec->mtx, firec->ftir->is_iso_encoding);
+ else
+ PsOut_FreeType_TextAttrs16(psOut, firec->ftir->download_ps_name, firec->size, firec->ftir->is_iso_encoding);
+ PsOut_FreeType_Text16(pGC->font, psOut, x, y, string, count);
+
+ return x;
+ }
+ else
+#endif /* XP_USE_FREETYPE */
+ if (firec->ftir->downloadableFont &&
+ (firec->ftir->font_type != PSFTI_FONT_TYPE_FREETYPE))
+ {
+ PsOutPtr psOut;
+ ColormapPtr cMap;
+ unsigned short c,
+ c_hiByte,
+ c_lowByte,
+ fontPage;
+ int i;
+
+ if( PsUpdateDrawableGC(pGC, pDrawable, &psOut, &cMap)==FALSE )
+ return x;
+
+ PsOut_DownloadType1(psOut, "PsPolyText16",
+ firec->ftir->download_ps_name, firec->ftir->filename);
+ firec->ftir->alreadyDownloaded[fontPage] = True;
+
+ PsOut_Offset(psOut, pDrawable->x, pDrawable->y);
+ PsOut_Color(psOut, PsGetPixelColor(cMap, pGC->fgPixel));
+ if (!firec->size)
+ PsOut_TextAttrsMtx(psOut, firec->ftir->download_ps_name, firec->mtx, firec->ftir->is_iso_encoding);
+ else
+ PsOut_TextAttrs(psOut, firec->ftir->download_ps_name, firec->size, firec->ftir->is_iso_encoding);
+ PsOut_Text16(psOut, x, y, string, count, -1);
+
+ return x;
+ }
+
+ /* Render glyphs as bitmaps */
+ {
+ unsigned long n, i;
+ int w;
+ CharInfoPtr charinfo[255]; /* encoding only has 1 byte for count */
+
+ GetGlyphs(pGC->font, (unsigned long)count, (unsigned char *)string,
+ (FONTLASTROW(pGC->font) == 0) ? Linear16Bit : TwoD16Bit,
+ &n, charinfo);
+ w = 0;
+ for (i=0; i < n; i++)
+ w += charinfo[i]->metrics.characterWidth;
+ if (n != 0)
+ PsPolyGlyphBlt(pDrawable, pGC, x, y, n, charinfo, FONTGLYPHS(pGC->font));
+ x += w;
+
+ return x;
+ }
+ }
+ return x;
+}
+
+void
+PsImageText8(
+ DrawablePtr pDrawable,
+ GCPtr pGC,
+ int x,
+ int y,
+ int count,
+ char *string)
+{
+ if( pDrawable->type==DRAWABLE_PIXMAP )
+ {
+ DisplayElmPtr elm;
+ PixmapPtr pix = (PixmapPtr)pDrawable;
+ PsPixmapPrivPtr priv = (PsPixmapPrivPtr)pix->devPrivate.ptr;
+ DisplayListPtr disp;
+ GCPtr gc;
+
+ if ((gc = PsCreateAndCopyGC(pDrawable, pGC)) == NULL) return;
+
+ disp = PsGetFreeDisplayBlock(priv);
+
+ elm = &disp->elms[disp->nelms];
+ elm->type = TextI8Cmd;
+ elm->gc = gc;
+ elm->c.text8.x = x;
+ elm->c.text8.y = y;
+ elm->c.text8.count = count;
+ elm->c.text8.string = (char *)xalloc(count);
+ memcpy(elm->c.text8.string, string, count);
+ disp->nelms += 1;
+ }
+ else
+ {
+ int iso;
+ int siz;
+ float mtx[4];
+ char *fnam;
+ PsOutPtr psOut;
+ ColormapPtr cMap;
+
+ if( PsUpdateDrawableGC(pGC, pDrawable, &psOut, &cMap)==FALSE ) return;
+ PsOut_Offset(psOut, pDrawable->x, pDrawable->y);
+ PsOut_Color(psOut, PsGetPixelColor(cMap, pGC->fgPixel));
+ fnam = PsGetPSFontName(pGC->font);
+ if( !fnam ) fnam = "Times-Roman";
+ siz = PsGetFontSize(pGC->font, mtx);
+ iso = PsIsISOLatin1Encoding(pGC->font);
+ if( !siz ) PsOut_TextAttrsMtx(psOut, fnam, mtx, iso);
+ else PsOut_TextAttrs(psOut, fnam, siz, iso);
+ PsOut_Text(psOut, x, y, string, count, PsGetPixelColor(cMap, pGC->bgPixel));
+ }
+}
+
+void
+PsImageText16(
+ DrawablePtr pDrawable,
+ GCPtr pGC,
+ int x,
+ int y,
+ int count,
+ unsigned short *string)
+{
+ if( pDrawable->type==DRAWABLE_PIXMAP )
+ {
+ DisplayElmPtr elm;
+ PixmapPtr pix = (PixmapPtr)pDrawable;
+ PsPixmapPrivPtr priv = (PsPixmapPrivPtr)pix->devPrivate.ptr;
+ DisplayListPtr disp;
+ GCPtr gc;
+
+ if ((gc = PsCreateAndCopyGC(pDrawable, pGC)) == NULL) return;
+
+ disp = PsGetFreeDisplayBlock(priv);
+
+ elm = &disp->elms[disp->nelms];
+ elm->type = TextI16Cmd;
+ elm->gc = gc;
+ elm->c.text16.x = x;
+ elm->c.text16.y = y;
+ elm->c.text16.count = count;
+ elm->c.text16.string =
+ (unsigned short *)xalloc(count*sizeof(unsigned short));
+ memcpy(elm->c.text16.string, string, count*sizeof(unsigned short));
+ disp->nelms += 1;
+ }
+ else
+ {
+ int i;
+ char *str;
+ if( !count ) return;
+ str = (char *)xalloc(count);
+ for( i=0 ; i<count ; i++ ) str[i] = string[i];
+ PsImageText8(pDrawable, pGC, x, y, count, str);
+ free(str);
+ }
+}
+
+void
+PsImageGlyphBlt(
+ DrawablePtr pDrawable,
+ GCPtr pGC,
+ int x,
+ int y,
+ unsigned int nGlyphs,
+ CharInfoPtr *pCharInfo,
+ pointer pGlyphBase)
+{
+ /* NOT TO BE IMPLEMENTED */
+}
+
+void
+PsPolyGlyphBlt(
+ DrawablePtr pDrawable,
+ GCPtr pGC,
+ int x,
+ int y,
+ unsigned int nGlyphs,
+ CharInfoPtr *pCharInfo,
+ pointer pGlyphBase)
+{
+ int width, height;
+ PixmapPtr pPixmap;
+ int nbyLine; /* bytes per line of padded pixmap */
+ FontPtr pfont;
+ GCPtr pGCtmp;
+ register int i;
+ register int j;
+ unsigned char *pbits; /* buffer for PutImage */
+ register unsigned char *pb; /* temp pointer into buffer */
+ register CharInfoPtr pci; /* currect char info */
+ register unsigned char *pglyph; /* pointer bits in glyph */
+ int gWidth, gHeight; /* width and height of glyph */
+ register int nbyGlyphWidth; /* bytes per scanline of glyph */
+ int nbyPadGlyph; /* server padded line of glyph */
+ int w, tmpx;
+ XID gcvals[3];
+
+ pfont = pGC->font;
+ width = FONTMAXBOUNDS(pfont,rightSideBearing) -
+ FONTMINBOUNDS(pfont,leftSideBearing);
+ height = FONTMAXBOUNDS(pfont,ascent) +
+ FONTMAXBOUNDS(pfont,descent);
+
+ if ((width == 0) || (height == 0) )
+ return;
+ {
+ int i;
+ w = 0;
+ for (i=0; i < nGlyphs; i++) w += pCharInfo[i]->metrics.characterWidth;
+ }
+ pGCtmp = GetScratchGC(1, pDrawable->pScreen);
+ if (!pGCtmp)
+ {
+ (*pDrawable->pScreen->DestroyPixmap)(pPixmap);
+ return;
+ }
+
+ gcvals[0] = GXcopy;
+ gcvals[1] = pGC->fgPixel;
+ gcvals[2] = pGC->bgPixel;
+
+ DoChangeGC(pGCtmp, GCFunction|GCForeground|GCBackground, gcvals, 0);
+
+
+ nbyLine = BitmapBytePad(width);
+ pbits = (unsigned char *)ALLOCATE_LOCAL(height*nbyLine);
+ if (!pbits){
+ PsDestroyPixmap(pPixmap);
+ return;
+ }
+ tmpx = 0;
+ while(nGlyphs--)
+ {
+ pci = *pCharInfo++;
+ pglyph = FONTGLYPHBITS(pGlyphBase, pci);
+ gWidth = GLYPHWIDTHPIXELS(pci);
+ gHeight = GLYPHHEIGHTPIXELS(pci);
+ if (gWidth && gHeight)
+ {
+ nbyGlyphWidth = GLYPHWIDTHBYTESPADDED(pci);
+ nbyPadGlyph = BitmapBytePad(gWidth);
+
+ if (nbyGlyphWidth == nbyPadGlyph
+#if GLYPHPADBYTES != 4
+ && (((int) pglyph) & 3) == 0
+#endif
+ )
+ {
+ pb = pglyph;
+ }
+ else
+ {
+ for (i=0, pb = pbits; i<gHeight; i++, pb = pbits+(i*nbyPadGlyph))
+ for (j = 0; j < nbyGlyphWidth; j++)
+ *pb++ = *pglyph++;
+ pb = pbits;
+ }
+
+ PsPutImageMask((DrawablePtr)pDrawable, pGCtmp,
+ 1, x + pci->metrics.leftSideBearing,
+ y - pci->metrics.ascent, gWidth, gHeight,
+ 0, XYBitmap, (char *)pb);
+ }
+
+ x += pci->metrics.characterWidth;
+ }
+ DEALLOCATE_LOCAL(pbits);
+ FreeScratchGC(pGCtmp);
+}
diff --git a/nx-X11/programs/Xserver/Xprint/ps/PsWindow.c b/nx-X11/programs/Xserver/Xprint/ps/PsWindow.c
new file mode 100644
index 000000000..313e51f31
--- /dev/null
+++ b/nx-X11/programs/Xserver/Xprint/ps/PsWindow.c
@@ -0,0 +1,462 @@
+/* $Xorg: PsWindow.c,v 1.4 2001/02/09 02:04:36 xorgcvs Exp $ */
+/*
+
+Copyright 1996, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+/*
+ * (c) Copyright 1996 Hewlett-Packard Company
+ * (c) Copyright 1996 International Business Machines Corp.
+ * (c) Copyright 1996 Sun Microsystems, Inc.
+ * (c) Copyright 1996 Novell, Inc.
+ * (c) Copyright 1996 Digital Equipment Corp.
+ * (c) Copyright 1996 Fujitsu Limited
+ * (c) Copyright 1996 Hitachi, Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject
+ * to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the names of the copyright holders
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * from said copyright holders.
+ */
+
+/*******************************************************************
+**
+** *********************************************************
+** *
+** * File: PsWindow.c
+** *
+** * Contents: Window code for PS driver.
+** *
+** * Created By: Roger Helmendach (Liberty Systems)
+** *
+** * Copyright: Copyright 1996 The Open Group, Inc.
+** *
+** *********************************************************
+**
+********************************************************************/
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <sys/wait.h>
+
+#include "mistruct.h"
+#include "regionstr.h"
+#include "windowstr.h"
+#include "gcstruct.h"
+
+#include "Ps.h"
+
+extern WindowPtr *WindowTable;
+
+/*
+ * The following list of strings defines the properties which will be
+ * placed on the screen's root window if the property was defined in
+ * the start-up configuration resource database.
+ */
+static char *propStrings[] = {
+ DT_PRINT_JOB_HEADER,
+ DT_PRINT_JOB_TRAILER,
+ DT_PRINT_JOB_COMMAND,
+ DT_PRINT_JOB_EXEC_COMMAND,
+ DT_PRINT_JOB_EXEC_OPTIONS,
+ DT_PRINT_PAGE_HEADER,
+ DT_PRINT_PAGE_TRAILER,
+ DT_PRINT_PAGE_COMMAND,
+ (char *)NULL
+};
+
+
+/*
+ * PsCreateWindow - watch for the creation of the root window.
+ * When it's created, register the screen with the print extension,
+ * and put the default command/header properties on it.
+ */
+/*ARGSUSED*/
+
+Bool
+PsCreateWindow(WindowPtr pWin)
+{
+ PsWindowPrivPtr pPriv;
+
+#if 0
+ Bool status = Success;
+ ScreenPtr pScreen = pWin->drawable.pScreen;
+ PsScreenPrivPtr pScreenPriv = (PsScreenPrivPtr)
+ pScreen->devPrivates[PsScreenPrivateIndex].ptr;
+ PsWindowPrivPtr pWinPriv = (PsWindowPrivPtr)
+ pWin->devPrivates[PsWindowPrivateIndex].ptr;
+
+ /*
+ * Initialize this window's private struct.
+ */
+ pWinPriv->jobFileName = (char *)NULL;
+ pWinPriv->pJobFile = (FILE *)NULL;
+ pWinPriv->pageFileName = (char *)NULL;
+ pWinPriv->pPageFile = (FILE *)NULL;
+
+ if(pWin->parent == (WindowPtr)NULL) /* root window? */
+ {
+ Atom propName; /* type = XA_STRING */
+ char *propVal;
+ int i;
+ XrmDatabase rmdb = pScreenPriv->resDB;
+
+ /*
+ * Put the defaults spec'd in the config files in properties on this
+ * screen's root window.
+ */
+ for(i = 0; propStrings[i] != (char *)NULL; i++)
+ {
+ if((propVal = _DtPrintGetPrinterResource(pWin, rmdb,
+ propStrings[i])) !=
+ (char *)NULL)
+ {
+ propName = MakeAtom(propStrings[i], strlen(propStrings[i]),
+ TRUE);
+ ChangeWindowProperty(pWin, propName, XA_STRING, 8,
+ PropModeReplace, strlen(propVal),
+ (pointer)propVal, FALSE);
+ xfree(propVal);
+ }
+ }
+ }
+
+ return status;
+#endif
+
+ pPriv = (PsWindowPrivPtr)pWin->devPrivates[PsWindowPrivateIndex].ptr;
+ pPriv->validContext = 0;
+
+ return TRUE;
+}
+
+
+/*ARGSUSED*/
+Bool PsMapWindow(WindowPtr pWindow)
+{
+ return TRUE;
+}
+
+/*ARGSUSED*/
+Bool
+PsPositionWindow(
+ WindowPtr pWin,
+ int x,
+ int y)
+{
+ return TRUE;
+}
+
+/*ARGSUSED*/
+Bool
+PsUnmapWindow(WindowPtr pWindow)
+{
+ return TRUE;
+}
+
+/*ARGSUSED*/
+void
+PsCopyWindow(
+ WindowPtr pWin,
+ DDXPointRec ptOldOrg,
+ RegionPtr prgnSrc)
+{
+}
+
+/*ARGSUSED*/
+Bool
+PsChangeWindowAttributes(
+ WindowPtr pWin,
+ unsigned long mask)
+{
+ return TRUE;
+}
+
+
+void
+PsPaintWindow(
+ WindowPtr pWin,
+ RegionPtr pRegion,
+ int what)
+{
+ int status;
+ WindowPtr pRoot;
+
+#define FUNCTION 0
+#define FOREGROUND 1
+#define TILE 2
+#define FILLSTYLE 3
+#define ABSX 4
+#define ABSY 5
+#define CLIPMASK 6
+#define SUBWINDOW 7
+#define COUNT_BITS 8
+
+ pointer gcval[7];
+ pointer newValues [COUNT_BITS];
+
+ BITS32 gcmask, index, mask;
+ RegionRec prgnWin;
+ DDXPointRec oldCorner;
+ BoxRec box;
+ WindowPtr pBgWin;
+ GCPtr pGC;
+ register int i;
+ register BoxPtr pbox;
+ register ScreenPtr pScreen = pWin->drawable.pScreen;
+ register xRectangle *prect;
+ int numRects;
+
+ gcmask = 0;
+
+ /*
+ * We don't want to paint a window that has no place to put the
+ * PS output.
+ */
+ if( PsGetContextFromWindow(pWin)==(XpContextPtr)NULL ) return;
+
+ if( what==PW_BACKGROUND )
+ {
+ switch(pWin->backgroundState)
+ {
+ case None: return;
+ case ParentRelative:
+ (*pWin->parent->drawable.pScreen->PaintWindowBackground)
+ (pWin->parent, pRegion, what);
+ return;
+ case BackgroundPixel:
+ newValues[FOREGROUND] = (pointer)pWin->background.pixel;
+ newValues[FILLSTYLE] = (pointer)FillSolid;
+ gcmask |= GCForeground | GCFillStyle;
+ break;
+ case BackgroundPixmap:
+ newValues[TILE] = (pointer)pWin->background.pixmap;
+ newValues[FILLSTYLE] = (pointer)FillTiled;
+ gcmask |= GCTile | GCFillStyle | GCTileStipXOrigin | GCTileStipYOrigin;
+ break;
+ }
+ }
+ else
+ {
+ if( pWin->borderIsPixel )
+ {
+ newValues[FOREGROUND] = (pointer)pWin->border.pixel;
+ newValues[FILLSTYLE] = (pointer)FillSolid;
+ gcmask |= GCForeground | GCFillStyle;
+ }
+ else
+ {
+ newValues[TILE] = (pointer)pWin->border.pixmap;
+ newValues[FILLSTYLE] = (pointer)FillTiled;
+ gcmask |= GCTile | GCFillStyle | GCTileStipXOrigin | GCTileStipYOrigin;
+ }
+ }
+
+ prect = (xRectangle *)ALLOCATE_LOCAL(REGION_NUM_RECTS(pRegion) *
+ sizeof(xRectangle));
+ if( !prect ) return;
+
+ newValues[FUNCTION] = (pointer)GXcopy;
+ gcmask |= GCFunction | GCClipMask;
+
+ i = pScreen->myNum;
+ pRoot = WindowTable[i];
+
+ pBgWin = pWin;
+ if (what == PW_BORDER)
+ {
+ while( pBgWin->backgroundState==ParentRelative ) pBgWin = pBgWin->parent;
+ }
+
+ pGC = GetScratchGC(pWin->drawable.depth, pWin->drawable.pScreen);
+ if( !pGC )
+ {
+ DEALLOCATE_LOCAL(prect);
+ return;
+ }
+ /*
+ * mash the clip list so we can paint the border by
+ * mangling the window in place, pretending it
+ * spans the entire screen
+ */
+ if( what==PW_BORDER )
+ {
+ prgnWin = pWin->clipList;
+ oldCorner.x = pWin->drawable.x;
+ oldCorner.y = pWin->drawable.y;
+ pWin->drawable.x = pWin->drawable.y = 0;
+ box.x1 = 0;
+ box.y1 = 0;
+ box.x2 = pScreen->width;
+ box.y2 = pScreen->height;
+ REGION_INIT(pScreen, &pWin->clipList, &box, 1);
+ pWin->drawable.serialNumber = NEXT_SERIAL_NUMBER;
+ newValues[ABSX] = (pointer)(long)pBgWin->drawable.x;
+ newValues[ABSY] = (pointer)(long)pBgWin->drawable.y;
+ }
+ else
+ {
+ newValues[ABSX] = (pointer)0;
+ newValues[ABSY] = (pointer)0;
+ }
+
+/*
+ * XXX Backing store is turned off for the PS driver
+
+ if( pWin->backStorage )
+ (*pWin->drawable.pScreen->DrawGuarantee) (pWin, pGC, GuaranteeVisBack);
+ */
+
+ mask = gcmask;
+ gcmask = 0;
+ i = 0;
+ while( mask )
+ {
+ index = lowbit (mask);
+ mask &= ~index;
+ switch(index)
+ {
+ case GCFunction:
+ if( (pointer)(long)pGC->alu!=newValues[FUNCTION] )
+ {
+ gcmask |= index;
+ gcval[i++] = newValues[FUNCTION];
+ }
+ break;
+ case GCTileStipXOrigin:
+ if( (pointer)(long)pGC->patOrg.x!=newValues[ABSX] )
+ {
+ gcmask |= index;
+ gcval[i++] = newValues[ABSX];
+ }
+ break;
+ case GCTileStipYOrigin:
+ if( (pointer)(long)pGC->patOrg.y!=newValues[ABSY] )
+ {
+ gcmask |= index;
+ gcval[i++] = newValues[ABSY];
+ }
+ break;
+ case GCClipMask:
+ if( (pointer)pGC->clientClipType!=(pointer)CT_NONE )
+ {
+ gcmask |= index;
+ gcval[i++] = (pointer)CT_NONE;
+ }
+ break;
+ case GCSubwindowMode:
+ if( (pointer)pGC->subWindowMode!=newValues[SUBWINDOW] )
+ {
+ gcmask |= index;
+ gcval[i++] = newValues[SUBWINDOW];
+ }
+ break;
+ case GCTile:
+ if( pGC->tileIsPixel || (pointer)pGC->tile.pixmap!=newValues[TILE] )
+ {
+ gcmask |= index;
+ gcval[i++] = newValues[TILE];
+ }
+ break;
+ case GCFillStyle:
+ if( (pointer)pGC->fillStyle!=newValues[FILLSTYLE] )
+ {
+ gcmask |= index;
+ gcval[i++] = newValues[FILLSTYLE];
+ }
+ break;
+ case GCForeground:
+ if( (pointer)pGC->fgPixel!=newValues[FOREGROUND] )
+ {
+ gcmask |= index;
+ gcval[i++] = newValues[FOREGROUND];
+ }
+ break;
+ }
+ }
+
+ if( gcmask ) DoChangeGC(pGC, gcmask, (XID *)gcval, 1);
+
+ if( pWin->drawable.serialNumber!=pGC->serialNumber )
+ ValidateGC((DrawablePtr)pWin, pGC);
+
+ numRects = REGION_NUM_RECTS(pRegion);
+ pbox = REGION_RECTS(pRegion);
+ for( i=numRects ; --i >= 0 ; pbox++,prect++ )
+ {
+ prect->x = pbox->x1 - pWin->drawable.x;
+ prect->y = pbox->y1 - pWin->drawable.y;
+ prect->width = pbox->x2 - pbox->x1;
+ prect->height = pbox->y2 - pbox->y1;
+ }
+ prect -= numRects;
+ (*pGC->ops->PolyFillRect)((DrawablePtr)pWin, pGC, numRects, prect);
+ DEALLOCATE_LOCAL(prect);
+
+/*
+ * XXX Backing store is turned off for the PS driver
+
+ if( pWin->backStorage )
+ (*pWin->drawable.pScreen->DrawGuarantee) (pWin, pGC, GuaranteeNothing);
+ */
+
+ if( what==PW_BORDER )
+ {
+ REGION_UNINIT(pScreen, &pWin->clipList);
+ pWin->clipList = prgnWin;
+ pWin->drawable.x = oldCorner.x;
+ pWin->drawable.y = oldCorner.y;
+ pWin->drawable.serialNumber = NEXT_SERIAL_NUMBER;
+ }
+ FreeScratchGC(pGC);
+}
+
+/*ARGSUSED*/
+Bool
+PsDestroyWindow(WindowPtr pWin)
+{
+ return TRUE;
+}
diff --git a/nx-X11/programs/Xserver/Xprint/ps/psout.c b/nx-X11/programs/Xserver/Xprint/ps/psout.c
new file mode 100644
index 000000000..376feec03
--- /dev/null
+++ b/nx-X11/programs/Xserver/Xprint/ps/psout.c
@@ -0,0 +1,1792 @@
+/* $Xorg: psout.c,v 1.9 2001/03/26 15:25:12 coskrey Exp $ */
+/*
+
+Copyright 1996, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+/*
+ * (c) Copyright 1996 Hewlett-Packard Company
+ * (c) Copyright 1996 International Business Machines Corp.
+ * (c) Copyright 1996, 2000 Sun Microsystems, Inc. All Rights Reserved.
+ * (c) Copyright 1996 Novell, Inc.
+ * (c) Copyright 1996 Digital Equipment Corp.
+ * (c) Copyright 1996 Fujitsu Limited
+ * (c) Copyright 1996 Hitachi, Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject
+ * to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the names of the copyright holders
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * from said copyright holders.
+ */
+
+/*******************************************************************
+**
+** *********************************************************
+** *
+** * File: psout.c
+** *
+** * Contents: Code to output PostScript to file
+** *
+** * Created By: Roger Helmendach (Liberty Systems)
+** *
+** * Copyright: Copyright 1996 The Open Group, Inc.
+** *
+** *********************************************************
+**
+********************************************************************/
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+#include "os.h"
+#define USE_PSOUT_PRIVATE 1
+#include "psout.h"
+#ifdef XP_USE_FREETYPE
+#include <ft2build.h>
+#include FT_FREETYPE_H
+#endif /* XP_USE_FREETYPE */
+/* For VENDOR_STRING and VENDOR_RELEASE */
+#include "site.h"
+
+extern PsElmPtr PsCloneFillElementList(int nElms, PsElmPtr elms);
+extern void PsDestroyFillElementList(int nElms, PsElmPtr elms);
+
+/*
+ * Standard definitions
+ */
+
+static char *S_StandardDefs = "\
+/d{def}bind def\
+/b{bind}bind d\
+/bd{b d}b d\
+/x{exch}bd\
+/xd{x d}bd\
+/dp{dup}bd\
+/t{true}bd\
+/f{false}bd\
+/p{pop}bd\
+/r{roll}bd\
+/c{copy}bd\
+/i{index}bd\
+/rp{repeat}bd\
+/n{newpath}bd\
+/w{setlinewidth}bd\
+/lc{setlinecap}bd\
+/lj{setlinejoin}bd\
+/sml{setmiterlimit}bd\
+/ds{setdash}bd\
+/ie{ifelse}bd\
+/len{length}bd\
+/m{moveto}bd\
+/rm{rmoveto}bd\
+/l{lineto}bd\
+/rl{rlineto}bd\
+/a{arc}bd\
+/an{arcn}bd\
+/st{stroke}bd\
+/fl{fill}bd\
+/ef{eofill}bd\
+/sp{showpage}bd\
+/cp{closepath}bd\
+/clp{clippath}bd\
+/cl{clip}bd\
+/pb{pathbbox}bd\
+/tr{translate}bd\
+/rt{rotate}bd\
+/dv{div}bd\
+/ml{mul}bd\
+/ad{add}bd\
+/ng{neg}bd\
+/scl{scale}bd\
+/sc{setrgbcolor}bd\
+/g{setgray}bd\
+/gs{gsave}bd\
+/gr{grestore}bd\
+/sv{save}bd\
+/rs{restore}bd\
+/mx{matrix}bd\
+/cm{currentmatrix}bd\
+/sm{setmatrix}bd\
+/ccm{concatmatrix}bd\
+/cc{concat}bd\
+/ff{findfont}bd\
+/mf{makefont}bd\
+/sf{setfont}bd\
+/cft{currentfont}bd\
+/fd{FontDirectory}bd\
+/sh{show}bd\
+/stw{stringwidth}bd\
+/ci{colorimage}bd\
+/ig{image}bd\
+/im{imagemask}bd\
+/cf{currentfile}bd\
+/rh{readhexstring}bd\
+/str{string}bd\
+/al{aload}bd\
+/wh{where}bd\
+/kn{known}bd\
+/stp{stopped}bd\
+/bg{begin}bd\
+/ed{end}bd\
+/fa{forall}bd\
+/pi{putinterval}bd\
+/mk{mark}bd\
+/ctm{cleartomark}bd\
+/df{definefont}bd\
+/cd{currentdict}bd\
+/db{20 dict dp bg}bd\
+/de{ed}bd\
+/languagelevel wh{p languagelevel}{1}ie\
+ 1 eq{/makepattern{p}bd/setpattern{p}bd/setpagedevice{p}bd}if\
+/mp{makepattern}bd\
+/spt{setpattern}bd\
+/spd{setpagedevice}bd\
+"
+#ifdef XP_USE_FREETYPE
+"/trmoveto{currentfont /FontMatrix get transform rm}d"
+#endif /* XP_USE_FREETYPE */
+;
+
+/*
+ * Composite definitions
+ *
+ *
+ * XYr - Return X/Y dpi for device
+ *
+ * XYr <xdpi> <ydpi>
+ *
+ * Cs - Coordinate setup (for origin upper left)
+ *
+ * <orient(0,1,2,3)> Cs
+ *
+ * P - Draw a point
+ *
+ * <x> <y> P
+ *
+ * R - Add rectangle to path
+ *
+ * <x> <y> <w> <h> R
+ *
+ * Ac - Add arc to path
+ *
+ * <x> <y> <w> <h> <ang1> <ang2> Ac
+ *
+ * An - Add arc to path (counterclockwise)
+ *
+ * <x> <y> <w> <h> <ang1> <ang2> An
+ *
+ * Tf - Set font
+ *
+ * <font_name> <size> <iso> Tf
+ *
+ * Tfm - Set font with matrix
+ *
+ * <font_name> <matrix> <iso> Tfm
+ *
+ * T - Draw text
+ *
+ * <text> <x> <y> T
+ *
+ * Tb - Draw text with background color
+ *
+ * <text> <x> <y> <bg_red> <bg_green> <bg_blue> Tb
+ *
+ * Im1 - Image 1 bit monochrome imagemask
+ *
+ * <x> <y> <w> <h> <sw> <sh> Im1
+ *
+ * Im24 - Image 24 bit RGB color
+ *
+ * <x> <y> <w> <h> <sw> <sh> Im24
+ *
+ * Im1t - Image 1 bit monochrome imagemask (in tile)
+ *
+ * <data> <x> <y> <w> <h> <sw> <sh> Im1t
+ *
+ * Im24t - Image 24 bit RGB color (in tile)
+ *
+ * <data> <x> <y> <w> <h> <sw> <sh> Im24t
+ */
+
+static char *S_CompositeDefs = "\
+/XYr{/currentpagedevice wh\
+ {p currentpagedevice dp /HWResolution kn\
+ {/HWResolution get al p}{p 300 300}ie}{300 300}ie}bd\
+/Cs{dp 0 eq{0 pHt tr XYr -1 x dv 72 ml x 1 x dv 72 ml x scl}if\
+ dp 1 eq{90 rt XYr -1 x dv 72 ml x 1 x dv 72 ml x scl}if\
+ dp 2 eq{pWd 0 tr XYr 1 x dv 72 ml x -1 x dv 72 ml x scl}if\
+ 3 eq{pHt pWd tr 90 rt XYr 1 x dv 72 ml x -1 x dv 72 ml x scl}if}bd\
+/P{gs 1 w [] 0 ds 2 c m .1 ad x .1 ad x l st gr}bd\
+/R{4 2 r m 1 i 0 rl 0 x rl ng 0 rl cp}bd\
+/Ac{mx_ cm p 6 -2 r tr 4 2 r ng scl 0 0 .5 5 3 r a mx_ sm}bd\
+/An{mx_ cm p 6 -2 r tr 4 2 r ng scl 0 0 .5 5 3 r an mx_ sm}bd\
+/ISO{dp len dict bg{1 i/FID ne{d}{p p}ie}fa\
+ /Encoding ISOLatin1Encoding d cd ed df}bd\
+/iN{dp len str cvs dp len x 1 i 3 ad str 2 c c p x p dp 3 -1 r(ISO)pi}bd\
+/Tp{{x dp iN dp fd x kn{x p dp/f_ x d ff}{dp/f_ x d x ff ISO}ie x}\
+ {x dp/f_ x d ff x}ie}bd\
+/Tf{Tp[x 0 0 2 i ng 0 0] dp/fm_ x d mf sf}bd\
+/Tfm{Tp 1 -1 tm1_ scl tm2_ ccm dp/fm_ x d mf sf}bd\
+/T{m sh}bd\
+/Tb{gs sc f_ ff sf cft/FontMatrix get 3 get\
+ cft/FontBBox get dp 1 get x 3 get 2 i ml 3 1 r ml\
+ 0 0 m 4 i stw p 4 i 4 i m fm_ cc\
+ 0 2 i rl dp 0 rl 0 2 i ng rl 0 3 i rl ng 0 rl cp fl p p\
+ gr T}bd\
+/Im1{6 4 r tr scl t [3 i 0 0 5 i 0 0]{cf str1 rh p} im}bd\
+/Im1rev{6 4 r tr scl f [3 i 0 0 5 i 0 0]{cf str1 rh p} im}bd\
+/Im24{gs 6 4 r tr scl 8 [3 i 0 0 5 i 0 0]{cf str3 rh p} f 3 ci}bd\
+/Im1t{6 4 r tr scl t [3 i 0 0 5 i 0 0]{} im}bd\
+/Im24t{gs 6 4 r tr scl 8 [3 i 0 0 5 i 0 0]{} f 3 ci}bd\
+/ck2{/currentpagedevice wh \
+{p dp currentpagedevice dp 3 -1 r kn \
+{x get al p 3 -1 r eq 3 1 r eq and } \
+{p p p p t}ie} \
+{p p p t}ie}bd \
+/ck1{/currentpagedevice wh \
+{p dp currentpagedevice dp 3 -1 r kn \
+{x get eq} {p p p t}ie} \
+{p p t}ie}bd \
+/mtx{scl t [3 i 0 0 5 i 0 0]}bd \
+";
+
+char *pg_orient[] = {"Portrait","Landscape","Reverse Portrait","Reverse Landscape"};
+/*
+ * Setup definitions
+ */
+
+static char *S_SetupDefs = "\
+ /mx_ mx d\
+ /im_ mx d\
+ /tm1_ mx d\
+ /tm2_ mx d\
+ /str3 3 str d\
+ /str1 1 str d\
+";
+
+/*******************************************************************
+ * PRIVATE FUNCTIONS *
+ *******************************************************************/
+
+void
+S_Flush(PsOutPtr self)
+{
+ int len;
+
+ if( self->Buf[0] == '\0' )
+ return;
+
+ len = strlen(self->Buf);
+
+ /* Append a newline char ('\n') if there isn't one there already */
+ if( self->Buf[len-1] != '\n' )
+ {
+ self->Buf[len++] = '\n';
+ self->Buf[len] = '\0';
+ }
+
+ (void)fwrite(self->Buf, len, 1, self->Fp);
+
+ self->Buf[0] = '\0';
+}
+
+static void
+S_Comment(PsOutPtr self, char *comment)
+{
+ S_Flush(self);
+ strcpy(self->Buf, comment);
+ S_Flush(self);
+}
+
+static void
+S_OutDefs(PsOutPtr self, char *defs)
+{
+ int i, k=0;
+ S_Flush(self);
+ memset(self->Buf, 0, sizeof(self->Buf));
+ for( i=0 ; defs[i]!='\0' ;)
+ {
+ if( k>70 && (i==0 || (i && defs[i-1]!='/')) &&
+ (defs[i]==' ' || defs[i]=='/' || defs[i]=='{') )
+ {
+ S_Flush(self);
+ k = 0;
+ memset(self->Buf, 0, sizeof(self->Buf));
+ }
+ if( k && self->Buf[k-1]==' ' && defs[i]==' ' ) { i++; continue; }
+ self->Buf[k] = defs[i];
+ k++; i++;
+ }
+ S_Flush(self);
+}
+
+void
+S_OutNum(PsOutPtr self, float num)
+{
+ int i;
+ char buf[64];
+ int len;
+
+ sprintf(buf, "%.3f", num);
+
+ /* Remove any zeros at the end */
+ for( i=strlen(buf)-1 ; buf[i]=='0' ; i-- ); buf[i+1] = '\0';
+ /* Remove '.' if it is the last character */
+ i = strlen(buf)-1; if( buf[i]=='.' ) buf[i] = '\0';
+
+ len = strlen(self->Buf);
+ if( len > 0 )
+ {
+ self->Buf[len++] = ' ';
+ self->Buf[len] = '\0';
+ }
+ strcpy(&self->Buf[len], buf);
+ if( (len+i)>70 ) S_Flush(self);
+}
+
+static void
+S_OutStr(PsOutPtr self, char *txt, int txtl)
+{
+ int i, k;
+ char buf[1024];
+ for( i=0,k=0 ; i<txtl ; i++ )
+ {
+ if( (txt[i]>=' ' && txt[i]<='~') &&
+ txt[i]!='(' && txt[i]!=')' && txt[i]!='\\' )
+ { buf[k] = txt[i]; k++; continue; }
+ buf[k] = '\\'; k++;
+ sprintf(&buf[k], "%03o", txt[i]&0xFF);
+ /* Skip to the end of the buffer */
+ while( buf[k] != '\0' )
+ k++;
+ }
+ strcat(self->Buf, "(");
+ i = strlen(self->Buf);
+ memcpy(&self->Buf[i], buf, k);
+ self->Buf[i+k] = '\0';
+ strcat(self->Buf, ")");
+ if( strlen(self->Buf)>70 ) S_Flush(self);
+}
+
+/* Same as S_OutStr() but takes |short *| instead of |char *| */
+static void
+S_OutStr16(PsOutPtr self, unsigned short *txt, int txtl)
+{
+ int i, k;
+ char buf[2048];
+ for( i=0,k=0 ; i<txtl ; i++ )
+ {
+ if( (txt[i]>=' ' && txt[i]<='~') &&
+ txt[i]!='(' && txt[i]!=')' && txt[i]!='\\' )
+ { buf[k] = txt[i]; k++; continue; }
+ buf[k] = '\\'; k++;
+ sprintf(&buf[k], "%03o", txt[i]&0xFFFF);
+ /* Skip to the end of the buffer */
+ while( buf[k] != '\0' )
+ k++;
+ }
+ strcat(self->Buf, "(");
+ i = strlen(self->Buf);
+ memcpy(&self->Buf[i], buf, k);
+ self->Buf[i+k] = '\0';
+ strcat(self->Buf, ")");
+ if( strlen(self->Buf)>70 ) S_Flush(self);
+}
+
+void
+S_OutTok(PsOutPtr self, char *tok, int cr)
+{
+ int len = strlen(self->Buf);
+ if( len > 0 )
+ {
+ self->Buf[len++] = ' ';
+ self->Buf[len] = '\0';
+ }
+ strcpy(&self->Buf[len], tok);
+ if( cr ) S_Flush(self);
+}
+
+static void
+S_Color(PsOutPtr self, PsOutColor clr)
+{
+ int ir, ig, ib;
+ ir = PSOUTCOLOR_TO_REDBITS(clr);
+ ig = PSOUTCOLOR_TO_GREENBITS(clr);
+ ib = PSOUTCOLOR_TO_BLUEBITS(clr);
+ if( ir==ig && ig==ib )
+ { S_OutNum(self, PSOUTCOLOR_BITS_TO_PSFLOAT(ir)); S_OutTok(self, "g", 1); }
+ else
+ {
+ S_OutNum(self, PSOUTCOLOR_BITS_TO_PSFLOAT(ir));
+ S_OutNum(self, PSOUTCOLOR_BITS_TO_PSFLOAT(ig));
+ S_OutNum(self, PSOUTCOLOR_BITS_TO_PSFLOAT(ib));
+ S_OutTok(self, "sc", 1);
+ }
+}
+
+static void
+S_SetPageDevice(PsOutPtr self, int orient, int count, int plex, int res,
+ int wd, int ht, int isPage)
+{
+ float fwd = ((float)wd/(float)res)*72.;
+ float fht = ((float)ht/(float)res)*72.;
+
+#define USE_WORKAROUND_COPY_COUNT_BUG 1
+
+#ifdef USE_WORKAROUND_COPY_COUNT_BUG
+ /* Workaround (see http://xprint.mozdev.org/bugs/show_bug.cgi?id=1861 -
+ * 'Need workaround for bug 1378 ...') to avoid that we print n^2 copies
+ * instead of n copies.
+ * The problem is that we use both /NumCopies here but pass the
+ * %copy-count% to the spooler, too.
+ * But we only have to use _one_ way...
+ *
+ * The final fix for bug 1378 (http://xprint.mozdev.org/bugs/show_bug.cgi?id=1378 -
+ * "PS DDX creates n^2 copies of a job instead of n copies") will back this
+ * workaround out and replace it with a better solution.
+ * (see mozilla.org bug 140030
+ * (http://bugzilla.mozilla.org/show_bug.cgi?id=140030 - "Setting number
+ * of copies causes too many copies to print") for the initial report for
+ * this issue...)
+ */
+ count = 1;
+#endif /* USE_WORKAROUND_COPY_COUNT_BUG */
+
+ S_OutTok(self, "/pWd", 0);
+ S_OutNum(self, fwd);
+ S_OutTok(self, "d /pHt", 0);
+ S_OutNum(self, fht);
+ S_OutTok(self, "d", 1);
+
+ /*
+ * if these are page attributes, have PostScript check to see if they
+ * have changed. If not, don't do setpagedevice, since it will cause
+ * a page flush and screw up duplex printing. Having PostScript check
+ * means we don't have to keep track ourselves.
+ */
+ if(isPage) {
+ S_OutNum(self, (float) orient);
+ S_OutTok(self, "/Orientation ck1", 0);
+ S_OutTok(self, "pWd pHt /PageSize ck2 and not {", 1);
+ }
+ S_OutTok(self, "{db", 0);
+
+ S_OutTok(self, "/Orientation", 0);
+ S_OutNum(self, (float) orient);
+ S_OutTok(self, " d ", 0);
+ S_OutTok(self, "/PageSize [pWd pHt] d", 0);
+
+ S_OutTok(self, " de spd", 0);
+ /*
+ * save a flag to show if we failed to set orientation... determined
+ * by both/either Orientation and/or PageSize, use this
+ * later to set/not set orientation using Cs command.
+ */
+ S_OutTok(self,"}stp /orientationFailed x d", 1);
+ /*
+ * if these are page attributes, have PostScript check to see if they
+ * have changed. If not, don't do setpagedevice, since it will cause
+ * a page flush and screw up duplex printing. Having PostScript check
+ * means we don't have to keep track ourselves.
+ */
+ if(isPage)
+ {
+ S_OutTok(self,"}if",1);
+
+ S_OutTok(self, (plex==0)?"f":"t", 0);
+ S_OutTok(self, "/Duplex ck1 ", 0);
+
+ S_OutTok(self, (plex==2)?"t":"f", 0);
+ S_OutTok(self, "/Tumble ck1 and ", 0);
+
+
+ S_OutNum(self, (float)res);
+ S_OutNum(self, (float)res);
+ S_OutTok(self, " /HWResolution ck2 and", 0);
+
+ if( count>1 )
+ {
+ S_OutNum(self, (float)count);
+ S_OutTok(self, " /NumCopies", 0);
+ S_OutTok(self, " ck1 and ", 0);
+ }
+ S_OutTok(self," not {",1);
+ }
+ S_OutTok(self, "{db", 0);
+
+ S_OutTok(self, "/Duplex ", 0);
+ S_OutTok(self, (plex==0)?"f":"t", 0);
+ S_OutTok(self, " d ", 0);
+
+ S_OutTok(self, "/Tumble ", 0);
+ S_OutTok(self, (plex==2)?"t":"f", 0);
+ S_OutTok(self, " d ", 0);
+
+ S_OutTok(self, " /HWResolution [", 0);
+ S_OutNum(self, (float)res);
+ S_OutNum(self, (float)res);
+ S_OutTok(self, "] d ", 0);
+
+ if( count>1 )
+ {
+ S_OutTok(self, " /NumCopies", 0);
+ S_OutNum(self, (float)count);
+ S_OutTok(self, " d ", 0);
+ }
+ S_OutTok(self, " de spd}stp p", 1);
+
+ if(isPage)
+ {
+ S_OutTok(self, "}if", 1);
+ }
+}
+
+/*******************************************************************
+ * PUBLIC FUNCTIONS *
+ *******************************************************************/
+
+FILE *
+PsOut_ChangeFile(PsOutPtr self, FILE *fp)
+{
+ FILE *nfp;
+
+ nfp = self->Fp;
+
+ self->Fp = fp;
+
+ return nfp;
+}
+
+PsOutPtr
+PsOut_BeginFile(FILE *fp, char *title, int orient, int count, int plex, int res,
+ int wd, int ht, Bool raw)
+{
+ int i;
+ char buffer[256+32]; /* enougth space for a title with 256 chars... */
+/*
+ * Get ready to output PostScript header
+ */
+ PsOutPtr psout;
+ psout = (PsOutPtr)xalloc(sizeof(PsOutRec));
+ memset(psout, 0, sizeof(PsOutRec));
+ psout->Fp = fp;
+ psout->isRaw = raw;
+ psout->pagenum = 0;
+
+ if (!raw) {
+/*
+ * Output PostScript header
+ */
+ /* GhostScript will rant about the missing BoundingBox if we use
+ * "%!PS-Adobe-3.0 EPSF-3.0" here... */
+ S_Comment(psout, "%!PS-Adobe-3.0");
+#ifdef XP_USE_FREETYPE
+ {
+ FT_Int ftmajor = 0,
+ ftminor = 0,
+ ftpatch = 0;
+ extern FT_Library ftypeLibrary; /* defined in xc/lib/font/FreeType/ftfuncs.c */
+
+ FT_Library_Version(ftypeLibrary, &ftmajor, &ftminor, &ftpatch);
+ sprintf(buffer,
+ "%%%%Creator: The X Print Server's PostScript DDX "
+ "(%s, release %d, FreeType version %d.%d.%d)",
+ VENDOR_STRING, VENDOR_RELEASE,
+ (int)ftmajor, (int)ftminor, (int)ftpatch);
+ }
+#else
+ sprintf(buffer,
+ "%%%%Creator: The X Print Server's PostScript DDX (%s, release %d)",
+ VENDOR_STRING, VENDOR_RELEASE);
+#endif /* XP_USE_FREETYPE */
+ S_Comment(psout, buffer);
+
+ if (title)
+ {
+ sprintf(buffer, "%%%%Title: %.256s", title);
+ S_Comment(psout, buffer);
+ }
+ S_Comment(psout, "%%EndComments");
+ S_Comment(psout, "%%BeginProlog");
+ S_Comment(psout, "%%BeginProcSet: XServer_PS_Functions");
+ S_OutDefs(psout, S_StandardDefs);
+ S_OutDefs(psout, S_CompositeDefs);
+ S_Comment(psout, "%%EndProcSet");
+ S_Comment(psout, "%%EndProlog");
+ S_Comment(psout, "%%BeginSetup");
+ /* set document level page attributes */
+ S_SetPageDevice(psout, orient, count, plex, res, wd, ht, 0);
+ S_Comment(psout, "%%Pages: atend");
+ S_OutDefs(psout, S_SetupDefs);
+ S_Comment(psout, "%%EndSetup");
+ }
+/*
+ * Initialize the structure
+ */
+ psout->CurColor = PSOUTCOLOR_NOCOLOR;
+ psout->LineWidth = 1;
+ psout->LineCap = PsCButt;
+ psout->LineJoin = PsJMiter;
+ psout->NDashes = 0;
+ psout->Dashes = (int *)0;
+ psout->FontName = (char *)0;
+ psout->FontSize = 0;
+ psout->start_image = 0;
+ for( i=0 ; i<4 ; i++ ) psout->FontMtx[i] = 0.;
+ psout->ImageFormat = 0;
+ return(psout);
+}
+
+void
+PsOut_EndFile(PsOutPtr self, int closeFile)
+{
+ char coms[50];
+ int i;
+
+ if (!self)
+ return;
+
+ if (!self->isRaw) {
+ S_Comment(self,"%%Trailer");
+ sprintf(coms,"%%%%Pages: %d", self->pagenum);
+ S_Comment(self, coms);
+ S_Comment(self, "%%EOF");
+ }
+ if( self->NDashes && self->Dashes ) xfree(self->Dashes);
+ if( self->FontName ) xfree(self->FontName);
+ if( self->Patterns ) xfree(self->Patterns);
+ if( self->Clip.rects ) xfree(self->Clip.rects);
+ if( closeFile ) fclose(self->Fp);
+ xfree(self);
+}
+
+void
+PsOut_BeginPage(PsOutPtr self, int orient, int count, int plex, int res,
+ int wd, int ht)
+{
+ char coms[50];
+
+/*** comment for pagenumbers *****/
+
+ S_Comment(self,"%%PageHeader");
+ self->pagenum++;
+ sprintf(coms,"%%%%Page: %d %d", self->pagenum, self->pagenum);
+ S_Comment(self, coms);
+ sprintf(coms,"%%%%PageOrientation: %s",pg_orient[orient]);
+ S_Comment(self, coms);
+
+/*** end comment *****************/
+
+ /* set page level page attributes */
+ S_SetPageDevice(self, orient, count, plex, res, wd, ht, 1);
+
+ S_OutTok(self, "gs ", 0);
+ /*
+ * check to see if we set orientation already; if it wasn't set,
+ * use Cs to set orientation here.
+ */
+ S_OutNum(self, (float)orient);
+ S_OutTok(self, "orientationFailed { ", 0);
+ S_OutNum(self, (float)orient);
+ S_OutTok(self, " } { 0 }ie Cs 100 sml gs", 1);
+}
+
+void
+PsOut_EndPage(PsOutPtr self)
+{
+ S_OutTok(self, "gr gr sp", 1);
+
+ /* did grestore: mark attributes 'dirty' so they will be re-sent */
+ PsOut_DirtyAttributes(self);
+
+/*** comment for pagenumbers *****/
+
+ S_Comment(self,"%%PageTrailer");
+
+/*** end comment *****************/
+}
+
+void
+PsOut_DirtyAttributes(PsOutPtr self)
+{
+ int i;
+ self->CurColor = PSOUTCOLOR_NOCOLOR;
+ self->LineWidth = -1;
+ self->LineCap = (PsCapEnum)-1;
+ self->LineJoin = (PsJoinEnum)-1;
+ self->NDashes = -1;
+ self->FontSize = -1;
+ for( i=0 ; i<4 ; i++ ) self->FontMtx[i] = -1.;
+ if( self->Dashes ) { xfree(self->Dashes); self->Dashes = (int *)0; }
+ if( self->FontName ) { xfree(self->FontName); self->FontName = (char *)0; }
+}
+
+void
+PsOut_Comment(PsOutPtr self, char *comment)
+{
+ S_Comment(self, comment);
+}
+
+void
+PsOut_Offset(PsOutPtr self, int x, int y)
+{
+ self->XOff = x;
+ self->YOff = y;
+}
+
+void
+PsOut_Clip(PsOutPtr self, int clpTyp, PsClipPtr clpinf)
+{
+ int i, k;
+ int changed = 0;
+ int xo = self->XOff;
+ int yo = self->YOff;
+
+ if( self->InTile ) return;
+ if( self->InFrame ) xo = yo = 0;
+ if( clpTyp!=self->ClipType ) changed = 1;
+ else
+ {
+ if( clpinf->nRects!=self->Clip.nRects ) changed = 1;
+ else
+ {
+ if( clpinf->nOutterClips!=self->Clip.nOutterClips ) changed = 1;
+ else
+ {
+ for( i=0 ; i<clpinf->nOutterClips ; i++ )
+ {
+ if( memcmp(&clpinf->outterClips[i], &self->Clip.outterClips[i],
+ sizeof(PsRectRec))!=0 ) break;
+ }
+ if( i<clpinf->nOutterClips ) changed = 1;
+ else
+ {
+ for( i=0 ; i<clpinf->nRects ; i++ )
+ {
+ if( memcmp(&clpinf->rects[i], &self->Clip.rects[i],
+ sizeof(PsRectRec))!=0 ) { changed = 1; break; }
+ }
+ }
+ }
+ }
+ if( clpinf->nElms!=self->Clip.nElms ) changed = 1;
+ else
+ {
+ for( i=0 ; i<clpinf->nElms ; i++ )
+ {
+ if( clpinf->elms[i].type!=PSOUT_POINTS )
+ {
+ if( memcmp(&clpinf->elms[i], &self->Clip.elms[i],
+ sizeof(PsElmRec))!=0 ) { changed = 1; break; }
+ }
+ else
+ {
+ if( clpinf->elms[i].type!=self->Clip.elms[i].type ||
+ clpinf->elms[i].nPoints!=self->Clip.elms[i].nPoints )
+ { changed = 1; break; }
+ else
+ {
+ for( k=0 ; k<clpinf->elms[i].nPoints ; k++ )
+ {
+ if( memcmp(&clpinf->elms[i].c.points[k],
+ &self->Clip.elms[i].c.points[k], sizeof(PsPointRec)) )
+ { changed = 1; break; }
+ }
+ if( changed ) break;
+ }
+ }
+ }
+ }
+ }
+
+ if( self->Clip.rects ) xfree(self->Clip.rects);
+ if( self->Clip.outterClips ) xfree(self->Clip.outterClips);
+ if( self->Clip.elms )
+ PsDestroyFillElementList(self->Clip.nElms, self->Clip.elms);
+ self->ClipType = clpTyp;
+ self->Clip.nRects = clpinf->nRects;
+ self->Clip.nElms = clpinf->nElms;
+ self->Clip.nOutterClips = clpinf->nOutterClips;
+ if( clpinf->nRects )
+ {
+ self->Clip.rects = (PsRectPtr)xalloc(clpinf->nRects*sizeof(PsRectRec));
+ memcpy(self->Clip.rects, clpinf->rects, clpinf->nRects*sizeof(PsRectRec));
+ }
+ else self->Clip.rects = 0;
+ if( clpinf->nOutterClips )
+ {
+ self->Clip.outterClips = (PsRectPtr)xalloc(clpinf->nOutterClips*
+ sizeof(PsRectRec));
+ memcpy(self->Clip.outterClips, clpinf->outterClips,
+ clpinf->nOutterClips*sizeof(PsRectRec));
+ }
+ else self->Clip.outterClips = 0;
+ if( clpinf->nElms )
+ self->Clip.elms = PsCloneFillElementList(clpinf->nElms, clpinf->elms);
+ else self->Clip.elms = 0;
+
+ PsOut_DirtyAttributes(self);
+ S_OutTok(self, "gr gs", 1);
+ if( self->Clip.nOutterClips )
+ {
+ for( i=0 ; i<self->Clip.nOutterClips ; i++ )
+ {
+ S_OutNum(self, (float)(self->Clip.outterClips[i].x));
+ S_OutNum(self, (float)(self->Clip.outterClips[i].y));
+ S_OutNum(self, (float)self->Clip.outterClips[i].w);
+ S_OutNum(self, (float)self->Clip.outterClips[i].h);
+ S_OutTok(self, "R", 1);
+ }
+ S_OutTok(self, "cl n", 1);
+ }
+ if( self->Clip.nRects )
+ {
+ for( i=0 ; i<self->Clip.nRects ; i++ )
+ {
+ S_OutNum(self, (float)(self->Clip.rects[i].x+xo));
+ S_OutNum(self, (float)(self->Clip.rects[i].y+yo));
+ S_OutNum(self, (float)self->Clip.rects[i].w);
+ S_OutNum(self, (float)self->Clip.rects[i].h);
+ S_OutTok(self, "R", 1);
+ }
+ S_OutTok(self, "cl n", 1);
+ }
+ if( self->Clip.nElms )
+ {
+ PsElmPtr elm = self->Clip.elms;
+ for( i=0 ; i<self->Clip.nElms ; i++,elm++ )
+ {
+ switch(elm->type)
+ {
+ case PSOUT_POINTS:
+ for( k=0 ; k<elm->nPoints ; k++ )
+ {
+ S_OutNum(self, (float)elm->c.points[k].x+xo);
+ S_OutNum(self, (float)elm->c.points[k].y+yo);
+ if( k==0 ) S_OutTok(self, "m", 0);
+ else S_OutTok(self, "l", 0);
+ }
+ S_OutTok(self, "cp", 1);
+ break;
+ case PSOUT_RECT:
+ S_OutNum(self, (float)elm->c.rect.x+xo);
+ S_OutNum(self, (float)elm->c.rect.y+yo);
+ S_OutNum(self, (float)elm->c.rect.w);
+ S_OutNum(self, (float)elm->c.rect.h);
+ S_OutTok(self, "R", 1);
+ break;
+ case PSOUT_ARC:
+ if( elm->c.arc.style==PsPieSlice )
+ {
+ S_OutNum(self, (float)elm->c.arc.x+xo+(float)elm->c.arc.w/2.);
+ S_OutNum(self, (float)elm->c.arc.y+yo+(float)elm->c.arc.h/2.);
+ S_OutTok(self, "m", 0);
+ }
+ S_OutNum(self, (float)elm->c.arc.x+xo+(float)elm->c.arc.w/2.);
+ S_OutNum(self, (float)elm->c.arc.y+yo+(float)elm->c.arc.h/2.);
+ S_OutNum(self, (float)elm->c.arc.w);
+ S_OutNum(self, (float)elm->c.arc.h);
+ S_OutNum(self, (float)elm->c.arc.a1/64.);
+ S_OutNum(self, (float)elm->c.arc.a1/64.+(float)elm->c.arc.a2/64.);
+ if( elm->c.arc.a2<0 ) S_OutTok(self, "An cp", 1);
+ else S_OutTok(self, "Ac cp", 1);
+ break;
+ }
+ }
+ S_OutTok(self, "cl n", 1);
+ }
+}
+
+void
+PsOut_Color(PsOutPtr self, PsOutColor clr)
+{
+ if( clr==self->CurColor || self->InTile>=PsStip ) return;
+ self->CurColor = clr;
+ S_Color(self, clr);
+}
+
+void
+PsOut_FillRule(PsOutPtr self, PsRuleEnum rule)
+{
+ self->FillRule = rule;
+}
+
+void
+PsOut_LineAttrs(PsOutPtr self, int wd, PsCapEnum cap, PsJoinEnum join,
+ int nDsh, int *dsh, int dshOff, PsOutColor bclr)
+{
+ int i;
+ int same = 1;
+
+ if( wd!=self->LineWidth && wd>=0 )
+ {
+ if( wd==0 ) wd = 1;
+ self->LineWidth = wd;
+ S_OutNum(self, (float)wd); S_OutTok(self, "w", 1);
+ }
+ if( cap!=self->LineCap )
+ {
+ self->LineCap = cap;
+ S_OutNum(self, (float)cap); S_OutTok(self, "lc", 1);
+ }
+ if( join!=self->LineJoin )
+ {
+ self->LineJoin = join;
+ S_OutNum(self, (float)join); S_OutTok(self, "lj", 1);
+ }
+ if( nDsh!=self->NDashes ) same = 0;
+ else if( dshOff!=self->DashOffset ) same = 0;
+ else if( nDsh )
+ {
+ for( i=0 ; i<nDsh ; i++ )
+ { if( dsh[i]!=self->Dashes[i] ) break; }
+ if( i<nDsh ) same = 0;
+ }
+ if( !same )
+ {
+ if( self->NDashes && self->Dashes )
+ { xfree(self->Dashes); self->Dashes = (int *)0; }
+ self->NDashes = nDsh;
+ self->DashOffset = dshOff;
+ if( nDsh ) self->Dashes = (int *)xalloc(sizeof(int)*nDsh);
+ S_OutTok(self, "[", 0);
+ for( i=0 ; i<nDsh ; i++ )
+ {
+ self->Dashes[i] = dsh[i];
+ S_OutNum(self, (float)dsh[i]);
+ }
+ S_OutTok(self, "]", 0);
+ S_OutNum(self, (float)dshOff);
+ S_OutTok(self, "ds", 1);
+ }
+
+ if( nDsh )
+ self->LineBClr = bclr;
+ else
+ bclr = PSOUTCOLOR_NOCOLOR;
+}
+
+void
+PsOut_TextAttrs(PsOutPtr self, char *fnam, int siz, int iso)
+{
+ int i;
+ char buf[256];
+ if( self->FontName && strcmp(fnam, self->FontName)==0 &&
+ siz==self->FontSize ) return;
+ if( self->FontName ) xfree(self->FontName);
+ self->FontName = (char *)xalloc(strlen(fnam)+1);
+ strcpy(self->FontName, fnam);
+ self->FontSize = siz;
+ for( i=0 ; i<4 ; i++ ) self->FontMtx[i] = -1.;
+ strcpy(buf, "/"); strcat(buf, fnam);
+ S_OutTok(self, buf, 0);
+ S_OutNum(self, (float)siz);
+ if( iso ) S_OutTok(self, "t", 0);
+ else S_OutTok(self, "f", 0);
+ S_OutTok(self, "Tf", 1);
+}
+
+void
+PsOut_TextAttrsMtx(PsOutPtr self, char *fnam, float *mtx, int iso)
+{
+ int i;
+ char buf[256];
+ if( self->FontName && strcmp(fnam, self->FontName)==0 &&
+ mtx[0]==self->FontMtx[0] && mtx[1]==self->FontMtx[1] &&
+ mtx[2]==self->FontMtx[2] && mtx[3]==self->FontMtx[3] ) return;
+ if( self->FontName ) xfree(self->FontName);
+ self->FontName = (char *)xalloc(strlen(fnam)+1);
+ strcpy(self->FontName, fnam);
+ for( i=0 ; i<4 ; i++ ) self->FontMtx[i] = mtx[i];
+ self->FontSize = -1;
+ strcpy(buf, "/"); strcat(buf, fnam); strcat(buf, " [");
+ S_OutTok(self, buf, 0);
+ for( i=0 ; i<4 ; i++ ) S_OutNum(self, mtx[i]);
+ S_OutTok(self, "0 0]", 0);
+ if( iso ) S_OutTok(self, "t", 0);
+ else S_OutTok(self, "f", 0);
+ S_OutTok(self, "Tfm", 1);
+}
+
+void
+PsOut_Polygon(PsOutPtr self, int nPts, PsPointPtr pts)
+{
+ int i;
+ int xo = self->XOff;
+ int yo = self->YOff;
+
+ if( self->InFrame || self->InTile ) xo = yo = 0;
+ if( nPts<=2 ) return;
+ for( i=0 ; i<nPts ; i++ )
+ {
+ S_OutNum(self, (float)(pts[i].x+xo));
+ S_OutNum(self, (float)(pts[i].y+yo));
+ if( i==0 ) S_OutTok(self, "m", 0);
+ else S_OutTok(self, "l", 0);
+ }
+ if( self->FillRule==PsEvenOdd ) S_OutTok(self, "cp ef", 1);
+ else S_OutTok(self, "cp fl", 1);
+}
+
+void
+PsOut_FillRect(PsOutPtr self, int x, int y, int w, int h)
+{
+ int xo = self->XOff;
+ int yo = self->YOff;
+
+ if( self->InFrame || self->InTile ) xo = yo = 0;
+ x += xo; y += yo;
+ S_OutNum(self, (float)x);
+ S_OutNum(self, (float)y);
+ S_OutNum(self, (float)w);
+ S_OutNum(self, (float)h);
+ S_OutTok(self, "R fl", 1);
+}
+
+void
+PsOut_FillArc(PsOutPtr self, int x, int y, int w, int h,
+ float ang1, float ang2, PsArcEnum style)
+{
+ int xo = self->XOff;
+ int yo = self->YOff;
+
+ if( self->InFrame || self->InTile ) xo = yo = 0;
+ x += xo; y += yo;
+ if( style==PsPieSlice )
+ {
+ S_OutNum(self, (float)x+(float)w/2.);
+ S_OutNum(self, (float)y+(float)h/2.);
+ S_OutTok(self, "m", 0);
+ }
+ S_OutNum(self, (float)x+(float)w/2.);
+ S_OutNum(self, (float)y+(float)h/2.);
+ S_OutNum(self, (float)w);
+ S_OutNum(self, (float)h);
+ S_OutNum(self, ang1);
+ S_OutNum(self, ang1+ang2);
+ if( ang2<0 ) S_OutTok(self, "An cp fl", 1);
+ else S_OutTok(self, "Ac cp fl", 1);
+}
+
+void
+PsOut_Lines(PsOutPtr self, int nPts, PsPointPtr pts)
+{
+ int i;
+ int xo = self->XOff;
+ int yo = self->YOff;
+
+ if( self->InFrame || self->InTile ) xo = yo = 0;
+ if( nPts<1 ) return;
+ for( i=0 ; i<nPts ; i++ )
+ {
+ S_OutNum(self, (float)(pts[i].x+xo));
+ S_OutNum(self, (float)(pts[i].y+yo));
+ if( i==0 ) S_OutTok(self, "m", 0);
+ else S_OutTok(self, "l", 0);
+ }
+ if( self->LineBClr != PSOUTCOLOR_NOCOLOR )
+ {
+ S_OutTok(self, "gs", 0);
+ S_Color(self, self->LineBClr);
+ S_OutTok(self, "[] 0 ds st gr", 0);
+ }
+ S_OutTok(self, "st", 1);
+}
+
+void
+PsOut_Points(PsOutPtr self, int nPts, PsPointPtr pts)
+{
+ int i;
+ int xo = self->XOff;
+ int yo = self->YOff;
+
+ if( self->InFrame || self->InTile ) xo = yo = 0;
+ if( nPts<1 ) return;
+ for( i=0 ; i<nPts ; i++ )
+ {
+ S_OutNum(self, (float)(pts[i].x+xo));
+ S_OutNum(self, (float)(pts[i].y+yo));
+ S_OutTok(self, "P", 1);
+ }
+}
+
+void
+PsOut_DrawRect(PsOutPtr self, int x, int y, int w, int h)
+{
+ int xo = self->XOff;
+ int yo = self->YOff;
+
+ if( self->InFrame || self->InTile ) xo = yo = 0;
+ x += xo; y += yo;
+ S_OutNum(self, (float)x);
+ S_OutNum(self, (float)y);
+ S_OutNum(self, (float)w);
+ S_OutNum(self, (float)h);
+ S_OutTok(self, "R", 0);
+ if( self->LineBClr != PSOUTCOLOR_NOCOLOR )
+ {
+ S_OutTok(self, "gs", 0);
+ S_Color(self, self->LineBClr);
+ S_OutTok(self, "[] 0 ds st gr", 0);
+ }
+ S_OutTok(self, "st", 1);
+}
+
+void
+PsOut_DrawArc(PsOutPtr self, int x, int y, int w, int h,
+ float ang1, float ang2)
+{
+ int xo = self->XOff;
+ int yo = self->YOff;
+
+ if( self->InFrame || self->InTile ) xo = yo = 0;
+ x += xo; y += yo;
+ S_OutNum(self, (float)x+(float)w/2.);
+ S_OutNum(self, (float)y+(float)h/2.);
+ S_OutNum(self, (float)w);
+ S_OutNum(self, (float)h);
+ S_OutNum(self, ang1);
+ S_OutNum(self, ang1+ang2);
+ if( ang2<0 ) S_OutTok(self, "An", 0);
+ else S_OutTok(self, "Ac", 0);
+ if( self->LineBClr != PSOUTCOLOR_NOCOLOR )
+ {
+ S_OutTok(self, "gs", 0);
+ S_Color(self, self->LineBClr);
+ S_OutTok(self, "[] 0 ds st gr", 0);
+ }
+ S_OutTok(self, "st", 1);
+}
+
+void
+PsOut_Text(PsOutPtr self, int x, int y, char *text, int textl, PsOutColor bclr)
+{
+ int xo = self->XOff;
+ int yo = self->YOff;
+
+ if( self->InFrame || self->InTile ) xo = yo = 0;
+ x += xo; y += yo;
+ S_OutStr(self, text, textl);
+ S_OutNum(self, (float)x);
+ S_OutNum(self, (float)y);
+ if( bclr == PSOUTCOLOR_NOCOLOR )
+ S_OutTok(self, "T", 1);
+ else
+ {
+ int ir = PSOUTCOLOR_TO_REDBITS(bclr);
+ int ig = PSOUTCOLOR_TO_GREENBITS(bclr);
+ int ib = PSOUTCOLOR_TO_BLUEBITS(bclr);
+
+ S_OutNum(self, PSOUTCOLOR_BITS_TO_PSFLOAT(ir));
+ S_OutNum(self, PSOUTCOLOR_BITS_TO_PSFLOAT(ig));
+ S_OutNum(self, PSOUTCOLOR_BITS_TO_PSFLOAT(ib));
+ S_OutTok(self, "Tb", 1);
+ }
+}
+
+void
+PsOut_Text16(PsOutPtr self, int x, int y, unsigned short *text, int textl, PsOutColor bclr)
+{
+ int xo = self->XOff;
+ int yo = self->YOff;
+
+ if( self->InFrame || self->InTile ) xo = yo = 0;
+ x += xo; y += yo;
+ S_OutStr16(self, text, textl);
+ S_OutNum(self, (float)x);
+ S_OutNum(self, (float)y);
+ if( bclr == PSOUTCOLOR_NOCOLOR )
+ S_OutTok(self, "T", 1);
+ else
+ {
+ int ir = PSOUTCOLOR_TO_REDBITS(bclr);
+ int ig = PSOUTCOLOR_TO_GREENBITS(bclr);
+ int ib = PSOUTCOLOR_TO_BLUEBITS(bclr);
+ S_OutNum(self, PSOUTCOLOR_BITS_TO_PSFLOAT(ir));
+ S_OutNum(self, PSOUTCOLOR_BITS_TO_PSFLOAT(ig));
+ S_OutNum(self, PSOUTCOLOR_BITS_TO_PSFLOAT(ib));
+ S_OutTok(self, "Tb", 1);
+ }
+}
+
+#ifdef BM_CACHE
+void /* new */
+PsOut_ImageCache(PsOutPtr self, int x, int y, long cache_id, PsOutColor bclr, PsOutColor fclr)
+{
+ char cacheID[10];
+ int xo = self->XOff;
+ int yo = self->YOff;
+
+ if( self->InFrame || self->InTile ) xo = yo = 0;
+ x += xo; y += yo;
+ sprintf(cacheID, "c%di", cache_id);
+
+ S_OutNum(self, (float)x);
+ S_OutNum(self, (float)y);
+
+ if( fclr==PSOUTCOLOR_WHITE )
+ {
+ int ir = PSOUTCOLOR_TO_REDBITS(bclr);
+ int ig = PSOUTCOLOR_TO_GREENBITS(bclr);
+ int ib = PSOUTCOLOR_TO_BLUEBITS(bclr);
+
+ if( ir==ig && ig==ib )
+ S_OutNum(self, PSOUTCOLOR_BITS_TO_PSFLOAT(ir));
+ else
+ S_OutNum(self, (float)0);
+ self->RevImage = 1;
+ }
+ else
+ {
+ int ir = PSOUTCOLOR_TO_REDBITS(fclr);
+ int ig = PSOUTCOLOR_TO_GREENBITS(fclr);
+ int ib = PSOUTCOLOR_TO_BLUEBITS(fclr);
+
+ if( ir==ig && ig==ib )
+ S_OutNum(self, PSOUTCOLOR_BITS_TO_PSFLOAT(ir));
+ else
+ S_OutNum(self, (float)0);
+ }
+
+ S_OutTok(self, cacheID, 1);
+} /* new */
+
+void /* new */
+PsOut_BeginImageCache(PsOutPtr self, long cache_id)
+{
+ char cacheID[10];
+
+ sprintf(cacheID, "/c%di {", cache_id);
+
+ S_OutTok(self, cacheID, 0);
+} /* new */
+
+void /* new */
+PsOut_EndImageCache(PsOutPtr self)
+{
+ S_OutTok(self, "}bd", 1);
+} /* new */
+#endif
+
+void
+PsOut_BeginImage(PsOutPtr self, PsOutColor bclr, PsOutColor fclr, int x, int y,
+ int w, int h, int sw, int sh, int format)
+{
+ PsOutColor savClr = self->CurColor;
+ int xo = self->XOff;
+ int yo = self->YOff;
+
+ if( self->InFrame || self->InTile ) xo = yo = 0;
+ x += xo; y += yo;
+ if( self->InTile )
+ {
+ if( self->InTile>=PsStip && format!=1 ) { self->ImgSkip = 1; return; }
+ self->ImgBClr = bclr; self->ImgFClr = fclr;
+ self->ImgX = x; self->ImgY = y;
+ self->ImgW = w; self->ImgH = h;
+ self->SclW = sw; self->SclH = sh;
+ S_OutTok(self, "<", 0);
+ self->ImageFormat = format;
+ self->RevImage = 0;
+ if( self->InTile==PsTile && format==1 && fclr==PSOUTCOLOR_WHITE )
+ self->RevImage = 1;
+ return;
+ }
+
+ self->RevImage = 0;
+ if( format==1 )
+ {
+ S_OutTok(self, "gs", 0);
+ if( fclr==PSOUTCOLOR_WHITE )
+ {
+ PsOut_Color(self, fclr);
+ PsOut_FillRect(self, x, y, sw, sh);
+ PsOut_Color(self, bclr);
+ self->RevImage = 1;
+ }
+ else
+ {
+ PsOut_Color(self, bclr);
+ PsOut_FillRect(self, x, y, sw, sh);
+ PsOut_Color(self, fclr);
+ }
+ }
+ S_OutNum(self, (float)x);
+ S_OutNum(self, (float)y);
+ S_OutNum(self, (float)w);
+ S_OutNum(self, (float)h);
+ S_OutNum(self, (float)sw);
+ S_OutNum(self, (float)sh);
+ if( format==1 ) {
+ if(self->RevImage)
+ S_OutTok(self, "Im1rev", 1);
+ else
+ S_OutTok(self, "Im1", 1);
+ }
+ else S_OutTok(self, "Im24", 1);
+ self->ImageFormat = format;
+ self->CurColor = savClr;
+}
+
+void
+PsOut_BeginImageIM(PsOutPtr self, PsOutColor bclr, PsOutColor fclr, int x, int y,
+ int w, int h, int sw, int sh, int format)
+{
+ PsOutColor savClr = self->CurColor;
+ int xo = self->XOff;
+ int yo = self->YOff;
+
+ if( self->InFrame || self->InTile ) xo = yo = 0;
+ x += xo; y += yo;
+ if( self->InTile )
+ {
+ if( self->InTile>=PsStip && format!=1 ) { self->ImgSkip = 1; return; }
+ self->ImgBClr = bclr; self->ImgFClr = fclr;
+ self->ImgX = x; self->ImgY = y;
+ self->ImgW = w; self->ImgH = h;
+ self->SclW = sw; self->SclH = sh;
+ S_OutTok(self, "<", 0);
+ self->ImageFormat = format;
+ self->RevImage = 0;
+ if( self->InTile==PsTile && format==1 && fclr==PSOUTCOLOR_WHITE )
+ self->RevImage = 1;
+ return;
+ }
+
+ self->RevImage = 0;
+ if( format==1 )
+ {
+ S_OutTok(self, "gs", 0);
+#ifdef BM_CACHE
+ S_OutTok(self, "g", 1);
+#else
+ if( fclr==PSOUTCOLOR_WHITE )
+ {
+ PsOut_Color(self, bclr);
+ self->RevImage = 1;
+ }
+ else
+ {
+ PsOut_Color(self, fclr);
+ }
+#endif
+ }
+
+#ifdef BM_CACHE
+ S_OutTok(self, "tr", 0); /* new */
+#else
+ S_OutNum(self, (float)x);
+ S_OutNum(self, (float)y);
+#endif
+ S_OutNum(self, (float)w);
+ S_OutNum(self, (float)h);
+ S_OutNum(self, (float)sw);
+ S_OutNum(self, (float)sh);
+#ifdef BM_CACHE
+ S_OutTok(self, "mtx", 1); /* new */
+ S_OutTok(self, "<", 0); /* new */
+ self->start_image = 1;
+#else
+ if( format==1 ){
+ if(self->RevImage)
+ S_OutTok(self, "Im1rev", 1);
+ else
+ S_OutTok(self, "Im1", 1);
+ }
+ else S_OutTok(self, "Im24", 1);
+#endif
+ self->ImageFormat = format;
+ self->CurColor = savClr;
+}
+
+void
+PsOut_EndImage(PsOutPtr self)
+{
+ if( self->ImgSkip ) { self->ImgSkip = 0; return; }
+ if( self->InTile )
+ {
+ S_OutTok(self, ">", 1);
+ if( self->ImageFormat==1 && self->InTile==PsTile )
+ {
+ if( self->ImgFClr==PSOUTCOLOR_WHITE )
+ {
+ PsOut_Color(self, self->ImgFClr);
+ PsOut_FillRect(self, self->ImgX, self->ImgY, self->SclW, self->SclH);
+ PsOut_Color(self, self->ImgBClr);
+ }
+ else
+ {
+ PsOut_Color(self, self->ImgBClr);
+ PsOut_FillRect(self, self->ImgX, self->ImgY, self->SclW, self->SclH);
+ PsOut_Color(self, self->ImgFClr);
+ }
+ }
+ S_OutNum(self, (float)self->ImgX);
+ S_OutNum(self, (float)self->ImgY);
+ S_OutNum(self, (float)self->ImgW);
+ S_OutNum(self, (float)self->ImgH);
+ S_OutNum(self, (float)self->SclW);
+ S_OutNum(self, (float)self->SclH);
+ if( self->ImageFormat==1 ) S_OutTok(self, "Im1t", 1);
+ else S_OutTok(self, "Im24t", 1);
+ self->ImageFormat = 0;
+ self->RevImage = 0;
+ return;
+ }
+ /*
+ * Bug 4639307: Move flush before "> im" to get all of bitmap into ps file.
+ */
+ S_Flush(self);
+#ifdef BM_CACHE
+ if(self->start_image)
+ S_OutTok(self, "> im", 1); /* new */
+#endif
+ self->ImageFormat = 0;
+ self->RevImage = 0;
+#ifdef BM_CACHE
+ if(self->start_image)
+ {
+ self->start_image = 0;
+ S_OutTok(self, "gr", 0);
+ }
+ else
+ S_OutTok(self, "gr", 1);
+#else
+ S_OutTok(self, "gr", 1);
+#endif
+}
+
+void
+PsOut_OutImageBytes(PsOutPtr self, int nBytes, char *bytes)
+{
+ int i;
+ int b;
+ int len;
+ const char hex[] = { '0', '1', '2', '3', '4', '5', '6', '7',
+ '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
+
+ if( (!self->ImageFormat) || self->ImgSkip ) return;
+
+ len = strlen(self->Buf);
+
+ for( i=0 ; i<nBytes ; i++ )
+ {
+ if( self->RevImage ) b = (int)((bytes[i]^0xFF)&0xFF);
+ else b = (int)(bytes[i]&0xFF);
+
+ self->Buf[len++] = hex[(b&0xF0) >> 4];
+ self->Buf[len++] = hex[(b&0x0F)];
+ self->Buf[len] = '\0';
+
+ if( len>70 )
+ {
+ S_Flush(self);
+ len = 0;
+ }
+ }
+}
+
+void
+PsOut_BeginFrame(PsOutPtr self, int xoff, int yoff, int x, int y,
+ int w, int h)
+{
+ int xo = self->XOff;
+ int yo = self->YOff;
+
+ if( self->InFrame ) xo = yo = 0;
+ S_OutTok(self, "gs", 0);
+ S_OutNum(self, (float)(x+xo));
+ S_OutNum(self, (float)(y+yo));
+ S_OutNum(self, (float)w);
+ S_OutNum(self, (float)h);
+ S_OutTok(self, "R cl n", 0);
+ xoff += xo; yoff += yo;
+ if( xoff || yoff )
+ {
+ S_OutNum(self, (float)xoff);
+ S_OutNum(self, (float)yoff);
+ S_OutTok(self, "tr", 0);
+ }
+ S_OutTok(self, "gs", 1);
+ self->InFrame += 1;
+}
+
+void
+PsOut_EndFrame(PsOutPtr self)
+{
+ self->InFrame -= 1;
+ if( self->InFrame<0 ) self->InFrame = 0;
+ S_OutTok(self, "gr gr", 1);
+ PsOut_DirtyAttributes(self);
+}
+
+int
+PsOut_BeginPattern(PsOutPtr self, void *tag, int w, int h, PsFillEnum type,
+ PsOutColor bclr, PsOutColor fclr)
+{
+ int i;
+ char key[64];
+
+ for( i=0 ; i<self->NPatterns ; i++ )
+ { if( self->Patterns[i].tag==tag && self->Patterns[i].type==type ) break; }
+ if( i<self->NPatterns ) return(1);
+ if( (self->NPatterns+1)>self->MxPatterns )
+ {
+ if( self->Patterns )
+ {
+ self->MxPatterns *= 2;
+ self->Patterns =
+ (PsPatPtr)xrealloc(self->Patterns, sizeof(PsPatRec)*self->MxPatterns);
+ }
+ else
+ {
+ self->MxPatterns = 64;
+ self->Patterns = (PsPatPtr)xalloc(sizeof(PsPatRec)*self->MxPatterns);
+ }
+ }
+ self->Patterns[self->NPatterns].tag = tag;
+ self->Patterns[self->NPatterns].type = type;
+ sprintf(key, "/ %d", (int)tag);
+ switch(type) {
+ case PsTile: key[1] = 't'; break;
+ case PsStip: key[1] = 's'; break;
+ case PsOpStip: key[1] = 'o'; break; }
+ S_OutTok(self, key, 0);
+ S_OutTok(self, "db/PatternType 1 d/PaintType 1 d", 0);
+ S_OutTok(self, "/TilingType 1 d/BBox[0 0", 0);
+ S_OutNum(self, (float)w);
+ S_OutNum(self, (float)h);
+ S_OutTok(self, "]d/XStep", 0);
+ S_OutNum(self, (float)w);
+ S_OutTok(self, "d/YStep", 0);
+ S_OutNum(self, (float)h);
+ S_OutTok(self, "d/PaintProc{bg sv", 1);
+ if( type==PsOpStip )
+ {
+ S_Color(self, bclr);
+ S_OutTok(self, "0 0", 0);
+ S_OutNum(self, (float)w);
+ S_OutNum(self, (float)h);
+ S_OutTok(self, "R fl", 1);
+ }
+ if( type!=PsTile ) S_Color(self, fclr);
+ self->NPatterns += 1;
+ self->InTile = type;
+ return(0);
+}
+
+void
+PsOut_EndPattern(PsOutPtr self)
+{
+ self->InTile = PsSolid;
+ S_OutTok(self, "rs ed}d de im_ mp d", 1);
+}
+
+void
+PsOut_SetPattern(PsOutPtr self, void *tag, PsFillEnum type)
+{
+ int i;
+ char key[64];
+
+ for( i=0 ; i<self->NPatterns ; i++ )
+ { if( tag==self->Patterns[i].tag && type==self->Patterns[i].type ) break; }
+ if( i>=self->NPatterns ) return;
+ sprintf(key, " %d", (int)tag);
+ switch(type) {
+ case PsTile: key[0] = 't'; break;
+ case PsStip: key[0] = 's'; break;
+ case PsOpStip: key[0] = 'o'; break; }
+ S_OutTok(self, key, 0);
+ S_OutTok(self, "spt", 1);
+ self->CurColor = PSOUTCOLOR_NOCOLOR;
+}
+
+void
+PsOut_RawData(PsOutPtr self, char *data, int len)
+{
+ S_Flush(self);
+ if (!ferror(self->Fp)) {
+ (void) fwrite(data, 1, len, self->Fp);
+ }
+}
+
+typedef enum PsDownfontFontType_
+{
+ PsDFT_Type1PFA=0,
+ PsDFT_Type1PFB,
+ PsDFT_TrueType /* not implemented yet */
+} PsDownfontFontType;
+
+/* Download a PS Type1 font */
+int
+PsOut_DownloadType1(PsOutPtr self, const char *auditmsg, const char *name, const char *fname)
+{
+ int i;
+ int stt;
+ char buf[256];
+ FILE *fp;
+ PsDownfontFontType type;
+
+ fp = fopen(fname, "r");
+ if( !fp )
+ return 0;
+
+#ifdef DEBUG_gisburn
+ /* This should be log-able! */
+ fprintf(stderr, "PsOut_DownloadType1: %s: Downloading '%s' from '%s'\n", auditmsg, name, fname);
+#endif /* DEBUG_gisburn */
+
+ fread(buf, 32, 1, fp);
+ fseek(fp, (long)0, 0);
+
+ /* Is this a Adobe PostScript Type 1 binary font (PFB) ? */
+ if( (buf[0]&0xFF)==0x80 && (buf[1]&0xFF)==0x01 )
+ {
+ type = PsDFT_Type1PFB;
+ }
+ /* Is this a Adobe PostScript ASCII font (PFA) ? */
+ else if (!strncmp(buf, "%!PS-AdobeFont", 14))
+ {
+ type = PsDFT_Type1PFA;
+ }
+ else
+ {
+ /* This should be log-able! */
+ fprintf(stderr, "PsOut_DownloadType1: Unknown font type for '%s'\n", fname);
+ return 0;
+ }
+
+ S_Flush(self);
+ sprintf(buf, "%%%%BeginFont: %s", name);
+ S_Comment(self, buf);
+
+ if( type == PsDFT_Type1PFB )
+ {
+ char *buf,
+ *pt;
+ int len,
+ ch,
+ stype;
+
+ ch = fgetc(fp);
+ /* Strip out the binary headers and de-binary it */
+ while( (ch&0xFF) == 0x80 )
+ {
+ stype = fgetc(fp);
+ if( stype==3 ) /* eof mark */
+ break;
+ len = fgetc(fp);
+ len |= fgetc(fp)<<8;
+ len |= fgetc(fp)<<16;
+ len |= fgetc(fp)<<24;
+ buf = (char *)xalloc(len+1);
+ if( stype==1 )
+ {
+ /* Process ASCII section */
+ len = fread(buf, 1, len, fp);
+ /* convert any lone CRs (ie Mac eol) to LFs */
+ for( pt = buf ; (pt = memchr(pt, '\r', len-(pt-buf))) != NULL ; pt++ )
+ {
+ if ( pt[1]!='\n' )
+ *pt = '\n';
+ }
+ fwrite(buf, 1, len, self->Fp);
+ }
+ else if( stype==2 )
+ {
+ int i;
+
+ /* Process binary section */
+ len = fread(buf, 1, len, fp);
+ for( i=0 ; i<len ; i++ )
+ {
+ ch = buf[i];
+ if( ((ch>>4)&0xf) <= 9 )
+ fputc('0'+((ch>>4)&0xf), self->Fp);
+ else
+ fputc('A'-10+((ch>>4)&0xf), self->Fp);
+
+ if( (ch&0xf) <= 9 )
+ fputc('0'+(ch&0xf), self->Fp);
+ else
+ fputc('A'-10+(ch&0xf), self->Fp);
+
+ if( (i&0x1f)==0x1f )
+ fputc('\n', self->Fp);
+ }
+ }
+ xfree(buf);
+
+ /* Next block... */
+ ch = fgetc(fp);
+ }
+ }
+ /* Is this a Adobe PostScript ASCII font (PFA) ? */
+ else if (type == PsDFT_Type1PFA)
+ {
+ for(;;)
+ {
+ stt = fread(buf, 1, 256, fp);
+ if( stt<=0 ) break;
+ if (!ferror(self->Fp)) {
+ (void) fwrite(buf, 1, stt, self->Fp);
+ }
+ if( stt<256 )
+ break;
+ }
+ }
+ fclose(fp);
+ S_Flush(self);
+ S_Comment(self, "%%EndFont");
+
+ /* Success... */
+ return 1;
+}
+
+
+
+
+
+
diff --git a/nx-X11/programs/Xserver/Xprint/ps/psout.h b/nx-X11/programs/Xserver/Xprint/ps/psout.h
new file mode 100644
index 000000000..8441d8d07
--- /dev/null
+++ b/nx-X11/programs/Xserver/Xprint/ps/psout.h
@@ -0,0 +1,335 @@
+/* $Xorg: psout.h,v 1.6 2001/02/09 02:04:37 xorgcvs Exp $ */
+/*
+
+Copyright 1996, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+/*
+ * (c) Copyright 1996 Hewlett-Packard Company
+ * (c) Copyright 1996 International Business Machines Corp.
+ * (c) Copyright 1996 Sun Microsystems, Inc.
+ * (c) Copyright 1996 Novell, Inc.
+ * (c) Copyright 1996 Digital Equipment Corp.
+ * (c) Copyright 1996 Fujitsu Limited
+ * (c) Copyright 1996 Hitachi, Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject
+ * to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the names of the copyright holders
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * from said copyright holders.
+ */
+
+/*******************************************************************
+**
+** *********************************************************
+** *
+** * File: psout.h
+** *
+** * Contents: Include file for psout.c
+** *
+** * Created By: Roger Helmendach (Liberty Systems)
+** *
+** * Copyright: Copyright 1996 The Open Group, Inc.
+** *
+** *********************************************************
+**
+********************************************************************/
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#ifndef _psout_
+#define _psout_
+
+#include <stdio.h>
+
+typedef enum PsCapEnum_ { PsCButt=0, PsCRound, PsCSquare } PsCapEnum;
+typedef enum PsJoinEnum_ { PsJMiter=0, PsJRound, PsJBevel } PsJoinEnum;
+typedef enum PsArcEnum_ { PsChord, PsPieSlice } PsArcEnum;
+typedef enum PsRuleEnum_ { PsEvenOdd, PsNZWinding } PsRuleEnum;
+typedef enum PsFillEnum_ { PsSolid=0, PsTile, PsStip, PsOpStip } PsFillEnum;
+
+typedef struct PsPointRec_
+{
+ int x;
+ int y;
+} PsPointRec;
+
+typedef PsPointRec *PsPointPtr;
+
+typedef struct PsRectRec_
+{
+ int x;
+ int y;
+ int w;
+ int h;
+} PsRectRec;
+
+typedef PsRectRec *PsRectPtr;
+
+typedef struct PsArcRec_
+{
+ int x;
+ int y;
+ int w;
+ int h;
+ int a1;
+ int a2;
+ PsArcEnum style;
+} PsArcRec;
+
+typedef PsArcRec *PsArcPtr;
+
+#define PSOUT_RECT 0
+#define PSOUT_ARC 1
+#define PSOUT_POINTS 2
+
+typedef struct PsElmRec_
+{
+ int type;
+ int nPoints;
+ union
+ {
+ PsRectRec rect;
+ PsArcRec arc;
+ PsPointPtr points;
+ } c;
+} PsElmRec;
+
+typedef PsElmRec *PsElmPtr;
+
+typedef struct PsClipRec_
+{
+ int nRects;
+ PsRectPtr rects;
+ int nElms;
+ PsElmPtr elms;
+ int nOutterClips;
+ PsRectPtr outterClips;
+} PsClipRec;
+
+typedef PsClipRec *PsClipPtr;
+
+typedef enum PsFTDownloadFontType_
+{
+ PsFontBitmap=0,
+ PsFontType1,
+ PsFontType3
+} PsFTDownloadFontType;
+
+/* Define |PsOutColor| color type which can hold one RGB value
+ * (note: this needs to be |signed| long/long long to represent
+ * special values such as |PSOUTCOLOR_NOCOLOR|)
+ */
+#ifdef PSOUT_USE_DEEPCOLOR
+/* 64bit |PsOutColor| which can hold 16bit R-,G-,B-values */
+#ifdef WIN32
+typedef signed __int64 PsOutColor;
+#else
+# if defined(__alpha__) || defined(__alpha) || \
+ defined(ia64) || defined(__ia64__) || \
+ defined(__sparc64__) || defined(_LP64) || \
+ defined(__s390x__) || \
+ defined(amd64) || defined (__amd64__) || \
+ defined (__powerpc64__) || \
+ (defined(sgi) && (_MIPS_SZLONG == 64))
+typedef signed long PsOutColor;
+# else
+typedef signed long long PsOutColor;
+# endif /* native 64bit platform */
+#endif /* WIN32 */
+
+#define PSOUTCOLOR_TO_REDBITS(clr) ((clr) >> 32)
+#define PSOUTCOLOR_TO_GREENBITS(clr) (((clr) >> 16) & 0xFFFF)
+#define PSOUTCOLOR_TO_BLUEBITS(clr) ((clr) & 0xFFFF)
+#define PSOUTCOLOR_BITS_TO_PSFLOAT(b) ((float)(b) / 65535.)
+#define PSOUTCOLOR_WHITE (0xFFFFFFFFFFFFLL)
+#define PSOUTCOLOR_NOCOLOR (-1LL)
+#define PSOUTCOLOR_TO_RGB24BIT(clr) (((PSOUTCOLOR_TO_REDBITS(clr) >> 8) << 16) | \
+ ((PSOUTCOLOR_TO_GREENBITS(clr) >> 8) << 8) | \
+ ((PSOUTCOLOR_TO_BLUEBITS(clr) >> 8) << 0))
+#else
+/* 32bit |PsOutColor| which can hold 8bit R-,G-,B-values */
+typedef signed long PsOutColor;
+#define PSOUTCOLOR_TO_REDBITS(clr) ((clr) >> 16)
+#define PSOUTCOLOR_TO_GREENBITS(clr) (((clr) >> 8) & 0xFF)
+#define PSOUTCOLOR_TO_BLUEBITS(clr) ((clr) & 0xFF)
+#define PSOUTCOLOR_BITS_TO_PSFLOAT(b) ((float)(b) / 255.)
+#define PSOUTCOLOR_WHITE (0xFFFFFF)
+#define PSOUTCOLOR_NOCOLOR (-1)
+#define PSOUTCOLOR_TO_RGB24BIT(clr) ((PSOUTCOLOR_TO_REDBITS(clr) << 16) | \
+ (PSOUTCOLOR_TO_GREENBITS(clr) << 8) | \
+ (PSOUTCOLOR_TO_BLUEBITS(clr) << 0))
+#endif /* PSOUT_USE_DEEPCOLOR */
+
+#ifdef USE_PSOUT_PRIVATE
+typedef void *voidPtr;
+
+typedef struct PsPatRec_
+{
+ PsFillEnum type;
+ voidPtr tag;
+} PsPatRec;
+
+typedef PsPatRec *PsPatPtr;
+
+typedef struct PsOutRec_
+{
+ FILE *Fp;
+ char Buf[16384];
+ PsOutColor CurColor;
+ int LineWidth;
+ PsCapEnum LineCap;
+ PsJoinEnum LineJoin;
+ int NDashes;
+ int *Dashes;
+ int DashOffset;
+ PsOutColor LineBClr;
+ PsRuleEnum FillRule;
+ char *FontName;
+ int FontSize;
+ float FontMtx[4];
+ int ImageFormat;
+ int RevImage;
+ int NPatterns;
+ int MxPatterns;
+ PsPatPtr Patterns;
+ int ClipType;
+ PsClipRec Clip;
+ int InFrame;
+ int XOff;
+ int YOff;
+
+ PsFillEnum InTile;
+ int ImgSkip;
+ PsOutColor ImgBClr;
+ PsOutColor ImgFClr;
+ int ImgX;
+ int ImgY;
+ int ImgW;
+ int ImgH;
+ int SclW;
+ int SclH;
+
+ Bool isRaw;
+
+ int pagenum;
+
+ int start_image;
+} PsOutRec;
+
+typedef struct PsOutRec_ *PsOutPtr;
+
+extern void S_Flush(PsOutPtr self);
+extern void S_OutNum(PsOutPtr self, float num);
+extern void S_OutTok(PsOutPtr self, char *tok, int cr);
+#else
+typedef struct PsOutRec_ *PsOutPtr;
+#endif /* USE_PSOUT_PRIVATE */
+
+extern PsOutPtr PsOut_BeginFile(FILE *fp, char *title, int orient, int count, int plex,
+ int res, int wd, int ht, Bool raw);
+extern void PsOut_EndFile(PsOutPtr self, int closeFile);
+extern void PsOut_BeginPage(PsOutPtr self, int orient, int count, int plex,
+ int res, int wd, int ht);
+extern void PsOut_EndPage(PsOutPtr self);
+extern void PsOut_DirtyAttributes(PsOutPtr self);
+extern void PsOut_Comment(PsOutPtr self, char *comment);
+extern void PsOut_Offset(PsOutPtr self, int x, int y);
+
+extern void PsOut_Clip(PsOutPtr self, int clpTyp, PsClipPtr clpinf);
+
+extern void PsOut_Color(PsOutPtr self, PsOutColor clr);
+extern void PsOut_FillRule(PsOutPtr self, PsRuleEnum rule);
+extern void PsOut_LineAttrs(PsOutPtr self, int wd, PsCapEnum cap,
+ PsJoinEnum join, int nDsh, int *dsh, int dshOff,
+ PsOutColor bclr);
+extern void PsOut_TextAttrs(PsOutPtr self, char *fnam, int siz, int iso);
+extern void PsOut_TextAttrsMtx(PsOutPtr self, char *fnam, float *mtx, int iso);
+
+extern void PsOut_Polygon(PsOutPtr self, int nPts, PsPointPtr pts);
+extern void PsOut_FillRect(PsOutPtr self, int x, int y, int w, int h);
+extern void PsOut_FillArc(PsOutPtr self, int x, int y, int w, int h,
+ float ang1, float ang2, PsArcEnum style);
+
+extern void PsOut_Lines(PsOutPtr self, int nPts, PsPointPtr pts);
+extern void PsOut_Points(PsOutPtr self, int nPts, PsPointPtr pts);
+extern void PsOut_DrawRect(PsOutPtr self, int x, int y, int w, int h);
+extern void PsOut_DrawArc(PsOutPtr self, int x, int y, int w, int h,
+ float ang1, float ang2);
+
+extern void PsOut_Text(PsOutPtr self, int x, int y, char *text, int textl,
+ PsOutColor bclr);
+extern void PsOut_Text16(PsOutPtr self, int x, int y, unsigned short *text, int textl, PsOutColor bclr);
+
+extern void PsOut_BeginImage(PsOutPtr self, PsOutColor bclr, PsOutColor fclr, int x, int y,
+ int w, int h, int sw, int sh, int format);
+extern void PsOut_BeginImageIM(PsOutPtr self, PsOutColor bclr, PsOutColor fclr, int x, int y,
+ int w, int h, int sw, int sh, int format);
+extern void PsOut_EndImage(PsOutPtr self);
+extern void PsOut_OutImageBytes(PsOutPtr self, int nBytes, char *bytes);
+
+extern void PsOut_BeginFrame(PsOutPtr self, int xoff, int yoff, int x, int y,
+ int w, int h);
+extern void PsOut_EndFrame(PsOutPtr self);
+
+extern int PsOut_BeginPattern(PsOutPtr self, void *tag, int w, int h,
+ PsFillEnum type, PsOutColor bclr, PsOutColor fclr);
+extern void PsOut_EndPattern(PsOutPtr self);
+extern void PsOut_SetPattern(PsOutPtr self, void *tag, PsFillEnum type);
+
+extern void PsOut_RawData(PsOutPtr self, char *data, int len);
+
+extern int PsOut_DownloadType1(PsOutPtr self, const char *auditmsg, const char *name, const char *fname);
+
+extern int PsOut_DownloadFreeType1(PsOutPtr self, const char *psfontname, FontPtr pFont, long block_offset);
+extern int PsOut_DownloadFreeType3(PsOutPtr self, const char *psfontname, FontPtr pFont, long block_offset);
+
+extern int PsOut_DownloadFreeType(PsOutPtr self, PsFTDownloadFontType downloadfonttype, const char *psfontname, FontPtr pFont, long block_offset);
+extern void PsOut_Get_FreeType_Glyph_Name( char *destbuf, FontPtr pFont, unsigned long x11fontindex);
+extern void PsOut_FreeType_Text(FontPtr pFont, PsOutPtr self, int x, int y, char *text, int textl);
+extern void PsOut_FreeType_Text16(FontPtr pFont, PsOutPtr self, int x, int y, unsigned short *text, int textl);
+
+extern void PsOut_FreeType_TextAttrs16(PsOutPtr self, char *fnam, int siz, int iso);
+extern void PsOut_FreeType_TextAttrsMtx16(PsOutPtr self, char *fnam, float *mtx, int iso);
+#endif
diff --git a/nx-X11/programs/Xserver/Xprint/ps/psout_ft.c b/nx-X11/programs/Xserver/Xprint/ps/psout_ft.c
new file mode 100644
index 000000000..34cb6a54d
--- /dev/null
+++ b/nx-X11/programs/Xserver/Xprint/ps/psout_ft.c
@@ -0,0 +1,335 @@
+
+/*
+Copyright (c) 2003-2004 Roland Mainz <roland.mainz@nrubsig.org>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+#include "os.h"
+#define USE_PSOUT_PRIVATE 1
+#include "psout.h"
+
+#include <ft2build.h>
+#include FT_FREETYPE_H
+#include FT_TYPE1_TABLES_H
+
+#include <X11/Xproto.h>
+#include <X11/fonts/font.h>
+#include <X11/fonts/fontstruct.h>
+#include <X11/fonts/fntfilst.h>
+#include <X11/fonts/fontutil.h>
+#include <X11/fonts/fontenc.h>
+#include "ft.h"
+#define NOT_IN_FTFUNCS
+#include "ftfuncs.h"
+#include "servermd.h" /* needed for endian test (IMAGE_BYTE_ORDER) */
+
+#define USE_FT_PS_NAMES 1
+
+#ifdef USE_FT_PS_NAMES
+void PsOut_Get_FreeType_Glyph_Name( char *destbuf, FontPtr pFont, unsigned long x11fontindex)
+{
+ FTFontPtr tf = (FTFontPtr)pFont->fontPrivate;
+ FT_Face ttface = tf->instance->face->face;
+ FT_Error error;
+ char buf[256];
+ unsigned long ftindex;
+
+ /* Remap X11 font index to FreeType font index */
+ ftindex = FTRemap(ttface, &tf->mapping, x11fontindex);
+
+ if( FT_Has_PS_Glyph_Names(ttface) )
+ {
+ error = FT_Get_Glyph_Name(ttface, ftindex, buf, 64);
+ }
+ else
+ {
+ error = 1;
+ }
+
+ if( error )
+ {
+ /* Check for unicode mapping
+ * See Adobe document "Unicode and Glyph Names"
+ * (http://partners.adobe.com/asn/tech/type/unicodegn.jsp)
+ */
+ if( (tf->mapping.mapping->type == FONT_ENCODING_UNICODE) &&
+ (ftindex < 0xFFFE) )
+ {
+ sprintf(buf, "uni%04lx", ftindex);
+ }
+ else
+ {
+ sprintf(buf, "ch%02lx", ftindex);
+ }
+ }
+
+ strcpy(destbuf, buf);
+}
+#endif /* USE_FT_PS_NAMES */
+
+int PsOut_DownloadFreeType(PsOutPtr self, PsFTDownloadFontType downloadfonttype, const char *psfontname, FontPtr pFont, long block_offset)
+{
+ switch(downloadfonttype)
+ {
+ case PsFontType3:
+ return PsOut_DownloadFreeType3(self, psfontname, pFont, block_offset);
+ case PsFontType1:
+ return PsOut_DownloadFreeType1(self, psfontname, pFont, block_offset);
+ default:
+ FatalError("PS DDX: PsOut_DownloadFreeType(downloadfonttype='%d' not implemented\n",
+ (int)downloadfonttype);
+ return 0; /* NO-OP, FatalError() will call |exit()| */
+ }
+}
+
+/* cloned from |PsOut_TextAttrs16| */
+void
+PsOut_FreeType_TextAttrs16(PsOutPtr self, char *fnam, int siz, int iso)
+{
+ int i;
+ if( self->FontName && strcmp(fnam, self->FontName)==0 &&
+ siz==self->FontSize ) return;
+ if( self->FontName ) xfree(self->FontName);
+ self->FontName = (char *)xalloc(strlen(fnam)+1);
+ strcpy(self->FontName, fnam);
+ self->FontSize = siz;
+ for( i=0 ; i<4 ; i++ ) self->FontMtx[i] = -1.;
+}
+
+/* cloned from |PsOut_TextAttrsMtx16| */
+void
+PsOut_FreeType_TextAttrsMtx16(PsOutPtr self, char *fnam, float *mtx, int iso)
+{
+ int i;
+ if( self->FontName && strcmp(fnam, self->FontName)==0 &&
+ mtx[0]==self->FontMtx[0] && mtx[1]==self->FontMtx[1] &&
+ mtx[2]==self->FontMtx[2] && mtx[3]==self->FontMtx[3] ) return;
+ if( self->FontName ) xfree(self->FontName);
+ self->FontName = (char *)xalloc(strlen(fnam)+1);
+ strcpy(self->FontName, fnam);
+ for( i=0 ; i<4 ; i++ ) self->FontMtx[i] = mtx[i];
+ self->FontSize = -1;
+}
+
+static
+int FT_Get_CharcellMetricsCharacterHeight(FontPtr pFont)
+{
+ FTFontPtr ftfont = (FTFontPtr)pFont->fontPrivate;
+
+ return ftfont->instance->charcellMetrics->ascent +
+ ftfont->instance->charcellMetrics->descent;
+}
+
+static
+int FT_Get_CharcellMetricsCharacterWidth(FontPtr pFont)
+{
+ FTFontPtr ftfont = (FTFontPtr)pFont->fontPrivate;
+
+ if( ftfont->instance->spacing != FT_PROPORTIONAL )
+ {
+ int width = ftfont->instance->charcellMetrics->characterWidth;
+
+ /* If the font uses a matrix make sure we transform the |characterWidth|
+ * back to it's original value since we download the untransformed font
+ * and use a PostScript transformation matrix to transform the font when
+ * rendering the text
+ */
+ if( ftfont->instance->transformation.nonIdentity )
+ {
+ FT_Vector v;
+
+ FT_Matrix m = ftfont->instance->transformation.matrix;
+ (void)FT_Matrix_Invert(&m); /* FixMe: We should check the return code */
+ v.x = width;
+ v.y = FT_Get_CharcellMetricsCharacterHeight(pFont);
+ FT_Vector_Transform(&v, &m);
+ width = v.x;
+ }
+
+ return width;
+ }
+
+ return 0;
+}
+
+void
+PsOut_FreeType_Text(FontPtr pFont, PsOutPtr self, int x, int y, char *text, int textl)
+{
+ int i;
+ int xo = self->XOff,
+ yo = self->YOff;
+ char buf[256];
+ int cwidth = FT_Get_CharcellMetricsCharacterWidth(pFont);
+
+ if( self->InFrame || self->InTile ) xo = yo = 0;
+ x += xo; y += yo;
+
+ S_OutNum(self, (float)x);
+ S_OutNum(self, (float)y);
+ S_OutTok(self, "moveto", 1);
+
+ S_OutTok(self, "[ ", 0);
+
+ for( i = 0 ; i < textl ; i++ )
+ {
+#ifdef USE_FT_PS_NAMES
+ char namebuf[256];
+ unsigned int ch = text[i]&0xFF;
+ unsigned long block_offset = 0;
+ PsOut_Get_FreeType_Glyph_Name(namebuf, pFont, ch+block_offset);
+
+ sprintf(buf, "/%s ", namebuf);
+#else
+ sprintf(buf, "/ch%02x ", text[i]&0xFF);
+#endif /* USE_FT_PS_NAMES */
+ S_OutTok(self, buf, 0);
+ }
+
+ /* Check whether we have any special spacing requirements (e.g. non-proportional fonts) ... */
+ if( cwidth != 0 )
+ {
+ /* If the we use a matrix to render the font (instead of using |self->FontSize|)
+ * we must apply the matrix to the "rmoveto" which is used to force the exact
+ * character width. The "trmoveto" macro will do that for us...
+ */
+ if( self->FontSize == -1 )
+ {
+ sprintf(buf, "]{gs glyphshow gr %d 0 trmoveto}fa", cwidth);
+ }
+ else
+ {
+ sprintf(buf, "]{gs glyphshow gr %d 0 rm}fa", cwidth);
+ }
+ }
+ else
+ {
+ sprintf(buf, "]{glyphshow}fa");
+ }
+ S_OutTok(self, buf, 0);
+}
+
+/* XXX: |PsOut_FreeType_Text16| should be rewritten - currently it uses lame,
+ * slow hacks and makes some risky assumtions about how |PsOut_Text16|
+ * allocates memory */
+void
+PsOut_FreeType_Text16(FontPtr pFont, PsOutPtr self, int x, int y, unsigned short *text, int textl)
+{
+ int i;
+ int xo = self->XOff,
+ yo = self->YOff;
+ unsigned short c,
+ c_hiByte,
+ c_lowByte,
+ fontPage;
+ long lastFontPage = -1;
+ char baseFontName[256];
+ char buf[256];
+
+ if( self->InFrame || self->InTile ) xo = yo = 0;
+ x += xo; y += yo;
+
+ strcpy(baseFontName, self->FontName);
+
+ S_OutNum(self, (float)x);
+ S_OutNum(self, (float)y);
+ S_OutTok(self, "moveto", 1);
+
+ for( i = 0 ; i < textl ; i++ )
+ {
+ c = text[i];
+#if IMAGE_BYTE_ORDER == LSBFirst
+ c_hiByte = c & 0x00FF;
+ c_lowByte = (c >> 8) & 0x00FF;
+#elif IMAGE_BYTE_ORDER == MSBFirst
+ c_hiByte = (c >> 8) & 0x00FF;
+ c_lowByte = c & 0x00FF;
+#else
+#error Unsupported byte order
+#endif
+ fontPage = c_hiByte;
+
+ if( fontPage != lastFontPage )
+ {
+ if( fontPage > 0 )
+ {
+ sprintf(buf, "%s_%x", baseFontName, fontPage);
+ }
+ else
+ {
+ sprintf(buf, "%s", baseFontName);
+ }
+
+ if( self->FontSize == -1 )
+ {
+ PsOut_TextAttrsMtx(self, buf, self->FontMtx, FALSE);
+ }
+ else
+ {
+ PsOut_TextAttrs(self, buf, self->FontSize, FALSE);
+ }
+ lastFontPage = fontPage;
+ }
+
+#ifdef USE_FT_PS_NAMES
+ {
+ char namebuf[256];
+ unsigned int ch = c_lowByte;
+ unsigned long block_offset = c_hiByte * 0x100 /* same as c_hiByte << 8 */;
+ int cwidth = FT_Get_CharcellMetricsCharacterWidth(pFont);
+ PsOut_Get_FreeType_Glyph_Name(namebuf, pFont, ch+block_offset);
+
+ /* Check whether we have any special spacing requirements (e.g. non-proportional fonts) ... */
+ if( cwidth != 0 )
+ {
+ /* If the we use a matrix to render the font (instead of using |self->FontSize|)
+ * we must apply the matrix to the "rmoveto" which is used to force the exact
+ * character width. The "trmoveto" macro will do that for us...
+ */
+ if( self->FontSize == -1 )
+ {
+ sprintf(buf, "gs /%s glyphshow gr %d 0 trmoveto", namebuf, cwidth);
+ }
+ else
+ {
+ sprintf(buf, "gs /%s glyphshow gr %d 0 rm", namebuf, cwidth);
+ }
+ }
+ else
+ {
+ sprintf(buf, "/%s glyphshow", namebuf);
+ }
+ }
+#else
+ sprintf(buf, "/ch%02x glyphshow", c_lowByte);
+#endif /* USE_FT_PS_NAMES */
+ S_OutTok(self, buf, 1);
+ }
+
+ if( self->FontName ) xfree(self->FontName);
+ self->FontName = (char *)xalloc(strlen(baseFontName)+1);
+ strcpy(self->FontName, baseFontName);
+}
+
diff --git a/nx-X11/programs/Xserver/Xprint/ps/psout_ftpstype1.c b/nx-X11/programs/Xserver/Xprint/ps/psout_ftpstype1.c
new file mode 100644
index 000000000..19e1bde18
--- /dev/null
+++ b/nx-X11/programs/Xserver/Xprint/ps/psout_ftpstype1.c
@@ -0,0 +1,185 @@
+
+/*
+Copyright (c) 2003-2004 Roland Mainz <roland.mainz@nrubsig.org>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+#include <sys/wait.h>
+
+#include "os.h"
+#define USE_PSOUT_PRIVATE 1
+#include "psout.h"
+
+#include <ft2build.h>
+#include FT_FREETYPE_H
+
+#include <X11/Xproto.h>
+#include <X11/fonts/font.h>
+#include <X11/fonts/fontstruct.h>
+#include <X11/fonts/fntfilst.h>
+#include <X11/fonts/fontutil.h>
+#include <X11/fonts/fontenc.h>
+#include "ft.h"
+#define NOT_IN_FTFUNCS
+#include "ftfuncs.h"
+
+int do_debug_ft2pt1 = FALSE;
+int do_enable_ft2pt1_optimizer = FALSE;
+
+/* Defined in ttf2pt1.c */
+int ft2pt1_main(int argc, char **argv,
+ FTFontPtr tf, const char *download_psfontname, unsigned long download_font_block_offset);
+
+/* Download FreeType outlines as PS Type1 font */
+int PsOut_DownloadFreeType1(PsOutPtr self, const char *psfontname, FontPtr pFont, long block_offset)
+{
+ FTFontPtr tf;
+ FT_Face face;
+ int ft2pt1_numargs = 0;
+ char *ft2pt1_args[40];
+ char *pstype1filename_prefix;
+ char pstype1filename[PATH_MAX+1];
+ int ft2pt1_main_retval;
+ pid_t childpid;
+
+ tf = (FTFontPtr)pFont->fontPrivate;
+ face = tf->instance->face->face;
+
+ /* Set debugging flags */
+ do_debug_ft2pt1 = (getenv("XPRT_PSDDX_DO_DEBUG_FT2PT1") != NULL);
+ do_enable_ft2pt1_optimizer = (getenv("XPRT_PSDDX_DO_ENABLE_FT2PT1_OPTIMIZER") != NULL);
+
+ if( do_debug_ft2pt1 )
+ {
+ fprintf(stderr, "# Converting FT2 font to PS Type1 filename='%s', ttface=%lx\n", tf->instance->face->filename, (long)face);
+ }
+
+ pstype1filename_prefix = tempnam(NULL, "Xprt_");
+
+ ft2pt1_args[ft2pt1_numargs] = "ft2pt1"; ft2pt1_numargs++;
+ ft2pt1_args[ft2pt1_numargs] = "-Ob"; ft2pt1_numargs++;
+ ft2pt1_args[ft2pt1_numargs] = "-e"; ft2pt1_numargs++;
+ ft2pt1_args[ft2pt1_numargs] = "-a"; ft2pt1_numargs++;
+ ft2pt1_args[ft2pt1_numargs] = "-Ga"; ft2pt1_numargs++;
+ if( do_enable_ft2pt1_optimizer )
+ {
+ /* Scale fonts to a 1000x1000 matrix */
+ ft2pt1_args[ft2pt1_numargs] = "-Ot"; ft2pt1_numargs++;
+ }
+ else
+ {
+ /* Disable the ttf2pt1 optimisations */
+ ft2pt1_args[ft2pt1_numargs] = "-Ou"; ft2pt1_numargs++;
+ ft2pt1_args[ft2pt1_numargs] = "-Oo"; ft2pt1_numargs++;
+ ft2pt1_args[ft2pt1_numargs] = "-Os"; ft2pt1_numargs++;
+ ft2pt1_args[ft2pt1_numargs] = "-Oh"; ft2pt1_numargs++;
+ }
+
+ if( !do_debug_ft2pt1 )
+ {
+ ft2pt1_args[ft2pt1_numargs] = "-W 0"; ft2pt1_numargs++;
+ }
+ ft2pt1_args[ft2pt1_numargs] = tf->instance->face->filename; ft2pt1_numargs++;
+ ft2pt1_args[ft2pt1_numargs] = pstype1filename_prefix; ft2pt1_numargs++;
+ ft2pt1_args[ft2pt1_numargs] = NULL;
+
+/* XXX: ttf2pt1 has lots of leaks and global vars which are not cleaned-up
+ * As long this problem exists we will simply fork() and call the converter
+ * from the child process (all resources are free'ed when the child process
+ * exists) as a workaround.
+ */
+#define FT2PT1_NEEDS_SEPERATE_PROCESS 1
+
+#ifdef FT2PT1_NEEDS_SEPERATE_PROCESS
+ /* Flush internal buffer and then the stdio stream before fork()! */
+ S_Flush(self);
+ fflush(self->Fp);
+
+ childpid = fork();
+ switch(childpid)
+ {
+ case -1:
+ FatalError("PS DDX internal error: Cannot fork() converter child process, errno=%d\n", (int)errno);
+ break;
+ case 0: /* child */
+ fclose(self->Fp);
+ self->Fp = NULL;
+
+ ft2pt1_main_retval = ft2pt1_main(ft2pt1_numargs, ft2pt1_args, tf, psfontname, block_offset);
+ if( do_debug_ft2pt1 )
+ {
+ fprintf(stderr, "## ft2pt1_main returned %d (child)\n", ft2pt1_main_retval);
+ }
+ exit(ft2pt1_main_retval);
+ break;
+ default: /* parent */
+ waitpid(childpid, &ft2pt1_main_retval, 0);
+ break;
+ }
+
+ if( do_debug_ft2pt1 )
+ {
+ fprintf(stderr, "## ft2pt1_main returned %d (parent)\n", ft2pt1_main_retval);
+ }
+#else
+ S_Flush(self);
+
+ ft2pt1_main_retval = ft2pt1_main(ft2pt1_numargs, ft2pt1_args, tf, psfontname, block_offset);
+ if( do_debug_ft2pt1 )
+ {
+ fprintf(stderr, "## ft2pt1_main returned %d (child)\n", ft2pt1_main_retval);
+ }
+#endif /* FT2PT1_NEEDS_SEPERATE_PROCESS */
+
+ if( ft2pt1_main_retval != EXIT_SUCCESS )
+ {
+ FatalError("PS DDX internal error while converting FreeType font '%s' to PS Type1, error=%d\n",
+ tf->instance->face->filename, ft2pt1_main_retval);
+ }
+
+ sprintf(pstype1filename, "%s.pfa", pstype1filename_prefix);
+ if( do_debug_ft2pt1 )
+ {
+ fprintf(stderr, "# Downloading converted FT2/PS Type1 filename='%s'\n", pstype1filename);
+ }
+
+ PsOut_DownloadType1(self, "PsOut_DownloadFreeType1", psfontname, pstype1filename);
+
+ if( !do_debug_ft2pt1 )
+ {
+ unlink(pstype1filename);
+ }
+
+ free(pstype1filename_prefix);
+
+ S_Flush(self);
+
+ return 0;
+}
+
+
diff --git a/nx-X11/programs/Xserver/Xprint/ps/psout_ftpstype3.c b/nx-X11/programs/Xserver/Xprint/ps/psout_ftpstype3.c
new file mode 100644
index 000000000..e9782e499
--- /dev/null
+++ b/nx-X11/programs/Xserver/Xprint/ps/psout_ftpstype3.c
@@ -0,0 +1,468 @@
+
+/*
+Copyright (c) 2003-2004 Roland Mainz <roland.mainz@nrubsig.org>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+#include "os.h"
+#define USE_PSOUT_PRIVATE 1
+#include "psout.h"
+
+#include <ft2build.h>
+#include FT_FREETYPE_H
+#include FT_TRUETYPE_TABLES_H
+#include FT_BBOX_H
+#include FT_GLYPH_H
+
+#include FT_CONFIG_CONFIG_H
+#include FT_CONFIG_OPTIONS_H
+#include FT_ERRORS_H
+#include FT_SYSTEM_H
+#include FT_IMAGE_H
+#include FT_TYPES_H
+#include FT_OUTLINE_H
+#include FT_MODULE_H
+#include FT_RENDER_H
+#include FT_TYPE1_TABLES_H
+#include FT_TRUETYPE_IDS_H
+#include FT_TRUETYPE_TAGS_H
+#include FT_CACHE_H
+#include FT_CACHE_IMAGE_H
+#include FT_CACHE_SMALL_BITMAPS_H
+#include FT_MULTIPLE_MASTERS_H
+#include FT_SFNT_NAMES_H
+
+#define USE_FT_INTERNALS 1
+#ifdef USE_FT_INTERNALS
+#include FT_INTERNAL_TYPE1_TYPES_H
+#include "t42types.h"
+#include FT_INTERNAL_OBJECTS_H
+#endif /* USE_FT_INTERNALS */
+
+#include <X11/Xproto.h>
+#include <X11/fonts/font.h>
+#include <X11/fonts/fontstruct.h>
+#include <X11/fonts/fntfilst.h>
+#include <X11/fonts/fontutil.h>
+#include <X11/fonts/fontenc.h>
+#include "ft.h"
+#define NOT_IN_FTFUNCS
+#include "ftfuncs.h"
+
+struct ft2info
+{
+ FontPtr pFont;
+ FTFontPtr tf;
+ FT_Face ttface;
+ struct
+ {
+ char *full_name;
+ char *copyright;
+ char *family;
+ char *subfamily;
+ char *version;
+ } nameid;
+ TT_Postscript *ttpostscript;
+ TT_Header *ttheader;
+};
+
+/* Local prototypes */
+static FT_Error PSType3_createOutlineGlyphs(FILE *out, struct ft2info *ti, unsigned long unicode, const char *psglyphname);
+static int PSType3_generateOutlineFont(FILE *out, const char *psfontname, struct ft2info *ti, long block_offset);
+
+extern FT_Library ftypeLibrary; /* defined in xc/lib/font/FreeType/ftfuncs.c */
+
+#define USE_FT_PS_NAMES 1
+
+static
+FT_Error PSType3_createOutlineGlyphs( FILE *out, struct ft2info *ti, unsigned long x11fontindex, const char *psglyphname )
+{
+ unsigned long ftindex;
+ FT_BBox bbox;
+ FT_Error error;
+ FT_Outline outline;
+
+ /* Remap X11 font index to FreeType font index */
+ ftindex = FTRemap(ti->ttface, &ti->tf->mapping, x11fontindex);
+
+ error = FT_Load_Glyph(ti->ttface, ftindex, (FT_LOAD_NO_BITMAP | FT_LOAD_NO_SCALE | FT_LOAD_NO_HINTING));
+ if( error )
+ {
+ fprintf(stderr, "PSType3_createOutlineGlyphs: FT_Load_Glyph() failure, error=%d\n", (int)error);
+ return error;
+ }
+
+ outline = ti->ttface->glyph->outline;
+
+ FT_Outline_Get_CBox(&outline, &bbox);
+
+ fprintf(out, "/%s {\n", psglyphname);
+ fprintf(out, "%ld 0 %ld %ld %ld %ld setcachedevice\n",
+ (signed long)ti->ttface->glyph->metrics.horiAdvance,
+ (long)bbox.xMin,
+ (long)bbox.yMin,
+ (long)bbox.xMax,
+ (long)bbox.yMax);
+
+ if( outline.n_contours > 0 )
+ {
+ long i,
+ j,
+ k, k1,
+ cs, ce,
+ nguide,
+ contour_start,
+ contour_end,
+ last_point;
+ Bool first;
+ FT_Vector *vec;
+
+ contour_start = ce = 0;
+
+ vec = outline.points;
+ last_point = outline.n_points;
+
+ i = j = k = 0;
+ first = TRUE;
+
+ while( i <= outline.contours[outline.n_contours - 1] )
+ {
+ contour_end = outline.contours[j];
+
+ if( first )
+ {
+ fprintf(out, "%ld %ld moveto\n", vec[i].x, vec[i].y);
+ contour_start = i;
+ first = FALSE;
+ }
+ else if( outline.tags[i] & FT_CURVE_TAG_ON )
+ {
+ fprintf(out, "%ld %ld lineto\n", vec[i].x, vec[i].y);
+ }
+ else
+ {
+ Bool finished = FALSE;
+
+ cs = i-1;
+ nguide = 0;
+ while( !finished )
+ {
+ if( i == contour_end+1 )
+ {
+ ce = contour_start;
+ finished = TRUE;
+ }
+ else if( outline.tags[i] & FT_CURVE_TAG_ON )
+ {
+ ce = i;
+ finished = TRUE;
+ }
+ else
+ {
+ i++;
+ nguide++;
+ }
+ }
+
+ switch( nguide )
+ {
+ case 0:
+ fprintf(out, "%ld %ld lineto\n", vec[ce].x, vec[ce].y);
+ break;
+
+ case 1:
+ fprintf(out, "%ld %ld %ld %ld %ld %ld curveto\n",
+ (vec[cs].x+2*vec[cs+1].x)/3,
+ (vec[cs].y+2*vec[cs+1].y)/3,
+ (2*vec[cs+1].x+vec[ce].x)/3,
+ (2*vec[cs+1].y+vec[ce].y)/3,
+ vec[ce].x, vec[ce].y);
+ break;
+
+ case 2:
+ fprintf(out, "%ld %ld %ld %ld %ld %ld curveto\n",
+ (-vec[cs].x+4*vec[cs+1].x)/3,
+ (-vec[cs].y+4*vec[cs+1].y)/3,
+ (4*vec[cs+2].x-vec[ce].x)/3,
+ (4*vec[cs+2].y-vec[ce].y)/3,
+ vec[ce].x, vec[ce].y);
+ break;
+
+ case 3:
+ fprintf(out, "%ld %ld %ld %ld %ld %ld curveto\n",
+ (vec[cs].x+2*vec[cs+1].x)/3,
+ (vec[cs].y+2*vec[cs+1].y)/3,
+ (5*vec[cs+1].x+vec[cs+2].x)/6,
+ (5*vec[cs+1].y+vec[cs+2].y)/6,
+ (vec[cs+1].x+vec[cs+2].x)/2,
+ (vec[cs+1].y+vec[cs+2].y)/2);
+
+ fprintf(out, "%ld %ld %ld %ld %ld %ld curveto\n",
+ (vec[cs+1].x+5*vec[cs+2].x)/6,
+ (vec[cs+1].y+5*vec[cs+2].y)/6,
+ (5*vec[cs+2].x+vec[cs+3].x)/6,
+ (5*vec[cs+2].y+vec[cs+3].y)/6,
+ (vec[cs+3].x+vec[cs+2].x)/2,
+ (vec[cs+3].y+vec[cs+2].y)/2);
+
+ fprintf(out, "%ld %ld %ld %ld %ld %ld curveto\n",
+ (vec[cs+2].x+5*vec[cs+3].x)/6,
+ (vec[cs+2].y+5*vec[cs+3].y)/6,
+ (2*vec[cs+3].x+vec[ce].x)/3,
+ (2*vec[cs+3].y+vec[ce].y)/3,
+ vec[ce].x, vec[ce].y);
+ break;
+
+ default: /* anything |nguide > 3| */
+ k1 = cs + nguide;
+
+ fprintf(out, "%ld %ld %ld %ld %ld %ld curveto\n",
+ (vec[cs].x+2*vec[cs+1].x)/3,
+ (vec[cs].y+2*vec[cs+1].y)/3,
+ (5*vec[cs+1].x+vec[cs+2].x)/6,
+ (5*vec[cs+1].y+vec[cs+2].y)/6,
+ (vec[cs+1].x+vec[cs+2].x)/2,
+ (vec[cs+1].y+vec[cs+2].y)/2);
+
+ for( k = cs+2 ; k <= k1-1 ; k++ )
+ {
+ fprintf(out, "%ld %ld %ld %ld %ld %ld curveto\n",
+ (vec[k-1].x+5*vec[k].x)/6,
+ (vec[k-1].y+5*vec[k].y)/6,
+ (5*vec[k].x+vec[k+1].x)/6,
+ (5*vec[k].y+vec[k+1].y)/6,
+ (vec[k].x+vec[k+1].x)/2,
+ (vec[k].y+vec[k+1].y)/2);
+ }
+
+ fprintf(out, "%ld %ld %ld %ld %ld %ld curveto\n",
+ (vec[k1-1].x+5*vec[k1].x)/6,
+ (vec[k1-1].y+5*vec[k1].y)/6,
+ (2*vec[k1].x+vec[ce].x)/3,
+ (2*vec[k1].y+vec[ce].y)/3,
+ vec[ce].x, vec[ce].y);
+ break;
+ }
+ }
+
+ if( i >= contour_end )
+ {
+ fprintf(out, "closepath\n");
+ first = TRUE;
+ i = contour_end + 1;
+ j++;
+ }
+ else
+ {
+ i++;
+ }
+ }
+ }
+
+ fprintf(out, "fill } bind def\n");
+
+ return 0;
+}
+
+#ifdef USE_FT_INTERNALS
+static FT_BBox *
+FT_Get_PS_Font_BBox( FT_Face face )
+{
+ const char *driver_name;
+ FT_BBox *font_bbox = NULL;
+
+ if ( face && face->driver && face->driver->root.clazz )
+ {
+ driver_name = face->driver->root.clazz->module_name;
+ if ( ft_strcmp( driver_name, "type1" ) == 0 )
+ font_bbox = &(((T1_Face)face)->type1.font_bbox);
+ else if ( ft_strcmp( driver_name, "t1cid" ) == 0 )
+ font_bbox = &(((CID_Face)face)->cid.font_bbox);
+ else if ( ft_strcmp( driver_name, "type42" ) == 0 )
+ font_bbox = &(((T42_Face)face)->type1.font_bbox);
+ }
+
+ return font_bbox;
+}
+#endif /* USE_FT_INTERNALS */
+
+static
+int PSType3_generateOutlineFont(FILE *out, const char *psfontname, struct ft2info *ti, long block_offset)
+{
+ long i;
+ double scaler;
+ const int numchars = 256;
+#ifdef USE_FT_PS_NAMES
+ int linewidth = 0;
+#endif /* USE_FT_PS_NAMES */
+
+ fprintf(out, "%%%%BeginFont: %s\n", psfontname);
+ fprintf(out, "22 dict begin\n");
+ fprintf(out, "/FontType 3 def\n");
+ fprintf(out, "/StrokeWidth 0 def\n");
+ fprintf(out, "/PaintType 0 def\n");
+ fprintf(out, "/FontName (%s) def\n", psfontname);
+ fprintf(out, "/FontInfo 9 dict dup begin\n");
+ fprintf(out, " /FullName (%s) def\n", ti->nameid.full_name?ti->nameid.full_name:psfontname);
+ fprintf(out, " /Notice (%s) def\n", ti->nameid.copyright?ti->nameid.copyright:"nothing here");
+ fprintf(out, " /FamilyName (%s) def\n", ti->nameid.family?ti->nameid.family:psfontname);
+ fprintf(out, " /Weight (%s) def\n", ti->nameid.subfamily?ti->nameid.subfamily:"Regular");
+ fprintf(out, " /version (%s) def\n", ti->nameid.version?ti->nameid.version:"0.1");
+
+ if( ti->ttpostscript )
+ {
+ fprintf(out, " /italicAngle %.9g def\n", (double)ti->ttpostscript->italicAngle);
+ fprintf(out, " /underlineThickness %d def\n", (int)ti->ttpostscript->underlineThickness);
+ fprintf(out, " /underlinePosition %d def\n", (int)ti->ttpostscript->underlinePosition);
+ fprintf(out, " /isFixedPitch %s def\n", ((ti->ttpostscript->isFixedPitch)?("true"):("false")));
+ }
+ else
+ {
+ fprintf(out, " /italicAngle %.9g def\n", 0.0);
+ fprintf(out, " /underlineThickness %d def\n", 100);
+ fprintf(out, " /underlinePosition %d def\n", 0);
+ fprintf(out, " /isFixedPitch false def\n");
+ }
+
+ fprintf(out, "end def\n");
+
+ scaler = (1000.0 / (double)ti->ttface->units_per_EM) / 1000.0;
+ fprintf(out, "/FontMatrix [%.9g 0 0 %.9g 0 0] def\n", scaler, scaler);
+
+ if( ti->ttheader )
+ {
+ fprintf(out, "/FontBBox [%d %d %d %d] def\n",
+ (int)ti->ttheader->xMin,
+ (int)ti->ttheader->yMin,
+ (int)ti->ttheader->xMax,
+ (int)ti->ttheader->yMax);
+ }
+ else
+ {
+ FT_BBox *font_bbox = FT_Get_PS_Font_BBox(ti->ttface);
+ fprintf(out, "/FontBBox [%d %d %d %d] def\n",
+ (int)font_bbox->xMin,
+ (int)font_bbox->yMin,
+ (int)font_bbox->xMax,
+ (int)font_bbox->yMax);
+ }
+
+ fprintf(out, "/Encoding [\n");
+ for( i = 0 ; i < 256 ; i++ )
+ {
+#ifdef USE_FT_PS_NAMES
+ char namebuf[256];
+ PsOut_Get_FreeType_Glyph_Name(namebuf, ti->pFont, i+block_offset);
+ linewidth += strlen(namebuf) + 2;
+ fprintf(out, "/%s%s", namebuf, (linewidth > 70)?(linewidth = 0, "\n"):(" "));
+#else
+ fprintf(out, "/ch%02x%s", i, (((i % 10) == 9)?("\n"):(" ")));
+#endif /* USE_FT_PS_NAMES */
+ }
+ fprintf(out, "] def\n");
+
+ fprintf(out, "/CharProcs %d dict def CharProcs begin\n", (int)(numchars + 1));
+ fprintf(out, "/.notdef {\n"
+ "1000 0 0 0 0 0 setcachedevice\n"
+ "fill } bind def\n");
+ for( i = 0 ; i < numchars ; i++ )
+ {
+ char buf[32];
+#ifdef USE_FT_PS_NAMES
+ char namebuf[256];
+ PsOut_Get_FreeType_Glyph_Name(namebuf, ti->pFont, i+block_offset);
+ sprintf(buf, "%s ", namebuf);
+#else
+ sprintf(buf, "ch%02lx ", i);
+#endif /* USE_FT_PS_NAMES */
+ PSType3_createOutlineGlyphs(out, ti, i+block_offset, buf);
+ }
+ fprintf(out, "end\n"
+ "/BuildGlyph {\n"
+ " exch /CharProcs get exch\n"
+ " 2 copy known not {pop /.notdef} if get exec } bind def\n"
+ "/BuildChar { 1 index /Encoding get exch get\n"
+ " 1 index /Encoding get exec } bind def\n");
+ fprintf(out, "currentdict end /%s exch definefont pop\n", psfontname);
+ fprintf(out, "%%EndFont\n");
+
+ return 0;
+}
+
+static
+char *FT_Get_TT_NAME_ID(FT_Face ttface, int index)
+{
+ FT_SfntName name;
+ char *s;
+
+ if( index >= FT_Get_Sfnt_Name_Count(ttface) )
+ return NULL;
+
+ FT_Get_Sfnt_Name(ttface, index, &name);
+ s = (char *)malloc(name.string_len+2);
+ if( !s )
+ return NULL;
+ memcpy(s, (char *)name.string, name.string_len);
+ s[name.string_len] = '\0';
+ return s;
+}
+
+int PsOut_DownloadFreeType3(PsOutPtr self, const char *psfontname, FontPtr pFont, long block_offset)
+{
+ struct ft2info cft2info = { 0 };
+ struct ft2info *ti = &cft2info;
+
+ S_Flush(self);
+
+ ti->tf = (FTFontPtr)pFont->fontPrivate;
+ ti->ttface = ti->tf->instance->face->face;
+ ti->pFont = pFont;
+#ifdef DEBUG_gisburn
+ fprintf(stderr, "# Downloading FT2 font filename='%s', ttface=%lx\n", ti->tf->instance->face->filename, (long)ti->ttface);
+#endif /* DEBUG_gisburn */
+
+ ti->nameid.full_name = FT_Get_TT_NAME_ID(ti->ttface, TT_NAME_ID_FULL_NAME);
+ ti->nameid.copyright = FT_Get_TT_NAME_ID(ti->ttface, TT_NAME_ID_COPYRIGHT);
+ ti->nameid.family = FT_Get_TT_NAME_ID(ti->ttface, TT_NAME_ID_FONT_FAMILY);
+ ti->nameid.subfamily = FT_Get_TT_NAME_ID(ti->ttface, TT_NAME_ID_FONT_SUBFAMILY);
+ ti->nameid.version = FT_Get_TT_NAME_ID(ti->ttface, TT_NAME_ID_VERSION_STRING);
+
+ ti->ttheader = (TT_Header *)FT_Get_Sfnt_Table(ti->ttface, ft_sfnt_head);
+ ti->ttpostscript = (TT_Postscript *)FT_Get_Sfnt_Table(ti->ttface, ft_sfnt_post);
+
+ PSType3_generateOutlineFont(self->Fp, psfontname, ti, block_offset);
+
+ free(ti->nameid.full_name);
+ free(ti->nameid.copyright);
+ free(ti->nameid.family);
+ free(ti->nameid.subfamily);
+ free(ti->nameid.version);
+
+ S_Flush(self);
+
+ return 0;
+}
+
diff --git a/nx-X11/programs/Xserver/Xprint/ps/ttf2pt1wrap.c b/nx-X11/programs/Xserver/Xprint/ps/ttf2pt1wrap.c
new file mode 100644
index 000000000..57bb777d2
--- /dev/null
+++ b/nx-X11/programs/Xserver/Xprint/ps/ttf2pt1wrap.c
@@ -0,0 +1,14 @@
+/*
+ * Wrapper to add missing symbol to externally supplied code
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#ifdef Lynx
+extern int optind;
+extern char *optarg;
+#endif
+
+#include "ttf2pt1.c"