pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jahew...@apache.org
Subject svn commit: r1620412 - /pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
Date Mon, 25 Aug 2014 18:52:59 GMT
Author: jahewson
Date: Mon Aug 25 18:52:59 2014
New Revision: 1620412

URL: http://svn.apache.org/r1620412
Log:
PDFBOX-2262: Remove AWT painting and buffer text clip

Modified:
    pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java

Modified: pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java?rev=1620412&r1=1620411&r2=1620412&view=diff
==============================================================================
--- pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
(original)
+++ pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
Mon Aug 25 18:52:59 2014
@@ -39,7 +39,6 @@ import java.util.Map;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.fontbox.cff.CFFCIDFont;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.cos.COSStream;
 import org.apache.pdfbox.pdmodel.font.PDCIDFontType0;
@@ -97,6 +96,9 @@ public class PageDrawer extends PDFGraph
     // last clipping path
     private Area lastClip;
 
+    // buffered clipping area for text being drawn
+    private Area textClippingArea;
+
     private final Map<PDFont, Glyph2D> fontGlyph2D = new HashMap<PDFont, Glyph2D>();
 
     private PDRectangle pageSize;
@@ -250,39 +252,23 @@ public class PageDrawer extends PDFGraph
     @Override
     protected void processText(byte[] string) throws IOException
     {
-        //
-        // todo: DEPRECATED: Used for AWT text only. Will be removed soon! Don't edit me.
-        //
-
         PDGraphicsState state = getGraphicsState();
         RenderingMode renderingMode = state.getTextState().getRenderingMode();
 
-        if (renderingMode == RenderingMode.FILL)
-        {
-            graphics.setComposite(state.getNonStrokingJavaComposite());
-            graphics.setPaint(getNonStrokingPaint());
-        }
-        else if (renderingMode == RenderingMode.STROKE)
-        {
-            graphics.setComposite(state.getStrokingJavaComposite());
-            graphics.setPaint(getStrokingPaint());
-            graphics.setStroke(getStroke());
-        }
-        else if (renderingMode == RenderingMode.NEITHER)
+        // buffer the text clip because it represents a single clipping area
+        if (renderingMode.isClip())
         {
-            return;
-        }
-        else
-        {
-            LOG.error("Unsupported RenderingMode " +
-                      this.getGraphicsState().getTextState().getRenderingMode() +
-                      " in PageDrawer.processTextPosition()." + " Using RenderingMode " +
-                      RenderingMode.FILL + " instead");
-            graphics.setComposite(state.getNonStrokingJavaComposite());
-            graphics.setPaint(getNonStrokingPaint());
+            textClippingArea = new Area();
         }
 
         super.processText(string);
+
+        // apply the buffered clip as one area
+        if (renderingMode.isClip())
+        {
+            state.intersectClippingPath(textClippingArea);
+            textClippingArea = null;
+        }
     }
 
     @Override
@@ -306,23 +292,12 @@ public class PageDrawer extends PDFGraph
             else
             {
                 Glyph2D glyph2D = createGlyph2D(font);
-                if (glyph2D != null)
-                {
-                    AffineTransform fontMatrixAT = new AffineTransform(
-                            fontMatrix.getValue(0, 0), fontMatrix.getValue(0, 1),
-                            fontMatrix.getValue(1, 0), fontMatrix.getValue(1, 1),
-                            fontMatrix.getValue(2, 0), fontMatrix.getValue(2, 1));
-                    at.concatenate(fontMatrixAT);
-                    // Let PDFBox render the font if supported
-                    drawGlyph2D(glyph2D, code, at);
-                }
-                else
-                {
-                    // Use AWT to render the font (standard14 fonts, substituted embedded
fonts)
-                    // TODO to be removed in the long run
-                    //drawString(font, unicode, at);
-                    throw new UnsupportedOperationException("No font for " + font.getBaseFont());
-                }
+                AffineTransform fontMatrixAT = new AffineTransform(
+                        fontMatrix.getValue(0, 0), fontMatrix.getValue(0, 1),
+                        fontMatrix.getValue(1, 0), fontMatrix.getValue(1, 1),
+                        fontMatrix.getValue(2, 0), fontMatrix.getValue(2, 1));
+                at.concatenate(fontMatrixAT);
+                drawGlyph2D(glyph2D, code, at);
             }
         }
         catch (IOException e)
@@ -368,7 +343,7 @@ public class PageDrawer extends PDFGraph
 
             if (renderingMode.isClip())
             {
-                state.intersectClippingPath(new Area(glyph));
+                textClippingArea.add(new Area(glyph));
             }
         }
     }
@@ -468,6 +443,12 @@ public class PageDrawer extends PDFGraph
             fontGlyph2D.put(font, glyph2D);
         }
 
+        if (glyph2D == null)
+        {
+            // todo: make sure this never happens
+            throw new UnsupportedOperationException("No font for " + font.getBaseFont());
+        }
+
         return glyph2D;
     }
 
@@ -487,10 +468,10 @@ public class PageDrawer extends PDFGraph
     }
 
     /**
-     * Generates awt raster for a soft mask
+     * Generates AWT raster for a soft mask
      * 
      * @param softMask
-     * @return awt raster for soft mask
+     * @return AWT raster for soft mask
      * @throws IOException
      */
     private Raster createSoftMaskRaster(PDSoftMask softMask) throws IOException



Mime
View raw message