From 70c7b2d8f385b529c990a723ca81cffe260a5d62 Mon Sep 17 00:00:00 2001
From: Martin Mares <mj@ucw.cz>
Date: Thu, 14 Jun 2012 18:04:02 +0200
Subject: [PATCH] PPD: More bits...

---
 ppd/PPD.pm     | 42 +++++++++++++++++++++++++--------------
 ppd/PPD/PJL.pm | 11 +++++++++++
 ppd/gen-hp     | 53 +++++++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 90 insertions(+), 16 deletions(-)
 create mode 100644 ppd/PPD/PJL.pm

diff --git a/ppd/PPD.pm b/ppd/PPD.pm
index a8d701a..ed74bb5 100644
--- a/ppd/PPD.pm
+++ b/ppd/PPD.pm
@@ -82,6 +82,12 @@ set('d/ColorDevice:b', 0);
 set('d/DefaultColorSpace:q', 'Gray');
 set('d/FileSystem:b', 0);
 
+# Section "c": CUPS options
+# (none by default)
+
+# Section "j": JCL options
+# (none by default)
+
 my @ui_groups = ();
 
 sub ui_group($) {
@@ -102,7 +108,7 @@ $options{'n'} = { Key => '', Options => [] };
 # option({
 #	Key => key,		# (mandatory)
 #	Name => name,		# descriptive name (default: same as Key)
-#	Type => type,		# PickOne / PickMany / Boolean
+#	Type => type,		# PickOne (default) / PickMany / Boolean
 #	UI => group,		# UI group ('' if outside groups, default: non-UI option)
 #	JCL => 1,		# if this is a JCL option
 #	Section => sec,		# OrderDependency section: ExitServer / Prolog / DocumentSetup /
@@ -137,9 +143,11 @@ sub heading($) {
 	print "\n";
 }
 
-sub emit($) {
-	my ($section) = @_;
+sub emit($;$) {
+	my ($section, $heading) = @_;
 	my $opts = $options{$section};
+	$opts or return;
+	heading($heading) if defined $heading;
 	for my $k (sort keys %$opts) {
 		my $v = $opts->{$k};
 		if (!$v) {
@@ -161,14 +169,19 @@ sub get_default($) {
 sub emit_option($) {
 	my ($o) = @_;
 	my $key = $o->{Key};
+	my $type = $o->{Type} // 'PickOne';
+	print "%* === $key ===\n";
 	my $jcl = ($o->{JCL} // ($key =~ /^JCL/)) ? "JCL" : "";
-	if (defined $o->{UI}) { print "*${jcl}OpenUI *$key/", ($o->{Name} // $o->{Key}), ': ', $o->{Type}, "\n"; }
+	if (defined $o->{UI}) { print "*${jcl}OpenUI *$key/", ($o->{Name} // $o->{Key}), ": $type\n"; }
 	my $pri = $o->{Priority} // 100;
 	my $sec = $o->{Section} // ($jcl ? "JCLSetup" : "AnySetup");
 	print '*', ((defined $o->{UI}) ? "" : 'NonUI'), "OrderDependency $pri $sec *$key\n";
 	print "*Default$key: ", get_default($o), "\n";
 	for my $v (@{$o->{Values}}) {
-		print "*$key ", $v->{Key}, '/', ($v->{Name} // $v->{Key}), ': ', format_value('i', $v->{PS}), "\n";
+		my $ps = $v->{PS};
+		# $ps = "\n$ps" unless $ps =~ /^\n/s;
+		# $ps = "$ps\n" unless $ps =~ /\n$/s;
+		print "*$key ", $v->{Key}, '/', ($v->{Name} // $v->{Key}), ': ', format_value('i', $ps), "\n";
 	}
 	if (defined $o->{UI}) { print "*${jcl}CloseUI *$key\n"; }
 	print "\n";
@@ -202,14 +215,11 @@ sub generate() {
 	print "*% PPD file generated by UCW PPD generator\n";
 	fill_missing();
 
-	heading("File version");
-	emit('f');
-
-	heading("Product information");
-	emit('p');
-
-	heading("Device capabilities");
-	emit('d');
+	emit('f', 'File version');
+	emit('p', 'Product information');
+	emit('d', 'Device capabilities');
+	emit('c', 'CUPS options');
+	emit('j', 'JCL setup');
 
 	for my $g (@ui_groups) {
 		next if $g->{Key} eq '';
@@ -220,8 +230,10 @@ sub generate() {
 	heading("General UI options");
 	emit_group($ui_groups[0]);
 
-	heading("Non-UI options");
-	emit_group($options{'n'});
+	if (@{$options{'n'}->{Options}}) {
+		heading("Non-UI options");
+		emit_group($options{'n'});
+	}
 }
 
 42;
diff --git a/ppd/PPD/PJL.pm b/ppd/PPD/PJL.pm
new file mode 100644
index 0000000..9392cd0
--- /dev/null
+++ b/ppd/PPD/PJL.pm
@@ -0,0 +1,11 @@
+package PPD::PJL;
+
+use PPD;
+
+sub add_jcl() {
+	set('j/JCLBegin', '<1B>%-12345X@PJL<0A>');
+	set('j/JCLToPSInterpreter', '@PJL ENTER LANGUAGE = POSTSCRIPT<0A>');
+	set('j/JCLEnd', '<1B>%-12345X@PJL EOJ<0A><1B>%-12345X<0A>');
+}
+
+42;
diff --git a/ppd/gen-hp b/ppd/gen-hp
index 7f35334..008ada7 100755
--- a/ppd/gen-hp
+++ b/ppd/gen-hp
@@ -5,6 +5,7 @@ use warnings;
 
 use lib ".";
 use PPD;
+use PPD::PJL;
 
 set('f/FileVersion', '1.0');
 set('f/PCFileName', 'HP4350.PPD');
@@ -18,10 +19,11 @@ set('d/TTRasterizer:s', 'Type42');
 set('d/VariablePaperSize:b', 1);
 set('d/Protocols:s', 'PJL TBCP');
 
+set('c/cupsProtocol:s', 'None');
+
 option({
 	Key => 'Duplex',
 	Name => '2-Sided Printing',
-	Type => 'PickOne',
 	UI => '',
 	Values => [
 		{ Key => 'None', Name => 'Off (1-Sided)', PS => "<< /Duplex false >> setpagedevice" },
@@ -30,4 +32,53 @@ option({
 	]
 });
 
+option({
+	Key => 'Resolution',
+	Name => 'Printer Resolution',
+	UI => '',
+	Priority => 5,
+	Section  => 'DocumentSetup',
+	Values => [
+		{ Key => '1200x1200dpi', Name => 'ProRes 1200', PS => '<< /HWResolution [1200 1200] /PreRenderingEnhance false >> setpagedevice' },
+		{ Key => '600x600x2dpi', Name => 'FastRes 1200', PS => '<< /HWResolution [1200 1200] /PreRenderingEnhance true >> setpagedevice', Default => 1 },
+		{ Key => '600x600dpi', Name => '600 DPI', PS => '<< /HWResolution [600 600] /PreRenderingEnhance false >> setpagedevice' },
+	]
+});
+
+option({
+	Key => 'HPEconoMode',
+	Name => 'EconoMode',
+	Type => 'Boolean',
+	UI => '',
+	Values => [
+		{ Key => 'False', Name => 'Highest Quality', PS => '<< /EconoMode false >> setpagedevice', Default => 1 },
+		{ Key => 'True', Name => 'Save Toner', PS => '<< /EconoMode true >> setpagedevice' },
+	]
+});
+
+option({
+	Key => 'Smoothing',
+	Name => 'Resolution Enhancement',
+	Type => 'Boolean',
+	UI => '',
+	Priority => 20,
+	Section  => 'DocumentSetup',
+	Values => [
+		{ Key => 'False', Name => 'Off', PS => '<< /PostRenderingEnhance true /PostRenderingEnhanceDetails << /REValue 0 /Type 8 >> >> setpagedevice' },
+		{ Key => 'True', Name => 'On', PS => '<< /PostRenderingEnhance true /PostRenderingEnhanceDetails << /REValue 2 /Type 8 >> >> setpagedevice', Default => 1 },
+	]
+});
+
+option({
+	Key => 'Collate',
+	Type => 'Boolean',
+	UI => '',
+	Values => [
+		{ Key => 'False', Name => 'Off', PS => '<< /Collate false >> setpagedevice' },
+		{ Key => 'True', Name => 'On', PS => '<< /Collate true >> setpagedevice', Default => 1 },
+	]
+});
+
+PPD::PJL::add_jcl();
+
 generate();
-- 
GitLab