pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jahew...@apache.org
Subject svn commit: r1621640 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox: cos/COSName.java pdmodel/graphics/image/PDImage.java pdmodel/graphics/image/PDImageXObject.java pdmodel/graphics/image/PDInlineImage.java rendering/PageDrawer.java
Date Sun, 31 Aug 2014 21:11:10 GMT
Author: jahewson
Date: Sun Aug 31 21:11:10 2014
New Revision: 1621640

URL: http://svn.apache.org/r1621640
Log:
PDFBOX-2302: Make better use of RenderingHints

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/PDImage.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/PDImageXObject.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/PDInlineImage.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java?rev=1621640&r1=1621639&r2=1621640&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java Sun Aug 31 21:11:10
2014
@@ -260,6 +260,7 @@ public final class COSName extends COSBa
     public static final COSName INDEX = new COSName("Index");
     public static final COSName INDEXED = new COSName("Indexed");
     public static final COSName INFO = new COSName("Info");
+    public static final COSName INTERPOLATE = new COSName("Interpolate");
     public static final COSName ITALIC_ANGLE = new COSName("ItalicAngle");
     // J
     public static final COSName JAVA_SCRIPT = new COSName("JavaScript");

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/PDImage.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/PDImage.java?rev=1621640&r1=1621639&r2=1621640&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/PDImage.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/PDImage.java
Sun Aug 31 21:11:10 2014
@@ -27,6 +27,7 @@ import org.apache.pdfbox.pdmodel.graphic
 
 /**
  * An image in a PDF document.
+ *
  * @author John Hewson
  */
 public interface PDImage extends COSObjectable
@@ -49,14 +50,12 @@ public interface PDImage extends COSObje
 
     /**
      * Returns a stream containing this image's data.
-     * @return stream containing the image data
      * @throws IOException if the
      */
     public PDStream getStream() throws IOException;
 
     /**
      * Returns true if the image is a stencil mask.
-     * @return true if the image is a stencil mask.
      */
     public boolean isStencil();
 
@@ -69,7 +68,6 @@ public interface PDImage extends COSObje
 
     /**
      * Returns bits per component of this image, or -1 if one has not been set.
-     * @return The number of bits per component.
      */
     public int getBitsPerComponent();
 
@@ -80,8 +78,7 @@ public interface PDImage extends COSObje
     public void setBitsPerComponent(int bitsPerComponent);
 
     /**
-     * Returns the image's color space
-     * @return The color space for this image.
+     * Returns the image's color space.
      * @throws IOException If there is an error getting the color space.
      */
     public PDColorSpace getColorSpace() throws IOException;
@@ -94,7 +91,6 @@ public interface PDImage extends COSObje
 
     /**
      * Returns height of this image, or -1 if one has not been set.
-     * @return The height.
      */
     public int getHeight();
 
@@ -106,7 +102,6 @@ public interface PDImage extends COSObje
 
     /**
      * Returns the width of this image, or -1 if one has not been set.
-     * @return The width.
      */
     public int getWidth();
 
@@ -124,7 +119,17 @@ public interface PDImage extends COSObje
 
     /**
      * Returns the decode array.
-     * @return the decode array.
      */
     public COSArray getDecode();
+
+    /**
+     * Returns true if the image should be interpolated when rendered.
+     */
+    public boolean getInterpolate();
+
+
+    /**
+     * Sets the Interpolate flag, true for high-quality image scaling.
+     */
+    public void setInterpolate(boolean value);
 }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/PDImageXObject.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/PDImageXObject.java?rev=1621640&r1=1621639&r2=1621640&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/PDImageXObject.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/PDImageXObject.java
Sun Aug 31 21:11:10 2014
@@ -423,6 +423,18 @@ public final class PDImageXObject extend
     }
 
     @Override
+    public boolean getInterpolate()
+    {
+        return getCOSStream().getBoolean(COSName.INTERPOLATE, false);
+    }
+
+    @Override
+    public void setInterpolate(boolean value)
+    {
+        getCOSStream().setBoolean(COSName.INTERPOLATE, value);
+    }
+
+    @Override
     public void setDecode(COSArray decode)
     {
         getCOSStream().setItem(COSName.DECODE, decode);

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/PDInlineImage.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/PDInlineImage.java?rev=1621640&r1=1621639&r2=1621640&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/PDInlineImage.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/PDInlineImage.java
Sun Aug 31 21:11:10 2014
@@ -183,6 +183,18 @@ public final class PDInlineImage impleme
         parameters.setInt(COSName.W, width);
     }
 
+    @Override
+    public boolean getInterpolate()
+    {
+        return parameters.getBoolean(COSName.I, COSName.INTERPOLATE, false);
+    }
+
+    @Override
+    public void setInterpolate(boolean value)
+    {
+        parameters.setBoolean(COSName.I, value);
+    }
+
     /**
      * Returns a list of filters applied to this stream, or null if there are
      * none.

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java?rev=1621640&r1=1621639&r2=1621640&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java Sun Aug
31 21:11:10 2014
@@ -138,6 +138,19 @@ public class PageDrawer extends PDFGraph
     }
 
     /**
+     * Sets high-quality rendering hints on the current Graphics2D.
+     */
+    private void setRenderingHints()
+    {
+        graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
+                                  RenderingHints.VALUE_INTERPOLATION_BILINEAR);
+        graphics.setRenderingHint(RenderingHints.KEY_RENDERING,
+                                  RenderingHints.VALUE_RENDER_QUALITY);
+        graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+                                  RenderingHints.VALUE_ANTIALIAS_ON);
+    }
+
+    /**
      * This will draw the page to the requested context.
      * 
      * @param g The graphics context to draw onto.
@@ -149,14 +162,15 @@ public class PageDrawer extends PDFGraph
     {
         graphics = (Graphics2D) g;
         xform = graphics.getTransform();
-        this.pageSize = pageSize;
-        graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
-        graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
+        setRenderingHints();
+
         graphics.translate(0, (int) pageSize.getHeight());
         graphics.scale(1, -1);
         // TODO use getStroke() to set the initial stroke
         graphics.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER));
 
+        this.pageSize = pageSize;
+
         // Only if there is some content, we have to process it.
         // Otherwise we are done here and we will produce an empty page
         PDPage page = getPage();
@@ -280,8 +294,7 @@ public class PageDrawer extends PDFGraph
     {
         pageSize = pageDimension;
         graphics = g;
-        graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
-        graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
+        setRenderingHints();
 
         initStream(pageDimension);
 
@@ -371,8 +384,6 @@ public class PageDrawer extends PDFGraph
      */
     private void drawGlyph2D(Glyph2D glyph2D, int code, AffineTransform at) throws IOException
     {
-        graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
-
         PDGraphicsState state = getGraphicsState();
         RenderingMode renderingMode = state.getTextState().getRenderingMode();
 
@@ -628,7 +639,6 @@ public class PageDrawer extends PDFGraph
         }
         graphics.setPaint(strokingPaint);
         graphics.setStroke(getStroke());
-        graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
         setClip();
         graphics.draw(linePath);
         linePath.reset();
@@ -647,7 +657,6 @@ public class PageDrawer extends PDFGraph
         }
         graphics.setPaint(nonStrokingPaint);
         linePath.setWindingRule(windingRule);
-        graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
         setClip();
         graphics.fill(linePath);
         linePath.reset();
@@ -740,8 +749,20 @@ public class PageDrawer extends PDFGraph
         }
         else
         {
+            if (!pdImage.getInterpolate())
+            {
+                graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
+                                          RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
+            }
+
             // draw the image
             drawBufferedImage(pdImage.getImage(), at);
+
+            if (!pdImage.getInterpolate())
+            {
+                graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
+                                          RenderingHints.VALUE_INTERPOLATION_BICUBIC);
+            }
         }
     }
 
@@ -760,8 +781,6 @@ public class PageDrawer extends PDFGraph
                             imageTransform.getScaleX(), imageTransform.getScaleY()));
             awtPaint = applySoftMaskToPaint(awtPaint, softMask);
             graphics.setPaint(awtPaint);
-            graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
-                    RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
             Rectangle2D unitRect = new Rectangle2D.Float(0, 0, 1, 1);
             graphics.fill(at.createTransformedShape(unitRect));
         }
@@ -785,7 +804,6 @@ public class PageDrawer extends PDFGraph
 
         graphics.setComposite(getGraphicsState().getNonStrokingJavaComposite());
         graphics.setPaint(paint);
-        graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
         graphics.setClip(null);
         lastClip = null;
         graphics.fill(getGraphicsState().getCurrentClippingPath());



Mime
View raw message