From 3950c83c2919fe59dbf442c0d4859778fadd0e8d Mon Sep 17 00:00:00 2001 From: Roger Leigh Date: Sun, 26 Oct 2008 16:16:09 +0000 Subject: Imported Upstream version 4.3.99+cvs20060521 --- src/cups/Makefile.am | 17 +-- src/cups/Makefile.in | 98 +++++++++++++++-- src/cups/cups-genppdupdate.in | 165 +++++++++++++++++++++-------- src/cups/epson.c | 13 +-- src/cups/genppd.c | 239 +++++++++++++++++++++++++----------------- src/cups/rastertoprinter.c | 107 +++++++++++++++++-- src/cups/test-ppds | 56 ++++++++++ 7 files changed, 521 insertions(+), 174 deletions(-) create mode 100755 src/cups/test-ppds (limited to 'src/cups') diff --git a/src/cups/Makefile.am b/src/cups/Makefile.am index f4ffc06..011bd07 100644 --- a/src/cups/Makefile.am +++ b/src/cups/Makefile.am @@ -1,4 +1,4 @@ -## $Id: Makefile.am,v 1.83 2005/11/22 14:43:05 rleigh Exp $ +## $Id: Makefile.am,v 1.87 2006/05/14 16:46:03 rlk Exp $ ## Copyright (C) 2000 Roger Leigh ## ## This program is free software; you can redistribute it and/or modify @@ -45,6 +45,9 @@ endif LOCAL_CPPFLAGS = $(GUTENPRINT_CFLAGS) $(CUPS_CFLAGS) +STP_ENV= STP_MODULE_PATH=$(top_builddir)/src/main/.libs:$(top_builddir)/src/main STP_DATA_PATH=$(top_srcdir)/src/main + +TESTS= test-ppds ## Programs @@ -157,7 +160,7 @@ all-local: $(INSTALL_DATA_LOCAL_DEPS) ppd: ppd-stamp -ppd-stamp: cups-genppd.@GUTENPRINT_MAJOR_VERSION@.@GUTENPRINT_MINOR_VERSION@ $(top_srcdir)/src/main/printers.xml $(top_srcdir)/src/main/papers.xml +ppd-stamp: cups-genppdconfig.@GUTENPRINT_MAJOR_VERSION@.@GUTENPRINT_MINOR_VERSION@ cups-genppd.@GUTENPRINT_MAJOR_VERSION@.@GUTENPRINT_MINOR_VERSION@ $(top_srcdir)/src/main/printers.xml $(top_srcdir)/src/main/papers.xml $(MAKE) ppd-stamp-phony touch ppd-stamp @@ -171,7 +174,7 @@ ppd-nonls: cups-genppd.@GUTENPRINT_MAJOR_VERSION@.@GUTENPRINT_MINOR_VERSION@ for language in C ; do \ mkdir ppd/$$language ; \ echo "$$language:" ; \ - LANGUAGE=$$language ./cups-genppd.@GUTENPRINT_MAJOR_VERSION@.@GUTENPRINT_MINOR_VERSION@ -p ppd/$$language ; \ + LANGUAGE=$$language $(STP_ENV) ./cups-genppd.@GUTENPRINT_MAJOR_VERSION@.@GUTENPRINT_MINOR_VERSION@ @WHICH_PPDS@ -p ppd/$$language ; \ done ppd-nls: cups-genppd.@GUTENPRINT_MAJOR_VERSION@.@GUTENPRINT_MINOR_VERSION@ @@ -179,10 +182,10 @@ ppd-nls: cups-genppd.@GUTENPRINT_MAJOR_VERSION@.@GUTENPRINT_MINOR_VERSION@ cd $(top_builddir)/po ; \ $(MAKE) ; \ $(MAKE) DESTDIR= prefix=$${wdir}/catalog datadir=$${wdir}/catalog/share install - for language in `./cups-genppd.@GUTENPRINT_MAJOR_VERSION@.@GUTENPRINT_MINOR_VERSION@ -L -c \`pwd\`/catalog/share/locale` ; do \ + for language in `$(STP_ENV) ./cups-genppd.@GUTENPRINT_MAJOR_VERSION@.@GUTENPRINT_MINOR_VERSION@ -L -c \`pwd\`/catalog/share/locale` ; do \ mkdir ppd/$$language ; \ echo "$$language:" ; \ - LANGUAGE=$$language ./cups-genppd.@GUTENPRINT_MAJOR_VERSION@.@GUTENPRINT_MINOR_VERSION@ -p ppd/$$language -c `pwd`/catalog/share/locale ; \ + LANGUAGE=$$language $(STP_ENV) ./cups-genppd.@GUTENPRINT_MAJOR_VERSION@.@GUTENPRINT_MINOR_VERSION@ @WHICH_PPDS@ -p ppd/$$language -c `pwd`/catalog/share/locale ; \ done $(RM) -r catalog @@ -213,5 +216,7 @@ EXTRA_DIST = \ README \ calibrate.ppm \ command.txt \ - command.types + command.types \ + test-ppds + diff --git a/src/cups/Makefile.in b/src/cups/Makefile.in index 9f1ccf9..b0b8b9e 100644 --- a/src/cups/Makefile.in +++ b/src/cups/Makefile.in @@ -16,6 +16,9 @@ # Variables +#export STP_MODULE_PATH = $(top_builddir)/src/main/.libs:$(top_builddir)/src/main +#export STP_DATA_PATH = $(top_srcdir)/src/main + srcdir = @srcdir@ @@ -321,6 +324,7 @@ USE_NLS = @USE_NLS@ USE_NLS_FALSE = @USE_NLS_FALSE@ USE_NLS_TRUE = @USE_NLS_TRUE@ VERSION = @VERSION@ +WHICH_PPDS = @WHICH_PPDS@ XGETTEXT = @XGETTEXT@ YACC = @YACC@ ac_ct_AR = @ac_ct_AR@ @@ -388,6 +392,8 @@ cupsexec_filterdir = $(pkglibdir)/filter @CUPS_PPDS_AT_TOP_LEVEL_TRUE@cups_modeldir = $(pkgdatadir)/model/ @CUPS_PPDS_AT_TOP_LEVEL_TRUE@DONT_UNINSTALL_PPDS = true LOCAL_CPPFLAGS = $(GUTENPRINT_CFLAGS) $(CUPS_CFLAGS) +STP_ENV = STP_MODULE_PATH=$(top_builddir)/src/main/.libs:$(top_builddir)/src/main STP_DATA_PATH=$(top_srcdir)/src/main +TESTS = test-ppds @BUILD_CUPS_TRUE@sbin_SCRIPTS = cups-genppdconfig.@GUTENPRINT_MAJOR_VERSION@.@GUTENPRINT_MINOR_VERSION@ cups-genppdupdate.@GUTENPRINT_MAJOR_VERSION@.@GUTENPRINT_MINOR_VERSION@ @BUILD_GENPPD_STATIC_TRUE@STATIC_LDOPTS = -static -export-dynamic cups_calibrate_SOURCES = cups-calibrate.c @@ -420,7 +426,8 @@ EXTRA_DIST = \ README \ calibrate.ppm \ command.txt \ - command.types + command.types \ + test-ppds all: all-am @@ -719,6 +726,79 @@ GTAGS: distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags +check-TESTS: $(TESTS) + @failed=0; all=0; xfail=0; xpass=0; skip=0; \ + srcdir=$(srcdir); export srcdir; \ + list='$(TESTS)'; \ + if test -n "$$list"; then \ + for tst in $$list; do \ + if test -f ./$$tst; then dir=./; \ + elif test -f $$tst; then dir=; \ + else dir="$(srcdir)/"; fi; \ + if $(TESTS_ENVIRONMENT) $${dir}$$tst; then \ + all=`expr $$all + 1`; \ + case " $(XFAIL_TESTS) " in \ + *" $$tst "*) \ + xpass=`expr $$xpass + 1`; \ + failed=`expr $$failed + 1`; \ + echo "XPASS: $$tst"; \ + ;; \ + *) \ + echo "PASS: $$tst"; \ + ;; \ + esac; \ + elif test $$? -ne 77; then \ + all=`expr $$all + 1`; \ + case " $(XFAIL_TESTS) " in \ + *" $$tst "*) \ + xfail=`expr $$xfail + 1`; \ + echo "XFAIL: $$tst"; \ + ;; \ + *) \ + failed=`expr $$failed + 1`; \ + echo "FAIL: $$tst"; \ + ;; \ + esac; \ + else \ + skip=`expr $$skip + 1`; \ + echo "SKIP: $$tst"; \ + fi; \ + done; \ + if test "$$failed" -eq 0; then \ + if test "$$xfail" -eq 0; then \ + banner="All $$all tests passed"; \ + else \ + banner="All $$all tests behaved as expected ($$xfail expected failures)"; \ + fi; \ + else \ + if test "$$xpass" -eq 0; then \ + banner="$$failed of $$all tests failed"; \ + else \ + banner="$$failed of $$all tests did not behave as expected ($$xpass unexpected passes)"; \ + fi; \ + fi; \ + dashes="$$banner"; \ + skipped=""; \ + if test "$$skip" -ne 0; then \ + skipped="($$skip tests were not run)"; \ + test `echo "$$skipped" | wc -c` -le `echo "$$banner" | wc -c` || \ + dashes="$$skipped"; \ + fi; \ + report=""; \ + if test "$$failed" -ne 0 && test -n "$(PACKAGE_BUGREPORT)"; then \ + report="Please report to $(PACKAGE_BUGREPORT)"; \ + test `echo "$$report" | wc -c` -le `echo "$$banner" | wc -c` || \ + dashes="$$report"; \ + fi; \ + dashes=`echo "$$dashes" | sed s/./=/g`; \ + echo "$$dashes"; \ + echo "$$banner"; \ + test -z "$$skipped" || echo "$$skipped"; \ + test -z "$$report" || echo "$$report"; \ + echo "$$dashes"; \ + test "$$failed" -eq 0; \ + else :; fi + distdir: $(DISTFILES) $(mkdir_p) $(distdir)/../../scripts @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \ @@ -751,6 +831,7 @@ distdir: $(DISTFILES) top_distdir="$(top_distdir)" distdir="$(distdir)" \ dist-hook check-am: all-am + $(MAKE) $(AM_MAKEFLAGS) check-TESTS check: check-am all-am: Makefile $(PROGRAMS) $(SCRIPTS) $(DATA) all-local installdirs: @@ -842,8 +923,8 @@ uninstall-am: uninstall-binPROGRAMS uninstall-cupsexec_backendPROGRAMS \ uninstall-local uninstall-pkgdataDATA uninstall-pkgsysconfDATA \ uninstall-sbinPROGRAMS uninstall-sbinSCRIPTS -.PHONY: CTAGS GTAGS all all-am all-local check check-am clean \ - clean-binPROGRAMS clean-cupsexec_backendPROGRAMS \ +.PHONY: CTAGS GTAGS all all-am all-local check check-TESTS check-am \ + clean clean-binPROGRAMS clean-cupsexec_backendPROGRAMS \ clean-cupsexec_filterPROGRAMS clean-generic clean-libtool \ clean-local clean-sbinPROGRAMS ctags dist-hook distclean \ distclean-compile distclean-generic distclean-libtool \ @@ -867,9 +948,6 @@ uninstall-am: uninstall-binPROGRAMS uninstall-cupsexec_backendPROGRAMS \ @SET_MAKE@ -export STP_MODULE_PATH = $(top_builddir)/src/main/.libs:$(top_builddir)/src/main -export STP_DATA_PATH = $(top_srcdir)/src/main - # Rules $(top_builddir)/src/main/libgutenprint.la: @@ -933,7 +1011,7 @@ all-local: $(INSTALL_DATA_LOCAL_DEPS) ppd: ppd-stamp -ppd-stamp: cups-genppd.@GUTENPRINT_MAJOR_VERSION@.@GUTENPRINT_MINOR_VERSION@ $(top_srcdir)/src/main/printers.xml $(top_srcdir)/src/main/papers.xml +ppd-stamp: cups-genppdconfig.@GUTENPRINT_MAJOR_VERSION@.@GUTENPRINT_MINOR_VERSION@ cups-genppd.@GUTENPRINT_MAJOR_VERSION@.@GUTENPRINT_MINOR_VERSION@ $(top_srcdir)/src/main/printers.xml $(top_srcdir)/src/main/papers.xml $(MAKE) ppd-stamp-phony touch ppd-stamp @@ -947,7 +1025,7 @@ ppd-nonls: cups-genppd.@GUTENPRINT_MAJOR_VERSION@.@GUTENPRINT_MINOR_VERSION@ for language in C ; do \ mkdir ppd/$$language ; \ echo "$$language:" ; \ - LANGUAGE=$$language ./cups-genppd.@GUTENPRINT_MAJOR_VERSION@.@GUTENPRINT_MINOR_VERSION@ -p ppd/$$language ; \ + LANGUAGE=$$language $(STP_ENV) ./cups-genppd.@GUTENPRINT_MAJOR_VERSION@.@GUTENPRINT_MINOR_VERSION@ @WHICH_PPDS@ -p ppd/$$language ; \ done ppd-nls: cups-genppd.@GUTENPRINT_MAJOR_VERSION@.@GUTENPRINT_MINOR_VERSION@ @@ -955,10 +1033,10 @@ ppd-nls: cups-genppd.@GUTENPRINT_MAJOR_VERSION@.@GUTENPRINT_MINOR_VERSION@ cd $(top_builddir)/po ; \ $(MAKE) ; \ $(MAKE) DESTDIR= prefix=$${wdir}/catalog datadir=$${wdir}/catalog/share install - for language in `./cups-genppd.@GUTENPRINT_MAJOR_VERSION@.@GUTENPRINT_MINOR_VERSION@ -L -c \`pwd\`/catalog/share/locale` ; do \ + for language in `$(STP_ENV) ./cups-genppd.@GUTENPRINT_MAJOR_VERSION@.@GUTENPRINT_MINOR_VERSION@ -L -c \`pwd\`/catalog/share/locale` ; do \ mkdir ppd/$$language ; \ echo "$$language:" ; \ - LANGUAGE=$$language ./cups-genppd.@GUTENPRINT_MAJOR_VERSION@.@GUTENPRINT_MINOR_VERSION@ -p ppd/$$language -c `pwd`/catalog/share/locale ; \ + LANGUAGE=$$language $(STP_ENV) ./cups-genppd.@GUTENPRINT_MAJOR_VERSION@.@GUTENPRINT_MINOR_VERSION@ @WHICH_PPDS@ -p ppd/$$language -c `pwd`/catalog/share/locale ; \ done $(RM) -r catalog diff --git a/src/cups/cups-genppdupdate.in b/src/cups/cups-genppdupdate.in index 1b90140..b0c3b0b 100644 --- a/src/cups/cups-genppdupdate.in +++ b/src/cups/cups-genppdupdate.in @@ -1,5 +1,5 @@ #! @PERL@ -w -# $Id: cups-genppdupdate.in,v 1.22 2005/12/24 22:41:11 rlk Exp $ +# $Id: cups-genppdupdate.in,v 1.24 2006/03/29 02:27:15 rlk Exp $ # Update CUPS PPDs for Gutenprint queues. # Copyright (C) 2002-2003 Roger Leigh (rleigh@debian.org) # @@ -37,6 +37,8 @@ our $opt_n; # No action our $opt_q; # Quiet mode our $opt_s; # Source PPD location our $opt_v; # Verbose mode +our $opt_N; # Don't update PPD file options +our $opt_o; # Output directory my $debug = 0; my $verbose = 0; # Verbose output @@ -45,11 +47,13 @@ if ($debug) { } my $quiet = 0; # No output my $no_action = 0; # Don't output files +my $reset_defaults = 0; # Reset options to default settings my $version = "@GUTENPRINT_MAJOR_VERSION@.@GUTENPRINT_MINOR_VERSION@"; my $ppd_dir = "@cups_conf_serverroot@/ppd"; # Location of in-use CUPS PPDs my $ppd_root_dir = "@cups_conf_datadir@/model"; my $ppd_base_dir = "$ppd_root_dir/gutenprint/$version"; # Available PPDs +my $ppd_out_dir = ""; # By default output into source directory my $gzext = ".gz"; my $updated_ppd_count = 0; @@ -65,6 +69,7 @@ my %languagemappings = ( "french" => "fr", "german" => "de", "greek" => "el", + "hungarian" => "hu", "italian" => "it", "japanese" => "jp", "norwegian" => "no", @@ -90,10 +95,44 @@ umask 0177; # Find all in-use Gutenprint PPD files... -my @ppdglob = glob("$ppd_dir/*.{ppd,PPD}"); +my @ppdglob; +if (@ARGV) { + my $f; + foreach $f (@ARGV) { + if (-f $f and ($f =~ /\.ppd$/i or $f =~ /\//)) { + if (-f $f) { + push @ppdglob, $f; + } else { + print STDERR "Cannot find file $f\n"; + } + } elsif (-f "$ppd_dir/$f" or + -f "$ppd_dir/$f.ppd" or + -f "$ppd_dir/$f.PPD") { + if (-f "$ppd_dir/$f") { + push @ppdglob, "$ppd_dir/$f"; + } + if (-f "$ppd_dir/$f.ppd") { + push @ppdglob, "$ppd_dir/$f.ppd"; + } + if (-f "$ppd_dir/$f.PPD") { + push @ppdglob, "$ppd_dir/$f.PPD"; + } + } else { + print STDERR "Cannot find file $ppd_dir/$f, $ppd_dir/$f.ppd, or $ppd_dir/$f.PPD\n"; + } + } +} else { + @ppdglob = glob("$ppd_dir/*.{ppd,PPD}"); +} my $ppdlist = join ' ', @ppdglob; if (@ppdglob) { - open PPDFILES, '-|', 'egrep', '-i', '-l', 'Gutenprint|Gimp-Print', @ppdglob or die "can't grep $ppd_dir/*: $!"; + open PPDFILES, '-|', 'egrep', '-i', '-l', 'Gutenprint|Gimp-Print', @ppdglob or die "can't grep $ppdlist: $!"; + while () { + chomp; + push @ppd_files, $_; + } + open PPDFILES, '-|', 'egrep', '-i', '-L', 'Foomatic', @ppd_files or die "can't grep $ppdlist: $!"; + @ppd_files = (); while () { chomp; push @ppd_files, $_; @@ -118,7 +157,11 @@ foreach (@ppd_files) { if (!$quiet || $verbose) { if ($updated_ppd_count > 0) { - print STDOUT "Updated $updated_ppd_count PPD files. Restart cupsd for the changes to take effect.\n"; + my $plural = ""; + if ($updated_ppd_count != 1) { + $plural = "s"; + } + print STDOUT "Updated $updated_ppd_count PPD file${plural}. Restart cupsd for the changes to take effect.\n"; exit (0); } else { print STDOUT "Failed to update any PPD files\n"; @@ -129,7 +172,7 @@ if (!$quiet || $verbose) { sub parse_options () { - getopts("dhnqs:v"); + getopts("dhnqs:vNo:"); if ($opt_n) { $no_action = 1; @@ -142,7 +185,7 @@ sub parse_options () { $ppd_base_dir = "$opt_s"; } else { - die "$opt_s: invalid directory: $!"; + die "$opt_s: invalid directory: $!\n"; } } if ($opt_v) { @@ -153,8 +196,19 @@ sub parse_options () { $verbose = 0; $quiet = 1; } + if ($opt_N) { + $reset_defaults = 1; + } + if ($opt_o) { + if (-d $opt_o) { + $ppd_out_dir = "$opt_o"; + } + else { + die "$opt_s: invalid directory: $!\n"; + } + } if ($opt_h) { - print "Usage: $0 [OPTION]...\n"; + print "Usage: $0 [OPTION]... [PPD_FILE]...\n"; print "Update CUPS+Gutenprint PPD files.\n\n"; print " -d Enable debugging\n"; print " -h Display this help text\n"; @@ -162,6 +216,8 @@ sub parse_options () { print " -q Quiet mode. No messages except errors.\n"; print " -s ppd_dir Use ppd_dir as the source PPD directory.\n"; print " -v Verbose messages.\n"; + print " -N Reset options to defaults.\n"; + print " -o out_dir Output PPD files to out_dir.\n"; exit (0); } } @@ -170,6 +226,11 @@ sub parse_options () { # Update the named PPD file. sub update_ppd ($) { my $ppd_source_filename = $_; + my $ppd_dest_filename = $ppd_source_filename; + if ($ppd_out_dir) { + $ppd_dest_filename =~ s;(.*)/([^/]+);$2;; + $ppd_dest_filename = "$ppd_out_dir/$ppd_dest_filename"; + } open ORIG, $_ or die "$_: can't open PPD file: $!"; seek (ORIG, 0, 0) or die "can't seek to start of PPD file"; @@ -177,7 +238,6 @@ sub update_ppd ($) { if ($debug) { print "Source Filename: $ppd_source_filename\n"; } - # Get the `PCFileName'; the new source PPD will have the same name. my ($filename) = ""; my ($driver) = ""; my ($gutenprintdriver) = ""; @@ -322,45 +382,46 @@ sub update_ppd ($) { } - # Update source buffer with old defaults... + if (! $reset_defaults) { + # Update source buffer with old defaults... - # Loop through each default in turn. + # Loop through each default in turn. default_loop: - foreach (sort keys %defaults) { - my $default_option = $_; - my $option; - ($option = $_) =~ s/Default//; # Strip off `Default' - # Check method is valid - my $orig_method = $orig_default_types{$option}; - my $new_method = $new_default_types{$option}; - if ((!defined($orig_method) || !defined($new_method)) || - $orig_method ne $new_method) { - next; - } - if ($new_method eq "PickOne") { - # Check the old setting is valid - foreach (@{$options{$option}}) { - if ($defaults{$default_option} eq $_) { # Valid option - # Set the option in the new PPD - $source_data =~ s/\*($default_option).*/*$1:$defaults{$default_option}/m; - if ($verbose) { - print "$ppd_source_filename: Set *$default_option to $defaults{$default_option}\n"; + foreach (sort keys %defaults) { + my $default_option = $_; + my $option; + ($option = $_) =~ s/Default//; # Strip off `Default' + # Check method is valid + my $orig_method = $orig_default_types{$option}; + my $new_method = $new_default_types{$option}; + if ((!defined($orig_method) || !defined($new_method)) || + $orig_method ne $new_method) { + next; + } + if ($new_method eq "PickOne") { + # Check the old setting is valid + foreach (@{$options{$option}}) { + if ($defaults{$default_option} eq $_) { # Valid option + # Set the option in the new PPD + $source_data =~ s/\*($default_option).*/*$1:$defaults{$default_option}/m; + if ($verbose) { + print "$ppd_source_filename: Set *$default_option to $defaults{$default_option}\n"; + } + next default_loop; } - next default_loop; } + printf STDERR + "$ppd_source_filename: Invalid option: *$default_option: $defaults{$default_option}. Skipped.\n"; + next; } - printf STDERR - "$ppd_source_filename: Invalid option: *$default_option: $defaults{$default_option}. Skipped.\n"; - next; + print STDERR + "$ppd_source_filename: PPD OpenUI method $new_default_types{$_} not understood. Skipped\n"; } - print STDERR - "$ppd_source_filename: PPD OpenUI method $new_default_types{$_} not understood. Skipped\n"; } - # Write new PPD... - my $tmpnew = "${ppd_source_filename}.new"; + my $tmpnew = "${ppd_dest_filename}.new"; if (! open NEWPPD, "> $tmpnew") { warn "Can't open $tmpnew for writing: $!\n"; return 0; @@ -372,16 +433,20 @@ default_loop: return 0; } - if (! rename $tmpnew, $ppd_source_filename) { - warn "Can't rename $tmpnew to $ppd_source_filename: $!\n"; + if (! rename $tmpnew, $ppd_dest_filename) { + warn "Can't rename $tmpnew to $ppd_dest_filename: $!\n"; unlink $tmpnew; return 0; } - chown($orig_metadata[4], $orig_metadata[5], $ppd_source_filename); - chmod(($orig_metadata[2] & 0777), $ppd_source_filename); + chown($orig_metadata[4], $orig_metadata[5], $ppd_dest_filename); + chmod(($orig_metadata[2] & 0777), $ppd_dest_filename); if (!$quiet || $verbose) { - print STDOUT "Updated $ppd_source_filename using $source\n"; + if ($ppd_dest_filename eq $ppd_source_filename) { + print STDOUT "Updated $ppd_source_filename using $source\n"; + } else { + print STDOUT "Updated $ppd_source_filename to $ppd_dest_filename using $source\n"; + } } return 1; # All done! @@ -394,9 +459,14 @@ sub find_ppd ($$$$) { my ($key) = '^\\*FileVersion:[ ]*"@VERSION@"$'; my ($lingo, $suffix, $base, $basedir); my ($current_best_file, $current_best_time); - my ($stored_name, $stored_dir); + my ($stored_name, $stored_dir, $simplified); $stored_name = $gutenprintfilename; - $stored_name =~ s,.*/([^/]*)(.gz)?$,$1,; + $stored_name =~ s,.*/([^/]*)(.sim)?(.ppd)?(.gz)?$,$1,; + if ($gutenprintfilename =~ m,.*/([^/]*)(.sim)(.ppd)?(.gz)?$,) { + $simplified = ".sim"; + } else { + $simplified = ""; + } $stored_dir = $gutenprintfilename; $stored_dir =~ s,(.*)/([^/]*)$,$1,; @@ -411,8 +481,8 @@ sub find_ppd ($$$$) { "") { foreach $suffix (".ppd$gzext", ".ppd") { - foreach $base ("${drivername}.$version", - "stp-${drivername}.$version", + foreach $base ("${drivername}.$version${simplified}", + "stp-${drivername}.$version${simplified}", $stored_name, $drivername) { foreach $basedir ($ppd_base_dir, @@ -442,6 +512,9 @@ sub find_ppd ($$$$) { if ($sb[9] > $current_best_time) { $current_best_time = $sb[9]; $current_best_file = $fn; + if ($debug) { + print STDERR "***current_best_file is $fn\n"; + } } } elsif ($debug) { print " Format invalid\n"; diff --git a/src/cups/epson.c b/src/cups/epson.c index 434c1ae..38fec8c 100644 --- a/src/cups/epson.c +++ b/src/cups/epson.c @@ -1,5 +1,5 @@ /* - * "$Id: epson.c,v 1.6 2002/12/22 21:03:32 rleigh Exp $" + * "$Id: epson.c,v 1.7 2006/03/18 23:54:49 rlk Exp $" * * EPSON backend for the Common UNIX Printing System. * @@ -324,9 +324,10 @@ main(int argc, /* I - Number of command-line arguments (6 or 7) */ while (nbytes > 0) { - if ((wbytes = write(fd_out, bufptr, nbytes)) < 0 && errno == EAGAIN) + if ((wbytes = write(fd_out, bufptr, nbytes)) < 0 && + (errno == EAGAIN || errno == EINTR)) { - /* Write would block, so sleep 0.2s and retry... */ + /* Write would block, so sleep 0.002s and retry... */ /* * Check for possible data coming back from the printer... @@ -340,13 +341,13 @@ main(int argc, /* I - Number of command-line arguments (6 or 7) */ read_backchannel(fd_out); #if defined(HAVE_TIME_H) && defined(HAVE_NANOSLEEP) sleeptime.tv_sec = 0; - sleeptime.tv_nsec = 200000000; + sleeptime.tv_nsec = 2000000; nanosleep(&sleeptime, &sleeptime); #elif defined(HAVE_UNISTD_H) && defined(HAVE_USLEEP) usleep(200000); #else timeout.tv_sec = 0; - timeout.tv_usec = 200000; + timeout.tv_usec = 2000; select(1, NULL, NULL, NULL, &timeout); #endif continue; @@ -765,5 +766,5 @@ list_devices(void) /* - * End of "$Id: epson.c,v 1.6 2002/12/22 21:03:32 rleigh Exp $". + * End of "$Id: epson.c,v 1.7 2006/03/18 23:54:49 rlk Exp $". */ diff --git a/src/cups/genppd.c b/src/cups/genppd.c index bdff9fe..f9011b4 100644 --- a/src/cups/genppd.c +++ b/src/cups/genppd.c @@ -1,5 +1,5 @@ /* - * "$Id: genppd.c,v 1.113 2005/12/31 21:27:29 rlk Exp $" + * "$Id: genppd.c,v 1.117 2006/04/22 00:41:04 rlk Exp $" * * PPD file generation program for the CUPS drivers. * @@ -124,7 +124,6 @@ const char *special_options[] = "Resolution", "OutputOrder", "Quality", - "ImageType", "Duplex", NULL }; @@ -161,7 +160,7 @@ int checkcat (const struct dirent *localedir); void printlangs(char** langs); void printmodels(int verbose); int write_ppd(const stp_printer_t *p, const char *prefix, - const char *language, int verbose); + const char *language, int verbose, int simplified); /* @@ -218,6 +217,7 @@ main(int argc, /* I - Number of command-line arguments */ char **models = NULL; /* Models to output, all if NULL */ int opt_printlangs = 0; /* Print available translations */ int opt_printmodels = 0;/* Print available models */ + int which_ppds = 2; /* Simplified PPD's = 1, full = 2 */ /* * Parse command-line args... @@ -227,7 +227,7 @@ main(int argc, /* I - Number of command-line arguments */ for (;;) { - if ((i = getopt(argc, argv, "23hvqc:p:l:LMVd:")) == -1) + if ((i = getopt(argc, argv, "23hvqc:p:l:LMVd:sa")) == -1) break; switch (i) @@ -271,6 +271,12 @@ main(int argc, /* I - Number of command-line arguments */ case 'd': cups_modeldir = optarg; break; + case 's': + which_ppds = 1; + break; + case 'a': + which_ppds = 3; + break; case 'V': printf("cups-genppd version %s, " "Copyright (c) 1993-2005 by Easy Software Products and Robert Krawitz.\n\n", @@ -413,7 +419,11 @@ main(int argc, /* I - Number of command-line arguments */ if (printer) { - if (write_ppd(printer, prefix, language, verbose)) + if ((which_ppds & 1) && + write_ppd(printer, prefix, language, verbose, 1)) + return 1; + if ((which_ppds & 2) && + write_ppd(printer, prefix, language, verbose, 0)) return 1; } else @@ -430,8 +440,15 @@ main(int argc, /* I - Number of command-line arguments */ { printer = stp_get_printer_by_index(i); - if (printer && write_ppd(printer, prefix, language, verbose)) - return (1); + if (printer) + { + if ((which_ppds & 1) && + write_ppd(printer, prefix, language, verbose, 1)) + return (1); + if ((which_ppds & 2) && + write_ppd(printer, prefix, language, verbose, 0)) + return (1); + } } } if (!verbose) @@ -458,7 +475,7 @@ void usage(void) { puts("Usage: cups-genppd [-c localedir] " - "[-l locale] [-p prefix] [-q] [-v] models...\n" + "[-l locale] [-p prefix] [-s | -a] [-q] [-v] models...\n" " cups-genppd -L [-c localedir]\n" " cups-genppd -M [-v]\n" " cups-genppd -h\n" @@ -484,6 +501,8 @@ help(void) " -l locale Output PPDs translated with messages for locale.\n" " -p prefix Output PPDs in directory prefix.\n" " -d prefix Embed directory prefix in PPD file.\n" + " -s Generate simplified PPD files.\n" + " -a Generate all (simplified and full) PPD files.\n" " -q Quiet mode.\n" " -v Verbose mode.\n" "models:\n" @@ -745,7 +764,8 @@ int /* O - Exit status */ write_ppd(const stp_printer_t *p, /* I - Printer driver */ const char *prefix, /* I - Prefix (directory) for PPD files */ const char *language, - int verbose) + int verbose, + int simplified) { int i, j, k, l; /* Looping vars */ gzFile fp; /* File to write to */ @@ -772,8 +792,9 @@ write_ppd(const stp_printer_t *p, /* I - Printer driver */ stp_parameter_list_t param_list; const stp_param_string_t *opt; int has_quality_parameter = 0; - int has_image_type_parameter = 0; int printer_is_color = 0; + int maximum_level = simplified ? + STP_PARAMETER_LEVEL_BASIC : STP_PARAMETER_LEVEL_ADVANCED4; /* * Initialize driver-specific variables... @@ -819,8 +840,9 @@ write_ppd(const stp_printer_t *p, /* I - Printer driver */ * * stp-escp2-ex.5.0.ppd.gz */ - snprintf(filename, sizeof(filename) - 1, "%s/stp-%s.%s%s%s", - prefix, driver, GUTENPRINT_RELEASE_VERSION, ppdext, gzext); + snprintf(filename, sizeof(filename) - 1, "%s/stp-%s.%s%s%s%s", + prefix, driver, GUTENPRINT_RELEASE_VERSION, + simplified ? ".sim" : "", ppdext, gzext); /* * Open the PPD file... @@ -877,7 +899,8 @@ write_ppd(const stp_printer_t *p, /* I - Printer driver */ */ gzprintf(fp, "*PCFileName: \"STP%05d.PPD\"\n", - stp_get_printer_index_by_driver(driver)); + stp_get_printer_index_by_driver(driver) + + simplified ? stp_printer_model_count() : 0); gzprintf(fp, "*Manufacturer: \"%s\"\n", manufacturer); /* @@ -909,8 +932,9 @@ write_ppd(const stp_printer_t *p, /* I - Printer driver */ * If this is changed, the corresponding change must be made in * rastertoprinter.c. Look for "ppd->nickname" */ - gzprintf(fp, "*NickName: \"%s%s%s\"\n", - long_name, CUPS_PPD_NICKNAME_STRING, VERSION); + gzprintf(fp, "*NickName: \"%s%s%s%s\"\n", + long_name, CUPS_PPD_NICKNAME_STRING, VERSION, + simplified ? " Simplified" : ""); if (cups_ppd_ps_level == 2) gzputs(fp, "*PSVersion: \"(2017.000) 550\"\n"); else @@ -965,12 +989,13 @@ write_ppd(const stp_printer_t *p, /* I - Printer driver */ gzputs(fp, "*cupsFilter: \"application/vnd.cups-command 33 commandtoepson\"\n"); gzputs(fp, "\n"); gzprintf(fp, "*StpDriverName: \"%s\"\n", driver); - gzprintf(fp, "*StpPPDLocation: \"%s%s%s/stp-%s.%s%s%s\"\n", + gzprintf(fp, "*StpPPDLocation: \"%s%s%s/stp-%s.%s%s%s%s\"\n", cups_modeldir, cups_modeldir[strlen(cups_modeldir) - 1] == '/' ? "" : "/", language ? language : "C", driver, GUTENPRINT_RELEASE_VERSION, + simplified ? ".sim" : "", ppdext, gzext); gzprintf(fp, "*StpLocale: \"%s\"\n", language ? language : "C"); @@ -1006,6 +1031,10 @@ write_ppd(const stp_printer_t *p, /* I - Printer driver */ variable_sizes = 1; continue; } + if (simplified && num_opts >= 10 && + (papersize->paper_unit == PAPERSIZE_ENGLISH_EXTENDED || + papersize->paper_unit == PAPERSIZE_METRIC_EXTENDED)) + continue; width = papersize->width; height = papersize->height; @@ -1016,7 +1045,16 @@ write_ppd(const stp_printer_t *p, /* I - Printer driver */ stp_set_string_parameter(v, "PageSize", opt->name); stp_get_media_size(v, &width, &height); - stp_get_imageable_area(v, &left, &right, &bottom, &top); + stp_get_maximum_imageable_area(v, &left, &right, &bottom, &top); + + if (left < 0) + left = 0; + if (right > width) + right = width; + if (bottom > height) + bottom = height; + if (top < 0) + top = 0; the_papers[cur_opt].name = opt->name; the_papers[cur_opt].text = opt->text; @@ -1085,7 +1123,15 @@ write_ppd(const stp_printer_t *p, /* I - Printer driver */ &min_width, &min_height); stp_set_string_parameter(v, "PageSize", "Custom"); stp_get_media_size(v, &width, &height); - stp_get_imageable_area(v, &left, &right, &bottom, &top); + stp_get_maximum_imageable_area(v, &left, &right, &bottom, &top); + if (left < 0) + left = 0; + if (top < 0) + top = 0; + if (bottom > height) + bottom = height; + if (right > width) + width = right; gzprintf(fp, "*MaxMediaWidth: \"%d\"\n", max_width); gzprintf(fp, "*MaxMediaHeight: \"%d\"\n", max_height); @@ -1120,52 +1166,67 @@ write_ppd(const stp_printer_t *p, /* I - Printer driver */ gzprintf(fp, "*ColorModel Gray/Grayscale:\t\"<<" "/cupsColorSpace %d" "/cupsColorOrder %d" + "%s" ">>setpagedevice\"\n", - CUPS_CSPACE_W, CUPS_ORDER_CHUNKED); + CUPS_CSPACE_W, CUPS_ORDER_CHUNKED, + simplified ? "/cupsBitsPerColor 8" : ""); gzprintf(fp, "*ColorModel Black/Inverted Grayscale:\t\"<<" "/cupsColorSpace %d" "/cupsColorOrder %d" + "%s" ">>setpagedevice\"\n", - CUPS_CSPACE_K, CUPS_ORDER_CHUNKED); + CUPS_CSPACE_K, CUPS_ORDER_CHUNKED, + simplified ? "/cupsBitsPerColor 8" : ""); if (printer_is_color) { gzprintf(fp, "*ColorModel RGB/RGB Color:\t\"<<" "/cupsColorSpace %d" "/cupsColorOrder %d" + "%s" ">>setpagedevice\"\n", - CUPS_CSPACE_RGB, CUPS_ORDER_CHUNKED); + CUPS_CSPACE_RGB, CUPS_ORDER_CHUNKED, + simplified ? "/cupsBitsPerColor 8" : ""); gzprintf(fp, "*ColorModel CMY/CMY Color:\t\"<<" "/cupsColorSpace %d" "/cupsColorOrder %d" + "%s" ">>setpagedevice\"\n", - CUPS_CSPACE_CMY, CUPS_ORDER_CHUNKED); + CUPS_CSPACE_CMY, CUPS_ORDER_CHUNKED, + simplified ? "/cupsBitsPerColor 8" : ""); gzprintf(fp, "*ColorModel CMYK/CMYK:\t\"<<" "/cupsColorSpace %d" "/cupsColorOrder %d" + "%s" ">>setpagedevice\"\n", - CUPS_CSPACE_CMYK, CUPS_ORDER_CHUNKED); + CUPS_CSPACE_CMYK, CUPS_ORDER_CHUNKED, + simplified ? "/cupsBitsPerColor 8" : ""); gzprintf(fp, "*ColorModel KCMY/KCMY:\t\"<<" "/cupsColorSpace %d" "/cupsColorOrder %d" + "%s" ">>setpagedevice\"\n", - CUPS_CSPACE_KCMY, CUPS_ORDER_CHUNKED); + CUPS_CSPACE_KCMY, CUPS_ORDER_CHUNKED, + simplified ? "/cupsBitsPerColor 8" : ""); } gzputs(fp, "*CloseUI: *ColorModel\n\n"); - /* - * 8 or 16 bit color (16 bit is slower) - */ - gzputs(fp, "*OpenUI *StpColorPrecision/Color Precision: PickOne\n"); - gzputs(fp, "*OrderDependency: 10 AnySetup *StpColorPrecision\n"); - gzputs(fp, "*DefaultStpColorPrecision: Normal\n"); - gzputs(fp, "*StpColorPrecision Normal/Normal:\t\"<<" - "/cupsBitsPerColor 8>>setpagedevice\"\n"); - gzputs(fp, "*StpColorPrecision Best/Best:\t\"<<" - "/cupsBitsPerColor 8" - "/cupsPreferredBitsPerColor 16>>setpagedevice\"\n"); - gzputs(fp, "*CloseUI: *StpColorPrecision\n\n"); + if (!simplified) + { + /* + * 8 or 16 bit color (16 bit is slower) + */ + gzputs(fp, "*OpenUI *StpColorPrecision/Color Precision: PickOne\n"); + gzputs(fp, "*OrderDependency: 10 AnySetup *StpColorPrecision\n"); + gzputs(fp, "*DefaultStpColorPrecision: Normal\n"); + gzputs(fp, "*StpColorPrecision Normal/Normal:\t\"<<" + "/cupsBitsPerColor 8>>setpagedevice\"\n"); + gzputs(fp, "*StpColorPrecision Best/Best:\t\"<<" + "/cupsBitsPerColor 8" + "/cupsPreferredBitsPerColor 16>>setpagedevice\"\n"); + gzputs(fp, "*CloseUI: *StpColorPrecision\n\n"); + } /* * Media types... @@ -1251,27 +1312,6 @@ write_ppd(const stp_printer_t *p, /* I - Printer driver */ stp_parameter_description_destroy(&desc); stp_clear_string_parameter(v, "Quality"); - /* - * Image type - */ - - stp_describe_parameter(v, "ImageType", &desc); - if (desc.p_type == STP_PARAMETER_TYPE_STRING_LIST && desc.is_active) - { - has_image_type_parameter = 1; - gzprintf(fp, "*OpenUI *StpImageType/%s: PickOne\n", _(desc.text)); - gzputs(fp, "*OrderDependency: 5 AnySetup *StpImageType\n"); - gzprintf(fp, "*DefaultStpImageType: %s\n", desc.deflt.str); - num_opts = stp_string_list_count(desc.bounds.str); - for (i = 0; i < num_opts; i++) - { - opt = stp_string_list_param(desc.bounds.str, i); - gzprintf(fp, "*StpImageType %s/%s: \"\"\n", opt->name, opt->text); - } - gzputs(fp, "*CloseUI: *StpImageType\n\n"); - } - stp_parameter_description_destroy(&desc); - /* * Resolutions... */ @@ -1279,40 +1319,43 @@ write_ppd(const stp_printer_t *p, /* I - Printer driver */ stp_describe_parameter(v, "Resolution", &desc); num_opts = stp_string_list_count(desc.bounds.str); - gzprintf(fp, "*OpenUI *Resolution/%s: PickOne\n", _("Resolution")); - gzputs(fp, "*OrderDependency: 20 AnySetup *Resolution\n"); - if (has_quality_parameter) - gzprintf(fp, "*DefaultResolution: None\n"); - else - gzprintf(fp, "*DefaultResolution: %s\n", desc.deflt.str); + if (!simplified || desc.p_level == STP_PARAMETER_LEVEL_BASIC) + { + gzprintf(fp, "*OpenUI *Resolution/%s: PickOne\n", _("Resolution")); + gzputs(fp, "*OrderDependency: 20 AnySetup *Resolution\n"); + if (has_quality_parameter) + gzprintf(fp, "*DefaultResolution: None\n"); + else + gzprintf(fp, "*DefaultResolution: %s\n", desc.deflt.str); - stp_clear_string_parameter(v, "Quality"); - if (has_quality_parameter) - gzprintf(fp, "*Resolution None/%s: \"\"\n", _("Automatic")); - for (i = 0; i < num_opts; i ++) - { - /* - * Strip resolution name to its essentials... - */ - opt = stp_string_list_param(desc.bounds.str, i); - stp_set_string_parameter(v, "Resolution", opt->name); - stp_describe_resolution(v, &xdpi, &ydpi); + stp_clear_string_parameter(v, "Quality"); + if (has_quality_parameter) + gzprintf(fp, "*Resolution None/%s: \"\"\n", _("Automatic")); + for (i = 0; i < num_opts; i ++) + { + /* + * Strip resolution name to its essentials... + */ + opt = stp_string_list_param(desc.bounds.str, i); + stp_set_string_parameter(v, "Resolution", opt->name); + stp_describe_resolution(v, &xdpi, &ydpi); - /* This should not happen! */ - if (xdpi == -1 || ydpi == -1) - continue; + /* This should not happen! */ + if (xdpi == -1 || ydpi == -1) + continue; - /* - * Write the resolution option... - */ + /* + * Write the resolution option... + */ - gzprintf(fp, "*Resolution %s/%s:\t\"<>setpagedevice\"\n", - opt->name, opt->text, xdpi, ydpi, i + 1); - } + gzprintf(fp, "*Resolution %s/%s:\t\"<>setpagedevice\"\n", + opt->name, opt->text, xdpi, ydpi, i + 1); + } - stp_parameter_description_destroy(&desc); + gzputs(fp, "*CloseUI: *Resolution\n\n"); + } - gzputs(fp, "*CloseUI: *Resolution\n\n"); + stp_parameter_description_destroy(&desc); stp_describe_parameter(v, "OutputOrder", &desc); if (desc.p_type == STP_PARAMETER_TYPE_STRING_LIST) @@ -1361,7 +1404,7 @@ write_ppd(const stp_printer_t *p, /* I - Printer driver */ for (j = 0; j <= STP_PARAMETER_CLASS_OUTPUT; j++) { - for (k = 0; k <= STP_PARAMETER_LEVEL_ADVANCED4; k++) + for (k = 0; k <= maximum_level; k++) { int printed_open_group = 0; size_t param_count = stp_parameter_list_count(param_list); @@ -1450,14 +1493,17 @@ write_ppd(const stp_printer_t *p, /* I - Printer driver */ gzprintf(fp, "*Stp%s None/%.3f: \"\"\n", desc.name, desc.deflt.dbl); gzprintf(fp, "*CloseUI: *Stp%s\n\n", desc.name); - gzprintf(fp, "*OpenUI *StpFine%s/%s %s: PickOne\n", - desc.name, _(desc.text), _("Fine Adjustment")); - gzprintf(fp, "*DefaultStpFine%s:None\n", desc.name); - gzprintf(fp, "*StpFine%s None/0.000: \"\"\n", desc.name); - for (i = 0; i < 100; i += 5) - gzprintf(fp, "*StpFine%s %d/%.3f: \"\"\n", - desc.name, i, ((double) i) * .001); - gzprintf(fp, "*CloseUI: *StpFine%s\n\n", desc.name); + if (!simplified) + { + gzprintf(fp, "*OpenUI *StpFine%s/%s %s: PickOne\n", + desc.name, _(desc.text), _("Fine Adjustment")); + gzprintf(fp, "*DefaultStpFine%s:None\n", desc.name); + gzprintf(fp, "*StpFine%s None/0.000: \"\"\n", desc.name); + for (i = 0; i < 100; i += 5) + gzprintf(fp, "*StpFine%s %d/%.3f: \"\"\n", + desc.name, i, ((double) i) * .001); + gzprintf(fp, "*CloseUI: *StpFine%s\n\n", desc.name); + } print_close_ui = 0; break; @@ -1479,9 +1525,6 @@ write_ppd(const stp_printer_t *p, /* I - Printer driver */ gzprintf(fp, "*Stp%s %d/%.1f mm: \"\"\n", desc.name, i, ((double) i) * 25.4 / 72); } - gzprintf(fp, "*CloseUI: *Stp%s\n\n", desc.name); - print_close_ui = 0; - break; default: break; @@ -1551,5 +1594,5 @@ write_ppd(const stp_printer_t *p, /* I - Printer driver */ /* - * End of "$Id: genppd.c,v 1.113 2005/12/31 21:27:29 rlk Exp $". + * End of "$Id: genppd.c,v 1.117 2006/04/22 00:41:04 rlk Exp $". */ diff --git a/src/cups/rastertoprinter.c b/src/cups/rastertoprinter.c index 64b0d0d..b3f74e8 100644 --- a/src/cups/rastertoprinter.c +++ b/src/cups/rastertoprinter.c @@ -1,5 +1,5 @@ /* - * "$Id: rastertoprinter.c,v 1.97 2005/12/24 23:15:23 rlk Exp $" + * "$Id: rastertoprinter.c,v 1.99 2006/04/17 02:06:18 rlk Exp $" * * Gutenprint based raster filter for the Common UNIX Printing System. * @@ -82,6 +82,10 @@ typedef struct int top; int width; int height; + int left_trim; + int right_trim; + int top_trim; + int bottom_trim; int adjusted_width; int adjusted_height; int last_percent; @@ -325,6 +329,7 @@ static stp_vars_t * initialize_page(cups_image_t *cups, const stp_vars_t *default_settings) { const stp_papersize_t *size; /* Paper size */ + int tmp_left, tmp_right, tmp_top, tmp_bottom, tmp_width, tmp_height; stp_vars_t *v = stp_vars_create_copy(default_settings); stp_set_page_width(v, cups->header.PageSize[0]); @@ -414,15 +419,78 @@ initialize_page(cups_image_t *cups, const stp_vars_t *default_settings) &(cups->bottom), &(cups->top)); fprintf(stderr, "DEBUG: Gutenprint limits w %d l %d r %d h %d t %d b %d\n", cups->width, cups->left, cups->right, cups->height, cups->top, cups->bottom); + + tmp_left = cups->header.ImagingBoundingBox[0]; + tmp_top = cups->header.ImagingBoundingBox[1]; + tmp_right = cups->header.ImagingBoundingBox[2]; + tmp_bottom = cups->header.ImagingBoundingBox[3]; + tmp_width = cups->right - cups->left; + tmp_height = cups->bottom - cups->top; + if (tmp_left < cups->left) + { + cups->left_trim = cups->left - tmp_left; + fprintf(stderr, "DEBUG: Gutenprint left margin %d\n", cups->left_trim); + tmp_left = cups->left; + } + else + { + cups->left_trim = 0; + fprintf(stderr, "DEBUG: Gutenprint adjusting left margin from %d to %d\n", + cups->left, tmp_left); + cups->left = tmp_left; + } + if (tmp_right > cups->right) + { + cups->right_trim = tmp_right - cups->right; + fprintf(stderr, "DEBUG: Gutenprint right margin %d\n", cups->right_trim); + tmp_right = cups->right; + } + else + { + cups->right_trim = 0; + fprintf(stderr, "DEBUG: Gutenprint adjusting right margin from %d to %d\n", + cups->right, tmp_right); + cups->right = tmp_right; + } + if (tmp_top < cups->top) + { + cups->top_trim = cups->top - tmp_top; + fprintf(stderr, "DEBUG: Gutenprint top margin %d\n", cups->top_trim); + tmp_top = cups->top; + } + else + { + cups->top_trim = 0; + fprintf(stderr, "DEBUG: Gutenprint adjusting top margin from %d to %d\n", + cups->top, tmp_top); + cups->top = tmp_top; + } + if (tmp_bottom > cups->bottom) + { + cups->bottom_trim = tmp_bottom - cups->bottom; + fprintf(stderr, "DEBUG: Gutenprint bottom margin %d\n", cups->bottom_trim); + tmp_bottom = cups->bottom; + } + else + { + cups->bottom_trim = 0; + fprintf(stderr, "DEBUG: Gutenprint adjusting bottom margin from %d to %d\n", + cups->bottom, tmp_bottom); + cups->bottom = tmp_bottom; + } + stp_set_width(v, cups->right - cups->left); stp_set_height(v, cups->bottom - cups->top); stp_set_left(v, cups->left); stp_set_top(v, cups->top); + cups->right = cups->width - cups->right; cups->width = cups->width - cups->left - cups->right; cups->width = cups->header.HWResolution[0] * cups->width / 72; cups->left = cups->header.HWResolution[0] * cups->left / 72; cups->right = cups->header.HWResolution[0] * cups->right / 72; + cups->left_trim = cups->header.HWResolution[0] * cups->left_trim / 72; + cups->right_trim = cups->header.HWResolution[0] * cups->right_trim / 72; cups->adjusted_width = cups->width; if (cups->adjusted_width > cups->header.cupsWidth) cups->adjusted_width = cups->header.cupsWidth; @@ -432,6 +500,8 @@ initialize_page(cups_image_t *cups, const stp_vars_t *default_settings) cups->height = cups->header.HWResolution[1] * cups->height / 72; cups->top = cups->header.HWResolution[1] * cups->top / 72; cups->bottom = cups->header.HWResolution[1] * cups->bottom / 72; + cups->top_trim = cups->header.HWResolution[1] * cups->top_trim / 72; + cups->bottom_trim = cups->header.HWResolution[1] * cups->bottom_trim / 72; cups->adjusted_height = cups->height; if (cups->adjusted_height > cups->header.cupsHeight) cups->adjusted_height = cups->header.cupsHeight; @@ -659,7 +729,14 @@ main(int argc, /* I - Number of command-line arguments */ return (1); } else if (strcmp(ppd->nickname + strlen(ppd->modelname) + - strlen(CUPS_PPD_NICKNAME_STRING), version_id) != 0) + strlen(CUPS_PPD_NICKNAME_STRING), version_id) != 0 && + (strlen(ppd->nickname + strlen(ppd->modelname) + + strlen(CUPS_PPD_NICKNAME_STRING)) < strlen(version_id) || + !((strncmp(ppd->nickname + strlen(ppd->modelname) + + strlen(CUPS_PPD_NICKNAME_STRING), version_id, + strlen(version_id)) == 0) && + *(ppd->nickname + strlen(ppd->modelname) + + strlen(CUPS_PPD_NICKNAME_STRING)) != ' '))) { fprintf(stderr, "ERROR: Gutenprint: The version of Gutenprint software installed (%s) does not match the PPD file (%s).\n", version_id, @@ -943,6 +1020,7 @@ Image_get_row(stp_image_t *image, /* I - Image */ unsigned char *orig = data; /* Temporary pointer */ static int warned = 0; /* Error warning printed? */ int new_percent; + int left_margin, right_margin; if ((cups = (cups_image_t *)(image->rep)) == NULL) { @@ -952,7 +1030,13 @@ Image_get_row(stp_image_t *image, /* I - Image */ bytes_per_line = ((cups->adjusted_width * cups->header.cupsBitsPerPixel) + CHAR_BIT - 1) / CHAR_BIT; - margin = cups->header.cupsBytesPerLine - bytes_per_line; + + left_margin = ((cups->left_trim * cups->header.cupsBitsPerPixel) + CHAR_BIT - 1) / + CHAR_BIT; + right_margin = ((cups->right_trim * cups->header.cupsBitsPerPixel) + CHAR_BIT - 1) / + CHAR_BIT; + margin = cups->header.cupsBytesPerLine - left_margin - bytes_per_line - + right_margin; if (cups->row < cups->header.cupsHeight) { @@ -960,12 +1044,19 @@ Image_get_row(stp_image_t *image, /* I - Image */ bytes_per_line, cups->row); while (cups->row <= row && cups->row < cups->header.cupsHeight) { + if (left_margin > 0) + { + fprintf(stderr, "DEBUG2: Gutenprint tossing left %d (%d)\n", + left_margin, cups->left_trim); + throwaway_data(left_margin, cups); + } cupsRasterReadPixels(cups->ras, data, bytes_per_line); cups->row ++; - if (margin > 0) + if (margin + right_margin > 0) { - fprintf(stderr, "DEBUG2: Gutenprint tossing right %d\n", margin); - throwaway_data(margin, cups); + fprintf(stderr, "DEBUG2: Gutenprint tossing right %d (%d) + %d\n", + right_margin, cups->right_trim, margin); + throwaway_data(margin + right_margin, cups); } } } @@ -1001,7 +1092,7 @@ Image_get_row(stp_image_t *image, /* I - Image */ if (warned == 0) { fprintf(stderr, - "WARNING: Gutenprint detected broken job options. " + "WARNING: Gutenprint detected bad CUPS bit depth (1). " "Output quality is degraded. Are you using psnup or non-ADSC PostScript?\n"); warned = 1; } @@ -1098,5 +1189,5 @@ Image_width(stp_image_t *image) /* I - Image */ /* - * End of "$Id: rastertoprinter.c,v 1.97 2005/12/24 23:15:23 rlk Exp $". + * End of "$Id: rastertoprinter.c,v 1.99 2006/04/17 02:06:18 rlk Exp $". */ diff --git a/src/cups/test-ppds b/src/cups/test-ppds new file mode 100755 index 0000000..050906a --- /dev/null +++ b/src/cups/test-ppds @@ -0,0 +1,56 @@ +#!/bin/sh + +status=0 +verbose=0 +strict=0 + +usage() { + echo "Usage: run-testpattern [-v] [-s]" + exit +} + +set_args() { + while true ; do + case "$1" in + -h*|--h*) usage ;; + -v) verbose=1 ;; + -s) strict=1 ;; + --) shift; args="$@"; return ;; + *) return ;; + esac + shift + done +} + +set_args `getopt vhs "$@"` + + +if [ -d ppd ] ; then + for f in ppd/* ; do + echo -n "$f..." + cupstestppd -r -q $f/* + if [ $? -ne 0 ] ; then + echo -n "FAILED" + if [ $verbose -ne 0 ] ; then + cupstestppd $f/* 2>&1 | grep FAIL + fi + status=1 + else + cupstestppd -q $f/* + if [ $? -ne 0 ] ; then + # Don't actually error if strict checks fail. + # These errors are less important, and we'll accept them. + echo -n "WARNING: strict checks failed" + if [ $verbose -ne 0 ] ; then + cupstestppd $f/* 2>&1 | grep FAIL + fi + if [ $strict -ne 0 ] ; then + status=1 + fi + fi + fi + echo + done +fi + +exit $status -- cgit v1.2.3