/*
* tkCanvPs.c --
*
* This module provides Postscript output support for canvases,
* including the "postscript" widget command plus a few utility
* procedures used for generating Postscript.
*
* Copyright (c) 1991-1994 The Regents of the University of California.
* Copyright (c) 1994-1996 Sun Microsystems, Inc.
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
* SCCS: @(#) tkCanvPs.c 1.52 96/11/19 12:47:09
*/
#include "tkInt.h"
#include "tkCanvas.h"
/*
* See tkCanvas.h for key data structures used to implement canvases.
*/
/*
* One of the following structures is created to keep track of Postscript
* output being generated. It consists mostly of information provided on
* the widget command line.
*/
typedef struct TkPostscriptInfo {
* coordinates. */
* corresponding to pageXString and
* pageYString. Don't forget that y-values
* grow upwards for Postscript! */
* maps into this many points. */
* on page (landscape mode). */
* containing font mapping information.
* Malloc'ed. */
* containing color mapping information.
* Malloc'ed. */
* "gray", or "color". Malloc'ed. */
* 0 for mono, 1 for gray, 2 for color. */
* NULL means return Postscript info as
* result. Malloc'ed. */
* families used in output. The hash table
* values are not used. */
* the pre-pass that collects font information,
* so the Postscript generated isn't
* relevant. */
/*
* The table below provides a template that's used to process arguments
* to the canvas "postscript" command and fill in TkPostscriptInfo
* structures.
*/
(char *) NULL, 0, 0}
};
/*
* Forward declarations for procedures defined later in this file:
*/
/*
*--------------------------------------------------------------
*
* TkCanvPostscriptCmd --
*
* This procedure is invoked to process the "postscript" options
* of the widget command for canvas widgets. See the user
* documentation for details on what it does.
*
* Results:
* A standard Tcl result.
*
* Side effects:
* See the user documentation.
*
*--------------------------------------------------------------
*/
/* ARGSUSED */
int
int argc; /* Number of arguments. */
char **argv; /* Argument strings. Caller has
* already parsed this command enough
* to know that argv[1] is
* "postscript". */
{
#endif /* WIN_TCL || MAC_TCL */
* area to be marked up, measured
* in canvas units from the positioning
* point on the page (reflects
* anchor position). Initial values
* needed only to stop compiler
* warnings. */
/*
*----------------------------------------------------------------
* Initialize the data structure describing Postscript generation,
* then process all the arguments to fill the data structure in.
*----------------------------------------------------------------
*/
psInfo.colorLevel = 0;
goto cleanup;
}
}
}
goto cleanup;
}
}
goto cleanup;
}
}
goto cleanup;
}
goto cleanup;
}
} else {
}
switch (psInfo.pageAnchor) {
case TK_ANCHOR_NW:
case TK_ANCHOR_W:
case TK_ANCHOR_SW:
deltaX = 0;
break;
case TK_ANCHOR_N:
case TK_ANCHOR_CENTER:
case TK_ANCHOR_S:
break;
case TK_ANCHOR_NE:
case TK_ANCHOR_E:
case TK_ANCHOR_SE:
break;
}
switch (psInfo.pageAnchor) {
case TK_ANCHOR_NW:
case TK_ANCHOR_N:
case TK_ANCHOR_NE:
break;
case TK_ANCHOR_W:
case TK_ANCHOR_CENTER:
case TK_ANCHOR_E:
break;
case TK_ANCHOR_SW:
case TK_ANCHOR_S:
case TK_ANCHOR_SE:
deltaY = 0;
break;
}
} else {
psInfo.colorLevel = 0;
} else {
"gray, or color", (char *) NULL);
goto cleanup;
}
}
if (p == NULL) {
goto cleanup;
}
goto cleanup;
}
}
/*
*--------------------------------------------------------
* Make a pre-pass over all of the items, generating Postscript
* and then throwing it away. The purpose of this pass is just
* to collect information about all the fonts in use, so that
* we can output font information in the proper form required
* by the Document Structuring Conventions.
*--------------------------------------------------------
*/
continue;
}
continue;
}
/*
* An error just occurred. Just skip out of this loop.
* There's no need to report the error now; it can be
* reported later (errors can happen later that don't
* happen now, so we still have to check for errors later
* anyway).
*/
break;
}
}
/*
*--------------------------------------------------------
* Generate the header and prolog for the Postscript.
*--------------------------------------------------------
*/
"%%Creator: Tk Canvas Widget\n", (char *) NULL);
(char *) NULL);
endpwent();
#endif /* WIN_TCL || MAC_TCL */
+ 1.0),
+ 1.0));
} else {
+ 1.0));
}
"\n", (char *) NULL);
"%%DocumentData: Clean7Bit\n", (char *) NULL);
p = "%%DocumentNeededResources: font ";
"\n", (char *) NULL);
p = "%%+ font ";
}
/*
* Read a standard prolog file in a native way and insert it into
* the Postscript.
*/
goto cleanup;
}
}
/*
*-----------------------------------------------------------
* Document setup: set the color level and include fonts.
*-----------------------------------------------------------
*/
(char *) NULL);
}
/*
*-----------------------------------------------------------
* Page setup: move to page positioning point, rotate if
* needed, set scale factor, offset for proper anchor position,
* and set clip region.
*-----------------------------------------------------------
*/
(char *) NULL);
}
" lineto closepath clip newpath\n", (char *) NULL);
}
/*
*---------------------------------------------------------------------
* Iterate through all the items, having each relevant one draw itself.
* Quit if any of the items returns an error.
*---------------------------------------------------------------------
*/
continue;
}
continue;
}
goto cleanup;
}
}
}
/*
*---------------------------------------------------------------------
* Output page-end information, such as commands to print the page
* and document trailer stuff.
*---------------------------------------------------------------------
*/
"%%Trailer\nend\n%%EOF\n", (char *) NULL);
}
/*
* Clean up psInfo to release malloc'ed stuff.
*/
}
}
}
}
}
}
}
}
}
return result;
}
/*
*--------------------------------------------------------------
*
* Tk_CanvasPsColor --
*
* This procedure is called by individual canvas items when
* they want to set a color value for output. Given information
* about an X color, this procedure will generate Postscript
* commands to set up an appropriate color in Postscript.
*
* Results:
* Returns a standard Tcl return value. If an error occurs
* then an error message will be left in interp->result.
* If no error occurs, then additional Postscript will be
* appended to interp->result.
*
* Side effects:
* None.
*
*--------------------------------------------------------------
*/
int
* or error message. */
{
int tmp;
return TCL_OK;
}
/*
* If there is a color map defined, then look up the color's name
* in the map and use the Postscript commands found there, if there
* are any.
*/
char *cmdString;
Tk_NameOfColor(colorPtr), 0);
return TCL_OK;
}
}
/*
* No color map entry for this color. Grab the color's intensities
* and output Postscript commands for them. Special note: X uses
* a range of 0-65535 for intensities, but most displays only use
* a range of 0-255, which maps to (0, 256, 512, ... 65280) in the
* X scale. This means that there's no way to get perfect white,
* since the highest intensity is only 65280 out of 65535. To
* work around this problem, rescale the X intensity to a 0-255
* scale and use that as the basis for the Postscript colors. This
* scheme still won't work if the display only uses 4 bits per color,
* but most diplays use at least 8 bits.
*/
return TCL_OK;
}
/*
*--------------------------------------------------------------
*
* Tk_CanvasPsFont --
*
* This procedure is called by individual canvas items when
* they want to output text. Given information about an X
* font, this procedure will generate Postscript commands
* to set up an appropriate font in Postscript.
*
* Results:
* Returns a standard Tcl return value. If an error occurs
* then an error message will be left in interp->result.
* If no error occurs, then additional Postscript will be
* appended to the interp->result.
*
* Side effects:
* The Postscript font name is entered into psInfoPtr->fontTable
* if it wasn't already there.
*
*--------------------------------------------------------------
*/
int
* or error message. */
* is to be printed. */
{
char *p;
/*
* First, look up the font's name in the font map, if there is one.
* If there is an entry for this font, it consists of a list
* containing font name and size. Use this information.
*/
int argc;
double size;
name, 0);
return TCL_ERROR;
}
if (argc != 2) {
goto badMapEntry;
}
goto badMapEntry;
}
}
return TCL_OK;
}
}
/*
* Not in the font map. Try to parse the name to get four fields:
* family name, weight, slant, and point size. To do this, split the
* font name up into fields, storing pointers to the first character
* of each field in fieldPtrs.
*/
if (name[0] != '-') {
goto error;
}
fieldPtrs[i] = p;
while (*p != '-') {
if (*p == 0) {
goto error;
}
p++;
}
p++;
}
/*
* Use the information from the X font name to make a guess at a
* Postscript font name of the form "<family>-<weight><slant>" where
* <weight> and <slant> may be omitted and if both are omitted then
* the dash is also omitted. Postscript is very picky about font names,
* so there are several heuristics in the code below (e.g. don't
* include a "Roman" slant except for "Times" font, and make sure
* that the first letter of each field is capitalized but no other
* letters are in caps).
*/
goto error;
}
}
}
}
*p = 0;
if (weightSize == 0) {
goto error;
}
(size_t) weightSize) == 0) {
weightString = "";
(size_t) weightSize) == 0) {
weightString = "Bold";
} else {
goto error;
}
goto error;
}
c = fieldPtrs[SLANT_FIELD][0];
if ((c == 'r') || (c == 'R')) {
slantString = "";
slantString = "Roman";
}
} else if ((c == 'i') || (c == 'I')) {
slantString = "Italic";
} else if ((c == 'o') || (c == 'O')) {
slantString = "Oblique";
} else {
goto error;
}
if ((weightString[0] != 0) || (slantString[0] != 0)) {
}
if (points == 0) {
goto error;
}
}
return TCL_OK;
return TCL_ERROR;
}
/*
*--------------------------------------------------------------
*
* Tk_CanvasPsBitmap --
*
* This procedure is called to output the contents of a
* sub-region of a bitmap in proper image data format for
* Postscript (i.e. data between angle brackets, one bit
* per pixel).
*
* Results:
* Returns a standard Tcl return value. If an error occurs
* then an error message will be left in interp->result.
* If no error occurs, then additional Postscript will be
* appended to interp->result.
*
* Side effects:
* None.
*
*--------------------------------------------------------------
*/
int
* or error message. */
* Postscript. */
* of rectangular region to output. */
{
return TCL_OK;
}
/*
* The following call should probably be a call to Tk_SizeOfBitmap
* instead, but it seems that we are occasionally invoked by custom
* item types that create their own bitmaps without registering them
* with Tk. XGetGeometry is a bit slower than Tk_SizeOfBitmap, but
* it shouldn't matter here.
*/
mask = 0x80;
value = 0;
charsInLine = 0;
}
mask >>= 1;
if (mask == 0) {
mask = 0x80;
value = 0;
charsInLine += 2;
if (charsInLine >= 60) {
charsInLine = 0;
}
}
}
if (mask != 0x80) {
mask = 0x80;
value = 0;
charsInLine += 2;
}
}
return TCL_OK;
}
/*
*--------------------------------------------------------------
*
* Tk_CanvasPsStipple --
*
* This procedure is called by individual canvas items when
* they have created a path that they'd like to be filled with
* a stipple pattern. Given information about an X bitmap,
* this procedure will generate Postscript commands to fill
* the current clip region using a stipple pattern defined by the
* bitmap.
*
* Results:
* Returns a standard Tcl return value. If an error occurs
* then an error message will be left in interp->result.
* If no error occurs, then additional Postscript will be
* appended to interp->result.
*
* Side effects:
* None.
*
*--------------------------------------------------------------
*/
int
* or error message. */
{
return TCL_OK;
}
/*
* The following call should probably be a call to Tk_SizeOfBitmap
* instead, but it seems that we are occasionally invoked by custom
* item types that create their own bitmaps without registering them
* with Tk. XGetGeometry is a bit slower than Tk_SizeOfBitmap, but
* it shouldn't matter here.
*/
return TCL_ERROR;
}
return TCL_OK;
}
/*
*--------------------------------------------------------------
*
* Tk_CanvasPsY --
*
* Given a y-coordinate in canvas coordinates, this procedure
* returns a y-coordinate to use for Postscript output.
*
* Results:
* Returns the Postscript coordinate that corresponds to
* "y".
*
* Side effects:
* None.
*
*--------------------------------------------------------------
*/
double
* Postscript is being generated. */
double y; /* Y-coordinate in canvas coords. */
{
}
/*
*--------------------------------------------------------------
*
* Tk_CanvasPsPath --
*
* Given an array of points for a path, generate Postscript
* commands to create the path.
*
* Results:
* Postscript commands get appended to what's in interp->result.
*
* Side effects:
* None.
*
*--------------------------------------------------------------
*/
void
* interpreter's result field. */
* is being generated. */
double *coordPtr; /* Pointer to first in array of
* 2*numPoints coordinates giving
* points for path. */
int numPoints; /* Number of points at *coordPtr. */
{
return;
}
}
}
/*
*--------------------------------------------------------------
*
* GetPostscriptPoints --
*
* Given a string, returns the number of Postscript points
* corresponding to that string.
*
* Results:
* The return value is a standard Tcl return result. If
* TCL_OK is returned, then everything went well and the
* screen distance is stored at *doublePtr; otherwise
* TCL_ERROR is returned and an error message is left in
* interp->result.
*
* Side effects:
* None.
*
*--------------------------------------------------------------
*/
static int
char *string; /* String describing a screen distance. */
double *doublePtr; /* Place to store converted result. */
{
char *end;
double d;
"\"", (char *) NULL);
return TCL_ERROR;
}
end++;
}
switch (*end) {
case 'c':
d *= 72.0/2.54;
end++;
break;
case 'i':
d *= 72.0;
end++;
break;
case 'm':
d *= 72.0/25.4;
end++;
break;
case 0:
break;
case 'p':
end++;
break;
default:
goto error;
}
end++;
}
if (*end != 0) {
goto error;
}
*doublePtr = d;
return TCL_OK;
}
/*
*--------------------------------------------------------------
*
* TkGetProlog --
*
* Locate and load the postscript prolog.
*
* Results:
* A standard Tcl Result. If everything is OK the prolog
* will be located in the result string of the interpreter.
*
* Side effects:
* None.
*
*--------------------------------------------------------------
*/
int
{
char *libDir;
int bufferSize;
char *prologBuffer;
"tk_library variable doesn't exist", (char *) NULL);
return TCL_ERROR;
}
/*
* Compute size of file by seeking to the end of the file. This will
* overallocate if we are performing CRLF translation.
*/
return TCL_ERROR;
}
if (bufferSize < 0) {
return TCL_ERROR;
}
if (bufferSize < 0) {
return TCL_ERROR;
}
prologBuffer[bufferSize] = 0;
return TCL_OK;
}