head	1.2;
access;
symbols
	RELEASE_8_3_0:1.2
	RELEASE_9_0_0:1.2
	RELEASE_7_4_0:1.2
	RELEASE_8_2_0:1.2
	RELEASE_8_1_0:1.2
	RELEASE_7_3_0:1.2
	RELEASE_8_0_0:1.2
	RELEASE_7_2_0:1.2
	RELEASE_7_1_0:1.2
	RELEASE_6_4_0:1.2
	RELEASE_6_3_0:1.2
	RELEASE_7_0_0:1.2
	RELEASE_6_2_0:1.2
	RELEASE_5_5_0:1.2
	RELEASE_6_1_0:1.2
	RELEASE_6_0_0:1.2
	RELEASE_5_4_0:1.2
	RELEASE_4_11_0:1.2
	RELEASE_5_3_0:1.2
	ISBN_1-57176-328-7:1.2;
locks; strict;
comment	@# @;


1.2
date	2004.07.23.18.58.55;	author hrs;	state Exp;
branches;
next	1.1;

1.1
date	2004.07.23.18.53.34;	author hrs;	state Exp;
branches;
next	;


desc
@@


1.2
log
@Remove trailing whitespaces.
@
text
@#!/usr/bin/perl -w
# $FreeBSD$
#
# epsgeom - extract geometry from a EPS file.
#
# Copyright (C) 2004 The FreeBSD Project. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#

my $x;
my $y;
my $width;
my $height;

my $gx;
my $gy;

if (@@ARGV != 4) {
	die "Error: invalid arguments.\n";
}

my $mode = shift @@ARGV;
my $hres = shift @@ARGV;
my $vres = shift @@ARGV;
my $file = shift @@ARGV;

my $realfile = `realpath ${file}`;
chomp $realfile;

open IN, "<$realfile" or die "Error: cannot open $realfile.\n";
while(<IN>) {
	last if (($x,$y,$width,$height) =
		/^%%BoundingBox:\s+([-\d]+)\s+([-\d]+)\s+([-\d]+)\s+([-\d]+)/);
	#print STDERR "DEBUG: $_";
}
close IN;

if (not defined($x)) {
	die "Error: no BoundingBox found.\n";
}

$width -= $x;
$height -= $y;

# (int)(((double)hres * (double)width  / 72.0) + 0.5),
$gx = $hres * $width / 72.0 + 0.5;
# (int)(((double)vres * (double)height / 72.0) + 0.5),
$gy = $vres * $height / 72.0 + 0.5;

my %replace = (
	       '@@X@@' => int $x,
	       '@@Y@@' => int $y,
	       '@@MX@@' => int -$x,
	       '@@MY@@' => int -$y,
	       '@@WIDTH@@'  => int $width,
	       '@@MWIDTH@@' => int -$width,
	       '@@HEIGHT@@' => int $height,
	       '@@MHEIGHT@@' => int -$height,
	       '@@ANGLE@@' => int 0,
	       '@@INPUT@@' => $realfile,
	       );

if ($mode eq "-replace") {
	foreach my $i (keys %replace) {
		printf "-e s,%s,%s,g ", $i, $replace{$i};
	}
} elsif ($mode eq "-offset") {
	#print STDERR "DEBUG: (int -$x), $y\n";
	printf "<< /PageOffset [%d %d] >> setpagedevice\n", (int -$x), $y;
	open IN, "<$realfile" or die "Error: cannot open $realfile.\n";
	print while(<IN>);
	close IN;
	print "\n";
	print "showpage\n";
} elsif ($mode eq "-geom") {
	#print STDERR "DEBUG: $x,$y,$width,$height\n";
	printf "%dx%d", $gx, $gy;
} else {
	die "Error: invalid mode specified.\n";
}

__END__
@


1.1
log
@Fix a build problem when print/ghostscript-afpl is used:
 - epsgeom+gs now converts EPS files.  graphics/peps is no longer used.
 - Add $PERL, $REALPATH, and $SETENV into doc.project.mk.

Tested by:	simon
@
text
@d16 1
a16 1
# 
@

