home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Best Objectech Shareware Selections
/
UNTITLED.iso
/
boss
/
grap
/
clip
/
017
/
bb4gs.ps
< prev
next >
Wrap
Text File
|
1992-04-22
|
15KB
|
600 lines
%!
% bb.ps --
%
% Prints a file, but keeps track of bounding box info, and prints the box at
% the end (around the figure.)
%
% $Header: bb.ps,v 1.14 91/03/21 13:04:02 cosell Exp $
% RCS log info at end
%
% This version, bb4gs.ps, modified for Ghostscript by William L. Kath
% <kath@nwu.edu>, 92/03/01; all changes clearly marked by `Ghostscript'
/strokepath { } def %% added by wlk for Ghostscript (I think
%% the strokepath operator is still not
%% fully implemented).
%% /show /print load def %% added by wlk for Ghostscript; uncomment
%% this lines to write %%BoundingBox to
%% stdout (e.g, for use in a filter to add
%% %%BoundingBox to a Postscript file);
%% alternatively, add these two lines to
%% a separate file and invoke before this
%% one when such a filter is desired.
50 dict /$BoundingBox exch def
$BoundingBox begin
/xdef {
exch def
} def
/xstore {
exch store
} def
/addcoords {
exch
4 -1 roll add
3 1 roll add
} def
%
% Stubs of old functions.
%
/-stroke /stroke load def
/-fill /fill load def
/-eofill /eofill load def
/-image /image load def
/-show /show load def
/-awidthshow /awidthshow load def
/-showpage /showpage load def
/-restore /restore load def
/-imagemask /imagemask load def
end % $BoundingBox
%
% New Functions. --- These go into the user dict to intercept the calls
%
/stroke {
$BoundingBox begin
gsave
initmatrix
(stroke called\n) traceprint %%DEBUG
{
strokepath % Make sure to take line width into account.
0 setlinejoin
flattenpath
} stopped { % strokepath often hits a limitcheck.
(Can't set up a strokepath\n) traceprint % DEBUG
grestore % Restore the original path
gsave
} if
includepath % Accumulate it into our box.
grestore
-stroke
end % $BoundingBox
} def
/fill {
$BoundingBox begin
gsave
(fill called\n) traceprint %%DEBUG
includepath
grestore
-fill
end % $BoundingBox
} def
/eofill {
$BoundingBox begin
gsave
(eofill called\n) traceprint %%DEBUG
includepath
grestore
-eofill
end % $BoundingBox
} def
%
% Text is implemented by reducing everything to an `awidthshow'.
%
/show {
$BoundingBox begin
(show called\n) traceprint %%DEBUG
0 0 0 0 0 % Extra parameters for awidthshow
6 -1 roll % Bring the string back up
awidthshow
end % $BoundingBox
} def
/widthshow {
$BoundingBox begin
(widthshow called\n) traceprint %%DEBUG
0 0 % Extra parameters for awidthshow
3 -1 roll % Bring the string back up.
awidthshow
end % $BoundingBox
} def
/ashow {
$BoundingBox begin
(ashow called\n) traceprint %%DEBUG
0 0 0
6 3 roll
awidthshow
end % $BoundingBox
} def
% This does all of the work of the text-rendering operators
% What it does, is compute, basically brute force, what 'charpath'
% would have given us virtually for free, if 'show' were the only
% operator that we needed to do.
/awidthshow {
$BoundingBox begin
gsave
6 (awidthshow:) debug %%DEBUG
currentpoint
2 copy /@starty xdef /@startx xdef
2 index stringwidth % Get the natural length of the string
addcoords % Add to the start to get the end.
2 index length % How many characters?
dup % Add the offsets to each character
6 index mul
exch 5 index mul
addcoords
5 index 3 index
chcount % How many padding characters?
dup % Add the offsets for each pad.
9 index mul
exch 8 index mul
addcoords
/@endy xdef /@endx xdef
% We now have the left and right edges (in user coords)
% of the text. Now we need only correct for the vertical
% displacements needed for the font and we can get the
% top and bottom edges of the enclosing box
fontheight % Get the height and depth of the current font.
@startx @starty addcoords
/@starty xdef /@startx xdef
@endx @endy addcoords
/@endy xdef /@endx xdef
newpath
@startx @starty moveto
@endx @starty lineto
@endx @endy lineto
@startx @endy lineto
closepath
includepath
grestore
-awidthshow
end % $BoundingBox
} def
%
% `image':
%
% Assume here that the image lands in the unit square.
%
/image {
$BoundingBox begin
(image called\n) traceprint %%DEBUG
gsave
newpath
0 0 moveto
1 0 rlineto
1 1 rlineto
-1 0 rlineto
closepath
includepath
grestore
-image
end % $BoundingBox
} def
/imagemask
{
$BoundingBox begin
(imagemask called\n) traceprint %%DEBUG
gsave
newpath
0 0 moveto
1 0 rlineto
1 1 rlineto
-1 0 rlineto
closepath
includepath
grestore
-imagemask
end % $BoundingBox
} def
% Just define this one out of existence
/framedevice { pop pop pop pop } def
% Handle restoring VM --- this is all OK, except that we have to
% hang onto the bb info we collected while in the about-to-be-discarded
% environment
/restore
{
$BoundingBox begin
(restore called\n) traceprint %%DEBUG
tracedump %% HACK, but the only way I see right now to get this stuff!
bbox-llx bbox-lly bbox-urx bbox-ury
5 -1 roll
-restore
/bbox-ury xstore /bbox-urx xstore
/bbox-lly xstore /bbox-llx xstore
end % $BoundingBox
} def
%
% `showpage':
%
% Just draw the box around the figure and print the page, and then initialize
% the bounding box variables again.
%
$BoundingBox begin
/temp-string 10 string def
end % $BoundingBox
/showpage {
$BoundingBox begin
initgraphics
(showpage\n) traceprint % DEBUG
dump-bbox % DEBUG
/bbox-llx round_down
/bbox-lly round_down
/bbox-ury round_up
/bbox-urx round_up
bbox-llx bbox-lly moveto % Make the box
bbox-llx bbox-ury lineto
bbox-urx bbox-ury lineto
bbox-urx bbox-lly lineto
closepath
bwstroke % Draw the box.
% Print the size of the bounding box both above and below the actual box
0 setgray
%% /Courier findfont 10 scalefont setfont
%% bbox-llx 36 max bbox-lly 12 sub 36 max moveto
/Courier findfont 25 scalefont setfont %% changed by wlk
bbox-llx 36 max bbox-lly 29 sub 36 max moveto %% for Ghostscript
(%%BoundingBox: ) -show
bbox-llx temp-string cvs -show ( ) -show
bbox-lly temp-string cvs -show ( ) -show
bbox-urx temp-string cvs -show ( ) -show
bbox-ury temp-string cvs -show
bbox-llx 36 max bbox-ury 12 add 740 min moveto
/-show load /print load ne %% added by wlk for Ghostscript
{ %% added by wlk for Ghostscript
(%%BoundingBox: ) -show
bbox-llx temp-string cvs -show ( ) -show
bbox-lly temp-string cvs -show ( ) -show
bbox-urx temp-string cvs -show ( ) -show
bbox-ury temp-string cvs -show
} if %% added by wlk for Ghostscript
init
-showpage