From: Glenn Adams Date: Fri, 18 Jan 2013 22:49:09 +0000 (+0000) Subject: FOP-2195: use sparse arrays for position adjustments X-Git-Tag: fop-2_0~238 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=81831e1fda50acdd41d02533a56cb7f18ccdd8f1;p=xmlgraphics-fop.git FOP-2195: use sparse arrays for position adjustments git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1435400 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/fop/render/intermediate/IFRenderer.java b/src/java/org/apache/fop/render/intermediate/IFRenderer.java index 01adec08d..f429efb2c 100644 --- a/src/java/org/apache/fop/render/intermediate/IFRenderer.java +++ b/src/java/org/apache/fop/render/intermediate/IFRenderer.java @@ -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 AbstractPathOrientedRenderer { 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 AbstractPathOrientedRenderer { 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 AbstractPathOrientedRenderer { 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 AbstractPathOrientedRenderer { 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--; diff --git a/src/java/org/apache/fop/render/intermediate/IFUtil.java b/src/java/org/apache/fop/render/intermediate/IFUtil.java index bdd7eb8a0..8906e901b 100644 --- a/src/java/org/apache/fop/render/intermediate/IFUtil.java +++ b/src/java/org/apache/fop/render/intermediate/IFUtil.java @@ -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; diff --git a/src/java/org/apache/fop/render/pdf/PDFPainter.java b/src/java/org/apache/fop/render/pdf/PDFPainter.java index d71c6aff4..d8e02cd93 100644 --- a/src/java/org/apache/fop/render/pdf/PDFPainter.java +++ b/src/java/org/apache/fop/render/pdf/PDFPainter.java @@ -445,7 +445,6 @@ public class PDFPainter extends AbstractIFPainter { 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 AbstractIFPainter { 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 ); diff --git a/src/java/org/apache/fop/util/XMLUtil.java b/src/java/org/apache/fop/util/XMLUtil.java index 86c0f66a8..87bf6c6d4 100644 --- a/src/java/org/apache/fop/util/XMLUtil.java +++ b/src/java/org/apache/fop/util/XMLUtil.java @@ -194,14 +194,18 @@ public final class XMLUtil implements XMLConstants { 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 ); diff --git a/status.xml b/status.xml index 97bf7784d..4a8fe39ca 100644 --- a/status.xml +++ b/status.xml @@ -59,6 +59,9 @@ documents. Example: the fix of marks layering will be such a case when it's done. --> + + Use sparse arrays for position adjustments. + Optimize lazy font load invocation for hot methods.