[Pkg-gs-devel] r42 - in gs-gpl/trunk/debian: . patches

Masayuki Hatta mhatta at costa.debian.org
Sun Oct 22 23:08:23 UTC 2006


Author: mhatta
Date: Sun Oct 22 23:08:22 2006
New Revision: 42

Added:
   gs-gpl/trunk/debian/gs-gpl.postinst
   gs-gpl/trunk/debian/gs-gpl.preinst
   gs-gpl/trunk/debian/gs-gpl.prerm
   gs-gpl/trunk/debian/patches/05_gxfcopy_qsort_64bit_clean.dpatch
   gs-gpl/trunk/debian/patches/06_libpaper_support.dpatch
   gs-gpl/trunk/debian/patches/08_big_cmap_post_table.dpatch
   gs-gpl/trunk/debian/patches/09_ijs_krgb_support.dpatch
   gs-gpl/trunk/debian/patches/11_brother_7x0_gdi_fix.dpatch
   gs-gpl/trunk/debian/patches/23_hl12x0_support.dpatch
Removed:
   gs-gpl/trunk/debian/patches/05_docdir_fix_for_gs-gpl.dpatch
   gs-gpl/trunk/debian/patches/06_ijs_krgb_support.dpatch
   gs-gpl/trunk/debian/patches/08_epsn_margin_workaround.dpatch
   gs-gpl/trunk/debian/patches/09_brother_7x0_gdi_fix.dpatch
   gs-gpl/trunk/debian/patches/10_powerpc_crash_fix.dpatch
   gs-gpl/trunk/debian/postinst
   gs-gpl/trunk/debian/prerm

Log:
As per 8.54.dfsg.1-5 (really)



Added: gs-gpl/trunk/debian/gs-gpl.postinst
==============================================================================
--- (empty file)
+++ gs-gpl/trunk/debian/gs-gpl.postinst	Sun Oct 22 23:08:22 2006
@@ -0,0 +1,44 @@
+#! /bin/sh
+# postinst script for gs-gpl
+#
+# see: dh_installdeb(1)
+
+set -e
+
+# summary of how this script can be called:
+#        * <postinst> `configure' <most-recently-configured-version>
+#        * <old-postinst> `abort-upgrade' <new version>
+#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
+#          <new-version>
+#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
+#          <failed-install-package> <version> `removing'
+#          <conflicting-package> <version>
+# for details, see http://www.debian.org/doc/debian-policy/ or
+# the debian-policy package
+#
+
+case "$1" in
+    configure)
+	update-alternatives --install /usr/bin/gs gs /usr/bin/gs-gpl 20 \
+	--slave /usr/share/man/man1/gs.1.gz gs.1.gz /usr/share/man/man1/gs-gpl.1.gz
+    ;;
+
+    abort-upgrade|abort-remove|abort-deconfigure)
+	update-alternatives --install /usr/bin/gs gs /usr/bin/gs-gpl 20 \
+	--slave /usr/share/man/man1/gs.1.gz gs.1.gz /usr/share/man/man1/gs-gpl.1.gz
+    ;;
+
+    *)
+        echo "postinst called with unknown argument \`$1'" >&2
+        exit 1
+    ;;
+esac
+
+# dh_installdeb will replace this with shell code automatically
+# generated by other debhelper scripts.
+
+#DEBHELPER#
+
+exit 0
+
+

Added: gs-gpl/trunk/debian/gs-gpl.preinst
==============================================================================
--- (empty file)
+++ gs-gpl/trunk/debian/gs-gpl.preinst	Sun Oct 22 23:08:22 2006
@@ -0,0 +1,41 @@
+#!/bin/sh
+# preinst script for gs-gpl
+#
+# see: dh_installdeb(1)
+
+set -e
+
+# summary of how this script can be called:
+#        * <new-preinst> `install'
+#        * <new-preinst> `install' <old-version>
+#        * <new-preinst> `upgrade' <old-version>
+#        * <old-preinst> `abort-upgrade' <new-version>
+#
+# for details, see http://www.debian.org/doc/debian-policy/ or
+# the debian-policy package
+
+
+case "$1" in
+    install|upgrade)
+
+	rm -rf /etc/gs-gpl
+
+    ;;
+
+    abort-upgrade)
+    ;;
+
+    *)
+        echo "preinst called with unknown argument \`$1'" >&2
+        exit 1
+    ;;
+esac
+
+# dh_installdeb will replace this with shell code automatically
+# generated by other debhelper scripts.
+
+#DEBHELPER#
+
+exit 0
+
+

Added: gs-gpl/trunk/debian/gs-gpl.prerm
==============================================================================
--- (empty file)
+++ gs-gpl/trunk/debian/gs-gpl.prerm	Sun Oct 22 23:08:22 2006
@@ -0,0 +1,40 @@
+#! /bin/sh
+# prerm script for gs-gpl
+#
+# see: dh_installdeb(1)
+
+set -e
+
+# summary of how this script can be called:
+#        * <prerm> `remove'
+#        * <old-prerm> `upgrade' <new-version>
+#        * <new-prerm> `failed-upgrade' <old-version>
+#        * <conflictor's-prerm> `remove' `in-favour' <package> <new-version>
+#        * <deconfigured's-prerm> `deconfigure' `in-favour'
+#          <package-being-installed> <version> `removing'
+#          <conflicting-package> <version>
+# for details, see http://www.debian.org/doc/debian-policy/ or
+# the debian-policy package
+
+
+case "$1" in
+    remove|deconfigure)
+#       install-info --quiet --remove /usr/info/gs-gpl.info.gz
+	update-alternatives --remove gs /usr/bin/gs-gpl
+        ;;
+    upgrade|failed-upgrade)
+        ;;
+    *)
+        echo "prerm called with unknown argument \`$1'" >&2
+        exit 1
+    ;;
+esac
+
+# dh_installdeb will replace this with shell code automatically
+# generated by other debhelper scripts.
+
+#DEBHELPER#
+
+exit 0
+
+

Added: gs-gpl/trunk/debian/patches/05_gxfcopy_qsort_64bit_clean.dpatch
==============================================================================
--- (empty file)
+++ gs-gpl/trunk/debian/patches/05_gxfcopy_qsort_64bit_clean.dpatch	Sun Oct 22 23:08:22 2006
@@ -0,0 +1,33 @@
+#! /bin/sh -e
+## 04_gxfcopy_qsort_64bit_clean.dpatch by Masayuki Hatta <mhatta at debian.org>
+##
+## All lines beginning with \`## DP:' are a description of the patch.
+## DP: Made qsort funciton call in src/gxfcopy.c 64bit clean
+
+if [ $# -ne 1 ]; then
+    echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
+    exit 1
+fi
+case "$1" in
+        -patch) patch -f --no-backup-if-mismatch --dry-run -p1 < $0 && patch -f --no-backup-if-mismatch -p1 < $0
+;;
+        -unpatch) patch -f --no-backup-if-mismatch -R -p1 < $0;;
+        *)
+                echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
+                exit 1;;
+esac
+
+exit 0
+
+diff -urN gs-gpl-8.54.dfsg.1.orig/src/gxfcopy.c gs-gpl-8.54.dfsg.1/src/gxfcopy.c
+--- gs-gpl-8.54.dfsg.1.orig/src/gxfcopy.c	2006-10-12 09:07:59.000000000 +0900
++++ gs-gpl-8.54.dfsg.1/src/gxfcopy.c	2006-10-12 09:09:09.000000000 +0900
+@@ -2391,7 +2391,7 @@
+ 	    a[j++] = &cfdata->names[i];
+ 	}
+     }
+-    qsort(a, cfdata->num_glyphs, sizeof(int), compare_glyph_names);
++    qsort(a, cfdata->num_glyphs, sizeof(gs_copied_glyph_name_t*), compare_glyph_names);
+     for (; j >= 0; j--)
+ 	cfdata->glyphs[j].order_index = a[j] - cfdata->names;    
+     gs_free_object(memory, a, "order_font_data");

Added: gs-gpl/trunk/debian/patches/06_libpaper_support.dpatch
==============================================================================
--- (empty file)
+++ gs-gpl/trunk/debian/patches/06_libpaper_support.dpatch	Sun Oct 22 23:08:22 2006
@@ -0,0 +1,88 @@
+#! /bin/sh -e
+## 06_libpaper_support.dpatch by Masayuki Hatta <mhatta at debian.org>
+##
+## All lines beginning with \`## DP:' are a description of the patch.
+## DP: Adds libpaper support
+
+if [ $# -ne 1 ]; then
+    echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
+    exit 1
+fi
+case "$1" in
+        -patch) patch -f --no-backup-if-mismatch --dry-run -p1 < $0 && patch -f --no-backup-if-mismatch -p1 < $0
+;;
+        -unpatch) patch -f --no-backup-if-mismatch -R -p1 < $0;;
+        *)
+                echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
+                exit 1;;
+esac
+
+exit 0
+
+diff -urN gs-gpl-8.01.orig/lib/gs_init.ps gs-gpl-8.01/lib/gs_init.ps
+--- gs-gpl-8.01.orig/lib/gs_init.ps	2003-11-21 04:29:12.000000000 +0900
++++ gs-gpl-8.01/lib/gs_init.ps	2004-03-24 14:57:02.000000000 +0900
+@@ -64,7 +64,13 @@
+ systemdict /.languagelevel known not { /.languagelevel 1 def } if
+ 
+ % Optionally choose a default paper size other than U.S. letter.
+-% (a4) /PAPERSIZE where { pop pop } { /PAPERSIZE exch def } ifelse
++% Debian: Libpaper's default is in DEFPAPERSIZE; use that if the
++%         current device is not "cups".
++currentdict /DEFPAPERSIZE known
++currentdict /DEVICE known { DEVICE } { () } ifelse
++(cups) ne and
++  { DEFPAPERSIZE /PAPERSIZE where { pop pop } { /PAPERSIZE exch def } ifelse }
++if
+ 
+ % Turn on array packing for the rest of initialization.
+ true setpacking
+diff -urN gs-gpl-8.01.orig/src/imainarg.c gs-gpl-8.01/src/imainarg.c
+--- gs-gpl-8.01.orig/src/imainarg.c	2002-08-28 09:16:14.000000000 +0900
++++ gs-gpl-8.01/src/imainarg.c	2004-03-24 15:01:08.000000000 +0900
+@@ -51,6 +51,15 @@
+ #include "ivmspace.h"
+ #include "vdtrace.h"
+ 
++/* Change by Torsten Landschoff <torsten at debian.org>:
++ * Include the paper.h header for the handling of the system paper size
++ * below.
++ *  -- Thu, 30 Mar 2000 21:28:25 +0200
++ *
++ * Applied to GPL/AFPL GhostScript by Masayuki Hatta
++ *  -- Wed Mar 24 14:58:20 JST 2004 */
++#include <paper.h>
++
+ /* Import operator procedures */
+ extern int zflush(i_ctx_t *);
+ extern int zflushpage(i_ctx_t *);
+@@ -203,6 +212,29 @@
+ 		return e_Fatal;
+ 	}
+     }
++
++    /* Change by Torsten Landschoff <torsten at debian.org>:
++     * If no papersize is given on the commandline we want gs to use the
++     * default papersize of the system. This change differs from the old
++     * Debian change in that it does not use arg_push_string and therefore
++     * is not using up the nesting depth.
++     *  -- Thu, 30 Mar 2000 21:28:25 +0200
++     *
++     * Applied to GPL/AFPL GhostScript by Masayuki Hatta
++     *  -- Wed Mar 24 15:00:00 JST 2004 */
++
++    {
++      const char *paper = systempapername();
++      static char paperswitch[15+40+1] = "-sDEFPAPERSIZE=";
++      /* strlen("-sDEFPAPERSIZE") + 40 + space for '\0' */
++      
++      if (paper != NULL) {
++	strncat(paperswitch, paper, 40);
++	swproc(minst, paperswitch, &args);
++	/* args is not modified since a "-s" argument does not need
++	 * such special handling */
++      }
++    }
+     while ((arg = arg_next(&args, &code)) != 0) {
+ 	switch (*arg) {
+ 	    case '-':

Added: gs-gpl/trunk/debian/patches/08_big_cmap_post_table.dpatch
==============================================================================
--- (empty file)
+++ gs-gpl/trunk/debian/patches/08_big_cmap_post_table.dpatch	Sun Oct 22 23:08:22 2006
@@ -0,0 +1,223 @@
+#! /bin/sh -e
+## 08_big_cmap_post_table.dpatch by Masayuki Hatta <mhatta at debian.org>
+##
+## All lines beginning with \`## DP:' are a description of the patch.
+## DP: Support big post table for cmap
+
+if [ $# -ne 1 ]; then
+    echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
+    exit 1
+fi
+case "$1" in
+        -patch) patch -f --no-backup-if-mismatch --dry-run -p1 < $0 && patch -f --no-backup-if-mismatch -p1 < $0
+;;
+        -unpatch) patch -f --no-backup-if-mismatch -R -p1 < $0;;
+        *)
+                echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
+                exit 1;;
+esac
+
+exit 0
+
+diff -urN gs-gpl-8.54.dfsg.1.orig/lib/gs_ttf.ps gs-gpl-8.54.dfsg.1/lib/gs_ttf.ps
+--- gs-gpl-8.54.dfsg.1.orig/lib/gs_ttf.ps	2006-10-15 17:58:21.000000000 +0900
++++ gs-gpl-8.54.dfsg.1/lib/gs_ttf.ps	2006-10-15 18:20:47.000000000 +0900
+@@ -273,6 +273,54 @@
+   } for pop exch pop
+ } bind def
+ 
++/.biglength { % <str>|<array of str> .biglength <integer>
++  dup type /arraytype eq { 0 exch { length add } forall } { length } ifelse
++} bind def
++
++/concats { % [str ...] concats str
++  () exch dup length 1 sub -1 0 {
++    1 index exch get dup type /stringtype ne { dup length string cvs } if
++    3 -1 roll exch dup length 2 index length add string
++    dup dup 4 2 roll copy length 4 -1 roll putinterval exch
++  } for pop
++} bind def
++
++% <str>|<array of str> <index> <count> .biggetinterval <str>|<array of str>
++/.biggetinterval {
++  3 dict begin
++  2 index type /arraytype eq {
++    /c exch def
++    /i exch def
++    [ exch {
++      dup length /l exch def
++      i c add l gt {
++        i l lt {
++          i l i sub getinterval
++          /c i c add l sub def
++          /i 0 def
++        } {
++          pop
++          /i i l sub def
++        } ifelse
++      } {
++        i c getinterval exit
++      } ifelse
++    } forall
++    ] dup .biglength 65535 le { concats } if
++  } { getinterval } ifelse
++  end
++} bind def
++
++% <str>|<array of str> <index> getu16 <integer>
++/.biggetu16 {
++  2 .biggetinterval 0 getu16
++} bind def
++
++% <str>|<array of str> <index> getu32 <integer>
++/.biggetu32 {
++  4 .biggetinterval 0 getu32
++} bind def
++
+ % Each procedure in this dictionary is called as follows:
+ %       <encodingtable> proc <glypharray>
+ /cmapformats mark
+@@ -363,14 +411,14 @@
+   } bind
+   4 {		% Microsoft/Adobe segmented mapping.
+     /etab exch def
+-    /nseg2 etab 6 getu16 def
+-    14 /endc etab 2 index nseg2 getinterval def
++    /nseg2 etab 6 .biggetu16 def
++    14 /endc etab 2 index nseg2 .biggetinterval def
+ 		% The Apple TrueType documentation omits the 2-byte
+ 		% 'reserved pad' that follows the endCount vector!
+     2 add
+-    nseg2 add /startc etab 2 index nseg2 getinterval def
+-    nseg2 add /iddelta etab 2 index nseg2 getinterval def
+-    nseg2 add /idroff etab 2 index nseg2 getinterval def
++    nseg2 add /startc etab 2 index nseg2 .biggetinterval def
++    nseg2 add /iddelta etab 2 index nseg2 .biggetinterval def
++    nseg2 add /idroff etab 2 index nseg2 .biggetinterval def
+ 		% The following hack allows us to properly handle
+ 		% idiosyncratic fonts that start at 0xf000:
+     pop
+@@ -382,8 +430,8 @@
+     /numcodes 0 def /glyphs 0 0 2 nseg2 3 sub {
+ 		% Stack: /glyphs numglyphs i2
+       /i2 exch def
+-      /scode startc i2 getu16 def
+-      /ecode endc i2 getu16 def
++      /scode startc i2 .biggetu16 def
++      /ecode endc i2 .biggetu16 def
+       numcodes scode firstcode sub
+ 		% Hack for fonts that have only 0x0000 and 0xf000 ranges
+       %dup 16#e000 ge { 255 and } if
+@@ -404,8 +452,8 @@
+     /numcodes 0 def /code 0 def
+     0 2 nseg2 3 sub {
+       /i2 exch def
+-      /scode startc i2 getu16 def
+-      /ecode endc i2 getu16 def
++      /scode startc i2 .biggetu16 def
++      /ecode endc i2 .biggetu16 def
+       numcodes scode firstcode sub
+ 		% Hack for fonts that have only 0x0000 and 0xf000 ranges
+       %dup 16#e000 ge { 255 and } if
+@@ -417,15 +465,15 @@
+ 	(scode=) print scode =only
+ 	( ecode=) print ecode =only
+ 	( delta=) print delta =only
+-	( droff=) print idroff i2 getu16 =
++	( droff=) print idroff i2 .biggetu16 =
+       } if
+-      idroff i2 getu16 dup 0 eq {
++      idroff i2 .biggetu16 dup 0 eq {
+ 	pop scode delta add 65535 and 1 ecode delta add 65535 and
+ 	{ putglyph } for
+       } {	% The +2 is for the 'reserved pad'.
+         /gloff exch 14 nseg2 3 mul add 2 add i2 add add def
+         0 1 ecode scode sub {
+-	  2 mul gloff add etab exch getu16
++	  2 mul gloff add etab exch .biggetu16
+ 	  dup 0 ne { delta add 65535 and } if putglyph
+ 	} for
+       } ifelse
+@@ -448,12 +496,12 @@
+ 
+ % <cmaptab> cmaparray <glypharray>
+ /cmaparray {
+-  dup 0 getu16 cmapformats exch .knownget {
++  dup 0 .biggetu16 cmapformats exch .knownget {
+     TTFDEBUG {
+-      (cmap: format ) print 1 index 0 getu16 = flush
++      (cmap: format ) print 1 index 0 .biggetu16 = flush
+     } if exec
+   } {
+-    (Can't handle format ) print 0 getu16 = flush
++    (Can't handle format ) print 0 .biggetu16 = flush
+     0 1 255 { } for 256 packedarray
+   } ifelse
+   TTFDEBUG {
+@@ -591,7 +639,7 @@
+ % Adobe requirement that each sfnts entry have even length.
+ /readtables mark
+ 	% Ordinary tables
+-  (cmap) //call.readtable
++  (cmap) //call.readbigtable
+   (head) 1 index
+   (hhea) 1 index
+   (maxp) 1 index
+@@ -964,10 +1012,21 @@
+   } ifelse
+ 		% Stack: ... /FontInfo mark key1 value1 ...
+   post null ne {
+-    /ItalicAngle first_post_string 4 gets32 65536.0 div
+-    /isFixedPitch first_post_string 12 getu32 0 ne
+-    /UnderlinePosition first_post_string 8 gets16 upem div
+-    /UnderlineThickness first_post_string 10 gets16 upem div
++     post type /arraytype eq {
++       % this post table is a big table. /post should be [(...) ...]
++       % data we actually need here should be first one in array.
++       /posttable post 1 get def
++     } {
++       /posttable post def
++     } ifelse
++%    /ItalicAngle first_post_string 4 gets32 65536.0 div
++%    /isFixedPitch first_post_string 12 getu32 0 ne
++%    /UnderlinePosition first_post_string 8 gets16 upem div
++%    /UnderlineThickness first_post_string 10 gets16 upem div
++     /ItalicAngle posttable 4 gets32 65536.0 div
++     /isFixedPitch posttable 12 getu32 0 ne
++     /UnderlinePosition posttable 8 gets16 upem div
++     /UnderlineThickness posttable 10 gets16 upem div
+   } if
+   counttomark 0 ne { .dicttomark } { pop pop } ifelse
+   /XUID [orgXUID 42 curxuid]
+@@ -1026,22 +1085,22 @@
+     } if
+     tabdict /cmap get                                   % bool [] i PlatID SpecID (cmap)
+     dup /cmaptab exch def % temporary
+-    0 1 2 index 2 getu16 1 sub {                         % bool [] i PlatID SpecID (cmap) j
+-      8 mul 4 add 1 index exch 8 getinterval             % bool [] i PlatID SpecID (cmap) (cmapsub)
++    0 1 2 index 2 .biggetu16 1 sub {                         % bool [] i PlatID SpecID (cmap) j
++      8 mul 4 add 1 index exch 8 .biggetinterval             % bool [] i PlatID SpecID (cmap) (cmapsub)
+       TTFDEBUG {
+-        (cmap: platform ) print dup 0 getu16 =only
+-        ( encoding ) print dup 2 getu16 = flush
++        (cmap: platform ) print dup 0 .biggetu16 =only
++        ( encoding ) print dup 2 .biggetu16 = flush
+       } if
+-      dup 0 getu16 4 index eq {
+-        dup 2 getu16 3 index eq {                        % bool [] i PlatID SpecID (cmap) (cmapsub)
++      dup 0 .biggetu16 4 index eq {
++        dup 2 .biggetu16 3 index eq {                        % bool [] i PlatID SpecID (cmap) (cmapsub)
+           TTFDEBUG {
+             (Choosen a cmap for platform=) print 3 index =only
+             ( encoding=) print 2 index =
+           } if
+           /cmapsub 1 index def
+-          dup 4 getu32                                   % bool [] i PlatID SpecID (cmap) (cmapsub) p
+-          cmaptab length 1 index sub                     % bool [] i PlatID SpecID (cmap) (cmapsub) p l
+-          cmaptab 3 1 roll getinterval
++          dup 4 .biggetu32                                   % bool [] i PlatID SpecID (cmap) (cmapsub) p
++          cmaptab .biglength 1 index sub                     % bool [] i PlatID SpecID (cmap) (cmapsub) p l
++          cmaptab 3 1 roll .biggetinterval
+           /cmaptab exch def                              % bool [] i PlatID SpecID (cmap) (cmapsub)
+           5 index 5 index 1 add get                      % bool [] i PlatID SpecID (cmap) (cmapsub) /Decoding
+           /Decoding exch def                             % bool [] i PlatID SpecID (cmap) (cmapsub)

Added: gs-gpl/trunk/debian/patches/09_ijs_krgb_support.dpatch
==============================================================================
--- (empty file)
+++ gs-gpl/trunk/debian/patches/09_ijs_krgb_support.dpatch	Sun Oct 22 23:08:22 2006
@@ -0,0 +1,797 @@
+#! /bin/sh -e
+## 09_ijs_krgb_support.dpatch by David Suffield <linux.deskjet at hp.com>
+##
+## All lines beginning with \`## DP:' are a description of the patch.
+## DP: Added KRGB colorspace support to gs IJS driver.
+## DP: Patch from HPLIP upstream, distributed in the hpijs package
+
+if [ $# -ne 1 ]; then
+    echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
+    exit 1
+fi
+case "$1" in
+        -patch) patch -f --no-backup-if-mismatch --dry-run -p1 < $0 && patch -f --no-backup-if-mismatch -p1 < $0 || exit 1
+;;
+        -unpatch) patch -R -f --no-backup-if-mismatch --dry-run -p1 < $0 && patch -f --no-backup-if-mismatch -R -p1 < $0 || exit 1
+;;
+        *)
+                echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
+                exit 1;;
+esac
+
+exit 0
+
+ at DPATCH@
+diff -urN gs-gpl-8.54.dfsg.1.orig/src/gdevijs.c gs-gpl-8.54.dfsg.1/src/gdevijs.c
+--- gs-gpl-8.54.dfsg.1.orig/src/gdevijs.c	2006-10-18 22:15:46.000000000 +0900
++++ gs-gpl-8.54.dfsg.1/src/gdevijs.c	2006-10-18 22:18:21.000000000 +0900
+@@ -23,6 +23,21 @@
+  * which is a security risk, since any program can be run.
+  * You should use -dSAFER which sets .LockSafetyParams to true 
+  * before opening this device.
++ *
++ * 11/26/03 David Suffield (gdevijs-krgb-1.0.patch)
++ * (c) 2003-2004 Copyright Hewlett-Packard Development Company, LP
++ *
++ * 1. Removed hpijs 1.0-1.0.2 workarounds, use hpijs 1.0.3 or higher.
++ * 2. Added krgb support.
++ *
++ * 02/21/05 David Suffield (gdevijs-krgb-1.1.patch)
++ * 1. Fixed segfault issue with 1-bit color space.
++ * 2. Fixed z-order issue with colored text on black rectangle.
++ *
++ * 02/22/06 David Suffield (gdevijs-krgb-1.2.patch)
++ * 1. Fixed krgb buffer overflow issue with out-of-band data in
++ *    fill_rectangle and copy_mono.  This buffer overflow condition 
++ *    occurred with fullbleed print jobs that had k-band images.
+  */
+ 
+ #include "unistd_.h"	/* for dup() */
+@@ -32,6 +47,11 @@
+ #include "ijs.h"
+ #include "ijs_client.h"
+ 
++//#define KRGB_DEBUG
++#ifdef KRGB_DEBUG
++#include <fcntl.h>
++#endif
++
+ /* This should go into gdevprn.h, or, better yet, gdevprn should
+    acquire an API for changing resolution. */
+ int gdev_prn_maybe_realloc_memory(gx_device_printer *pdev,
+@@ -49,6 +69,14 @@
+ private dev_proc_put_params(gsijs_put_params);
+ private dev_proc_finish_copydevice(gsijs_finish_copydevice);
+ 
++/* Following definitions are for krgb support. */
++private dev_proc_create_buf_device(gsijs_create_buf_device);
++private dev_proc_fill_rectangle(gsijs_fill_rectangle);
++private dev_proc_copy_mono(gsijs_copy_mono);
++private dev_proc_fill_mask(gsijs_fill_mask);
++private dev_proc_fill_path(gsijs_fill_path);
++private dev_proc_stroke_path(gsijs_stroke_path);
++
+ private const gx_device_procs gsijs_procs = {
+ 	gsijs_open,
+ 	NULL,	/* get_initial_matrix */
+@@ -123,6 +151,14 @@
+ 
+     IjsClientCtx *ctx;
+     int ijs_version;
++
++    /* Additional parameters for krgb support. */
++    int krgb_mode;     /* 0=false, 1=true */
++    int k_path;        /* k plane path, 0=false, 1=true */
++    int k_width;       /* k plane width in pixels */
++    int k_band_size;   /* k plane buffer size in bytes, byte aligned */
++    unsigned char *k_band;  /* k plane buffer */
++    gx_device_procs prn_procs;  /* banding playback procedures */
+ };
+ 
+ #define DEFAULT_DPI 74   /* See gsijs_set_resolution() below. */
+@@ -150,7 +186,12 @@
+     FALSE,	/* Tumble_set */
+ 
+     NULL,	/* IjsClient *ctx */
+-    0		/* ijs_version */
++    0,		/* ijs_version */
++    0,          /* krgb_mode */
++    0,          /* k_path */
++    0,          /* k_width */
++    0,          /* k_band_size */
++    NULL        /* k_band buffer */
+ };
+ 
+ 
+@@ -166,12 +207,355 @@
+ 
+ /**************************************************************************/
+ 
+-/* ------ Private definitions ------ */
++/* ---------------- Low-level graphic procedures ---------------- */
++
++static unsigned char xmask[] =
++{
++   0x80,    /* x=0 */
++   0x40,    /* 1 */
++   0x20,    /* 2 */
++   0x10,    /* 3 */
++   0x08,    /* 4 */
++   0x04,    /* 5 */
++   0x02,    /* 6 */
++   0x01     /* 7 */
++};
++
++private int gsijs_fill_rectangle(gx_device * dev, int x, int y, int w, int h,
++           gx_color_index color)
++{
++   gx_device_ijs *ijsdev = (gx_device_ijs *)((gx_device_forward *)dev)->target;
++
++   if (ijsdev->krgb_mode && ijsdev->k_path && y >= 0 && x >= 0) 
++   {
++      int raster = (ijsdev->k_width+7) >> 3;
++      register unsigned char *dest;
++      int dest_start_bit;
++      int band_height = ijsdev->k_band_size/raster;
++      int i,j,x1,y1,w1,h1;
++
++      if (h <= 0 || w <= 0)
++         return 0;
++
++      /* Check for out-of-band graphic. */
++      if (x >= ijsdev->k_width || y >= band_height)
++         return 0;  /* out-of-band */
++
++      /* Check for x clipping. */
++      if (x < 0)
++      {
++         x1 = 0;
++         w1 = w + x;
++      }
++      else if ((x+w) > ijsdev->k_width)
++      {
++         x1 = x;
++         w1 = ijsdev->k_width - x;
++      }
++      else
++      { 
++         x1 = x;
++         w1 = w;
++      }
++
++      dest_start_bit = x1 & 7;
++
++      /* Check for y clipping. */
++      if (y < 0)
++      {
++         y1 = 0;
++         h1 = h + y;
++      }
++      else if ((y+h) > band_height)
++      {
++         y1 = y;
++         h1 = band_height - y;
++      }
++      else 
++      {
++         y1 = y;
++         h1 = h;
++      }
++
++      dest=ijsdev->k_band+(raster*y1)+(x1 >> 3);
++
++      /* Note x,y orgin 0,0 is stored first byte 0 left to right. */
++
++      if (color==0x0)
++      { 
++         /* Color is black, store in k plane band instead of regular band. */
++         for (j=0; j<h1; j++)
++         {
++            for (i=0; i<w1; i++)
++               dest[(dest_start_bit+i)>>3] |= xmask[(dest_start_bit+i)&7];
++            dest+=raster;    
++         }
++         return 0;
++      }
++      else
++      {
++         /* Color is not black, remove any k plane bits
++	  * for z-order dependencies, store in regular band. */
++         for (j=0; j<h1; j++)
++         {
++            for (i=0; i<w1; i++)
++               dest[(dest_start_bit+i)>>3] &= ~xmask[(dest_start_bit+i)&7];
++            dest+=raster;    
++         }
++      }
++   }
++
++   return (*ijsdev->prn_procs.fill_rectangle)(dev, x, y, w, h, color);
++}
++
++private int gsijs_copy_mono(gx_device * dev, const byte * data,
++      int dx, int draster, gx_bitmap_id id,
++      int x, int y, int w, int height, gx_color_index zero, gx_color_index one)
++{
++   gx_device_ijs *ijsdev = (gx_device_ijs *)((gx_device_forward *)dev)->target;
++
++   //   if (ijsdev->krgb_mode && ijsdev->k_path && one==0x0) 
++   if (ijsdev->krgb_mode && ijsdev->k_path) 
++   {
++      /* Store in k plane band instead of regular band. */
++      int raster = (ijsdev->k_width+7) >> 3;       /* raster width in bytes,
++						      byte aligned */
++      register unsigned char *dest;
++      register const unsigned char *scan;
++      int dest_start_bit;
++      int scan_start_bit;
++      int band_height = ijsdev->k_band_size/raster;
++      int i,x1,y1,w1,h1,h=height;
++      
++      if (h <= 0 || w <= 0)
++         return 0;
++
++      /* Check for out-of-band graphic. */
++      if (x >= ijsdev->k_width || y >= band_height)
++         return 0;  /* out-of-band */
++
++      /* Check for x clipping. */
++      if (x < 0)
++      {
++         x1 = 0;
++         w1 = w + x;
++         /* adj dx here?? */
++      }
++      else if ((x+w) > ijsdev->k_width)
++      {
++         x1 = x;
++         w1 = ijsdev->k_width - x;
++      }
++      else
++      { 
++         x1 = x;
++         w1 = w;
++      }
++
++      scan=data+(dx >> 3);
++      dest_start_bit = x1 & 7;
++      scan_start_bit = dx & 7;
++
++      /* Check for y clipping. */
++      if (y < 0)
++      {
++         y1 = 0;
++         h1 = h + y;
++         scan+=draster*(h-h1);
++      }
++      else if ((y+h) > band_height)
++      {
++         y1 = y;
++         h1 = band_height - y;
++      }
++      else 
++      {
++         y1 = y;
++         h1 = h;
++      }
++
++      dest=ijsdev->k_band+(raster*y1)+(x1 >> 3);
++
++      if (one==0x0)
++      {
++         /* Color is black, store in k plane band instead of regular band. */
++         while (h1-- > 0)
++         {
++            for (i=0; i<w1; i++)
++            {
++               if (scan[(scan_start_bit+i)>>3] & xmask[(scan_start_bit+i)&7])
++                  dest[(dest_start_bit+i)>>3] |= xmask[(dest_start_bit+i)&7];
++            }
++            scan+=draster;
++            dest+=raster;
++         }
++         return 0;
++      }
++      else
++      {
++         /* Color is not black, remove any k plane bits for
++	  * z-order dependencies, store in regular band. */
++         while (h1-- > 0)
++         {
++            for (i=0; i<w1; i++)
++            {
++               if (scan[(scan_start_bit+i)>>3] & xmask[(scan_start_bit+i)&7])
++                  dest[(dest_start_bit+i)>>3] &= ~xmask[(dest_start_bit+i)&7];
++            }
++            scan+=draster;
++            dest+=raster;
++         }
++      }   
++   }
++
++   return (*ijsdev->prn_procs.copy_mono)(dev, data, dx, draster, id,
++		   x, y, w, height, zero, one);
++}
++
++/* ---------------- High-level graphic procedures ---------------- */
++
++private int gsijs_fill_mask(gx_device * dev,
++      const byte * data, int dx, int raster, gx_bitmap_id id,
++      int x, int y, int w, int h,
++      const gx_drawing_color * pdcolor, int depth,
++      gs_logical_operation_t lop, const gx_clip_path * pcpath)
++{
++   gx_device_ijs *ijsdev = (gx_device_ijs *)((gx_device_forward *)dev)->target;
++   int code;
++
++   ijsdev->k_path = 1;
++
++   code = (*ijsdev->prn_procs.fill_mask)(dev, data, dx, raster, id,
++		   x, y, w, h, pdcolor, depth, lop, pcpath);
++
++   ijsdev->k_path = 0;
++
++   return code;
++}
++
++private int gsijs_fill_path(gx_device * dev, const gs_imager_state * pis,
++      gx_path * ppath, const gx_fill_params * params,
++      const gx_drawing_color * pdcolor,
++      const gx_clip_path * pcpath)
++{
++   gx_device_ijs *ijsdev = (gx_device_ijs *)((gx_device_forward *)dev)->target;
++   int code;
++
++   ijsdev->k_path = 1;
++
++   code = (*ijsdev->prn_procs.fill_path)(dev, pis, ppath, params,
++		   pdcolor, pcpath);
++
++   ijsdev->k_path = 0;
++
++   return 0;
++}
++
++private int gsijs_stroke_path(gx_device * dev, const gs_imager_state * pis,
++        gx_path * ppath, const gx_stroke_params * params,
++        const gx_drawing_color * pdcolor,
++        const gx_clip_path * pcpath)
++{
++   gx_device_ijs *ijsdev = (gx_device_ijs *)((gx_device_forward *)dev)->target;
++   int code;
+ 
+-/* Versions 1.0 through 1.0.2 of hpijs report IJS version 0.29, and
+-   require some workarounds. When more up-to-date hpijs versions
+-   become ubiquitous, all these workarounds should be removed. */
+-#define HPIJS_1_0_VERSION 29
++   ijsdev->k_path = 1;
++
++   code = (*ijsdev->prn_procs.stroke_path)(dev, pis, ppath, params,
++		   pdcolor, pcpath);
++
++   ijsdev->k_path = 0;
++
++   return code;
++}
++
++/* ---------------- krgb banding playback procedures ---------------- */
++
++private int gsijs_get_bits(gx_device_printer * pdev, int y, byte * str, byte ** actual_data)
++{
++   gx_device_ijs *ijsdev = (gx_device_ijs *)pdev;
++   gx_device_clist_common *cdev = (gx_device_clist_common *)pdev;
++   int band_height = cdev->page_info.band_params.BandHeight;
++   int band_number = y/band_height;
++   int raster = (ijsdev->k_width+7) >> 3;       /* raster width in bytes,
++						   byte aligned */
++   int y1=raster*(y-(band_height*band_number));
++ 
++   if (y1 == 0)
++   {
++      /* First raster for band, clear k_band.
++       * Banding playback occurs on first raster. */
++      memset(ijsdev->k_band, 0, ijsdev->k_band_size); 
++   }
++
++   return gdev_prn_get_bits(pdev, y, str, actual_data);  /* get raster from
++							    regular band */
++}
++
++private int gsijs_k_get_bits(gx_device_printer * pdev, int y,
++		byte ** actual_data)
++{
++   gx_device_ijs *ijsdev = (gx_device_ijs *)pdev;
++   gx_device_clist_common *cdev = (gx_device_clist_common *)pdev;
++   int band_height = cdev->page_info.band_params.BandHeight;
++   int band_number = y/band_height;
++   int raster = (ijsdev->k_width+7) >> 3;       /* raster width in bytes,
++						   byte aligned */
++   int y1=raster*(y-(band_height*band_number));
++ 
++   *actual_data = ijsdev->k_band+y1;
++
++   return 0;
++}
++
++private int gsijs_create_buf_device(gx_device **pbdev, gx_device *target,
++            const gx_render_plane_t *render_plane, gs_memory_t *mem,
++	    bool for_band)
++{
++   gx_device_ijs *ijsdev = (gx_device_ijs *)target;
++   int n_chan = ijsdev->color_info.num_components;
++   int code = gx_default_create_buf_device(pbdev, target, render_plane,
++		   mem, for_band);
++   if (code < 0 || n_chan != 3)
++      return code;
++
++   /* Save buffer (vector) procedures so that
++    * we can hook them during banding playback. */
++   ijsdev->prn_procs = (*pbdev)->procs;
++
++   /* Replace buffer procedures with krgb procedures. */
++   set_dev_proc(*pbdev, fill_rectangle, gsijs_fill_rectangle);
++   set_dev_proc(*pbdev, copy_mono, gsijs_copy_mono);
++   set_dev_proc(*pbdev, fill_mask, gsijs_fill_mask);
++   set_dev_proc(*pbdev, fill_path, gsijs_fill_path);
++   set_dev_proc(*pbdev, stroke_path, gsijs_stroke_path);
++
++   return code;
++}
++
++/* See if IJS server supports krgb. Return value: 0=false, 1=true. */
++private int
++gsijs_set_krgb_mode(gx_device_ijs *ijsdev)
++{
++    char buf[256];
++    int n_chan = ijsdev->color_info.num_components;
++    int code;
++
++    if (n_chan != 3)
++        return 0;    /* no krgb support, not RGB colorspace */
++
++    buf[0] = 0;
++    code = ijs_client_enum_param(ijsdev->ctx, 0, "ColorSpace",
++		    buf, sizeof(buf)-1);
++    if (code >= 0)
++        buf[code] = 0;
++    if (strstr(buf, "KRGB") == NULL)
++        return 0;  /* no krgb support */
++
++    return 1;  /* krgb is supported */
++}
++
++/* ------ Private definitions ------ */
+ 
+ private int
+ gsijs_parse_wxh (const char *val, int size, double *pw, double *ph)
+@@ -209,34 +593,6 @@
+ }
+ 
+ /**
+- * gsijs_set_generic_params_hpijs: Set generic IJS parameters.
+- *
+- * This version is specialized for hpijs 1.0 through 1.0.2, and
+- * accommodates a number of quirks.
+- **/
+-private int
+-gsijs_set_generic_params_hpijs(gx_device_ijs *ijsdev)
+-{
+-    char buf[256];
+-    int code = 0;
+-
+-    /* IjsParams, Duplex, and Tumble get set at this point because
+-       they may affect margins. */
+-    if (ijsdev->IjsParams) {
+-	code = gsijs_client_set_param(ijsdev, "IjsParams", ijsdev->IjsParams);
+-    }
+-
+-    if (code == 0 && ijsdev->Duplex_set) {
+-	int duplex_val;
+-	
+-	duplex_val = ijsdev->Duplex ? (ijsdev->IjsTumble ? 1 : 2) : 0;
+-	sprintf (buf, "%d", duplex_val);
+-	code = gsijs_client_set_param(ijsdev, "Duplex", buf);
+-    }
+-    return code;
+-}
+-
+-/**
+  * gsijs_set_generic_params: Set generic IJS parameters.
+  **/
+ private int
+@@ -247,9 +603,6 @@
+     int i, j;
+     char *value;
+ 
+-    if (ijsdev->ijs_version == HPIJS_1_0_VERSION)
+-	return gsijs_set_generic_params_hpijs(ijsdev);
+-
+     /* Split IjsParams into separate parameters and send to ijs server */
+     value = NULL;
+     for (i=0, j=0; (j < ijsdev->IjsParams_size) && (i < sizeof(buf)-1); j++) {
+@@ -290,68 +643,6 @@
+ }
+ 
+ /**
+- * gsijs_set_margin_params_hpijs: Do margin negotiation with IJS server.
+- *
+- * This version is specialized for hpijs 1.0 through 1.0.2, and
+- * accommodates a number of quirks.
+- **/
+-private int
+-gsijs_set_margin_params_hpijs(gx_device_ijs *ijsdev)
+-{
+-    char buf[256];
+-    int code = 0;
+-
+-    if (code == 0) {
+-	sprintf(buf, "%d", ijsdev->width);
+-	code = gsijs_client_set_param(ijsdev, "Width", buf);
+-    }
+-    if (code == 0) {
+-	sprintf(buf, "%d", ijsdev->height);
+-	code = gsijs_client_set_param(ijsdev, "Height", buf);
+-    }
+-
+-    if (code == 0) {
+-	double printable_width, printable_height;
+-	double printable_left, printable_top;
+-	float m[4];
+-
+-	code = ijs_client_get_param(ijsdev->ctx, 0, "PrintableArea",
+-				   buf, sizeof(buf));
+-	if (code == IJS_EUNKPARAM)
+-	    /* IJS server doesn't support margin negotiations.
+-	       That's ok. */
+-	    return 0;
+-	else if (code >= 0) {
+-	    code = gsijs_parse_wxh(buf, code,
+-				    &printable_width, &printable_height);
+-	}
+-
+-	if (code == 0) {
+-	    code = ijs_client_get_param(ijsdev->ctx, 0, "PrintableTopLeft",
+-					buf, sizeof(buf));
+-	    if (code == IJS_EUNKPARAM)
+-		return 0;
+-	    else if (code >= 0) {
+-		code = gsijs_parse_wxh(buf, code,
+-					&printable_left, &printable_top);
+-	    }
+-	}
+-
+-	if (code == 0) {
+-	    m[0] = printable_left;
+-	    m[1] = ijsdev->MediaSize[1] * (1.0 / 72) -
+-	      printable_top - printable_height;
+-	    m[2] = ijsdev->MediaSize[0] * (1.0 / 72) -
+-	      printable_left - printable_width;
+-	    m[3] = printable_top;
+-	    gx_device_set_margins((gx_device *)ijsdev, m, true);
+-	}
+-    }
+-
+-    return code;
+-}
+-
+-/**
+  * gsijs_set_margin_params: Do margin negotiation with IJS server.
+  **/
+ private int
+@@ -362,9 +653,6 @@
+     int i, j;
+     char *value;
+ 
+-    if (ijsdev->ijs_version == HPIJS_1_0_VERSION)
+-	return gsijs_set_margin_params_hpijs(ijsdev);
+-
+     /* Split IjsParams into separate parameters and send to ijs server */
+     value = NULL;
+     for (i=0, j=0; (j < ijsdev->IjsParams_size) && (i < sizeof(buf)-1); j++) {
+@@ -531,12 +819,19 @@
+     char buf[256];
+     bool use_outputfd;
+     int fd = -1;
++    long max_bitmap = ijsdev->space_params.MaxBitmap;
+ 
+     if (strlen(ijsdev->IjsServer) == 0) {
+ 	eprintf("ijs server not specified\n");
+ 	return gs_note_error(gs_error_ioerror);
+     }
+ 
++    ijsdev->space_params.MaxBitmap = 0;	/* force banding */
++
++    /* Set create_buf_device in printer device,
++     * so that we can hook the banding playback procedures. */
++    ijsdev->printer_procs.buf_procs.create_buf_device = gsijs_create_buf_device;
++
+     /* Decide whether to use OutputFile or OutputFD. Note: how to
+        determine this is a tricky question, so we just allow the
+        user to set it.
+@@ -551,6 +846,8 @@
+     if (code < 0)
+ 	return code;
+ 
++    ijsdev->space_params.MaxBitmap = max_bitmap;
++    
+     if (use_outputfd) {
+ 	/* Note: dup() may not be portable to all interesting IJS
+ 	   platforms. In that case, this branch should be #ifdef'ed out.
+@@ -610,6 +907,9 @@
+     if (code >= 0)
+ 	code = gsijs_set_margin_params(ijsdev);
+ 
++    if (code >= 0)
++        ijsdev->krgb_mode = gsijs_set_krgb_mode(ijsdev);
++
+     return code;
+ }
+ 
+@@ -690,21 +990,6 @@
+     return min(width, end);
+ }
+ 
+-private int ijs_all_white(unsigned char *data, int size)
+-{
+-   int clean = 1;
+-   int i;
+-   for (i = 0; i < size; i++)
+-   {
+-     if (data[i] != 0xFF)
+-     {
+-        clean = 0;
+-        break;
+-     }
+-   }
+-   return clean;
+-}
+-
+ /* Print a page.  Don't use normal printer gdev_prn_output_page 
+  * because it opens the output file.
+  */
+@@ -715,8 +1000,9 @@
+     gx_device_printer *pdev = (gx_device_printer *)dev;
+     int raster = gdev_prn_raster(pdev);
+     int ijs_width, ijs_height;
+-    int row_bytes;
++    int row_bytes, k_row_bytes=0;
+     int n_chan = pdev->color_info.num_components;
++    int krgb_mode = ijsdev->krgb_mode;
+     unsigned char *data;
+     char buf[256];
+     double xres = pdev->HWResolution[0];
+@@ -732,13 +1018,24 @@
+ 
+     /* Determine bitmap width and height */
+     ijs_height = gdev_prn_print_scan_lines(dev);
+-    if (ijsdev->ijs_version == HPIJS_1_0_VERSION) {
+-	ijs_width = pdev->width;
+-    } else {
+-	ijs_width = gsijs_raster_width(dev);
+-    }
++    ijs_width = gsijs_raster_width(dev);
++
+     row_bytes = (ijs_width * pdev->color_info.depth + 7) >> 3;
+ 
++    if (krgb_mode)
++    {
++        gx_device_clist_common *cdev = (gx_device_clist_common *)dev;
++        int band_height = cdev->page_info.band_params.BandHeight;
++        k_row_bytes = (ijs_width + 7) >> 3;
++
++        /* Create banding buffer for k plane. */
++        ijsdev->k_width = ijs_width;
++        ijsdev->k_band_size = band_height * k_row_bytes;   
++        if ((ijsdev->k_band = gs_malloc(pdev->memory, ijsdev->k_band_size,
++			1, "gsijs_output_page")) == (unsigned char *)NULL)
++           return gs_note_error(gs_error_VMerror);
++    }
++
+     /* Required page parameters */
+     sprintf(buf, "%d", n_chan);
+     gsijs_client_set_param(ijsdev, "NumChan", buf);
+@@ -747,44 +1044,76 @@
+ 
+     /* This needs to become more sophisticated for DeviceN. */
+     strcpy(buf, (n_chan == 4) ? "DeviceCMYK" : 
+-	((n_chan == 3) ? "DeviceRGB" : "DeviceGray"));
++	((n_chan == 3) ? (krgb_mode ? "KRGB" : "DeviceRGB") : "DeviceGray"));
+     gsijs_client_set_param(ijsdev, "ColorSpace", buf);
+ 
+-    /* If hpijs 1.0, don't set width and height here, because it
+-       expects them to be the paper size. */
+-    if (ijsdev->ijs_version != HPIJS_1_0_VERSION) {
+-	sprintf(buf, "%d", ijs_width);
+-	gsijs_client_set_param(ijsdev, "Width", buf);
+-	sprintf(buf, "%d", ijs_height);
+-	gsijs_client_set_param(ijsdev, "Height", buf);
+-    }
++    sprintf(buf, "%d", ijs_width);
++    gsijs_client_set_param(ijsdev, "Width", buf);
++    sprintf(buf, "%d", ijs_height);
++    gsijs_client_set_param(ijsdev, "Height", buf);
+ 
+     sprintf(buf, "%gx%g", xres, yres);
+     gsijs_client_set_param(ijsdev, "Dpi", buf);
+ 
++#ifdef KRGB_DEBUG
++    int kfd, rgbfd;
++    char sz[128];
++    kfd = open("/tmp/k.pbm", O_CREAT | O_TRUNC | O_RDWR, 0644);
++    rgbfd = open("/tmp/rgb.ppm", O_CREAT | O_TRUNC | O_RDWR, 0644);
++    snprintf(sz, sizeof(sz), "P4\n#gdevijs test\n%d\n%d\n",
++		    ijs_width, ijs_height);
++    write(kfd, sz, strlen(sz));
++    snprintf(sz, sizeof(sz), "P6\n#gdevijs test\n%d\n%d\n255\n",
++		    ijs_width, ijs_height);
++    write(rgbfd, sz, strlen(sz));
++#endif
++
+     for (i=0; i<num_copies; i++) {
+  	unsigned char *actual_data;
+ 	ijs_client_begin_cmd (ijsdev->ctx, IJS_CMD_BEGIN_PAGE);
+ 	status = ijs_client_send_cmd_wait(ijsdev->ctx);
+ 
+ 	for (y = 0; y < ijs_height; y++) {
+-	    code = gdev_prn_get_bits(pdev, y, data, &actual_data);
+-	    if (code < 0)
+-		break;
++            if (krgb_mode)
++                code = gsijs_get_bits(pdev, y, data, &actual_data);
++            else
++                code = gdev_prn_get_bits(pdev, y, data, &actual_data);
++            if (code < 0)
++                break;
++#ifdef KRGB_DEBUG
++            write(rgbfd, actual_data, row_bytes);
++#endif
++            status = ijs_client_send_data_wait(ijsdev->ctx, 0,
++			    (char *)actual_data, row_bytes);
++            if (status)
++                break;
+ 
+-	    if (ijsdev->ijs_version == HPIJS_1_0_VERSION &&
+-		ijs_all_white(actual_data, row_bytes))
+-		status = ijs_client_send_data_wait(ijsdev->ctx, 0, NULL, 0);
+-	    else
+-		status = ijs_client_send_data_wait(ijsdev->ctx, 0,
+-		    (char *)actual_data, row_bytes);
+-	    if (status)
+-		break;
++            if (krgb_mode) {
++                code = gsijs_k_get_bits(pdev, y, &actual_data);
++                if (code < 0)
++                    break;
++#ifdef KRGB_DEBUG
++                write(kfd, actual_data, k_row_bytes);
++#endif
++                status = ijs_client_send_data_wait(ijsdev->ctx, 0,
++				(char *)actual_data, k_row_bytes);
++                if (status)
++                    break;
++	    }
+ 	}
+ 	ijs_client_begin_cmd(ijsdev->ctx, IJS_CMD_END_PAGE);
+ 	status = ijs_client_send_cmd_wait(ijsdev->ctx);
+     }
+ 
++#ifdef KRGB_DEBUG
++    close(kfd);
++    close(rgbfd);
++#endif
++
++    if(krgb_mode)
++        gs_free(pdev->memory, ijsdev->k_band, ijsdev->k_band_size,
++			1, "gsijs_output_page");
++
+     gs_free_object(pdev->memory, data, "gsijs_output_page");
+ 
+     endcode = (pdev->buffer_space && !pdev->is_async_renderer ?
+@@ -1090,7 +1419,6 @@
+ 	dprintf2("ijs: Can't set parameter %s=%s\n", key, value);
+     return code;
+ }
+- 
+ 
+ private int
+ gsijs_set_color_format(gx_device_ijs *ijsdev)

Added: gs-gpl/trunk/debian/patches/11_brother_7x0_gdi_fix.dpatch
==============================================================================
--- (empty file)
+++ gs-gpl/trunk/debian/patches/11_brother_7x0_gdi_fix.dpatch	Sun Oct 22 23:08:22 2006
@@ -0,0 +1,32 @@
+#! /bin/sh -e
+## 11_brother_7x0_fix.dpatch by Masayuki Hatta <mhatta at debian.org>
+##
+## All lines beginning with \`## DP:' are a description of the patch.
+## DP: Fix a problem with Brother 7x0 GDI, suggested by B. Janssen.
+
+if [ $# -ne 1 ]; then
+    echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
+    exit 1
+fi
+case "$1" in
+        -patch) patch -f --no-backup-if-mismatch --dry-run -p1 < $0 && patch -f --no-backup-if-mismatch -p1 < $0
+;;
+        -unpatch) patch -f --no-backup-if-mismatch -R -p1 < $0;;
+        *)
+                echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
+                exit 1;;
+esac
+
+exit 0
+
+diff -urN gs-gpl-8.01.orig/src/gdevhl7x.c gs-gpl-8.01/src/gdevhl7x.c
+--- gs-gpl-8.01.orig/src/gdevhl7x.c	2004-08-15 13:18:12.000000000 +0900
++++ gs-gpl-8.01/src/gdevhl7x.c	2004-08-15 13:19:29.000000000 +0900
+@@ -83,6 +83,7 @@
+ 
+  */
+ 
++#define USE_POSSIBLY_FLAWED_COMPRESSION 1
+ 
+ /* Type definitions */
+ typedef struct {

Added: gs-gpl/trunk/debian/patches/23_hl12x0_support.dpatch
==============================================================================
--- (empty file)
+++ gs-gpl/trunk/debian/patches/23_hl12x0_support.dpatch	Sun Oct 22 23:08:22 2006
@@ -0,0 +1,772 @@
+#! /bin/sh -e
+## 23_hl12x0_support.dpatch by Masayuki Hatta <mhatta at debian.org>
+##
+## All lines beginning with \`## DP:' are a description of the patch.
+## DP: Adds Brother HL-1240/1250 support.
+## DP: License: Public Domain
+
+if [ $# -ne 1 ]; then
+    echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
+    exit 1
+fi
+case "$1" in
+        -patch) patch -f --no-backup-if-mismatch --dry-run -p1 < $0 && patch -f --no-backup-if-mismatch -p1 < $0
+;;
+        -unpatch) patch -f --no-backup-if-mismatch -R -p1 < $0;;
+        *)
+                echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
+                exit 1;;
+esac
+
+exit 0
+
+diff -urN gs-gpl-8.54.dfsg.1.orig/src/gdevhl12.c gs-gpl-8.54.dfsg.1/src/gdevhl12.c
+--- gs-gpl-8.54.dfsg.1.orig/src/gdevhl12.c	1970-01-01 09:00:00.000000000 +0900
++++ gs-gpl-8.54.dfsg.1/src/gdevhl12.c	2006-10-21 14:23:06.000000000 +0900
+@@ -0,0 +1,745 @@
++/*
++   Contributors:
++     Created by Marek Michalkiewicz <marekm at amelek.gda.pl>
++
++   THIS SOFTWARE IS NOT COPYRIGHTED
++
++   This source code is offered for use in the public domain.  You may
++   use, modify or distribute it freely.
++
++   This code is distributed in the hope that it will be useful, but
++   WITHOUT ANY WARRANTY.  ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
++   DISCLAIMED.  This includes but is not limited to warranties of
++   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
++
++   (Legalese borrowed from the Mingw32 runtime libraries.)
++ */
++
++/*$Id: gdevhl12.c,v 1.6 2002/07/30 18:53:21 easysw Exp $ */
++/* gdevhl12.c - Brother HL-1250 driver for Ghostscript */
++
++/*
++   This driver handles the 1200x600 dpi mode, and some settings like
++   paper source and toner save mode.  600x600 dpi and below is handled
++   by gdevdljm.c (basically as in the ljet4 device, with minor changes
++   in initialization and margins, and PCL wrapped in PJL).
++
++   There are two device names made available by this driver, which
++   differ only in the default (maximum) resolution:
++
++     -sDEVICE=hl1240
++	600x600 dpi, for HL-1030/1240 (uses standard PCL modes 2 and 3)
++
++     -sDEVICE=hl1250
++	1200x600 dpi, for HL-1050/1070/1250/1270N
++	(uses special compression mode 1027 for 1200x600 dpi,
++	otherwise modes 2 and 3 as above)
++
++   Tested with a HL-1250, both 1200x600 and 600x600 dpi.  Please test
++   with other models and report results (both problems and success).
++   Some notes on the other models:
++
++     HL-1070 and HL-1270N
++	can also print Postscript directly, at maximum 600x600 dpi
++	(this driver can print 1200x600 dpi using mode 1027).
++
++     HL-1240
++	should no longer be limited to 300 dpi - this driver sends
++	the recommended "@PJL SET RESOLUTION=..." command.  PLEASE TEST.
++	There have been some vague problem reports (wrong margins? not
++	clear for what paper size, quite possibly Letter, not A4?) with
++	this printer, if you have it and some Ghostscript hacking skills,
++	_please_ try to help, fix it and send me a patch - thanks!
++
++     HL-1030
++	should no longer be "Paperweight" despite the "for Windows only"
++	warning :-) - it knows enough PCL to print raster graphics, but
++	*requires* "@PJL ENTER LANGUAGE=PCL", so it does not work with
++	the ljet4 driver sending raw PCL.  The windows driver uses an
++	undocumented compression mode 1030, but modes 2 and 3 work too.
++	PLEASE TEST.
++
++   New models, still need to be tested:
++     HL-1230 (GDI printer)
++     HL-1440 (GDI printer)
++     HL-1450 (PCL6 and PS2 emulation)
++     HL-1470N (PCL6 and PS2 emulation)
++
++   Additional settings (gs command line options) for this driver:
++
++     -dEconoMode=0...2
++	toner save mode: 0 = disabled (default), 1 = 25%, 2 = 50%
++
++     -dPaperType=0...4
++	paper type: 0 = plain (default), 1 = thin, 2 = thick, 3 = thicker,
++	4 = transparency
++
++     -dSourceTray=0...4
++	paper source: 0 = auto (default), 1 = dual, 2 = upper, 3 = lower,
++	4 = manual (not all models support the optional lower tray)
++
++   The 1200x600 dpi mode may require a lot of printer memory - the manual
++   recommends at least 10 MB; for me it seems to work well with 8 MB: 4 MB
++   standard + 4 MB "finally found some good use for that old PS/2 SIMM" :-).
++   Even at just 600x600 dpi (normal PCL 5 control codes) print quality is
++   very good, at 1200x600 dpi it is difficult to see the difference (more
++   visible on grayscale images).  So 600x600 dpi is best for general use.
++
++   The HL-1250 also supports PCL 6 (PCL XL) but
++   - I don't have the documentation for that
++   - the pxlmono driver works, but the output looks a bit different
++     from that generated by the ljet4 or (this) 1200x600 dpi driver
++     (lines appear very thin - not yet sure if this is a driver bug
++     or differences in PCL 6 implementation, someone should check on
++     a HP printer, does tiger.ps printed using the ljet4 and pxlmono
++     drivers, both at 600x600 dpi, look the same?)
++   so let's use the good old ljet4 (PCL 5) driver for now.
++   (PCL 6 seems to offer better compression though.)
++
++   To do: the undocumented mode 1030 may offer better compression
++   (may help print complex graphics at 600 dpi - the HL-1030/1240 have
++   only 2 MB of non-expandable RAM, which may not be enough for data
++   that doesn't compress well).  The windows driver uses this mode for
++   all models, not just HL-1030.  Documentation may be available later.
++
++   Many thanks to Richard Thomas <richardt at brother.co.uk> for help
++   (sending me a HL-1250, documentation, answering my questions).
++
++   Thanks to L. Peter Deutsch <ghost at aladdin.com> for making gdevdjet.c
++   and gdevdljm.[ch] available under a dual AFPL/GPL license.
++ */
++
++#include "gdevprn.h"
++#include "gdevdljm.h"
++
++#undef stderr
++#include <stdio.h>
++
++#ifdef X_DPI
++#  define X_DPI2 X_DPI
++#else
++#  define X_DPI 600
++#  define X_DPI2 1200
++#endif
++
++#ifndef Y_DPI
++#  define Y_DPI 600
++#endif
++
++typedef enum {
++    ECONO_OFF = 0,
++    ECONO_25,
++    ECONO_50
++} hl1250_econo_t;
++
++typedef enum {
++    PTYPE_PLAIN = 0,
++    PTYPE_THIN,
++    PTYPE_THICK,
++    PTYPE_THICK2,
++    PTYPE_TRANS
++} hl1250_paper_t;
++
++typedef enum {
++    TRAY_AUTO = 0,
++    TRAY_DUAL,
++    TRAY_UPPER,
++    TRAY_LOWER,
++    TRAY_MANUAL
++} hl1250_tray_t;
++
++typedef struct gx_device_hl1250_s {
++    gx_device_common;
++    gx_prn_device_common;
++    hl1250_econo_t econo_mode;
++    hl1250_paper_t paper_type;
++    hl1250_tray_t source_tray;
++} gx_device_hl1250;
++
++private dev_proc_open_device(hl1250_open);
++private dev_proc_close_device(hl1250_close);
++private dev_proc_print_page_copies(hl1250_print_page_copies);
++private dev_proc_get_params(hl1250_get_params);
++private dev_proc_put_params(hl1250_put_params);
++
++private const gx_device_procs prn_hl1250_procs =
++prn_params_procs(hl1250_open, gdev_prn_output_page, hl1250_close,
++		 hl1250_get_params, hl1250_put_params);
++
++#define hl1250_device_copies(dname, xdpi, ydpi)\
++{   prn_device_std_body_copies(gx_device_hl1250, prn_hl1250_procs,\
++			       dname,\
++			       DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,\
++			       xdpi, ydpi,\
++			       0, 0, 0, 0,\
++			       1, hl1250_print_page_copies),\
++    ECONO_OFF, PTYPE_PLAIN, TRAY_AUTO\
++}
++
++const gx_device_hl1250 gs_hl1250_device =
++hl1250_device_copies("hl1250", X_DPI2, Y_DPI);
++
++const gx_device_hl1250 gs_hl1240_device =
++hl1250_device_copies("hl1240", X_DPI, Y_DPI);
++
++/* defines for the 1200x600 dpi mode (mode 1027) */
++
++/* max number of 16-bit words in one 1200 dpi scan line */
++#define SCAN_WORDS 640
++
++/* number of scan lines per band */
++#define BAND_SCANS 64
++
++/* max number of 16-bit words in one 64-line band after compression,
++   limited by 16-bit length field - 7 bytes header + 0xFFF8 bytes data -
++   note that we may have to lose some data if it can't compress well
++   (maximum possible uncompressed data length is about 80K).  */
++#define MAX_BAND_WORDS 0x7FFC
++
++/* codes (16-bit words) to send in the 1200x600 dpi data block: */
++
++/* vertical compression (copy COUNT words from the previous line) */
++#define HL_VERT(count) (0xE000 | (count))
++
++/* 16-bit horizontal compression (repeat the next word COUNT times) */
++#define HL_HOR16(count) (0x8000 | (count))
++
++/* 8-bit horiz. compression (repeat DATA byte COUNT*2 times, COUNT < 32) */
++#define HL_HOR8(count, data) (0xC000 | ((count) << 8) | ((data) & 0xFF))
++
++/* 4-bit horiz. compression (repeat DATA nibble COUNT*4 times, COUNT < 512) */
++#define HL_HOR4(count, data) (0xA000 | (count) | (((data) & 0x0F) << 9))
++
++/* no compression, COUNT words of data follow */
++#define HL_COPY(count) ((count) << 4)
++
++typedef unsigned short u16;
++
++/* The printer expects 16-bit data words in big endian order.  */
++#if arch_is_big_endian
++#define cpu_to_be16(x) (x)
++#else
++private u16
++cpu_to_be16(u16 x)
++{
++    return (x >> 8) | (x << 8);
++}
++#endif
++
++typedef struct hl1250_state_s {
++    /* smallest area that contains all black dots of the band */
++    /* x = xl..xr-1, y = yt..yb-1, width=xr-xl, height=yb-yt */
++    unsigned int xl, xr, yt, yb;
++
++    /* number of words in the output buffer */
++    unsigned int out_count;
++
++    /* output buffer for compressed data */
++    u16 out_buf[MAX_BAND_WORDS];
++
++    /* input buffer for one 64-line band */
++    u16 in_buf[BAND_SCANS][SCAN_WORDS];
++} hl1250_state_t;
++
++/*
++   find the smallest rectangle that contains all black dots of the
++   band (in other words, the outside of that rectangle is all white)
++   returns 0 if the band is completely white, else 1
++   XXX - it should be faster to scan 32-bit (instead of 16-bit) words
++ */
++private int
++hl1250_check_area(hl1250_state_t * s)
++{
++    unsigned int x, y, xleft, xright, ytop, ybottom;
++    int line_not_white, band_not_white;
++
++    band_not_white = 0;
++    xright = s->xl;
++    xleft = s->xr;
++    ybottom = s->yt;
++    ytop = s->yb;
++    for (y = s->yt; y < s->yb; y++) {
++	line_not_white = 0;
++	for (x = s->xl; x < s->xr; x++) {
++	    if (s->in_buf[y][x]) {
++		if (xleft > x)
++		    xleft = x;
++		if (xright <= x)
++		    xright = x + 1;
++		line_not_white = 1;
++	    }
++	}
++	if (line_not_white) {
++	    if (ytop > y)
++		ytop = y;
++	    if (ybottom <= y)
++		ybottom = y + 1;
++	    band_not_white = 1;
++	}
++    }
++    if (band_not_white) {
++	s->xl = xleft;
++	s->xr = xright;
++	s->yt = ytop;
++	s->yb = ybottom;
++    } else {
++	s->xr = s->xl;
++	s->yb = s->yt;
++    }
++    return band_not_white;
++}
++
++/*
++   Compressed data of this band is larger than MAX_BAND_WORDS.
++   Repeat each line using vertical compression, effectively reducing
++   resolution to 1200x300 dpi.  This shouldn't happen too often.
++ */
++private void
++hl1250_lose_resolution(hl1250_state_t * s)
++{
++    unsigned int x, y;
++    u16 data0, data1, mask;
++    u16 *out;
++    const u16 *line0;
++    const u16 *line1;
++    unsigned int width = s->xr - s->xl;
++
++    out = s->out_buf;
++    for (y = s->yt; y < s->yb; y += 2) {
++	line0 = &s->in_buf[y][s->xl];
++	line1 = line0;
++	if (y + 1 < s->yb)
++	    line1 = &s->in_buf[y + 1][s->xl];
++	mask = (y & 2) ? 0x5555 : 0xAAAA;
++	*out++ = cpu_to_be16(HL_COPY(width));
++	for (x = 0; x < width; x++) {
++	    data0 = line0[x];
++	    data1 = line1[x];
++	    *out++ = (data0 & data1) | (data0 & mask) | (data1 & mask);
++	}
++	*out++ = cpu_to_be16(HL_VERT(width));
++    }
++    s->out_count = out - s->out_buf;
++}
++
++/*
++   Try to compress a single scan line.
++   Return 1 on success, 0 on failure (data doesn't compress
++   well enough to fit in MAX_BAND_WORDS words, truncated).
++ */
++private int
++hl1250_compress_line(hl1250_state_t * s, unsigned int y)
++{
++    unsigned int total_len;	/* total data words after compression */
++    unsigned int copy_len;	/* number of words to copy uncompressed */
++    unsigned int hlen, vlen;	/* length for hor. and vert. compression */
++    unsigned int clen, ulen;	/* compressed and uncompressed words */
++    u16 data;			/* word currently being processed */
++    u16 hl_code;		/* code to send */
++    int x, i;
++    u16 *out;
++    unsigned int width = s->xr - s->xl;
++    const u16 *line = &s->in_buf[y][s->xl];
++    const u16 *prev = (y > s->yt ? &s->in_buf[y - 1][s->xl] : NULL);
++
++    out = &s->out_buf[s->out_count];
++    x = 0;
++    copy_len = 0;
++    total_len = s->out_count;
++    while (x < width) {
++	data = line[x];
++
++	/* how many words (hlen >= 1) to repeat */
++	for (i = x + 1; i < width; i++) {
++	    if (line[i] != data)
++		break;
++	}
++	hlen = i - x;
++	/* if not the first line, try vertical compression */
++	vlen = 0;
++	if (prev) {
++	    for (i = x; i < width; i++) {
++		if (line[i] != prev[i])
++		    break;
++	    }
++	    vlen = i - x;
++	}
++	/* find the best method to encode the data */
++	ulen = hlen;
++	clen = 1;
++	if (vlen >= hlen) {
++	    /* vertical compression */
++	    ulen = vlen;
++	    hl_code = HL_VERT(vlen);
++	} else if ((data ^ (data >> 8)) & 0xFF) {
++	    /* 16-bit horizontal compression */
++	    hl_code = HL_HOR16(hlen);
++	    clen = 2;
++	} else if ((data ^ (data >> 4)) & 0x0F) {
++	    /* 8-bit horizontal compression (if possible) */
++	    if (hlen < 32) {
++		hl_code = HL_HOR8(hlen, data);
++	    } else {
++		hl_code = HL_HOR16(hlen);
++		clen = 2;
++	    }
++	} else {
++	    /* 4-bit horizontal compression (if possible) */
++	    if (hlen < 512) {
++		hl_code = HL_HOR4(hlen, data);
++	    } else {
++		hl_code = HL_HOR16(hlen);
++		clen = 2;
++	    }
++	}
++	/*
++	   now see if we should copy the word without compression
++	   (the cost of leaving/re-entering copy mode is one word).
++	 */
++	if (ulen < clen + (copy_len > 0)) {
++	    /* yes, copy */
++	    copy_len += ulen;
++	} else {
++	    if (copy_len) {
++		/* first, copy data (if any) */
++		total_len += copy_len + 1;
++		if (total_len > MAX_BAND_WORDS)
++		    goto error_out;
++		*out++ = cpu_to_be16(HL_COPY(copy_len));
++		memcpy(out, &line[x - copy_len], copy_len * sizeof(u16));
++		out += copy_len;
++		copy_len = 0;
++	    }
++	    /* now send the current code */
++	    total_len += clen;
++	    if (total_len > MAX_BAND_WORDS)
++		goto error_out;
++	    *out++ = cpu_to_be16(hl_code);
++	    if (clen == 2) {
++		/* 16-bit compression */
++		*out++ = data;
++	    }
++	}
++	/* move to the next word to process */
++	x += ulen;
++    }
++    /* copy anything left at the end */
++    if (copy_len) {
++	total_len += copy_len + 1;
++	if (total_len > MAX_BAND_WORDS)
++	    goto error_out;
++	*out++ = cpu_to_be16(HL_COPY(copy_len));
++	memcpy(out, &line[width - copy_len], copy_len * sizeof(u16));
++	out += copy_len;
++    }
++  error_out:
++    s->out_count = out - s->out_buf;
++    return (total_len <= MAX_BAND_WORDS);
++}
++
++/*
++   send a 16-bit big endian value
++ */
++private void
++put_be16(FILE * fp, u16 data)
++{
++    putc(data >> 8, fp);
++    putc(data & 0xFF, fp);
++}
++
++/*
++   prn_stream = data sent to the printer
++   s->xl,xr,yt,yb,in_buf = band (max 64 lines), coordinates band-relative
++   band = Y coordinate of the band from top of page
++ */
++private void
++hl1250_compress_band(FILE * prn_stream, hl1250_state_t * s, unsigned int band)
++{
++    unsigned int y, ytop, ybottom;
++
++    s->out_count = 0;
++
++    if (!hl1250_check_area(s))
++	return;
++
++    /*
++       It seems HL-1250 1200x600 dpi mode has an undocumented feature -
++       it rounds the X left coordinate of the image up to next 32 dots.
++       Probably the RISC inside likes 32-bit alignment.  No big problem,
++       we just have to round it down (it's in 16-bit words here).
++     */
++    s->xl &= ~1;
++
++    ytop = s->yt;
++    ybottom = s->yb;
++    for (y = ytop; y < ybottom; y++) {
++	if (hl1250_compress_line(s, y))
++	    continue;
++#if 1
++	/* XXX - please report if you ever see this, then change to #if 0 */
++	fprintf(stderr,
++		"hl1250: compression failed (y=%u), doing 1200x300 dpi\n",
++		band + y);
++#endif
++	hl1250_lose_resolution(s);
++	break;
++    }
++    if (s->out_count) {
++	fprintf(prn_stream, "\033*b%uW", s->out_count * sizeof(u16) + 9);
++	put_be16(prn_stream, s->out_count * sizeof(u16) + 7);
++	put_be16(prn_stream, s->xl * 16);
++	put_be16(prn_stream, band + ytop);
++	putc(ybottom - ytop, prn_stream);
++	put_be16(prn_stream, s->xr - s->xl);
++	fwrite(s->out_buf, sizeof(u16), s->out_count, prn_stream);
++    }
++}
++
++
++private int
++hl1250_print_1200dpi(gx_device_printer * pdev, FILE * prn_stream,
++		     int num_copies, const char *page_init)
++{
++    int band, lnum;
++    int code = 0;
++    hl1250_state_t *s;
++    int line_size = gdev_prn_raster(pdev);
++    int num_rows = dev_print_scan_lines(pdev);
++    int paper_size = gdev_pcl_paper_size((gx_device *) pdev);
++
++    s = (hl1250_state_t *) gs_alloc_byte_array(pdev->memory, 1, sizeof(*s),
++					       "hl1250_print_1200dpi");
++    if (!s)
++	return_error(gs_error_VMerror);
++
++    memset(s, 0, sizeof(*s));
++
++    if (line_size > sizeof(s->in_buf[0]))
++	line_size = sizeof(s->in_buf[0]);
++
++    if (pdev->PageCount == 0) {
++	/* reset, set paper size */
++	fprintf(prn_stream, "\033E\033&l%dA", paper_size);
++    }
++    fputs("\033&u1200D", prn_stream);
++    fputs("\033&l0o0l0E", prn_stream);
++    fputs(page_init, prn_stream);
++    fprintf(prn_stream, "\033&l%dX", num_copies);
++    fputs("\033*rB\033*p0x0Y", prn_stream);
++
++    /* set 600dpi (vertical) resolution */
++    fputs("\033*t600R", prn_stream);
++
++    /* start raster graphics */
++    fputs("\033*r1A", prn_stream);
++
++    /* transfer data in the special 1200x600 dpi format */
++    fputs("\033*b1027M", prn_stream);
++
++    for (band = 0; band < num_rows; band += BAND_SCANS) {
++	int next_band = band + BAND_SCANS;
++
++	if (next_band > num_rows)
++	    next_band = num_rows;
++	for (lnum = band; lnum < next_band; lnum++) {
++	    code = gdev_prn_copy_scan_lines(pdev, lnum,
++			      (byte *) (s->in_buf[lnum - band]), line_size);
++	    if (code < 0)
++		goto error_out;
++	}
++	s->yt = 0;
++	s->yb = next_band - band;
++	s->xl = 0;
++	s->xr = 635;		/* max width */
++	hl1250_compress_band(prn_stream, s, band);
++    }
++  error_out:
++    fputs("\033*rB\f", prn_stream);
++    gs_free_object(pdev->memory, s, "hl1250_print_1200dpi");
++    return code;
++}
++
++
++private int
++hl1250_open(gx_device * pdev)
++{
++    /* margins: left, bottom, right, top */
++    /* XXX - only A4 tested, letter size margins likely need to be tweaked */
++    static const float margins_a4_600[4] = {0.05, 0.15, 0.25, 0.15};
++    static const float margins_a4_1200[4] = {0.05, 0.2, 0.1, 0.15};
++    static const float margins_letter_600[4] = {0.05, 0.15, 0.25, 0.15};
++    static const float margins_letter_1200[4] = {0.05, 0.2, 0.1, 0.15};
++
++    int x_dpi = (int)((gx_device_printer *) pdev)->x_pixels_per_inch;
++    int paper_size = gdev_pcl_paper_size(pdev);
++
++    if (x_dpi == 1200) {
++	if (paper_size == PAPER_SIZE_A4)
++	    gx_device_set_margins(pdev, margins_a4_1200, true);
++	else
++	    gx_device_set_margins(pdev, margins_letter_1200, true);
++    } else {
++	if (paper_size == PAPER_SIZE_A4)
++	    gx_device_set_margins(pdev, margins_a4_600, false);
++	else
++	    gx_device_set_margins(pdev, margins_letter_600, false);
++    }
++    return gdev_prn_open(pdev);
++}
++
++#define UEL "\033%-12345X"
++
++/* XXX - how to get the name of the job (PS file) being printed? */
++#define PJL_JOB_NAME "Ghost"
++
++private int
++hl1250_close(gx_device * pdev)
++{
++    int code = gdev_prn_open_printer(pdev, 1);
++    FILE *fp;
++
++    if (code < 0)
++	return code;
++    fp = ((gx_device_printer *) pdev)->file;
++    /* job separation, reset, UEL */
++    fputs("\033&l1T\033E", fp);
++    fputs(UEL, fp);
++    fprintf(fp, "@PJL EOJ NAME=\"%s\"\r\n", PJL_JOB_NAME);
++    fputs(UEL, fp);
++    return gdev_prn_close(pdev);
++}
++
++
++private int
++hl1250_print_page_copies(gx_device_printer * pdev, FILE * prn_stream,
++			 int num_copies)
++{
++    int x_dpi = (int)pdev->x_pixels_per_inch;
++    int y_dpi = (int)pdev->y_pixels_per_inch;
++    const char *tray_pjl;
++    const char *tray_pcl;
++    const gx_device_hl1250 *hl1250 = (gx_device_hl1250 *) pdev;
++    hl1250_econo_t econo_mode = hl1250->econo_mode;
++    hl1250_paper_t paper_type = hl1250->paper_type;
++    hl1250_tray_t source_tray = hl1250->source_tray;
++    static const char * const onoff[2] = { "OFF", "ON" };
++    static const char * const papertypes[5] =
++	{ "REGULAR", "THIN", "THICK", "THICK2", "TRANSPARENCY" };
++
++    tray_pjl = "AUTO";
++    tray_pcl = "";
++    switch (source_tray) {
++	case TRAY_DUAL:
++	    tray_pcl = "\033&l0H";
++	    break;
++	case TRAY_UPPER:
++	    tray_pjl = "TRAY1";
++	    tray_pcl = "\033&l1H";
++	    break;
++	case TRAY_LOWER:
++	    tray_pjl = "TRAY2";
++	    tray_pcl = "\033&l5H";
++	    break;
++	case TRAY_MANUAL:
++	    tray_pcl = "\033&l2H";
++	    break;
++	default:
++	    break;
++    }
++    if (pdev->PageCount == 0) {
++	/* initialize printer */
++	fputs(UEL, prn_stream);
++	fputs("@PJL \r\n", prn_stream);
++	fprintf(prn_stream, "@PJL JOB NAME=\"%s\"\r\n", PJL_JOB_NAME);
++	fprintf(prn_stream, "@PJL SET ECONOMODE=%s\n", onoff[econo_mode != 0]);
++	if (econo_mode)
++	    fprintf(prn_stream, "@PJL SET ECONOLEVEL=%d\n", 3 - (int)econo_mode);
++	fprintf(prn_stream, "@PJL SET MEDIATYPE=%s\n", papertypes[paper_type]);
++	fprintf(prn_stream, "@PJL SET SOURCETRAY=%s\n", tray_pjl);
++	fprintf(prn_stream, "@PJL SET RESOLUTION=%d\n", y_dpi);
++	fprintf(prn_stream, "@PJL SET RAS1200MODE=%s\n", onoff[x_dpi == 1200]);
++
++	fputs("@PJL ENTER LANGUAGE=PCL\n", prn_stream);
++    }
++    if (x_dpi != 1200) {
++	char page_init[100];
++
++	/* We get the printer to translate the coordinate system for us.
++	   It seems the HL-1250 needs a slightly different translation
++	   (-120, 0) compared to the one in the ljet4 driver (-180, 36)
++	   (X, Y coordinates here are specified in 1/720-inch units).  */
++
++	sprintf(page_init, "\033&l-120U\033*r0F\033&u%dD%s", y_dpi, tray_pcl);
++	return dljet_mono_print_page_copies(pdev, prn_stream, num_copies,
++					    y_dpi, PCL_LJ4_FEATURES, page_init);
++    }
++    return hl1250_print_1200dpi(pdev, prn_stream, num_copies, tray_pcl);
++}
++
++private int
++hl1250_put_param_int(gs_param_list * plist, gs_param_name pname,
++		     int *pvalue, int minval, int maxval, int ecode)
++{
++    int code, value;
++
++    code = param_read_int(plist, pname, &value);
++    switch (code) {
++	case 0:
++	    if (value < minval || value > maxval)
++		param_signal_error(plist, pname, gs_error_rangecheck);
++	    *pvalue = value;
++	    return (ecode < 0 ? ecode : 1);
++	case 1:
++	    return ecode;
++	default:
++	    return code;
++    }
++}
++
++private int
++hl1250_get_params(gx_device * pdev, gs_param_list * plist)
++{
++    gx_device_hl1250 *hl1250 = (gx_device_hl1250 *) pdev;
++    int code, val;
++
++    code = gdev_prn_get_params(pdev, plist);
++    if (code < 0)
++	return code;
++    val = hl1250->econo_mode;
++    code = param_write_int(plist, "EconoMode", &val);
++    if (code < 0)
++	return code;
++    val = hl1250->paper_type;
++    code = param_write_int(plist, "PaperType", &val);
++    if (code < 0)
++	return code;
++    val = hl1250->source_tray;
++    code = param_write_int(plist, "SourceTray", &val);
++    return code;
++}
++
++private int
++hl1250_put_params(gx_device * pdev, gs_param_list * plist)
++{
++    int code = 0;
++    gx_device_hl1250 *hl1250 = (gx_device_hl1250 *) pdev;
++    int econo_mode = hl1250->econo_mode;
++    int paper_type = hl1250->paper_type;
++    int source_tray = hl1250->source_tray;
++
++    code = hl1250_put_param_int(plist, "EconoMode", &econo_mode,
++				ECONO_OFF, ECONO_50, code);
++    code = hl1250_put_param_int(plist, "PaperType", &paper_type,
++				PTYPE_PLAIN, PTYPE_TRANS, code);
++    code = hl1250_put_param_int(plist, "SourceTray", &source_tray,
++				TRAY_AUTO, TRAY_MANUAL, code);
++    if (code < 0)
++	return code;
++    code = gdev_prn_put_params(pdev, plist);
++    if (code < 0)
++	return code;
++    hl1250->econo_mode = econo_mode;
++    hl1250->paper_type = paper_type;
++    hl1250->source_tray = source_tray;
++    return 0;
++}
+



More information about the Pkg-gs-devel mailing list