Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/complexscripts/util/GlyphSequence.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/complexscripts/util/GlyphSequence.java?rev=1466146&r1=1466145&r2=1466146&view=diff ============================================================================== --- xmlgraphics/fop/trunk/src/java/org/apache/fop/complexscripts/util/GlyphSequence.java (original) +++ xmlgraphics/fop/trunk/src/java/org/apache/fop/complexscripts/util/GlyphSequence.java Tue Apr 9 17:31:41 2013 @@ -65,15 +65,15 @@ public class GlyphSequence implements Cl * @param associations a (possibly null) array of glyph to character associations * @param predications true if predications are enabled */ - public GlyphSequence ( IntBuffer characters, IntBuffer glyphs, List associations, boolean predications ) { - if ( characters == null ) { - characters = IntBuffer.allocate ( DEFAULT_CHARS_CAPACITY ); + public GlyphSequence (IntBuffer characters, IntBuffer glyphs, List associations, boolean predications) { + if (characters == null) { + characters = IntBuffer.allocate (DEFAULT_CHARS_CAPACITY); } - if ( glyphs == null ) { - glyphs = IntBuffer.allocate ( characters.capacity() ); + if (glyphs == null) { + glyphs = IntBuffer.allocate (characters.capacity()); } - if ( associations == null ) { - associations = makeIdentityAssociations ( characters.limit(), glyphs.limit() ); + if (associations == null) { + associations = makeIdentityAssociations (characters.limit(), glyphs.limit()); } this.characters = characters; this.glyphs = glyphs; @@ -91,8 +91,8 @@ public class GlyphSequence implements Cl * @param glyphs a (possibly null) buffer of glyphs * @param associations a (possibly null) array of glyph to character associations */ - public GlyphSequence ( IntBuffer characters, IntBuffer glyphs, List associations ) { - this ( characters, glyphs, associations, false ); + public GlyphSequence (IntBuffer characters, IntBuffer glyphs, List associations) { + this (characters, glyphs, associations, false); } /** @@ -101,8 +101,8 @@ public class GlyphSequence implements Cl * of glyphs buffer and association list. * @param gs an existing glyph sequence */ - public GlyphSequence ( GlyphSequence gs ) { - this ( gs.characters.duplicate(), copyBuffer ( gs.glyphs ), copyAssociations ( gs.associations ), gs.predications ); + public GlyphSequence (GlyphSequence gs) { + this (gs.characters.duplicate(), copyBuffer (gs.glyphs), copyAssociations (gs.associations), gs.predications); } /** @@ -119,8 +119,8 @@ public class GlyphSequence implements Cl * @param ial input association list * @param lal lookahead association list */ - public GlyphSequence ( GlyphSequence gs, int[] bga, int[] iga, int[] lga, CharAssociation[] bal, CharAssociation[] ial, CharAssociation[] lal ) { - this ( gs.characters.duplicate(), concatGlyphs ( bga, iga, lga ), concatAssociations ( bal, ial, lal ), gs.predications ); + public GlyphSequence (GlyphSequence gs, int[] bga, int[] iga, int[] lga, CharAssociation[] bal, CharAssociation[] ial, CharAssociation[] lal) { + this (gs.characters.duplicate(), concatGlyphs (bga, iga, lga), concatAssociations (bal, ial, lal), gs.predications); } /** @@ -141,9 +141,9 @@ public class GlyphSequence implements Cl * @param copy true if to return a newly instantiated array of characters * @return array of characters */ - public int[] getCharacterArray ( boolean copy ) { - if ( copy ) { - return toArray ( characters ); + public int[] getCharacterArray (boolean copy) { + if (copy) { + return toArray (characters); } else { return characters.array(); } @@ -165,8 +165,8 @@ public class GlyphSequence implements Cl * @throws IndexOutOfBoundsException if index is less than zero * or exceeds last valid position */ - public int getGlyph ( int index ) throws IndexOutOfBoundsException { - return glyphs.get ( index ); + public int getGlyph (int index) throws IndexOutOfBoundsException { + return glyphs.get (index); } /** @@ -176,11 +176,11 @@ public class GlyphSequence implements Cl * @throws IndexOutOfBoundsException if index is greater or equal to * the limit of the underlying glyph buffer */ - public void setGlyph ( int index, int gi ) throws IndexOutOfBoundsException { - if ( gi > 65535 ) { + public void setGlyph (int index, int gi) throws IndexOutOfBoundsException { + if (gi > 65535) { gi = 65535; } - glyphs.put ( index, gi ); + glyphs.put (index, gi); } /** @@ -200,20 +200,20 @@ public class GlyphSequence implements Cl * indicating all avaialble glyphs starting at offset * @return glyph array */ - public int[] getGlyphs ( int offset, int count ) { + public int[] getGlyphs (int offset, int count) { int ng = getGlyphCount(); - if ( offset < 0 ) { + if (offset < 0) { offset = 0; - } else if ( offset > ng ) { + } else if (offset > ng) { offset = ng; } - if ( count < 0 ) { + if (count < 0) { count = ng - offset; } int[] ga = new int [ count ]; - for ( int i = offset, n = offset + count, k = 0; i < n; i++ ) { - if ( k < ga.length ) { - ga [ k++ ] = glyphs.get ( i ); + for (int i = offset, n = offset + count, k = 0; i < n; i++) { + if (k < ga.length) { + ga [ k++ ] = glyphs.get (i); } } return ga; @@ -229,9 +229,9 @@ public class GlyphSequence implements Cl * @param copy true if to return a newly instantiated array of glyphs * @return array of glyphs */ - public int[] getGlyphArray ( boolean copy ) { - if ( copy ) { - return toArray ( glyphs ); + public int[] getGlyphArray (boolean copy) { + if (copy) { + return toArray (glyphs); } else { return glyphs.array(); } @@ -253,8 +253,8 @@ public class GlyphSequence implements Cl * @throws IndexOutOfBoundsException if index is less than zero * or exceeds last valid position */ - public CharAssociation getAssociation ( int index ) throws IndexOutOfBoundsException { - return (CharAssociation) associations.get ( index ); + public CharAssociation getAssociation (int index) throws IndexOutOfBoundsException { + return (CharAssociation) associations.get (index); } /** @@ -272,20 +272,20 @@ public class GlyphSequence implements Cl * indicating all avaialble associations starting at offset * @return associations */ - public CharAssociation[] getAssociations ( int offset, int count ) { + public CharAssociation[] getAssociations (int offset, int count) { int ng = getGlyphCount(); - if ( offset < 0 ) { + if (offset < 0) { offset = 0; - } else if ( offset > ng ) { + } else if (offset > ng) { offset = ng; } - if ( count < 0 ) { + if (count < 0) { count = ng - offset; } CharAssociation[] aa = new CharAssociation [ count ]; - for ( int i = offset, n = offset + count, k = 0; i < n; i++ ) { - if ( k < aa.length ) { - aa [ k++ ] = (CharAssociation) associations.get ( i ); + for (int i = offset, n = offset + count, k = 0; i < n; i++) { + if (k < aa.length) { + aa [ k++ ] = (CharAssociation) associations.get (i); } } return aa; @@ -295,7 +295,7 @@ public class GlyphSequence implements Cl * Enable or disable predications. * @param enable true if predications are to be enabled; otherwise false to disable */ - public void setPredications ( boolean enable ) { + public void setPredications (boolean enable) { this.predications = enable; } @@ -313,11 +313,11 @@ public class GlyphSequence implements Cl * @param key predication key * @param value predication value */ - public void setPredication ( int offset, String key, Object value ) { - if ( predications ) { - CharAssociation[] aa = getAssociations ( offset, 1 ); + public void setPredication (int offset, String key, Object value) { + if (predications) { + CharAssociation[] aa = getAssociations (offset, 1); CharAssociation ca = aa[0]; - ca.setPredication ( key, value ); + ca.setPredication (key, value); } } @@ -327,11 +327,11 @@ public class GlyphSequence implements Cl * @param key predication key * @return predication KEY at OFFSET or null if none exists */ - public Object getPredication ( int offset, String key ) { - if ( predications ) { - CharAssociation[] aa = getAssociations ( offset, 1 ); + public Object getPredication (int offset, String key) { + if (predications) { + CharAssociation[] aa = getAssociations (offset, 1); CharAssociation ca = aa[0]; - return ca.getPredication ( key ); + return ca.getPredication (key); } else { return null; } @@ -343,15 +343,15 @@ public class GlyphSequence implements Cl * @return zero if glyphs are the same, otherwise returns 1 or -1 according to whether this glyph sequence's * glyphs are lexicographically greater or lesser than the glyphs in the specified string buffer */ - public int compareGlyphs ( IntBuffer gb ) { + public int compareGlyphs (IntBuffer gb) { int ng = getGlyphCount(); - for ( int i = 0, n = gb.limit(); i < n; i++ ) { - if ( i < ng ) { - int g1 = glyphs.get ( i ); - int g2 = gb.get ( i ); - if ( g1 > g2 ) { + for (int i = 0, n = gb.limit(); i < n; i++) { + if (i < ng) { + int g1 = glyphs.get (i); + int g2 = gb.get (i); + if (g1 > g2) { return 1; - } else if ( g1 < g2 ) { + } else if (g1 < g2) { return -1; } } else { @@ -365,11 +365,11 @@ public class GlyphSequence implements Cl public Object clone() { try { GlyphSequence gs = (GlyphSequence) super.clone(); - gs.characters = copyBuffer ( characters ); - gs.glyphs = copyBuffer ( glyphs ); - gs.associations = copyAssociations ( associations ); + gs.characters = copyBuffer (characters); + gs.glyphs = copyBuffer (glyphs); + gs.associations = copyAssociations (associations); return gs; - } catch ( CloneNotSupportedException e ) { + } catch (CloneNotSupportedException e) { return null; } } @@ -377,15 +377,15 @@ public class GlyphSequence implements Cl /** {@inheritDoc} */ public String toString() { StringBuffer sb = new StringBuffer(); - sb.append ( '{' ); - sb.append ( "chars = [" ); - sb.append ( characters ); - sb.append ( "], glyphs = [" ); - sb.append ( glyphs ); - sb.append ( "], associations = [" ); - sb.append ( associations ); - sb.append ( "]" ); - sb.append ( '}' ); + sb.append ('{'); + sb.append ("chars = ["); + sb.append (characters); + sb.append ("], glyphs = ["); + sb.append (glyphs); + sb.append ("], associations = ["); + sb.append (associations); + sb.append ("]"); + sb.append ('}'); return sb.toString(); } @@ -395,16 +395,16 @@ public class GlyphSequence implements Cl * @param ga2 second glyph array * @return true if arrays are botth null or both non-null and have identical elements */ - public static boolean sameGlyphs ( int[] ga1, int[] ga2 ) { - if ( ga1 == ga2 ) { + public static boolean sameGlyphs (int[] ga1, int[] ga2) { + if (ga1 == ga2) { return true; - } else if ( ( ga1 == null ) || ( ga2 == null ) ) { + } else if ((ga1 == null) || (ga2 == null)) { return false; - } else if ( ga1.length != ga2.length ) { + } else if (ga1.length != ga2.length) { return false; } else { - for ( int i = 0, n = ga1.length; i < n; i++ ) { - if ( ga1[i] != ga2[i] ) { + for (int i = 0, n = ga1.length; i < n; i++) { + if (ga1[i] != ga2[i]) { return false; } } @@ -419,26 +419,26 @@ public class GlyphSequence implements Cl * @param lga lookahead glyph array * @return new integer buffer containing concatenated glyphs */ - public static IntBuffer concatGlyphs ( int[] bga, int[] iga, int[] lga ) { + public static IntBuffer concatGlyphs (int[] bga, int[] iga, int[] lga) { int ng = 0; - if ( bga != null ) { + if (bga != null) { ng += bga.length; } - if ( iga != null ) { + if (iga != null) { ng += iga.length; } - if ( lga != null ) { + if (lga != null) { ng += lga.length; } - IntBuffer gb = IntBuffer.allocate ( ng ); - if ( bga != null ) { - gb.put ( bga ); + IntBuffer gb = IntBuffer.allocate (ng); + if (bga != null) { + gb.put (bga); } - if ( iga != null ) { - gb.put ( iga ); + if (iga != null) { + gb.put (iga); } - if ( lga != null ) { - gb.put ( lga ); + if (lga != null) { + gb.put (lga); } gb.flip(); return gb; @@ -451,32 +451,32 @@ public class GlyphSequence implements Cl * @param laa lookahead association array * @return new list containing concatenated associations */ - public static List concatAssociations ( CharAssociation[] baa, CharAssociation[] iaa, CharAssociation[] laa ) { + public static List concatAssociations (CharAssociation[] baa, CharAssociation[] iaa, CharAssociation[] laa) { int na = 0; - if ( baa != null ) { + if (baa != null) { na += baa.length; } - if ( iaa != null ) { + if (iaa != null) { na += iaa.length; } - if ( laa != null ) { + if (laa != null) { na += laa.length; } - if ( na > 0 ) { - List gl = new ArrayList ( na ); - if ( baa != null ) { - for ( int i = 0; i < baa.length; i++ ) { - gl.add ( baa[i] ); + if (na > 0) { + List gl = new ArrayList (na); + if (baa != null) { + for (int i = 0; i < baa.length; i++) { + gl.add (baa[i]); } } - if ( iaa != null ) { - for ( int i = 0; i < iaa.length; i++ ) { - gl.add ( iaa[i] ); + if (iaa != null) { + for (int i = 0; i < iaa.length; i++) { + gl.add (iaa[i]); } } - if ( laa != null ) { - for ( int i = 0; i < laa.length; i++ ) { - gl.add ( laa[i] ); + if (laa != null) { + for (int i = 0; i < laa.length; i++) { + gl.add (laa[i]); } } return gl; @@ -491,11 +491,11 @@ public class GlyphSequence implements Cl * @param sa array of glyph sequences, whose glyph arrays and association lists are to be concatenated * @return new glyph sequence referring to character array of GS and concatenated glyphs and associations of SA */ - public static GlyphSequence join ( GlyphSequence gs, GlyphSequence[] sa ) { + public static GlyphSequence join (GlyphSequence gs, GlyphSequence[] sa) { assert sa != null; int tg = 0; int ta = 0; - for ( int i = 0, n = sa.length; i < n; i++ ) { + for (int i = 0, n = sa.length; i < n; i++) { GlyphSequence s = sa [ i ]; IntBuffer ga = s.getGlyphs(); assert ga != null; @@ -507,14 +507,14 @@ public class GlyphSequence implements Cl tg += ng; ta += na; } - IntBuffer uga = IntBuffer.allocate ( tg ); - ArrayList ual = new ArrayList ( ta ); - for ( int i = 0, n = sa.length; i < n; i++ ) { + IntBuffer uga = IntBuffer.allocate (tg); + ArrayList ual = new ArrayList (ta); + for (int i = 0, n = sa.length; i < n; i++) { GlyphSequence s = sa [ i ]; - uga.put ( s.getGlyphs() ); - ual.addAll ( s.getAssociations() ); + uga.put (s.getGlyphs()); + ual.addAll (s.getAssociations()); } - return new GlyphSequence ( gs.getCharacters(), uga, ual, gs.getPredications() ); + return new GlyphSequence (gs.getCharacters(), uga, ual, gs.getPredications()); } /** @@ -525,93 +525,93 @@ public class GlyphSequence implements Cl * @param target index to which source sub-sequence is to be moved * @return reordered sequence (or original if no reordering performed) */ - public static GlyphSequence reorder ( GlyphSequence gs, int source, int count, int target ) { - if ( source != target ) { + public static GlyphSequence reorder (GlyphSequence gs, int source, int count, int target) { + if (source != target) { int ng = gs.getGlyphCount(); - int[] ga = gs.getGlyphArray ( false ); + int[] ga = gs.getGlyphArray (false); int[] nga = new int [ ng ]; - GlyphSequence.CharAssociation[] aa = gs.getAssociations ( 0, ng ); + GlyphSequence.CharAssociation[] aa = gs.getAssociations (0, ng); GlyphSequence.CharAssociation[] naa = new GlyphSequence.CharAssociation [ ng ]; - if ( source < target ) { + if (source < target) { int t = 0; - for ( int s = 0, e = source; s < e; s++, t++ ) { + for (int s = 0, e = source; s < e; s++, t++) { nga[t] = ga[s]; naa[t] = aa[s]; } - for ( int s = source + count, e = target; s < e; s++, t++ ) { + for (int s = source + count, e = target; s < e; s++, t++) { nga[t] = ga[s]; naa[t] = aa[s]; } - for ( int s = source, e = source + count; s < e; s++, t++ ) { + for (int s = source, e = source + count; s < e; s++, t++) { nga[t] = ga[s]; naa[t] = aa[s]; } - for ( int s = target, e = ng; s < e; s++, t++ ) { + for (int s = target, e = ng; s < e; s++, t++) { nga[t] = ga[s]; naa[t] = aa[s]; } } else { int t = 0; - for ( int s = 0, e = target; s < e; s++, t++ ) { + for (int s = 0, e = target; s < e; s++, t++) { nga[t] = ga[s]; naa[t] = aa[s]; } - for ( int s = source, e = source + count; s < e; s++, t++ ) { + for (int s = source, e = source + count; s < e; s++, t++) { nga[t] = ga[s]; naa[t] = aa[s]; } - for ( int s = target, e = source; s < e; s++, t++ ) { + for (int s = target, e = source; s < e; s++, t++) { nga[t] = ga[s]; naa[t] = aa[s]; } - for ( int s = source + count, e = ng; s < e; s++, t++ ) { + for (int s = source + count, e = ng; s < e; s++, t++) { nga[t] = ga[s]; naa[t] = aa[s]; } } - return new GlyphSequence ( gs, null, nga, null, null, naa, null ); + return new GlyphSequence (gs, null, nga, null, null, naa, null); } else { return gs; } } - private static int[] toArray ( IntBuffer ib ) { - if ( ib != null ) { + private static int[] toArray (IntBuffer ib) { + if (ib != null) { int n = ib.limit(); int[] ia = new int[n]; - ib.get ( ia, 0, n ); + ib.get (ia, 0, n); return ia; } else { return new int[0]; } } - private static List makeIdentityAssociations ( int numChars, int numGlyphs ) { + private static List makeIdentityAssociations (int numChars, int numGlyphs) { int nc = numChars; int ng = numGlyphs; - List av = new ArrayList ( ng ); - for ( int i = 0, n = ng; i < n; i++ ) { - int k = ( i > nc ) ? nc : i; - av.add ( new CharAssociation ( i, ( k == nc ) ? 0 : 1 ) ); + List av = new ArrayList (ng); + for (int i = 0, n = ng; i < n; i++) { + int k = (i > nc) ? nc : i; + av.add (new CharAssociation (i, (k == nc) ? 0 : 1)); } return av; } - private static IntBuffer copyBuffer ( IntBuffer ib ) { - if ( ib != null ) { + private static IntBuffer copyBuffer (IntBuffer ib) { + if (ib != null) { int[] ia = new int [ ib.capacity() ]; int p = ib.position(); int l = ib.limit(); - System.arraycopy ( ib.array(), 0, ia, 0, ia.length ); - return IntBuffer.wrap ( ia, p, l - p ); + System.arraycopy (ib.array(), 0, ia, 0, ia.length); + return IntBuffer.wrap (ia, p, l - p); } else { return null; } } - private static List copyAssociations ( List ca ) { - if ( ca != null ) { - return new ArrayList ( ca ); + private static List copyAssociations (List ca) { + if (ca != null) { + return new ArrayList (ca); } else { return ca; } @@ -645,7 +645,7 @@ public class GlyphSequence implements Cl private static volatile Map<String,PredicationMerger> predicationMergers; interface PredicationMerger { - Object merge ( String key, Object v1, Object v2 ); + Object merge (String key, Object v1, Object v2); } /** @@ -656,10 +656,10 @@ public class GlyphSequence implements Cl * members of array are sub-interval starts, and odd members are sub-interval * ends (exclusive) */ - public CharAssociation ( int offset, int count, int[] subIntervals ) { + public CharAssociation (int offset, int count, int[] subIntervals) { this.offset = offset; this.count = count; - this.subIntervals = ( ( subIntervals != null ) && ( subIntervals.length > 2 ) ) ? subIntervals : null; + this.subIntervals = ((subIntervals != null) && (subIntervals.length > 2)) ? subIntervals : null; } /** @@ -667,8 +667,8 @@ public class GlyphSequence implements Cl * @param offset into array of UTF-16 code elements (in associated CharSequence) * @param count of UTF-16 character code elements (in associated CharSequence) */ - public CharAssociation ( int offset, int count ) { - this ( offset, count, null ); + public CharAssociation (int offset, int count) { + this (offset, count, null); } /** @@ -677,8 +677,8 @@ public class GlyphSequence implements Cl * members of array are sub-interval starts, and odd members are sub-interval * ends (exclusive) */ - public CharAssociation ( int[] subIntervals ) { - this ( getSubIntervalsStart ( subIntervals ), getSubIntervalsLength ( subIntervals ), subIntervals ); + public CharAssociation (int[] subIntervals) { + this (getSubIntervalsStart (subIntervals), getSubIntervalsLength (subIntervals), subIntervals); } /** @return offset (start of association interval) */ @@ -713,7 +713,7 @@ public class GlyphSequence implements Cl /** @return count of subintervals of disjoint association */ public int getSubIntervalCount() { - return ( subIntervals != null ) ? ( subIntervals.length / 2 ) : 0; + return (subIntervals != null) ? (subIntervals.length / 2) : 0; } /** @@ -721,19 +721,19 @@ public class GlyphSequence implements Cl * @param count length of interval * @return true if this association is contained within [offset,offset+count) */ - public boolean contained ( int offset, int count ) { + public boolean contained (int offset, int count) { int s = offset; int e = offset + count; - if ( ! isDisjoint() ) { + if (! isDisjoint()) { int s0 = getStart(); int e0 = getEnd(); - return ( s0 >= s ) && ( e0 <= e ); + return (s0 >= s) && (e0 <= e); } else { int ns = getSubIntervalCount(); - for ( int i = 0; i < ns; i++ ) { + for (int i = 0; i < ns; i++) { int s0 = subIntervals [ 2 * i + 0 ]; int e0 = subIntervals [ 2 * i + 1 ]; - if ( ( s0 >= s ) && ( e0 <= e ) ) { + if ((s0 >= s) && (e0 <= e)) { return true; } } @@ -746,12 +746,12 @@ public class GlyphSequence implements Cl * @param key predication key * @param value predication value */ - public void setPredication ( String key, Object value ) { - if ( predications == null ) { + public void setPredication (String key, Object value) { + if (predications == null) { predications = new HashMap<String,Object>(); } - if ( predications != null ) { - predications.put ( key, value ); + if (predications != null) { + predications.put (key, value); } } @@ -760,9 +760,9 @@ public class GlyphSequence implements Cl * @param key predication key * @return predication KEY at OFFSET or null if none exists */ - public Object getPredication ( String key ) { - if ( predications != null ) { - return predications.get ( key ); + public Object getPredication (String key) { + if (predications != null) { + return predications.get (key); } else { return null; } @@ -773,17 +773,17 @@ public class GlyphSequence implements Cl * @param key predication key * @param value predication value */ - public void mergePredication ( String key, Object value ) { - if ( predications == null ) { + public void mergePredication (String key, Object value) { + if (predications == null) { predications = new HashMap<String,Object>(); } - if ( predications != null ) { - if ( predications.containsKey ( key ) ) { - Object v1 = predications.get ( key ); + if (predications != null) { + if (predications.containsKey (key)) { + Object v1 = predications.get (key); Object v2 = value; - predications.put ( key, mergePredicationValues ( key, v1, v2 ) ); + predications.put (key, mergePredicationValues (key, v1, v2)); } else { - predications.put ( key, value ); + predications.put (key, value); } } } @@ -796,11 +796,11 @@ public class GlyphSequence implements Cl * @param v2 second (to be merged) predication value * @return merged value */ - public static Object mergePredicationValues ( String key, Object v1, Object v2 ) { - PredicationMerger pm = getPredicationMerger ( key ); - if ( pm != null ) { - return pm.merge ( key, v1, v2 ); - } else if ( v2 != null ) { + public static Object mergePredicationValues (String key, Object v1, Object v2) { + PredicationMerger pm = getPredicationMerger (key); + if (pm != null) { + return pm.merge (key, v1, v2); + } else if (v2 != null) { return v2; } else { return v1; @@ -811,10 +811,10 @@ public class GlyphSequence implements Cl * Merge predications from another CA. * @param ca from which to merge */ - public void mergePredications ( CharAssociation ca ) { - if ( ca.predications != null ) { - for ( Map.Entry<String,Object> e : ca.predications.entrySet() ) { - mergePredication ( e.getKey(), e.getValue() ); + public void mergePredications (CharAssociation ca) { + if (ca.predications != null) { + for (Map.Entry<String,Object> e : ca.predications.entrySet()) { + mergePredication (e.getKey(), e.getValue()); } } } @@ -823,11 +823,11 @@ public class GlyphSequence implements Cl public Object clone() { try { CharAssociation ca = (CharAssociation) super.clone(); - if ( predications != null ) { - ca.predications = new HashMap<String,Object> ( predications ); + if (predications != null) { + ca.predications = new HashMap<String,Object> (predications); } return ca; - } catch ( CloneNotSupportedException e ) { + } catch (CloneNotSupportedException e) { return null; } } @@ -837,12 +837,12 @@ public class GlyphSequence implements Cl * @param key for predication merger * @param pm predication merger */ - public static void setPredicationMerger ( String key, PredicationMerger pm ) { - if ( predicationMergers == null ) { + public static void setPredicationMerger (String key, PredicationMerger pm) { + if (predicationMergers == null) { predicationMergers = new HashMap<String,PredicationMerger>(); } - if ( predicationMergers != null ) { - predicationMergers.put ( key, pm ); + if (predicationMergers != null) { + predicationMergers.put (key, pm); } } @@ -851,9 +851,9 @@ public class GlyphSequence implements Cl * @param key for predication merger * @return predication merger or null if none exists */ - public static PredicationMerger getPredicationMerger ( String key ) { - if ( predicationMergers != null ) { - return predicationMergers.get ( key ); + public static PredicationMerger getPredicationMerger (String key) { + if (predicationMergers != null) { + return predicationMergers.get (key); } else { return null; } @@ -865,9 +865,9 @@ public class GlyphSequence implements Cl * @param repeat count * @return array of replicated associations */ - public static CharAssociation[] replicate ( CharAssociation a, int repeat ) { + public static CharAssociation[] replicate (CharAssociation a, int repeat) { CharAssociation[] aa = new CharAssociation [ repeat ]; - for ( int i = 0, n = aa.length; i < n; i++ ) { + for (int i = 0, n = aa.length; i < n; i++) { aa [ i ] = (CharAssociation) a.clone(); } return aa; @@ -879,71 +879,71 @@ public class GlyphSequence implements Cl * @param aa array of associations to join * @return (possibly disjoint) association containing joined associations */ - public static CharAssociation join ( CharAssociation[] aa ) { + public static CharAssociation join (CharAssociation[] aa) { CharAssociation ca; // extract sorted intervals - int[] ia = extractIntervals ( aa ); - if ( ( ia == null ) || ( ia.length == 0 ) ) { - ca = new CharAssociation ( 0, 0 ); - } else if ( ia.length == 2 ) { + int[] ia = extractIntervals (aa); + if ((ia == null) || (ia.length == 0)) { + ca = new CharAssociation (0, 0); + } else if (ia.length == 2) { int s = ia[0]; int e = ia[1]; - ca = new CharAssociation ( s, e - s ); + ca = new CharAssociation (s, e - s); } else { - ca = new CharAssociation ( mergeIntervals ( ia ) ); + ca = new CharAssociation (mergeIntervals (ia)); } - return mergePredicates ( ca, aa ); + return mergePredicates (ca, aa); } - private static CharAssociation mergePredicates ( CharAssociation ca, CharAssociation[] aa ) { - for ( CharAssociation a : aa ) { - ca.mergePredications ( a ); + private static CharAssociation mergePredicates (CharAssociation ca, CharAssociation[] aa) { + for (CharAssociation a : aa) { + ca.mergePredications (a); } return ca; } - private static int getSubIntervalsStart ( int[] ia ) { + private static int getSubIntervalsStart (int[] ia) { int us = Integer.MAX_VALUE; int ue = Integer.MIN_VALUE; - if ( ia != null ) { - for ( int i = 0, n = ia.length; i < n; i += 2 ) { + if (ia != null) { + for (int i = 0, n = ia.length; i < n; i += 2) { int s = ia [ i + 0 ]; int e = ia [ i + 1 ]; - if ( s < us ) { + if (s < us) { us = s; } - if ( e > ue ) { + if (e > ue) { ue = e; } } - if ( ue < 0 ) { + if (ue < 0) { ue = 0; } - if ( us > ue ) { + if (us > ue) { us = ue; } } return us; } - private static int getSubIntervalsLength ( int[] ia ) { + private static int getSubIntervalsLength (int[] ia) { int us = Integer.MAX_VALUE; int ue = Integer.MIN_VALUE; - if ( ia != null ) { - for ( int i = 0, n = ia.length; i < n; i += 2 ) { + if (ia != null) { + for (int i = 0, n = ia.length; i < n; i += 2) { int s = ia [ i + 0 ]; int e = ia [ i + 1 ]; - if ( s < us ) { + if (s < us) { us = s; } - if ( e > ue ) { + if (e > ue) { ue = e; } } - if ( ue < 0 ) { + if (ue < 0) { ue = 0; } - if ( us > ue ) { + if (us > ue) { us = ue; } } @@ -953,11 +953,11 @@ public class GlyphSequence implements Cl /** * Extract sorted sub-intervals. */ - private static int[] extractIntervals ( CharAssociation[] aa ) { + private static int[] extractIntervals (CharAssociation[] aa) { int ni = 0; - for ( int i = 0, n = aa.length; i < n; i++ ) { + for (int i = 0, n = aa.length; i < n; i++) { CharAssociation a = aa [ i ]; - if ( a.isDisjoint() ) { + if (a.isDisjoint()) { ni += a.getSubIntervalCount(); } else { ni += 1; @@ -965,11 +965,11 @@ public class GlyphSequence implements Cl } int[] sa = new int [ ni ]; int[] ea = new int [ ni ]; - for ( int i = 0, k = 0; i < aa.length; i++ ) { + for (int i = 0, k = 0; i < aa.length; i++) { CharAssociation a = aa [ i ]; - if ( a.isDisjoint() ) { + if (a.isDisjoint()) { int[] da = a.getSubIntervals(); - for ( int j = 0; j < da.length; j += 2 ) { + for (int j = 0; j < da.length; j += 2) { sa [ k ] = da [ j + 0 ]; ea [ k ] = da [ j + 1 ]; k++; @@ -980,7 +980,7 @@ public class GlyphSequence implements Cl k++; } } - return sortIntervals ( sa, ea ); + return sortIntervals (sa, ea); } private static final int[] sortIncrements16 // CSOK: ConstantNameCheck @@ -992,23 +992,23 @@ public class GlyphSequence implements Cl /** * Sort sub-intervals using modified Shell Sort. */ - private static int[] sortIntervals ( int[] sa, int[] ea ) { + private static int[] sortIntervals (int[] sa, int[] ea) { assert sa != null; assert ea != null; assert sa.length == ea.length; int ni = sa.length; - int[] incr = ( ni < 21 ) ? sortIncrements03 : sortIncrements16; - for ( int k = 0; k < incr.length; k++ ) { - for ( int h = incr [ k ], i = h, n = ni, j; i < n; i++ ) { + int[] incr = (ni < 21) ? sortIncrements03 : sortIncrements16; + for (int k = 0; k < incr.length; k++) { + for (int h = incr [ k ], i = h, n = ni, j; i < n; i++) { int s1 = sa [ i ]; int e1 = ea [ i ]; - for ( j = i; j >= h; j -= h) { + for (j = i; j >= h; j -= h) { int s2 = sa [ j - h ]; int e2 = ea [ j - h ]; - if ( s2 > s1 ) { + if (s2 > s1) { sa [ j ] = s2; ea [ j ] = e2; - } else if ( ( s2 == s1 ) && ( e2 > e1 ) ) { + } else if ((s2 == s1) && (e2 > e1)) { sa [ j ] = s2; ea [ j ] = e2; } else { @@ -1020,9 +1020,9 @@ public class GlyphSequence implements Cl } } int[] ia = new int [ ni * 2 ]; - for ( int i = 0; i < ni; i++ ) { - ia [ ( i * 2 ) + 0 ] = sa [ i ]; - ia [ ( i * 2 ) + 1 ] = ea [ i ]; + for (int i = 0; i < ni; i++) { + ia [ (i * 2) + 0 ] = sa [ i ]; + ia [ (i * 2) + 1 ] = ea [ i ]; } return ia; } @@ -1030,7 +1030,7 @@ public class GlyphSequence implements Cl /** * Merge overlapping and abutting sub-intervals. */ - private static int[] mergeIntervals ( int[] ia ) { + private static int[] mergeIntervals (int[] ia) { int ni = ia.length; int i; int n; @@ -1038,33 +1038,33 @@ public class GlyphSequence implements Cl int is; int ie; // count merged sub-intervals - for ( i = 0, n = ni, nm = 0, is = ie = -1; i < n; i += 2 ) { + for (i = 0, n = ni, nm = 0, is = ie = -1; i < n; i += 2) { int s = ia [ i + 0 ]; int e = ia [ i + 1 ]; - if ( ( ie < 0 ) || ( s > ie ) ) { + if ((ie < 0) || (s > ie)) { is = s; ie = e; nm++; - } else if ( s >= is ) { - if ( e > ie ) { + } else if (s >= is) { + if (e > ie) { ie = e; } } } int[] mi = new int [ nm * 2 ]; // populate merged sub-intervals - for ( i = 0, n = ni, nm = 0, is = ie = -1; i < n; i += 2 ) { + for (i = 0, n = ni, nm = 0, is = ie = -1; i < n; i += 2) { int s = ia [ i + 0 ]; int e = ia [ i + 1 ]; int k = nm * 2; - if ( ( ie < 0 ) || ( s > ie ) ) { + if ((ie < 0) || (s > ie)) { is = s; ie = e; mi [ k + 0 ] = is; mi [ k + 1 ] = ie; nm++; - } else if ( s >= is ) { - if ( e > ie ) { + } else if (s >= is) { + if (e > ie) { ie = e; } mi [ k - 1 ] = ie;
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/complexscripts/util/GlyphTester.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/complexscripts/util/GlyphTester.java?rev=1466146&r1=1466145&r2=1466146&view=diff ============================================================================== --- xmlgraphics/fop/trunk/src/java/org/apache/fop/complexscripts/util/GlyphTester.java (original) +++ xmlgraphics/fop/trunk/src/java/org/apache/fop/complexscripts/util/GlyphTester.java Tue Apr 9 17:31:41 2013 @@ -32,6 +32,6 @@ public interface GlyphTester { * @param flags that apply to lookup in scope * @return true if test is satisfied */ - boolean test ( int gi, int flags ); + boolean test (int gi, int flags); } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
