Re: [Gnome-print] First draft of new encoding routines



Scott Gifford <sgifford@tir.com> writes:

> Lauris Kaplinski <lauris@ximian.com> writes:
> 
> > On 14 Jun 2001 19:14:55 -0400, Scott Gifford wrote:
> > > Chema Celorio <chema@ximian.com> writes:
> > > > We want to patch gnome-print-ps2.c, the gnome-print-ps.c driver is the
> > > > "legacy" one and is there mostly for testing.
> > > 
> > > I thought so, and even started the patch, but when I ran "testprint"
> > > it didn't use that.  Do I need to pass a flag to configure to make it
> > > use gnome-print-ps2?
> > 
> > Ah, unless you install gnome-print, there are no printer description 
> > files, so default ps driver will be used.
> > Once you either install your gnome-print, or copy profiles manually to
> > $prefix/share/gnome-print/VERSION, ps2 will be used instead of ps.
> 
> Thanks for the tip.  Here's a patch against gnome-print-ps2.c; you'll
> want to apply my first patch, then this one on top of it.  In my next
> iteration, I'll combine everything into one patch.
> 
> It has basic support for LanguageLevel1 printing, since it was pretty
> easy to do; it only includes the gnomeprintimage function if it's
> needed; and it tries to make proper use of the DSC Resource tags.
> 
> Again, all feedback will be appreciated.
> 
> ----ScottG.

As usual, I forgot the attachment.  :-)

--- gnome-print-orig/libgnomeprint/gnome-print-ps2.c	Tue May 29 22:46:19 2001
+++ gnome-print/libgnomeprint/gnome-print-ps2.c	Thu Jun 14 23:44:07 2001
@@ -35,6 +35,8 @@
 #define debug(section,str) if (FALSE) printf ("%s:%d (%s) %s\n", __FILE__, __LINE__, __FUNCTION__, str); 
 	
 #include "config.h"
+#include "filter.h"
+
 #include <math.h>
 #include <string.h>
 #include <time.h>
@@ -101,6 +103,8 @@
 	gint gsave_level;
 	gint ps_level;
 
+        gint used_image;
+  
 	FILE *buf;
 
 	ArtDRect bbox;
@@ -125,6 +129,8 @@
 static gint gnome_print_ps2_rgbimage (GnomePrintContext *pc, const char *data, gint width, gint height, gint rowstride);
 static gint gnome_print_ps2_beginpage (GnomePrintContext *pc, const char *name);
 static gint gnome_print_ps2_showpage (GnomePrintContext *pc);
+static gint gnome_print_ps2_addresource_gnomeprintimage(GnomePrintContext *pc);
+
 static gint gnome_print_ps2_close (GnomePrintContext *pc);
 
 static gint gp_ps2_set_color (GnomePrintContext *pc);
@@ -201,9 +207,11 @@
 	ps2->ps_level = 2;
 	
 	ps2->gsave_level = 0;
-
+        
 	ps2->fonts = NULL;
 
+        ps2->used_image = 0;
+        
 	ps2->private_font = NULL;
 	ps2->private_font_flag = GP_GC_FLAG_UNSET;
 	ps2->private_color_flag = GP_GC_FLAG_UNSET;
@@ -215,6 +223,8 @@
 	/* We empty bbox here, as the real thing has to be filled in ::new */
 	ps2->bbox.x0 = ps2->bbox.y0 = 0.0;
 	ps2->bbox.x1 = ps2->bbox.y1 = 0.0;
+
+        filter_register_all();
 }
 
 static void
@@ -603,11 +613,18 @@
 			gnome_print_context_fprintf (pc, "%%%%+ font %s" EOL, f->encodedname);
 		}
 	}
+        if (ps2->used_image && (ps2->ps_level > 1) )
+        {
+          /* %%DocumentSuppliedResources: */
+          gnome_print_context_fprintf(pc,"%%%%+ procset gnome-printimage-procs-%s" EOL, VERSION);
+        }
+        
 	g_free (date);
 	gnome_print_context_fprintf (pc, "%%%%EndComments" EOL);
 	/* Prolog */
 	gnome_print_context_fprintf (pc, "%%%%BeginProlog" EOL);
 	/* Abbreviations */
+
 	gnome_print_context_fprintf (pc, "%%%%BeginResource: procset gnome-print-procs-%s" EOL, VERSION);
 	gnome_print_context_fprintf (pc, "/|/def load def/,/load load" EOL);
 	gnome_print_context_fprintf (pc, "|/n/newpath , |/m/moveto , |/l/lineto , |/c/curveto ," EOL);
@@ -620,7 +637,11 @@
 	gnome_print_context_fprintf (pc, "|/SP/showpage , |/p/pop , |/EX/exch , |/DF/definefont , |" EOL);
 	gnome_print_context_fprintf (pc, "/F {scalefont setfont} def" EOL);
 	gnome_print_context_fprintf (pc, "%%%%EndResource" EOL);
-	gnome_print_context_fprintf (pc, "%%%%EndProlog" EOL);
+
+        if (ps2->used_image && (ps2->ps_level > 1) )
+          gnome_print_ps2_addresource_gnomeprintimage(pc);
+        
+        gnome_print_context_fprintf (pc, "%%%%EndProlog" EOL);
 
 	/* Prolog */
 	gnome_print_context_fprintf (pc, "%%%%BeginSetup" EOL);
@@ -1001,15 +1022,15 @@
 {
 	GnomePrintPs2 *ps2;
 	const gdouble *ctm;
-	gint ret, r, c;
-
-#if 0
-	gchar *hex_data;
-	gint data_size, data_size_real;
-#endif
-
+	gint ret, r;
+        Filter *filt;
+        int outbytes;
+        char *outbuf;
+        
+        
 	ps2 = GNOME_PRINT_PS2 (pc);
-
+        ps2->used_image = 1;
+        
 	if (!ps2->pages || ps2->pages->shown) {
 		ret = gnome_print_beginpage (pc, "Unnamed");
 		g_return_val_if_fail (ret == GNOME_PRINT_OK, ret);
@@ -1025,14 +1046,9 @@
 	*       for Level 2 and 3 printers...
 	*/
 
-#if 0
-        if (ps2->ps_level == 1);
-#else
-	if (TRUE) {
-#endif
+        if (ps2->ps_level == 1)
+        {
 		/* Level 1 image commands */
-			gchar *hex;
-		gint hex_size;
 
 		ret = gp_ps2_fprintf (ps2, "/buf %d string def" EOL "%d %d 8" EOL, w * ch, w, h);
 		ret += gp_ps2_fprintf (ps2, "[%d 0 0 %d 0 %d]" EOL, w, -h, h);
@@ -1043,108 +1059,40 @@
 		} else {
 			ret += gp_ps2_fprintf (ps2, "false %d colorimage" EOL, ch);
 		}
-
-		hex = g_new (gchar, gnome_print_encode_hex_wcs (w * ch));
-
-	       /*
-	        * MRS - Keep lines < 255 characters long for DSC conformance. Since
-		*       images will likely be wider than 127 grayscale pixels, we
-		*       need to do this...  We wrap every 80 characters to make it
-		*       easier to "more" the files if we have to...
-		*/
-
-		for (r = 0; r < h; r++) {
-			hex_size = gnome_print_encode_hex (px + r * rowstride, hex, w * ch);
-			fwrite (hex, sizeof (gchar), hex_size, ps2->buf);
-			gp_ps2_fprintf (ps2, EOL);
-		}
-
-		g_free (hex);
+                filt = filter_init("ASCIIHexEncode");
 	} else {
 		/* Level 2/3 image commands */
-		gchar *a85;
-		gint a85_size;
-
-		ret += gp_ps2_fprintf (ps2, "[%d 0 0 %d 0 %d]" EOL, w, -h, h);
-		ret += gp_ps2_fprintf (ps2, "{ currentfile buf reada85string pop }" EOL);
 
 		if (ch == 1)
 			ret = gp_ps2_fprintf (ps2, "/DeviceGray setcolorspace" EOL);
 		else
 			ret = gp_ps2_fprintf (ps2, "/DeviceRGB setcolorspace" EOL);
-
-		ret += gp_ps2_fprintf (ps2, "<<"
-							"/ImageType 1"
-							"/Width %d"
-							"/Height %d"
-							"/BitsPerComponent 8"
-							"/ImageMatrix[%d 0 0 %d 0 %d]"
-							"/Decode[%s]"
-							"/Interpolate true"
-							"/DataSource currentfile/ASCII85Decode filter"
-							">>image" EOL,
-						    w, h,
-						    w, -h, h,
-						    ch == 1 ? "0 1" : "0 1 0 1 0 1");
-
-		a85 = g_new (gchar, gnome_print_encode_ascii85_wcs (w * ch));
-
-	       /*
-	        * MRS - Keep lines < 255 characters long for DSC conformance. Since
-		*       images will likely be wider than ~200 grayscale pixels, we
-		*       need to do this...  We wrap every 80 characters to make it
-		*       easier to "more" the files if we have to...
-		*/
-
-		for (r = 0; r < h; r++) {
-			a85_size = gnome_print_encode_ascii85 (px + r * rowstride, a85, w * ch);
-
-			for (c = 0; c < a85_size; c += 80) {
-				if ((c + 80) < a85_size)
-					fwrite (a85 + c, sizeof (gchar), 80, ps2->buf);
-				else
-					fwrite (a85 + c, sizeof (gchar), a85_size - c, ps2->buf);
-
-				gp_ps2_fprintf (ps2, EOL);
-			}
-		}
-
-		/* End the ASCII 85 stream with "~>"... */
-                gp_ps2_fprintf (ps2, "~>" EOL);
-
-		g_free (a85);
-	}
+                
+                ret += gp_ps2_fprintf(ps2, "%d %d 8 %d" EOL, w, h, ch);
+                ret += gp_ps2_fprintf(ps2,"currentfile" EOL);
+
+                if ( (filt = filter_init("multi")) == NULL)
+                  return -1;
+                if (filter_opt_setstr(filt,"add","RunLengthEncode") < 0)
+                  return -1;
+                if (filter_opt_setstr(filt,"add","ASCII85Encode") < 0)
+                  return -1;
+
+                ret += gp_ps2_fprintf(ps2,"  /%s filter " EOL "   /%s filter" EOL, "ASCII85Decode", "RunLengthDecode");
+                ret += gp_ps2_fprintf(ps2, "gnomeprintimage" EOL);
+	}
+
+        for (r = 0; r < h; r++) {
+          filter(filt,0,w*ch,px+r*rowstride,&outbytes,&outbuf);
+          fwrite (outbuf, sizeof (gchar), outbytes, ps2->buf);
+        }
+        filter(filt,1,0,"",&outbytes,&outbuf);
+        fwrite (outbuf, sizeof (gchar), outbytes, ps2->buf);
+        filter_free(filt);
 
 	gp_ps2_fprintf (ps2, "Q" EOL);
 
 	return 0;
-#if 0
-	/* Image commands */
-	ret = gp_ps2_fprintf (ps2, "/buf %d string def" EOL "%d %d 8" EOL, width * bytes_per_pixel, width, height);
-
-	ret += gp_ps2_fprintf (ps2, "[%d 0 0 %d 0 %d]" EOL, width, -height, height);
-
-	ret += gp_ps2_fprintf (ps2, "{ currentfile buf readhexstring pop }\n");
-
-	if (bytes_per_pixel == 1) {
-		ret += gp_ps2_fprintf (ps2, "image" EOL);
-	} else if (bytes_per_pixel == 3) {
-		ret += gp_ps2_fprintf (ps2, "false %d colorimage" EOL, bytes_per_pixel);
-	}
-
-	data_size = width * bytes_per_pixel;
-	hex_data = g_new (gchar, gnome_print_encode_hex_wcs (data_size));
-
-	for (r = 0; r < height; r++) {
-		data_size_real = gnome_print_encode_hex (data + r * rowstride, hex_data, data_size);
-		gnome_print_context_write_file (pc, hex_data, data_size_real);
-		gp_ps2_fprintf (ps2, EOL);
-	}
-
-	g_free (hex_data);
-
-	return 0;
-#endif
 }
 
 
@@ -1439,4 +1387,50 @@
 }
 #endif
 
+static gint gnome_print_ps2_addresource_gnomeprintimage(GnomePrintContext *pc)
+{
+  int ret = 0;
+  
+  ret += gnome_print_context_fprintf(pc,"%%BeginResource: procset gnome-printimage-procs-%s" EOL, VERSION);
+  ret += gnome_print_context_fprintf(pc, "%s","
+/gnomeprintimage { % def
+  /decodedfile exch def  % def /decodedfile to the first thing on the stack
+
+  % Create a string of the appropriate blocksize
+  exch 
+  dup dup 8192 exch idiv mul  % (8192 div top) * top (appropriate blocksize)
+  /buf exch string def        % Create string of blocksize, def to /buf
+  exch
+
+  % Build an appropriate matrix.
+  4 copy    % Create a working set
+  pop pop   % Ignore numbers besides dimensions
+  0 exch
+  0 exch
+  dup
+  -1 mul
+  exch
+  0 exch
+
+  6 array
+  astore
+
+  exch      % Push the matrix into its place.
+
+  % Here's the code fragment
+  { decodedfile buf readstring pop }
+
+  % Finish out the parameters to colorimage
+  exch
+  false
+  exch
+
+  % And we're good!
+  colorimage
+} def
+%% EndResource
+");
+
+  return ret;
+}
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]