net-print/cups-filters: fix issues when removing ghostscript/ijs

When we remove ghostscript-based filters, CUPS complains about a missing
'gstoraster' filter, even if it doesn't need it. The fix is to drop the
gstoraster rules from the MIME conversion rules. Patch accepted here:

  https://bugs.linuxfoundation.org/show_bug.cgi?id=1346

Also, ijs [1] is part of the ghostscript package, so it needs to be dropped
when we drop ghostscript (i.e., USE="-postscript"). Patch accepted here:

  https://bugs.linuxfoundation.org/show_bug.cgi?id=1345

[1] IJS derives from HPIJS (HP InkJet Server) but is not HP-specific.
    According to its README, it is "a protocol for transmission of
    raster page images."

BUG=chrome-os-partner:47758, chrome-os-partner:49267
TEST=check that cups-filters builds, deploys, and doesn't complain in syslog

Change-Id: Ic1370e816df2fbf103a983b01e23298d6cf8cb1a
Signed-off-by: Brian Norris <briannorris@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/330188
Reviewed-by: Mike Frysinger <vapier@chromium.org>
diff --git a/net-print/cups-filters/cups-filters-1.8.2.ebuild b/net-print/cups-filters/cups-filters-1.8.2.ebuild
index 73d8e9b..f88c4f9 100644
--- a/net-print/cups-filters/cups-filters-1.8.2.ebuild
+++ b/net-print/cups-filters/cups-filters-1.8.2.ebuild
@@ -49,6 +49,8 @@
 src_prepare() {
 	base_src_prepare
 	sed -e "s/AM_CONFIG_HEADER/AC_CONFIG_HEADERS/" -i configure.ac || die
+	epatch "${FILESDIR}/${PN}-1.8.2-disable-ijs.patch"
+	epatch "${FILESDIR}/${PN}-1.8.2-gstoraster.patch"
 	eautoreconf
 }
 
@@ -60,6 +62,7 @@
 		$(use_enable static-libs static) \
 		$(use_enable foomatic) \
 		$(use_enable postscript ghostscript) \
+		$(use_enable postscript ijs) \
 		--with-fontdir="fonts/conf.avail" \
 		--with-pdftops=pdftops \
 		--enable-imagefilters \
diff --git a/net-print/cups-filters/files/cups-filters-1.8.2-disable-ijs.patch b/net-print/cups-filters/files/cups-filters-1.8.2-disable-ijs.patch
new file mode 100644
index 0000000..30259d9
--- /dev/null
+++ b/net-print/cups-filters/files/cups-filters-1.8.2-disable-ijs.patch
@@ -0,0 +1,72 @@
+ijs is part of the ghostscript package, so it needs to be dropped when we drop
+ghostscript (i.e., USE="-postscript"). Patch accepted here:
+
+https://bugs.linuxfoundation.org/show_bug.cgi?id=1345
+
+---
+=== modified file 'Makefile.am'
+--- Makefile.am	2016-02-10 15:16:33 +0000
++++ Makefile.am	2016-03-02 20:46:26 +0000
+@@ -490,7 +490,6 @@
+ 	bannertopdf \
+ 	commandtoescpx \
+ 	commandtopclx \
+-	pdftoijs \
+ 	sys5ippprinter \
+ 	pdftops \
+ 	pdftoraster \
+@@ -499,6 +498,10 @@
+ 	texttopdf \
+ 	urftopdf \
+ 	rastertopdf
++if ENABLE_IJS
++pkgfilter_PROGRAMS += \
++	pdftoijs
++endif
+ if ENABLE_GHOSTSCRIPT
+ pkgfilter_PROGRAMS += \
+ 	gstoraster
+@@ -846,9 +849,12 @@
+ 	ppd/Fuji_Xerox-DocuPrint_CM305_df-PDF.ppd \
+ 	ppd/Generic-PDF_Printer-PDF.ppd \
+ 	ppd/HP-Color_LaserJet_CM3530_MFP-PDF.ppd \
+-	ppd/HP-PhotoSmart_Pro_B8300-hpijs-pdftoijs.ppd \
+ 	ppd/Ricoh-PDF_Printer-PDF.ppd \
+ 	ppd/textonly.ppd
++if ENABLE_IJS
++ppd_DATA += \
++	ppd/HP-PhotoSmart_Pro_B8300-hpijs-pdftoijs.ppd
++endif
+ if ENABLE_GHOSTSCRIPT
+ ppd_DATA += \
+ 	ppd/pxlcolor.ppd \
+
+=== modified file 'configure.ac'
+--- configure.ac	2016-02-11 13:59:52 +0000
++++ configure.ac	2016-03-02 21:18:05 +0000
+@@ -443,7 +443,7 @@
+ ])
+ PKG_CHECK_MODULES([FREETYPE], [freetype2], [AC_DEFINE([HAVE_FREETYPE_H], [1], [Have FreeType2 include files])])
+ PKG_CHECK_MODULES([FONTCONFIG], [fontconfig >= 2.0.0])
+-PKG_CHECK_MODULES([IJS], [ijs])
++PKG_CHECK_MODULES([IJS], [ijs], [have_ijs=yes], [have_ijs=no])
+ PKG_CHECK_MODULES([POPPLER], [poppler >= 0.18])
+ PKG_CHECK_MODULES([ZLIB], [zlib])
+ AC_DEFINE([HAVE_LIBZ], [], [Define that we use zlib])
+@@ -489,6 +489,15 @@
+ 	[enable_ghostscript="$enableval"],
+ 	[enable_ghostscript=yes]
+ )
++AC_ARG_ENABLE([ijs],
++	[AS_HELP_STRING([--disable-ijs], [Disable filters using IJS.])],
++	[enable_ijs="$enableval"],
++	[enable_ijs=yes]
++)
++AS_IF([test "x$enable_ijs" = "xyes" -a "x$have_ijs" != "xyes"], [
++       AC_MSG_ERROR([IJS not found, but requested.])
++])
++AM_CONDITIONAL(ENABLE_IJS, test "x$enable_ijs" = "xyes")
+ AC_ARG_WITH([pdftops],
+ 	[AS_HELP_STRING([--with-pdftops=value], [Set which pdftops to use (gs,pdftops,pdftocairo,acroread,hybrid).])],
+ 	[with_pdftops="$withval"],
+
diff --git a/net-print/cups-filters/files/cups-filters-1.8.2-gstoraster.patch b/net-print/cups-filters/files/cups-filters-1.8.2-gstoraster.patch
new file mode 100644
index 0000000..6c246a1
--- /dev/null
+++ b/net-print/cups-filters/files/cups-filters-1.8.2-gstoraster.patch
@@ -0,0 +1,72 @@
+When we remove ghostscript-based filters, CUPS complains about a missing
+'gstoraster' filter, even if it doesn't need it. The fix is to drop the
+gstoraster rules from the MIME conversion rules. Patch accepted here:
+
+https://bugs.linuxfoundation.org/show_bug.cgi?id=1346
+
+---
+=== modified file 'COPYING'
+--- COPYING	2016-01-21 14:50:23 +0000
++++ COPYING	2016-03-03 02:35:23 +0000
+@@ -103,7 +103,7 @@
+   1993-2007, Easy Software Products
+ License: GPL-2
+ 
+-Files: mime/cupsfilters.convs*
++Files: mime/cupsfilters*.convs*
+ Copyright: 2007-2011, Apple Inc
+   1997-2007, Easy Software Products
+   2012-2016, Till Kamppeter
+
+=== modified file 'Makefile.am'
+--- Makefile.am	2016-03-03 02:39:23 +0000
++++ Makefile.am	2016-03-03 02:44:15 +0000
+@@ -292,6 +292,10 @@
+ pkgmime_DATA = \
+ 	mime/cupsfilters.convs \
+ 	mime/cupsfilters.types
++if ENABLE_GHOSTSCRIPT
++pkgmime_DATA += \
++	mime/cupsfilters-ghostscript.convs
++endif
+ if ENABLE_BRAILLE
+ pkgmime_DATA += \
+ 	mime/braille.convs \
+
+=== added file 'mime/cupsfilters-ghostscript.convs'
+--- mime/cupsfilters-ghostscript.convs	1970-01-01 00:00:00 +0000
++++ mime/cupsfilters-ghostscript.convs	2016-03-03 02:31:30 +0000
+@@ -0,0 +1,19 @@
++#
++#   MIME conversions file for OpenPrinting CUPS Filters.
++#
++#   Copyright 2007-2011 by Apple Inc.
++#   Copyright 1997-2007 by Easy Software Products.
++#   Copyright 2012-2016 by Till Kamppeter.
++#
++#   These coded instructions, statements, and computer programs are the
++#   property of Apple Inc. and are protected by Federal copyright
++#   law.  Distribution and use rights are outlined in the file "COPYING"
++#   which should have been included with this file.
++#
++
++#
++# Ghostscript-based filters...
++#
++
++application/vnd.cups-pdf	application/vnd.cups-raster	99	gstoraster
++application/vnd.cups-postscript	application/vnd.cups-raster	175	gstoraster
+
+=== modified file 'mime/cupsfilters.convs'
+--- mime/cupsfilters.convs	2016-01-21 14:50:23 +0000
++++ mime/cupsfilters.convs	2016-03-03 02:35:59 +0000
+@@ -83,8 +83,6 @@
+ # Raster filters...
+ #
+ 
+-application/vnd.cups-pdf	application/vnd.cups-raster	99	gstoraster
+-application/vnd.cups-postscript	application/vnd.cups-raster	175	gstoraster
+ application/vnd.cups-pdf	application/vnd.cups-raster	100	pdftoraster
+ image/gif			application/vnd.cups-raster	100	imagetoraster
+ image/png			application/vnd.cups-raster	100	imagetoraster
+