diff options
author | joye <joye> | 2014-06-04 17:01:46 (GMT) |
---|---|---|
committer | joye <joye> | 2014-06-04 17:01:46 (GMT) |
commit | 32cb8bf3e3c83fc994d5ef93a897951411d3638b (patch) | |
tree | 8eb79497e713496a0bc9d3972ad886fa31849375 | |
parent | 3a09f3af0eb560eb8ebb4f7c843ade55076cf0f4 (diff) | |
download | blt-32cb8bf3e3c83fc994d5ef93a897951411d3638b.zip blt-32cb8bf3e3c83fc994d5ef93a897951411d3638b.tar.gz blt-32cb8bf3e3c83fc994d5ef93a897951411d3638b.tar.bz2 |
*** empty log message ***
-rw-r--r-- | src/bltGrPSOutput.C | 532 | ||||
-rw-r--r-- | src/bltGrPSOutput.h | 3 |
2 files changed, 480 insertions, 55 deletions
diff --git a/src/bltGrPSOutput.C b/src/bltGrPSOutput.C index e43b370..c50ee18 100644 --- a/src/bltGrPSOutput.C +++ b/src/bltGrPSOutput.C @@ -42,6 +42,8 @@ extern "C" { using namespace Blt; +#define PS_MAXPECT (1<<4) + #ifdef TCL_UTF_MAX # define HAVE_UTF 1 #else @@ -466,57 +468,6 @@ void PostScript::setBitmap(Display *display, Pixmap bitmap, int w, int h) XDestroyImage(imagePtr); } -int PostScript::includeFile(const char *fileName) -{ - Tcl_Channel channel; - Tcl_DString dString; - int nBytes; - - Tcl_Interp* interp = graphPtr_->interp_; - char* buf = scratchArr_; - - // Read in a standard prolog file from file and append it to the - // PostScript output stored in the Tcl_DString in psPtr. - char* libDir = (char *)Tcl_GetVar(interp, "tkblt_library", TCL_GLOBAL_ONLY); - if (libDir == NULL) { - Tcl_AppendResult(interp, "couldn't find TKBLT script library:", - "global variable \"tkblt_library\" doesn't exist", - (char *)NULL); - return TCL_ERROR; - } - Tcl_DStringInit(&dString); - Tcl_DStringAppend(&dString, libDir, -1); - Tcl_DStringAppend(&dString, "/", -1); - Tcl_DStringAppend(&dString, fileName, -1); - fileName = Tcl_DStringValue(&dString); - varAppend("\n% including file \"", fileName, "\"\n\n", NULL); - channel = Tcl_OpenFileChannel(interp, fileName, "r", 0); - if (channel == NULL) { - Tcl_AppendResult(interp, "couldn't open prologue file \"", fileName, - "\": ", Tcl_PosixError(interp), (char *)NULL); - return TCL_ERROR; - } - for(;;) { - nBytes = Tcl_Read(channel, buf, POSTSCRIPT_BUFSIZ); - if (nBytes < 0) { - Tcl_AppendResult(interp, "error reading prologue file \"", - fileName, "\": ", Tcl_PosixError(interp), - (char *)NULL); - Tcl_Close(interp, channel); - Tcl_DStringFree(&dString); - return TCL_ERROR; - } - if (nBytes == 0) { - break; - } - buf[nBytes] = '\0'; - append(buf); - } - Tcl_DStringFree(&dString); - Tcl_Close(interp, channel); - return TCL_OK; -} - void PostScript::XColorToPostScript(XColor* colorPtr) { format("%g %g %g", @@ -567,8 +518,8 @@ int PostScript::preamble(const char* fileName) append("%%DocumentNeededResources: font Helvetica Courier\n"); addComments(ops->comments); append("%%EndComments\n\n"); - if (includeFile("bltGraph.pro") != TCL_OK) - return TCL_ERROR; + + prolog(); if (ops->footer) { const char* who = getenv("LOGNAME"); @@ -641,3 +592,478 @@ void PostScript::drawText(const char* string, double x, double y) return; } +void PostScript::prolog() +{ + append( +"%%BeginProlog\n" +"%\n" +"% PostScript prolog file of the BLT graph widget.\n" +"%\n" +"% Copyright 1989-1992 Regents of the University of California.\n" +"% Permission to use, copy, modify, and distribute this\n" +"% software and its documentation for any purpose and without\n" +"% fee is hereby granted, provided that the above copyright\n" +"% notice appear in all copies. The University of California\n" +"% makes no representations about the suitability of this\n" +"% software for any purpose. It is provided 'as is' without\n" +"% express or implied warranty.\n" +"%\n" +"% Copyright 1991-1997 Bell Labs Innovations for Lucent Technologies.\n" +"%\n" +"% Permission to use, copy, modify, and distribute this software and its\n" +"% documentation for any purpose and without fee is hereby granted, provided\n" +"% that the above copyright notice appear in all copies and that both that the\n" +"% copyright notice and warranty disclaimer appear in supporting documentation,\n" +"% and that the names of Lucent Technologies any of their entities not be used\n" +"% in advertising or publicity pertaining to distribution of the software\n" +"% without specific, written prior permission.\n" +"%\n" +"% Lucent Technologies disclaims all warranties with regard to this software,\n" +"% including all implied warranties of merchantability and fitness. In no event\n" +"% shall Lucent Technologies be liable for any special, indirect or\n" +"% consequential damages or any damages whatsoever resulting from loss of use,\n" +"% data or profits, whether in an action of contract, negligence or other\n" +"% tortuous action, arising out of or in connection with the use or performance\n" +"% of this software.\n" +"%\n" +"\n" +"200 dict begin\n" +"\n" +"/BaseRatio 1.3467736870885982 def % Ratio triangle base / symbol size\n" +"/BgColorProc 0 def % Background color routine (symbols)\n" +"/DrawSymbolProc 0 def % Routine to draw symbol outline/fill\n" +"/StippleProc 0 def % Stipple routine (bar segments)\n" +"/DashesProc 0 def % Dashes routine (line segments)\n" +" \n" +"% Define the array ISOLatin1Encoding (which specifies how characters are \n" +"% encoded for ISO-8859-1 fonts), if it isn't already present (Postscript \n" +"% level 2 is supposed to define it, but level 1 doesn't). \n" +"\n" +"systemdict /ISOLatin1Encoding known not { \n" +" /ISOLatin1Encoding [ \n" +" /space /space /space /space /space /space /space /space \n" +" /space /space /space /space /space /space /space /space \n" +" /space /space /space /space /space /space /space /space \n" +" /space /space /space /space /space /space /space /space \n" +" /space /exclam /quotedbl /numbersign /dollar /percent /ampersand \n" +" /quoteright \n" +" /parenleft /parenright /asterisk /plus /comma /minus /period /slash \n" +" /zero /one /two /three /four /five /six /seven \n" +" /eight /nine /colon /semicolon /less /equal /greater /question \n" +" /at /A /B /C /D /E /F /G \n" +" /H /I /J /K /L /M /N /O \n" +" /P /Q /R /S /T /U /V /W \n" +" /X /Y /Z /bracketleft /backslash /bracketright /asciicircum /underscore \n" +" /quoteleft /a /b /c /d /e /f /g \n" +" /h /i /j /k /l /m /n /o \n" +" /p /q /r /s /t /u /v /w \n" +" /x /y /z /braceleft /bar /braceright /asciitilde /space \n" +" /space /space /space /space /space /space /space /space \n" +" /space /space /space /space /space /space /space /space \n" +" /dotlessi /grave /acute /circumflex /tilde /macron /breve /dotaccent \n" +" /dieresis /space /ring /cedilla /space /hungarumlaut /ogonek /caron \n" +" /space /exclamdown /cent /sterling /currency /yen /brokenbar /section \n" +" /dieresis /copyright /ordfeminine /guillemotleft /logicalnot /hyphen \n" +" /registered /macron \n" +" /degree /plusminus /twosuperior /threesuperior /acute /mu /paragraph \n" +" /periodcentered \n" +" /cedillar /onesuperior /ordmasculine /guillemotright /onequarter \n" +" /onehalf /threequarters /questiondown \n" +" /Agrave /Aacute /Acircumflex /Atilde /Adieresis /Aring /AE /Ccedilla \n" +" /Egrave /Eacute /Ecircumflex /Edieresis /Igrave /Iacute /Icircumflex \n" +" /Idieresis \n" +" /Eth /Ntilde /Ograve /Oacute /Ocircumflex /Otilde /Odieresis /multiply \n" +" /Oslash /Ugrave /Uacute /Ucircumflex /Udieresis /Yacute /Thorn \n" +" /germandbls \n" +" /agrave /aacute /acircumflex /atilde /adieresis /aring /ae /ccedilla \n" +" /egrave /eacute /ecircumflex /edieresis /igrave /iacute /icircumflex \n" +" /idieresis \n" +" /eth /ntilde /ograve /oacute /ocircumflex /otilde /odieresis /divide \n" +" /oslash /ugrave /uacute /ucircumflex /udieresis /yacute /thorn \n" +" /ydieresis \n" +" ] def \n" +"} if \n" +"\n" +"% font ISOEncode font \n" +"% This procedure changes the encoding of a font from the default \n" +"% Postscript encoding to ISOLatin1. It is typically invoked just \n" +"% before invoking 'setfont'. The body of this procedure comes from \n" +"% Section 5.6.1 of the Postscript book. \n" +"\n" +"/ISOEncode { \n" +" dup length dict\n" +" begin \n" +" {1 index /FID ne {def} {pop pop} ifelse} forall \n" +" /Encoding ISOLatin1Encoding def \n" +" currentdict \n" +" end \n" +"\n" +" % I'm not sure why it's necessary to use 'definefont' on this new \n" +" % font, but it seems to be important; just use the name 'Temporary' \n" +" % for the font. \n" +"\n" +" /Temporary exch definefont \n" +"} bind def \n" +"\n" +"/Stroke {\n" +" gsave\n" +" stroke\n" +" grestore\n" +"} def\n" +"\n" +"/Fill {\n" +" gsave\n" +" fill\n" +" grestore\n" +"} def\n" +"\n" +"/SetFont { \n" +" % Stack: pointSize fontName\n" +" findfont exch scalefont ISOEncode setfont\n" +"} def\n" +"\n" +"/Box {\n" +" % Stack: x y width height\n" +" newpath\n" +" exch 4 2 roll moveto\n" +" dup 0 rlineto\n" +" exch 0 exch rlineto\n" +" neg 0 rlineto\n" +" closepath\n" +"} def\n" +"\n" +"% The next two definitions are taken from '$tk_library/prolog.ps'\n" +"\n" +"% desiredSize EvenPixels closestSize\n" +"%\n" +"% The procedure below is used for stippling. Given the optimal size\n" +"% of a dot in a stipple pattern in the current user coordinate system,\n" +"% compute the closest size that is an exact multiple of the device's\n" +"% pixel size. This allows stipple patterns to be displayed without\n" +"% aliasing effects.\n" +"\n" +"/EvenPixels {\n" +" % Compute exact number of device pixels per stipple dot.\n" +" dup 0 matrix currentmatrix dtransform\n" +" dup mul exch dup mul add sqrt\n" +"\n" +" % Round to an integer, make sure the number is at least 1, and compute\n" +" % user coord distance corresponding to this.\n" +" dup round dup 1 lt {pop 1} if\n" +" exch div mul\n" +"} bind def\n" +"\n" +"% width height string filled StippleFill --\n" +"%\n" +"% Given a path and other graphics information already set up, this\n" +"% procedure will fill the current path in a stippled fashion. 'String'\n" +"% contains a proper image description of the stipple pattern and\n" +"% 'width' and 'height' give its dimensions. If 'filled' is true then\n" +"% it means that the area to be stippled is gotten by filling the\n" +"% current path (e.g. the interior of a polygon); if it's false, the\n" +"% area is gotten by stroking the current path (e.g. a wide line).\n" +"% Each stipple dot is assumed to be about one unit across in the\n" +"% current user coordinate system.\n" +"\n" +"% width height string StippleFill --\n" +"%\n" +"% Given a path already set up and a clipping region generated from\n" +"% it, this procedure will fill the clipping region with a stipple\n" +"% pattern. 'String' contains a proper image description of the\n" +"% stipple pattern and 'width' and 'height' give its dimensions. Each\n" +"% stipple dot is assumed to be about one unit across in the current\n" +"% user coordinate system. This procedure trashes the graphics state.\n" +"\n" +"/StippleFill {\n" +" % The following code is needed to work around a NeWSprint bug.\n" +"\n" +" /tmpstip 1 index def\n" +"\n" +" % Change the scaling so that one user unit in user coordinates\n" +" % corresponds to the size of one stipple dot.\n" +" 1 EvenPixels dup scale\n" +"\n" +" % Compute the bounding box occupied by the path (which is now\n" +" % the clipping region), and round the lower coordinates down\n" +" % to the nearest starting point for the stipple pattern. Be\n" +" % careful about negative numbers, since the rounding works\n" +" % differently on them.\n" +"\n" +" pathbbox\n" +" 4 2 roll\n" +" 5 index div dup 0 lt {1 sub} if cvi 5 index mul 4 1 roll\n" +" 6 index div dup 0 lt {1 sub} if cvi 6 index mul 3 2 roll\n" +"\n" +" % Stack now: width height string y1 y2 x1 x2\n" +" % Below is a doubly-nested for loop to iterate across this area\n" +" % in units of the stipple pattern size, going up columns then\n" +" % across rows, blasting out a stipple-pattern-sized rectangle at\n" +" % each position\n" +"\n" +" 6 index exch {\n" +" 2 index 5 index 3 index {\n" +" % Stack now: width height string y1 y2 x y\n" +"\n" +" gsave\n" +" 1 index exch translate\n" +" 5 index 5 index true matrix tmpstip imagemask\n" +" grestore\n" +" } for\n" +" pop\n" +" } for\n" +" pop pop pop pop pop\n" +"} bind def\n" +"\n" +"\n" +"/LS { % Stack: x1 y1 x2 y2\n" +" newpath \n" +" 4 2 roll moveto \n" +" lineto \n" +" closepath\n" +" stroke\n" +"} def\n" +"\n" +"/EndText {\n" +" %Stack :\n" +" grestore\n" +"} def\n" +"\n" +"/BeginText {\n" +" %Stack : w h theta centerX centerY\n" +" gsave\n" +" % Translate the origin to the center of bounding box and rotate\n" +" translate neg rotate\n" +" % Translate back to the origin of the text region\n" +" -0.5 mul exch -0.5 mul exch translate\n" +"} def\n" +"\n" +"/DrawAdjText {\n" +" %Stack : str strWidth x y\n" +" moveto % Go to the text position\n" +" exch dup dup 4 2 roll\n" +"\n" +" % Adjust character widths to get desired overall string width\n" +" % adjust X = (desired width - real width)/#chars\n" +"\n" +" stringwidth pop sub exch\n" +" length div\n" +" 0 3 -1 roll\n" +"\n" +" % Flip back the scale so that the string is not drawn in reverse\n" +"\n" +" gsave\n" +" 1 -1 scale\n" +" ashow\n" +" grestore\n" +"} def\n" +"\n" +"/DrawBitmap {\n" +" % Stack: ?bgColorProc? boolean centerX centerY width height theta imageStr\n" +" gsave\n" +" 6 -2 roll translate % Translate to center of bounding box\n" +" 4 1 roll neg rotate % Rotate by theta\n" +" \n" +" % Find upperleft corner of bounding box\n" +" \n" +" 2 copy -.5 mul exch -.5 mul exch translate\n" +" 2 copy scale % Make pixel unit scale\n" +" newpath\n" +" 0 0 moveto \n" +" 0 1 lineto \n" +" 1 1 lineto \n" +" 1 0 lineto\n" +" closepath\n" +" \n" +" % Fill rectangle with background color\n" +" \n" +" 4 -1 roll { \n" +" gsave \n" +" 4 -1 roll exec fill \n" +" grestore \n" +" } if\n" +" \n" +" % Paint the image string into the unit rectangle\n" +" \n" +" 2 copy true 3 -1 roll 0 0 5 -1 roll 0 0 6 array astore 5 -1 roll\n" +" imagemask\n" +" grestore\n" +"} def\n" +"\n" +"% Symbols:\n" +"\n" +"% Skinny-cross\n" +"/Sc {\n" +" % Stack: x y symbolSize\n" +" gsave\n" +" 3 -2 roll translate 45 rotate\n" +" 0 0 3 -1 roll Sp\n" +" grestore\n" +"} def\n" +"\n" +"% Skinny-plus\n" +"/Sp {\n" +" % Stack: x y symbolSize\n" +" gsave\n" +" 3 -2 roll translate\n" +" 2 idiv\n" +" dup 2 copy\n" +" newpath \n" +" neg 0 \n" +" moveto 0 \n" +" lineto\n" +" DrawSymbolProc\n" +" newpath \n" +" neg 0 \n" +" exch moveto 0 \n" +" exch lineto\n" +" DrawSymbolProc\n" +" grestore\n" +"} def\n" +"\n" +"% Cross\n" +"/Cr {\n" +" % Stack: x y symbolSize\n" +" gsave\n" +" 3 -2 roll translate 45 rotate\n" +" 0 0 3 -1 roll Pl\n" +" grestore\n" +"} def\n" +"\n" +"% Plus\n" +"/Pl {\n" +" % Stack: x y symbolSize\n" +" gsave\n" +" 3 -2 roll translate\n" +" dup 2 idiv\n" +" exch 6 idiv\n" +"\n" +" %\n" +" % 2 3 The plus/cross symbol is a\n" +" % closed polygon of 12 points.\n" +" % 0 1 4 5 The diagram to the left\n" +" % x,y represents the positions of\n" +" % 11 10 7 6 the points which are computed\n" +" % below.\n" +" % 9 8\n" +" %\n" +"\n" +" newpath\n" +" 2 copy exch neg exch neg moveto \n" +" dup neg dup lineto\n" +" 2 copy neg exch neg lineto\n" +" 2 copy exch neg lineto\n" +" dup dup neg lineto \n" +" 2 copy neg lineto 2 copy lineto\n" +" dup dup lineto \n" +" 2 copy exch lineto \n" +" 2 copy neg exch lineto\n" +" dup dup neg exch lineto \n" +" exch neg exch lineto\n" +" closepath\n" +" DrawSymbolProc\n" +" grestore\n" +"} def\n" +"\n" +"% Circle\n" +"/Ci {\n" +" % Stack: x y symbolSize\n" +" gsave\n" +" 3 copy pop moveto \n" +" newpath\n" +" 2 div 0 360 arc\n" +" closepath \n" +" DrawSymbolProc\n" +" grestore\n" +"} def\n" +"\n" +"% Square\n" +"/Sq {\n" +" % Stack: x y symbolSize\n" +" gsave\n" +" dup dup 2 div dup\n" +" 6 -1 roll exch sub exch\n" +" 5 -1 roll exch sub 4 -2 roll Box\n" +" DrawSymbolProc\n" +" grestore\n" +"} def\n" +"\n" +"% Line\n" +"/Li {\n" +" % Stack: x y symbolSize\n" +" gsave\n" +" 3 1 roll exch 3 -1 roll 2 div 3 copy\n" +" newpath\n" +" sub exch moveto \n" +" add exch lineto\n" +" closepath\n" +" stroke\n" +" grestore\n" +"} def\n" +"\n" +"% Diamond\n" +"/Di {\n" +" % Stack: x y symbolSize\n" +" gsave\n" +" 3 1 roll translate 45 rotate 0 0 3 -1 roll Sq\n" +" grestore\n" +"} def\n" +" \n" +"% Triangle\n" +"/Tr {\n" +" % Stack: x y symbolSize\n" +" gsave\n" +" 3 -2 roll translate\n" +" BaseRatio mul 0.5 mul % Calculate 1/2 base\n" +" dup 0 exch 30 cos mul % h1 = height above center point\n" +" neg % b2 0 -h1\n" +" newpath \n" +" moveto % point 1; b2\n" +" dup 30 sin 30 cos div mul % h2 = height below center point\n" +" 2 copy lineto % point 2; b2 h2\n" +" exch neg exch lineto % \n" +" closepath\n" +" DrawSymbolProc\n" +" grestore\n" +"} def\n" +"\n" +"% Arrow\n" +"/Ar {\n" +" % Stack: x y symbolSize\n" +" gsave\n" +" 3 -2 roll translate\n" +" BaseRatio mul 0.5 mul % Calculate 1/2 base\n" +" dup 0 exch 30 cos mul % h1 = height above center point\n" +" % b2 0 h1\n" +" newpath moveto % point 1; b2\n" +" dup 30 sin 30 cos div mul % h2 = height below center point\n" +" neg % -h2 b2\n" +" 2 copy lineto % point 2; b2 h2\n" +" exch neg exch lineto % \n" +" closepath\n" +" DrawSymbolProc\n" +" grestore\n" +"} def\n" +"\n" +"% Bitmap\n" +"/Bm {\n" +" % Stack: x y symbolSize\n" +" gsave\n" +" 3 1 roll translate pop DrawSymbolProc\n" +" grestore\n" +"} def\n" +"\n" +"%%EndProlog\n" +"\n" +"%%BeginSetup\n" +"gsave % Save the graphics state\n" +"\n" +"% Default line/text style parameters\n" +"\n" +"1 setlinewidth % width\n" +"1 setlinejoin % join\n" +"0 setlinecap % cap\n" +"[] 0 setdash % dashes\n" +"\n" +"0 0 0 setrgbcolor % color\n" +); +} diff --git a/src/bltGrPSOutput.h b/src/bltGrPSOutput.h index 2b1cea7..04a0803 100644 --- a/src/bltGrPSOutput.h +++ b/src/bltGrPSOutput.h @@ -33,7 +33,6 @@ #include <tk.h> #define POSTSCRIPT_BUFSIZ ((BUFSIZ*2)-1) -#define PS_MAXPECT (1<<4) class Graph; class PageSetup; @@ -51,7 +50,7 @@ class PostScript { void byteToHex(unsigned char, char*); void setJoinStyle(int); void setCapStyle(int); - int includeFile(const char*); + void prolog(); public: PostScript(Graph*); |