You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by ga...@apache.org on 2013/01/18 23:49:09 UTC

svn commit: r1435400 - in /xmlgraphics/fop/trunk: ./ src/java/org/apache/fop/render/intermediate/ src/java/org/apache/fop/render/pdf/ src/java/org/apache/fop/util/

Author: gadams
Date: Fri Jan 18 22:49:09 2013
New Revision: 1435400

URL: http://svn.apache.org/viewvc?rev=1435400&view=rev
Log:
FOP-2195: use sparse arrays for position adjustments

Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/IFRenderer.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/IFUtil.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFPainter.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/util/XMLUtil.java
    xmlgraphics/fop/trunk/status.xml

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/IFRenderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/IFRenderer.java?rev=1435400&r1=1435399&r2=1435400&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/IFRenderer.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/IFRenderer.java Fri Jan 18 22:49:09 2013
@@ -27,7 +27,6 @@ import java.awt.geom.AffineTransform;
 import java.awt.geom.Rectangle2D;
 import java.io.IOException;
 import java.io.OutputStream;
-import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
@@ -1133,8 +1132,7 @@ public class IFRenderer extends Abstract
 
     private class TextUtil {
         private static final int INITIAL_BUFFER_SIZE = 16;
-        private int[][] dp = new int[INITIAL_BUFFER_SIZE][4];
-        // private int lastDPPos = 0; // TBD - not yet used
+        private int[][] dp = new int[INITIAL_BUFFER_SIZE][];
         private final StringBuffer text = new StringBuffer();
         private int startx;
         private int starty;
@@ -1163,16 +1161,15 @@ public class IFRenderer extends Abstract
                 if (idx > dp.length - 1) {
                     int newSize = Math.max(dp.length, idx + 1) + INITIAL_BUFFER_SIZE;
                     int[][] newDP = new int[newSize][];
-                    // reuse prior PA[0]...PA[dp.length-1]
+                    // reuse prior DP[0]...DP[dp.length-1]
                     System.arraycopy(dp, 0, newDP, 0, dp.length);
-                    // populate new PA[dp.length]...PA[newDP.length-1]
-                    for ( int i = dp.length, n = newDP.length; i < n; i++ ) {
-                        newDP[i] = new int[4];
-                    }
+                    // switch to new DP, leaving DP[dp.length]...DP[newDP.length-1] unpopulated
                     dp = newDP;
                 }
+                if ( dp[idx - 1] == null ) {
+                    dp[idx - 1] = new int[4];
+                }
                 IFUtil.adjustPA ( dp[idx - 1], pa );
-                // lastDPPos = idx;
             }
         }
 
@@ -1180,9 +1177,8 @@ public class IFRenderer extends Abstract
             if (text.length() > 0) {
                 text.setLength(0);
                 for ( int i = 0, n = dp.length; i < n; i++ ) {
-                    Arrays.fill(dp[i], 0);
+                    dp[i] = null;
                 }
-                // lastDPPos = 0;
             }
         }
 
@@ -1230,7 +1226,7 @@ public class IFRenderer extends Abstract
                 int i  = ( tl < pl ) ? tl : pl;
                 while ( i > 0 ) {
                     int[] pa = dp [ i - 1 ];
-                    if ( !IFUtil.isPAIdentity ( pa ) ) {
+                    if ( ( pa != null ) && !IFUtil.isPAIdentity ( pa ) ) {
                         break;
                     } else {
                         i--;

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/IFUtil.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/IFUtil.java?rev=1435400&r1=1435399&r2=1435400&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/IFUtil.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/IFUtil.java Fri Jan 18 22:49:09 2013
@@ -217,7 +217,9 @@ public final class IFUtil {
         if ( dp != null ) {
             dx = new int [ count ];
             for ( int i = 0, n = count; i < n; i++ ) {
-                dx [ i ] = dp [ i ] [ 0 ];      // xPlaAdjust[i]
+                if ( dp [ i ] != null ) {
+                    dx [ i ] = dp [ i ] [ 0 ];      // xPlaAdjust[i]
+                }
             }
         } else {
             dx = null;
@@ -330,7 +332,7 @@ public final class IFUtil {
         } else {
             for ( int i = 0, n = dp.length; i < n; i++ ) {
                 int[] pa = dp[i];
-                if ( pa[0] != pa[2] ) {
+                if ( ( pa != null ) && ( pa[0] != pa[2] ) ) {
                     return false;
                 }
             }
@@ -369,12 +371,15 @@ public final class IFUtil {
         if ( ( dp == null ) || ( offset > dp.length ) || ( ( offset + count ) > dp.length ) ) {
             throw new IllegalArgumentException();
         } else {
-            int[][] dpNew = new int [ count ] [ 4 ];
+            int[][] dpNew = new int [ count ] [];
             for ( int i = 0, n = count; i < n; i++ ) {
-                int[] paDst = dpNew [ i ];
                 int[] paSrc = dp [ i + offset ];
-                for ( int k = 0; k < 4; k++ ) {
-                    paDst [ k ] = paSrc [ k ];
+                if ( paSrc != null ) {
+                    int[] paDst = new int [ 4 ];
+                    for ( int k = 0; k < 4; k++ ) {
+                        paDst [ k ] = paSrc [ k ];
+                    }
+                    dpNew [ i ] = paDst;
                 }
             }
             return dpNew;

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFPainter.java?rev=1435400&r1=1435399&r2=1435400&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFPainter.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFPainter.java Fri Jan 18 22:49:09 2013
@@ -445,7 +445,6 @@ public class PDFPainter extends Abstract
             int         fs              = state.getFontSize();
             float       fsPoints        = fs / 1000f;
             Font        f               = getFontInfo().getFontInstance(triplet, fs);
-            // String      fn              = f.getFontName();
             PDFTextUtil tu              = generator.getTextUtil();
             double      xc              = 0f;
             double      yc              = 0f;
@@ -457,7 +456,7 @@ public class PDFPainter extends Abstract
             generator.updateCharacterSpacing ( letterSpacing / 1000f );
             for ( int i = 0, n = text.length(); i < n; i++ ) {
                 char    ch              = text.charAt ( i );
-                int[]   pa              = ( i < dp.length ) ? dp [ i ] : paZero;
+                int[]   pa              = ( ( i >= dp.length ) || ( dp[i] == null ) ) ? paZero : dp[i];
                 double  xo              = xc + pa[0];
                 double  yo              = yc + pa[1];
                 double  xa              = f.getCharWidth(ch) + maybeWordOffsetX ( wox, ch, null );

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/util/XMLUtil.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/util/XMLUtil.java?rev=1435400&r1=1435399&r2=1435400&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/util/XMLUtil.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/util/XMLUtil.java Fri Jan 18 22:49:09 2013
@@ -194,14 +194,18 @@ public final class XMLUtil implements XM
         sb.append ( na );
         for ( int i = 0; i < na; i++ ) {
             int[] pa = dp [ i ];
-            for ( int k = 0; k < 4; k++ ) {
-                int a = pa [ k ];
-                if ( a != 0 ) {
-                    encodeNextAdjustment ( sb, nz, a );
-                    nz = 0;
-                } else {
-                    nz++;
+            if ( pa != null ) {
+                for ( int k = 0; k < 4; k++ ) {
+                    int a = pa [ k ];
+                    if ( a != 0 ) {
+                        encodeNextAdjustment ( sb, nz, a );
+                        nz = 0;
+                    } else {
+                        nz++;
+                    }
                 }
+            } else {
+                nz += 4;
             }
         }
         encodeNextAdjustment ( sb, nz, 0 );

Modified: xmlgraphics/fop/trunk/status.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/status.xml?rev=1435400&r1=1435399&r2=1435400&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/status.xml (original)
+++ xmlgraphics/fop/trunk/status.xml Fri Jan 18 22:49:09 2013
@@ -59,6 +59,9 @@
       documents. Example: the fix of marks layering will be such a case when it's done.
     -->
     <release version="FOP Trunk" date="TBD">
+      <action context="Fonts" dev="GA" type="fix" fixes-bug="FOP-2195">
+       Use sparse arrays for position adjustments.
+      </action>
       <action context="Fonts" dev="GA" type="fix" fixes-bug="FOP-2194">
        Optimize lazy font load invocation for hot methods.
       </action>



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org