[comp.lang.postscript] Psdraft

ken@cs.rochester.edu (Ken Yap) (04/26/88)

Some time ago a program called psdraft went past. It printed your
chosen word (usually DRAFT) slanted and in a light stipple or outline
over the existing page contents. I saved a copy of the posting but
couldn't get it to work, probably because some long lines got split.
Does someone have a working version to send me?

	if you have psdraft
		if length < 2k
			mail it to me, taking care with long lines
		else
			mail me a note and I will pick the nearest site
	else if you want a copy
		don't post me too messages, mail me,
		I will mail you a copy or post

Thanks in advance.

	Ken

ken@cs.rochester.edu (Ken Yap) (04/27/88)

Thanks to all who sent me copies of psdraft and to Spencer Thomas for
writing it in the first place. Works great. Some of you asked me for
copies and I also made one small change to handle ()\ characters
correctly so I'm posting.

Next question. How do I make a transparent stipple? I tried doing 0.90
setgray then (string) show but it obscures the existing page contents.
I suppose I could lay the gray string first thing, but I see no
beginning of page operator I can redefine.

	Ken

#! /bin/sh
#
# Put the word "DRAFT" (or a specified word) on each page of a postscript
# document.
#
# Usage:
# 	psdraft -s draftstring file ...
#
# Author: Spencer W. Thomas
#	  Computer Science Dept.
#	  University of Utah
#	  (Now spencer@crim.eecs.umich.edu)

#
# Insert header after first line that does not begin %% or %!
#

trap "rm -f /tmp/psd$$.*" 0 1 2 15

if [ "x$1" = "x-s" ] ; then
	draftstring=`echo $2 | sed 's/[()\\\\]/\\\\&/g'`
	shift
	shift
else
	draftstring=DRAFT
fi

if [ "x$*" = "x" ] ; then
	echo "Usage: psdraft [-s draftstring] files ..."
fi

# Create sed script file

sed "s/(DRAFT)/($draftstring)/" <<'EOF' >/tmp/psd$$.sed
1,/^[^%]/{ 
s/^%/%/
s/^$//
t skip
i\
% Prelude to show a draft string on every page.\
(DRAFT)\
/DRAFTDICT 10 dict def\
DRAFTDICT begin\
/DRAFTSTRING exch def\
/bd /Helvetica-Bold findfont def\
/od bd maxlength 1 add dict def\
bd {exch dup /FID ne {exch od 3 1 roll put} {pop pop} ifelse} forall\
od /FontName /Outline0 put od /PaintType 2 put od /StrokeWidth 0 put\
/Outline0 od definefont pop\
/DRAFT { gsave\
	 initmatrix\
	/Outline0 findfont setfont\
	DRAFTSTRING dup stringwidth pop 8.875 exch div dup 72 mul dup scale\
	52.3 rotate 2.5 exch div -.35 translate\
	0 0 moveto show\
	grestore } def\
/oldshow /showpage load def\
/oldcopy /copypage load def\
end\
/showpage { DRAFTDICT begin DRAFT oldshow end } def\
/copypage { DRAFTDICT begin DRAFT oldcopy end } def\
% End of draft prelude
: skip
}
EOF

cat $* | sed -f /tmp/psd$$.sed 

spencer@spline.eecs.umich.edu (Spencer W. Thomas) (04/28/88)

> Next question. How do I make a transparent stipple? I tried doing 0.90
> setgray then (string) show but it obscures the existing page contents.
> I suppose I could lay the gray string first thing, but I see no
> beginning of page operator I can redefine.

Yes, I ran into this problem.  It's actually possible to do for
specific types of postscript files, but I couldn't figure a good way
to do it in general, especially given that psrev (or a similar
program) may decide to re-order the file.  (E.g., there was one posted
a while ago that would do what you wanted for files output by a
specific TeX postprocessor.)  If you know you won't have psrev
screwing things up, you can modify showpage to draw the DRAFT string
after it actually does the show, and then draw one instance of the
string before you get started.


=Spencer (spencer@crim.eecs.umich.edu)

samlb@well.UUCP (Samuel B. Bassett) (05/01/88)

I'd try 0.8 (0.7, 0.6...) setgray until the underlying text shows through
the draft, if I were in your shoes . . .
-- 
Sam'l Bassett -- Semantic Engineering for fun & profit.
34 Oakland Ave., San Anselmo  CA  94960;               DDD:  (415) 454-7282
UUCP:  {hplabs,ptsfa,lll-crg}!well!samlb;         Internet: samlb@well.uucp
Compuserve:  71735,1776;      WU Easylink ESL 6284-3034;       MCI SBassett

liam@cs.qmc.ac.uk (William Roberts) (05/07/88)

In article <5847@well.UUCP> samlb@well.UUCP (Samuel B. Bassett) writes:
>I'd try 0.8 (0.7, 0.6...) setgray until the underlying text shows through
>the draft, if I were in your shoes . . .
Fun maybe - but you definitely won't make any profit with such
a fundamentally incorrect understanding of PostScript!

It won't work: PostScript "ink" is logically opaque, whatever
the "colour" applied, so there will never be anything visible
underneath.

The problem of "how do I print the gray text at beginning of page"
is easy and is solved in two stages:

1) Change "showpage" so that it becomes

        /showpage { showpage do_grey_text } bind def

   and thereby do your grey text immediately at the beginning
   of all pages except the very first (NB: do_grey_text is
   probably not the actual routine name...)

2) Notice that the psdraft stuff is being inserted before the
   any of the actual printing commands in the PostScript
   document, so just print the grey text directly at the end of
   the PostScript code inserted by psdraft

Note for purists: the second step actually causes printing
within the Prologue and so breaks the document structuring
conventions. To do this properly would involve adding the
do_grey_text (or whatever) immediately after the first %%Page comment


The only approved way of laying down black dots in some kind of
stipple pattern without filling the white around them is to use
the "imagemask" primitive and a stipple bit pattern. This is
like "image" applied to a 1 bit-per-pixel raster, except that
only the "black" pixels are painted. The clipping region
applies, so you can clip to the outline of the text, but you
will have to do your own tesselation.

The unapproved way (used extensively by the Macintosh) is to
change the halftone screen using "setscreen", but this isn't
properly portable between printers as it depends on the printer
pixel size etc.
-- 

William Roberts         ARPA: liam@cs.qmc.ac.uk  (gw: cs.ucl.edu)
Queen Mary College      UUCP: liam@qmc-cs.UUCP
LONDON, UK              Tel:  01-975 5250

ralph@laas.laas.fr (Ralph P. Sobek) (01/26/89)

Concerning my article <276@laas.laas.fr> I received two requests to
repost the psdraft shell script.  It prints diagonally across all
pages of a PostScript(tm) file the user supplied draftstring or
"DRAFT".  Author credits are contained within the script.  I post it,
being a satisfied user.

	--Ralph

Ralph P. Sobek			  Disclaimer: The above ruminations are my own.
ralph@laas.laas.fr			   Addresses are ordered by importance.
ralph@laas.uucp, or ...!uunet!mcvax!laas!ralph		If all else fails, try:
SOBEK@FRMOP11.BITNET				      sobek@eclair.Berkeley.EDU

#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	psdraft
# This archive created: Wed Jan 25 17:12:04 1989
export PATH; PATH=/bin:$PATH
echo shar: extracting "'psdraft'" '(1530 characters)'
if test -f 'psdraft'
then
	echo shar: will not over-write existing file "'psdraft'"
else
sed 's/^X//' << \SHAR_EOF > 'psdraft'
X#! /bin/sh
X#
X# Put the word "DRAFT" (or a specified word) on each page of a postscript
X# document.
X#
X# Usage:
X#      psdraft -s draftstring file ...
X#
X#
X# Author: Spencer W. Thomas
X#        Computer Science Dept.
X#        University of Utah
X#        thomas@cs.utah.edu
X
X#
X# Insert header after first line that does not begin %% or %!
X#
X
Xtrap "rm -f /tmp/psd$$.*" 0 1 2 15
X
Xif [ "x$1" = "x-s" ] ; then
X       draftstring=$2
X       shift
X       shift
Xelse
X       draftstring=DRAFT
Xfi
X
Xif [ "x$*" = "x" ] ; then
X       echo "Usage: psdraft [-s draftstring] files ..."
X	exit
Xfi
X
X# Create sed script file
X
Xsed "s/(DRAFT)/($draftstring)/" <<'EOF' >/tmp/psd$$.sed
X1,/^[^%]/{
Xs/^%/%/
Xs/^$//
Xt skip
Xi\
X% Prelude to show a draft string on every page.\
X(DRAFT)\
X/DRAFTDICT 10 dict def\
XDRAFTDICT begin\
X/DRAFTSTRING exch def\
X/bd /Helvetica-Bold findfont def\
X/od bd maxlength 1 add dict def\
Xbd {exch dup /FID ne {exch od 3 1 roll put} {pop pop} ifelse} forall\
Xod /FontName /Outline0 put od /PaintType 2 put od /StrokeWidth 0 put\
X/Outline0 od definefont pop\
X/DRAFT { gsave\
X        initmatrix\
X       /Outline0 findfont setfont\
X       DRAFTSTRING dup stringwidth pop 8.875 exch div dup 72 mul dup scale\
X       52.3 rotate 2.5 exch div -.35 translate\
X       0 0 moveto show\
X       grestore } def\
X/oldshow /showpage load def\
X/oldcopy /copypage load def\
Xend\
X/showpage { DRAFTDICT begin DRAFT oldshow end } def\
X/copypage { DRAFTDICT begin DRAFT oldcopy end } def\
X% End of draft prelude
X: skip
X}
XEOF
X
Xcat $* | sed -f /tmp/psd$$.sed
SHAR_EOF
if test 1530 -ne "`wc -c < 'psdraft'`"
then
	echo shar: error transmitting "'psdraft'" '(should have been 1530 characters)'
fi
chmod +x 'psdraft'
fi # end of overwriting check
#	End of shell archive
exit 0

-- 
Ralph P. Sobek			  Disclaimer: The above ruminations are my own.
ralph@laas.laas.fr			   Addresses are ordered by importance.
ralph@laas.uucp, or ...!uunet!mcvax!laas!ralph		If all else fails, try:
SOBEK@FRMOP11.BITNET				      sobek@eclair.Berkeley.EDU

brown@hpdmd48.boi.hp.com (Kevin Brown) (10/25/90)

To get psdraft to work, I had to remove the parens around $greylevel in the
sed command.  With the parens Postscript interpreted the argument to gsetrey
as a string instead of a float.

Is there a way to make the grey draft string transparent instead of
opaque?  As is, it prints over my text making it hard to distribute as
a draft copy.

Kevin Brown
brown@hpbsm15.boi.hp.com

clewis@ecicrl.UUCP (Chris Lewis) (11/07/90)

In article <16600006@hpdmd48.boi.hp.com> brown@hpdmd48.boi.hp.com (Kevin Brown) writes:

>Is there a way to make the grey draft string transparent instead of
>opaque?  As is, it prints over my text making it hard to distribute as
>a draft copy.

Yes, just make sure that the draft string is "show"'d before the rest of
the text on the page is "show"'d....
-- 
Chris Lewis, Phone: TBA
UUCP: uunet!utai!lsuc!ecicrl!clewis
Moderator of the Ferret Mailing List (ferret-request@eci386)
Psroff mailing list (psroff-request@eci386)

cloos@acsu.buffalo.edu (James H. Cloos) (11/15/90)

A while back I posted a small psdraft script that I had expanded.  Not
only did I manage to shar an old copy of the file, but there was a
conceptual error in the postscript, ie showing the grey string over
the page, rather than under it.  I tried a small change to fix that
error, though it does not put up the string on the first page if you
use the grey option.  Perhaps someone can help out with that problem.

Here is the revised psdraft file, in shar format:

=--==--===--====--=====--======--=======--======--=====--====--===--==--=
#!/bin/sh
# This is a shell archive.  Remove anything before this line, then
# unpack it by saving it in a file and typing "sh file".  (Files
# unpacked will be owned by you and have default permissions.)
#
# This archive contains:
# psdraft

echo x - psdraft
sed -e 's/^X//' > "psdraft" << '//E*O*F psdraft//'
X#! /bin/sh
X#
X# Put the word "DRAFT" (or a specified word) on each page of a postscript
X# document.
X#
X# Usage:
X# 	psdraft -s draftstring file ...
X#
X#
X# Author: Spencer W. Thomas
X#	  Computer Science Dept.
X#	  University of Utah
X#	  thomas@cs.utah.edu
X#
X# Augmented to do grey string, choose font by:
X#		James H. Cloos, Jr.
X# currently @	Milard Filmore College
X#		State University of New York @ Buffalo
X#		cloos@ACSU.Buffalo.EDU ; cloos@ub.UUCP
X#
X
X#
X# Insert header after first line that does not begin %% or %!
X#
X
Xtrap "rm -f /tmp/psd$$.*" 0 1 2 15
X
Xdraftstring=DRAFT
Xgreylevel=.85
Xdogrey=DRAFTO
Xfont=Helvetica-Bold
Xdodrafto=DRAFTO
Xdodraftg=
X
Xwhile getopts s:g:f: cc
Xdo
X	case $cc in
X	s) draftstring=$OPTARG;;
X	g) greylevel=$OPTARG
X		dodrafto=
X		dodraftg=DRAFTG ;;
X	f) font=$OPTARG;;
X	\?) echo "Usage: psdraft [-s draftstring] files ..."
X		exit 2;;
X	esac
Xdone
X
Xshift `expr $OPTIND - 1`
X
X# Create sed script file
X
Xsed -e "s/(DRAFT)/($draftstring)/" \
X-e "s/(GREYLEVEL)/$greylevel/" \
X-e "s/ DODRAFTG / $dodraftg /" \
X-e "s/ DODRAFTO / $dodrafto /" \
X-e "s*/FONT*/$font*" <<'EOF' >/tmp/psd$$.sed
X1,/^[^%]/{ 
Xs/^%/%/
Xs/^$//
Xt skip
Xi\
X% Prelude to show a draft string on every page.\
X(DRAFT)\
X/DRAFTDICT 10 dict def\
XDRAFTDICT begin\
X/DRAFTSTRING exch def\
X/bd /FONT findfont def\
X/od bd maxlength 1 add dict def\
Xbd {exch dup /FID ne {exch od 3 1 roll put} {pop pop} ifelse} forall\
Xod /FontName /Outline0 put od /PaintType 2 put od /StrokeWidth 0 put\
X/Outline0 od definefont pop\
X/DRAFTO { gsave\
X	 initmatrix\
X	/Outline0 findfont setfont\
X	DRAFTSTRING dup stringwidth pop 8.875 exch div dup 72 mul dup scale\
X	52.3 rotate 2.5 exch div -.35 translate\
X	0 0 moveto show\
X	grestore } def\
X/DRAFTG { gsave\
X	 initmatrix\
X	/FONT findfont setfont (GREYLEVEL) setgray\
X	DRAFTSTRING dup stringwidth pop 8.875 exch div dup 72 mul dup scale\
X	52.3 rotate 2.5 exch div -.35 translate\
X	0 0 moveto show\
X	grestore } def\
X/oldshow /showpage load def\
X/oldcopy /copypage load def\
Xend\
X/showpage { DRAFTDICT begin DODRAFTO oldshow DODRAFTG end } def\
X/copypage { DRAFTDICT begin DODRAFTO oldcopy DODRAFTG end } def\
X% End of draft prelude
X: skip
X}
XEOF
X
Xcat $* | sed -f /tmp/psd$$.sed 
//E*O*F psdraft//

echo Possible errors detected by \'wc\' [hopefully none]:
temp=/tmp/shar$$
trap "rm -f $temp; exit" 0 1 2 3 15
cat > $temp <<\!!!
      96     353    2169 psdraft
!!!
wc  psdraft | sed 's=[^ ]*/==' | diff -b $temp -
exit 0
-==--==---==----==-----==------==-------==------==-----==----==---==--==-
Enjoy,

-JimC
--
James H. Cloos, Jr.		Phone:  +1 716 673-1250
cloos@ACSU.Buffalo.EDU		Snail:  PersonalZipCode:  14048-0772, USA
cloos@ub.UUCP			Quote:  <>