Blame SOURCES/paps-cups.patch

78523c
diff -pruN paps-0.6.8.orig/configure.in paps-0.6.8/configure.in
78523c
--- paps-0.6.8.orig/configure.in	2007-01-19 20:06:10.000000000 +0900
78523c
+++ paps-0.6.8/configure.in	2008-11-07 08:21:19.000000000 +0900
78523c
@@ -7,6 +7,19 @@ AC_LANG_C
78523c
 AC_PROG_CC
78523c
 AM_PROG_LIBTOOL
78523c
 
78523c
+dnl ======================================================
78523c
+dnl check for CUPS
78523c
+dnl ======================================================
78523c
+AC_PATH_PROG(CUPS_CONFIG, cups-config, no)
78523c
+if test "$CUPS_CONFIG" = "no"; then
78523c
+  AC_MSG_ERROR([Please install cups development packages/files])
78523c
+fi
78523c
+CUPS_CFLAGS=`$CUPS_CONFIG --cflags | sed -e 's/-O[0-9]*//' -e 's/-m[^\t]*//g'`
78523c
+CUPS_LIBS=`$CUPS_CONFIG --libs`
78523c
+
78523c
+AC_SUBST(CUPS_CFLAGS)
78523c
+AC_SUBST(CUPS_LIBS)
78523c
+
78523c
 DX_HTML_FEATURE(ON)
78523c
 DX_CHM_FEATURE(OFF)
78523c
 DX_CHI_FEATURE(OFF)
78523c
diff -pruN paps-0.6.8.orig/src/Makefile.am paps-0.6.8/src/Makefile.am
78523c
--- paps-0.6.8.orig/src/Makefile.am	2008-11-07 08:21:05.000000000 +0900
78523c
+++ paps-0.6.8/src/Makefile.am	2008-11-07 08:21:19.000000000 +0900
78523c
@@ -5,10 +5,10 @@ libpapsinc_HEADERS = libpaps.h
78523c
 libpapsincdir = $(includedir)
78523c
 
78523c
 bin_PROGRAMS = paps
78523c
-paps_CFLAGS  = -Wall 
78523c
+paps_CFLAGS  = -Wall $(CUPS_CFLAGS)
78523c
 paps_SOURCES = paps.c
78523c
 paps_LDADD = $(lib_LTLIBRARIES) $(all_libraries)
78523c
-paps_LDFLAGS = `pkg-config --libs pangoft2`
78523c
+paps_LDFLAGS = `pkg-config --libs pangoft2` $(CUPS_LIBS)
78523c
 paps_DEPENDENCIES = $(lib_LTLIBRARIES)
78523c
 
78523c
 EXTRA_DIST = test_libpaps.c paps.1
78523c
diff -pruN paps-0.6.8.orig/src/paps.c paps-0.6.8/src/paps.c
78523c
--- paps-0.6.8.orig/src/paps.c	2008-11-07 08:21:05.000000000 +0900
78523c
+++ paps-0.6.8/src/paps.c	2008-11-07 08:26:28.000000000 +0900
78523c
@@ -31,6 +31,8 @@
78523c
 #include <string.h>
78523c
 #include <time.h>
78523c
 #include <locale.h>
78523c
+#include <cups/cups.h>
78523c
+#include <cups/ppd.h>
78523c
 
78523c
 #define BUFSIZE 1024
78523c
 #define DEFAULT_FONT_FAMILY	"Monospace"
78523c
@@ -86,9 +88,11 @@ typedef struct {
78523c
   gboolean do_wordwrap;
78523c
   gboolean do_use_markup;
78523c
   gboolean do_stretch_chars;
78523c
+  gboolean cups_mode;
78523c
   PangoDirection pango_dir;
78523c
   gchar *filename;
78523c
   gchar *header_font_desc;
78523c
+  gchar *owner;
78523c
   gint lpi;
78523c
   gint cpi;
78523c
 } page_layout_t;
78523c
@@ -320,8 +324,8 @@ int main(int argc, char *argv[])
78523c
   int num_pages = 1;
78523c
   int gutter_width = 40;
78523c
   int total_gutter_width;
78523c
-  int page_width = paper_sizes[0].width;
78523c
-  int page_height = paper_sizes[0].height;
78523c
+  int page_width = -1;
78523c
+  int page_height = -1;
78523c
   int do_tumble = -1;   /* -1 means not initialized */
78523c
   int do_duplex = -1;
78523c
   gchar *paps_header = NULL;
78523c
@@ -331,6 +335,8 @@ int main(int argc, char *argv[])
78523c
   int max_width = 0, w;
78523c
   GIConv cvh = NULL;
78523c
   GOptionGroup *options;
78523c
+  gboolean cups_mode = FALSE;
78523c
+  gchar *page_owner = NULL;
78523c
 
78523c
   /* Set locale from environment. */
78523c
   setlocale(LC_ALL, "");
78523c
@@ -348,6 +354,130 @@ int main(int argc, char *argv[])
78523c
   g_option_context_add_main_entries(ctxt, entries, NULL);
78523c
 #endif
78523c
   
78523c
+  /* check if the process is being invoked as CUPS filter */
78523c
+  G_STMT_START {
78523c
+	gchar *prgname = g_path_get_basename(argv[0]);
78523c
+	cups_option_t *options = NULL;
78523c
+	ppd_file_t *ppd;
78523c
+	ppd_size_t *pagesize;
78523c
+	int num_options;
78523c
+	const char *val;
78523c
+
78523c
+	if (strncmp(prgname, "texttopaps", 10) == 0 ||
78523c
+	    getenv("CUPS_SERVER") != NULL) {
78523c
+		g_set_prgname(prgname);
78523c
+		/* argument format should be job-id user title copies options [file] */
78523c
+		cups_mode = TRUE;
78523c
+		/* set default values */
78523c
+		page_layout.lpi = 6.0L;
78523c
+		page_layout.cpi = 10.0L;
78523c
+		left_margin = 18;
78523c
+		right_margin = 18;
78523c
+		top_margin = 36;
78523c
+		bottom_margin = 36;
78523c
+		page_width = 612;
78523c
+		page_height = 792;
78523c
+		font = g_strdup(MAKE_FONT_NAME ("Courier", DEFAULT_FONT_SIZE));
78523c
+		header_font_desc = g_strdup(MAKE_FONT_NAME ("Courier", HEADER_FONT_SCALE));
78523c
+
78523c
+		if (argc < 6 || argc > 7) {
78523c
+			fprintf(stderr, "ERROR: %s job-id user title copies options [file]\n", prgname);
78523c
+			exit(1);
78523c
+		}
78523c
+		if (argc == 6) {
78523c
+			filename_in = "stdin";
78523c
+			IN = stdin;
78523c
+		} else {
78523c
+			filename_in = argv[6];
78523c
+			if ((IN = fopen(filename_in, "rb")) == NULL) {
78523c
+				fprintf(stderr, "ERROR: unable to open print file -\n");
78523c
+				exit(1);
78523c
+			}
78523c
+		}
78523c
+		title = argv[3];
78523c
+		page_owner = argv[2];
78523c
+		num_options = cupsParseOptions(argv[5], 0, &options);
78523c
+
78523c
+		if ((val = cupsGetOption("prettyprint", num_options, options)) != NULL &&
78523c
+		    g_ascii_strcasecmp(val, "no") &&
78523c
+		    g_ascii_strcasecmp(val, "off") &&
78523c
+		    g_ascii_strcasecmp(val, "false")) {
78523c
+			/* XXX: need to support the keywords highlighting */
78523c
+		}
78523c
+		ppd = ppdOpenFile(getenv("PPD"));
78523c
+		ppdMarkDefaults(ppd);
78523c
+		cupsMarkOptions(ppd, num_options, options);
78523c
+
78523c
+		if ((pagesize = ppdPageSize(ppd, NULL)) != NULL) {
78523c
+			page_width = pagesize->width;
78523c
+			page_height = pagesize->length;
78523c
+			top_margin = pagesize->length - pagesize->top;
78523c
+			bottom_margin = pagesize->bottom;
78523c
+			left_margin = pagesize->left;
78523c
+			right_margin = pagesize->width - pagesize->right;
78523c
+		}
78523c
+
78523c
+		if ((val = cupsGetOption("landscape", num_options, options)) != NULL) {
78523c
+			if (g_ascii_strcasecmp(val, "no") &&
78523c
+			    g_ascii_strcasecmp(val, "off") &&
78523c
+			    g_ascii_strcasecmp(val, "false"))
78523c
+				do_landscape = TRUE;
78523c
+		}
78523c
+		/* XXX: need to support orientation-requested? */
78523c
+		if ((val = cupsGetOption("page-left", num_options, options)) != NULL) {
78523c
+			left_margin = (int)atof(val);
78523c
+		}
78523c
+		if ((val = cupsGetOption("page-right", num_options, options)) != NULL) {
78523c
+			right_margin = (int)atof(val);
78523c
+		}
78523c
+		if ((val = cupsGetOption("page-bottom", num_options, options)) != NULL) {
78523c
+			bottom_margin = (int)atof(val);
78523c
+		}
78523c
+		if ((val = cupsGetOption("page-top", num_options, options)) != NULL) {
78523c
+			top_margin = (int)atof(val);
78523c
+		}
78523c
+		if (ppdIsMarked(ppd, "Duplex", "DuplexNoTumble") ||
78523c
+		    ppdIsMarked(ppd, "Duplex", "DuplexTumble") ||
78523c
+		    ppdIsMarked(ppd, "JCLDuplex", "DuplexNoTumble") ||
78523c
+		    ppdIsMarked(ppd, "JCLDuplex", "DuplexTumble") ||
78523c
+		    ppdIsMarked(ppd, "EFDuplex", "DuplexNoTumble") ||
78523c
+		    ppdIsMarked(ppd, "EFDuplex", "DuplexTumble") ||
78523c
+		    ppdIsMarked(ppd, "KD03Duplex", "DuplexNoTumble") ||
78523c
+		    ppdIsMarked(ppd, "KD03Duplex", "DuplexTumble")) {
78523c
+			do_duplex = TRUE;
78523c
+		}
78523c
+		if ((val = cupsGetOption("wrap", num_options, options)) != NULL) {
78523c
+			do_wordwrap = !g_ascii_strcasecmp(val, "true") ||
78523c
+				      !g_ascii_strcasecmp(val, "on") ||
78523c
+				      !g_ascii_strcasecmp(val, "yes");
78523c
+		}
78523c
+		if ((val = cupsGetOption("columns", num_options, options)) != NULL) {
78523c
+			num_columns = atoi(val);
78523c
+		}
78523c
+		if ((val = cupsGetOption("cpi", num_options, options)) != NULL) {
78523c
+			page_layout.cpi = atof(val);
78523c
+		}
78523c
+		if ((val = cupsGetOption("lpi", num_options, options)) != NULL) {
78523c
+			page_layout.lpi = atof(val);
78523c
+		}
78523c
+		if (getenv("CHARSET") != NULL) {
78523c
+			char *charset = getenv("CHARSET");
78523c
+			/* Map CUPS charset names to real ones.
78523c
+			 * http://cups.org/newsgroups.php?s9797+gcups.general+v9797+T1
78523c
+			 */
78523c
+			if (!g_ascii_strcasecmp(charset, "windows-932")) {
78523c
+				charset = "WINDOWS-31J";
78523c
+			}
78523c
+			if (g_ascii_strcasecmp(charset, "utf-8") &&
78523c
+			    g_ascii_strcasecmp(charset, "utf8")) {
78523c
+				encoding = g_strdup(charset);
78523c
+			}
78523c
+		}
78523c
+	}
78523c
+  } G_STMT_END;
78523c
+
78523c
+  if (!cups_mode) {
78523c
+
78523c
   /* Parse command line */
78523c
   if (!g_option_context_parse(ctxt, &argc, &argv, &error))
78523c
     {
78523c
@@ -374,6 +504,8 @@ int main(int argc, char *argv[])
78523c
       IN = stdin;
78523c
     }
78523c
   title = filename_in;
78523c
+
78523c
+  } /* if (!cups_mode) */
78523c
   
78523c
   paps = paps_new();
78523c
   pango_context = paps_get_pango_context (paps);
78523c
@@ -392,8 +524,10 @@ int main(int argc, char *argv[])
78523c
   pango_context_set_font_description (pango_context, font_description);
78523c
 
78523c
   /* Page layout */
78523c
-  page_width = paper_sizes[(int)paper_type].width;
78523c
-  page_height = paper_sizes[(int)paper_type].height;
78523c
+  if (page_width < 0)
78523c
+    page_width = paper_sizes[(int)paper_type].width;
78523c
+  if (page_height < 0)
78523c
+    page_height = paper_sizes[(int)paper_type].height;
78523c
   
78523c
   if (num_columns == 1)
78523c
     total_gutter_width = 0;
78523c
@@ -456,6 +590,8 @@ int main(int argc, char *argv[])
78523c
   page_layout.pango_dir = pango_dir;
78523c
   page_layout.filename = filename_in;
78523c
   page_layout.header_font_desc = header_font_desc;
78523c
+  page_layout.owner = page_owner;
78523c
+  page_layout.cups_mode = cups_mode;
78523c
 
78523c
   /* calculate x-coordinate scale */
78523c
   if (page_layout.cpi > 0.0L)
78523c
@@ -756,6 +892,12 @@ split_text_into_paragraphs (PangoContext
78523c
           if (wc == (gunichar)-1)
78523c
             {
78523c
               fprintf (stderr, "%s: Invalid character in input\n", g_get_prgname ());
78523c
+              if (page_layout->cups_mode)
78523c
+                {
78523c
+                  /* try to continue parsing texts */
78523c
+                  p = next;
78523c
+                  continue;
78523c
+                }
78523c
               wc = 0;
78523c
             }
78523c
           if (!*p || !wc || wc == '\n' || wc == '\f')
78523c
@@ -925,21 +1067,32 @@ void print_postscript_header(FILE *OUT,
78523c
   int orientation = page_layout->page_width > page_layout->page_height;
78523c
   int bb_page_width = page_layout->page_width;
78523c
   int bb_page_height = page_layout->page_height;
78523c
+  char *owner = NULL;
78523c
   
78523c
   /* Keep bounding box non-rotated to make ggv happy */
78523c
-  if (orientation)
78523c
+  /* ensure the correct bounding box for CUPS */
78523c
+  if (orientation && !page_layout->cups_mode)
78523c
     {
78523c
       int tmp = bb_page_width;
78523c
       bb_page_width = bb_page_height;
78523c
       bb_page_height = tmp;
78523c
     }
78523c
   
78523c
+  if (page_layout->owner)
78523c
+    {
78523c
+      owner = g_strdup_printf("%%%%For: %s\n", page_layout->owner);
78523c
+    }
78523c
+  else
78523c
+    {
78523c
+      owner = g_strdup("");
78523c
+    }
78523c
   fprintf(OUT,
78523c
           "%%!PS-Adobe-3.0\n"
78523c
+	  "%s"
78523c
           "%%%%Title: %s\n"
78523c
           "%%%%Creator: paps version 0.6.7 by Dov Grobgeld\n"
78523c
           "%%%%Pages: (atend)\n"
78523c
-          "%%%%BoundingBox: 0 0 %d %d\n"
78523c
+          "%%%%BoundingBox: 0 0 %d %d\n%s"
78523c
           "%%%%BeginProlog\n"
78523c
           "%%%%Orientation: %s\n"
78523c
           "/papsdict 1 dict def\n"
78523c
@@ -961,7 +1114,7 @@ void print_postscript_header(FILE *OUT,
78523c
           "             pagewidth\n"
78523c
           "             /pagewidth pageheight def\n"
78523c
           "             /pageheight exch def\n"
78523c
-          "             /orientation 3 def\n"
78523c
+          "             /orientation %d def\n"
78523c
           "         } if\n"
78523c
           "         2 dict\n"
78523c
           "         dup /PageSize [pagewidth pageheight] put\n"
78523c
@@ -986,11 +1139,21 @@ void print_postscript_header(FILE *OUT,
78523c
           "  90 rotate\n"
78523c
           "  0 pageheight neg translate\n"
78523c
           "} def\n",
78523c
+	  /*
78523c
+	   * Put %%cupsRotation tag to prevent the rotation in pstops.
78523c
+	   * This breaks paps's behavior to make it in landscape say.
78523c
+	   * (RH#222137)
78523c
+	   */
78523c
+	  (page_layout->cups_mode ? "%cupsRotation: 0\n" : ""),
78523c
           title,
78523c
           bb_page_width,
78523c
           bb_page_height,
78523c
-          orientation_names[orientation]
78523c
+          owner,
78523c
+          orientation_names[orientation],
78523c
+          /* For landscape, rotate page to portrait orientation for CUPS (RH#222137) */
78523c
+          page_layout->cups_mode ? 2 : 3
78523c
           );
78523c
+  g_free(owner);
78523c
   
78523c
   fprintf(OUT,
78523c
           "%% User settings\n"