🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.postscript
Article #411

Re: PS-EPS-PS?

#411
From: Graham Beint
Date: Tue, 07 Apr 1992 19:12
117 lines
3615 bytes
In article <1992Apr1.143848.22242@athena.cs.uga.edu> dwivian@ada.stat.uga.edu (Dwivian Unterschreiber) writes:
>As everyone else in the free world, I'm looking for PS-EPS-PS converter


Don't understand!

A PS file comprises 1 or more pages, an EPS file 0 or 1 page acording to
the presence or absence of a call to showpage. Therefore PS->EPS? is not
generally meaningful.

EPSF->EPSI->EPSF and EPSF->PS are meaningful.

The former requires the addition and stripping of an EPSI header. This has
a length of 30 bytes first 4 in sequence are 0xC5 0xD0 0xD3 0xC6 (EPSF with
the top bits set) the next 4 would in this case be the number 30 and  the 4
after those would be the length of the EPSF file, both numbers in 
little-endian format, bytes 12-27 would all be 0 and bytes 28-29 can be 0xFFFF.

Piping the length through a bit of awk or whatever would generate the header.

Stripping the EPSF from an EPSI file is less easy in a script.

The following script can be used to convert stdin or a list of EPSF files
into a a PS document, scaling each EPSF image to the largest size that will
fit on the page. An optional argument determines whether or not the aspect
ratio is preserved.

I have come across some EPSF files which have a portrait bounding box but 
have obviously lost a switch to landscape since they proceed to image a 
letterbox image which is then clipped on the right.

-----------------------eps2ps---------------------------------------
#!/bin/sh

# Check first argument for aspect flag and assume rest are EPSF files
if [ "false" = "$1" -o "true" = "$1" ]
then
    bool="$1"
    shift
else
    bool=true
fi

echo '%!
% not prepared to honour it with a conformance level

% given the line BoundingBox: x0 y0 x1 y1
% scaleeps wil change the scaling appropriately
% x0 y0 x1 y1 bool scaleeps -
/scaleeps
{
    % query clip area
    gsave clippath pathbbox grestore

    4 copy
    % centre clip area
    2 div exch 2 div exch translate
    2 div exch 2 div exch translate

    % calculate width and height of clip area
    3 -1 roll sub exch 3 -1 roll sub exch

    % calculate x scaling
    exch 4 index 7 index sub div exch
    % calculate y scaling
    3 index 6 index sub div

    % scale but retain aspect ratio depending on bool
    3 -1 roll{2 copy gt{exch}if pop dup}if scale

    % centre epsf area
    -2 div exch -2 div exch translate
    -2 div exch -2 div exch translate
}bind def

/showeps
{save /VM exch def
    /Aspect exch def
    mark
    /StdIn (%stdin) (r) file def
    % scan for bounding box and then interpret rest of line to get limits
    {
	/BufIn 512 string def % should be enough
	/StrBB (%%BoundingBox:) def
	{
	    StdIn BufIn readline not{pop stop}if
	    StrBB anchorsearch exch pop{cvx exec exit}if
	}loop
    }stopped not
    % run input stream
    {
	/showpage{}def	% Turn of showpage until end of EPSF
	Aspect
	scaleeps
	{
	    StdIn cvx exec % run won't stop
	}stopped pop
    }if
    cleartomark
VM restore}bind def
'

for i in ${*--}
do
    echo "
%%Page: ? ?
$bool showeps
"

    cat $i

    echo '
% A crude way of handling end of page
stop
showpage
'
done
Technical Details
Message-ID: <1433@uniplex.co.uk>
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!uknet!acorn!uniplex!gb
References: <1992Apr1.143848.22242@athena.cs.uga.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!uknet!acorn!uniplex!gb
From: gb@uniplex.co.uk (Graham Beint)
Newsgroups: comp.lang.postscript
Subject: Re: PS-EPS-PS?
Message-ID: <1433@uniplex.co.uk>
Date: 7 Apr 92 19:12:45 GMT
References: <1992Apr1.143848.22242@athena.cs.uga.edu>
Reply-To: gb@uniplex.UUCP (Graham Beint)
Organization: Uniplex Limited, Redwood House, Hemel Hempstead
Lines: 117