| 1 |
#!@PERL@ |
| 2 |
|
| 3 |
# Find smallest page size in PPD file. |
| 4 |
# |
| 5 |
# Copyright 2018 Robert Krawitz ([email protected]) |
| 6 |
# |
| 7 |
# This program is free software; you can redistribute it and/or modify it |
| 8 |
# under the terms of the GNU General Public License as published by the Free |
| 9 |
# Software Foundation; either version 2 of the License, or (at your option) |
| 10 |
# any later version. |
| 11 |
# |
| 12 |
# This program is distributed in the hope that it will be useful, but |
| 13 |
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 14 |
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 15 |
# for more details. |
| 16 |
# |
| 17 |
# You should have received a copy of the GNU General Public License |
| 18 |
# along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 19 |
# |
| 20 |
# This is faster than using Gutenprint to do this; stp_init() is still |
| 21 |
# quite expensive for such small operations. |
| 22 |
|
| 23 |
use strict; |
| 24 |
|
| 25 |
open(PPD, $ENV{'PPD'}) || die "Can't open PPD file $ENV{'PPD'}: $!\n"; |
| 26 |
my ($min_size_name) = ""; |
| 27 |
my ($min_size_dim) = 0; |
| 28 |
while (<PPD>) { |
| 29 |
if ($min_size_name ne '' && ! /^\*PaperDimension/) { |
| 30 |
print "$min_size_name\n"; |
| 31 |
exit; |
| 32 |
} |
| 33 |
next if (! /^\*PaperDimension/); |
| 34 |
$_ =~ /^\*PaperDimension *([^\/]+)\/[^\"]*"([0-9.]+) *([0-9.]+)/; |
| 35 |
my ($pname) = $1; |
| 36 |
my ($x) = $2; |
| 37 |
my ($y) = $3; |
| 38 |
if ($min_size_name eq "" || ($x * $y < $min_size_dim)) { |
| 39 |
$min_size_name = $pname; |
| 40 |
$min_size_dim = $x * $y; |
| 41 |
} |
| 42 |
} |