From 12cfc158942ea17e31850f74c4e0ee1ea3b01905 Mon Sep 17 00:00:00 2001
From: Jussi Pakkanen <jpakkane@gmail.com>
Date: Mon, 17 Sep 2012 20:24:20 +0300
Subject: [PATCH 1/1] Overprint 1-bit images using ImageMasks.

---
 Scribus/scribus/pdflib_core.cpp |   13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/Scribus/scribus/pdflib_core.cpp b/Scribus/scribus/pdflib_core.cpp
index ce4a448..ee4a982 100644
--- a/Scribus/scribus/pdflib_core.cpp
+++ b/Scribus/scribus/pdflib_core.cpp
@@ -9855,10 +9855,18 @@ bool PDFLibCore::PDF_Image(PageItem* c, const QString& fn, double sx, double sy,
 			int bytesWritten = 0;
 			// Fixme: outType variable should be set directly in the if/else maze above.
 			ColorSpaceEnum outType;
+			// Overprint does not work for images in general, but it does work
+			// for 1 bit images if they are drawn as image masks.
+			// PDF 1.3 spec, pages 197 and 257
+			bool overprint1bitImage = false;
 			if (img.imgInfo.colorspace == ColorSpaceMonochrome && c->effectsInUse.count() == 0)
 				outType = ColorSpaceMonochrome;
 			else
 				outType = getOutputType(exportToGrayscale, exportToCMYK);
+			if(outType == ColorSpaceMonochrome
+				&& img.imgInfo.colorspace == ColorSpaceMonochrome &&
+				c->overprint())
+				overprint1bitImage = true;
 			if ((outType != ColorSpaceMonochrome) && (doc.HasCMS) && (Options.UseProfiles2))
 			{
 				PutDoc("/ColorSpace "+ICCProfiles[profInUse].ICCArray+"\n");
@@ -9874,6 +9882,11 @@ bool PDFLibCore::PDF_Image(PageItem* c, const QString& fn, double sx, double sy,
 				switch (outType)
 				{
 					case ColorSpaceMonochrome :
+						if (overprint1bitImage)
+							PutDoc("/ImageMask true\n");
+						else
+							PutDoc("/ColorSpace /DeviceGray\n");
+						break;
 					case ColorSpaceGray : PutDoc("/ColorSpace /DeviceGray\n"); break;
 					case ColorSpaceCMYK : PutDoc("/ColorSpace /DeviceCMYK\n"); break;
 					default : PutDoc("/ColorSpace /DeviceRGB\n"); break;
-- 
1.7.10.4

