Automatic text overprint patch

View: New views
3 Messages — Rating Filter:   Alert me  

Automatic text overprint patch

by MatthiasR :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

I've implemented a small patch which allows to automatically set the
overprint state for text in pdf output. This is useful when text and
background colors are printed on different printing plates because it
ensures that no white spaces are visible if the printing plates are not
positioned perfectly.

See also: http://www.nabble.com/Overprint-Black-Text-td9852903.html

Feel free to review or integrate it into fop trunk if it's for any use
to you.

Usage:
foUserAgent.getRendererOptions().put(PDFConfigurationConstants.KEY_ENABLE_AUTO_OVERPRINT,
Boolean.TRUE);

Regards,
Matthias Reischenbacher



__________ Information from ESET NOD32 Antivirus, version of virus signature database 4470 (20090930) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com


Index: src/java/org/apache/fop/pdf/PDFGState.java
===================================================================
--- src/java/org/apache/fop/pdf/PDFGState.java (revision 820021)
+++ src/java/org/apache/fop/pdf/PDFGState.java (working copy)
@@ -153,6 +153,9 @@
         sb.append("<<\n/Type /ExtGState\n");
         appendVal(sb, GSTATE_ALPHA_NONSTROKE);
         appendVal(sb, GSTATE_ALPHA_STROKE);
+        appendVal(sb, GSTATE_OVERPRINT_FILL);
+        appendVal(sb, GSTATE_OVERPRINT_MODE);
+        appendVal(sb, GSTATE_OVERPRINT_STROKE);
 
         sb.append(">>\nendobj\n");
         return sb.toString();
Index: src/java/org/apache/fop/render/pdf/PDFConfigurationConstants.java
===================================================================
--- src/java/org/apache/fop/render/pdf/PDFConfigurationConstants.java (revision 820021)
+++ src/java/org/apache/fop/render/pdf/PDFConfigurationConstants.java (working copy)
@@ -49,4 +49,7 @@
      * PDF/X profile is active).
      */
     String KEY_DISABLE_SRGB_COLORSPACE = "disable-srgb-colorspace";
+    
+    /** Rendering Options key for enabling automatic text overprinting. */
+    String KEY_ENABLE_AUTO_OVERPRINT = "auto-overprint-enabled";
 }
Index: src/java/org/apache/fop/render/pdf/PDFPainter.java
===================================================================
--- src/java/org/apache/fop/render/pdf/PDFPainter.java (revision 820021)
+++ src/java/org/apache/fop/render/pdf/PDFPainter.java (working copy)
@@ -26,6 +26,8 @@
 import java.awt.Rectangle;
 import java.awt.geom.AffineTransform;
 import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.w3c.dom.Document;
 
@@ -39,6 +41,7 @@
 import org.apache.fop.fonts.SingleByteFont;
 import org.apache.fop.fonts.Typeface;
 import org.apache.fop.pdf.PDFDocument;
+import org.apache.fop.pdf.PDFGState;
 import org.apache.fop.pdf.PDFNumber;
 import org.apache.fop.pdf.PDFTextUtil;
 import org.apache.fop.pdf.PDFXObject;
@@ -59,6 +62,14 @@
     /** logging instance */
     private static Log log = LogFactory.getLog(PDFPainter.class);
 
+    /** Graphic state settings with overprinting enabled */
+    private static Map overprintGStateSettings = new HashMap();
+    static {
+        overprintGStateSettings.put(PDFGState.GSTATE_OVERPRINT_STROKE, Boolean.TRUE);
+        overprintGStateSettings.put(PDFGState.GSTATE_OVERPRINT_FILL, Boolean.TRUE);
+        overprintGStateSettings.put(PDFGState.GSTATE_OVERPRINT_MODE, new Integer(1));
+    }
+
     private PDFDocumentHandler documentHandler;
 
     /** The current content generator */
@@ -255,6 +266,25 @@
     /** {@inheritDoc} */
     public void drawText(int x, int y, int letterSpacing, int wordSpacing, int[] dx, String text)
             throws IFException {
+        boolean useOverprint = false;
+        if (this.getPDFUtil().isAutoOverpintEnabled()) {
+            Color backColor = generator.currentState.getBackColor();
+            Color textColor = state.getTextColor();
+            useOverprint = !backColor.equals(Color.white) && !textColor.equals(Color.white)
+                    && !textColor.equals(backColor);
+        }
+
+        if (useOverprint) {
+            generator.saveGraphicsState();
+
+            PDFGState gstate = this.getPDFDoc().getFactory().makeGState(overprintGStateSettings,
+                    generator.getState().getGState());
+
+            documentHandler.pdfResources.addGState(gstate);
+
+            generator.add("/" + gstate.getName() + " gs\n");
+        }
+
         generator.updateColor(state.getTextColor(), true, null);
         generator.beginTextObject();
         FontTriplet triplet = new FontTriplet(
@@ -330,6 +360,10 @@
 
         }
         textutil.writeTJ();
+        
+        if (useOverprint) {
+            generator.restoreGraphicsState();
+        }
     }
 
 }
Index: src/java/org/apache/fop/render/pdf/PDFRenderingUtil.java
===================================================================
--- src/java/org/apache/fop/render/pdf/PDFRenderingUtil.java (revision 820021)
+++ src/java/org/apache/fop/render/pdf/PDFRenderingUtil.java (working copy)
@@ -91,6 +91,7 @@
     /** Optional URI to an output profile to be used. */
     protected String outputProfileURI;
 
+    protected boolean autoOverprintEnabled = false;
 
     PDFRenderingUtil(FOUserAgent userAgent) {
         this.userAgent = userAgent;
@@ -173,6 +174,10 @@
         if (setting != null) {
             this.disableSRGBColorSpace = booleanValueOf(setting);
         }
+        setting = userAgent.getRendererOptions().get(KEY_ENABLE_AUTO_OVERPRINT);
+        if (setting != null) {
+            this.autoOverprintEnabled = booleanValueOf(setting);
+        }
     }
 
     public FOUserAgent getUserAgent() {
@@ -408,4 +413,11 @@
         nums.put(pageIndex, dict);
     }
 
+    /**
+     * Checks if automatic overprinting is enabled (defaults to false).
+     * @return true if overprinting should be applied to text
+     */
+    public boolean isAutoOverpintEnabled() {
+        return autoOverprintEnabled;
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@...
For additional commands, e-mail: fop-users-help@...

Re: Automatic text overprint patch

by Jeremias Maerki-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Matthias, please attach your patch to a new Bugzilla entry:
https://issues.apache.org/bugzilla/enter_bug.cgi?product=Fop
That way we can better keep track of it and it doesn't get lost so
easily in the noise.

Thanks!

On 30.09.2009 18:58:46 Matthias Reischenbacher wrote:

> Hello,
>
> I've implemented a small patch which allows to automatically set the
> overprint state for text in pdf output. This is useful when text and
> background colors are printed on different printing plates because it
> ensures that no white spaces are visible if the printing plates are not
> positioned perfectly.
>
> See also: http://www.nabble.com/Overprint-Black-Text-td9852903.html
>
> Feel free to review or integrate it into fop trunk if it's for any use
> to you.
>
> Usage:
> foUserAgent.getRendererOptions().put(PDFConfigurationConstants.KEY_ENABLE_AUTO_OVERPRINT,
> Boolean.TRUE);
>
> Regards,
> Matthias Reischenbacher
>
>
>
> __________ Information from ESET NOD32 Antivirus, version of virus signature database 4470 (20090930) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>




Jeremias Maerki


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@...
For additional commands, e-mail: fop-users-help@...


Re: Automatic text overprint patch

by MatthiasR :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Jeremias,

ok done. Here's the bugzilla link:
https://issues.apache.org/bugzilla/show_bug.cgi?id=47927

Regards,
Matthias

Jeremias Maerki wrote:

> Matthias, please attach your patch to a new Bugzilla entry:
> https://issues.apache.org/bugzilla/enter_bug.cgi?product=Fop
> That way we can better keep track of it and it doesn't get lost so
> easily in the noise.
>
> Thanks!
>
> On 30.09.2009 18:58:46 Matthias Reischenbacher wrote:
>> Hello,
>>
>> I've implemented a small patch which allows to automatically set the
>> overprint state for text in pdf output. This is useful when text and
>> background colors are printed on different printing plates because it
>> ensures that no white spaces are visible if the printing plates are not
>> positioned perfectly.
>>
>> See also: http://www.nabble.com/Overprint-Black-Text-td9852903.html
>>
>> Feel free to review or integrate it into fop trunk if it's for any use
>> to you.
>>
>> Usage:
>> foUserAgent.getRendererOptions().put(PDFConfigurationConstants.KEY_ENABLE_AUTO_OVERPRINT,
>> Boolean.TRUE);
>>
>> Regards,
>> Matthias Reischenbacher
>>
>>
>>
>> __________ Information from ESET NOD32 Antivirus, version of virus signature database 4470 (20090930) __________
>>
>> The message was checked by ESET NOD32 Antivirus.
>>
>> http://www.eset.com
>>
>
>
>
>
> Jeremias Maerki
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-users-unsubscribe@...
> For additional commands, e-mail: fop-users-help@...
>
> __________ Information from ESET NOD32 Antivirus, version of virus signature database 4471 (20090930) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
>
>


__________ Information from ESET NOD32 Antivirus, version of virus signature database 4473 (20091001) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@...
For additional commands, e-mail: fop-users-help@...