ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: "George N. White III" <aa056@chebucto.ns.ca>
Subject: Re: %%BoundingBox: (atend)
Date: Wed, 02 Jun 2004 10:13:33 -0300	[thread overview]
Message-ID: <Pine.SGI.4.60.0406020743050.107538@montigo.bio.dfo.ca> (raw)
In-Reply-To: <6.1.1.1.2.20040601203359.07de2640@server-1>

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1038 bytes --]

On Tue, 1 Jun 2004, Hans Hagen wrote:

> At 14:24 30/05/2004, you wrote:
>> Hello,
>> ConTeXt does not find the EPS-BoundingBox in EPS files generated by 
>> xmgrace.
>> Such a file begins like this:
>> 
>> %!PS-Adobe-3.0 EPSF-3.0
>> %%BoundingBox: (atend)
> [...]
>> If not, I'm going to write a script, that converts the file.
>
> if you have a small demo file i can add that feature to texutil

I'd suggest adopting some of the conventions used by the
LaTeX2e graphics bundle, in particular, to look for the 
BoundingBox in filename.(e)ps.bb.

Rather than making texutil more complex a separate tool (findbb, attached)
that reliably writes the bbox by trying several methods, even using the 
ghostscript bbox device to generate one (e.g., in the case of files 
created with dvips -E that get incorrect BoundingBox entries because the 
dvips calculation ignores things drawn by \specials).

Try "findbb xmgracefile.ps > xmgracefile.ps.bb"

--
George N. White III  <aa056@chebucto.ns.ca>
   Head of St. Margarets Bay, Nova Scotia, Canada

[-- Attachment #2: unix ksh script (should work with bash) to find BoundingBox --]
[-- Type: TEXT/PLAIN, Size: 2434 bytes --]

#! /bin/ksh
# findbb -- write PostScript BoundingBox to stdout

# Notes:

# 0. The '-b' flag can be used with .pdf files.

# 1. (e)ps files may contain binary preview images and may
#    use non-native newlines, so must be handled as binary.  
#    Our approach is to grab the first 5000 bytes
#    of the file, then convert \012 and \015 to \012 for
#    processing with tools intended for use with text files.

# 2. if the file does not provide a BoundingBox line, use
#    the GhostScript bbox device (-b flag) to generate one.

# 3. if the first entry is %%BoundingBox: (atend), examine
#    the last 5000 bytes of the file

# Bugs:
#    Does not normalize the line by adding a space after the ':'
#    Does not handle large preview images

# Author: George N. White III <aa056@chebucto.ns.ca>
#     

pgm="$(basename $0)"
usage="usage: $pgm [-b] filename"

TMPDIR=${TMPDIR:-/usr/tmp}
GS_PROG=${GS_PROG:-gsc} 

tempnm=$(mktemp $TMPDIR/$pgm-temp.XXXXXXXXXX ) || exit 1
pipenm=$(mktemp $TMPDIR/$pgm-pipe.XXXXXXXXXX ) || exit 1
/sbin/rm -f "$pipenm" && /sbin/mknod "$pipenm" p

trap "rm -f $tempnm $pipenm ; exit \$rc" 0

flags=""
case $# in
2) case $1 in
   -b) flags="b$flags" ; shift
       ;;
    *) print -u2 $usage ; exit 1
       ;;
    esac
    ;;
1)  ;;
*)  print -u2 $usage ; exit 1
    ;;
esac

# can we read the file?
if [ -r "$1" ] ; then
    fnm="$1"
else
    print -u2 "$pgm: unable to read file <$1>."
    exit 1
fi

case $flags in
*b*) $GS_PROG -q -dBATCH -dNOPAUSE -sDEVICE=bbox $fnm > $tempnm 2>&1 
     set $(grep --max-count=1 '^%%BoundingBox:' $tempnm ) || exit 1
     ;;
*)   set $(head --bytes=5000 $fnm | tr '[\012\015]' '\012' | grep --max-count=1 '^%%BoundingBox:') || exit 1
     ;;
esac

case "$#" in
1|2) # handle '^%%BoundingBox:(atend)' and '^%%BoundingBox: (atend)'
   case "$1$2" in
   %%BoundingBox:\(atend\)) print -u2 "$pgm -- looking 'atend'"
       bbox=$(tail --bytes=5000 $fnm | tr '[\012\015]' '\012' \
            | grep '^%%BoundingBox:'|tail -1)
       ;;
   *)
       print -u2 "$pgm failed to find BoundingBox" ; exit 1
       ;;
   esac
   ;;
4|5) # handle BoundingBox:NN ... and BoundingBox: NN ...
   case "$1$2" in
   %%BoundingBox:*)   bbox="$@"
       ;;
   *)
       ;;
   esac
   ;;
*) print -u2 "$pgm failed to find BoundingBox, try setting '-b' flag." ; exit 1
   
esac
print "$bbox"

  reply	other threads:[~2004-06-02 13:13 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-05-30 12:24 Peter Münster
2004-06-01 18:35 ` Hans Hagen
2004-06-02 13:13   ` George N. White III [this message]
2004-06-02 13:46     ` Taco Hoekwater
2004-06-02 18:13       ` Peter Münster
2004-06-03  7:50         ` Taco Hoekwater
2004-06-03 16:52           ` Peter Münster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.SGI.4.60.0406020743050.107538@montigo.bio.dfo.ca \
    --to=aa056@chebucto.ns.ca \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).