summaryrefslogtreecommitdiff
path: root/src/cups/min-pagesize.in
blob: 06cd148303505b520cf737ac0be417c1775ba977 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!@PERL@

# Find smallest page size in PPD file.
#
# Copyright 2018 Robert Krawitz (rlk@alum.mit.edu)
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
#
# This is faster than using Gutenprint to do this; stp_init() is still
# quite expensive for such small operations.

use strict;

open(PPD, $ENV{'PPD'}) || die "Can't open PPD file $ENV{'PPD'}: $!\n";
my ($min_size_name) = "";
my ($min_size_dim) = 0;
while (<PPD>) {
    if ($min_size_name ne '' && ! /^\*PaperDimension/) {
	print "$min_size_name\n";
	exit;
    }
    next if (! /^\*PaperDimension/);
    $_ =~ /^\*PaperDimension *([^\/]+)\/[^\"]*"([0-9.]+) *([0-9.]+)/;
    my ($pname) = $1;
    my ($x) = $2;
    my ($y) = $3;
    if ($min_size_name eq "" || ($x * $y < $min_size_dim)) {
	$min_size_name = $pname;
	$min_size_dim = $x * $y;
    }
}