git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1466146 13f79535-47bb-0310-9956-ffa450edef68tags/fop-2_0
@@ -155,7 +155,7 @@ | |||
<!-- ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... --> | |||
<!-- ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... --> | |||
<!-- <module name="MethodParamPad"/> produces 4316 new errors --> | |||
<module name="MethodParamPad"/> | |||
<!-- ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... --> | |||
<!-- ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... --> | |||
@@ -206,7 +206,7 @@ | |||
<!-- ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... --> | |||
<!-- ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... --> | |||
<!-- <module name="ParenPad"/> produces 16666 new errors --> | |||
<module name="ParenPad"/> | |||
<!-- ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... --> | |||
<!-- ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... --> |
@@ -140,72 +140,72 @@ public final class GenerateBidiClass { | |||
String line; | |||
int lineNumber = 0; | |||
TreeSet intervals = new TreeSet(); | |||
while ( ( line = b.readLine() ) != null ) { | |||
while ((line = b.readLine()) != null) { | |||
lineNumber++; | |||
if ( line.startsWith("#") ) { | |||
if (line.startsWith("#")) { | |||
continue; | |||
} else if ( line.length() == 0 ) { | |||
} else if (line.length() == 0) { | |||
continue; | |||
} else { | |||
if ( line.indexOf ( "#" ) != -1 ) { | |||
line = ( line.split ( "#" ) ) [ 0 ]; | |||
if (line.indexOf ("#") != -1) { | |||
line = (line.split ("#")) [ 0 ]; | |||
} | |||
String[] fa = line.split ( ";" ); | |||
if ( fa.length == 2 ) { | |||
int[] interval = parseInterval ( fa[0].trim() ); | |||
byte bidiClass = (byte) parseBidiClass ( fa[1].trim() ); | |||
if ( interval[1] == interval[0] ) { // singleton | |||
String[] fa = line.split (";"); | |||
if (fa.length == 2) { | |||
int[] interval = parseInterval (fa[0].trim()); | |||
byte bidiClass = (byte) parseBidiClass (fa[1].trim()); | |||
if (interval[1] == interval[0]) { // singleton | |||
int c = interval[0]; | |||
if ( c <= 0x00FF ) { | |||
if ( bcL1 [ c - 0x0000 ] == 0 ) { | |||
if (c <= 0x00FF) { | |||
if (bcL1 [ c - 0x0000 ] == 0) { | |||
bcL1 [ c - 0x0000 ] = bidiClass; | |||
} else { | |||
throw new Exception ( "duplicate singleton entry: " + c ); | |||
throw new Exception ("duplicate singleton entry: " + c); | |||
} | |||
} else if ( ( c >= 0x0590 ) && ( c <= 0x06FF ) ) { | |||
if ( bcR1 [ c - 0x0590 ] == 0 ) { | |||
} else if ((c >= 0x0590) && (c <= 0x06FF)) { | |||
if (bcR1 [ c - 0x0590 ] == 0) { | |||
bcR1 [ c - 0x0590 ] = bidiClass; | |||
} else { | |||
throw new Exception ( "duplicate singleton entry: " + c ); | |||
throw new Exception ("duplicate singleton entry: " + c); | |||
} | |||
} else { | |||
addInterval ( intervals, c, c, bidiClass ); | |||
addInterval (intervals, c, c, bidiClass); | |||
} | |||
} else { // non-singleton | |||
int s = interval[0]; | |||
int e = interval[1]; // inclusive | |||
if ( s <= 0x00FF ) { | |||
for ( int i = s; i <= e; i++ ) { | |||
if ( i <= 0x00FF ) { | |||
if ( bcL1 [ i - 0x0000 ] == 0 ) { | |||
if (s <= 0x00FF) { | |||
for (int i = s; i <= e; i++) { | |||
if (i <= 0x00FF) { | |||
if (bcL1 [ i - 0x0000 ] == 0) { | |||
bcL1 [ i - 0x0000 ] = bidiClass; | |||
} else { | |||
throw new Exception ( "duplicate singleton entry: " + i ); | |||
throw new Exception ("duplicate singleton entry: " + i); | |||
} | |||
} else { | |||
addInterval ( intervals, i, e, bidiClass ); | |||
addInterval (intervals, i, e, bidiClass); | |||
break; | |||
} | |||
} | |||
} else if ( ( s >= 0x0590 ) && ( s <= 0x06FF ) ) { | |||
for ( int i = s; i <= e; i++ ) { | |||
if ( i <= 0x06FF ) { | |||
if ( bcR1 [ i - 0x0590 ] == 0 ) { | |||
} else if ((s >= 0x0590) && (s <= 0x06FF)) { | |||
for (int i = s; i <= e; i++) { | |||
if (i <= 0x06FF) { | |||
if (bcR1 [ i - 0x0590 ] == 0) { | |||
bcR1 [ i - 0x0590 ] = bidiClass; | |||
} else { | |||
throw new Exception ( "duplicate singleton entry: " + i ); | |||
throw new Exception ("duplicate singleton entry: " + i); | |||
} | |||
} else { | |||
addInterval ( intervals, i, e, bidiClass ); | |||
addInterval (intervals, i, e, bidiClass); | |||
break; | |||
} | |||
} | |||
} else { | |||
addInterval ( intervals, s, e, bidiClass ); | |||
addInterval (intervals, s, e, bidiClass); | |||
} | |||
} | |||
} else { | |||
throw new Exception ( "bad syntax, line(" + lineNumber + "): " + line ); | |||
throw new Exception ("bad syntax, line(" + lineNumber + "): " + line); | |||
} | |||
} | |||
} | |||
@@ -215,7 +215,7 @@ public final class GenerateBidiClass { | |||
bcS1 = new int [ niv ]; | |||
bcE1 = new int [ niv ]; | |||
bcC1 = new byte [ niv ]; | |||
for ( Iterator it = intervals.iterator(); it.hasNext(); ivIndex++ ) { | |||
for (Iterator it = intervals.iterator(); it.hasNext(); ivIndex++) { | |||
Interval iv = (Interval) it.next(); | |||
bcS1[ivIndex] = iv.start; | |||
bcE1[ivIndex] = iv.end; | |||
@@ -225,219 +225,219 @@ public final class GenerateBidiClass { | |||
test(); | |||
} | |||
private static int[] parseInterval ( String interval ) throws Exception { | |||
private static int[] parseInterval (String interval) throws Exception { | |||
int s; | |||
int e; | |||
String[] fa = interval.split("\\.\\."); | |||
if ( fa.length == 1 ) { | |||
s = Integer.parseInt ( fa[0], 16 ); | |||
if (fa.length == 1) { | |||
s = Integer.parseInt (fa[0], 16); | |||
e = s; | |||
} else if ( fa.length == 2 ) { | |||
s = Integer.parseInt ( fa[0], 16 ); | |||
e = Integer.parseInt ( fa[1], 16 ); | |||
} else if (fa.length == 2) { | |||
s = Integer.parseInt (fa[0], 16); | |||
e = Integer.parseInt (fa[1], 16); | |||
} else { | |||
throw new Exception ( "bad interval syntax: " + interval ); | |||
throw new Exception ("bad interval syntax: " + interval); | |||
} | |||
if ( e < s ) { | |||
throw new Exception ( "bad interval, start must be less than or equal to end: " + interval ); | |||
if (e < s) { | |||
throw new Exception ("bad interval, start must be less than or equal to end: " + interval); | |||
} | |||
return new int[] {s, e}; | |||
} | |||
private static int parseBidiClass ( String bidiClass ) { | |||
private static int parseBidiClass (String bidiClass) { | |||
int bc = 0; | |||
if ( "L".equals ( bidiClass ) ) { | |||
if ("L".equals (bidiClass)) { | |||
bc = BidiConstants.L; | |||
} else if ( "LRE".equals ( bidiClass ) ) { | |||
} else if ("LRE".equals (bidiClass)) { | |||
bc = BidiConstants.LRE; | |||
} else if ( "LRO".equals ( bidiClass ) ) { | |||
} else if ("LRO".equals (bidiClass)) { | |||
bc = BidiConstants.LRO; | |||
} else if ( "R".equals ( bidiClass ) ) { | |||
} else if ("R".equals (bidiClass)) { | |||
bc = BidiConstants.R; | |||
} else if ( "AL".equals ( bidiClass ) ) { | |||
} else if ("AL".equals (bidiClass)) { | |||
bc = BidiConstants.AL; | |||
} else if ( "RLE".equals ( bidiClass ) ) { | |||
} else if ("RLE".equals (bidiClass)) { | |||
bc = BidiConstants.RLE; | |||
} else if ( "RLO".equals ( bidiClass ) ) { | |||
} else if ("RLO".equals (bidiClass)) { | |||
bc = BidiConstants.RLO; | |||
} else if ( "PDF".equals ( bidiClass ) ) { | |||
} else if ("PDF".equals (bidiClass)) { | |||
bc = BidiConstants.PDF; | |||
} else if ( "EN".equals ( bidiClass ) ) { | |||
} else if ("EN".equals (bidiClass)) { | |||
bc = BidiConstants.EN; | |||
} else if ( "ES".equals ( bidiClass ) ) { | |||
} else if ("ES".equals (bidiClass)) { | |||
bc = BidiConstants.ES; | |||
} else if ( "ET".equals ( bidiClass ) ) { | |||
} else if ("ET".equals (bidiClass)) { | |||
bc = BidiConstants.ET; | |||
} else if ( "AN".equals ( bidiClass ) ) { | |||
} else if ("AN".equals (bidiClass)) { | |||
bc = BidiConstants.AN; | |||
} else if ( "CS".equals ( bidiClass ) ) { | |||
} else if ("CS".equals (bidiClass)) { | |||
bc = BidiConstants.CS; | |||
} else if ( "NSM".equals ( bidiClass ) ) { | |||
} else if ("NSM".equals (bidiClass)) { | |||
bc = BidiConstants.NSM; | |||
} else if ( "BN".equals ( bidiClass ) ) { | |||
} else if ("BN".equals (bidiClass)) { | |||
bc = BidiConstants.BN; | |||
} else if ( "B".equals ( bidiClass ) ) { | |||
} else if ("B".equals (bidiClass)) { | |||
bc = BidiConstants.B; | |||
} else if ( "S".equals ( bidiClass ) ) { | |||
} else if ("S".equals (bidiClass)) { | |||
bc = BidiConstants.S; | |||
} else if ( "WS".equals ( bidiClass ) ) { | |||
} else if ("WS".equals (bidiClass)) { | |||
bc = BidiConstants.WS; | |||
} else if ( "ON".equals ( bidiClass ) ) { | |||
} else if ("ON".equals (bidiClass)) { | |||
bc = BidiConstants.ON; | |||
} else { | |||
throw new IllegalArgumentException ( "unknown bidi class: " + bidiClass ); | |||
throw new IllegalArgumentException ("unknown bidi class: " + bidiClass); | |||
} | |||
return bc; | |||
} | |||
private static void addInterval ( SortedSet intervals, int start, int end, int bidiClass ) { | |||
intervals.add ( new Interval ( start, end, bidiClass ) ); | |||
private static void addInterval (SortedSet intervals, int start, int end, int bidiClass) { | |||
intervals.add (new Interval (start, end, bidiClass)); | |||
} | |||
private static void dumpData ( PrintWriter out ) { | |||
private static void dumpData (PrintWriter out) { | |||
boolean first; | |||
StringBuffer sb = new StringBuffer(); | |||
// bcL1 | |||
first = true; | |||
sb.setLength(0); | |||
out.println ( "private static byte[] bcL1 = {" ); | |||
for ( int i = 0; i < bcL1.length; i++ ) { | |||
if ( ! first ) { | |||
sb.append ( "," ); | |||
out.println ("private static byte[] bcL1 = {"); | |||
for (int i = 0; i < bcL1.length; i++) { | |||
if (! first) { | |||
sb.append (","); | |||
} else { | |||
first = false; | |||
} | |||
sb.append ( bcL1[i] ); | |||
if ( sb.length() > 120 ) { | |||
sb.append (bcL1[i]); | |||
if (sb.length() > 120) { | |||
sb.append(','); | |||
out.println(sb); | |||
first = true; | |||
sb.setLength(0); | |||
} | |||
} | |||
if ( sb.length() > 0 ) { | |||
if (sb.length() > 0) { | |||
out.println(sb); | |||
} | |||
out.println ( "};" ); | |||
out.println ("};"); | |||
out.println(); | |||
// bcR1 | |||
first = true; | |||
sb.setLength(0); | |||
out.println ( "private static byte[] bcR1 = {" ); | |||
for ( int i = 0; i < bcR1.length; i++ ) { | |||
if ( ! first ) { | |||
sb.append ( "," ); | |||
out.println ("private static byte[] bcR1 = {"); | |||
for (int i = 0; i < bcR1.length; i++) { | |||
if (! first) { | |||
sb.append (","); | |||
} else { | |||
first = false; | |||
} | |||
sb.append ( bcR1[i] ); | |||
if ( sb.length() > 120 ) { | |||
sb.append (bcR1[i]); | |||
if (sb.length() > 120) { | |||
sb.append(','); | |||
out.println(sb); | |||
first = true; | |||
sb.setLength(0); | |||
} | |||
} | |||
if ( sb.length() > 0 ) { | |||
if (sb.length() > 0) { | |||
out.println(sb); | |||
} | |||
out.println ( "};" ); | |||
out.println ("};"); | |||
out.println(); | |||
// bcS1 | |||
first = true; | |||
sb.setLength(0); | |||
out.println ( "private static int[] bcS1 = {" ); | |||
for ( int i = 0; i < bcS1.length; i++ ) { | |||
if ( ! first ) { | |||
sb.append ( "," ); | |||
out.println ("private static int[] bcS1 = {"); | |||
for (int i = 0; i < bcS1.length; i++) { | |||
if (! first) { | |||
sb.append (","); | |||
} else { | |||
first = false; | |||
} | |||
sb.append ( bcS1[i] ); | |||
if ( sb.length() > 120 ) { | |||
sb.append (bcS1[i]); | |||
if (sb.length() > 120) { | |||
sb.append(','); | |||
out.println(sb); | |||
first = true; | |||
sb.setLength(0); | |||
} | |||
} | |||
if ( sb.length() > 0 ) { | |||
if (sb.length() > 0) { | |||
out.println(sb); | |||
} | |||
out.println ( "};" ); | |||
out.println ("};"); | |||
out.println(); | |||
// bcE1 | |||
first = true; | |||
sb.setLength(0); | |||
out.println ( "private static int[] bcE1 = {" ); | |||
for ( int i = 0; i < bcE1.length; i++ ) { | |||
if ( ! first ) { | |||
sb.append ( "," ); | |||
out.println ("private static int[] bcE1 = {"); | |||
for (int i = 0; i < bcE1.length; i++) { | |||
if (! first) { | |||
sb.append (","); | |||
} else { | |||
first = false; | |||
} | |||
sb.append ( bcE1[i] ); | |||
if ( sb.length() > 120 ) { | |||
sb.append (bcE1[i]); | |||
if (sb.length() > 120) { | |||
sb.append(','); | |||
out.println(sb); | |||
first = true; | |||
sb.setLength(0); | |||
} | |||
} | |||
if ( sb.length() > 0 ) { | |||
if (sb.length() > 0) { | |||
out.println(sb); | |||
} | |||
out.println ( "};" ); | |||
out.println ("};"); | |||
out.println(); | |||
// bcC1 | |||
first = true; | |||
sb.setLength(0); | |||
out.println ( "private static byte[] bcC1 = {" ); | |||
for ( int i = 0; i < bcC1.length; i++ ) { | |||
if ( ! first ) { | |||
sb.append ( "," ); | |||
out.println ("private static byte[] bcC1 = {"); | |||
for (int i = 0; i < bcC1.length; i++) { | |||
if (! first) { | |||
sb.append (","); | |||
} else { | |||
first = false; | |||
} | |||
sb.append ( bcC1[i] ); | |||
if ( sb.length() > 120 ) { | |||
sb.append (bcC1[i]); | |||
if (sb.length() > 120) { | |||
sb.append(','); | |||
out.println(sb); | |||
first = true; | |||
sb.setLength(0); | |||
} | |||
} | |||
if ( sb.length() > 0 ) { | |||
if (sb.length() > 0) { | |||
out.println(sb); | |||
} | |||
out.println ( "};" ); | |||
out.println ("};"); | |||
out.println(); | |||
} | |||
private static int getBidiClass ( int ch ) { | |||
if ( ch <= 0x00FF ) { | |||
private static int getBidiClass (int ch) { | |||
if (ch <= 0x00FF) { | |||
return bcL1 [ ch - 0x0000 ]; | |||
} else if ( ( ch >= 0x0590 ) && ( ch <= 0x06FF ) ) { | |||
} else if ((ch >= 0x0590) && (ch <= 0x06FF)) { | |||
return bcR1 [ ch - 0x0590 ]; | |||
} else { | |||
return getBidiClass ( ch, bcS1, bcE1, bcC1 ); | |||
return getBidiClass (ch, bcS1, bcE1, bcC1); | |||
} | |||
} | |||
private static int getBidiClass ( int ch, int[] sa, int[] ea, byte[] ca ) { | |||
int k = Arrays.binarySearch ( sa, ch ); | |||
if ( k >= 0 ) { | |||
private static int getBidiClass (int ch, int[] sa, int[] ea, byte[] ca) { | |||
int k = Arrays.binarySearch (sa, ch); | |||
if (k >= 0) { | |||
return ca [ k ]; | |||
} else { | |||
k = - ( k + 1 ); | |||
if ( k == 0 ) { | |||
k = - (k + 1); | |||
if (k == 0) { | |||
return BidiConstants.L; | |||
} else if ( ch <= ea [ k - 1 ] ) { | |||
} else if (ch <= ea [ k - 1 ]) { | |||
return ca [ k - 1 ]; | |||
} else { | |||
return BidiConstants.L; | |||
@@ -495,12 +495,12 @@ public final class GenerateBidiClass { | |||
}; | |||
private static void test() throws Exception { | |||
for ( int i = 0, n = testData.length / 2; i < n; i++ ) { | |||
for (int i = 0, n = testData.length / 2; i < n; i++) { | |||
int ch = testData [ i * 2 + 0 ]; | |||
int tc = testData [ i * 2 + 1 ]; | |||
int bc = getBidiClass ( ch ); | |||
if ( bc != tc ) { | |||
throw new Exception ( "test mapping failed for character (0x" + Integer.toHexString(ch) + "): expected " + tc + ", got " + bc ); | |||
int bc = getBidiClass (ch); | |||
if (bc != tc) { | |||
throw new Exception ("test mapping failed for character (0x" + Integer.toHexString(ch) + "): expected " + tc + ", got " + bc); | |||
} | |||
} | |||
} | |||
@@ -548,20 +548,20 @@ public final class GenerateBidiClass { | |||
int start; // CSOK: VisibilityModifier | |||
int end; // CSOK: VisibilityModifier | |||
int bidiClass; // CSOK: VisibilityModifier | |||
Interval ( int start, int end, int bidiClass ) { | |||
Interval (int start, int end, int bidiClass) { | |||
this.start = start; | |||
this.end = end; | |||
this.bidiClass = bidiClass; | |||
} | |||
public int compareTo ( Object o ) { | |||
public int compareTo (Object o) { | |||
Interval iv = (Interval) o; | |||
if ( start < iv.start ) { | |||
if (start < iv.start) { | |||
return -1; | |||
} else if ( start > iv.start ) { | |||
} else if (start > iv.start) { | |||
return 1; | |||
} else if ( end < iv.end ) { | |||
} else if (end < iv.end) { | |||
return -1; | |||
} else if ( end > iv.end ) { | |||
} else if (end > iv.end) { | |||
return 1; | |||
} else { | |||
return 0; |
@@ -83,7 +83,7 @@ public final class GenerateLineBreakUtils { | |||
* @param outFileName Name of the output file. | |||
* @throws Exception in case anything goes wrong. | |||
*/ | |||
private static void convertLineBreakProperties( // CSOK: MethodLength | |||
private static void convertLineBreakProperties(// CSOK: MethodLength | |||
String lineBreakFileName, | |||
String propertyValueFileName, | |||
String breakPairFileName, |
@@ -91,8 +91,8 @@ public class AFPBorderPainter extends AbstractAFPPainter { | |||
AFPLineDataInfo lineDataInfo = new AFPLineDataInfo(); | |||
lineDataInfo.setColor(borderPaintInfo.getColor()); | |||
lineDataInfo.setRotation(paintingState.getRotation()); | |||
lineDataInfo.setX1 ( Math.round(x1) ); | |||
lineDataInfo.setY1 ( Math.round(y1) ); | |||
lineDataInfo.setX1 (Math.round(x1)); | |||
lineDataInfo.setY1 (Math.round(y1)); | |||
float thickness; | |||
if (borderPaintInfo.isHorizontal()) { | |||
thickness = y2 - y1; | |||
@@ -107,68 +107,68 @@ public class AFPBorderPainter extends AbstractAFPPainter { | |||
int thickness3 = (int)Math.floor(thickness / 3f); | |||
lineDataInfo.setThickness(thickness3); | |||
if (borderPaintInfo.isHorizontal()) { | |||
lineDataInfo.setX2 ( Math.round(x2) ); | |||
lineDataInfo.setY2 ( lineDataInfo.getY1() ); | |||
lineDataInfo.setX2 (Math.round(x2)); | |||
lineDataInfo.setY2 (lineDataInfo.getY1()); | |||
dataStream.createLine(lineDataInfo); | |||
int distance = thickness3 * 2; | |||
lineDataInfo = new AFPLineDataInfo(lineDataInfo); | |||
lineDataInfo.setY1 ( lineDataInfo.getY1() + distance ); | |||
lineDataInfo.setY2 ( lineDataInfo.getY2() + distance ); | |||
lineDataInfo.setY1 (lineDataInfo.getY1() + distance); | |||
lineDataInfo.setY2 (lineDataInfo.getY2() + distance); | |||
dataStream.createLine(lineDataInfo); | |||
} else { | |||
lineDataInfo.setX2 ( lineDataInfo.getX1() ); | |||
lineDataInfo.setY2 ( Math.round(y2) ); | |||
lineDataInfo.setX2 (lineDataInfo.getX1()); | |||
lineDataInfo.setY2 (Math.round(y2)); | |||
dataStream.createLine(lineDataInfo); | |||
int distance = thickness3 * 2; | |||
lineDataInfo = new AFPLineDataInfo(lineDataInfo); | |||
lineDataInfo.setX1 ( lineDataInfo.getX1() + distance ); | |||
lineDataInfo.setX2 ( lineDataInfo.getX2() + distance ); | |||
lineDataInfo.setX1 (lineDataInfo.getX1() + distance); | |||
lineDataInfo.setX2 (lineDataInfo.getX2() + distance); | |||
dataStream.createLine(lineDataInfo); | |||
} | |||
break; | |||
case Constants.EN_DASHED: | |||
if (borderPaintInfo.isHorizontal()) { | |||
int dashWidth = (int) unitConv.pt2units(BorderPainter.dashWidthCalculator(w, h)); | |||
lineDataInfo.setX2 ( lineDataInfo.getX1() + dashWidth ); | |||
lineDataInfo.setY2 ( lineDataInfo.getY1() ); | |||
lineDataInfo.setX2 (lineDataInfo.getX1() + dashWidth); | |||
lineDataInfo.setY2 (lineDataInfo.getY1()); | |||
int ex2 = Math.round(x2); | |||
int spaceWidth = (int) (BorderPainter.DASHED_BORDER_SPACE_RATIO * dashWidth); | |||
while (lineDataInfo.getX2() <= ex2) { | |||
dataStream.createLine(lineDataInfo); | |||
lineDataInfo.setX1 ( lineDataInfo.getX2() + spaceWidth ); | |||
lineDataInfo.setX2 ( lineDataInfo.getX1() + dashWidth ); | |||
lineDataInfo.setX1 (lineDataInfo.getX2() + spaceWidth); | |||
lineDataInfo.setX2 (lineDataInfo.getX1() + dashWidth); | |||
} | |||
} else { | |||
int dashWidth = (int) unitConv.pt2units(BorderPainter.dashWidthCalculator(h, w)); | |||
lineDataInfo.setX2 ( lineDataInfo.getX1() ); | |||
lineDataInfo.setY2 ( lineDataInfo.getY1() + dashWidth ); | |||
lineDataInfo.setX2 (lineDataInfo.getX1()); | |||
lineDataInfo.setY2 (lineDataInfo.getY1() + dashWidth); | |||
int ey2 = Math.round(y2); | |||
int spaceWidth = (int) (BorderPainter.DASHED_BORDER_SPACE_RATIO * dashWidth); | |||
while (lineDataInfo.getY2() <= ey2) { | |||
dataStream.createLine(lineDataInfo); | |||
lineDataInfo.setY1 ( lineDataInfo.getY2() + spaceWidth ); | |||
lineDataInfo.setY2 ( lineDataInfo.getY1() + dashWidth ); | |||
lineDataInfo.setY1 (lineDataInfo.getY2() + spaceWidth); | |||
lineDataInfo.setY2 (lineDataInfo.getY1() + dashWidth); | |||
} | |||
} | |||
break; | |||
case Constants.EN_DOTTED: | |||
if (borderPaintInfo.isHorizontal()) { | |||
lineDataInfo.setX2 ( lineDataInfo.getX1() + lineDataInfo.getThickness() ); | |||
lineDataInfo.setY2 ( lineDataInfo.getY1() ); | |||
lineDataInfo.setX2 (lineDataInfo.getX1() + lineDataInfo.getThickness()); | |||
lineDataInfo.setY2 (lineDataInfo.getY1()); | |||
int ex2 = Math.round(x2); | |||
while (lineDataInfo.getX1() + lineDataInfo.getThickness() < ex2) { | |||
dataStream.createLine(lineDataInfo); | |||
lineDataInfo.setX1 ( lineDataInfo.getX1() + 3 * lineDataInfo.getThickness() ); | |||
lineDataInfo.setX2 ( lineDataInfo.getX1() + lineDataInfo.getThickness() ); | |||
lineDataInfo.setX1 (lineDataInfo.getX1() + 3 * lineDataInfo.getThickness()); | |||
lineDataInfo.setX2 (lineDataInfo.getX1() + lineDataInfo.getThickness()); | |||
} | |||
} else { | |||
lineDataInfo.setX2 ( lineDataInfo.getX1() ); | |||
lineDataInfo.setY2 ( lineDataInfo.getY1() + lineDataInfo.getThickness() ); | |||
lineDataInfo.setX2 (lineDataInfo.getX1()); | |||
lineDataInfo.setY2 (lineDataInfo.getY1() + lineDataInfo.getThickness()); | |||
int ey2 = Math.round(y2); | |||
while (lineDataInfo.getY1() + lineDataInfo.getThickness() < ey2) { | |||
dataStream.createLine(lineDataInfo); | |||
lineDataInfo.setY1 ( lineDataInfo.getY1() + 3 * lineDataInfo.getThickness() ); | |||
lineDataInfo.setY2 ( lineDataInfo.getY1() + lineDataInfo.getThickness() ); | |||
lineDataInfo.setY1 (lineDataInfo.getY1() + 3 * lineDataInfo.getThickness()); | |||
lineDataInfo.setY2 (lineDataInfo.getY1() + lineDataInfo.getThickness()); | |||
} | |||
} | |||
break; | |||
@@ -176,25 +176,25 @@ public class AFPBorderPainter extends AbstractAFPPainter { | |||
case Constants.EN_RIDGE: | |||
//TODO | |||
int yNew; | |||
lineDataInfo.setX2 ( Math.round(x2) ); | |||
lineDataInfo.setX2 (Math.round(x2)); | |||
float colFactor = (borderPaintInfo.getStyle() == Constants.EN_GROOVE ? 0.4f : -0.4f); | |||
float h3 = (y2 - y1) / 3; | |||
lineDataInfo.setColor | |||
( ColorUtil.lightenColor(borderPaintInfo.getColor(), -colFactor) ); | |||
lineDataInfo.setThickness ( Math.round(h3) ); | |||
(ColorUtil.lightenColor(borderPaintInfo.getColor(), -colFactor)); | |||
lineDataInfo.setThickness (Math.round(h3)); | |||
yNew = Math.round(y1); | |||
lineDataInfo.setY1 ( yNew ); | |||
lineDataInfo.setY2 ( yNew ); | |||
lineDataInfo.setY1 (yNew); | |||
lineDataInfo.setY2 (yNew); | |||
dataStream.createLine(lineDataInfo); | |||
lineDataInfo.setColor ( borderPaintInfo.getColor() ); | |||
lineDataInfo.setColor (borderPaintInfo.getColor()); | |||
yNew = Math.round(y1 + h3); | |||
lineDataInfo.setY1 ( yNew ); | |||
lineDataInfo.setY2 ( yNew ); | |||
lineDataInfo.setY1 (yNew); | |||
lineDataInfo.setY2 (yNew); | |||
dataStream.createLine(lineDataInfo); | |||
lineDataInfo.setColor ( ColorUtil.lightenColor(borderPaintInfo.getColor(), colFactor) ); | |||
lineDataInfo.setColor (ColorUtil.lightenColor(borderPaintInfo.getColor(), colFactor)); | |||
yNew = Math.round(y1 + h3 + h3); | |||
lineDataInfo.setY1 ( yNew ); | |||
lineDataInfo.setY2 ( yNew ); | |||
lineDataInfo.setY1 (yNew); | |||
lineDataInfo.setY2 (yNew); | |||
dataStream.createLine(lineDataInfo); | |||
break; | |||
case Constants.EN_HIDDEN: | |||
@@ -204,11 +204,11 @@ public class AFPBorderPainter extends AbstractAFPPainter { | |||
case Constants.EN_SOLID: | |||
default: | |||
if (borderPaintInfo.isHorizontal()) { | |||
lineDataInfo.setX2 ( Math.round(x2) ); | |||
lineDataInfo.setY2 ( lineDataInfo.getY1() ); | |||
lineDataInfo.setX2 (Math.round(x2)); | |||
lineDataInfo.setY2 (lineDataInfo.getY1()); | |||
} else { | |||
lineDataInfo.setX2 ( lineDataInfo.getX1() ); | |||
lineDataInfo.setY2 ( Math.round(y2) ); | |||
lineDataInfo.setX2 (lineDataInfo.getX1()); | |||
lineDataInfo.setY2 (Math.round(y2)); | |||
} | |||
dataStream.createLine(lineDataInfo); | |||
} |
@@ -53,39 +53,39 @@ public class AFPRectanglePainter extends AbstractAFPPainter { | |||
AffineTransform at = paintingState.getData().getTransform(); | |||
AFPLineDataInfo lineDataInfo = new AFPLineDataInfo(); | |||
lineDataInfo.setColor ( paintingState.getColor() ); | |||
lineDataInfo.setRotation ( paintingState.getRotation() ); | |||
lineDataInfo.setThickness ( Math.round(height) ); | |||
lineDataInfo.setColor (paintingState.getColor()); | |||
lineDataInfo.setRotation (paintingState.getRotation()); | |||
lineDataInfo.setThickness (Math.round(height)); | |||
switch (lineDataInfo.getRotation()) { | |||
case 90: | |||
lineDataInfo.setX1 ( Math.round((float)at.getTranslateY() + x) ); | |||
lineDataInfo.setX1 (Math.round((float)at.getTranslateY() + x)); | |||
yNew = pageWidth - Math.round((float)at.getTranslateX()) + Math.round(y); | |||
lineDataInfo.setY1 ( yNew ); | |||
lineDataInfo.setY2 ( yNew ); | |||
lineDataInfo.setX2 ( Math.round(width + (float)at.getTranslateY() + x) ); | |||
lineDataInfo.setY1 (yNew); | |||
lineDataInfo.setY2 (yNew); | |||
lineDataInfo.setX2 (Math.round(width + (float)at.getTranslateY() + x)); | |||
break; | |||
case 180: | |||
lineDataInfo.setX1 ( pageWidth - Math.round((float)at.getTranslateX() - x) ); | |||
lineDataInfo.setX1 (pageWidth - Math.round((float)at.getTranslateX() - x)); | |||
yNew = pageHeight - Math.round((float)at.getTranslateY() - y); | |||
lineDataInfo.setY1 ( yNew ); | |||
lineDataInfo.setY2 ( yNew ); | |||
lineDataInfo.setX2 ( pageWidth - Math.round((float)at.getTranslateX() - x - width) ); | |||
lineDataInfo.setY1 (yNew); | |||
lineDataInfo.setY2 (yNew); | |||
lineDataInfo.setX2 (pageWidth - Math.round((float)at.getTranslateX() - x - width)); | |||
break; | |||
case 270: | |||
lineDataInfo.setX1 ( pageHeight - Math.round((float)at.getTranslateY() - x) ); | |||
lineDataInfo.setX1 (pageHeight - Math.round((float)at.getTranslateY() - x)); | |||
yNew = Math.round((float)at.getTranslateX() + y); | |||
lineDataInfo.setY1 ( yNew ); | |||
lineDataInfo.setY2 ( yNew ); | |||
lineDataInfo.setX2 ( pageHeight - Math.round((float)at.getTranslateY() - x - width) ); | |||
lineDataInfo.setY1 (yNew); | |||
lineDataInfo.setY2 (yNew); | |||
lineDataInfo.setX2 (pageHeight - Math.round((float)at.getTranslateY() - x - width)); | |||
break; | |||
case 0: | |||
default: | |||
lineDataInfo.setX1 ( Math.round((float)at.getTranslateX() + x) ); | |||
lineDataInfo.setX1 (Math.round((float)at.getTranslateX() + x)); | |||
yNew = Math.round((float)at.getTranslateY() + y); | |||
lineDataInfo.setY1 ( yNew ); | |||
lineDataInfo.setY2 ( yNew ); | |||
lineDataInfo.setX2 ( Math.round((float)at.getTranslateX() + x + width) ); | |||
lineDataInfo.setY1 (yNew); | |||
lineDataInfo.setY2 (yNew); | |||
lineDataInfo.setX2 (Math.round((float)at.getTranslateX() + x + width)); | |||
break; | |||
} | |||
dataStream.createLine(lineDataInfo); |
@@ -234,7 +234,7 @@ public class Factory { | |||
public ActiveEnvironmentGroup createActiveEnvironmentGroup( | |||
int width, int height, int widthRes, int heightRes) { | |||
String name = ACTIVE_ENVIRONMENT_GROUP_NAME_PREFIX | |||
+ StringUtils.lpad(String.valueOf(++activeEnvironmentGroupCount ), '0', 5); | |||
+ StringUtils.lpad(String.valueOf(++activeEnvironmentGroupCount), '0', 5); | |||
return new ActiveEnvironmentGroup(this, name, width, height, widthRes, heightRes); | |||
} | |||
@@ -195,8 +195,8 @@ public class GraphicsObject extends AbstractDataObject { | |||
* @param lineWidth the line width multiplier | |||
*/ | |||
public void setLineWidth(float lineWidth) { | |||
float epsilon = Float.intBitsToFloat ( 0x00800000 ); // Float.MIN_NORMAL (JDK1.6) | |||
if ( Math.abs ( graphicsState.lineWidth - lineWidth ) > epsilon ) { | |||
float epsilon = Float.intBitsToFloat (0x00800000); // Float.MIN_NORMAL (JDK1.6) | |||
if (Math.abs (graphicsState.lineWidth - lineWidth) > epsilon) { | |||
addObject(new GraphicsSetFractionalLineWidth(lineWidth)); | |||
graphicsState.lineWidth = lineWidth; | |||
} |
@@ -35,7 +35,7 @@ public class EncodingTriplet extends AbstractTriplet { | |||
/** | |||
* @param encoding the CCSID character set encoding | |||
*/ | |||
public EncodingTriplet( int encoding) { | |||
public EncodingTriplet(int encoding) { | |||
super(CODED_GRAPHIC_CHARACTER_SET_GLOBAL_IDENTIFIER); | |||
this.encoding = encoding; | |||
} |
@@ -77,23 +77,23 @@ public class DTDEntityResolver implements EntityResolver { | |||
throws IOException { | |||
URL resource = null; | |||
if ( AFP_DTD_1_2_ID.equals(publicId) ) { | |||
resource = getResource( AFP_DTD_1_2_RESOURCE ); | |||
} else if ( AFP_DTD_1_1_ID.equals(publicId) ) { | |||
resource = getResource( AFP_DTD_1_1_RESOURCE ); | |||
} else if ( AFP_DTD_1_0_ID.equals(publicId) ) { | |||
if (AFP_DTD_1_2_ID.equals(publicId)) { | |||
resource = getResource(AFP_DTD_1_2_RESOURCE); | |||
} else if (AFP_DTD_1_1_ID.equals(publicId)) { | |||
resource = getResource(AFP_DTD_1_1_RESOURCE); | |||
} else if (AFP_DTD_1_0_ID.equals(publicId)) { | |||
throw new FontRuntimeException( | |||
"The AFP Installed Font Definition 1.0 DTD is not longer supported" ); | |||
} else if (systemId != null && systemId.indexOf("afp-fonts.dtd") >= 0 ) { | |||
"The AFP Installed Font Definition 1.0 DTD is not longer supported"); | |||
} else if (systemId != null && systemId.indexOf("afp-fonts.dtd") >= 0) { | |||
throw new FontRuntimeException( | |||
"The AFP Installed Font Definition DTD must be specified using the public id" ); | |||
"The AFP Installed Font Definition DTD must be specified using the public id"); | |||
} else { | |||
return null; | |||
} | |||
InputSource inputSource = new InputSource( resource.openStream() ); | |||
inputSource.setPublicId( publicId ); | |||
inputSource.setSystemId( systemId ); | |||
InputSource inputSource = new InputSource(resource.openStream()); | |||
inputSource.setPublicId(publicId); | |||
inputSource.setSystemId(systemId); | |||
return inputSource; | |||
} | |||
@@ -111,10 +111,10 @@ public class DTDEntityResolver implements EntityResolver { | |||
cl = ClassLoader.getSystemClassLoader(); | |||
} | |||
URL resource = cl.getResource( resourcePath ); | |||
URL resource = cl.getResource(resourcePath); | |||
if (resource == null) { | |||
throw new FontRuntimeException( "Resource " + resourcePath | |||
+ "could not be found on the classpath" ); | |||
throw new FontRuntimeException("Resource " + resourcePath | |||
+ "could not be found on the classpath"); | |||
} | |||
return resource; |
@@ -225,7 +225,7 @@ public class Area extends AreaTreeObject implements Serializable { | |||
* | |||
* @param bidiLevel the bidirectional embedding level | |||
*/ | |||
public void setBidiLevel ( int bidiLevel ) { | |||
public void setBidiLevel (int bidiLevel) { | |||
this.bidiLevel = bidiLevel; | |||
} | |||
@@ -412,9 +412,9 @@ public class Area extends AreaTreeObject implements Serializable { | |||
* | |||
* @param traits the map of traits | |||
*/ | |||
public void setTraits ( Map traits ) { | |||
if ( traits != null ) { | |||
this.traits = new TreeMap<Integer, Object>( traits ); | |||
public void setTraits (Map traits) { | |||
if (traits != null) { | |||
this.traits = new TreeMap<Integer, Object>(traits); | |||
} else { | |||
this.traits = null; | |||
} |
@@ -798,8 +798,8 @@ public class AreaTreeParser { | |||
= XMLUtil.getAttributeAsPositionAdjustments(lastAttributes, "position-adjust"); | |||
content.flip(); | |||
WordArea word = new WordArea | |||
( offset, level, content.toString().trim(), letterAdjust, | |||
null, gposAdjustments, reversed ); | |||
(offset, level, content.toString().trim(), letterAdjust, | |||
null, gposAdjustments, reversed); | |||
AbstractTextArea text = getCurrentText(); | |||
word.setParentArea(text); | |||
text.addChildArea(word); | |||
@@ -851,7 +851,7 @@ public class AreaTreeParser { | |||
setTraits(attributes, leader, SUBSET_COLOR); | |||
setTraits(attributes, leader, SUBSET_FONT); | |||
leader.setBlockProgressionOffset | |||
( XMLUtil.getAttributeAsInt(attributes, "offset", 0) ); | |||
(XMLUtil.getAttributeAsInt(attributes, "offset", 0)); | |||
String ruleStyle = attributes.getValue("ruleStyle"); | |||
if (ruleStyle != null) { | |||
leader.setRuleStyle(ruleStyle); | |||
@@ -876,7 +876,7 @@ public class AreaTreeParser { | |||
viewport.setContentPosition(XMLUtil.getAttributeAsRectangle2D(attributes, "pos")); | |||
viewport.setClip(XMLUtil.getAttributeAsBoolean(attributes, "clip", false)); | |||
viewport.setBlockProgressionOffset | |||
( XMLUtil.getAttributeAsInt(attributes, "offset", 0) ); | |||
(XMLUtil.getAttributeAsInt(attributes, "offset", 0)); | |||
Area parent = (Area)areaStack.peek(); | |||
parent.addChildArea(viewport); | |||
areaStack.push(viewport); |
@@ -146,8 +146,8 @@ public class BodyRegion extends RegionReference { | |||
* @param wmtg a WM traits getter | |||
*/ | |||
public void setWritingModeTraits(WritingModeTraitsGetter wmtg) { | |||
if ( getMainReference() != null ) { | |||
getMainReference().setWritingModeTraits ( wmtg ); | |||
if (getMainReference() != null) { | |||
getMainReference().setWritingModeTraits (wmtg); | |||
} | |||
} | |||
@@ -341,7 +341,7 @@ public class CTM implements Serializable { | |||
* can set ipd and bpd appropriately based on the writing mode. | |||
*/ | |||
switch ( writingMode.getEnumValue() ) { | |||
switch (writingMode.getEnumValue()) { | |||
case EN_TB_LR: | |||
case EN_TB_RL: | |||
reldims.ipd = height; |
@@ -130,12 +130,12 @@ public class LineArea extends Area { | |||
* <p> Used by bidirectional processing after line area consituent reordering.</p> | |||
* @param inlineAreas the list of inline areas | |||
*/ | |||
public void setInlineAreas ( List inlineAreas ) { | |||
for ( Iterator<InlineArea> it = inlineAreas.iterator(); it.hasNext();) { | |||
public void setInlineAreas (List inlineAreas) { | |||
for (Iterator<InlineArea> it = inlineAreas.iterator(); it.hasNext();) { | |||
InlineArea ia = it.next(); | |||
Area pa = ia.getParentArea(); | |||
if ( pa == null ) { | |||
ia.setParentArea ( this ); | |||
if (pa == null) { | |||
ia.setParentArea (this); | |||
} else { | |||
assert pa == this; | |||
} |
@@ -80,7 +80,7 @@ public class LinkResolver implements Resolvable, Serializable { | |||
public void resolveIDRef(String id, PageViewport pv) { | |||
if (idRef.equals(id) && pv != null) { | |||
resolved = true; | |||
if ( area != null ) { | |||
if (area != null) { | |||
Trait.InternalLink iLink = new Trait.InternalLink(pv.getKey(), idRef); | |||
area.addTrait(Trait.INTERNAL_LINK, iLink); | |||
area = null; // break circular reference from basic link area to this resolver | |||
@@ -95,17 +95,17 @@ public class LinkResolver implements Resolvable, Serializable { | |||
* @param dependent resolvable | |||
*/ | |||
public void addDependent(Resolvable dependent) { | |||
if ( dependents == null ) { | |||
if (dependents == null) { | |||
dependents = new ArrayList<Resolvable>(); | |||
} | |||
dependents.add(dependent); | |||
} | |||
private void resolveDependents(String id, PageViewport pv) { | |||
if ( dependents != null ) { | |||
if (dependents != null) { | |||
List<PageViewport> pages = new ArrayList<PageViewport>(); | |||
pages.add(pv); | |||
for ( Resolvable r : dependents ) { | |||
for (Resolvable r : dependents) { | |||
r.resolveIDRef(id, pages); | |||
} | |||
} |
@@ -131,8 +131,8 @@ public class MainReference extends Area { | |||
* @param wmtg a WM traits getter | |||
*/ | |||
public void setWritingModeTraits(WritingModeTraitsGetter wmtg) { | |||
for ( Span s : getSpans() ) { | |||
s.setWritingModeTraits ( wmtg ); | |||
for (Span s : getSpans()) { | |||
s.setWritingModeTraits (wmtg); | |||
} | |||
} | |||
@@ -519,7 +519,7 @@ public class PageViewport extends AreaTreeObject implements Resolvable { | |||
* @param wmtg a WM traits getter | |||
*/ | |||
public void setWritingModeTraits(WritingModeTraitsGetter wmtg) { | |||
if ( page != null ) { | |||
if (page != null) { | |||
page.setWritingModeTraits(wmtg); | |||
} | |||
} |
@@ -193,16 +193,16 @@ public class Span extends Area { | |||
* @param wmtg a WM traits getter | |||
*/ | |||
public void setWritingModeTraits(WritingModeTraitsGetter wmtg) { | |||
switch ( wmtg.getColumnProgressionDirection().getEnumValue() ) { | |||
switch (wmtg.getColumnProgressionDirection().getEnumValue()) { | |||
case Constants.EN_RL: | |||
setBidiLevel(1); | |||
for ( Iterator<NormalFlow> it = flowAreas.iterator(); it.hasNext();) { | |||
for (Iterator<NormalFlow> it = flowAreas.iterator(); it.hasNext();) { | |||
it.next().setBidiLevel(1); | |||
} | |||
break; | |||
default: | |||
resetBidiLevel(); | |||
for ( Iterator<NormalFlow> it = flowAreas.iterator(); it.hasNext();) { | |||
for (Iterator<NormalFlow> it = flowAreas.iterator(); it.hasNext();) { | |||
it.next().resetBidiLevel(); | |||
} | |||
break; |
@@ -58,7 +58,7 @@ public class BasicLinkArea extends InlineParent { | |||
* @param resolver the link resolver that will resolve this basic link or null | |||
*/ | |||
public void setResolver(LinkResolver resolver) { | |||
assert ( resolver == null ) || ( this.resolver == null ); | |||
assert (resolver == null) || (this.resolver == null); | |||
this.resolver = resolver; | |||
} | |||
@@ -106,7 +106,7 @@ public class InlineArea extends Area { | |||
* Default constructor for inline area. | |||
*/ | |||
public InlineArea() { | |||
this ( 0, -1 ); | |||
this (0, -1); | |||
} | |||
/** | |||
@@ -114,7 +114,7 @@ public class InlineArea extends Area { | |||
* @param blockProgressionOffset a block progression offset or zero | |||
* @param bidiLevel a resolved bidi level or -1 | |||
*/ | |||
protected InlineArea ( int blockProgressionOffset, int bidiLevel ) { | |||
protected InlineArea (int blockProgressionOffset, int bidiLevel) { | |||
this.blockProgressionOffset = blockProgressionOffset; | |||
setBidiLevel(bidiLevel); | |||
} | |||
@@ -311,9 +311,9 @@ public class InlineArea extends Area { | |||
* @param runs current list of inline runs | |||
* @return modified list of inline runs, having appended new run | |||
*/ | |||
public List collectInlineRuns ( List runs ) { | |||
public List collectInlineRuns (List runs) { | |||
assert runs != null; | |||
runs.add ( new InlineRun ( this, new int[] {getBidiLevel()}) ); | |||
runs.add (new InlineRun (this, new int[] {getBidiLevel()})); | |||
return runs; | |||
} | |||
@@ -322,8 +322,8 @@ public class InlineArea extends Area { | |||
* @param ia inline area to test | |||
* @return true if specified inline area is an ancestor or same as this area | |||
*/ | |||
public boolean isAncestorOrSelf ( InlineArea ia ) { | |||
return ( ia == this ) || isAncestor ( ia ); | |||
public boolean isAncestorOrSelf (InlineArea ia) { | |||
return (ia == this) || isAncestor (ia); | |||
} | |||
/** | |||
@@ -331,12 +331,12 @@ public class InlineArea extends Area { | |||
* @param ia inline area to test | |||
* @return true if specified inline area is an ancestor of this area | |||
*/ | |||
public boolean isAncestor ( InlineArea ia ) { | |||
for ( Area p = getParentArea(); p != null;) { | |||
if ( p == ia ) { | |||
public boolean isAncestor (InlineArea ia) { | |||
for (Area p = getParentArea(); p != null;) { | |||
if (p == ia) { | |||
return true; | |||
} else if ( p instanceof InlineArea ) { | |||
p = ( (InlineArea) p ).getParentArea(); | |||
} else if (p instanceof InlineArea) { | |||
p = ((InlineArea) p).getParentArea(); | |||
} else { | |||
p = null; | |||
} |
@@ -64,7 +64,7 @@ public class InlineParent extends InlineArea { | |||
if (autoSize) { | |||
increaseIPD(childArea.getAllocIPD()); | |||
} | |||
updateLevel ( childArea.getBidiLevel() ); | |||
updateLevel (childArea.getBidiLevel()); | |||
int childOffset = childArea.getVirtualOffset(); | |||
minChildOffset = Math.min(minChildOffset, childOffset); | |||
maxAfterEdge = Math.max(maxAfterEdge, childOffset + childArea.getVirtualBPD()); | |||
@@ -114,10 +114,10 @@ public class InlineParent extends InlineArea { | |||
} | |||
@Override | |||
public List collectInlineRuns ( List runs ) { | |||
for ( Iterator<InlineArea> it = getChildAreas().iterator(); it.hasNext();) { | |||
public List collectInlineRuns (List runs) { | |||
for (Iterator<InlineArea> it = getChildAreas().iterator(); it.hasNext();) { | |||
InlineArea ia = it.next(); | |||
runs = ia.collectInlineRuns ( runs ); | |||
runs = ia.collectInlineRuns (runs); | |||
} | |||
return runs; | |||
} | |||
@@ -127,20 +127,20 @@ public class InlineParent extends InlineArea { | |||
* signalling that they will inherit the level of their parent text area. | |||
*/ | |||
public void resetChildrenLevel() { | |||
for ( Iterator it = inlines.iterator(); it.hasNext();) { | |||
( (InlineArea) it.next() ) .resetBidiLevel(); | |||
for (Iterator it = inlines.iterator(); it.hasNext();) { | |||
((InlineArea) it.next()) .resetBidiLevel(); | |||
} | |||
} | |||
private void updateLevel ( int newLevel ) { | |||
if ( newLevel >= 0 ) { | |||
private void updateLevel (int newLevel) { | |||
if (newLevel >= 0) { | |||
int curLevel = getBidiLevel(); | |||
if ( curLevel >= 0 ) { | |||
if ( newLevel < curLevel ) { | |||
setBidiLevel ( newLevel ); | |||
if (curLevel >= 0) { | |||
if (newLevel < curLevel) { | |||
setBidiLevel (newLevel); | |||
} | |||
} else { | |||
setBidiLevel ( newLevel ); | |||
setBidiLevel (newLevel); | |||
} | |||
} | |||
} |
@@ -44,7 +44,7 @@ public class SpaceArea extends InlineArea { | |||
* @param bidiLevel the bidirectional embedding level (or -1 if not defined) | |||
*/ | |||
public SpaceArea(int blockProgressionOffset, int bidiLevel, char space, boolean adjustable) { | |||
super ( blockProgressionOffset, bidiLevel ); | |||
super (blockProgressionOffset, bidiLevel); | |||
this.space = space; | |||
this.isAdjustable = adjustable; | |||
} |
@@ -89,12 +89,12 @@ public class TextArea extends AbstractTextArea { | |||
* @param blockProgressionOffset the offset for the next area | |||
*/ | |||
public void addWord | |||
( String word, int ipd, int[] letterAdjust, int[] levels, | |||
int[][] gposAdjustments, int blockProgressionOffset ) { | |||
int minWordLevel = findMinLevel ( levels ); | |||
(String word, int ipd, int[] letterAdjust, int[] levels, | |||
int[][] gposAdjustments, int blockProgressionOffset) { | |||
int minWordLevel = findMinLevel (levels); | |||
WordArea wordArea = new WordArea | |||
( blockProgressionOffset, minWordLevel, word, letterAdjust, levels, gposAdjustments ); | |||
wordArea.setIPD ( ipd ); | |||
(blockProgressionOffset, minWordLevel, word, letterAdjust, levels, gposAdjustments); | |||
wordArea.setIPD (ipd); | |||
addChildArea(wordArea); | |||
wordArea.setParentArea(this); | |||
updateLevel(minWordLevel); | |||
@@ -110,9 +110,9 @@ public class TextArea extends AbstractTextArea { | |||
* @param level resolved bidirection level of space character | |||
*/ | |||
public void addSpace | |||
( char space, int ipd, boolean adjustable, int blockProgressionOffset, int level ) { | |||
(char space, int ipd, boolean adjustable, int blockProgressionOffset, int level) { | |||
SpaceArea spaceArea = new SpaceArea(blockProgressionOffset, level, space, adjustable); | |||
spaceArea.setIPD ( ipd ); | |||
spaceArea.setIPD (ipd); | |||
addChildArea(spaceArea); | |||
spaceArea.setParentArea(this); | |||
updateLevel(level); | |||
@@ -167,29 +167,29 @@ public class TextArea extends AbstractTextArea { | |||
return sb.toString(); | |||
} | |||
private void updateLevel ( int newLevel ) { | |||
if ( newLevel >= 0 ) { | |||
private void updateLevel (int newLevel) { | |||
if (newLevel >= 0) { | |||
int curLevel = getBidiLevel(); | |||
if ( curLevel >= 0 ) { | |||
if ( newLevel < curLevel ) { | |||
setBidiLevel ( newLevel ); | |||
if (curLevel >= 0) { | |||
if (newLevel < curLevel) { | |||
setBidiLevel (newLevel); | |||
} | |||
} else { | |||
setBidiLevel ( newLevel ); | |||
setBidiLevel (newLevel); | |||
} | |||
} | |||
} | |||
private static int findMinLevel ( int[] levels ) { | |||
if ( levels != null ) { | |||
private static int findMinLevel (int[] levels) { | |||
if (levels != null) { | |||
int lMin = Integer.MAX_VALUE; | |||
for ( int i = 0, n = levels.length; i < n; i++ ) { | |||
for (int i = 0, n = levels.length; i < n; i++) { | |||
int l = levels [ i ]; | |||
if ( ( l >= 0 ) && ( l < lMin ) ) { | |||
if ((l >= 0) && (l < lMin)) { | |||
lMin = l; | |||
} | |||
} | |||
if ( lMin == Integer.MAX_VALUE ) { | |||
if (lMin == Integer.MAX_VALUE) { | |||
return -1; | |||
} else { | |||
return lMin; | |||
@@ -199,10 +199,10 @@ public class TextArea extends AbstractTextArea { | |||
} | |||
} | |||
private int[] makeLevels ( int level, int count ) { | |||
if ( level >= 0 ) { | |||
private int[] makeLevels (int level, int count) { | |||
if (level >= 0) { | |||
int[] levels = new int [ count ]; | |||
Arrays.fill ( levels, level ); | |||
Arrays.fill (levels, level); | |||
return levels; | |||
} else { | |||
return null; |
@@ -162,9 +162,9 @@ public class UnresolvedPageNumber extends TextArea implements Resolvable { | |||
* @return modified list of inline runs, having appended new run | |||
*/ | |||
@Override | |||
public List collectInlineRuns ( List runs ) { | |||
public List collectInlineRuns (List runs) { | |||
assert runs != null; | |||
runs.add ( new InlineRun ( this, new int[] {getBidiLevel()}) ); | |||
runs.add (new InlineRun (this, new int[] {getBidiLevel()})); | |||
return runs; | |||
} | |||
} |
@@ -67,14 +67,14 @@ public class WordArea extends InlineArea { | |||
* @param reversed true if word is known to be reversed at construction time | |||
*/ | |||
public WordArea | |||
( int blockProgressionOffset, int level, String word, int[] letterAdjust, int[] levels, | |||
int[][] gposAdjustments, boolean reversed ) { | |||
super ( blockProgressionOffset, level ); | |||
int length = ( word != null ) ? word.length() : 0; | |||
(int blockProgressionOffset, int level, String word, int[] letterAdjust, int[] levels, | |||
int[][] gposAdjustments, boolean reversed) { | |||
super (blockProgressionOffset, level); | |||
int length = (word != null) ? word.length() : 0; | |||
this.word = word; | |||
this.letterAdjust = maybeAdjustLength ( letterAdjust, length ); | |||
this.levels = maybePopulateLevels ( levels, level, length ); | |||
this.gposAdjustments = maybeAdjustLength ( gposAdjustments, length ); | |||
this.letterAdjust = maybeAdjustLength (letterAdjust, length); | |||
this.levels = maybePopulateLevels (levels, level, length); | |||
this.gposAdjustments = maybeAdjustLength (gposAdjustments, length); | |||
this.reversed = reversed; | |||
} | |||
@@ -89,9 +89,9 @@ public class WordArea extends InlineArea { | |||
* @param gposAdjustments array of general position adjustments or null if none apply | |||
*/ | |||
public WordArea | |||
( int blockProgressionOffset, int level, String word, int[] letterAdjust, int[] levels, | |||
int[][] gposAdjustments ) { | |||
this ( blockProgressionOffset, level, word, letterAdjust, levels, gposAdjustments, false ); | |||
(int blockProgressionOffset, int level, String word, int[] letterAdjust, int[] levels, | |||
int[][] gposAdjustments) { | |||
this (blockProgressionOffset, level, word, letterAdjust, levels, gposAdjustments, false); | |||
} | |||
/** @return Returns the word. */ | |||
@@ -120,12 +120,12 @@ public class WordArea extends InlineArea { | |||
* @return a (possibly null) array of per-character (glyph) levels over the specified | |||
* sequence | |||
*/ | |||
public int[] getBidiLevels ( int start, int end ) { | |||
public int[] getBidiLevels (int start, int end) { | |||
assert start <= end; | |||
if ( this.levels != null ) { | |||
if (this.levels != null) { | |||
int n = end - start; | |||
int[] levels = new int [ n ]; | |||
for ( int i = 0; i < n; i++ ) { | |||
for (int i = 0; i < n; i++) { | |||
levels[i] = this.levels [ start + i ]; | |||
} | |||
return levels; | |||
@@ -141,10 +141,10 @@ public class WordArea extends InlineArea { | |||
* level | |||
* @return a resolved bidirectional level or, if not specified, then -1 | |||
*/ | |||
public int bidiLevelAt ( int position ) { | |||
if ( position > word.length() ) { | |||
public int bidiLevelAt (int position) { | |||
if (position > word.length()) { | |||
throw new IndexOutOfBoundsException(); | |||
} else if ( levels != null ) { | |||
} else if (levels != null) { | |||
return levels [ position ]; | |||
} else { | |||
return -1; | |||
@@ -152,15 +152,15 @@ public class WordArea extends InlineArea { | |||
} | |||
@Override | |||
public List collectInlineRuns ( List runs ) { | |||
public List collectInlineRuns (List runs) { | |||
assert runs != null; | |||
InlineRun r; | |||
if ( getBidiLevels() != null ) { | |||
r = new InlineRun ( this, getBidiLevels() ); | |||
if (getBidiLevels() != null) { | |||
r = new InlineRun (this, getBidiLevels()); | |||
} else { | |||
r = new InlineRun ( this, -1, word.length() ); | |||
r = new InlineRun (this, -1, word.length()); | |||
} | |||
runs.add ( r ); | |||
runs.add (r); | |||
return runs; | |||
} | |||
@@ -180,10 +180,10 @@ public class WordArea extends InlineArea { | |||
* level | |||
* @return an array of adjustments or null if none applies | |||
*/ | |||
public int[] glyphPositionAdjustmentsAt ( int position ) { | |||
if ( position > word.length() ) { | |||
public int[] glyphPositionAdjustmentsAt (int position) { | |||
if (position > word.length()) { | |||
throw new IndexOutOfBoundsException(); | |||
} else if ( gposAdjustments != null ) { | |||
} else if (gposAdjustments != null) { | |||
return gposAdjustments [ position ]; | |||
} else { | |||
return null; | |||
@@ -195,18 +195,18 @@ public class WordArea extends InlineArea { | |||
* adjustments.</p> | |||
* @param mirror if true, then perform mirroring if mirrorred characters | |||
*/ | |||
public void reverse ( boolean mirror ) { | |||
if ( word.length() > 0 ) { | |||
word = ( ( new StringBuffer ( word ) ) .reverse() ) .toString(); | |||
if ( levels != null ) { | |||
reverse ( levels ); | |||
public void reverse (boolean mirror) { | |||
if (word.length() > 0) { | |||
word = ((new StringBuffer (word)) .reverse()) .toString(); | |||
if (levels != null) { | |||
reverse (levels); | |||
} | |||
if ( gposAdjustments != null ) { | |||
reverse ( gposAdjustments ); | |||
if (gposAdjustments != null) { | |||
reverse (gposAdjustments); | |||
} | |||
reversed = !reversed; | |||
if ( mirror ) { | |||
word = CharMirror.mirror ( word ); | |||
if (mirror) { | |||
word = CharMirror.mirror (word); | |||
} | |||
} | |||
} | |||
@@ -215,8 +215,8 @@ public class WordArea extends InlineArea { | |||
* <p>Perform mirroring on mirrorable characters.</p> | |||
*/ | |||
public void mirror() { | |||
if ( word.length() > 0 ) { | |||
word = CharMirror.mirror ( word ); | |||
if (word.length() > 0) { | |||
word = CharMirror.mirror (word); | |||
} | |||
} | |||
@@ -236,14 +236,14 @@ public class WordArea extends InlineArea { | |||
* If int[] array is not of specified length, then create | |||
* a new copy of the first length entries. | |||
*/ | |||
private static int[] maybeAdjustLength ( int[] ia, int length ) { | |||
if ( ia != null ) { | |||
if ( ia.length == length ) { | |||
private static int[] maybeAdjustLength (int[] ia, int length) { | |||
if (ia != null) { | |||
if (ia.length == length) { | |||
return ia; | |||
} else { | |||
int[] iaNew = new int [ length ]; | |||
for ( int i = 0, n = ia.length; i < n; i++ ) { | |||
if ( i < length ) { | |||
for (int i = 0, n = ia.length; i < n; i++) { | |||
if (i < length) { | |||
iaNew [ i ] = ia [ i ]; | |||
} else { | |||
break; | |||
@@ -260,14 +260,14 @@ public class WordArea extends InlineArea { | |||
* If int[][] matrix is not of specified length, then create | |||
* a new shallow copy of the first length entries. | |||
*/ | |||
private static int[][] maybeAdjustLength ( int[][] im, int length ) { | |||
if ( im != null ) { | |||
if ( im.length == length ) { | |||
private static int[][] maybeAdjustLength (int[][] im, int length) { | |||
if (im != null) { | |||
if (im.length == length) { | |||
return im; | |||
} else { | |||
int[][] imNew = new int [ length ][]; | |||
for ( int i = 0, n = im.length; i < n; i++ ) { | |||
if ( i < length ) { | |||
for (int i = 0, n = im.length; i < n; i++) { | |||
if (i < length) { | |||
imNew [ i ] = im [ i ]; | |||
} else { | |||
break; | |||
@@ -280,16 +280,16 @@ public class WordArea extends InlineArea { | |||
} | |||
} | |||
private static int[] maybePopulateLevels ( int[] levels, int level, int count ) { | |||
if ( ( levels == null ) && ( level >= 0 ) ) { | |||
private static int[] maybePopulateLevels (int[] levels, int level, int count) { | |||
if ((levels == null) && (level >= 0)) { | |||
levels = new int[count]; | |||
Arrays.fill ( levels, level ); | |||
Arrays.fill (levels, level); | |||
} | |||
return maybeAdjustLength ( levels, count ); | |||
return maybeAdjustLength (levels, count); | |||
} | |||
private static void reverse ( int[] a ) { | |||
for ( int i = 0, n = a.length, m = n / 2; i < m; i++ ) { | |||
private static void reverse (int[] a) { | |||
for (int i = 0, n = a.length, m = n / 2; i < m; i++) { | |||
int k = n - i - 1; | |||
int t = a [ k ]; | |||
a [ k ] = a [ i ]; | |||
@@ -297,8 +297,8 @@ public class WordArea extends InlineArea { | |||
} | |||
} | |||
private static void reverse ( int[][] aa ) { | |||
for ( int i = 0, n = aa.length, m = n / 2; i < m; i++ ) { | |||
private static void reverse (int[][] aa) { | |||
for (int i = 0, n = aa.length, m = n / 2; i < m; i++) { | |||
int k = n - i - 1; | |||
int[] t = aa [ k ]; | |||
aa [ k ] = aa [ i ]; |
@@ -241,25 +241,25 @@ private static byte[] bcC1 = { | |||
* @param ch a unicode scalar value | |||
* @return bidi class | |||
*/ | |||
public static int getBidiClass ( int ch ) { | |||
if ( ch <= 0x00FF ) { | |||
public static int getBidiClass (int ch) { | |||
if (ch <= 0x00FF) { | |||
return bcL1 [ ch - 0x0000 ]; | |||
} else if ( ( ch >= 0x0590 ) && ( ch <= 0x06FF ) ) { | |||
} else if ((ch >= 0x0590) && (ch <= 0x06FF)) { | |||
return bcR1 [ ch - 0x0590 ]; | |||
} else { | |||
return getBidiClass ( ch, bcS1, bcE1, bcC1 ); | |||
return getBidiClass (ch, bcS1, bcE1, bcC1); | |||
} | |||
} | |||
private static int getBidiClass ( int ch, int[] sa, int[] ea, byte[] ca ) { | |||
int k = Arrays.binarySearch ( sa, ch ); | |||
if ( k >= 0 ) { | |||
private static int getBidiClass (int ch, int[] sa, int[] ea, byte[] ca) { | |||
int k = Arrays.binarySearch (sa, ch); | |||
if (k >= 0) { | |||
return ca [ k ]; | |||
} else { | |||
k = - ( k + 1 ); | |||
if ( k == 0 ) { | |||
k = - (k + 1); | |||
if (k == 0) { | |||
return BidiConstants.L; | |||
} else if ( ch <= ea [ k - 1 ] ) { | |||
} else if (ch <= ea [ k - 1 ]) { | |||
return ca [ k - 1 ]; | |||
} else { | |||
return BidiConstants.L; |
@@ -57,183 +57,183 @@ public final class BidiResolver { | |||
* Resolve inline directionality. | |||
* @param ps a page sequence FO instance | |||
*/ | |||
public static void resolveInlineDirectionality ( PageSequence ps ) { | |||
public static void resolveInlineDirectionality (PageSequence ps) { | |||
if (log.isDebugEnabled()) { | |||
log.debug ( "BD: RESOLVE: " + ps ); | |||
log.debug ("BD: RESOLVE: " + ps); | |||
} | |||
List ranges = pruneEmptyRanges ( ps.collectDelimitedTextRanges ( new Stack() ) ); | |||
resolveInlineDirectionality ( ranges ); | |||
List ranges = pruneEmptyRanges (ps.collectDelimitedTextRanges (new Stack())); | |||
resolveInlineDirectionality (ranges); | |||
} | |||
/** | |||
* Reorder line area. | |||
* @param la a line area instance | |||
*/ | |||
public static void reorder ( LineArea la ) { | |||
public static void reorder (LineArea la) { | |||
// 1. collect inline levels | |||
List runs = collectRuns ( la.getInlineAreas(), new Vector() ); | |||
List runs = collectRuns (la.getInlineAreas(), new Vector()); | |||
if (log.isDebugEnabled()) { | |||
dumpRuns ( "BD: REORDER: INPUT:", runs ); | |||
dumpRuns ("BD: REORDER: INPUT:", runs); | |||
} | |||
// 2. split heterogeneous inlines | |||
runs = splitRuns ( runs ); | |||
runs = splitRuns (runs); | |||
if (log.isDebugEnabled()) { | |||
dumpRuns ( "BD: REORDER: SPLIT INLINES:", runs ); | |||
dumpRuns ("BD: REORDER: SPLIT INLINES:", runs); | |||
} | |||
// 3. determine minimum and maximum levels | |||
int[] mm = computeMinMaxLevel ( runs, null ); | |||
int[] mm = computeMinMaxLevel (runs, null); | |||
if (log.isDebugEnabled()) { | |||
log.debug( "BD: REORDER: { min = " + mm[0] + ", max = " + mm[1] + "}" ); | |||
log.debug("BD: REORDER: { min = " + mm[0] + ", max = " + mm[1] + "}"); | |||
} | |||
// 4. reorder from maximum level to minimum odd level | |||
int mn = mm[0]; | |||
int mx = mm[1]; | |||
if ( mx > 0 ) { | |||
for ( int l1 = mx, l2 = ( ( mn & 1 ) == 0 ) ? ( mn + 1 ) : mn; l1 >= l2; l1-- ) { | |||
runs = reorderRuns ( runs, l1 ); | |||
if (mx > 0) { | |||
for (int l1 = mx, l2 = ((mn & 1) == 0) ? (mn + 1) : mn; l1 >= l2; l1--) { | |||
runs = reorderRuns (runs, l1); | |||
} | |||
} | |||
if (log.isDebugEnabled()) { | |||
dumpRuns ( "BD: REORDER: REORDERED RUNS:", runs ); | |||
dumpRuns ("BD: REORDER: REORDERED RUNS:", runs); | |||
} | |||
// 5. reverse word consituents (characters and glyphs) while mirroring | |||
boolean mirror = true; | |||
reverseWords ( runs, mirror ); | |||
reverseWords (runs, mirror); | |||
if (log.isDebugEnabled()) { | |||
dumpRuns ( "BD: REORDER: REORDERED WORDS:", runs ); | |||
dumpRuns ("BD: REORDER: REORDERED WORDS:", runs); | |||
} | |||
// 6. replace line area's inline areas with reordered runs' inline areas | |||
replaceInlines ( la, replicateSplitWords ( runs ) ); | |||
replaceInlines (la, replicateSplitWords (runs)); | |||
} | |||
private static void resolveInlineDirectionality ( List ranges ) { | |||
for ( Iterator it = ranges.iterator(); it.hasNext(); ) { | |||
private static void resolveInlineDirectionality (List ranges) { | |||
for (Iterator it = ranges.iterator(); it.hasNext(); ) { | |||
DelimitedTextRange r = (DelimitedTextRange) it.next(); | |||
r.resolve(); | |||
if (log.isDebugEnabled()) { | |||
log.debug ( r ); | |||
log.debug (r); | |||
} | |||
} | |||
} | |||
private static List collectRuns ( List inlines, List runs ) { | |||
for ( Iterator it = inlines.iterator(); it.hasNext(); ) { | |||
private static List collectRuns (List inlines, List runs) { | |||
for (Iterator it = inlines.iterator(); it.hasNext(); ) { | |||
InlineArea ia = (InlineArea) it.next(); | |||
runs = ia.collectInlineRuns ( runs ); | |||
runs = ia.collectInlineRuns (runs); | |||
} | |||
return runs; | |||
} | |||
private static List splitRuns ( List runs ) { | |||
private static List splitRuns (List runs) { | |||
List runsNew = new Vector(); | |||
for ( Iterator it = runs.iterator(); it.hasNext(); ) { | |||
for (Iterator it = runs.iterator(); it.hasNext(); ) { | |||
InlineRun ir = (InlineRun) it.next(); | |||
if ( ir.isHomogenous() ) { | |||
runsNew.add ( ir ); | |||
if (ir.isHomogenous()) { | |||
runsNew.add (ir); | |||
} else { | |||
runsNew.addAll ( ir.split() ); | |||
runsNew.addAll (ir.split()); | |||
} | |||
} | |||
if ( ! runsNew.equals ( runs ) ) { | |||
if (! runsNew.equals (runs)) { | |||
runs = runsNew; | |||
} | |||
return runs; | |||
} | |||
private static int[] computeMinMaxLevel ( List runs, int[] mm ) { | |||
if ( mm == null ) { | |||
private static int[] computeMinMaxLevel (List runs, int[] mm) { | |||
if (mm == null) { | |||
mm = new int[] {Integer.MAX_VALUE, Integer.MIN_VALUE}; | |||
} | |||
for ( Iterator it = runs.iterator(); it.hasNext(); ) { | |||
for (Iterator it = runs.iterator(); it.hasNext(); ) { | |||
InlineRun ir = (InlineRun) it.next(); | |||
ir.updateMinMax ( mm ); | |||
ir.updateMinMax (mm); | |||
} | |||
return mm; | |||
} | |||
private static List reorderRuns ( List runs, int level ) { | |||
private static List reorderRuns (List runs, int level) { | |||
assert level >= 0; | |||
List runsNew = new Vector(); | |||
for ( int i = 0, n = runs.size(); i < n; i++ ) { | |||
for (int i = 0, n = runs.size(); i < n; i++) { | |||
InlineRun iri = (InlineRun) runs.get(i); | |||
if ( iri.getMinLevel() < level ) { | |||
runsNew.add ( iri ); | |||
if (iri.getMinLevel() < level) { | |||
runsNew.add (iri); | |||
} else { | |||
int s = i; | |||
int e = s; | |||
while ( e < n ) { | |||
while (e < n) { | |||
InlineRun ire = (InlineRun) runs.get(e); | |||
if ( ire.getMinLevel() < level ) { | |||
if (ire.getMinLevel() < level) { | |||
break; | |||
} else { | |||
e++; | |||
} | |||
} | |||
if ( s < e ) { | |||
runsNew.addAll ( reverseRuns ( runs, s, e ) ); | |||
if (s < e) { | |||
runsNew.addAll (reverseRuns (runs, s, e)); | |||
} | |||
i = e - 1; | |||
} | |||
} | |||
if ( ! runsNew.equals ( runs ) ) { | |||
if (! runsNew.equals (runs)) { | |||
runs = runsNew; | |||
} | |||
return runs; | |||
} | |||
private static List reverseRuns ( List runs, int s, int e ) { | |||
private static List reverseRuns (List runs, int s, int e) { | |||
int n = e - s; | |||
Vector runsNew = new Vector ( n ); | |||
if ( n > 0 ) { | |||
for ( int i = 0; i < n; i++ ) { | |||
int k = ( n - i - 1 ); | |||
Vector runsNew = new Vector (n); | |||
if (n > 0) { | |||
for (int i = 0; i < n; i++) { | |||
int k = (n - i - 1); | |||
InlineRun ir = (InlineRun) runs.get(s + k); | |||
ir.reverse(); | |||
runsNew.add ( ir ); | |||
runsNew.add (ir); | |||
} | |||
} | |||
return runsNew; | |||
} | |||
private static void reverseWords ( List runs, boolean mirror ) { | |||
for ( Iterator it = runs.iterator(); it.hasNext(); ) { | |||
private static void reverseWords (List runs, boolean mirror) { | |||
for (Iterator it = runs.iterator(); it.hasNext(); ) { | |||
InlineRun ir = (InlineRun) it.next(); | |||
ir.maybeReverseWord ( mirror ); | |||
ir.maybeReverseWord (mirror); | |||
} | |||
} | |||
private static List replicateSplitWords ( List runs ) { | |||
private static List replicateSplitWords (List runs) { | |||
// [TBD] for each run which inline word area appears multiple times in | |||
// runs, replicate that word | |||
return runs; | |||
} | |||
private static void replaceInlines ( LineArea la, List runs ) { | |||
private static void replaceInlines (LineArea la, List runs) { | |||
List<InlineArea> inlines = new ArrayList<InlineArea>(); | |||
for ( Iterator it = runs.iterator(); it.hasNext(); ) { | |||
for (Iterator it = runs.iterator(); it.hasNext(); ) { | |||
InlineRun ir = (InlineRun) it.next(); | |||
inlines.add ( ir.getInline() ); | |||
inlines.add (ir.getInline()); | |||
} | |||
la.setInlineAreas ( unflattenInlines ( inlines ) ); | |||
la.setInlineAreas (unflattenInlines (inlines)); | |||
} | |||
private static List unflattenInlines ( List<InlineArea> inlines ) { | |||
return new UnflattenProcessor ( inlines ) .unflatten(); | |||
private static List unflattenInlines (List<InlineArea> inlines) { | |||
return new UnflattenProcessor (inlines) .unflatten(); | |||
} | |||
private static void dumpRuns ( String header, List runs ) { | |||
log.debug ( header ); | |||
for ( Iterator it = runs.iterator(); it.hasNext(); ) { | |||
private static void dumpRuns (String header, List runs) { | |||
log.debug (header); | |||
for (Iterator it = runs.iterator(); it.hasNext(); ) { | |||
InlineRun ir = (InlineRun) it.next(); | |||
log.debug ( ir ); | |||
log.debug (ir); | |||
} | |||
} | |||
private static List pruneEmptyRanges ( Stack ranges ) { | |||
private static List pruneEmptyRanges (Stack ranges) { | |||
Vector rv = new Vector(); | |||
for ( Iterator it = ranges.iterator(); it.hasNext(); ) { | |||
for (Iterator it = ranges.iterator(); it.hasNext(); ) { | |||
DelimitedTextRange r = (DelimitedTextRange) it.next(); | |||
if ( ! r.isEmpty() ) { | |||
rv.add ( r ); | |||
if (! r.isEmpty()) { | |||
rv.add (r); | |||
} | |||
} | |||
return rv; |
@@ -54,7 +54,7 @@ public class DelimitedTextRange { | |||
* Primary constructor. | |||
* @param fn node that generates this text range | |||
*/ | |||
public DelimitedTextRange ( FONode fn ) { | |||
public DelimitedTextRange (FONode fn) { | |||
this.fn = fn; | |||
this.buffer = new StringBuffer(); | |||
this.intervals = new Vector(); | |||
@@ -71,16 +71,16 @@ public class DelimitedTextRange { | |||
* @param it character iterator | |||
* @param fn node that generates interval being appended | |||
*/ | |||
public void append ( CharIterator it, FONode fn ) { | |||
if ( it != null ) { | |||
public void append (CharIterator it, FONode fn) { | |||
if (it != null) { | |||
int s = buffer.length(); | |||
int e = s; | |||
while ( it.hasNext() ) { | |||
while (it.hasNext()) { | |||
char c = it.nextChar(); | |||
buffer.append ( c ); | |||
buffer.append (c); | |||
e++; | |||
} | |||
intervals.add ( new TextInterval ( fn, s, e ) ); | |||
intervals.add (new TextInterval (fn, s, e)); | |||
} | |||
} | |||
/** | |||
@@ -88,12 +88,12 @@ public class DelimitedTextRange { | |||
* @param c character | |||
* @param fn node that generates interval being appended | |||
*/ | |||
public void append ( char c, FONode fn ) { | |||
if ( c != 0 ) { | |||
public void append (char c, FONode fn) { | |||
if (c != 0) { | |||
int s = buffer.length(); | |||
int e = s + 1; | |||
buffer.append ( c ); | |||
intervals.add ( new TextInterval ( fn, s, e ) ); | |||
buffer.append (c); | |||
intervals.add (new TextInterval (fn, s, e)); | |||
} | |||
} | |||
/** | |||
@@ -108,32 +108,32 @@ public class DelimitedTextRange { | |||
*/ | |||
public void resolve() { | |||
WritingModeTraitsGetter tg; | |||
if ( ( tg = WritingModeTraits.getWritingModeTraitsGetter ( getNode() ) ) != null ) { | |||
resolve ( tg.getInlineProgressionDirection() ); | |||
if ((tg = WritingModeTraits.getWritingModeTraitsGetter (getNode())) != null) { | |||
resolve (tg.getInlineProgressionDirection()); | |||
} | |||
} | |||
@Override | |||
public String toString() { | |||
StringBuffer sb = new StringBuffer ( "DR: " + fn.getLocalName() + " { <" + CharUtilities.toNCRefs ( buffer.toString() ) + ">" ); | |||
sb.append ( ", intervals <" ); | |||
StringBuffer sb = new StringBuffer ("DR: " + fn.getLocalName() + " { <" + CharUtilities.toNCRefs (buffer.toString()) + ">"); | |||
sb.append (", intervals <"); | |||
boolean first = true; | |||
for ( Iterator it = intervals.iterator(); it.hasNext(); ) { | |||
for (Iterator it = intervals.iterator(); it.hasNext(); ) { | |||
TextInterval ti = (TextInterval) it.next(); | |||
if ( first ) { | |||
if (first) { | |||
first = false; | |||
} else { | |||
sb.append(','); | |||
} | |||
sb.append ( ti.toString() ); | |||
sb.append (ti.toString()); | |||
} | |||
sb.append("> }"); | |||
return sb.toString(); | |||
} | |||
private void resolve ( Direction paragraphEmbeddingLevel ) { | |||
private void resolve (Direction paragraphEmbeddingLevel) { | |||
int [] levels; | |||
if ( ( levels = UnicodeBidiAlgorithm.resolveLevels ( buffer, paragraphEmbeddingLevel ) ) != null ) { | |||
assignLevels ( levels ); | |||
assignBlockLevel ( paragraphEmbeddingLevel ); | |||
if ((levels = UnicodeBidiAlgorithm.resolveLevels (buffer, paragraphEmbeddingLevel)) != null) { | |||
assignLevels (levels); | |||
assignBlockLevel (paragraphEmbeddingLevel); | |||
assignTextLevels(); | |||
} | |||
} | |||
@@ -145,13 +145,13 @@ public class DelimitedTextRange { | |||
* @param levels array of levels each corresponding to each index of the delimited | |||
* text range | |||
*/ | |||
private void assignLevels ( int[] levels ) { | |||
Vector intervalsNew = new Vector ( intervals.size() ); | |||
for ( Iterator it = intervals.iterator(); it.hasNext(); ) { | |||
private void assignLevels (int[] levels) { | |||
Vector intervalsNew = new Vector (intervals.size()); | |||
for (Iterator it = intervals.iterator(); it.hasNext(); ) { | |||
TextInterval ti = (TextInterval) it.next(); | |||
intervalsNew.addAll ( assignLevels ( ti, levels ) ); | |||
intervalsNew.addAll (assignLevels (ti, levels)); | |||
} | |||
if ( ! intervalsNew.equals ( intervals ) ) { | |||
if (! intervalsNew.equals (intervals)) { | |||
intervals = intervalsNew; | |||
} | |||
} | |||
@@ -167,30 +167,30 @@ public class DelimitedTextRange { | |||
* @return a list of text intervals as described above | |||
*/ | |||
private static final Log log = LogFactory.getLog(BidiResolver.class); // CSOK: ConstantNameCheck | |||
private List assignLevels ( TextInterval ti, int[] levels ) { | |||
private List assignLevels (TextInterval ti, int[] levels) { | |||
Vector tiv = new Vector(); | |||
FONode fn = ti.getNode(); | |||
int fnStart = ti.getStart(); // start of node's text in delimited text range | |||
for ( int i = fnStart, n = ti.getEnd(); i < n; ) { | |||
for (int i = fnStart, n = ti.getEnd(); i < n; ) { | |||
int s = i; // inclusive start index of interval in delimited text range | |||
int e = s; // exclusive end index of interval in delimited text range | |||
int l = levels [ s ]; // current run level | |||
while ( e < n ) { // skip to end of run level or end of interval | |||
if ( levels [ e ] != l ) { | |||
while (e < n) { // skip to end of run level or end of interval | |||
if (levels [ e ] != l) { | |||
break; | |||
} else { | |||
e++; | |||
} | |||
} | |||
if ( ( ti.getStart() == s ) && ( ti.getEnd() == e ) ) { | |||
ti.setLevel ( l ); // reuse interval, assigning it single level | |||
if ((ti.getStart() == s) && (ti.getEnd() == e)) { | |||
ti.setLevel (l); // reuse interval, assigning it single level | |||
} else { | |||
ti = new TextInterval ( fn, fnStart, s, e, l ); // subdivide interval | |||
ti = new TextInterval (fn, fnStart, s, e, l); // subdivide interval | |||
} | |||
if (log.isDebugEnabled()) { | |||
log.debug ( "AL(" + l + "): " + ti ); | |||
log.debug ("AL(" + l + "): " + ti); | |||
} | |||
tiv.add ( ti ); | |||
tiv.add (ti); | |||
i = e; | |||
} | |||
return tiv; | |||
@@ -199,25 +199,25 @@ public class DelimitedTextRange { | |||
* <p>Assign resolved levels for each interval to source #PCDATA in the associated FOText.</p> | |||
*/ | |||
private void assignTextLevels() { | |||
for ( Iterator it = intervals.iterator(); it.hasNext(); ) { | |||
for (Iterator it = intervals.iterator(); it.hasNext(); ) { | |||
TextInterval ti = (TextInterval) it.next(); | |||
ti.assignTextLevels(); | |||
} | |||
} | |||
private void assignBlockLevel ( Direction paragraphEmbeddingLevel ) { | |||
int defaultLevel = ( paragraphEmbeddingLevel == Direction.RL ) ? 1 : 0; | |||
for ( Iterator it = intervals.iterator(); it.hasNext(); ) { | |||
private void assignBlockLevel (Direction paragraphEmbeddingLevel) { | |||
int defaultLevel = (paragraphEmbeddingLevel == Direction.RL) ? 1 : 0; | |||
for (Iterator it = intervals.iterator(); it.hasNext(); ) { | |||
TextInterval ti = (TextInterval) it.next(); | |||
assignBlockLevel ( ti.getNode(), defaultLevel ); | |||
assignBlockLevel (ti.getNode(), defaultLevel); | |||
} | |||
} | |||
private void assignBlockLevel ( FONode node, int defaultLevel ) { | |||
for ( FONode fn = node; fn != null; fn = fn.getParent() ) { | |||
if ( fn instanceof FObj ) { | |||
private void assignBlockLevel (FONode node, int defaultLevel) { | |||
for (FONode fn = node; fn != null; fn = fn.getParent()) { | |||
if (fn instanceof FObj) { | |||
FObj fo = (FObj) fn; | |||
if ( fo.isBidiRangeBlockItem() ) { | |||
if ( fo.getBidiLevel() < 0 ) { | |||
fo.setBidiLevel ( defaultLevel ); | |||
if (fo.isBidiRangeBlockItem()) { | |||
if (fo.getBidiLevel() < 0) { | |||
fo.setBidiLevel (defaultLevel); | |||
} | |||
break; | |||
} |
@@ -57,12 +57,12 @@ public class InlineRun { | |||
* @param inline which generated this inline run | |||
* @param levels levels array | |||
*/ | |||
public InlineRun ( InlineArea inline, int[] levels ) { | |||
public InlineRun (InlineArea inline, int[] levels) { | |||
assert inline != null; | |||
assert levels != null; | |||
this.inline = inline; | |||
this.levels = levels; | |||
setMinMax ( levels ); | |||
setMinMax (levels); | |||
} | |||
/** | |||
* Alternate constructor. | |||
@@ -70,8 +70,8 @@ public class InlineRun { | |||
* @param level for each index | |||
* @param count of indices | |||
*/ | |||
public InlineRun ( InlineArea inline, int level, int count ) { | |||
this ( inline, makeLevels ( level, count ) ); | |||
public InlineRun (InlineArea inline, int level, int count) { | |||
this (inline, makeLevels (level, count)); | |||
} | |||
/** | |||
* Obtain inline area that generated this inline run. | |||
@@ -94,16 +94,16 @@ public class InlineRun { | |||
public int getMaxLevel() { | |||
return maxLevel; | |||
} | |||
private void setMinMax ( int[] levels ) { | |||
private void setMinMax (int[] levels) { | |||
int mn = Integer.MAX_VALUE; | |||
int mx = Integer.MIN_VALUE; | |||
if ( ( levels != null ) && ( levels.length > 0 ) ) { | |||
for ( int i = 0, n = levels.length; i < n; i++ ) { | |||
if ((levels != null) && (levels.length > 0)) { | |||
for (int i = 0, n = levels.length; i < n; i++) { | |||
int l = levels [ i ]; | |||
if ( l < mn ) { | |||
if (l < mn) { | |||
mn = l; | |||
} | |||
if ( l > mx ) { | |||
if (l > mx) { | |||
mx = l; | |||
} | |||
} | |||
@@ -126,19 +126,19 @@ public class InlineRun { | |||
*/ | |||
public List split() { | |||
List runs = new Vector(); | |||
for ( int i = 0, n = levels.length; i < n; ) { | |||
for (int i = 0, n = levels.length; i < n; ) { | |||
int l = levels [ i ]; | |||
int s = i; | |||
int e = s; | |||
while ( e < n ) { | |||
if ( levels [ e ] != l ) { | |||
while (e < n) { | |||
if (levels [ e ] != l) { | |||
break; | |||
} else { | |||
e++; | |||
} | |||
} | |||
if ( s < e ) { | |||
runs.add ( new InlineRun ( inline, l, e - s ) ); | |||
if (s < e) { | |||
runs.add (new InlineRun (inline, l, e - s)); | |||
} | |||
i = e; | |||
} | |||
@@ -149,11 +149,11 @@ public class InlineRun { | |||
* Update a min/max array to correspond with this run's min/max values. | |||
* @param mm reference to min/max array | |||
*/ | |||
public void updateMinMax ( int[] mm ) { | |||
if ( minLevel < mm[0] ) { | |||
public void updateMinMax (int[] mm) { | |||
if (minLevel < mm[0]) { | |||
mm[0] = minLevel; | |||
} | |||
if ( maxLevel > mm[1] ) { | |||
if (maxLevel > mm[1]) { | |||
mm[1] = maxLevel; | |||
} | |||
} | |||
@@ -162,7 +162,7 @@ public class InlineRun { | |||
* @return true if run is homogenous and odd (i.e., right to left) | |||
*/ | |||
public boolean maybeNeedsMirroring() { | |||
return ( minLevel == maxLevel ) && ( ( minLevel & 1 ) != 0 ); | |||
return (minLevel == maxLevel) && ((minLevel & 1) != 0); | |||
} | |||
/** | |||
* Reverse run (by incrementing reversal count, not actually reversing). | |||
@@ -175,41 +175,41 @@ public class InlineRun { | |||
* reversal. | |||
* @param mirror if true then also mirror characters | |||
*/ | |||
public void maybeReverseWord ( boolean mirror ) { | |||
if ( inline instanceof WordArea ) { | |||
public void maybeReverseWord (boolean mirror) { | |||
if (inline instanceof WordArea) { | |||
WordArea w = (WordArea) inline; | |||
// if not already reversed, then reverse now | |||
if ( ! w.isReversed() ) { | |||
if ( ( reversals & 1 ) != 0 ) { | |||
w.reverse ( mirror ); | |||
} else if ( mirror && maybeNeedsMirroring() ) { | |||
if (! w.isReversed()) { | |||
if ((reversals & 1) != 0) { | |||
w.reverse (mirror); | |||
} else if (mirror && maybeNeedsMirroring()) { | |||
w.mirror(); | |||
} | |||
} | |||
} | |||
} | |||
@Override | |||
public boolean equals ( Object o ) { | |||
if ( o instanceof InlineRun ) { | |||
public boolean equals (Object o) { | |||
if (o instanceof InlineRun) { | |||
InlineRun ir = (InlineRun) o; | |||
if ( ir.inline != inline ) { | |||
if (ir.inline != inline) { | |||
return false; | |||
} else if ( ir.minLevel != minLevel ) { | |||
} else if (ir.minLevel != minLevel) { | |||
return false; | |||
} else if ( ir.maxLevel != maxLevel ) { | |||
} else if (ir.maxLevel != maxLevel) { | |||
return false; | |||
} else if ( ( ir.levels != null ) && ( levels != null ) ) { | |||
if ( ir.levels.length != levels.length ) { | |||
} else if ((ir.levels != null) && (levels != null)) { | |||
if (ir.levels.length != levels.length) { | |||
return false; | |||
} else { | |||
for ( int i = 0, n = levels.length; i < n; i++ ) { | |||
if ( ir.levels[i] != levels[i] ) { | |||
for (int i = 0, n = levels.length; i < n; i++) { | |||
if (ir.levels[i] != levels[i]) { | |||
return false; | |||
} | |||
} | |||
return true; | |||
} | |||
} else if ( ( ir.levels == null ) && ( levels == null ) ) { | |||
} else if ((ir.levels == null) && (levels == null)) { | |||
return true; | |||
} else { | |||
return false; | |||
@@ -220,88 +220,88 @@ public class InlineRun { | |||
} | |||
@Override | |||
public int hashCode() { | |||
int l = ( inline != null ) ? inline.hashCode() : 0; | |||
l = ( l ^ minLevel ) + ( l << 19 ); | |||
l = ( l ^ maxLevel ) + ( l << 11 ); | |||
int l = (inline != null) ? inline.hashCode() : 0; | |||
l = (l ^ minLevel) + (l << 19); | |||
l = (l ^ maxLevel) + (l << 11); | |||
return l; | |||
} | |||
@Override | |||
public String toString() { | |||
StringBuffer sb = new StringBuffer( "RR: { type = \'" ); | |||
StringBuffer sb = new StringBuffer("RR: { type = \'"); | |||
char c; | |||
String content = null; | |||
if ( inline instanceof WordArea ) { | |||
if (inline instanceof WordArea) { | |||
c = 'W'; | |||
content = ( (WordArea) inline ) .getWord(); | |||
} else if ( inline instanceof SpaceArea ) { | |||
content = ((WordArea) inline) .getWord(); | |||
} else if (inline instanceof SpaceArea) { | |||
c = 'S'; | |||
content = ( (SpaceArea) inline ) .getSpace(); | |||
} else if ( inline instanceof Anchor ) { | |||
content = ((SpaceArea) inline) .getSpace(); | |||
} else if (inline instanceof Anchor) { | |||
c = 'A'; | |||
} else if ( inline instanceof Leader ) { | |||
} else if (inline instanceof Leader) { | |||
c = 'L'; | |||
} else if ( inline instanceof Space ) { | |||
} else if (inline instanceof Space) { | |||
c = 'S'; | |||
} else if ( inline instanceof UnresolvedPageNumber ) { | |||
} else if (inline instanceof UnresolvedPageNumber) { | |||
c = '#'; | |||
content = ( (UnresolvedPageNumber) inline ) .getText(); | |||
} else if ( inline instanceof InlineBlockParent ) { | |||
content = ((UnresolvedPageNumber) inline) .getText(); | |||
} else if (inline instanceof InlineBlockParent) { | |||
c = 'B'; | |||
} else if ( inline instanceof InlineViewport ) { | |||
} else if (inline instanceof InlineViewport) { | |||
c = 'V'; | |||
} else if ( inline instanceof InlineParent ) { | |||
} else if (inline instanceof InlineParent) { | |||
c = 'I'; | |||
} else { | |||
c = '?'; | |||
} | |||
sb.append ( c ); | |||
sb.append ( "\', levels = \'" ); | |||
sb.append ( generateLevels ( levels ) ); | |||
sb.append ( "\', min = " ); | |||
sb.append ( minLevel ); | |||
sb.append ( ", max = " ); | |||
sb.append ( maxLevel ); | |||
sb.append ( ", reversals = " ); | |||
sb.append ( reversals ); | |||
sb.append ( ", content = <" ); | |||
sb.append ( CharUtilities.toNCRefs ( content ) ); | |||
sb.append ( "> }" ); | |||
sb.append (c); | |||
sb.append ("\', levels = \'"); | |||
sb.append (generateLevels (levels)); | |||
sb.append ("\', min = "); | |||
sb.append (minLevel); | |||
sb.append (", max = "); | |||
sb.append (maxLevel); | |||
sb.append (", reversals = "); | |||
sb.append (reversals); | |||
sb.append (", content = <"); | |||
sb.append (CharUtilities.toNCRefs (content)); | |||
sb.append ("> }"); | |||
return sb.toString(); | |||
} | |||
private String generateLevels ( int[] levels ) { | |||
private String generateLevels (int[] levels) { | |||
StringBuffer lb = new StringBuffer(); | |||
int maxLevel = -1; | |||
int numLevels = levels.length; | |||
for ( int i = 0; i < numLevels; i++ ) { | |||
for (int i = 0; i < numLevels; i++) { | |||
int l = levels [ i ]; | |||
if ( l > maxLevel ) { | |||
if (l > maxLevel) { | |||
maxLevel = l; | |||
} | |||
} | |||
if ( maxLevel < 0 ) { | |||
if (maxLevel < 0) { | |||
// leave level buffer empty | |||
} else if ( maxLevel < 10 ) { | |||
} else if (maxLevel < 10) { | |||
// use string of decimal digits | |||
for ( int i = 0; i < numLevels; i++ ) { | |||
lb.append ( (char) ( '0' + levels [ i ] ) ); | |||
for (int i = 0; i < numLevels; i++) { | |||
lb.append ((char) ('0' + levels [ i ])); | |||
} | |||
} else { | |||
// use comma separated list | |||
boolean first = true; | |||
for ( int i = 0; i < numLevels; i++ ) { | |||
if ( first ) { | |||
for (int i = 0; i < numLevels; i++) { | |||
if (first) { | |||
first = false; | |||
} else { | |||
lb.append(','); | |||
} | |||
lb.append ( levels [ i ] ); | |||
lb.append (levels [ i ]); | |||
} | |||
} | |||
return lb.toString(); | |||
} | |||
private static int[] makeLevels ( int level, int count ) { | |||
private static int[] makeLevels (int level, int count) { | |||
int[] levels = new int [ count ]; | |||
Arrays.fill ( levels, level ); | |||
Arrays.fill (levels, level); | |||
return levels; | |||
} | |||
} |
@@ -42,10 +42,10 @@ class TextInterval { | |||
private int start; // starting index within delimited text range | |||
private int end; // ending index within delimited text range | |||
private int level; // resolved level or default (-1) | |||
TextInterval ( FONode fn, int start, int end ) { | |||
this ( fn, start, start, end, -1 ); | |||
TextInterval (FONode fn, int start, int end) { | |||
this (fn, start, start, end, -1); | |||
} | |||
TextInterval ( FONode fn, int textStart, int start, int end, int level ) { | |||
TextInterval (FONode fn, int textStart, int start, int end, int level) { | |||
this.fn = fn; | |||
this.textStart = textStart; | |||
this.start = start; | |||
@@ -67,42 +67,42 @@ class TextInterval { | |||
int getLevel() { | |||
return level; | |||
} | |||
void setLevel ( int level ) { | |||
void setLevel (int level) { | |||
this.level = level; | |||
} | |||
public int length() { | |||
return end - start; | |||
} | |||
public String getText() { | |||
if ( fn instanceof FOText ) { | |||
return ( (FOText) fn ) .getCharSequence() .toString(); | |||
} else if ( fn instanceof Character ) { | |||
return new String ( new char[] {( (Character) fn ) .getCharacter()} ); | |||
if (fn instanceof FOText) { | |||
return ((FOText) fn) .getCharSequence() .toString(); | |||
} else if (fn instanceof Character) { | |||
return new String (new char[] {((Character) fn) .getCharacter()}); | |||
} else { | |||
return null; | |||
} | |||
} | |||
public void assignTextLevels() { | |||
if ( fn instanceof FOText ) { | |||
( (FOText) fn ) .setBidiLevel ( level, start - textStart, end - textStart ); | |||
} else if ( fn instanceof Character ) { | |||
( (Character) fn ) .setBidiLevel ( level ); | |||
} else if ( fn instanceof AbstractPageNumberCitation ) { | |||
( (AbstractPageNumberCitation) fn ) .setBidiLevel ( level ); | |||
} else if ( fn instanceof AbstractGraphics ) { | |||
( (AbstractGraphics) fn ) .setBidiLevel ( level ); | |||
} else if ( fn instanceof Leader ) { | |||
( (Leader) fn ) .setBidiLevel ( level ); | |||
if (fn instanceof FOText) { | |||
((FOText) fn) .setBidiLevel (level, start - textStart, end - textStart); | |||
} else if (fn instanceof Character) { | |||
((Character) fn) .setBidiLevel (level); | |||
} else if (fn instanceof AbstractPageNumberCitation) { | |||
((AbstractPageNumberCitation) fn) .setBidiLevel (level); | |||
} else if (fn instanceof AbstractGraphics) { | |||
((AbstractGraphics) fn) .setBidiLevel (level); | |||
} else if (fn instanceof Leader) { | |||
((Leader) fn) .setBidiLevel (level); | |||
} | |||
} | |||
public boolean equals ( Object o ) { | |||
if ( o instanceof TextInterval ) { | |||
public boolean equals (Object o) { | |||
if (o instanceof TextInterval) { | |||
TextInterval ti = (TextInterval) o; | |||
if ( ti.getNode() != fn ) { | |||
if (ti.getNode() != fn) { | |||
return false; | |||
} else if ( ti.getStart() != start ) { | |||
} else if (ti.getStart() != start) { | |||
return false; | |||
} else if ( ti.getEnd() != end ) { | |||
} else if (ti.getEnd() != end) { | |||
return false; | |||
} else { | |||
return true; | |||
@@ -112,31 +112,31 @@ class TextInterval { | |||
} | |||
} | |||
public int hashCode() { | |||
int l = ( fn != null ) ? fn.hashCode() : 0; | |||
l = ( l ^ start ) + ( l << 19 ); | |||
l = ( l ^ end ) + ( l << 11 ); | |||
int l = (fn != null) ? fn.hashCode() : 0; | |||
l = (l ^ start) + (l << 19); | |||
l = (l ^ end) + (l << 11); | |||
return l; | |||
} | |||
public String toString() { | |||
StringBuffer sb = new StringBuffer(); | |||
char c; | |||
if ( fn instanceof FOText ) { | |||
if (fn instanceof FOText) { | |||
c = 'T'; | |||
} else if ( fn instanceof Character ) { | |||
} else if (fn instanceof Character) { | |||
c = 'C'; | |||
} else if ( fn instanceof BidiOverride ) { | |||
} else if (fn instanceof BidiOverride) { | |||
c = 'B'; | |||
} else if ( fn instanceof AbstractPageNumberCitation ) { | |||
} else if (fn instanceof AbstractPageNumberCitation) { | |||
c = '#'; | |||
} else if ( fn instanceof AbstractGraphics ) { | |||
} else if (fn instanceof AbstractGraphics) { | |||
c = 'G'; | |||
} else if ( fn instanceof Leader ) { | |||
} else if (fn instanceof Leader) { | |||
c = 'L'; | |||
} else { | |||
c = '?'; | |||
} | |||
sb.append ( c ); | |||
sb.append ( "[" + start + "," + end + "][" + textStart + "](" + level + ")" ); | |||
sb.append (c); | |||
sb.append ("[" + start + "," + end + "][" + textStart + "](" + level + ")"); | |||
return sb.toString(); | |||
} | |||
} |
@@ -54,7 +54,7 @@ class UnflattenProcessor { | |||
private TextArea tcNew; // new text area container being constructed | |||
private Stack<InlineParent> icOrig; // stack of original inline parent containers | |||
private Stack<InlineParent> icNew; // stack of new inline parent containers being constructed | |||
UnflattenProcessor ( List<InlineArea> inlines ) { | |||
UnflattenProcessor (List<InlineArea> inlines) { | |||
this.il = inlines; | |||
this.ilNew = new ArrayList<InlineArea>(); | |||
this.iaLevelLast = -1; | |||
@@ -62,90 +62,90 @@ class UnflattenProcessor { | |||
this.icNew = new Stack<InlineParent>(); | |||
} | |||
List unflatten() { | |||
if ( il != null ) { | |||
for ( Iterator<InlineArea> it = il.iterator(); it.hasNext(); ) { | |||
process ( it.next() ); | |||
if (il != null) { | |||
for (Iterator<InlineArea> it = il.iterator(); it.hasNext(); ) { | |||
process (it.next()); | |||
} | |||
} | |||
finishAll(); | |||
return ilNew; | |||
} | |||
private void process ( InlineArea ia ) { | |||
process ( findInlineContainers ( ia ), findTextContainer ( ia ), ia ); | |||
private void process (InlineArea ia) { | |||
process (findInlineContainers (ia), findTextContainer (ia), ia); | |||
} | |||
private void process ( List<InlineParent> ich, TextArea tc, InlineArea ia ) { | |||
if ( ( tcNew == null ) || ( tc != tcNew ) ) { | |||
maybeFinishTextContainer ( tc, ia ); | |||
maybeFinishInlineContainers ( ich, tc, ia ); | |||
update ( ich, tc, ia ); | |||
private void process (List<InlineParent> ich, TextArea tc, InlineArea ia) { | |||
if ((tcNew == null) || (tc != tcNew)) { | |||
maybeFinishTextContainer (tc, ia); | |||
maybeFinishInlineContainers (ich, tc, ia); | |||
update (ich, tc, ia); | |||
} else { | |||
// skip inline area whose text container is the current new text container, | |||
// which occurs in the context of the inline runs produced by a filled area | |||
} | |||
} | |||
private boolean shouldFinishTextContainer ( TextArea tc, InlineArea ia ) { | |||
if ( ( tcOrig != null ) && ( tc != tcOrig ) ) { | |||
private boolean shouldFinishTextContainer (TextArea tc, InlineArea ia) { | |||
if ((tcOrig != null) && (tc != tcOrig)) { | |||
return true; | |||
} else if ( ( iaLevelLast != -1 ) && ( ia.getBidiLevel() != iaLevelLast ) ) { | |||
} else if ((iaLevelLast != -1) && (ia.getBidiLevel() != iaLevelLast)) { | |||
return true; | |||
} else { | |||
return false; | |||
} | |||
} | |||
private void finishTextContainer() { | |||
finishTextContainer ( null, null ); | |||
finishTextContainer (null, null); | |||
} | |||
private void finishTextContainer ( TextArea tc, InlineArea ia ) { | |||
if ( tcNew != null ) { | |||
updateIPD ( tcNew ); | |||
if ( ! icNew.empty() ) { | |||
icNew.peek().addChildArea ( tcNew ); | |||
private void finishTextContainer (TextArea tc, InlineArea ia) { | |||
if (tcNew != null) { | |||
updateIPD (tcNew); | |||
if (! icNew.empty()) { | |||
icNew.peek().addChildArea (tcNew); | |||
} else { | |||
ilNew.add ( tcNew ); | |||
ilNew.add (tcNew); | |||
} | |||
} | |||
tcNew = null; | |||
} | |||
private void maybeFinishTextContainer ( TextArea tc, InlineArea ia ) { | |||
if ( shouldFinishTextContainer ( tc, ia ) ) { | |||
finishTextContainer ( tc, ia ); | |||
private void maybeFinishTextContainer (TextArea tc, InlineArea ia) { | |||
if (shouldFinishTextContainer (tc, ia)) { | |||
finishTextContainer (tc, ia); | |||
} | |||
} | |||
private boolean shouldFinishInlineContainer ( List<InlineParent> ich, TextArea tc, InlineArea ia ) { | |||
if ( ( ich == null ) || ich.isEmpty() ) { | |||
private boolean shouldFinishInlineContainer (List<InlineParent> ich, TextArea tc, InlineArea ia) { | |||
if ((ich == null) || ich.isEmpty()) { | |||
return ! icOrig.empty(); | |||
} else { | |||
if ( ! icOrig.empty() ) { | |||
if (! icOrig.empty()) { | |||
InlineParent ic = ich.get(0); | |||
InlineParent ic0 = icOrig.peek(); | |||
return ( ic != ic0 ) && ! isInlineParentOf ( ic, ic0 ); | |||
return (ic != ic0) && ! isInlineParentOf (ic, ic0); | |||
} else { | |||
return false; | |||
} | |||
} | |||
} | |||
private void finishInlineContainer() { | |||
finishInlineContainer ( null, null, null ); | |||
finishInlineContainer (null, null, null); | |||
} | |||
private void finishInlineContainer ( List<InlineParent> ich, TextArea tc, InlineArea ia ) { | |||
if ( ( ich != null ) && ! ich.isEmpty() ) { // finish non-matching inner inline container(s) | |||
for ( Iterator<InlineParent> it = ich.iterator(); it.hasNext(); ) { | |||
private void finishInlineContainer (List<InlineParent> ich, TextArea tc, InlineArea ia) { | |||
if ((ich != null) && ! ich.isEmpty()) { // finish non-matching inner inline container(s) | |||
for (Iterator<InlineParent> it = ich.iterator(); it.hasNext(); ) { | |||
InlineParent ic = it.next(); | |||
InlineParent ic0 = icOrig.empty() ? null : icOrig.peek(); | |||
if ( ic0 == null ) { | |||
if (ic0 == null) { | |||
assert icNew.empty(); | |||
} else if ( ic != ic0 ) { | |||
} else if (ic != ic0) { | |||
assert ! icNew.empty(); | |||
InlineParent icO0 = icOrig.pop(); | |||
InlineParent icN0 = icNew.pop(); | |||
assert icO0 != null; | |||
assert icN0 != null; | |||
if ( icNew.empty() ) { | |||
ilNew.add ( icN0 ); | |||
if (icNew.empty()) { | |||
ilNew.add (icN0); | |||
} else { | |||
icNew.peek().addChildArea ( icN0 ); | |||
icNew.peek().addChildArea (icN0); | |||
} | |||
if ( ! icOrig.empty() && ( icOrig.peek() == ic ) ) { | |||
if (! icOrig.empty() && (icOrig.peek() == ic)) { | |||
break; | |||
} | |||
} else { | |||
@@ -153,184 +153,184 @@ class UnflattenProcessor { | |||
} | |||
} | |||
} else { // finish all inline containers | |||
while ( ! icNew.empty() ) { | |||
while (! icNew.empty()) { | |||
InlineParent icO0 = icOrig.pop(); | |||
InlineParent icN0 = icNew.pop(); | |||
assert icO0 != null; | |||
assert icN0 != null; | |||
if ( icNew.empty() ) { | |||
ilNew.add ( icN0 ); | |||
if (icNew.empty()) { | |||
ilNew.add (icN0); | |||
} else { | |||
icNew.peek().addChildArea ( icN0 ); | |||
icNew.peek().addChildArea (icN0); | |||
} | |||
} | |||
} | |||
} | |||
private void maybeFinishInlineContainers ( List<InlineParent> ich, TextArea tc, InlineArea ia ) { | |||
if ( shouldFinishInlineContainer ( ich, tc, ia ) ) { | |||
finishInlineContainer ( ich, tc, ia ); | |||
private void maybeFinishInlineContainers (List<InlineParent> ich, TextArea tc, InlineArea ia) { | |||
if (shouldFinishInlineContainer (ich, tc, ia)) { | |||
finishInlineContainer (ich, tc, ia); | |||
} | |||
} | |||
private void finishAll() { | |||
finishTextContainer(); | |||
finishInlineContainer(); | |||
} | |||
private void update ( List<InlineParent> ich, TextArea tc, InlineArea ia ) { | |||
if ( ! alreadyUnflattened ( ia ) ) { | |||
if ( ( ich != null ) && ! ich.isEmpty() ) { | |||
pushInlineContainers ( ich ); | |||
private void update (List<InlineParent> ich, TextArea tc, InlineArea ia) { | |||
if (! alreadyUnflattened (ia)) { | |||
if ((ich != null) && ! ich.isEmpty()) { | |||
pushInlineContainers (ich); | |||
} | |||
if ( tc != null ) { | |||
pushTextContainer ( tc, ia ); | |||
if (tc != null) { | |||
pushTextContainer (tc, ia); | |||
} else { | |||
pushNonTextInline ( ia ); | |||
pushNonTextInline (ia); | |||
} | |||
iaLevelLast = ia.getBidiLevel(); | |||
tcOrig = tc; | |||
} else if ( tcNew != null ) { | |||
} else if (tcNew != null) { | |||
finishTextContainer(); | |||
tcOrig = null; | |||
} else { | |||
tcOrig = null; | |||
} | |||
} | |||
private boolean alreadyUnflattened ( InlineArea ia ) { | |||
for ( Iterator<InlineArea> it = ilNew.iterator(); it.hasNext(); ) { | |||
if ( ia.isAncestorOrSelf ( it.next() ) ) { | |||
private boolean alreadyUnflattened (InlineArea ia) { | |||
for (Iterator<InlineArea> it = ilNew.iterator(); it.hasNext(); ) { | |||
if (ia.isAncestorOrSelf (it.next())) { | |||
return true; | |||
} | |||
} | |||
return false; | |||
} | |||
private void pushInlineContainers ( List<InlineParent> ich ) { | |||
private void pushInlineContainers (List<InlineParent> ich) { | |||
LinkedList<InlineParent> icl = new LinkedList<InlineParent>(); | |||
for ( Iterator<InlineParent> it = ich.iterator(); it.hasNext(); ) { | |||
for (Iterator<InlineParent> it = ich.iterator(); it.hasNext(); ) { | |||
InlineParent ic = it.next(); | |||
if ( icOrig.search ( ic ) >= 0 ) { | |||
if (icOrig.search (ic) >= 0) { | |||
break; | |||
} else { | |||
icl.addFirst ( ic ); | |||
icl.addFirst (ic); | |||
} | |||
} | |||
for ( Iterator<InlineParent> it = icl.iterator(); it.hasNext(); ) { | |||
for (Iterator<InlineParent> it = icl.iterator(); it.hasNext(); ) { | |||
InlineParent ic = it.next(); | |||
icOrig.push ( ic ); | |||
icNew.push ( generateInlineContainer ( ic ) ); | |||
icOrig.push (ic); | |||
icNew.push (generateInlineContainer (ic)); | |||
} | |||
} | |||
private void pushTextContainer ( TextArea tc, InlineArea ia ) { | |||
if ( tc instanceof UnresolvedPageNumber ) { | |||
private void pushTextContainer (TextArea tc, InlineArea ia) { | |||
if (tc instanceof UnresolvedPageNumber) { | |||
tcNew = tc; | |||
} else { | |||
if ( tcNew == null ) { | |||
tcNew = generateTextContainer ( tc ); | |||
if (tcNew == null) { | |||
tcNew = generateTextContainer (tc); | |||
} | |||
tcNew.addChildArea ( ia ); | |||
tcNew.addChildArea (ia); | |||
} | |||
} | |||
private void pushNonTextInline ( InlineArea ia ) { | |||
if ( icNew.empty() ) { | |||
ilNew.add ( ia ); | |||
private void pushNonTextInline (InlineArea ia) { | |||
if (icNew.empty()) { | |||
ilNew.add (ia); | |||
} else { | |||
icNew.peek().addChildArea ( ia ); | |||
icNew.peek().addChildArea (ia); | |||
} | |||
} | |||
private InlineParent generateInlineContainer ( InlineParent i ) { | |||
if ( i instanceof BasicLinkArea ) { | |||
return generateBasicLinkArea ( (BasicLinkArea) i ); | |||
} else if ( i instanceof FilledArea ) { | |||
return generateFilledArea ( (FilledArea) i ); | |||
private InlineParent generateInlineContainer (InlineParent i) { | |||
if (i instanceof BasicLinkArea) { | |||
return generateBasicLinkArea ((BasicLinkArea) i); | |||
} else if (i instanceof FilledArea) { | |||
return generateFilledArea ((FilledArea) i); | |||
} else { | |||
return generateInlineContainer0 ( i ); | |||
return generateInlineContainer0 (i); | |||
} | |||
} | |||
private InlineParent generateBasicLinkArea ( BasicLinkArea l ) { | |||
private InlineParent generateBasicLinkArea (BasicLinkArea l) { | |||
BasicLinkArea lc = new BasicLinkArea(); | |||
if ( l != null ) { | |||
initializeInlineContainer ( lc, l ); | |||
initializeLinkArea ( lc, l ); | |||
if (l != null) { | |||
initializeInlineContainer (lc, l); | |||
initializeLinkArea (lc, l); | |||
} | |||
return lc; | |||
} | |||
private void initializeLinkArea ( BasicLinkArea lc, BasicLinkArea l ) { | |||
private void initializeLinkArea (BasicLinkArea lc, BasicLinkArea l) { | |||
assert lc != null; | |||
assert l != null; | |||
LinkResolver r = l.getResolver(); | |||
if ( r != null ) { | |||
if (r != null) { | |||
String[] idrefs = r.getIDRefs(); | |||
if ( idrefs.length > 0 ) { | |||
if (idrefs.length > 0) { | |||
String idref = idrefs[0]; | |||
LinkResolver lr = new LinkResolver ( idref, lc ); | |||
lc.setResolver ( lr ); | |||
r.addDependent ( lr ); | |||
LinkResolver lr = new LinkResolver (idref, lc); | |||
lc.setResolver (lr); | |||
r.addDependent (lr); | |||
} | |||
} | |||
} | |||
private InlineParent generateFilledArea ( FilledArea f ) { | |||
private InlineParent generateFilledArea (FilledArea f) { | |||
FilledArea fc = new FilledArea(); | |||
if ( f != null ) { | |||
initializeInlineContainer ( fc, f ); | |||
initializeFilledArea ( fc, f ); | |||
if (f != null) { | |||
initializeInlineContainer (fc, f); | |||
initializeFilledArea (fc, f); | |||
} | |||
return fc; | |||
} | |||
private void initializeFilledArea ( FilledArea fc, FilledArea f ) { | |||
private void initializeFilledArea (FilledArea fc, FilledArea f) { | |||
assert fc != null; | |||
assert f != null; | |||
fc.setIPD ( f.getIPD() ); | |||
fc.setUnitWidth ( f.getUnitWidth() ); | |||
fc.setAdjustingInfo( f.getAdjustingInfo() ); | |||
fc.setIPD (f.getIPD()); | |||
fc.setUnitWidth (f.getUnitWidth()); | |||
fc.setAdjustingInfo(f.getAdjustingInfo()); | |||
} | |||
private InlineParent generateInlineContainer0 ( InlineParent i ) { | |||
private InlineParent generateInlineContainer0 (InlineParent i) { | |||
InlineParent ic = new InlineParent(); | |||
if ( i != null ) { | |||
initializeInlineContainer ( ic, i ); | |||
if (i != null) { | |||
initializeInlineContainer (ic, i); | |||
} | |||
return ic; | |||
} | |||
private void initializeInlineContainer ( InlineParent ic, InlineParent i ) { | |||
private void initializeInlineContainer (InlineParent ic, InlineParent i) { | |||
assert ic != null; | |||
assert i != null; | |||
ic.setTraits ( i.getTraits() ); | |||
ic.setBPD ( i.getBPD() ); | |||
ic.setBlockProgressionOffset ( i.getBlockProgressionOffset() ); | |||
ic.setTraits (i.getTraits()); | |||
ic.setBPD (i.getBPD()); | |||
ic.setBlockProgressionOffset (i.getBlockProgressionOffset()); | |||
} | |||
private TextArea generateTextContainer ( TextArea t ) { | |||
private TextArea generateTextContainer (TextArea t) { | |||
TextArea tc = new TextArea(); | |||
if ( t != null ) { | |||
tc.setTraits ( t.getTraits() ); | |||
tc.setBPD ( t.getBPD() ); | |||
tc.setBlockProgressionOffset ( t.getBlockProgressionOffset() ); | |||
tc.setBaselineOffset ( t.getBaselineOffset() ); | |||
tc.setTextWordSpaceAdjust ( t.getTextWordSpaceAdjust() ); | |||
tc.setTextLetterSpaceAdjust ( t.getTextLetterSpaceAdjust() ); | |||
if (t != null) { | |||
tc.setTraits (t.getTraits()); | |||
tc.setBPD (t.getBPD()); | |||
tc.setBlockProgressionOffset (t.getBlockProgressionOffset()); | |||
tc.setBaselineOffset (t.getBaselineOffset()); | |||
tc.setTextWordSpaceAdjust (t.getTextWordSpaceAdjust()); | |||
tc.setTextLetterSpaceAdjust (t.getTextLetterSpaceAdjust()); | |||
} | |||
return tc; | |||
} | |||
private void updateIPD ( TextArea tc ) { | |||
private void updateIPD (TextArea tc) { | |||
int numAdjustable = 0; | |||
for ( Iterator it = tc.getChildAreas().iterator(); it.hasNext(); ) { | |||
for (Iterator it = tc.getChildAreas().iterator(); it.hasNext(); ) { | |||
InlineArea ia = (InlineArea) it.next(); | |||
if ( ia instanceof SpaceArea ) { | |||
if (ia instanceof SpaceArea) { | |||
SpaceArea sa = (SpaceArea) ia; | |||
if ( sa.isAdjustable() ) { | |||
if (sa.isAdjustable()) { | |||
numAdjustable++; | |||
} | |||
} | |||
} | |||
if ( numAdjustable > 0 ) { | |||
tc.setIPD ( tc.getIPD() + ( numAdjustable * tc.getTextWordSpaceAdjust() ) ); | |||
if (numAdjustable > 0) { | |||
tc.setIPD (tc.getIPD() + (numAdjustable * tc.getTextWordSpaceAdjust())); | |||
} | |||
} | |||
private TextArea findTextContainer ( InlineArea ia ) { | |||
private TextArea findTextContainer (InlineArea ia) { | |||
assert ia != null; | |||
TextArea t = null; | |||
while ( t == null ) { | |||
if ( ia instanceof TextArea ) { | |||
while (t == null) { | |||
if (ia instanceof TextArea) { | |||
t = (TextArea) ia; | |||
} else { | |||
Area p = ia.getParentArea(); | |||
if ( p instanceof InlineArea ) { | |||
if (p instanceof InlineArea) { | |||
ia = (InlineArea) p; | |||
} else { | |||
break; | |||
@@ -339,23 +339,23 @@ class UnflattenProcessor { | |||
} | |||
return t; | |||
} | |||
private List<InlineParent> findInlineContainers ( InlineArea ia ) { | |||
private List<InlineParent> findInlineContainers (InlineArea ia) { | |||
assert ia != null; | |||
List<InlineParent> ich = new ArrayList<InlineParent>(); | |||
Area a = ia.getParentArea(); | |||
while ( a != null ) { | |||
if ( a instanceof InlineArea ) { | |||
if ( ( a instanceof InlineParent ) && ! ( a instanceof TextArea ) ) { | |||
ich.add ( (InlineParent) a ); | |||
while (a != null) { | |||
if (a instanceof InlineArea) { | |||
if ((a instanceof InlineParent) && ! (a instanceof TextArea)) { | |||
ich.add ((InlineParent) a); | |||
} | |||
a = ( (InlineArea) a ) .getParentArea(); | |||
a = ((InlineArea) a) .getParentArea(); | |||
} else { | |||
a = null; | |||
} | |||
} | |||
return ich; | |||
} | |||
private boolean isInlineParentOf ( InlineParent ic0, InlineParent ic1 ) { | |||
private boolean isInlineParentOf (InlineParent ic0, InlineParent ic1) { | |||
assert ic0 != null; | |||
return ic0.getParentArea() == ic1; | |||
} |
@@ -59,10 +59,10 @@ public final class UnicodeBidiAlgorithm implements BidiConstants { | |||
* @param cs input character sequence representing a UTF-16 encoded string | |||
* @param defaultLevel the default paragraph level, which must be zero (LR) or one (RL) | |||
*/ | |||
public static int[] resolveLevels ( CharSequence cs, Direction defaultLevel ) { | |||
public static int[] resolveLevels (CharSequence cs, Direction defaultLevel) { | |||
int[] chars = new int [ cs.length() ]; | |||
if ( convertToScalar ( cs, chars ) || ( defaultLevel == Direction.RL ) ) { | |||
return resolveLevels ( chars, ( defaultLevel == Direction.RL ) ? 1 : 0, new int [ chars.length ] ); | |||
if (convertToScalar (cs, chars) || (defaultLevel == Direction.RL)) { | |||
return resolveLevels (chars, (defaultLevel == Direction.RL) ? 1 : 0, new int [ chars.length ]); | |||
} else { | |||
return null; | |||
} | |||
@@ -78,8 +78,8 @@ public final class UnicodeBidiAlgorithm implements BidiConstants { | |||
* @param defaultLevel the default paragraph level, which must be zero (LR) or one (RL) | |||
* @param levels array to receive levels, one for each character in chars array | |||
*/ | |||
public static int[] resolveLevels ( int[] chars, int defaultLevel, int[] levels ) { | |||
return resolveLevels ( chars, getClasses ( chars ), defaultLevel, levels, false ); | |||
public static int[] resolveLevels (int[] chars, int defaultLevel, int[] levels) { | |||
return resolveLevels (chars, getClasses (chars), defaultLevel, levels, false); | |||
} | |||
/** | |||
@@ -94,47 +94,47 @@ public final class UnicodeBidiAlgorithm implements BidiConstants { | |||
* @param levels array to receive levels, one for each character in chars array | |||
* @param useRuleL1 true if rule L1 should be used | |||
*/ | |||
public static int[] resolveLevels ( int[] chars, int[] classes, int defaultLevel, int[] levels, boolean useRuleL1 ) { | |||
public static int[] resolveLevels (int[] chars, int[] classes, int defaultLevel, int[] levels, boolean useRuleL1) { | |||
int[] ica = classes; | |||
int[] wca = copySequence ( ica ); | |||
int[] wca = copySequence (ica); | |||
int[] ea = new int [ levels.length ]; | |||
resolveExplicit ( wca, defaultLevel, ea ); | |||
resolveRuns ( wca, defaultLevel, ea, levelsFromEmbeddings ( ea, levels ) ); | |||
if ( useRuleL1 ) { | |||
resolveSeparators ( ica, wca, defaultLevel, levels ); | |||
resolveExplicit (wca, defaultLevel, ea); | |||
resolveRuns (wca, defaultLevel, ea, levelsFromEmbeddings (ea, levels)); | |||
if (useRuleL1) { | |||
resolveSeparators (ica, wca, defaultLevel, levels); | |||
} | |||
dump ( "RL: CC(" + ( ( chars != null ) ? chars.length : -1 ) + ")", chars, classes, defaultLevel, levels ); | |||
dump ("RL: CC(" + ((chars != null) ? chars.length : -1) + ")", chars, classes, defaultLevel, levels); | |||
return levels; | |||
} | |||
private static int[] copySequence ( int[] ta ) { | |||
private static int[] copySequence (int[] ta) { | |||
int[] na = new int [ ta.length ]; | |||
System.arraycopy ( ta, 0, na, 0, na.length ); | |||
System.arraycopy (ta, 0, na, 0, na.length); | |||
return na; | |||
} | |||
private static void resolveExplicit ( int[] wca, int defaultLevel, int[] ea ) { | |||
private static void resolveExplicit (int[] wca, int defaultLevel, int[] ea) { | |||
int[] es = new int [ MAX_LEVELS ]; /* embeddings stack */ | |||
int ei = 0; /* embeddings stack index */ | |||
int ec = defaultLevel; /* current embedding level */ | |||
for ( int i = 0, n = wca.length; i < n; i++ ) { | |||
for (int i = 0, n = wca.length; i < n; i++) { | |||
int bc = wca [ i ]; /* bidi class of current char */ | |||
int el; /* embedding level to assign to current char */ | |||
switch ( bc ) { | |||
switch (bc) { | |||
case LRE: // start left-to-right embedding | |||
case RLE: // start right-to-left embedding | |||
case LRO: // start left-to-right override | |||
case RLO: // start right-to-left override | |||
{ | |||
int en; /* new embedding level */ | |||
if ( ( bc == RLE ) || ( bc == RLO ) ) { | |||
en = ( ( ec & ~OVERRIDE ) + 1 ) | 1; | |||
if ((bc == RLE) || (bc == RLO)) { | |||
en = ((ec & ~OVERRIDE) + 1) | 1; | |||
} else { | |||
en = ( ( ec & ~OVERRIDE ) + 2 ) & ~1; | |||
en = ((ec & ~OVERRIDE) + 2) & ~1; | |||
} | |||
if ( en < ( MAX_LEVELS + 1 ) ) { | |||
if (en < (MAX_LEVELS + 1)) { | |||
es [ ei++ ] = ec; | |||
if ( ( bc == LRO ) || ( bc == RLO ) ) { | |||
if ((bc == LRO) || (bc == RLO)) { | |||
ec = en | OVERRIDE; | |||
} else { | |||
ec = en & ~OVERRIDE; | |||
@@ -148,7 +148,7 @@ public final class UnicodeBidiAlgorithm implements BidiConstants { | |||
case PDF: // pop directional formatting | |||
{ | |||
el = ec; | |||
if ( ei > 0 ) { | |||
if (ei > 0) { | |||
ec = es [ --ei ]; | |||
} else { | |||
// ignore isolated PDF | |||
@@ -167,15 +167,15 @@ public final class UnicodeBidiAlgorithm implements BidiConstants { | |||
break; | |||
} | |||
} | |||
switch ( bc ) { | |||
switch (bc) { | |||
case BN: | |||
break; | |||
case LRE: case RLE: case LRO: case RLO: case PDF: | |||
wca [ i ] = BN; | |||
break; | |||
default: | |||
if ( ( el & OVERRIDE ) != 0 ) { | |||
wca [ i ] = directionOfLevel ( el ); | |||
if ((el & OVERRIDE) != 0) { | |||
wca [ i ] = directionOfLevel (el); | |||
} | |||
break; | |||
} | |||
@@ -183,38 +183,38 @@ public final class UnicodeBidiAlgorithm implements BidiConstants { | |||
} | |||
} | |||
private static int directionOfLevel ( int level ) { | |||
return ( ( level & 1 ) != 0 ) ? R : L; | |||
private static int directionOfLevel (int level) { | |||
return ((level & 1) != 0) ? R : L; | |||
} | |||
private static int levelOfEmbedding ( int embedding ) { | |||
private static int levelOfEmbedding (int embedding) { | |||
return embedding & ~OVERRIDE; | |||
} | |||
private static int[] levelsFromEmbeddings ( int[] ea, int[] la ) { | |||
private static int[] levelsFromEmbeddings (int[] ea, int[] la) { | |||
assert ea != null; | |||
assert la != null; | |||
assert la.length == ea.length; | |||
for ( int i = 0, n = la.length; i < n; i++ ) { | |||
la [ i ] = levelOfEmbedding ( ea [ i ] ); | |||
for (int i = 0, n = la.length; i < n; i++) { | |||
la [ i ] = levelOfEmbedding (ea [ i ]); | |||
} | |||
return la; | |||
} | |||
private static void resolveRuns ( int[] wca, int defaultLevel, int[] ea, int[] la ) { | |||
if ( la.length != wca.length ) { | |||
throw new IllegalArgumentException ( "levels sequence length must match classes sequence length" ); | |||
} else if ( la.length != ea.length ) { | |||
throw new IllegalArgumentException ( "levels sequence length must match embeddings sequence length" ); | |||
private static void resolveRuns (int[] wca, int defaultLevel, int[] ea, int[] la) { | |||
if (la.length != wca.length) { | |||
throw new IllegalArgumentException ("levels sequence length must match classes sequence length"); | |||
} else if (la.length != ea.length) { | |||
throw new IllegalArgumentException ("levels sequence length must match embeddings sequence length"); | |||
} else { | |||
for ( int i = 0, n = ea.length, lPrev = defaultLevel; i < n; ) { | |||
for (int i = 0, n = ea.length, lPrev = defaultLevel; i < n; ) { | |||
int s = i; | |||
int e = s; | |||
int l = findNextNonRetainedFormattingLevel ( wca, ea, s, lPrev ); | |||
while ( e < n ) { | |||
if ( la [ e ] != l ) { | |||
if ( startsWithRetainedFormattingRun ( wca, ea, e ) ) { | |||
e += getLevelRunLength ( ea, e ); | |||
int l = findNextNonRetainedFormattingLevel (wca, ea, s, lPrev); | |||
while (e < n) { | |||
if (la [ e ] != l) { | |||
if (startsWithRetainedFormattingRun (wca, ea, e)) { | |||
e += getLevelRunLength (ea, e); | |||
} else { | |||
break; | |||
} | |||
@@ -222,34 +222,34 @@ public final class UnicodeBidiAlgorithm implements BidiConstants { | |||
e++; | |||
} | |||
} | |||
lPrev = resolveRun ( wca, defaultLevel, ea, la, s, e, l, lPrev ); | |||
lPrev = resolveRun (wca, defaultLevel, ea, la, s, e, l, lPrev); | |||
i = e; | |||
} | |||
} | |||
} | |||
private static int findNextNonRetainedFormattingLevel ( int[] wca, int[] ea, int start, int lPrev ) { | |||
private static int findNextNonRetainedFormattingLevel (int[] wca, int[] ea, int start, int lPrev) { | |||
int s = start; | |||
int e = wca.length; | |||
while ( s < e ) { | |||
if ( startsWithRetainedFormattingRun ( wca, ea, s ) ) { | |||
s += getLevelRunLength ( ea, s ); | |||
while (s < e) { | |||
if (startsWithRetainedFormattingRun (wca, ea, s)) { | |||
s += getLevelRunLength (ea, s); | |||
} else { | |||
break; | |||
} | |||
} | |||
if ( s < e ) { | |||
return levelOfEmbedding ( ea [ s ] ); | |||
if (s < e) { | |||
return levelOfEmbedding (ea [ s ]); | |||
} else { | |||
return lPrev; | |||
} | |||
} | |||
private static int getLevelRunLength ( int[] ea, int start ) { | |||
private static int getLevelRunLength (int[] ea, int start) { | |||
assert start < ea.length; | |||
int nl = 0; | |||
for ( int s = start, e = ea.length, l0 = levelOfEmbedding ( ea [ start ] ); s < e; s++ ) { | |||
if ( levelOfEmbedding ( ea [ s ] ) == l0 ) { | |||
for (int s = start, e = ea.length, l0 = levelOfEmbedding (ea [ start ]); s < e; s++) { | |||
if (levelOfEmbedding (ea [ s ]) == l0) { | |||
nl++; | |||
} else { | |||
break; | |||
@@ -258,21 +258,21 @@ public final class UnicodeBidiAlgorithm implements BidiConstants { | |||
return nl; | |||
} | |||
private static boolean startsWithRetainedFormattingRun ( int[] wca, int[] ea, int start ) { | |||
int nl = getLevelRunLength ( ea, start ); | |||
if ( nl > 0 ) { | |||
int nc = getRetainedFormattingRunLength ( wca, start ); | |||
return ( nc >= nl ); | |||
private static boolean startsWithRetainedFormattingRun (int[] wca, int[] ea, int start) { | |||
int nl = getLevelRunLength (ea, start); | |||
if (nl > 0) { | |||
int nc = getRetainedFormattingRunLength (wca, start); | |||
return (nc >= nl); | |||
} else { | |||
return false; | |||
} | |||
} | |||
private static int getRetainedFormattingRunLength ( int[] wca, int start ) { | |||
private static int getRetainedFormattingRunLength (int[] wca, int start) { | |||
assert start < wca.length; | |||
int nc = 0; | |||
for ( int s = start, e = wca.length; s < e; s++ ) { | |||
if ( wca [ s ] == BidiConstants.BN ) { | |||
for (int s = start, e = wca.length; s < e; s++) { | |||
if (wca [ s ] == BidiConstants.BN) { | |||
nc++; | |||
} else { | |||
break; | |||
@@ -281,209 +281,209 @@ public final class UnicodeBidiAlgorithm implements BidiConstants { | |||
return nc; | |||
} | |||
private static int resolveRun ( int[] wca, int defaultLevel, int[] ea, int[] la, int start, int end, int level, int levelPrev ) { | |||
private static int resolveRun (int[] wca, int defaultLevel, int[] ea, int[] la, int start, int end, int level, int levelPrev) { | |||
// determine start of run direction | |||
int sor = directionOfLevel ( max ( levelPrev, level ) ); | |||
int sor = directionOfLevel (max (levelPrev, level)); | |||
// determine end of run direction | |||
int le = -1; | |||
if ( end == wca.length ) { | |||
le = max ( level, defaultLevel ); | |||
if (end == wca.length) { | |||
le = max (level, defaultLevel); | |||
} else { | |||
for ( int i = end; i < wca.length; i++ ) { | |||
if ( wca [ i ] != BidiConstants.BN ) { | |||
le = max ( level, la [ i ] ); | |||
for (int i = end; i < wca.length; i++) { | |||
if (wca [ i ] != BidiConstants.BN) { | |||
le = max (level, la [ i ]); | |||
break; | |||
} | |||
} | |||
if ( le < 0 ) { | |||
le = max ( level, defaultLevel ); | |||
if (le < 0) { | |||
le = max (level, defaultLevel); | |||
} | |||
} | |||
int eor = directionOfLevel ( le ); | |||
int eor = directionOfLevel (le); | |||
if (log.isDebugEnabled()) { | |||
log.debug ( "BR[" + padLeft ( start, 3 ) + "," + padLeft ( end, 3 ) + "] :" + padLeft ( level, 2 ) + ": SOR(" + getClassName(sor) + "), EOR(" + getClassName(eor) + ")" ); | |||
log.debug ("BR[" + padLeft (start, 3) + "," + padLeft (end, 3) + "] :" + padLeft (level, 2) + ": SOR(" + getClassName(sor) + "), EOR(" + getClassName(eor) + ")"); | |||
} | |||
resolveWeak ( wca, defaultLevel, ea, la, start, end, level, sor, eor ); | |||
resolveNeutrals ( wca, defaultLevel, ea, la, start, end, level, sor, eor ); | |||
resolveImplicit ( wca, defaultLevel, ea, la, start, end, level, sor, eor ); | |||
resolveWeak (wca, defaultLevel, ea, la, start, end, level, sor, eor); | |||
resolveNeutrals (wca, defaultLevel, ea, la, start, end, level, sor, eor); | |||
resolveImplicit (wca, defaultLevel, ea, la, start, end, level, sor, eor); | |||
// if this run is all retained formatting, then return prior level, otherwise this run's level | |||
return isRetainedFormatting ( wca, start, end ) ? levelPrev : level; | |||
return isRetainedFormatting (wca, start, end) ? levelPrev : level; | |||
} | |||
private static void resolveWeak ( int[] wca, int defaultLevel, int[] ea, int[] la, int start, int end, int level, int sor, int eor ) { | |||
private static void resolveWeak (int[] wca, int defaultLevel, int[] ea, int[] la, int start, int end, int level, int sor, int eor) { | |||
// W1 - X BN* NSM -> X BN* X | |||
for ( int i = start, n = end, bcPrev = sor; i < n; i++ ) { | |||
for (int i = start, n = end, bcPrev = sor; i < n; i++) { | |||
int bc = wca [ i ]; | |||
if ( bc == NSM ) { | |||
if (bc == NSM) { | |||
wca [ i ] = bcPrev; | |||
} else if ( bc != BN ) { | |||
} else if (bc != BN) { | |||
bcPrev = bc; | |||
} | |||
} | |||
// W2 - AL ... EN -> AL ... AN | |||
for ( int i = start, n = end, bcPrev = sor; i < n; i++ ) { | |||
for (int i = start, n = end, bcPrev = sor; i < n; i++) { | |||
int bc = wca [ i ]; | |||
if ( bc == EN ) { | |||
if ( bcPrev == AL ) { | |||
if (bc == EN) { | |||
if (bcPrev == AL) { | |||
wca [ i ] = AN; | |||
} | |||
} else if ( isStrong ( bc ) ) { | |||
} else if (isStrong (bc)) { | |||
bcPrev = bc; | |||
} | |||
} | |||
// W3 - AL -> R | |||
for ( int i = start, n = end; i < n; i++ ) { | |||
for (int i = start, n = end; i < n; i++) { | |||
int bc = wca [ i ]; | |||
if ( bc == AL ) { | |||
if (bc == AL) { | |||
wca [ i ] = R; | |||
} | |||
} | |||
// W4 - EN BN* ES BN* EN -> EN BN* EN BN* EN; XN BN* CS BN* XN -> XN BN* XN BN* XN | |||
for ( int i = start, n = end, bcPrev = sor; i < n; i++ ) { | |||
for (int i = start, n = end, bcPrev = sor; i < n; i++) { | |||
int bc = wca [ i ]; | |||
if ( bc == ES ) { | |||
if (bc == ES) { | |||
int bcNext = eor; | |||
for ( int j = i + 1; j < n; j++ ) { | |||
if ( ( bc = wca [ j ] ) != BN ) { | |||
for (int j = i + 1; j < n; j++) { | |||
if ((bc = wca [ j ]) != BN) { | |||
bcNext = bc; | |||
break; | |||
} | |||
} | |||
if ( ( bcPrev == EN ) && ( bcNext == EN ) ) { | |||
if ((bcPrev == EN) && (bcNext == EN)) { | |||
wca [ i ] = EN; | |||
} | |||
} else if ( bc == CS ) { | |||
} else if (bc == CS) { | |||
int bcNext = eor; | |||
for ( int j = i + 1; j < n; j++ ) { | |||
if ( ( bc = wca [ j ] ) != BN ) { | |||
for (int j = i + 1; j < n; j++) { | |||
if ((bc = wca [ j ]) != BN) { | |||
bcNext = bc; | |||
break; | |||
} | |||
} | |||
if ( ( bcPrev == EN ) && ( bcNext == EN ) ) { | |||
if ((bcPrev == EN) && (bcNext == EN)) { | |||
wca [ i ] = EN; | |||
} else if ( ( bcPrev == AN ) && ( bcNext == AN ) ) { | |||
} else if ((bcPrev == AN) && (bcNext == AN)) { | |||
wca [ i ] = AN; | |||
} | |||
} | |||
if ( bc != BN ) { | |||
if (bc != BN) { | |||
bcPrev = bc; | |||
} | |||
} | |||
// W5 - EN (ET|BN)* -> EN (EN|BN)*; (ET|BN)* EN -> (EN|BN)* EN | |||
for ( int i = start, n = end, bcPrev = sor; i < n; i++ ) { | |||
for (int i = start, n = end, bcPrev = sor; i < n; i++) { | |||
int bc = wca [ i ]; | |||
if ( bc == ET ) { | |||
if (bc == ET) { | |||
int bcNext = eor; | |||
for ( int j = i + 1; j < n; j++ ) { | |||
for (int j = i + 1; j < n; j++) { | |||
bc = wca [ j ]; | |||
if ( ( bc != BN ) && ( bc != ET ) ) { | |||
if ((bc != BN) && (bc != ET)) { | |||
bcNext = bc; | |||
break; | |||
} | |||
} | |||
if ( ( bcPrev == EN ) || ( bcNext == EN ) ) { | |||
if ((bcPrev == EN) || (bcNext == EN)) { | |||
wca [ i ] = EN; | |||
} | |||
} else if ( ( bc != BN ) && ( bc != ET ) ) { | |||
} else if ((bc != BN) && (bc != ET)) { | |||
bcPrev = bc; | |||
} | |||
} | |||
// W6 - BN* (ET|ES|CS) BN* -> ON* ON ON* | |||
for ( int i = start, n = end; i < n; i++ ) { | |||
for (int i = start, n = end; i < n; i++) { | |||
int bc = wca [ i ]; | |||
if ( ( bc == ET ) || ( bc == ES ) || ( bc == CS ) ) { | |||
if ((bc == ET) || (bc == ES) || (bc == CS)) { | |||
wca [ i ] = ON; | |||
resolveAdjacentBoundaryNeutrals ( wca, start, end, i, ON ); | |||
resolveAdjacentBoundaryNeutrals (wca, start, end, i, ON); | |||
} | |||
} | |||
// W7 - L ... EN -> L ... L | |||
for ( int i = start, n = end, bcPrev = sor; i < n; i++ ) { | |||
for (int i = start, n = end, bcPrev = sor; i < n; i++) { | |||
int bc = wca [ i ]; | |||
if ( bc == EN ) { | |||
if ( bcPrev == L ) { | |||
if (bc == EN) { | |||
if (bcPrev == L) { | |||
wca [ i ] = L; | |||
} | |||
} else if ( ( bc == L ) || ( bc == R ) ) { | |||
} else if ((bc == L) || (bc == R)) { | |||
bcPrev = bc; | |||
} | |||
} | |||
} | |||
private static void resolveNeutrals ( int[] wca, int defaultLevel, int[] ea, int[] la, int start, int end, int level, int sor, int eor ) { | |||
private static void resolveNeutrals (int[] wca, int defaultLevel, int[] ea, int[] la, int start, int end, int level, int sor, int eor) { | |||
// N1 - (L|R) N+ (L|R) -> L L+ L | R R+ R; (AN|EN) N+ R -> (AN|EN) R+ R; R N+ (AN|EN) -> R R+ (AN|EN) | |||
for ( int i = start, n = end, bcPrev = sor; i < n; i++ ) { | |||
for (int i = start, n = end, bcPrev = sor; i < n; i++) { | |||
int bc = wca [ i ]; | |||
if ( isNeutral ( bc ) ) { | |||
if (isNeutral (bc)) { | |||
int bcNext = eor; | |||
for ( int j = i + 1; j < n; j++ ) { | |||
for (int j = i + 1; j < n; j++) { | |||
bc = wca [ j ]; | |||
if ( ( bc == L ) || ( bc == R ) ) { | |||
if ((bc == L) || (bc == R)) { | |||
bcNext = bc; | |||
break; | |||
} else if ( ( bc == AN ) || ( bc == EN ) ) { | |||
} else if ((bc == AN) || (bc == EN)) { | |||
bcNext = R; | |||
break; | |||
} else if ( isNeutral ( bc ) ) { | |||
} else if (isNeutral (bc)) { | |||
continue; | |||
} else if ( isRetainedFormatting ( bc ) ) { | |||
} else if (isRetainedFormatting (bc)) { | |||
continue; | |||
} else { | |||
break; | |||
} | |||
} | |||
if ( bcPrev == bcNext ) { | |||
if (bcPrev == bcNext) { | |||
wca [ i ] = bcPrev; | |||
resolveAdjacentBoundaryNeutrals ( wca, start, end, i, bcPrev ); | |||
resolveAdjacentBoundaryNeutrals (wca, start, end, i, bcPrev); | |||
} | |||
} else if ( ( bc == L ) || ( bc == R ) ) { | |||
} else if ((bc == L) || (bc == R)) { | |||
bcPrev = bc; | |||
} else if ( ( bc == AN ) || ( bc == EN ) ) { | |||
} else if ((bc == AN) || (bc == EN)) { | |||
bcPrev = R; | |||
} | |||
} | |||
// N2 - N -> embedding level | |||
for ( int i = start, n = end; i < n; i++ ) { | |||
for (int i = start, n = end; i < n; i++) { | |||
int bc = wca [ i ]; | |||
if ( isNeutral ( bc ) ) { | |||
int bcEmbedding = directionOfLevel ( levelOfEmbedding ( ea [ i ] ) ); | |||
if (isNeutral (bc)) { | |||
int bcEmbedding = directionOfLevel (levelOfEmbedding (ea [ i ])); | |||
wca [ i ] = bcEmbedding; | |||
resolveAdjacentBoundaryNeutrals ( wca, start, end, i, bcEmbedding ); | |||
resolveAdjacentBoundaryNeutrals (wca, start, end, i, bcEmbedding); | |||
} | |||
} | |||
} | |||
private static void resolveAdjacentBoundaryNeutrals ( int[] wca, int start, int end, int index, int bcNew ) { | |||
if ( ( index < start ) || ( index >= end ) ) { | |||
private static void resolveAdjacentBoundaryNeutrals (int[] wca, int start, int end, int index, int bcNew) { | |||
if ((index < start) || (index >= end)) { | |||
throw new IllegalArgumentException(); | |||
} else { | |||
for ( int i = index - 1; i >= start; i-- ) { | |||
for (int i = index - 1; i >= start; i--) { | |||
int bc = wca [ i ]; | |||
if ( bc == BN ) { | |||
if (bc == BN) { | |||
wca [ i ] = bcNew; | |||
} else { | |||
break; | |||
} | |||
} | |||
for ( int i = index + 1; i < end; i++ ) { | |||
for (int i = index + 1; i < end; i++) { | |||
int bc = wca [ i ]; | |||
if ( bc == BN ) { | |||
if (bc == BN) { | |||
wca [ i ] = bcNew; | |||
} else { | |||
break; | |||
@@ -492,25 +492,25 @@ public final class UnicodeBidiAlgorithm implements BidiConstants { | |||
} | |||
} | |||
private static void resolveImplicit ( int[] wca, int defaultLevel, int[] ea, int[] la, int start, int end, int level, int sor, int eor ) { | |||
for ( int i = start, n = end; i < n; i++ ) { | |||
private static void resolveImplicit (int[] wca, int defaultLevel, int[] ea, int[] la, int start, int end, int level, int sor, int eor) { | |||
for (int i = start, n = end; i < n; i++) { | |||
int bc = wca [ i ]; // bidi class | |||
int el = la [ i ]; // embedding level | |||
int ed = 0; // embedding level delta | |||
if ( ( el & 1 ) == 0 ) { // even | |||
if ( bc == R ) { | |||
if ((el & 1) == 0) { // even | |||
if (bc == R) { | |||
ed = 1; | |||
} else if ( bc == AN ) { | |||
} else if (bc == AN) { | |||
ed = 2; | |||
} else if ( bc == EN ) { | |||
} else if (bc == EN) { | |||
ed = 2; | |||
} | |||
} else { // odd | |||
if ( bc == L ) { | |||
if (bc == L) { | |||
ed = 1; | |||
} else if ( bc == EN ) { | |||
} else if (bc == EN) { | |||
ed = 1; | |||
} else if ( bc == AN ) { | |||
} else if (bc == AN) { | |||
ed = 1; | |||
} | |||
} | |||
@@ -526,17 +526,17 @@ public final class UnicodeBidiAlgorithm implements BidiConstants { | |||
* @param dl default paragraph level | |||
* @param la array of output levels to be adjusted, as produced by bidi algorithm | |||
*/ | |||
private static void resolveSeparators ( int[] ica, int[] wca, int dl, int[] la ) { | |||
private static void resolveSeparators (int[] ica, int[] wca, int dl, int[] la) { | |||
// steps (1) through (3) | |||
for ( int i = 0, n = ica.length; i < n; i++ ) { | |||
for (int i = 0, n = ica.length; i < n; i++) { | |||
int ic = ica[i]; | |||
if ( ( ic == BidiConstants.S ) || ( ic == BidiConstants.B ) ) { | |||
if ((ic == BidiConstants.S) || (ic == BidiConstants.B)) { | |||
la[i] = dl; | |||
for ( int k = i - 1; k >= 0; k-- ) { | |||
for (int k = i - 1; k >= 0; k--) { | |||
int pc = ica[k]; | |||
if ( isRetainedFormatting ( pc ) ) { | |||
if (isRetainedFormatting (pc)) { | |||
continue; | |||
} else if ( pc == BidiConstants.WS ) { | |||
} else if (pc == BidiConstants.WS) { | |||
la[k] = dl; | |||
} else { | |||
break; | |||
@@ -545,22 +545,22 @@ public final class UnicodeBidiAlgorithm implements BidiConstants { | |||
} | |||
} | |||
// step (4) - consider end of input sequence to be end of line, but skip any trailing boundary neutrals and retained formatting codes | |||
for ( int i = ica.length; i > 0; i-- ) { | |||
for (int i = ica.length; i > 0; i--) { | |||
int k = i - 1; | |||
int ic = ica[k]; | |||
if ( isRetainedFormatting ( ic ) ) { | |||
if (isRetainedFormatting (ic)) { | |||
continue; | |||
} else if ( ic == BidiConstants.WS ) { | |||
} else if (ic == BidiConstants.WS) { | |||
la[k] = dl; | |||
} else { | |||
break; | |||
} | |||
} | |||
// step (5) - per section 5.2 | |||
for ( int i = 0, n = ica.length; i < n; i++ ) { | |||
for (int i = 0, n = ica.length; i < n; i++) { | |||
int ic = ica[i]; | |||
if ( isRetainedFormatting ( ic ) ) { | |||
if ( i == 0 ) { | |||
if (isRetainedFormatting (ic)) { | |||
if (i == 0) { | |||
la[i] = dl; | |||
} else { | |||
la[i] = la [ i - 1 ]; | |||
@@ -569,8 +569,8 @@ public final class UnicodeBidiAlgorithm implements BidiConstants { | |||
} | |||
} | |||
private static boolean isStrong ( int bc ) { | |||
switch ( bc ) { | |||
private static boolean isStrong (int bc) { | |||
switch (bc) { | |||
case L: | |||
case R: | |||
case AL: | |||
@@ -580,8 +580,8 @@ public final class UnicodeBidiAlgorithm implements BidiConstants { | |||
} | |||
} | |||
private static boolean isNeutral ( int bc ) { | |||
switch ( bc ) { | |||
private static boolean isNeutral (int bc) { | |||
switch (bc) { | |||
case WS: | |||
case ON: | |||
case S: | |||
@@ -592,8 +592,8 @@ public final class UnicodeBidiAlgorithm implements BidiConstants { | |||
} | |||
} | |||
private static boolean isRetainedFormatting ( int bc ) { | |||
switch ( bc ) { | |||
private static boolean isRetainedFormatting (int bc) { | |||
switch (bc) { | |||
case LRE: | |||
case LRO: | |||
case RLE: | |||
@@ -606,30 +606,30 @@ public final class UnicodeBidiAlgorithm implements BidiConstants { | |||
} | |||
} | |||
private static boolean isRetainedFormatting ( int[] ca, int s, int e ) { | |||
for ( int i = s; i < e; i++ ) { | |||
if ( ! isRetainedFormatting ( ca[i] ) ) { | |||
private static boolean isRetainedFormatting (int[] ca, int s, int e) { | |||
for (int i = s; i < e; i++) { | |||
if (! isRetainedFormatting (ca[i])) { | |||
return false; | |||
} | |||
} | |||
return true; | |||
} | |||
private static int max ( int x, int y ) { | |||
if ( x > y ) { | |||
private static int max (int x, int y) { | |||
if (x > y) { | |||
return x; | |||
} else { | |||
return y; | |||
} | |||
} | |||
private static int[] getClasses ( int[] chars ) { | |||
private static int[] getClasses (int[] chars) { | |||
int[] classes = new int [ chars.length ]; | |||
int bc; | |||
for ( int i = 0, n = chars.length; i < n; i++ ) { | |||
for (int i = 0, n = chars.length; i < n; i++) { | |||
int ch = chars [ i ]; | |||
if ( ch >= 0 ) { | |||
bc = BidiClass.getBidiClass ( chars [ i ] ); | |||
if (ch >= 0) { | |||
bc = BidiClass.getBidiClass (chars [ i ]); | |||
} else { | |||
bc = SURROGATE; | |||
} | |||
@@ -652,38 +652,38 @@ public final class UnicodeBidiAlgorithm implements BidiConstants { | |||
* @throws IllegalArgumentException if the input sequence is not a valid UTF-16 string, e.g., | |||
* if it contains an isolated UTF-16 surrogate | |||
*/ | |||
private static boolean convertToScalar ( CharSequence cs, int[] chars ) throws IllegalArgumentException { | |||
private static boolean convertToScalar (CharSequence cs, int[] chars) throws IllegalArgumentException { | |||
boolean triggered = false; | |||
if ( chars.length != cs.length() ) { | |||
throw new IllegalArgumentException ( "characters array length must match input sequence length" ); | |||
if (chars.length != cs.length()) { | |||
throw new IllegalArgumentException ("characters array length must match input sequence length"); | |||
} | |||
for ( int i = 0, n = chars.length; i < n; ) { | |||
int chIn = cs.charAt ( i ); | |||
for (int i = 0, n = chars.length; i < n; ) { | |||
int chIn = cs.charAt (i); | |||
int chOut; | |||
if ( chIn < 0xD800 ) { | |||
if (chIn < 0xD800) { | |||
chOut = chIn; | |||
} else if ( chIn < 0xDC00 ) { | |||
} else if (chIn < 0xDC00) { | |||
int chHi = chIn; | |||
int chLo; | |||
if ( ( i + 1 ) < n ) { | |||
chLo = cs.charAt ( i + 1 ); | |||
if ( ( chLo >= 0xDC00 ) && ( chLo <= 0xDFFF ) ) { | |||
chOut = convertToScalar ( chHi, chLo ); | |||
if ((i + 1) < n) { | |||
chLo = cs.charAt (i + 1); | |||
if ((chLo >= 0xDC00) && (chLo <= 0xDFFF)) { | |||
chOut = convertToScalar (chHi, chLo); | |||
} else { | |||
throw new IllegalArgumentException ( "isolated high surrogate" ); | |||
throw new IllegalArgumentException ("isolated high surrogate"); | |||
} | |||
} else { | |||
throw new IllegalArgumentException ( "truncated surrogate pair" ); | |||
throw new IllegalArgumentException ("truncated surrogate pair"); | |||
} | |||
} else if ( chIn < 0xE000 ) { | |||
throw new IllegalArgumentException ( "isolated low surrogate" ); | |||
} else if (chIn < 0xE000) { | |||
throw new IllegalArgumentException ("isolated low surrogate"); | |||
} else { | |||
chOut = chIn; | |||
} | |||
if ( ! triggered && triggersBidi ( chOut ) ) { | |||
if (! triggered && triggersBidi (chOut)) { | |||
triggered = true; | |||
} | |||
if ( ( chOut & 0xFF0000 ) == 0 ) { | |||
if ((chOut & 0xFF0000) == 0) { | |||
chars [ i++ ] = chOut; | |||
} else { | |||
chars [ i++ ] = chOut; | |||
@@ -700,13 +700,13 @@ public final class UnicodeBidiAlgorithm implements BidiConstants { | |||
* @param chLo low (least significant or second) surrogate | |||
* @throws IllegalArgumentException if one of the input surrogates is not valid | |||
*/ | |||
private static int convertToScalar ( int chHi, int chLo ) { | |||
if ( ( chHi < 0xD800 ) || ( chHi > 0xDBFF ) ) { | |||
throw new IllegalArgumentException ( "bad high surrogate" ); | |||
} else if ( ( chLo < 0xDC00 ) || ( chLo > 0xDFFF ) ) { | |||
throw new IllegalArgumentException ( "bad low surrogate" ); | |||
private static int convertToScalar (int chHi, int chLo) { | |||
if ((chHi < 0xD800) || (chHi > 0xDBFF)) { | |||
throw new IllegalArgumentException ("bad high surrogate"); | |||
} else if ((chLo < 0xDC00) || (chLo > 0xDFFF)) { | |||
throw new IllegalArgumentException ("bad low surrogate"); | |||
} else { | |||
return ( ( ( chHi & 0x03FF ) << 10 ) | ( chLo & 0x03FF ) ) + 0x10000; | |||
return (((chHi & 0x03FF) << 10) | (chLo & 0x03FF)) + 0x10000; | |||
} | |||
} | |||
@@ -718,8 +718,8 @@ public final class UnicodeBidiAlgorithm implements BidiConstants { | |||
* @return true if character triggers bidirectional processing | |||
* @param ch a unicode scalar value | |||
*/ | |||
private static boolean triggersBidi ( int ch ) { | |||
switch ( BidiClass.getBidiClass ( ch ) ) { | |||
private static boolean triggersBidi (int ch) { | |||
switch (BidiClass.getBidiClass (ch)) { | |||
case R: | |||
case AL: | |||
case AN: | |||
@@ -731,39 +731,39 @@ public final class UnicodeBidiAlgorithm implements BidiConstants { | |||
} | |||
} | |||
private static void dump ( String header, int[] chars, int[] classes, int defaultLevel, int[] levels ) { | |||
log.debug ( header ); | |||
log.debug ( "BD: default level(" + defaultLevel + ")" ); | |||
private static void dump (String header, int[] chars, int[] classes, int defaultLevel, int[] levels) { | |||
log.debug (header); | |||
log.debug ("BD: default level(" + defaultLevel + ")"); | |||
StringBuffer sb = new StringBuffer(); | |||
if ( chars != null ) { | |||
for ( int i = 0, n = chars.length; i < n; i++ ) { | |||
if (chars != null) { | |||
for (int i = 0, n = chars.length; i < n; i++) { | |||
int ch = chars [ i ]; | |||
sb.setLength(0); | |||
if ( ( ch > 0x20 ) && ( ch < 0x7F ) ) { | |||
sb.append ( (char) ch ); | |||
if ((ch > 0x20) && (ch < 0x7F)) { | |||
sb.append ((char) ch); | |||
} else { | |||
sb.append ( CharUtilities.charToNCRef ( ch ) ); | |||
sb.append (CharUtilities.charToNCRef (ch)); | |||
} | |||
for ( int k = sb.length(); k < 12; k++ ) { | |||
sb.append ( ' ' ); | |||
for (int k = sb.length(); k < 12; k++) { | |||
sb.append (' '); | |||
} | |||
sb.append ( ": " + padRight ( getClassName ( classes[i] ), 4 ) + " " + levels[i] ); | |||
log.debug ( sb ); | |||
sb.append (": " + padRight (getClassName (classes[i]), 4) + " " + levels[i]); | |||
log.debug (sb); | |||
} | |||
} else { | |||
for ( int i = 0, n = classes.length; i < n; i++ ) { | |||
for (int i = 0, n = classes.length; i < n; i++) { | |||
sb.setLength(0); | |||
for ( int k = sb.length(); k < 12; k++ ) { | |||
sb.append ( ' ' ); | |||
for (int k = sb.length(); k < 12; k++) { | |||
sb.append (' '); | |||
} | |||
sb.append ( ": " + padRight ( getClassName ( classes[i] ), 4 ) + " " + levels[i] ); | |||
log.debug ( sb ); | |||
sb.append (": " + padRight (getClassName (classes[i]), 4) + " " + levels[i]); | |||
log.debug (sb); | |||
} | |||
} | |||
} | |||
private static String getClassName ( int bc ) { | |||
switch ( bc ) { | |||
private static String getClassName (int bc) { | |||
switch (bc) { | |||
case L: // left-to-right | |||
return "L"; | |||
case LRE: // left-to-right embedding | |||
@@ -809,16 +809,16 @@ public final class UnicodeBidiAlgorithm implements BidiConstants { | |||
} | |||
} | |||
private static String padLeft ( int n, int width ) { | |||
return padLeft ( Integer.toString ( n ), width ); | |||
private static String padLeft (int n, int width) { | |||
return padLeft (Integer.toString (n), width); | |||
} | |||
private static String padLeft ( String s, int width ) { | |||
private static String padLeft (String s, int width) { | |||
StringBuffer sb = new StringBuffer(); | |||
for ( int i = s.length(); i < width; i++ ) { | |||
for (int i = s.length(); i < width; i++) { | |||
sb.append(' '); | |||
} | |||
sb.append ( s ); | |||
sb.append (s); | |||
return sb.toString(); | |||
} | |||
@@ -828,9 +828,9 @@ public final class UnicodeBidiAlgorithm implements BidiConstants { | |||
} | |||
*/ | |||
private static String padRight ( String s, int width ) { | |||
StringBuffer sb = new StringBuffer ( s ); | |||
for ( int i = sb.length(); i < width; i++ ) { | |||
private static String padRight (String s, int width) { | |||
StringBuffer sb = new StringBuffer (s); | |||
for (int i = sb.length(); i < width; i++) { | |||
sb.append(' '); | |||
} | |||
return sb.toString(); |
@@ -35,7 +35,7 @@ public interface GlyphClassMapping { | |||
* @param set for coverage set based class mappings, indicates set index, otherwise ignored | |||
* @return size of class table | |||
*/ | |||
int getClassSize ( int set ); | |||
int getClassSize (int set); | |||
/** | |||
* Map glyph identifier (code) to coverge index. Returns -1 if glyph identifier is not in the domain of | |||
@@ -44,6 +44,6 @@ public interface GlyphClassMapping { | |||
* @param set for coverage set based class mappings, indicates set index, otherwise ignored | |||
* @return non-negative glyph class index or -1 if glyph identifiers is not mapped by table | |||
*/ | |||
int getClassIndex ( int gid, int set ); | |||
int getClassIndex (int gid, int set); | |||
} |
@@ -46,7 +46,7 @@ public final class GlyphClassTable extends GlyphMappingTable implements GlyphCla | |||
private GlyphClassMapping cm; | |||
private GlyphClassTable ( GlyphClassMapping cm ) { | |||
private GlyphClassTable (GlyphClassMapping cm) { | |||
assert cm != null; | |||
assert cm instanceof GlyphMappingTable; | |||
this.cm = cm; | |||
@@ -54,22 +54,22 @@ public final class GlyphClassTable extends GlyphMappingTable implements GlyphCla | |||
/** {@inheritDoc} */ | |||
public int getType() { | |||
return ( (GlyphMappingTable) cm ) .getType(); | |||
return ((GlyphMappingTable) cm) .getType(); | |||
} | |||
/** {@inheritDoc} */ | |||
public List getEntries() { | |||
return ( (GlyphMappingTable) cm ) .getEntries(); | |||
return ((GlyphMappingTable) cm) .getEntries(); | |||
} | |||
/** {@inheritDoc} */ | |||
public int getClassSize ( int set ) { | |||
return cm.getClassSize ( set ); | |||
public int getClassSize (int set) { | |||
return cm.getClassSize (set); | |||
} | |||
/** {@inheritDoc} */ | |||
public int getClassIndex ( int gid, int set ) { | |||
return cm.getClassIndex ( gid, set ); | |||
public int getClassIndex (int gid, int set) { | |||
return cm.getClassIndex (gid, set); | |||
} | |||
/** | |||
@@ -77,30 +77,30 @@ public final class GlyphClassTable extends GlyphMappingTable implements GlyphCla | |||
* @param entries list of mapped or ranged class entries, or null or empty list | |||
* @return a new covera table instance | |||
*/ | |||
public static GlyphClassTable createClassTable ( List entries ) { | |||
public static GlyphClassTable createClassTable (List entries) { | |||
GlyphClassMapping cm; | |||
if ( ( entries == null ) || ( entries.size() == 0 ) ) { | |||
cm = new EmptyClassTable ( entries ); | |||
} else if ( isMappedClass ( entries ) ) { | |||
cm = new MappedClassTable ( entries ); | |||
} else if ( isRangeClass ( entries ) ) { | |||
cm = new RangeClassTable ( entries ); | |||
} else if ( isCoverageSetClass ( entries ) ) { | |||
cm = new CoverageSetClassTable ( entries ); | |||
if ((entries == null) || (entries.size() == 0)) { | |||
cm = new EmptyClassTable (entries); | |||
} else if (isMappedClass (entries)) { | |||
cm = new MappedClassTable (entries); | |||
} else if (isRangeClass (entries)) { | |||
cm = new RangeClassTable (entries); | |||
} else if (isCoverageSetClass (entries)) { | |||
cm = new CoverageSetClassTable (entries); | |||
} else { | |||
cm = null; | |||
} | |||
assert cm != null : "unknown class type"; | |||
return new GlyphClassTable ( cm ); | |||
return new GlyphClassTable (cm); | |||
} | |||
private static boolean isMappedClass ( List entries ) { | |||
if ( ( entries == null ) || ( entries.size() == 0 ) ) { | |||
private static boolean isMappedClass (List entries) { | |||
if ((entries == null) || (entries.size() == 0)) { | |||
return false; | |||
} else { | |||
for ( Iterator it = entries.iterator(); it.hasNext();) { | |||
for (Iterator it = entries.iterator(); it.hasNext();) { | |||
Object o = it.next(); | |||
if ( ! ( o instanceof Integer ) ) { | |||
if (! (o instanceof Integer)) { | |||
return false; | |||
} | |||
} | |||
@@ -108,13 +108,13 @@ public final class GlyphClassTable extends GlyphMappingTable implements GlyphCla | |||
} | |||
} | |||
private static boolean isRangeClass ( List entries ) { | |||
if ( ( entries == null ) || ( entries.size() == 0 ) ) { | |||
private static boolean isRangeClass (List entries) { | |||
if ((entries == null) || (entries.size() == 0)) { | |||
return false; | |||
} else { | |||
for ( Iterator it = entries.iterator(); it.hasNext();) { | |||
for (Iterator it = entries.iterator(); it.hasNext();) { | |||
Object o = it.next(); | |||
if ( ! ( o instanceof MappingRange ) ) { | |||
if (! (o instanceof MappingRange)) { | |||
return false; | |||
} | |||
} | |||
@@ -122,13 +122,13 @@ public final class GlyphClassTable extends GlyphMappingTable implements GlyphCla | |||
} | |||
} | |||
private static boolean isCoverageSetClass ( List entries ) { | |||
if ( ( entries == null ) || ( entries.size() == 0 ) ) { | |||
private static boolean isCoverageSetClass (List entries) { | |||
if ((entries == null) || (entries.size() == 0)) { | |||
return false; | |||
} else { | |||
for ( Iterator it = entries.iterator(); it.hasNext();) { | |||
for (Iterator it = entries.iterator(); it.hasNext();) { | |||
Object o = it.next(); | |||
if ( ! ( o instanceof GlyphCoverageTable ) ) { | |||
if (! (o instanceof GlyphCoverageTable)) { | |||
return false; | |||
} | |||
} | |||
@@ -137,15 +137,15 @@ public final class GlyphClassTable extends GlyphMappingTable implements GlyphCla | |||
} | |||
private static class EmptyClassTable extends GlyphMappingTable.EmptyMappingTable implements GlyphClassMapping { | |||
public EmptyClassTable ( List entries ) { | |||
super ( entries ); | |||
public EmptyClassTable (List entries) { | |||
super (entries); | |||
} | |||
/** {@inheritDoc} */ | |||
public int getClassSize ( int set ) { | |||
public int getClassSize (int set) { | |||
return 0; | |||
} | |||
/** {@inheritDoc} */ | |||
public int getClassIndex ( int gid, int set ) { | |||
public int getClassIndex (int gid, int set) { | |||
return -1; | |||
} | |||
} | |||
@@ -154,16 +154,16 @@ public final class GlyphClassTable extends GlyphMappingTable implements GlyphCla | |||
private int firstGlyph; | |||
private int[] gca; | |||
private int gcMax = -1; | |||
public MappedClassTable ( List entries ) { | |||
populate ( entries ); | |||
public MappedClassTable (List entries) { | |||
populate (entries); | |||
} | |||
/** {@inheritDoc} */ | |||
public List getEntries() { | |||
List entries = new java.util.ArrayList(); | |||
entries.add ( Integer.valueOf ( firstGlyph ) ); | |||
if ( gca != null ) { | |||
for ( int i = 0, n = gca.length; i < n; i++ ) { | |||
entries.add ( Integer.valueOf ( gca [ i ] ) ); | |||
entries.add (Integer.valueOf (firstGlyph)); | |||
if (gca != null) { | |||
for (int i = 0, n = gca.length; i < n; i++) { | |||
entries.add (Integer.valueOf (gca [ i ])); | |||
} | |||
} | |||
return entries; | |||
@@ -173,33 +173,33 @@ public final class GlyphClassTable extends GlyphMappingTable implements GlyphCla | |||
return gcMax + 1; | |||
} | |||
/** {@inheritDoc} */ | |||
public int getMappedIndex ( int gid ) { | |||
public int getMappedIndex (int gid) { | |||
int i = gid - firstGlyph; | |||
if ( ( i >= 0 ) && ( i < gca.length ) ) { | |||
if ((i >= 0) && (i < gca.length)) { | |||
return gca [ i ]; | |||
} else { | |||
return -1; | |||
} | |||
} | |||
/** {@inheritDoc} */ | |||
public int getClassSize ( int set ) { | |||
public int getClassSize (int set) { | |||
return getMappingSize(); | |||
} | |||
/** {@inheritDoc} */ | |||
public int getClassIndex ( int gid, int set ) { | |||
return getMappedIndex ( gid ); | |||
public int getClassIndex (int gid, int set) { | |||
return getMappedIndex (gid); | |||
} | |||
private void populate ( List entries ) { | |||
private void populate (List entries) { | |||
// obtain entries iterator | |||
Iterator it = entries.iterator(); | |||
// extract first glyph | |||
int firstGlyph = 0; | |||
if ( it.hasNext() ) { | |||
if (it.hasNext()) { | |||
Object o = it.next(); | |||
if ( o instanceof Integer ) { | |||
firstGlyph = ( (Integer) o ) . intValue(); | |||
if (o instanceof Integer) { | |||
firstGlyph = ((Integer) o) . intValue(); | |||
} else { | |||
throw new AdvancedTypographicTableFormatException ( "illegal entry, first entry must be Integer denoting first glyph value, but is: " + o ); | |||
throw new AdvancedTypographicTableFormatException ("illegal entry, first entry must be Integer denoting first glyph value, but is: " + o); | |||
} | |||
} | |||
// extract glyph class array | |||
@@ -207,16 +207,16 @@ public final class GlyphClassTable extends GlyphMappingTable implements GlyphCla | |||
int n = entries.size() - 1; | |||
int gcMax = -1; | |||
int[] gca = new int [ n ]; | |||
while ( it.hasNext() ) { | |||
while (it.hasNext()) { | |||
Object o = it.next(); | |||
if ( o instanceof Integer ) { | |||
int gc = ( (Integer) o ) . intValue(); | |||
if (o instanceof Integer) { | |||
int gc = ((Integer) o) . intValue(); | |||
gca [ i++ ] = gc; | |||
if ( gc > gcMax ) { | |||
if (gc > gcMax) { | |||
gcMax = gc; | |||
} | |||
} else { | |||
throw new AdvancedTypographicTableFormatException ( "illegal mapping entry, must be Integer: " + o ); | |||
throw new AdvancedTypographicTableFormatException ("illegal mapping entry, must be Integer: " + o); | |||
} | |||
} | |||
assert i == n; | |||
@@ -229,11 +229,11 @@ public final class GlyphClassTable extends GlyphMappingTable implements GlyphCla | |||
public String toString() { | |||
StringBuffer sb = new StringBuffer(); | |||
sb.append("{ firstGlyph = " + firstGlyph + ", classes = {"); | |||
for ( int i = 0, n = gca.length; i < n; i++ ) { | |||
if ( i > 0 ) { | |||
for (int i = 0, n = gca.length; i < n; i++) { | |||
if (i > 0) { | |||
sb.append(','); | |||
} | |||
sb.append ( Integer.toString ( gca [ i ] ) ); | |||
sb.append (Integer.toString (gca [ i ])); | |||
} | |||
sb.append("} }"); | |||
return sb.toString(); | |||
@@ -241,37 +241,37 @@ public final class GlyphClassTable extends GlyphMappingTable implements GlyphCla | |||
} | |||
private static class RangeClassTable extends GlyphMappingTable.RangeMappingTable implements GlyphClassMapping { | |||
public RangeClassTable ( List entries ) { | |||
super ( entries ); | |||
public RangeClassTable (List entries) { | |||
super (entries); | |||
} | |||
/** {@inheritDoc} */ | |||
public int getMappedIndex ( int gid, int s, int m ) { | |||
public int getMappedIndex (int gid, int s, int m) { | |||
return m; | |||
} | |||
/** {@inheritDoc} */ | |||
public int getClassSize ( int set ) { | |||
public int getClassSize (int set) { | |||
return getMappingSize(); | |||
} | |||
/** {@inheritDoc} */ | |||
public int getClassIndex ( int gid, int set ) { | |||
return getMappedIndex ( gid ); | |||
public int getClassIndex (int gid, int set) { | |||
return getMappedIndex (gid); | |||
} | |||
} | |||
private static class CoverageSetClassTable extends GlyphMappingTable.EmptyMappingTable implements GlyphClassMapping { | |||
public CoverageSetClassTable ( List entries ) { | |||
throw new UnsupportedOperationException ( "coverage set class table not yet supported" ); | |||
public CoverageSetClassTable (List entries) { | |||
throw new UnsupportedOperationException ("coverage set class table not yet supported"); | |||
} | |||
/** {@inheritDoc} */ | |||
public int getType() { | |||
return GLYPH_CLASS_TYPE_COVERAGE_SET; | |||
} | |||
/** {@inheritDoc} */ | |||
public int getClassSize ( int set ) { | |||
public int getClassSize (int set) { | |||
return 0; | |||
} | |||
/** {@inheritDoc} */ | |||
public int getClassIndex ( int gid, int set ) { | |||
public int getClassIndex (int gid, int set) { | |||
return -1; | |||
} | |||
} |
@@ -42,6 +42,6 @@ public interface GlyphCoverageMapping { | |||
* @param gid glyph identifier (code) | |||
* @return non-negative glyph coverage index or -1 if glyph identifiers is not mapped by table | |||
*/ | |||
int getCoverageIndex ( int gid ); | |||
int getCoverageIndex (int gid); | |||
} |
@@ -51,7 +51,7 @@ public final class GlyphCoverageTable extends GlyphMappingTable implements Glyph | |||
private GlyphCoverageMapping cm; | |||
private GlyphCoverageTable ( GlyphCoverageMapping cm ) { | |||
private GlyphCoverageTable (GlyphCoverageMapping cm) { | |||
assert cm != null; | |||
assert cm instanceof GlyphMappingTable; | |||
this.cm = cm; | |||
@@ -59,12 +59,12 @@ public final class GlyphCoverageTable extends GlyphMappingTable implements Glyph | |||
/** {@inheritDoc} */ | |||
public int getType() { | |||
return ( (GlyphMappingTable) cm ) .getType(); | |||
return ((GlyphMappingTable) cm) .getType(); | |||
} | |||
/** {@inheritDoc} */ | |||
public List getEntries() { | |||
return ( (GlyphMappingTable) cm ) .getEntries(); | |||
return ((GlyphMappingTable) cm) .getEntries(); | |||
} | |||
/** {@inheritDoc} */ | |||
@@ -73,8 +73,8 @@ public final class GlyphCoverageTable extends GlyphMappingTable implements Glyph | |||
} | |||
/** {@inheritDoc} */ | |||
public int getCoverageIndex ( int gid ) { | |||
return cm.getCoverageIndex ( gid ); | |||
public int getCoverageIndex (int gid) { | |||
return cm.getCoverageIndex (gid); | |||
} | |||
/** | |||
@@ -82,28 +82,28 @@ public final class GlyphCoverageTable extends GlyphMappingTable implements Glyph | |||
* @param entries list of mapped or ranged coverage entries, or null or empty list | |||
* @return a new covera table instance | |||
*/ | |||
public static GlyphCoverageTable createCoverageTable ( List entries ) { | |||
public static GlyphCoverageTable createCoverageTable (List entries) { | |||
GlyphCoverageMapping cm; | |||
if ( ( entries == null ) || ( entries.size() == 0 ) ) { | |||
cm = new EmptyCoverageTable ( entries ); | |||
} else if ( isMappedCoverage ( entries ) ) { | |||
cm = new MappedCoverageTable ( entries ); | |||
} else if ( isRangeCoverage ( entries ) ) { | |||
cm = new RangeCoverageTable ( entries ); | |||
if ((entries == null) || (entries.size() == 0)) { | |||
cm = new EmptyCoverageTable (entries); | |||
} else if (isMappedCoverage (entries)) { | |||
cm = new MappedCoverageTable (entries); | |||
} else if (isRangeCoverage (entries)) { | |||
cm = new RangeCoverageTable (entries); | |||
} else { | |||
cm = null; | |||
} | |||
assert cm != null : "unknown coverage type"; | |||
return new GlyphCoverageTable ( cm ); | |||
return new GlyphCoverageTable (cm); | |||
} | |||
private static boolean isMappedCoverage ( List entries ) { | |||
if ( ( entries == null ) || ( entries.size() == 0 ) ) { | |||
private static boolean isMappedCoverage (List entries) { | |||
if ((entries == null) || (entries.size() == 0)) { | |||
return false; | |||
} else { | |||
for ( Iterator it = entries.iterator(); it.hasNext();) { | |||
for (Iterator it = entries.iterator(); it.hasNext();) { | |||
Object o = it.next(); | |||
if ( ! ( o instanceof Integer ) ) { | |||
if (! (o instanceof Integer)) { | |||
return false; | |||
} | |||
} | |||
@@ -111,13 +111,13 @@ public final class GlyphCoverageTable extends GlyphMappingTable implements Glyph | |||
} | |||
} | |||
private static boolean isRangeCoverage ( List entries ) { | |||
if ( ( entries == null ) || ( entries.size() == 0 ) ) { | |||
private static boolean isRangeCoverage (List entries) { | |||
if ((entries == null) || (entries.size() == 0)) { | |||
return false; | |||
} else { | |||
for ( Iterator it = entries.iterator(); it.hasNext();) { | |||
for (Iterator it = entries.iterator(); it.hasNext();) { | |||
Object o = it.next(); | |||
if ( ! ( o instanceof MappingRange ) ) { | |||
if (! (o instanceof MappingRange)) { | |||
return false; | |||
} | |||
} | |||
@@ -126,41 +126,41 @@ public final class GlyphCoverageTable extends GlyphMappingTable implements Glyph | |||
} | |||
private static class EmptyCoverageTable extends GlyphMappingTable.EmptyMappingTable implements GlyphCoverageMapping { | |||
public EmptyCoverageTable ( List entries ) { | |||
super ( entries ); | |||
public EmptyCoverageTable (List entries) { | |||
super (entries); | |||
} | |||
/** {@inheritDoc} */ | |||
public int getCoverageSize() { | |||
return 0; | |||
} | |||
/** {@inheritDoc} */ | |||
public int getCoverageIndex ( int gid ) { | |||
public int getCoverageIndex (int gid) { | |||
return -1; | |||
} | |||
} | |||
private static class MappedCoverageTable extends GlyphMappingTable.MappedMappingTable implements GlyphCoverageMapping { | |||
private int[] map; | |||
public MappedCoverageTable ( List entries ) { | |||
populate ( entries ); | |||
public MappedCoverageTable (List entries) { | |||
populate (entries); | |||
} | |||
/** {@inheritDoc} */ | |||
public List getEntries() { | |||
List entries = new java.util.ArrayList(); | |||
if ( map != null ) { | |||
for ( int i = 0, n = map.length; i < n; i++ ) { | |||
entries.add ( Integer.valueOf ( map [ i ] ) ); | |||
if (map != null) { | |||
for (int i = 0, n = map.length; i < n; i++) { | |||
entries.add (Integer.valueOf (map [ i ])); | |||
} | |||
} | |||
return entries; | |||
} | |||
/** {@inheritDoc} */ | |||
public int getMappingSize() { | |||
return ( map != null ) ? map.length : 0; | |||
return (map != null) ? map.length : 0; | |||
} | |||
public int getMappedIndex ( int gid ) { | |||
public int getMappedIndex (int gid) { | |||
int i; | |||
if ( ( i = Arrays.binarySearch ( map, gid ) ) >= 0 ) { | |||
if ((i = Arrays.binarySearch (map, gid)) >= 0) { | |||
return i; | |||
} else { | |||
return -1; | |||
@@ -171,34 +171,34 @@ public final class GlyphCoverageTable extends GlyphMappingTable implements Glyph | |||
return getMappingSize(); | |||
} | |||
/** {@inheritDoc} */ | |||
public int getCoverageIndex ( int gid ) { | |||
return getMappedIndex ( gid ); | |||
public int getCoverageIndex (int gid) { | |||
return getMappedIndex (gid); | |||
} | |||
private void populate ( List entries ) { | |||
private void populate (List entries) { | |||
int i = 0; | |||
int skipped = 0; | |||
int n = entries.size(); | |||
int gidMax = -1; | |||
int[] map = new int [ n ]; | |||
for ( Iterator it = entries.iterator(); it.hasNext();) { | |||
for (Iterator it = entries.iterator(); it.hasNext();) { | |||
Object o = it.next(); | |||
if ( o instanceof Integer ) { | |||
int gid = ( (Integer) o ) . intValue(); | |||
if ( ( gid >= 0 ) && ( gid < 65536 ) ) { | |||
if ( gid > gidMax ) { | |||
if (o instanceof Integer) { | |||
int gid = ((Integer) o) . intValue(); | |||
if ((gid >= 0) && (gid < 65536)) { | |||
if (gid > gidMax) { | |||
map [ i++ ] = gidMax = gid; | |||
} else { | |||
log.info ( "ignoring out of order or duplicate glyph index: " + gid ); | |||
log.info ("ignoring out of order or duplicate glyph index: " + gid); | |||
skipped++; | |||
} | |||
} else { | |||
throw new AdvancedTypographicTableFormatException ( "illegal glyph index: " + gid ); | |||
throw new AdvancedTypographicTableFormatException ("illegal glyph index: " + gid); | |||
} | |||
} else { | |||
throw new AdvancedTypographicTableFormatException ( "illegal coverage entry, must be Integer: " + o ); | |||
throw new AdvancedTypographicTableFormatException ("illegal coverage entry, must be Integer: " + o); | |||
} | |||
} | |||
assert ( i + skipped ) == n; | |||
assert (i + skipped) == n; | |||
assert this.map == null; | |||
this.map = map; | |||
} | |||
@@ -206,11 +206,11 @@ public final class GlyphCoverageTable extends GlyphMappingTable implements Glyph | |||
public String toString() { | |||
StringBuffer sb = new StringBuffer(); | |||
sb.append('{'); | |||
for ( int i = 0, n = map.length; i < n; i++ ) { | |||
if ( i > 0 ) { | |||
for (int i = 0, n = map.length; i < n; i++) { | |||
if (i > 0) { | |||
sb.append(','); | |||
} | |||
sb.append ( Integer.toString ( map [ i ] ) ); | |||
sb.append (Integer.toString (map [ i ])); | |||
} | |||
sb.append('}'); | |||
return sb.toString(); | |||
@@ -218,11 +218,11 @@ public final class GlyphCoverageTable extends GlyphMappingTable implements Glyph | |||
} | |||
private static class RangeCoverageTable extends GlyphMappingTable.RangeMappingTable implements GlyphCoverageMapping { | |||
public RangeCoverageTable ( List entries ) { | |||
super ( entries ); | |||
public RangeCoverageTable (List entries) { | |||
super (entries); | |||
} | |||
/** {@inheritDoc} */ | |||
public int getMappedIndex ( int gid, int s, int m ) { | |||
public int getMappedIndex (int gid, int s, int m) { | |||
return m + gid - s; | |||
} | |||
/** {@inheritDoc} */ | |||
@@ -230,8 +230,8 @@ public final class GlyphCoverageTable extends GlyphMappingTable implements Glyph | |||
return getMappingSize(); | |||
} | |||
/** {@inheritDoc} */ | |||
public int getCoverageIndex ( int gid ) { | |||
return getMappedIndex ( gid ); | |||
public int getCoverageIndex (int gid) { | |||
return getMappedIndex (gid); | |||
} | |||
} | |||
@@ -34,6 +34,6 @@ public interface GlyphDefinition { | |||
* @param gi a glyph index | |||
* @return true if some (unspecified) definition is available for the specified glyph | |||
*/ | |||
boolean hasDefinition ( int gi ); | |||
boolean hasDefinition (int gi); | |||
} |
@@ -38,8 +38,8 @@ public abstract class GlyphDefinitionSubtable extends GlyphSubtable implements G | |||
* @param format subtable format | |||
* @param mapping subtable coverage table | |||
*/ | |||
protected GlyphDefinitionSubtable ( String id, int sequence, int flags, int format, GlyphMappingTable mapping ) { | |||
super ( id, sequence, flags, format, mapping ); | |||
protected GlyphDefinitionSubtable (String id, int sequence, int flags, int format, GlyphMappingTable mapping) { | |||
super (id, sequence, flags, format, mapping); | |||
} | |||
/** {@inheritDoc} */ | |||
@@ -49,7 +49,7 @@ public abstract class GlyphDefinitionSubtable extends GlyphSubtable implements G | |||
/** {@inheritDoc} */ | |||
public String getTypeName() { | |||
return GlyphDefinitionTable.getLookupTypeName ( getType() ); | |||
return GlyphDefinitionTable.getLookupTypeName (getType()); | |||
} | |||
/** {@inheritDoc} */ | |||
@@ -58,16 +58,16 @@ public abstract class GlyphDefinitionSubtable extends GlyphSubtable implements G | |||
} | |||
/** {@inheritDoc} */ | |||
public boolean hasDefinition ( int gi ) { | |||
public boolean hasDefinition (int gi) { | |||
GlyphCoverageMapping cvm; | |||
if ( ( cvm = getCoverage() ) != null ) { | |||
if ( cvm.getCoverageIndex ( gi ) >= 0 ) { | |||
if ((cvm = getCoverage()) != null) { | |||
if (cvm.getCoverageIndex (gi) >= 0) { | |||
return true; | |||
} | |||
} | |||
GlyphClassMapping clm; | |||
if ( ( clm = getClasses() ) != null ) { | |||
if ( clm.getClassIndex ( gi, 0 ) >= 0 ) { | |||
if ((clm = getClasses()) != null) { | |||
if (clm.getClassIndex (gi, 0) >= 0) { | |||
return true; | |||
} | |||
} |
@@ -74,17 +74,17 @@ public class GlyphDefinitionTable extends GlyphTable { | |||
* Instantiate a <code>GlyphDefinitionTable</code> object using the specified subtables. | |||
* @param subtables a list of identified subtables | |||
*/ | |||
public GlyphDefinitionTable ( List subtables ) { | |||
super ( null, new HashMap(0) ); | |||
if ( ( subtables == null ) || ( subtables.size() == 0 ) ) { | |||
throw new AdvancedTypographicTableFormatException ( "subtables must be non-empty" ); | |||
public GlyphDefinitionTable (List subtables) { | |||
super (null, new HashMap(0)); | |||
if ((subtables == null) || (subtables.size() == 0)) { | |||
throw new AdvancedTypographicTableFormatException ("subtables must be non-empty"); | |||
} else { | |||
for ( Iterator it = subtables.iterator(); it.hasNext();) { | |||
for (Iterator it = subtables.iterator(); it.hasNext();) { | |||
Object o = it.next(); | |||
if ( o instanceof GlyphDefinitionSubtable ) { | |||
addSubtable ( (GlyphSubtable) o ); | |||
if (o instanceof GlyphDefinitionSubtable) { | |||
addSubtable ((GlyphSubtable) o); | |||
} else { | |||
throw new AdvancedTypographicTableFormatException ( "subtable must be a glyph definition subtable" ); | |||
throw new AdvancedTypographicTableFormatException ("subtable must be a glyph definition subtable"); | |||
} | |||
} | |||
freezeSubtables(); | |||
@@ -102,25 +102,25 @@ public class GlyphDefinitionTable extends GlyphTable { | |||
* @param language a language identifier | |||
* @return the reordered (output) glyph sequence | |||
*/ | |||
public GlyphSequence reorderCombiningMarks ( GlyphSequence gs, int[][] gpa, String script, String language ) { | |||
ScriptProcessor sp = ScriptProcessor.getInstance ( script ); | |||
return sp.reorderCombiningMarks ( this, gs, gpa, script, language ); | |||
public GlyphSequence reorderCombiningMarks (GlyphSequence gs, int[][] gpa, String script, String language) { | |||
ScriptProcessor sp = ScriptProcessor.getInstance (script); | |||
return sp.reorderCombiningMarks (this, gs, gpa, script, language); | |||
} | |||
/** {@inheritDoc} */ | |||
protected void addSubtable ( GlyphSubtable subtable ) { | |||
if ( subtable instanceof GlyphClassSubtable ) { | |||
protected void addSubtable (GlyphSubtable subtable) { | |||
if (subtable instanceof GlyphClassSubtable) { | |||
this.gct = (GlyphClassSubtable) subtable; | |||
} else if ( subtable instanceof AttachmentPointSubtable ) { | |||
} else if (subtable instanceof AttachmentPointSubtable) { | |||
// TODO - not yet used | |||
// this.apt = (AttachmentPointSubtable) subtable; | |||
} else if ( subtable instanceof LigatureCaretSubtable ) { | |||
} else if (subtable instanceof LigatureCaretSubtable) { | |||
// TODO - not yet used | |||
// this.lct = (LigatureCaretSubtable) subtable; | |||
} else if ( subtable instanceof MarkAttachmentSubtable ) { | |||
} else if (subtable instanceof MarkAttachmentSubtable) { | |||
this.mat = (MarkAttachmentSubtable) subtable; | |||
} else { | |||
throw new UnsupportedOperationException ( "unsupported glyph definition subtable type: " + subtable ); | |||
throw new UnsupportedOperationException ("unsupported glyph definition subtable type: " + subtable); | |||
} | |||
} | |||
@@ -130,9 +130,9 @@ public class GlyphDefinitionTable extends GlyphTable { | |||
* @param gc a pre-defined glyph class (GLYPH_CLASS_BASE|GLYPH_CLASS_LIGATURE|GLYPH_CLASS_MARK|GLYPH_CLASS_COMPONENT). | |||
* @return true if glyph belongs to specified glyph class | |||
*/ | |||
public boolean isGlyphClass ( int gid, int gc ) { | |||
if ( gct != null ) { | |||
return gct.isGlyphClass ( gid, gc ); | |||
public boolean isGlyphClass (int gid, int gc) { | |||
if (gct != null) { | |||
return gct.isGlyphClass (gid, gc); | |||
} else { | |||
return false; | |||
} | |||
@@ -143,9 +143,9 @@ public class GlyphDefinitionTable extends GlyphTable { | |||
* @param gid a glyph identifier (index) | |||
* @return a pre-defined glyph class (GLYPH_CLASS_BASE|GLYPH_CLASS_LIGATURE|GLYPH_CLASS_MARK|GLYPH_CLASS_COMPONENT). | |||
*/ | |||
public int getGlyphClass ( int gid ) { | |||
if ( gct != null ) { | |||
return gct.getGlyphClass ( gid ); | |||
public int getGlyphClass (int gid) { | |||
if (gct != null) { | |||
return gct.getGlyphClass (gid); | |||
} else { | |||
return -1; | |||
} | |||
@@ -157,9 +157,9 @@ public class GlyphDefinitionTable extends GlyphTable { | |||
* @param mac a (font specific) mark attachment class | |||
* @return true if glyph belongs to specified mark attachment class | |||
*/ | |||
public boolean isMarkAttachClass ( int gid, int mac ) { | |||
if ( mat != null ) { | |||
return mat.isMarkAttachClass ( gid, mac ); | |||
public boolean isMarkAttachClass (int gid, int mac) { | |||
if (mat != null) { | |||
return mat.isMarkAttachClass (gid, mac); | |||
} else { | |||
return false; | |||
} | |||
@@ -170,9 +170,9 @@ public class GlyphDefinitionTable extends GlyphTable { | |||
* @param gid a glyph identifier (index) | |||
* @return a non-negative mark attachment class, or -1 if no class defined | |||
*/ | |||
public int getMarkAttachClass ( int gid ) { | |||
if ( mat != null ) { | |||
return mat.getMarkAttachClass ( gid ); | |||
public int getMarkAttachClass (int gid) { | |||
if (mat != null) { | |||
return mat.getMarkAttachClass (gid); | |||
} else { | |||
return -1; | |||
} | |||
@@ -183,16 +183,16 @@ public class GlyphDefinitionTable extends GlyphTable { | |||
* @param name lookup type name | |||
* @return lookup type | |||
*/ | |||
public static int getLookupTypeFromName ( String name ) { | |||
public static int getLookupTypeFromName (String name) { | |||
int t; | |||
String s = name.toLowerCase(); | |||
if ( "glyphclass".equals ( s ) ) { | |||
if ("glyphclass".equals (s)) { | |||
t = GDEF_LOOKUP_TYPE_GLYPH_CLASS; | |||
} else if ( "attachmentpoint".equals ( s ) ) { | |||
} else if ("attachmentpoint".equals (s)) { | |||
t = GDEF_LOOKUP_TYPE_ATTACHMENT_POINT; | |||
} else if ( "ligaturecaret".equals ( s ) ) { | |||
} else if ("ligaturecaret".equals (s)) { | |||
t = GDEF_LOOKUP_TYPE_LIGATURE_CARET; | |||
} else if ( "markattachment".equals ( s ) ) { | |||
} else if ("markattachment".equals (s)) { | |||
t = GDEF_LOOKUP_TYPE_MARK_ATTACHMENT; | |||
} else { | |||
t = -1; | |||
@@ -205,9 +205,9 @@ public class GlyphDefinitionTable extends GlyphTable { | |||
* @param type lookup type | |||
* @return lookup type name | |||
*/ | |||
public static String getLookupTypeName ( int type ) { | |||
public static String getLookupTypeName (int type) { | |||
String tn = null; | |||
switch ( type ) { | |||
switch (type) { | |||
case GDEF_LOOKUP_TYPE_GLYPH_CLASS: | |||
tn = "glyphclass"; | |||
break; | |||
@@ -238,20 +238,20 @@ public class GlyphDefinitionTable extends GlyphTable { | |||
* @param entries subtable entries | |||
* @return a glyph subtable instance | |||
*/ | |||
public static GlyphSubtable createSubtable ( int type, String id, int sequence, int flags, int format, GlyphMappingTable mapping, List entries ) { | |||
public static GlyphSubtable createSubtable (int type, String id, int sequence, int flags, int format, GlyphMappingTable mapping, List entries) { | |||
GlyphSubtable st = null; | |||
switch ( type ) { | |||
switch (type) { | |||
case GDEF_LOOKUP_TYPE_GLYPH_CLASS: | |||
st = GlyphClassSubtable.create ( id, sequence, flags, format, mapping, entries ); | |||
st = GlyphClassSubtable.create (id, sequence, flags, format, mapping, entries); | |||
break; | |||
case GDEF_LOOKUP_TYPE_ATTACHMENT_POINT: | |||
st = AttachmentPointSubtable.create ( id, sequence, flags, format, mapping, entries ); | |||
st = AttachmentPointSubtable.create (id, sequence, flags, format, mapping, entries); | |||
break; | |||
case GDEF_LOOKUP_TYPE_LIGATURE_CARET: | |||
st = LigatureCaretSubtable.create ( id, sequence, flags, format, mapping, entries ); | |||
st = LigatureCaretSubtable.create (id, sequence, flags, format, mapping, entries); | |||
break; | |||
case GDEF_LOOKUP_TYPE_MARK_ATTACHMENT: | |||
st = MarkAttachmentSubtable.create ( id, sequence, flags, format, mapping, entries ); | |||
st = MarkAttachmentSubtable.create (id, sequence, flags, format, mapping, entries); | |||
break; | |||
default: | |||
break; | |||
@@ -260,8 +260,8 @@ public class GlyphDefinitionTable extends GlyphTable { | |||
} | |||
private abstract static class GlyphClassSubtable extends GlyphDefinitionSubtable { | |||
GlyphClassSubtable ( String id, int sequence, int flags, int format, GlyphMappingTable mapping, List entries ) { | |||
super ( id, sequence, flags, format, mapping ); | |||
GlyphClassSubtable (String id, int sequence, int flags, int format, GlyphMappingTable mapping, List entries) { | |||
super (id, sequence, flags, format, mapping); | |||
} | |||
/** {@inheritDoc} */ | |||
public int getType() { | |||
@@ -273,16 +273,16 @@ public class GlyphDefinitionTable extends GlyphTable { | |||
* @param gc a pre-defined glyph class (GLYPH_CLASS_BASE|GLYPH_CLASS_LIGATURE|GLYPH_CLASS_MARK|GLYPH_CLASS_COMPONENT). | |||
* @return true if glyph belongs to specified glyph class | |||
*/ | |||
public abstract boolean isGlyphClass ( int gid, int gc ); | |||
public abstract boolean isGlyphClass (int gid, int gc); | |||
/** | |||
* Determine glyph class. | |||
* @param gid a glyph identifier (index) | |||
* @return a pre-defined glyph class (GLYPH_CLASS_BASE|GLYPH_CLASS_LIGATURE|GLYPH_CLASS_MARK|GLYPH_CLASS_COMPONENT). | |||
*/ | |||
public abstract int getGlyphClass ( int gid ); | |||
static GlyphDefinitionSubtable create ( String id, int sequence, int flags, int format, GlyphMappingTable mapping, List entries ) { | |||
if ( format == 1 ) { | |||
return new GlyphClassSubtableFormat1 ( id, sequence, flags, format, mapping, entries ); | |||
public abstract int getGlyphClass (int gid); | |||
static GlyphDefinitionSubtable create (String id, int sequence, int flags, int format, GlyphMappingTable mapping, List entries) { | |||
if (format == 1) { | |||
return new GlyphClassSubtableFormat1 (id, sequence, flags, format, mapping, entries); | |||
} else { | |||
throw new UnsupportedOperationException(); | |||
} | |||
@@ -290,31 +290,31 @@ public class GlyphDefinitionTable extends GlyphTable { | |||
} | |||
private static class GlyphClassSubtableFormat1 extends GlyphClassSubtable { | |||
GlyphClassSubtableFormat1 ( String id, int sequence, int flags, int format, GlyphMappingTable mapping, List entries ) { | |||
super ( id, sequence, flags, format, mapping, entries ); | |||
GlyphClassSubtableFormat1 (String id, int sequence, int flags, int format, GlyphMappingTable mapping, List entries) { | |||
super (id, sequence, flags, format, mapping, entries); | |||
} | |||
/** {@inheritDoc} */ | |||
public List getEntries() { | |||
return null; | |||
} | |||
/** {@inheritDoc} */ | |||
public boolean isCompatible ( GlyphSubtable subtable ) { | |||
public boolean isCompatible (GlyphSubtable subtable) { | |||
return subtable instanceof GlyphClassSubtable; | |||
} | |||
/** {@inheritDoc} */ | |||
public boolean isGlyphClass ( int gid, int gc ) { | |||
public boolean isGlyphClass (int gid, int gc) { | |||
GlyphClassMapping cm = getClasses(); | |||
if ( cm != null ) { | |||
return cm.getClassIndex ( gid, 0 ) == gc; | |||
if (cm != null) { | |||
return cm.getClassIndex (gid, 0) == gc; | |||
} else { | |||
return false; | |||
} | |||
} | |||
/** {@inheritDoc} */ | |||
public int getGlyphClass ( int gid ) { | |||
public int getGlyphClass (int gid) { | |||
GlyphClassMapping cm = getClasses(); | |||
if ( cm != null ) { | |||
return cm.getClassIndex ( gid, 0 ); | |||
if (cm != null) { | |||
return cm.getClassIndex (gid, 0); | |||
} else { | |||
return -1; | |||
} | |||
@@ -322,16 +322,16 @@ public class GlyphDefinitionTable extends GlyphTable { | |||
} | |||
private abstract static class AttachmentPointSubtable extends GlyphDefinitionSubtable { | |||
AttachmentPointSubtable ( String id, int sequence, int flags, int format, GlyphMappingTable mapping, List entries ) { | |||
super ( id, sequence, flags, format, mapping ); | |||
AttachmentPointSubtable (String id, int sequence, int flags, int format, GlyphMappingTable mapping, List entries) { | |||
super (id, sequence, flags, format, mapping); | |||
} | |||
/** {@inheritDoc} */ | |||
public int getType() { | |||
return GDEF_LOOKUP_TYPE_ATTACHMENT_POINT; | |||
} | |||
static GlyphDefinitionSubtable create ( String id, int sequence, int flags, int format, GlyphMappingTable mapping, List entries ) { | |||
if ( format == 1 ) { | |||
return new AttachmentPointSubtableFormat1 ( id, sequence, flags, format, mapping, entries ); | |||
static GlyphDefinitionSubtable create (String id, int sequence, int flags, int format, GlyphMappingTable mapping, List entries) { | |||
if (format == 1) { | |||
return new AttachmentPointSubtableFormat1 (id, sequence, flags, format, mapping, entries); | |||
} else { | |||
throw new UnsupportedOperationException(); | |||
} | |||
@@ -339,30 +339,30 @@ public class GlyphDefinitionTable extends GlyphTable { | |||
} | |||
private static class AttachmentPointSubtableFormat1 extends AttachmentPointSubtable { | |||
AttachmentPointSubtableFormat1 ( String id, int sequence, int flags, int format, GlyphMappingTable mapping, List entries ) { | |||
super ( id, sequence, flags, format, mapping, entries ); | |||
AttachmentPointSubtableFormat1 (String id, int sequence, int flags, int format, GlyphMappingTable mapping, List entries) { | |||
super (id, sequence, flags, format, mapping, entries); | |||
} | |||
/** {@inheritDoc} */ | |||
public List getEntries() { | |||
return null; | |||
} | |||
/** {@inheritDoc} */ | |||
public boolean isCompatible ( GlyphSubtable subtable ) { | |||
public boolean isCompatible (GlyphSubtable subtable) { | |||
return subtable instanceof AttachmentPointSubtable; | |||
} | |||
} | |||
private abstract static class LigatureCaretSubtable extends GlyphDefinitionSubtable { | |||
LigatureCaretSubtable ( String id, int sequence, int flags, int format, GlyphMappingTable mapping, List entries ) { | |||
super ( id, sequence, flags, format, mapping ); | |||
LigatureCaretSubtable (String id, int sequence, int flags, int format, GlyphMappingTable mapping, List entries) { | |||
super (id, sequence, flags, format, mapping); | |||
} | |||
/** {@inheritDoc} */ | |||
public int getType() { | |||
return GDEF_LOOKUP_TYPE_LIGATURE_CARET; | |||
} | |||
static GlyphDefinitionSubtable create ( String id, int sequence, int flags, int format, GlyphMappingTable mapping, List entries ) { | |||
if ( format == 1 ) { | |||
return new LigatureCaretSubtableFormat1 ( id, sequence, flags, format, mapping, entries ); | |||
static GlyphDefinitionSubtable create (String id, int sequence, int flags, int format, GlyphMappingTable mapping, List entries) { | |||
if (format == 1) { | |||
return new LigatureCaretSubtableFormat1 (id, sequence, flags, format, mapping, entries); | |||
} else { | |||
throw new UnsupportedOperationException(); | |||
} | |||
@@ -370,22 +370,22 @@ public class GlyphDefinitionTable extends GlyphTable { | |||
} | |||
private static class LigatureCaretSubtableFormat1 extends LigatureCaretSubtable { | |||
LigatureCaretSubtableFormat1 ( String id, int sequence, int flags, int format, GlyphMappingTable mapping, List entries ) { | |||
super ( id, sequence, flags, format, mapping, entries ); | |||
LigatureCaretSubtableFormat1 (String id, int sequence, int flags, int format, GlyphMappingTable mapping, List entries) { | |||
super (id, sequence, flags, format, mapping, entries); | |||
} | |||
/** {@inheritDoc} */ | |||
public List getEntries() { | |||
return null; | |||
} | |||
/** {@inheritDoc} */ | |||
public boolean isCompatible ( GlyphSubtable subtable ) { | |||
public boolean isCompatible (GlyphSubtable subtable) { | |||
return subtable instanceof LigatureCaretSubtable; | |||
} | |||
} | |||
private abstract static class MarkAttachmentSubtable extends GlyphDefinitionSubtable { | |||
MarkAttachmentSubtable ( String id, int sequence, int flags, int format, GlyphMappingTable mapping, List entries ) { | |||
super ( id, sequence, flags, format, mapping ); | |||
MarkAttachmentSubtable (String id, int sequence, int flags, int format, GlyphMappingTable mapping, List entries) { | |||
super (id, sequence, flags, format, mapping); | |||
} | |||
/** {@inheritDoc} */ | |||
public int getType() { | |||
@@ -397,16 +397,16 @@ public class GlyphDefinitionTable extends GlyphTable { | |||
* @param mac a (font specific) mark attachment class | |||
* @return true if glyph belongs to specified mark attachment class | |||
*/ | |||
public abstract boolean isMarkAttachClass ( int gid, int mac ); | |||
public abstract boolean isMarkAttachClass (int gid, int mac); | |||
/** | |||
* Determine mark attachment class. | |||
* @param gid a glyph identifier (index) | |||
* @return a non-negative mark attachment class, or -1 if no class defined | |||
*/ | |||
public abstract int getMarkAttachClass ( int gid ); | |||
static GlyphDefinitionSubtable create ( String id, int sequence, int flags, int format, GlyphMappingTable mapping, List entries ) { | |||
if ( format == 1 ) { | |||
return new MarkAttachmentSubtableFormat1 ( id, sequence, flags, format, mapping, entries ); | |||
public abstract int getMarkAttachClass (int gid); | |||
static GlyphDefinitionSubtable create (String id, int sequence, int flags, int format, GlyphMappingTable mapping, List entries) { | |||
if (format == 1) { | |||
return new MarkAttachmentSubtableFormat1 (id, sequence, flags, format, mapping, entries); | |||
} else { | |||
throw new UnsupportedOperationException(); | |||
} | |||
@@ -414,31 +414,31 @@ public class GlyphDefinitionTable extends GlyphTable { | |||
} | |||
private static class MarkAttachmentSubtableFormat1 extends MarkAttachmentSubtable { | |||
MarkAttachmentSubtableFormat1 ( String id, int sequence, int flags, int format, GlyphMappingTable mapping, List entries ) { | |||
super ( id, sequence, flags, format, mapping, entries ); | |||
MarkAttachmentSubtableFormat1 (String id, int sequence, int flags, int format, GlyphMappingTable mapping, List entries) { | |||
super (id, sequence, flags, format, mapping, entries); | |||
} | |||
/** {@inheritDoc} */ | |||
public List getEntries() { | |||
return null; | |||
} | |||
/** {@inheritDoc} */ | |||
public boolean isCompatible ( GlyphSubtable subtable ) { | |||
public boolean isCompatible (GlyphSubtable subtable) { | |||
return subtable instanceof MarkAttachmentSubtable; | |||
} | |||
/** {@inheritDoc} */ | |||
public boolean isMarkAttachClass ( int gid, int mac ) { | |||
public boolean isMarkAttachClass (int gid, int mac) { | |||
GlyphClassMapping cm = getClasses(); | |||
if ( cm != null ) { | |||
return cm.getClassIndex ( gid, 0 ) == mac; | |||
if (cm != null) { | |||
return cm.getClassIndex (gid, 0) == mac; | |||
} else { | |||
return false; | |||
} | |||
} | |||
/** {@inheritDoc} */ | |||
public int getMarkAttachClass ( int gid ) { | |||
public int getMarkAttachClass (int gid) { | |||
GlyphClassMapping cm = getClasses(); | |||
if ( cm != null ) { | |||
return cm.getClassIndex ( gid, 0 ); | |||
if (cm != null) { | |||
return cm.getClassIndex (gid, 0); | |||
} else { | |||
return -1; | |||
} |
@@ -76,7 +76,7 @@ public class GlyphMappingTable { | |||
* @param gid glyph identifier (code) | |||
* @return non-negative glyph mapping index or -1 if glyph identifiers is not mapped by table | |||
*/ | |||
public int getMappedIndex ( int gid ) { | |||
public int getMappedIndex (int gid) { | |||
return -1; | |||
} | |||
@@ -86,13 +86,13 @@ public class GlyphMappingTable { | |||
* Construct empty mapping table. | |||
*/ | |||
public EmptyMappingTable() { | |||
this ( (List) null ); | |||
this ((List) null); | |||
} | |||
/** | |||
* Construct empty mapping table with entries (ignored). | |||
* @param entries list of entries (ignored) | |||
*/ | |||
public EmptyMappingTable ( List entries ) { | |||
public EmptyMappingTable (List entries) { | |||
} | |||
/** {@inheritDoc} */ | |||
public int getType() { | |||
@@ -107,7 +107,7 @@ public class GlyphMappingTable { | |||
return 0; | |||
} | |||
/** {@inheritDoc} */ | |||
public int getMappedIndex ( int gid ) { | |||
public int getMappedIndex (int gid) { | |||
return -1; | |||
} | |||
} | |||
@@ -135,8 +135,8 @@ public class GlyphMappingTable { | |||
* Construct range mapping table. | |||
* @param entries of mapping ranges | |||
*/ | |||
public RangeMappingTable ( List entries ) { | |||
populate ( entries ); | |||
public RangeMappingTable (List entries) { | |||
populate (entries); | |||
} | |||
/** {@inheritDoc} */ | |||
public int getType() { | |||
@@ -145,9 +145,9 @@ public class GlyphMappingTable { | |||
/** {@inheritDoc} */ | |||
public List getEntries() { | |||
List entries = new java.util.ArrayList(); | |||
if ( sa != null ) { | |||
for ( int i = 0, n = sa.length; i < n; i++ ) { | |||
entries.add ( new MappingRange ( sa [ i ], ea [ i ], ma [ i ] ) ); | |||
if (sa != null) { | |||
for (int i = 0, n = sa.length; i < n; i++) { | |||
entries.add (new MappingRange (sa [ i ], ea [ i ], ma [ i ])); | |||
} | |||
} | |||
return entries; | |||
@@ -157,17 +157,17 @@ public class GlyphMappingTable { | |||
return miMax + 1; | |||
} | |||
/** {@inheritDoc} */ | |||
public int getMappedIndex ( int gid ) { | |||
public int getMappedIndex (int gid) { | |||
int i; | |||
int mi; | |||
if ( ( i = Arrays.binarySearch ( sa, gid ) ) >= 0 ) { | |||
mi = getMappedIndex ( gid, sa [ i ], ma [ i ] ); // matches start of (some) range | |||
} else if ( ( i = - ( i + 1 ) ) == 0 ) { | |||
if ((i = Arrays.binarySearch (sa, gid)) >= 0) { | |||
mi = getMappedIndex (gid, sa [ i ], ma [ i ]); // matches start of (some) range | |||
} else if ((i = - (i + 1)) == 0) { | |||
mi = -1; // precedes first range | |||
} else if ( gid > ea [ --i ] ) { | |||
} else if (gid > ea [ --i ]) { | |||
mi = -1; // follows preceding (or last) range | |||
} else { | |||
mi = getMappedIndex ( gid, sa [ i ], ma [ i ] ); // intersects (some) range | |||
mi = getMappedIndex (gid, sa [ i ], ma [ i ]); // intersects (some) range | |||
} | |||
return mi; | |||
} | |||
@@ -179,8 +179,8 @@ public class GlyphMappingTable { | |||
* @param m mapping value | |||
* @return non-negative glyph mapping index or -1 if glyph identifiers is not mapped by table | |||
*/ | |||
public abstract int getMappedIndex ( int gid, int s, int m ); | |||
private void populate ( List entries ) { | |||
public abstract int getMappedIndex (int gid, int s, int m); | |||
private void populate (List entries) { | |||
int i = 0; | |||
int n = entries.size(); | |||
int gidMax = -1; | |||
@@ -188,35 +188,35 @@ public class GlyphMappingTable { | |||
int[] sa = new int [ n ]; | |||
int[] ea = new int [ n ]; | |||
int[] ma = new int [ n ]; | |||
for ( Iterator it = entries.iterator(); it.hasNext();) { | |||
for (Iterator it = entries.iterator(); it.hasNext();) { | |||
Object o = it.next(); | |||
if ( o instanceof MappingRange ) { | |||
if (o instanceof MappingRange) { | |||
MappingRange r = (MappingRange) o; | |||
int gs = r.getStart(); | |||
int ge = r.getEnd(); | |||
int mi = r.getIndex(); | |||
if ( ( gs < 0 ) || ( gs > 65535 ) ) { | |||
throw new AdvancedTypographicTableFormatException ( "illegal glyph range: [" + gs + "," + ge + "]: bad start index" ); | |||
} else if ( ( ge < 0 ) || ( ge > 65535 ) ) { | |||
throw new AdvancedTypographicTableFormatException ( "illegal glyph range: [" + gs + "," + ge + "]: bad end index" ); | |||
} else if ( gs > ge ) { | |||
throw new AdvancedTypographicTableFormatException ( "illegal glyph range: [" + gs + "," + ge + "]: start index exceeds end index" ); | |||
} else if ( gs < gidMax ) { | |||
throw new AdvancedTypographicTableFormatException ( "out of order glyph range: [" + gs + "," + ge + "]" ); | |||
} else if ( mi < 0 ) { | |||
throw new AdvancedTypographicTableFormatException ( "illegal mapping index: " + mi ); | |||
if ((gs < 0) || (gs > 65535)) { | |||
throw new AdvancedTypographicTableFormatException ("illegal glyph range: [" + gs + "," + ge + "]: bad start index"); | |||
} else if ((ge < 0) || (ge > 65535)) { | |||
throw new AdvancedTypographicTableFormatException ("illegal glyph range: [" + gs + "," + ge + "]: bad end index"); | |||
} else if (gs > ge) { | |||
throw new AdvancedTypographicTableFormatException ("illegal glyph range: [" + gs + "," + ge + "]: start index exceeds end index"); | |||
} else if (gs < gidMax) { | |||
throw new AdvancedTypographicTableFormatException ("out of order glyph range: [" + gs + "," + ge + "]"); | |||
} else if (mi < 0) { | |||
throw new AdvancedTypographicTableFormatException ("illegal mapping index: " + mi); | |||
} else { | |||
int miLast; | |||
sa [ i ] = gs; | |||
ea [ i ] = gidMax = ge; | |||
ma [ i ] = mi; | |||
if ( ( miLast = mi + ( ge - gs ) ) > miMax ) { | |||
if ((miLast = mi + (ge - gs)) > miMax) { | |||
miMax = miLast; | |||
} | |||
i++; | |||
} | |||
} else { | |||
throw new AdvancedTypographicTableFormatException ( "illegal mapping entry, must be Integer: " + o ); | |||
throw new AdvancedTypographicTableFormatException ("illegal mapping entry, must be Integer: " + o); | |||
} | |||
} | |||
assert i == n; | |||
@@ -232,15 +232,15 @@ public class GlyphMappingTable { | |||
public String toString() { | |||
StringBuffer sb = new StringBuffer(); | |||
sb.append('{'); | |||
for ( int i = 0, n = sa.length; i < n; i++ ) { | |||
if ( i > 0 ) { | |||
for (int i = 0, n = sa.length; i < n; i++) { | |||
if (i > 0) { | |||
sb.append(','); | |||
} | |||
sb.append ( '[' ); | |||
sb.append ( Integer.toString ( sa [ i ] ) ); | |||
sb.append ( Integer.toString ( ea [ i ] ) ); | |||
sb.append ( "]:" ); | |||
sb.append ( Integer.toString ( ma [ i ] ) ); | |||
sb.append ('['); | |||
sb.append (Integer.toString (sa [ i ])); | |||
sb.append (Integer.toString (ea [ i ])); | |||
sb.append ("]:"); | |||
sb.append (Integer.toString (ma [ i ])); | |||
} | |||
sb.append('}'); | |||
return sb.toString(); | |||
@@ -261,7 +261,7 @@ public class GlyphMappingTable { | |||
* Instantiate a mapping range. | |||
*/ | |||
public MappingRange() { | |||
this ( 0, 0, 0 ); | |||
this (0, 0, 0); | |||
} | |||
/** | |||
@@ -270,10 +270,10 @@ public class GlyphMappingTable { | |||
* @param gidEnd end of range | |||
* @param index mapping index | |||
*/ | |||
public MappingRange ( int gidStart, int gidEnd, int index ) { | |||
if ( ( gidStart < 0 ) || ( gidEnd < 0 ) || ( index < 0 ) ) { | |||
public MappingRange (int gidStart, int gidEnd, int index) { | |||
if ((gidStart < 0) || (gidEnd < 0) || (index < 0)) { | |||
throw new AdvancedTypographicTableFormatException(); | |||
} else if ( gidStart > gidEnd ) { | |||
} else if (gidStart > gidEnd) { | |||
throw new AdvancedTypographicTableFormatException(); | |||
} else { | |||
this.gidStart = gidStart; | |||
@@ -307,8 +307,8 @@ public class GlyphMappingTable { | |||
* @param interval an array of length two or greater or null | |||
* @return interval as a pair of integers, filled into specified array | |||
*/ | |||
public int[] getInterval ( int[] interval ) { | |||
if ( ( interval == null ) || ( interval.length != 2 ) ) { | |||
public int[] getInterval (int[] interval) { | |||
if ((interval == null) || (interval.length != 2)) { | |||
throw new IllegalArgumentException(); | |||
} else { | |||
interval[0] = gidStart; |
@@ -39,6 +39,6 @@ public interface GlyphPositioning { | |||
* adjustment occurred; it only means that no further glyph subtables for the current lookup table | |||
* should be applied. | |||
*/ | |||
boolean position ( GlyphPositioningState ps ); | |||
boolean position (GlyphPositioningState ps); | |||
} |
@@ -60,8 +60,8 @@ public class GlyphPositioningState extends GlyphProcessingState { | |||
* @param adjustments positioning adjustments to which positioning is applied | |||
* @param sct script context tester (or null) | |||
*/ | |||
public GlyphPositioningState ( GlyphSequence gs, String script, String language, String feature, int fontSize, int[] widths, int[][] adjustments, ScriptContextTester sct ) { | |||
super ( gs, script, language, feature, sct ); | |||
public GlyphPositioningState (GlyphSequence gs, String script, String language, String feature, int fontSize, int[] widths, int[][] adjustments, ScriptContextTester sct) { | |||
super (gs, script, language, feature, sct); | |||
this.fontSize = fontSize; | |||
this.widths = widths; | |||
this.adjustments = adjustments; | |||
@@ -72,8 +72,8 @@ public class GlyphPositioningState extends GlyphProcessingState { | |||
* except as follows: input glyph sequence is copied deep except for its characters array. | |||
* @param ps existing positioning state to copy from | |||
*/ | |||
public GlyphPositioningState ( GlyphPositioningState ps ) { | |||
super ( ps ); | |||
public GlyphPositioningState (GlyphPositioningState ps) { | |||
super (ps); | |||
this.fontSize = ps.fontSize; | |||
this.widths = ps.widths; | |||
this.adjustments = ps.adjustments; | |||
@@ -90,8 +90,8 @@ public class GlyphPositioningState extends GlyphProcessingState { | |||
* @param adjustments positioning adjustments to which positioning is applied | |||
* @param sct script context tester (or null) | |||
*/ | |||
public GlyphPositioningState reset ( GlyphSequence gs, String script, String language, String feature, int fontSize, int[] widths, int[][] adjustments, ScriptContextTester sct ) { | |||
super.reset ( gs, script, language, feature, sct ); | |||
public GlyphPositioningState reset (GlyphSequence gs, String script, String language, String feature, int fontSize, int[] widths, int[][] adjustments, ScriptContextTester sct) { | |||
super.reset (gs, script, language, feature, sct); | |||
this.fontSize = fontSize; | |||
this.widths = widths; | |||
this.adjustments = adjustments; | |||
@@ -104,8 +104,8 @@ public class GlyphPositioningState extends GlyphProcessingState { | |||
* @param gi glyph index | |||
* @return design advancement, or zero if glyph index is not present | |||
*/ | |||
public int getWidth ( int gi ) { | |||
if ( ( widths != null ) && ( gi < widths.length ) ) { | |||
public int getWidth (int gi) { | |||
if ((widths != null) && (gi < widths.length)) { | |||
return widths [ gi ]; | |||
} else { | |||
return 0; | |||
@@ -117,8 +117,8 @@ public class GlyphPositioningState extends GlyphProcessingState { | |||
* @param v value containing adjustments | |||
* @return true if a non-zero adjustment was made | |||
*/ | |||
public boolean adjust ( GlyphPositioningTable.Value v ) { | |||
return adjust ( v, 0 ); | |||
public boolean adjust (GlyphPositioningTable.Value v) { | |||
return adjust (v, 0); | |||
} | |||
/** | |||
@@ -127,10 +127,10 @@ public class GlyphPositioningState extends GlyphProcessingState { | |||
* @param offset from current position index | |||
* @return true if a non-zero adjustment was made | |||
*/ | |||
public boolean adjust ( GlyphPositioningTable.Value v, int offset ) { | |||
public boolean adjust (GlyphPositioningTable.Value v, int offset) { | |||
assert v != null; | |||
if ( ( index + offset ) < indexLast ) { | |||
return v.adjust ( adjustments [ index + offset ], fontSize ); | |||
if ((index + offset) < indexLast) { | |||
return v.adjust (adjustments [ index + offset ], fontSize); | |||
} else { | |||
throw new IndexOutOfBoundsException(); | |||
} | |||
@@ -141,7 +141,7 @@ public class GlyphPositioningState extends GlyphProcessingState { | |||
* @return array of adjustments (int[4]) at current position | |||
*/ | |||
public int[] getAdjustment() { | |||
return getAdjustment ( 0 ); | |||
return getAdjustment (0); | |||
} | |||
/** | |||
@@ -150,8 +150,8 @@ public class GlyphPositioningState extends GlyphProcessingState { | |||
* @return array of adjustments (int[4]) at specified offset | |||
* @throws IndexOutOfBoundsException if offset is invalid | |||
*/ | |||
public int[] getAdjustment ( int offset ) throws IndexOutOfBoundsException { | |||
if ( ( index + offset ) < indexLast ) { | |||
public int[] getAdjustment (int offset) throws IndexOutOfBoundsException { | |||
if ((index + offset) < indexLast) { | |||
return adjustments [ index + offset ]; | |||
} else { | |||
throw new IndexOutOfBoundsException(); | |||
@@ -165,10 +165,10 @@ public class GlyphPositioningState extends GlyphProcessingState { | |||
* @return true if subtable applied, or false if it did not (e.g., its | |||
* input coverage table did not match current input context) | |||
*/ | |||
public boolean apply ( GlyphPositioningSubtable st ) { | |||
public boolean apply (GlyphPositioningSubtable st) { | |||
assert st != null; | |||
updateSubtableState ( st ); | |||
boolean applied = st.position ( this ); | |||
updateSubtableState (st); | |||
boolean applied = st.position (this); | |||
return applied; | |||
} | |||
@@ -182,24 +182,24 @@ public class GlyphPositioningState extends GlyphProcessingState { | |||
* the lookups are to apply, and to be consumed once the application has finished | |||
* @return true if lookups are non-null and non-empty; otherwise, false | |||
*/ | |||
public boolean apply ( GlyphTable.RuleLookup[] lookups, int nig ) { | |||
if ( ( lookups != null ) && ( lookups.length > 0 ) ) { | |||
public boolean apply (GlyphTable.RuleLookup[] lookups, int nig) { | |||
if ((lookups != null) && (lookups.length > 0)) { | |||
// apply each rule lookup to extracted input glyph array | |||
for ( int i = 0, n = lookups.length; i < n; i++ ) { | |||
for (int i = 0, n = lookups.length; i < n; i++) { | |||
GlyphTable.RuleLookup l = lookups [ i ]; | |||
if ( l != null ) { | |||
if (l != null) { | |||
GlyphTable.LookupTable lt = l.getLookup(); | |||
if ( lt != null ) { | |||
if (lt != null) { | |||
// perform positioning on a copy of previous state | |||
GlyphPositioningState ps = new GlyphPositioningState ( this ); | |||
GlyphPositioningState ps = new GlyphPositioningState (this); | |||
// apply lookup table positioning | |||
if ( lt.position ( ps, l.getSequenceIndex() ) ) { | |||
setAdjusted ( true ); | |||
if (lt.position (ps, l.getSequenceIndex())) { | |||
setAdjusted (true); | |||
} | |||
} | |||
} | |||
} | |||
consume ( nig ); | |||
consume (nig); | |||
return true; | |||
} else { | |||
return false; | |||
@@ -218,7 +218,7 @@ public class GlyphPositioningState extends GlyphProcessingState { | |||
* @param adjusted true if to set adjusted state, otherwise false to | |||
* clear adjusted state | |||
*/ | |||
public void setAdjusted ( boolean adjusted ) { | |||
public void setAdjusted (boolean adjusted) { | |||
this.adjusted = adjusted; | |||
} | |||
@@ -44,8 +44,8 @@ public abstract class GlyphPositioningSubtable extends GlyphSubtable implements | |||
* @param format subtable format | |||
* @param coverage subtable coverage table | |||
*/ | |||
protected GlyphPositioningSubtable ( String id, int sequence, int flags, int format, GlyphCoverageTable coverage ) { | |||
super ( id, sequence, flags, format, coverage ); | |||
protected GlyphPositioningSubtable (String id, int sequence, int flags, int format, GlyphCoverageTable coverage) { | |||
super (id, sequence, flags, format, coverage); | |||
} | |||
/** {@inheritDoc} */ | |||
@@ -55,11 +55,11 @@ public abstract class GlyphPositioningSubtable extends GlyphSubtable implements | |||
/** {@inheritDoc} */ | |||
public String getTypeName() { | |||
return GlyphPositioningTable.getLookupTypeName ( getType() ); | |||
return GlyphPositioningTable.getLookupTypeName (getType()); | |||
} | |||
/** {@inheritDoc} */ | |||
public boolean isCompatible ( GlyphSubtable subtable ) { | |||
public boolean isCompatible (GlyphSubtable subtable) { | |||
return subtable instanceof GlyphPositioningSubtable; | |||
} | |||
@@ -69,7 +69,7 @@ public abstract class GlyphPositioningSubtable extends GlyphSubtable implements | |||
} | |||
/** {@inheritDoc} */ | |||
public boolean position ( GlyphPositioningState ps ) { | |||
public boolean position (GlyphPositioningState ps) { | |||
return false; | |||
} | |||
@@ -85,24 +85,24 @@ public abstract class GlyphPositioningSubtable extends GlyphSubtable implements | |||
* @param sequenceIndex if non negative, then apply subtables only at specified sequence index | |||
* @return true if a non-zero adjustment occurred | |||
*/ | |||
public static final boolean position ( GlyphPositioningState ps, GlyphPositioningSubtable[] sta, int sequenceIndex ) { | |||
public static final boolean position (GlyphPositioningState ps, GlyphPositioningSubtable[] sta, int sequenceIndex) { | |||
int sequenceStart = ps.getPosition(); | |||
boolean appliedOneShot = false; | |||
while ( ps.hasNext() ) { | |||
while (ps.hasNext()) { | |||
boolean applied = false; | |||
if ( ! appliedOneShot && ps.maybeApplicable() ) { | |||
for ( int i = 0, n = sta.length; ! applied && ( i < n ); i++ ) { | |||
if ( sequenceIndex < 0 ) { | |||
applied = ps.apply ( sta [ i ] ); | |||
} else if ( ps.getPosition() == ( sequenceStart + sequenceIndex ) ) { | |||
applied = ps.apply ( sta [ i ] ); | |||
if ( applied ) { | |||
if (! appliedOneShot && ps.maybeApplicable()) { | |||
for (int i = 0, n = sta.length; ! applied && (i < n); i++) { | |||
if (sequenceIndex < 0) { | |||
applied = ps.apply (sta [ i ]); | |||
} else if (ps.getPosition() == (sequenceStart + sequenceIndex)) { | |||
applied = ps.apply (sta [ i ]); | |||
if (applied) { | |||
appliedOneShot = true; | |||
} | |||
} | |||
} | |||
} | |||
if ( ! applied || ! ps.didConsume() ) { | |||
if (! applied || ! ps.didConsume()) { | |||
ps.applyDefault(); | |||
} | |||
ps.next(); | |||
@@ -123,9 +123,9 @@ public abstract class GlyphPositioningSubtable extends GlyphSubtable implements | |||
* @param sct script context tester | |||
* @return true if a non-zero adjustment occurred | |||
*/ | |||
public static final boolean position ( GlyphSequence gs, String script, String language, String feature, int fontSize, GlyphPositioningSubtable[] sta, int[] widths, int[][] adjustments, ScriptContextTester sct ) { | |||
synchronized ( state ) { | |||
return position ( state.reset ( gs, script, language, feature, fontSize, widths, adjustments, sct ), sta, -1 ); | |||
public static final boolean position (GlyphSequence gs, String script, String language, String feature, int fontSize, GlyphPositioningSubtable[] sta, int[] widths, int[][] adjustments, ScriptContextTester sct) { | |||
synchronized (state) { | |||
return position (state.reset (gs, script, language, feature, fontSize, widths, adjustments, sct), sta, -1); | |||
} | |||
} | |||
@@ -37,6 +37,6 @@ public interface GlyphSubstitution { | |||
* @return true if the glyph subtable was applied, meaning that the current context matches the | |||
* associated input context glyph coverage table | |||
*/ | |||
boolean substitute ( GlyphSubstitutionState ss ); | |||
boolean substitute (GlyphSubstitutionState ss); | |||
} |
@@ -61,10 +61,10 @@ public class GlyphSubstitutionState extends GlyphProcessingState { | |||
* @param feature feature identifier | |||
* @param sct script context tester (or null) | |||
*/ | |||
public GlyphSubstitutionState ( GlyphSequence gs, String script, String language, String feature, ScriptContextTester sct ) { | |||
super ( gs, script, language, feature, sct ); | |||
this.ogb = IntBuffer.allocate ( gs.getGlyphCount() ); | |||
this.oal = new ArrayList ( gs.getGlyphCount() ); | |||
public GlyphSubstitutionState (GlyphSequence gs, String script, String language, String feature, ScriptContextTester sct) { | |||
super (gs, script, language, feature, sct); | |||
this.ogb = IntBuffer.allocate (gs.getGlyphCount()); | |||
this.oal = new ArrayList (gs.getGlyphCount()); | |||
this.predications = gs.getPredications(); | |||
} | |||
@@ -73,10 +73,10 @@ public class GlyphSubstitutionState extends GlyphProcessingState { | |||
* except as follows: input glyph sequence is copied deep except for its characters array. | |||
* @param ss existing positioning state to copy from | |||
*/ | |||
public GlyphSubstitutionState ( GlyphSubstitutionState ss ) { | |||
super ( ss ); | |||
this.ogb = IntBuffer.allocate ( indexLast ); | |||
this.oal = new ArrayList ( indexLast ); | |||
public GlyphSubstitutionState (GlyphSubstitutionState ss) { | |||
super (ss); | |||
this.ogb = IntBuffer.allocate (indexLast); | |||
this.oal = new ArrayList (indexLast); | |||
} | |||
/** | |||
@@ -87,11 +87,11 @@ public class GlyphSubstitutionState extends GlyphProcessingState { | |||
* @param feature feature identifier | |||
* @param sct script context tester (or null) | |||
*/ | |||
public GlyphSubstitutionState reset ( GlyphSequence gs, String script, String language, String feature, ScriptContextTester sct ) { | |||
super.reset ( gs, script, language, feature, sct ); | |||
public GlyphSubstitutionState reset (GlyphSequence gs, String script, String language, String feature, ScriptContextTester sct) { | |||
super.reset (gs, script, language, feature, sct); | |||
this.alternatesIndex = null; | |||
this.ogb = IntBuffer.allocate ( gs.getGlyphCount() ); | |||
this.oal = new ArrayList ( gs.getGlyphCount() ); | |||
this.ogb = IntBuffer.allocate (gs.getGlyphCount()); | |||
this.oal = new ArrayList (gs.getGlyphCount()); | |||
this.predications = gs.getPredications(); | |||
return this; | |||
} | |||
@@ -100,7 +100,7 @@ public class GlyphSubstitutionState extends GlyphProcessingState { | |||
* Set alternates indices. | |||
* @param alternates array of alternates indices ordered by coverage index | |||
*/ | |||
public void setAlternates ( int[] alternates ) { | |||
public void setAlternates (int[] alternates) { | |||
this.alternatesIndex = alternates; | |||
} | |||
@@ -113,10 +113,10 @@ public class GlyphSubstitutionState extends GlyphProcessingState { | |||
* @param ci coverage index | |||
* @return an alternates index | |||
*/ | |||
public int getAlternatesIndex ( int ci ) { | |||
if ( alternatesIndex == null ) { | |||
public int getAlternatesIndex (int ci) { | |||
if (alternatesIndex == null) { | |||
return 0; | |||
} else if ( ( ci < 0 ) || ( ci > alternatesIndex.length ) ) { | |||
} else if ((ci < 0) || (ci > alternatesIndex.length)) { | |||
return 0; | |||
} else { | |||
return alternatesIndex [ ci ]; | |||
@@ -129,15 +129,15 @@ public class GlyphSubstitutionState extends GlyphProcessingState { | |||
* @param a character association that applies to glyph | |||
* @param predication a predication value to add to association A if predications enabled | |||
*/ | |||
public void putGlyph ( int glyph, GlyphSequence.CharAssociation a, Object predication ) { | |||
if ( ! ogb.hasRemaining() ) { | |||
ogb = growBuffer ( ogb ); | |||
public void putGlyph (int glyph, GlyphSequence.CharAssociation a, Object predication) { | |||
if (! ogb.hasRemaining()) { | |||
ogb = growBuffer (ogb); | |||
} | |||
ogb.put ( glyph ); | |||
if ( predications && ( predication != null ) ) { | |||
a.setPredication ( feature, predication ); | |||
ogb.put (glyph); | |||
if (predications && (predication != null)) { | |||
a.setPredication (feature, predication); | |||
} | |||
oal.add ( a ); | |||
oal.add (a); | |||
} | |||
/** | |||
@@ -146,12 +146,12 @@ public class GlyphSubstitutionState extends GlyphProcessingState { | |||
* @param associations array of character associations that apply to glyphs | |||
* @param predication optional predicaion object to be associated with glyphs' associations | |||
*/ | |||
public void putGlyphs ( int[] glyphs, GlyphSequence.CharAssociation[] associations, Object predication ) { | |||
public void putGlyphs (int[] glyphs, GlyphSequence.CharAssociation[] associations, Object predication) { | |||
assert glyphs != null; | |||
assert associations != null; | |||
assert associations.length >= glyphs.length; | |||
for ( int i = 0, n = glyphs.length; i < n; i++ ) { | |||
putGlyph ( glyphs [ i ], associations [ i ], predication ); | |||
for (int i = 0, n = glyphs.length; i < n; i++) { | |||
putGlyph (glyphs [ i ], associations [ i ], predication); | |||
} | |||
} | |||
@@ -162,10 +162,10 @@ public class GlyphSubstitutionState extends GlyphProcessingState { | |||
*/ | |||
public GlyphSequence getOutput() { | |||
int position = ogb.position(); | |||
if ( position > 0 ) { | |||
ogb.limit ( position ); | |||
if (position > 0) { | |||
ogb.limit (position); | |||
ogb.rewind(); | |||
return new GlyphSequence ( igs.getCharacters(), ogb, oal ); | |||
return new GlyphSequence (igs.getCharacters(), ogb, oal); | |||
} else { | |||
return igs; | |||
} | |||
@@ -181,10 +181,10 @@ public class GlyphSubstitutionState extends GlyphProcessingState { | |||
* @return true if subtable applied, or false if it did not (e.g., its | |||
* input coverage table did not match current input context) | |||
*/ | |||
public boolean apply ( GlyphSubstitutionSubtable st ) { | |||
public boolean apply (GlyphSubstitutionSubtable st) { | |||
assert st != null; | |||
updateSubtableState ( st ); | |||
boolean applied = st.substitute ( this ); | |||
updateSubtableState (st); | |||
boolean applied = st.substitute (this); | |||
return applied; | |||
} | |||
@@ -198,32 +198,32 @@ public class GlyphSubstitutionState extends GlyphProcessingState { | |||
* the lookups are to apply, and to be consumed once the application has finished | |||
* @return true if lookups are non-null and non-empty; otherwise, false | |||
*/ | |||
public boolean apply ( GlyphTable.RuleLookup[] lookups, int nig ) { | |||
public boolean apply (GlyphTable.RuleLookup[] lookups, int nig) { | |||
// int nbg = index; | |||
int nlg = indexLast - ( index + nig ); | |||
int nlg = indexLast - (index + nig); | |||
int nog = 0; | |||
if ( ( lookups != null ) && ( lookups.length > 0 ) ) { | |||
if ((lookups != null) && (lookups.length > 0)) { | |||
// apply each rule lookup to extracted input glyph array | |||
for ( int i = 0, n = lookups.length; i < n; i++ ) { | |||
for (int i = 0, n = lookups.length; i < n; i++) { | |||
GlyphTable.RuleLookup l = lookups [ i ]; | |||
if ( l != null ) { | |||
if (l != null) { | |||
GlyphTable.LookupTable lt = l.getLookup(); | |||
if ( lt != null ) { | |||
if (lt != null) { | |||
// perform substitution on a copy of previous state | |||
GlyphSubstitutionState ss = new GlyphSubstitutionState ( this ); | |||
GlyphSubstitutionState ss = new GlyphSubstitutionState (this); | |||
// apply lookup table substitutions | |||
GlyphSequence gs = lt.substitute ( ss, l.getSequenceIndex() ); | |||
GlyphSequence gs = lt.substitute (ss, l.getSequenceIndex()); | |||
// replace current input sequence starting at current position with result | |||
if ( replaceInput ( 0, -1, gs ) ) { | |||
if (replaceInput (0, -1, gs)) { | |||
nog = gs.getGlyphCount() - nlg; | |||
} | |||
} | |||
} | |||
} | |||
// output glyphs and associations | |||
putGlyphs ( getGlyphs ( 0, nog, false, null, null, null ), getAssociations ( 0, nog, false, null, null, null ), null ); | |||
putGlyphs (getGlyphs (0, nog, false, null, null, null), getAssociations (0, nog, false, null, null, null), null); | |||
// consume replaced input glyphs | |||
consume ( nog ); | |||
consume (nog); | |||
return true; | |||
} else { | |||
return false; | |||
@@ -237,17 +237,17 @@ public class GlyphSubstitutionState extends GlyphProcessingState { | |||
public void applyDefault() { | |||
super.applyDefault(); | |||
int gi = getGlyph(); | |||
if ( gi != 65535 ) { | |||
putGlyph ( gi, getAssociation(), null ); | |||
if (gi != 65535) { | |||
putGlyph (gi, getAssociation(), null); | |||
} | |||
} | |||
private static IntBuffer growBuffer ( IntBuffer ib ) { | |||
private static IntBuffer growBuffer (IntBuffer ib) { | |||
int capacity = ib.capacity(); | |||
int capacityNew = capacity * 2; | |||
IntBuffer ibNew = IntBuffer.allocate ( capacityNew ); | |||
IntBuffer ibNew = IntBuffer.allocate (capacityNew); | |||
ib.rewind(); | |||
return ibNew.put ( ib ); | |||
return ibNew.put (ib); | |||
} | |||
} |
@@ -43,8 +43,8 @@ public abstract class GlyphSubstitutionSubtable extends GlyphSubtable implements | |||
* @param format subtable format | |||
* @param coverage subtable coverage table | |||
*/ | |||
protected GlyphSubstitutionSubtable ( String id, int sequence, int flags, int format, GlyphCoverageTable coverage ) { | |||
super ( id, sequence, flags, format, coverage ); | |||
protected GlyphSubstitutionSubtable (String id, int sequence, int flags, int format, GlyphCoverageTable coverage) { | |||
super (id, sequence, flags, format, coverage); | |||
} | |||
/** {@inheritDoc} */ | |||
@@ -54,11 +54,11 @@ public abstract class GlyphSubstitutionSubtable extends GlyphSubtable implements | |||
/** {@inheritDoc} */ | |||
public String getTypeName() { | |||
return GlyphSubstitutionTable.getLookupTypeName ( getType() ); | |||
return GlyphSubstitutionTable.getLookupTypeName (getType()); | |||
} | |||
/** {@inheritDoc} */ | |||
public boolean isCompatible ( GlyphSubtable subtable ) { | |||
public boolean isCompatible (GlyphSubtable subtable) { | |||
return subtable instanceof GlyphSubstitutionSubtable; | |||
} | |||
@@ -68,7 +68,7 @@ public abstract class GlyphSubstitutionSubtable extends GlyphSubtable implements | |||
} | |||
/** {@inheritDoc} */ | |||
public boolean substitute ( GlyphSubstitutionState ss ) { | |||
public boolean substitute (GlyphSubstitutionState ss) { | |||
return false; | |||
} | |||
@@ -85,24 +85,24 @@ public abstract class GlyphSubstitutionSubtable extends GlyphSubtable implements | |||
* @param sequenceIndex if non negative, then apply subtables only at specified sequence index | |||
* @return output glyph sequence | |||
*/ | |||
public static final GlyphSequence substitute ( GlyphSubstitutionState ss, GlyphSubstitutionSubtable[] sta, int sequenceIndex ) { | |||
public static final GlyphSequence substitute (GlyphSubstitutionState ss, GlyphSubstitutionSubtable[] sta, int sequenceIndex) { | |||
int sequenceStart = ss.getPosition(); | |||
boolean appliedOneShot = false; | |||
while ( ss.hasNext() ) { | |||
while (ss.hasNext()) { | |||
boolean applied = false; | |||
if ( ! appliedOneShot && ss.maybeApplicable() ) { | |||
for ( int i = 0, n = sta.length; ! applied && ( i < n ); i++ ) { | |||
if ( sequenceIndex < 0 ) { | |||
applied = ss.apply ( sta [ i ] ); | |||
} else if ( ss.getPosition() == ( sequenceStart + sequenceIndex ) ) { | |||
applied = ss.apply ( sta [ i ] ); | |||
if ( applied ) { | |||
if (! appliedOneShot && ss.maybeApplicable()) { | |||
for (int i = 0, n = sta.length; ! applied && (i < n); i++) { | |||
if (sequenceIndex < 0) { | |||
applied = ss.apply (sta [ i ]); | |||
} else if (ss.getPosition() == (sequenceStart + sequenceIndex)) { | |||
applied = ss.apply (sta [ i ]); | |||
if (applied) { | |||
appliedOneShot = true; | |||
} | |||
} | |||
} | |||
} | |||
if ( ! applied || ! ss.didConsume() ) { | |||
if (! applied || ! ss.didConsume()) { | |||
ss.applyDefault(); | |||
} | |||
ss.next(); | |||
@@ -120,9 +120,9 @@ public abstract class GlyphSubstitutionSubtable extends GlyphSubtable implements | |||
* @param sct script context tester | |||
* @return output glyph sequence | |||
*/ | |||
public static final GlyphSequence substitute ( GlyphSequence gs, String script, String language, String feature, GlyphSubstitutionSubtable[] sta, ScriptContextTester sct ) { | |||
synchronized ( state ) { | |||
return substitute ( state.reset ( gs, script, language, feature, sct ), sta, -1 ); | |||
public static final GlyphSequence substitute (GlyphSequence gs, String script, String language, String feature, GlyphSubstitutionSubtable[] sta, ScriptContextTester sct) { | |||
synchronized (state) { | |||
return substitute (state.reset (gs, script, language, feature, sct), sta, -1); | |||
} | |||
} | |||
@@ -73,12 +73,12 @@ public abstract class GlyphSubtable implements Comparable { | |||
* @param format subtable format | |||
* @param mapping subtable mapping table | |||
*/ | |||
protected GlyphSubtable ( String lookupId, int sequence, int flags, int format, GlyphMappingTable mapping ) | |||
protected GlyphSubtable (String lookupId, int sequence, int flags, int format, GlyphMappingTable mapping) | |||
{ | |||
if ( ( lookupId == null ) || ( lookupId.length() == 0 ) ) { | |||
throw new AdvancedTypographicTableFormatException ( "invalid lookup identifier, must be non-empty string" ); | |||
} else if ( mapping == null ) { | |||
throw new AdvancedTypographicTableFormatException ( "invalid mapping table, must not be null" ); | |||
if ((lookupId == null) || (lookupId.length() == 0)) { | |||
throw new AdvancedTypographicTableFormatException ("invalid lookup identifier, must be non-empty string"); | |||
} else if (mapping == null) { | |||
throw new AdvancedTypographicTableFormatException ("invalid mapping table, must not be null"); | |||
} else { | |||
this.lookupId = lookupId; | |||
this.sequence = sequence; | |||
@@ -109,7 +109,7 @@ public abstract class GlyphSubtable implements Comparable { | |||
* @return true if specified subtable is compatible with this glyph subtable, where by compatible | |||
* is meant that they share the same lookup type | |||
*/ | |||
public abstract boolean isCompatible ( GlyphSubtable subtable ); | |||
public abstract boolean isCompatible (GlyphSubtable subtable); | |||
/** @return true if subtable uses reverse scanning of glyph sequence, meaning from the last glyph | |||
* in a glyph sequence to the first glyph | |||
@@ -134,7 +134,7 @@ public abstract class GlyphSubtable implements Comparable { | |||
/** @return this subtable's governing glyph definition table or null if none available */ | |||
public GlyphDefinitionTable getGDEF() { | |||
GlyphTable gt = getTable(); | |||
if ( gt != null ) { | |||
if (gt != null) { | |||
return gt.getGlyphDefinitions(); | |||
} else { | |||
return null; | |||
@@ -143,7 +143,7 @@ public abstract class GlyphSubtable implements Comparable { | |||
/** @return this subtable's coverage mapping or null if mapping is not a coverage mapping */ | |||
public GlyphCoverageMapping getCoverage() { | |||
if ( mapping instanceof GlyphCoverageMapping ) { | |||
if (mapping instanceof GlyphCoverageMapping) { | |||
return (GlyphCoverageMapping) mapping; | |||
} else { | |||
return null; | |||
@@ -152,7 +152,7 @@ public abstract class GlyphSubtable implements Comparable { | |||
/** @return this subtable's class mapping or null if mapping is not a class mapping */ | |||
public GlyphClassMapping getClasses() { | |||
if ( mapping instanceof GlyphClassMapping ) { | |||
if (mapping instanceof GlyphClassMapping) { | |||
return (GlyphClassMapping) mapping; | |||
} else { | |||
return null; | |||
@@ -165,7 +165,7 @@ public abstract class GlyphSubtable implements Comparable { | |||
/** @return this subtable's parent table (or null if undefined) */ | |||
public synchronized GlyphTable getTable() { | |||
WeakReference r = this.table; | |||
return ( r != null ) ? (GlyphTable) r.get() : null; | |||
return (r != null) ? (GlyphTable) r.get() : null; | |||
} | |||
/** | |||
@@ -175,17 +175,17 @@ public abstract class GlyphSubtable implements Comparable { | |||
* @param table the table or null | |||
* @throws IllegalStateException if table is already set to non-null | |||
*/ | |||
public synchronized void setTable ( GlyphTable table ) throws IllegalStateException { | |||
public synchronized void setTable (GlyphTable table) throws IllegalStateException { | |||
WeakReference r = this.table; | |||
if ( table == null ) { | |||
if (table == null) { | |||
this.table = null; | |||
if ( r != null ) { | |||
if (r != null) { | |||
r.clear(); | |||
} | |||
} else if ( r == null ) { | |||
this.table = new WeakReference ( table ); | |||
} else if (r == null) { | |||
this.table = new WeakReference (table); | |||
} else { | |||
throw new IllegalStateException ( "table already set" ); | |||
throw new IllegalStateException ("table already set"); | |||
} | |||
} | |||
@@ -193,7 +193,7 @@ public abstract class GlyphSubtable implements Comparable { | |||
* Resolve references to lookup tables, e.g., in RuleLookup, to the lookup tables themselves. | |||
* @param lookupTables map from lookup table identifers, e.g. "lu4", to lookup tables | |||
*/ | |||
public void resolveLookupReferences ( Map/*<String,GlyphTable.LookupTable>*/ lookupTables ) { | |||
public void resolveLookupReferences (Map/*<String,GlyphTable.LookupTable>*/ lookupTables) { | |||
} | |||
/** | |||
@@ -201,9 +201,9 @@ public abstract class GlyphSubtable implements Comparable { | |||
* @param gid glyph id | |||
* @return the corresponding coverage index of the specified glyph id | |||
*/ | |||
public int getCoverageIndex ( int gid ) { | |||
if ( mapping instanceof GlyphCoverageMapping ) { | |||
return ( (GlyphCoverageMapping) mapping ) .getCoverageIndex ( gid ); | |||
public int getCoverageIndex (int gid) { | |||
if (mapping instanceof GlyphCoverageMapping) { | |||
return ((GlyphCoverageMapping) mapping) .getCoverageIndex (gid); | |||
} else { | |||
return -1; | |||
} | |||
@@ -214,8 +214,8 @@ public abstract class GlyphSubtable implements Comparable { | |||
* @return the corresponding coverage index of the specified glyph id | |||
*/ | |||
public int getCoverageSize() { | |||
if ( mapping instanceof GlyphCoverageMapping ) { | |||
return ( (GlyphCoverageMapping) mapping ) .getCoverageSize(); | |||
if (mapping instanceof GlyphCoverageMapping) { | |||
return ((GlyphCoverageMapping) mapping) .getCoverageSize(); | |||
} else { | |||
return 0; | |||
} | |||
@@ -224,7 +224,7 @@ public abstract class GlyphSubtable implements Comparable { | |||
/** {@inheritDoc} */ | |||
public int hashCode() { | |||
int hc = sequence; | |||
hc = ( hc * 3 ) + ( lookupId.hashCode() ^ hc ); | |||
hc = (hc * 3) + (lookupId.hashCode() ^ hc); | |||
return hc; | |||
} | |||
@@ -233,10 +233,10 @@ public abstract class GlyphSubtable implements Comparable { | |||
* @return true if the lookup identifier and the sequence number of the specified subtable is the same | |||
* as the lookup identifier and sequence number of this subtable | |||
*/ | |||
public boolean equals ( Object o ) { | |||
if ( o instanceof GlyphSubtable ) { | |||
public boolean equals (Object o) { | |||
if (o instanceof GlyphSubtable) { | |||
GlyphSubtable st = (GlyphSubtable) o; | |||
return lookupId.equals ( st.lookupId ) && ( sequence == st.sequence ); | |||
return lookupId.equals (st.lookupId) && (sequence == st.sequence); | |||
} else { | |||
return false; | |||
} | |||
@@ -247,14 +247,14 @@ public abstract class GlyphSubtable implements Comparable { | |||
* @return the result of comparing the lookup identifier and the sequence number of the specified subtable with | |||
* the lookup identifier and sequence number of this subtable | |||
*/ | |||
public int compareTo ( Object o ) { | |||
public int compareTo (Object o) { | |||
int d; | |||
if ( o instanceof GlyphSubtable ) { | |||
if (o instanceof GlyphSubtable) { | |||
GlyphSubtable st = (GlyphSubtable) o; | |||
if ( ( d = lookupId.compareTo ( st.lookupId ) ) == 0 ) { | |||
if ( sequence < st.sequence ) { | |||
if ((d = lookupId.compareTo (st.lookupId)) == 0) { | |||
if (sequence < st.sequence) { | |||
d = -1; | |||
} else if ( sequence > st.sequence ) { | |||
} else if (sequence > st.sequence) { | |||
d = 1; | |||
} | |||
} | |||
@@ -269,12 +269,12 @@ public abstract class GlyphSubtable implements Comparable { | |||
* @param subtables array of glyph subtables | |||
* @return true if any of the specified subtables uses reverse scanning. | |||
*/ | |||
public static boolean usesReverseScan ( GlyphSubtable[] subtables ) { | |||
if ( ( subtables == null ) || ( subtables.length == 0 ) ) { | |||
public static boolean usesReverseScan (GlyphSubtable[] subtables) { | |||
if ((subtables == null) || (subtables.length == 0)) { | |||
return false; | |||
} else { | |||
for ( int i = 0, n = subtables.length; i < n; i++ ) { | |||
if ( subtables[i].usesReverseScan() ) { | |||
for (int i = 0, n = subtables.length; i < n; i++) { | |||
if (subtables[i].usesReverseScan()) { | |||
return true; | |||
} | |||
} | |||
@@ -288,27 +288,27 @@ public abstract class GlyphSubtable implements Comparable { | |||
* @return consistent flags | |||
* @throws IllegalStateException if inconsistent flags | |||
*/ | |||
public static int getFlags ( GlyphSubtable[] subtables ) throws IllegalStateException { | |||
if ( ( subtables == null ) || ( subtables.length == 0 ) ) { | |||
public static int getFlags (GlyphSubtable[] subtables) throws IllegalStateException { | |||
if ((subtables == null) || (subtables.length == 0)) { | |||
return 0; | |||
} else { | |||
int flags = 0; | |||
// obtain first non-zero value of flags in array of subtables | |||
for ( int i = 0, n = subtables.length; i < n; i++ ) { | |||
for (int i = 0, n = subtables.length; i < n; i++) { | |||
int f = subtables[i].getFlags(); | |||
if ( flags == 0 ) { | |||
if (flags == 0) { | |||
flags = f; | |||
break; | |||
} | |||
} | |||
// enforce flag consistency | |||
for ( int i = 0, n = subtables.length; i < n; i++ ) { | |||
for (int i = 0, n = subtables.length; i < n; i++) { | |||
int f = subtables[i].getFlags(); | |||
if ( f != flags ) { | |||
throw new IllegalStateException ( "inconsistent lookup flags " + f + ", expected " + flags ); | |||
if (f != flags) { | |||
throw new IllegalStateException ("inconsistent lookup flags " + f + ", expected " + flags); | |||
} | |||
} | |||
return flags | ( usesReverseScan ( subtables ) ? LF_INTERNAL_USE_REVERSE_SCAN : 0 ); | |||
return flags | (usesReverseScan (subtables) ? LF_INTERNAL_USE_REVERSE_SCAN : 0); | |||
} | |||
} | |||
@@ -44,7 +44,7 @@ public interface Positionable { | |||
* @return array (sequence) of 4-tuples of placement [PX,PY] and advance [AX,AY] adjustments, in that order, | |||
* with one 4-tuple for each element of glyph sequence, or null if no non-zero adjustment applies | |||
*/ | |||
int[][] performPositioning ( CharSequence cs, String script, String language, int fontSize ); | |||
int[][] performPositioning (CharSequence cs, String script, String language, int fontSize); | |||
/** | |||
* Perform glyph positioning using an implied font size. | |||
@@ -54,6 +54,6 @@ public interface Positionable { | |||
* @return array (sequence) of 4-tuples of placement [PX,PY] and advance [AX,AY] adjustments, in that order, | |||
* with one 4-tuple for each element of glyph sequence, or null if no non-zero adjustment applies | |||
*/ | |||
int[][] performPositioning ( CharSequence cs, String script, String language ); | |||
int[][] performPositioning (CharSequence cs, String script, String language); | |||
} |
@@ -46,7 +46,7 @@ public interface Substitutable { | |||
* @return output sequence (represented as a character sequence, where each character in the returned sequence | |||
* denotes "font characters", i.e., character codes that map directly (1-1) to their associated glyphs | |||
*/ | |||
CharSequence performSubstitution ( CharSequence cs, String script, String language ); | |||
CharSequence performSubstitution (CharSequence cs, String script, String language); | |||
/** | |||
* Reorder combining marks in character sequence so that they precede (within the sequence) the base | |||
@@ -59,6 +59,6 @@ public interface Substitutable { | |||
* @param language a language identifier | |||
* @return output sequence containing reordered "font characters" | |||
*/ | |||
CharSequence reorderCombiningMarks ( CharSequence cs, int[][] gpa, String script, String language ); | |||
CharSequence reorderCombiningMarks (CharSequence cs, int[][] gpa, String script, String language); | |||
} |
@@ -75,49 +75,49 @@ public class ArabicScriptProcessor extends DefaultScriptProcessor { | |||
private static class SubstitutionScriptContextTester implements ScriptContextTester { | |||
private static Map/*<String,GlyphContextTester>*/ testerMap = new HashMap/*<String,GlyphContextTester>*/(); | |||
static { | |||
testerMap.put ( "fina", new GlyphContextTester() { | |||
public boolean test ( String script, String language, String feature, GlyphSequence gs, int index, int flags ) { | |||
return inFinalContext ( script, language, feature, gs, index, flags ); | |||
testerMap.put ("fina", new GlyphContextTester() { | |||
public boolean test (String script, String language, String feature, GlyphSequence gs, int index, int flags) { | |||
return inFinalContext (script, language, feature, gs, index, flags); | |||
} | |||
} ); | |||
testerMap.put ( "init", new GlyphContextTester() { | |||
public boolean test ( String script, String language, String feature, GlyphSequence gs, int index, int flags ) { | |||
return inInitialContext ( script, language, feature, gs, index, flags ); | |||
}); | |||
testerMap.put ("init", new GlyphContextTester() { | |||
public boolean test (String script, String language, String feature, GlyphSequence gs, int index, int flags) { | |||
return inInitialContext (script, language, feature, gs, index, flags); | |||
} | |||
} ); | |||
testerMap.put ( "isol", new GlyphContextTester() { | |||
public boolean test ( String script, String language, String feature, GlyphSequence gs, int index, int flags ) { | |||
return inIsolateContext ( script, language, feature, gs, index, flags ); | |||
}); | |||
testerMap.put ("isol", new GlyphContextTester() { | |||
public boolean test (String script, String language, String feature, GlyphSequence gs, int index, int flags) { | |||
return inIsolateContext (script, language, feature, gs, index, flags); | |||
} | |||
} ); | |||
testerMap.put ( "liga", new GlyphContextTester() { | |||
public boolean test ( String script, String language, String feature, GlyphSequence gs, int index, int flags ) { | |||
return inLigatureContext ( script, language, feature, gs, index, flags ); | |||
}); | |||
testerMap.put ("liga", new GlyphContextTester() { | |||
public boolean test (String script, String language, String feature, GlyphSequence gs, int index, int flags) { | |||
return inLigatureContext (script, language, feature, gs, index, flags); | |||
} | |||
} ); | |||
testerMap.put ( "medi", new GlyphContextTester() { | |||
public boolean test ( String script, String language, String feature, GlyphSequence gs, int index, int flags ) { | |||
return inMedialContext ( script, language, feature, gs, index, flags ); | |||
}); | |||
testerMap.put ("medi", new GlyphContextTester() { | |||
public boolean test (String script, String language, String feature, GlyphSequence gs, int index, int flags) { | |||
return inMedialContext (script, language, feature, gs, index, flags); | |||
} | |||
} ); | |||
}); | |||
} | |||
public GlyphContextTester getTester ( String feature ) { | |||
return (GlyphContextTester) testerMap.get ( feature ); | |||
public GlyphContextTester getTester (String feature) { | |||
return (GlyphContextTester) testerMap.get (feature); | |||
} | |||
} | |||
private static class PositioningScriptContextTester implements ScriptContextTester { | |||
private static Map/*<String,GlyphContextTester>*/ testerMap = new HashMap/*<String,GlyphContextTester>*/(); | |||
public GlyphContextTester getTester ( String feature ) { | |||
return (GlyphContextTester) testerMap.get ( feature ); | |||
public GlyphContextTester getTester (String feature) { | |||
return (GlyphContextTester) testerMap.get (feature); | |||
} | |||
} | |||
private final ScriptContextTester subContextTester; | |||
private final ScriptContextTester posContextTester; | |||
ArabicScriptProcessor ( String script ) { | |||
super ( script ); | |||
ArabicScriptProcessor (String script) { | |||
super (script); | |||
this.subContextTester = new SubstitutionScriptContextTester(); | |||
this.posContextTester = new PositioningScriptContextTester(); | |||
} | |||
@@ -144,26 +144,26 @@ public class ArabicScriptProcessor extends DefaultScriptProcessor { | |||
/** {@inheritDoc} */ | |||
@Override | |||
public GlyphSequence reorderCombiningMarks ( GlyphDefinitionTable gdef, GlyphSequence gs, int[][] gpa, String script, String language ) { | |||
public GlyphSequence reorderCombiningMarks (GlyphDefinitionTable gdef, GlyphSequence gs, int[][] gpa, String script, String language) { | |||
// a side effect of BIDI reordering is to order combining marks before their base, so we need to override the default here to | |||
// prevent double reordering | |||
return gs; | |||
} | |||
private static boolean inFinalContext ( String script, String language, String feature, GlyphSequence gs, int index, int flags ) { | |||
GlyphSequence.CharAssociation a = gs.getAssociation ( index ); | |||
int[] ca = gs.getCharacterArray ( false ); | |||
private static boolean inFinalContext (String script, String language, String feature, GlyphSequence gs, int index, int flags) { | |||
GlyphSequence.CharAssociation a = gs.getAssociation (index); | |||
int[] ca = gs.getCharacterArray (false); | |||
int nc = gs.getCharacterCount(); | |||
if ( nc == 0 ) { | |||
if (nc == 0) { | |||
return false; | |||
} else { | |||
int s = a.getStart(); | |||
int e = a.getEnd(); | |||
if ( ! hasFinalPrecedingContext ( ca, nc, s, e ) ) { | |||
if (! hasFinalPrecedingContext (ca, nc, s, e)) { | |||
return false; | |||
} else if ( forcesFinalThisContext ( ca, nc, s, e ) ) { | |||
} else if (forcesFinalThisContext (ca, nc, s, e)) { | |||
return true; | |||
} else if ( ! hasFinalFollowingContext ( ca, nc, s, e ) ) { | |||
} else if (! hasFinalFollowingContext (ca, nc, s, e)) { | |||
return false; | |||
} else { | |||
return true; | |||
@@ -171,18 +171,18 @@ public class ArabicScriptProcessor extends DefaultScriptProcessor { | |||
} | |||
} | |||
private static boolean inInitialContext ( String script, String language, String feature, GlyphSequence gs, int index, int flags ) { | |||
GlyphSequence.CharAssociation a = gs.getAssociation ( index ); | |||
int[] ca = gs.getCharacterArray ( false ); | |||
private static boolean inInitialContext (String script, String language, String feature, GlyphSequence gs, int index, int flags) { | |||
GlyphSequence.CharAssociation a = gs.getAssociation (index); | |||
int[] ca = gs.getCharacterArray (false); | |||
int nc = gs.getCharacterCount(); | |||
if ( nc == 0 ) { | |||
if (nc == 0) { | |||
return false; | |||
} else { | |||
int s = a.getStart(); | |||
int e = a.getEnd(); | |||
if ( ! hasInitialPrecedingContext ( ca, nc, s, e ) ) { | |||
if (! hasInitialPrecedingContext (ca, nc, s, e)) { | |||
return false; | |||
} else if ( ! hasInitialFollowingContext ( ca, nc, s, e ) ) { | |||
} else if (! hasInitialFollowingContext (ca, nc, s, e)) { | |||
return false; | |||
} else { | |||
return true; | |||
@@ -190,30 +190,30 @@ public class ArabicScriptProcessor extends DefaultScriptProcessor { | |||
} | |||
} | |||
private static boolean inIsolateContext ( String script, String language, String feature, GlyphSequence gs, int index, int flags ) { | |||
GlyphSequence.CharAssociation a = gs.getAssociation ( index ); | |||
private static boolean inIsolateContext (String script, String language, String feature, GlyphSequence gs, int index, int flags) { | |||
GlyphSequence.CharAssociation a = gs.getAssociation (index); | |||
int nc = gs.getCharacterCount(); | |||
if ( nc == 0 ) { | |||
if (nc == 0) { | |||
return false; | |||
} else if ( ( a.getStart() == 0 ) && ( a.getEnd() == nc ) ) { | |||
} else if ((a.getStart() == 0) && (a.getEnd() == nc)) { | |||
return true; | |||
} else { | |||
return false; | |||
} | |||
} | |||
private static boolean inLigatureContext ( String script, String language, String feature, GlyphSequence gs, int index, int flags ) { | |||
GlyphSequence.CharAssociation a = gs.getAssociation ( index ); | |||
int[] ca = gs.getCharacterArray ( false ); | |||
private static boolean inLigatureContext (String script, String language, String feature, GlyphSequence gs, int index, int flags) { | |||
GlyphSequence.CharAssociation a = gs.getAssociation (index); | |||
int[] ca = gs.getCharacterArray (false); | |||
int nc = gs.getCharacterCount(); | |||
if ( nc == 0 ) { | |||
if (nc == 0) { | |||
return false; | |||
} else { | |||
int s = a.getStart(); | |||
int e = a.getEnd(); | |||
if ( ! hasLigaturePrecedingContext ( ca, nc, s, e ) ) { | |||
if (! hasLigaturePrecedingContext (ca, nc, s, e)) { | |||
return false; | |||
} else if ( ! hasLigatureFollowingContext ( ca, nc, s, e ) ) { | |||
} else if (! hasLigatureFollowingContext (ca, nc, s, e)) { | |||
return false; | |||
} else { | |||
return true; | |||
@@ -221,20 +221,20 @@ public class ArabicScriptProcessor extends DefaultScriptProcessor { | |||
} | |||
} | |||
private static boolean inMedialContext ( String script, String language, String feature, GlyphSequence gs, int index, int flags ) { | |||
GlyphSequence.CharAssociation a = gs.getAssociation ( index ); | |||
int[] ca = gs.getCharacterArray ( false ); | |||
private static boolean inMedialContext (String script, String language, String feature, GlyphSequence gs, int index, int flags) { | |||
GlyphSequence.CharAssociation a = gs.getAssociation (index); | |||
int[] ca = gs.getCharacterArray (false); | |||
int nc = gs.getCharacterCount(); | |||
if ( nc == 0 ) { | |||
if (nc == 0) { | |||
return false; | |||
} else { | |||
int s = a.getStart(); | |||
int e = a.getEnd(); | |||
if ( ! hasMedialPrecedingContext ( ca, nc, s, e ) ) { | |||
if (! hasMedialPrecedingContext (ca, nc, s, e)) { | |||
return false; | |||
} else if ( ! hasMedialThisContext ( ca, nc, s, e ) ) { | |||
} else if (! hasMedialThisContext (ca, nc, s, e)) { | |||
return false; | |||
} else if ( ! hasMedialFollowingContext ( ca, nc, s, e ) ) { | |||
} else if (! hasMedialFollowingContext (ca, nc, s, e)) { | |||
return false; | |||
} else { | |||
return true; | |||
@@ -242,209 +242,209 @@ public class ArabicScriptProcessor extends DefaultScriptProcessor { | |||
} | |||
} | |||
private static boolean hasFinalPrecedingContext ( int[] ca, int nc, int s, int e ) { | |||
private static boolean hasFinalPrecedingContext (int[] ca, int nc, int s, int e) { | |||
int chp = 0; | |||
int clp = 0; | |||
for ( int i = s; i > 0; i-- ) { | |||
for (int i = s; i > 0; i--) { | |||
int k = i - 1; | |||
if ( ( k >= 0 ) && ( k < nc ) ) { | |||
if ((k >= 0) && (k < nc)) { | |||
chp = ca [ k ]; | |||
clp = BidiClass.getBidiClass ( chp ); | |||
if ( clp != BidiConstants.NSM ) { | |||
clp = BidiClass.getBidiClass (chp); | |||
if (clp != BidiConstants.NSM) { | |||
break; | |||
} | |||
} | |||
} | |||
if ( clp != BidiConstants.AL ) { | |||
if (clp != BidiConstants.AL) { | |||
return false; | |||
} else if ( hasIsolateInitial ( chp ) ) { | |||
} else if (hasIsolateInitial (chp)) { | |||
return false; | |||
} else { | |||
return true; | |||
} | |||
} | |||
private static boolean forcesFinalThisContext ( int[] ca, int nc, int s, int e ) { | |||
private static boolean forcesFinalThisContext (int[] ca, int nc, int s, int e) { | |||
int chl = 0; | |||
int cll = 0; | |||
for ( int i = 0, n = e - s; i < n; i++ ) { | |||
for (int i = 0, n = e - s; i < n; i++) { | |||
int k = n - i - 1; | |||
int j = s + k; | |||
if ( ( j >= 0 ) && ( j < nc ) ) { | |||
if ((j >= 0) && (j < nc)) { | |||
chl = ca [ j ]; | |||
cll = BidiClass.getBidiClass ( chl ); | |||
if ( cll != BidiConstants.NSM ) { | |||
cll = BidiClass.getBidiClass (chl); | |||
if (cll != BidiConstants.NSM) { | |||
break; | |||
} | |||
} | |||
} | |||
if ( cll != BidiConstants.AL ) { | |||
if (cll != BidiConstants.AL) { | |||
return false; | |||
} | |||
if ( hasIsolateInitial ( chl ) ) { | |||
if (hasIsolateInitial (chl)) { | |||
return true; | |||
} else { | |||
return false; | |||
} | |||
} | |||
private static boolean hasFinalFollowingContext ( int[] ca, int nc, int s, int e ) { | |||
private static boolean hasFinalFollowingContext (int[] ca, int nc, int s, int e) { | |||
int chf = 0; | |||
int clf = 0; | |||
for ( int i = e, n = nc; i < n; i++ ) { | |||
for (int i = e, n = nc; i < n; i++) { | |||
chf = ca [ i ]; | |||
clf = BidiClass.getBidiClass ( chf ); | |||
if ( clf != BidiConstants.NSM ) { | |||
clf = BidiClass.getBidiClass (chf); | |||
if (clf != BidiConstants.NSM) { | |||
break; | |||
} | |||
} | |||
if ( clf != BidiConstants.AL ) { | |||
if (clf != BidiConstants.AL) { | |||
return true; | |||
} else if ( hasIsolateFinal ( chf ) ) { | |||
} else if (hasIsolateFinal (chf)) { | |||
return true; | |||
} else { | |||
return false; | |||
} | |||
} | |||
private static boolean hasInitialPrecedingContext ( int[] ca, int nc, int s, int e ) { | |||
private static boolean hasInitialPrecedingContext (int[] ca, int nc, int s, int e) { | |||
int chp = 0; | |||
int clp = 0; | |||
for ( int i = s; i > 0; i-- ) { | |||
for (int i = s; i > 0; i--) { | |||
int k = i - 1; | |||
if ( ( k >= 0 ) && ( k < nc ) ) { | |||
if ((k >= 0) && (k < nc)) { | |||
chp = ca [ k ]; | |||
clp = BidiClass.getBidiClass ( chp ); | |||
if ( clp != BidiConstants.NSM ) { | |||
clp = BidiClass.getBidiClass (chp); | |||
if (clp != BidiConstants.NSM) { | |||
break; | |||
} | |||
} | |||
} | |||
if ( clp != BidiConstants.AL ) { | |||
if (clp != BidiConstants.AL) { | |||
return true; | |||
} else if ( hasIsolateInitial ( chp ) ) { | |||
} else if (hasIsolateInitial (chp)) { | |||
return true; | |||
} else { | |||
return false; | |||
} | |||
} | |||
private static boolean hasInitialFollowingContext ( int[] ca, int nc, int s, int e ) { | |||
private static boolean hasInitialFollowingContext (int[] ca, int nc, int s, int e) { | |||
int chf = 0; | |||
int clf = 0; | |||
for ( int i = e, n = nc; i < n; i++ ) { | |||
for (int i = e, n = nc; i < n; i++) { | |||
chf = ca [ i ]; | |||
clf = BidiClass.getBidiClass ( chf ); | |||
if ( clf != BidiConstants.NSM ) { | |||
clf = BidiClass.getBidiClass (chf); | |||
if (clf != BidiConstants.NSM) { | |||
break; | |||
} | |||
} | |||
if ( clf != BidiConstants.AL ) { | |||
if (clf != BidiConstants.AL) { | |||
return false; | |||
} else if ( hasIsolateFinal ( chf ) ) { | |||
} else if (hasIsolateFinal (chf)) { | |||
return false; | |||
} else { | |||
return true; | |||
} | |||
} | |||
private static boolean hasMedialPrecedingContext ( int[] ca, int nc, int s, int e ) { | |||
private static boolean hasMedialPrecedingContext (int[] ca, int nc, int s, int e) { | |||
int chp = 0; | |||
int clp = 0; | |||
for ( int i = s; i > 0; i-- ) { | |||
for (int i = s; i > 0; i--) { | |||
int k = i - 1; | |||
if ( ( k >= 0 ) && ( k < nc ) ) { | |||
if ((k >= 0) && (k < nc)) { | |||
chp = ca [ k ]; | |||
clp = BidiClass.getBidiClass ( chp ); | |||
if ( clp != BidiConstants.NSM ) { | |||
clp = BidiClass.getBidiClass (chp); | |||
if (clp != BidiConstants.NSM) { | |||
break; | |||
} | |||
} | |||
} | |||
if ( clp != BidiConstants.AL ) { | |||
if (clp != BidiConstants.AL) { | |||
return false; | |||
} else if ( hasIsolateInitial ( chp ) ) { | |||
} else if (hasIsolateInitial (chp)) { | |||
return false; | |||
} else { | |||
return true; | |||
} | |||
} | |||
private static boolean hasMedialThisContext ( int[] ca, int nc, int s, int e ) { | |||
private static boolean hasMedialThisContext (int[] ca, int nc, int s, int e) { | |||
int chf = 0; // first non-NSM char in [s,e) | |||
int clf = 0; | |||
for ( int i = 0, n = e - s; i < n; i++ ) { | |||
for (int i = 0, n = e - s; i < n; i++) { | |||
int k = s + i; | |||
if ( ( k >= 0 ) && ( k < nc ) ) { | |||
if ((k >= 0) && (k < nc)) { | |||
chf = ca [ s + i ]; | |||
clf = BidiClass.getBidiClass ( chf ); | |||
if ( clf != BidiConstants.NSM ) { | |||
clf = BidiClass.getBidiClass (chf); | |||
if (clf != BidiConstants.NSM) { | |||
break; | |||
} | |||
} | |||
} | |||
if ( clf != BidiConstants.AL ) { | |||
if (clf != BidiConstants.AL) { | |||
return false; | |||
} | |||
int chl = 0; // last non-NSM char in [s,e) | |||
int cll = 0; | |||
for ( int i = 0, n = e - s; i < n; i++ ) { | |||
for (int i = 0, n = e - s; i < n; i++) { | |||
int k = n - i - 1; | |||
int j = s + k; | |||
if ( ( j >= 0 ) && ( j < nc ) ) { | |||
if ((j >= 0) && (j < nc)) { | |||
chl = ca [ j ]; | |||
cll = BidiClass.getBidiClass ( chl ); | |||
if ( cll != BidiConstants.NSM ) { | |||
cll = BidiClass.getBidiClass (chl); | |||
if (cll != BidiConstants.NSM) { | |||
break; | |||
} | |||
} | |||
} | |||
if ( cll != BidiConstants.AL ) { | |||
if (cll != BidiConstants.AL) { | |||
return false; | |||
} | |||
if ( hasIsolateFinal ( chf ) ) { | |||
if (hasIsolateFinal (chf)) { | |||
return false; | |||
} else if ( hasIsolateInitial ( chl ) ) { | |||
} else if (hasIsolateInitial (chl)) { | |||
return false; | |||
} else { | |||
return true; | |||
} | |||
} | |||
private static boolean hasMedialFollowingContext ( int[] ca, int nc, int s, int e ) { | |||
private static boolean hasMedialFollowingContext (int[] ca, int nc, int s, int e) { | |||
int chf = 0; | |||
int clf = 0; | |||
for ( int i = e, n = nc; i < n; i++ ) { | |||
for (int i = e, n = nc; i < n; i++) { | |||
chf = ca [ i ]; | |||
clf = BidiClass.getBidiClass ( chf ); | |||
if ( clf != BidiConstants.NSM ) { | |||
clf = BidiClass.getBidiClass (chf); | |||
if (clf != BidiConstants.NSM) { | |||
break; | |||
} | |||
} | |||
if ( clf != BidiConstants.AL ) { | |||
if (clf != BidiConstants.AL) { | |||
return false; | |||
} else if ( hasIsolateFinal ( chf ) ) { | |||
} else if (hasIsolateFinal (chf)) { | |||
return false; | |||
} else { | |||
return true; | |||
} | |||
} | |||
private static boolean hasLigaturePrecedingContext ( int[] ca, int nc, int s, int e ) { | |||
private static boolean hasLigaturePrecedingContext (int[] ca, int nc, int s, int e) { | |||
return true; | |||
} | |||
private static boolean hasLigatureFollowingContext ( int[] ca, int nc, int s, int e ) { | |||
private static boolean hasLigatureFollowingContext (int[] ca, int nc, int s, int e) { | |||
int chf = 0; | |||
int clf = 0; | |||
for ( int i = e, n = nc; i < n; i++ ) { | |||
for (int i = e, n = nc; i < n; i++) { | |||
chf = ca [ i ]; | |||
clf = BidiClass.getBidiClass ( chf ); | |||
if ( clf != BidiConstants.NSM ) { | |||
clf = BidiClass.getBidiClass (chf); | |||
if (clf != BidiConstants.NSM) { | |||
break; | |||
} | |||
} | |||
if ( clf == BidiConstants.AL ) { | |||
if (clf == BidiConstants.AL) { | |||
return true; | |||
} else { | |||
return false; | |||
@@ -504,8 +504,8 @@ public class ArabicScriptProcessor extends DefaultScriptProcessor { | |||
0x06EF // REH WITH INVERTED V | |||
}; | |||
private static boolean hasIsolateInitial ( int ch ) { | |||
return Arrays.binarySearch ( isolatedInitials, ch ) >= 0; | |||
private static boolean hasIsolateInitial (int ch) { | |||
return Arrays.binarySearch (isolatedInitials, ch) >= 0; | |||
} | |||
/** | |||
@@ -516,8 +516,8 @@ public class ArabicScriptProcessor extends DefaultScriptProcessor { | |||
0x0621 // HAMZA | |||
}; | |||
private static boolean hasIsolateFinal ( int ch ) { | |||
return Arrays.binarySearch ( isolatedFinals, ch ) >= 0; | |||
private static boolean hasIsolateFinal (int ch) { | |||
return Arrays.binarySearch (isolatedFinals, ch) >= 0; | |||
} | |||
} |
@@ -49,8 +49,8 @@ public class DefaultScriptProcessor extends ScriptProcessor { | |||
"mkmk" // mark to mark positioning | |||
}; | |||
DefaultScriptProcessor ( String script ) { | |||
super ( script ); | |||
DefaultScriptProcessor (String script) { | |||
super (script); | |||
} | |||
@Override | |||
@@ -79,43 +79,43 @@ public class DefaultScriptProcessor extends ScriptProcessor { | |||
@Override | |||
/** {@inheritDoc} */ | |||
public GlyphSequence reorderCombiningMarks ( GlyphDefinitionTable gdef, GlyphSequence gs, int[][] gpa, String script, String language ) { | |||
public GlyphSequence reorderCombiningMarks (GlyphDefinitionTable gdef, GlyphSequence gs, int[][] gpa, String script, String language) { | |||
int ng = gs.getGlyphCount(); | |||
int[] ga = gs.getGlyphArray ( false ); | |||
int[] ga = gs.getGlyphArray (false); | |||
int nm = 0; | |||
// count combining marks | |||
for ( int i = 0; i < ng; i++ ) { | |||
for (int i = 0; i < ng; i++) { | |||
int gid = ga [ i ]; | |||
if ( gdef.isGlyphClass ( gid, GlyphDefinitionTable.GLYPH_CLASS_MARK ) ) { | |||
if (gdef.isGlyphClass (gid, GlyphDefinitionTable.GLYPH_CLASS_MARK)) { | |||
nm++; | |||
} | |||
} | |||
// only reorder if there is at least one mark and at least one non-mark glyph | |||
if ( ( nm > 0 ) && ( ( ng - nm ) > 0 ) ) { | |||
GlyphSequence.CharAssociation[] aa = gs.getAssociations ( 0, -1 ); | |||
if ((nm > 0) && ((ng - nm) > 0)) { | |||
GlyphSequence.CharAssociation[] aa = gs.getAssociations (0, -1); | |||
int[] nga = new int [ ng ]; | |||
int[][] npa = ( gpa != null ) ? new int [ ng ][] : null; | |||
int[][] npa = (gpa != null) ? new int [ ng ][] : null; | |||
GlyphSequence.CharAssociation[] naa = new GlyphSequence.CharAssociation [ ng ]; | |||
int k = 0; | |||
GlyphSequence.CharAssociation ba = null; | |||
int bg = -1; | |||
int[] bpa = null; | |||
for ( int i = 0; i < ng; i++ ) { | |||
for (int i = 0; i < ng; i++) { | |||
int gid = ga [ i ]; | |||
int[] pa = ( gpa != null ) ? gpa [ i ] : null; | |||
int[] pa = (gpa != null) ? gpa [ i ] : null; | |||
GlyphSequence.CharAssociation ca = aa [ i ]; | |||
if ( gdef.isGlyphClass ( gid, GlyphDefinitionTable.GLYPH_CLASS_MARK ) ) { | |||
if (gdef.isGlyphClass (gid, GlyphDefinitionTable.GLYPH_CLASS_MARK)) { | |||
nga [ k ] = gid; | |||
naa [ k ] = ca; | |||
if ( npa != null ) { | |||
if (npa != null) { | |||
npa [ k ] = pa; | |||
} | |||
k++; | |||
} else { | |||
if ( bg != -1 ) { | |||
if (bg != -1) { | |||
nga [ k ] = bg; | |||
naa [ k ] = ba; | |||
if ( npa != null ) { | |||
if (npa != null) { | |||
npa [ k ] = bpa; | |||
} | |||
k++; | |||
@@ -123,26 +123,26 @@ public class DefaultScriptProcessor extends ScriptProcessor { | |||
ba = null; | |||
bpa = null; | |||
} | |||
if ( bg == -1 ) { | |||
if (bg == -1) { | |||
bg = gid; | |||
ba = ca; | |||
bpa = pa; | |||
} | |||
} | |||
} | |||
if ( bg != -1 ) { | |||
if (bg != -1) { | |||
nga [ k ] = bg; | |||
naa [ k ] = ba; | |||
if ( npa != null ) { | |||
if (npa != null) { | |||
npa [ k ] = bpa; | |||
} | |||
k++; | |||
} | |||
assert k == ng; | |||
if ( npa != null ) { | |||
System.arraycopy ( npa, 0, gpa, 0, ng ); | |||
if (npa != null) { | |||
System.arraycopy (npa, 0, gpa, 0, ng); | |||
} | |||
return new GlyphSequence ( gs, null, nga, null, null, naa, null ); | |||
return new GlyphSequence (gs, null, nga, null, null, naa, null); | |||
} else { | |||
return gs; | |||
} |
@@ -42,8 +42,8 @@ public class DevanagariScriptProcessor extends IndicScriptProcessor { | |||
/** logging instance */ | |||
private static final Log log = LogFactory.getLog(DevanagariScriptProcessor.class); // CSOK: ConstantNameCheck | |||
DevanagariScriptProcessor ( String script ) { | |||
super ( script ); | |||
DevanagariScriptProcessor (String script) { | |||
super (script); | |||
} | |||
@Override | |||
@@ -53,12 +53,12 @@ public class DevanagariScriptProcessor extends IndicScriptProcessor { | |||
@Override | |||
// find rightmost pre-base matra | |||
protected int findPreBaseMatra ( GlyphSequence gs ) { | |||
protected int findPreBaseMatra (GlyphSequence gs) { | |||
int ng = gs.getGlyphCount(); | |||
int lk = -1; | |||
for ( int i = ng; i > 0; i-- ) { | |||
for (int i = ng; i > 0; i--) { | |||
int k = i - 1; | |||
if ( containsPreBaseMatra ( gs, k ) ) { | |||
if (containsPreBaseMatra (gs, k)) { | |||
lk = k; | |||
break; | |||
} | |||
@@ -68,15 +68,15 @@ public class DevanagariScriptProcessor extends IndicScriptProcessor { | |||
@Override | |||
// find leftmost pre-base matra target, starting from source | |||
protected int findPreBaseMatraTarget ( GlyphSequence gs, int source ) { | |||
protected int findPreBaseMatraTarget (GlyphSequence gs, int source) { | |||
int ng = gs.getGlyphCount(); | |||
int lk = -1; | |||
for ( int i = ( source < ng ) ? source : ng; i > 0; i-- ) { | |||
for (int i = (source < ng) ? source : ng; i > 0; i--) { | |||
int k = i - 1; | |||
if ( containsConsonant ( gs, k ) ) { | |||
if ( containsHalfConsonant ( gs, k ) ) { | |||
if (containsConsonant (gs, k)) { | |||
if (containsHalfConsonant (gs, k)) { | |||
lk = k; | |||
} else if ( lk == -1 ) { | |||
} else if (lk == -1) { | |||
lk = k; | |||
} else { | |||
break; | |||
@@ -86,39 +86,39 @@ public class DevanagariScriptProcessor extends IndicScriptProcessor { | |||
return lk; | |||
} | |||
private static boolean containsPreBaseMatra ( GlyphSequence gs, int k ) { | |||
GlyphSequence.CharAssociation a = gs.getAssociation ( k ); | |||
int[] ca = gs.getCharacterArray ( false ); | |||
for ( int i = a.getStart(), e = a.getEnd(); i < e; i++ ) { | |||
if ( isPreM ( ca [ i ] ) ) { | |||
private static boolean containsPreBaseMatra (GlyphSequence gs, int k) { | |||
GlyphSequence.CharAssociation a = gs.getAssociation (k); | |||
int[] ca = gs.getCharacterArray (false); | |||
for (int i = a.getStart(), e = a.getEnd(); i < e; i++) { | |||
if (isPreM (ca [ i ])) { | |||
return true; | |||
} | |||
} | |||
return false; | |||
} | |||
private static boolean containsConsonant ( GlyphSequence gs, int k ) { | |||
GlyphSequence.CharAssociation a = gs.getAssociation ( k ); | |||
int[] ca = gs.getCharacterArray ( false ); | |||
for ( int i = a.getStart(), e = a.getEnd(); i < e; i++ ) { | |||
if ( isC ( ca [ i ] ) ) { | |||
private static boolean containsConsonant (GlyphSequence gs, int k) { | |||
GlyphSequence.CharAssociation a = gs.getAssociation (k); | |||
int[] ca = gs.getCharacterArray (false); | |||
for (int i = a.getStart(), e = a.getEnd(); i < e; i++) { | |||
if (isC (ca [ i ])) { | |||
return true; | |||
} | |||
} | |||
return false; | |||
} | |||
private static boolean containsHalfConsonant ( GlyphSequence gs, int k ) { | |||
Boolean half = (Boolean) gs.getAssociation ( k ) . getPredication ( "half" ); | |||
return ( half != null ) ? half.booleanValue() : false; | |||
private static boolean containsHalfConsonant (GlyphSequence gs, int k) { | |||
Boolean half = (Boolean) gs.getAssociation (k) . getPredication ("half"); | |||
return (half != null) ? half.booleanValue() : false; | |||
} | |||
@Override | |||
protected int findReph ( GlyphSequence gs ) { | |||
protected int findReph (GlyphSequence gs) { | |||
int ng = gs.getGlyphCount(); | |||
int li = -1; | |||
for ( int i = 0; i < ng; i++ ) { | |||
if ( containsReph ( gs, i ) ) { | |||
for (int i = 0; i < ng; i++) { | |||
if (containsReph (gs, i)) { | |||
li = i; | |||
break; | |||
} | |||
@@ -127,58 +127,58 @@ public class DevanagariScriptProcessor extends IndicScriptProcessor { | |||
} | |||
@Override | |||
protected int findRephTarget ( GlyphSequence gs, int source ) { | |||
protected int findRephTarget (GlyphSequence gs, int source) { | |||
int ng = gs.getGlyphCount(); | |||
int c1 = -1; | |||
int c2 = -1; | |||
// first candidate target is after first non-half consonant | |||
for ( int i = 0; i < ng; i++ ) { | |||
if ( ( i != source ) && containsConsonant ( gs, i ) ) { | |||
if ( ! containsHalfConsonant ( gs, i ) ) { | |||
for (int i = 0; i < ng; i++) { | |||
if ((i != source) && containsConsonant (gs, i)) { | |||
if (! containsHalfConsonant (gs, i)) { | |||
c1 = i + 1; | |||
break; | |||
} | |||
} | |||
} | |||
// second candidate target is after last non-prebase matra after first candidate or before first syllable or vedic mark | |||
for ( int i = ( c1 >= 0 ) ? c1 : 0; i < ng; i++ ) { | |||
if ( containsMatra ( gs, i ) && ! containsPreBaseMatra ( gs, i ) ) { | |||
for (int i = (c1 >= 0) ? c1 : 0; i < ng; i++) { | |||
if (containsMatra (gs, i) && ! containsPreBaseMatra (gs, i)) { | |||
c2 = i + 1; | |||
} else if ( containsOtherMark ( gs, i ) ) { | |||
} else if (containsOtherMark (gs, i)) { | |||
c2 = i; | |||
break; | |||
} | |||
} | |||
if ( c2 >= 0 ) { | |||
if (c2 >= 0) { | |||
return c2; | |||
} else if ( c1 >= 0 ) { | |||
} else if (c1 >= 0) { | |||
return c1; | |||
} else { | |||
return source; | |||
} | |||
} | |||
private static boolean containsReph ( GlyphSequence gs, int k ) { | |||
Boolean rphf = (Boolean) gs.getAssociation ( k ) . getPredication ( "rphf" ); | |||
return ( rphf != null ) ? rphf.booleanValue() : false; | |||
private static boolean containsReph (GlyphSequence gs, int k) { | |||
Boolean rphf = (Boolean) gs.getAssociation (k) . getPredication ("rphf"); | |||
return (rphf != null) ? rphf.booleanValue() : false; | |||
} | |||
private static boolean containsMatra ( GlyphSequence gs, int k ) { | |||
GlyphSequence.CharAssociation a = gs.getAssociation ( k ); | |||
int[] ca = gs.getCharacterArray ( false ); | |||
for ( int i = a.getStart(), e = a.getEnd(); i < e; i++ ) { | |||
if ( isM ( ca [ i ] ) ) { | |||
private static boolean containsMatra (GlyphSequence gs, int k) { | |||
GlyphSequence.CharAssociation a = gs.getAssociation (k); | |||
int[] ca = gs.getCharacterArray (false); | |||
for (int i = a.getStart(), e = a.getEnd(); i < e; i++) { | |||
if (isM (ca [ i ])) { | |||
return true; | |||
} | |||
} | |||
return false; | |||
} | |||
private static boolean containsOtherMark ( GlyphSequence gs, int k ) { | |||
GlyphSequence.CharAssociation a = gs.getAssociation ( k ); | |||
int[] ca = gs.getCharacterArray ( false ); | |||
for ( int i = a.getStart(), e = a.getEnd(); i < e; i++ ) { | |||
switch ( typeOf ( ca [ i ] ) ) { | |||
private static boolean containsOtherMark (GlyphSequence gs, int k) { | |||
GlyphSequence.CharAssociation a = gs.getAssociation (k); | |||
int[] ca = gs.getCharacterArray (false); | |||
for (int i = a.getStart(), e = a.getEnd(); i < e; i++) { | |||
switch (typeOf (ca [ i ])) { | |||
case C_T: // tone (e.g., udatta, anudatta) | |||
case C_A: // accent (e.g., acute, grave) | |||
case C_O: // other (e.g., candrabindu, anusvara, visarga, etc) | |||
@@ -191,18 +191,18 @@ public class DevanagariScriptProcessor extends IndicScriptProcessor { | |||
} | |||
private static class DevanagariSyllabizer extends DefaultSyllabizer { | |||
DevanagariSyllabizer ( String script, String language ) { | |||
super ( script, language ); | |||
DevanagariSyllabizer (String script, String language) { | |||
super (script, language); | |||
} | |||
@Override | |||
// | C ... | |||
protected int findStartOfSyllable ( int[] ca, int s, int e ) { | |||
if ( ( s < 0 ) || ( s >= e ) ) { | |||
protected int findStartOfSyllable (int[] ca, int s, int e) { | |||
if ((s < 0) || (s >= e)) { | |||
return -1; | |||
} else { | |||
while ( s < e ) { | |||
while (s < e) { | |||
int c = ca [ s ]; | |||
if ( isC ( c ) ) { | |||
if (isC (c)) { | |||
break; | |||
} else { | |||
s++; | |||
@@ -213,29 +213,29 @@ public class DevanagariScriptProcessor extends IndicScriptProcessor { | |||
} | |||
@Override | |||
// D* L? | ... | |||
protected int findEndOfSyllable ( int[] ca, int s, int e ) { | |||
if ( ( s < 0 ) || ( s >= e ) ) { | |||
protected int findEndOfSyllable (int[] ca, int s, int e) { | |||
if ((s < 0) || (s >= e)) { | |||
return -1; | |||
} else { | |||
int nd = 0; | |||
int nl = 0; | |||
int i; | |||
// consume dead consonants | |||
while ( ( i = isDeadConsonant ( ca, s, e ) ) > s ) { | |||
while ((i = isDeadConsonant (ca, s, e)) > s) { | |||
s = i; | |||
nd++; | |||
} | |||
// consume zero or one live consonant | |||
if ( ( i = isLiveConsonant ( ca, s, e ) ) > s ) { | |||
if ((i = isLiveConsonant (ca, s, e)) > s) { | |||
s = i; | |||
nl++; | |||
} | |||
return ( ( nd > 0 ) || ( nl > 0 ) ) ? s : -1; | |||
return ((nd > 0) || (nl > 0)) ? s : -1; | |||
} | |||
} | |||
// D := ( C N? H )? | |||
private int isDeadConsonant ( int[] ca, int s, int e ) { | |||
if ( s < 0 ) { | |||
private int isDeadConsonant (int[] ca, int s, int e) { | |||
if (s < 0) { | |||
return -1; | |||
} else { | |||
int c; | |||
@@ -244,9 +244,9 @@ public class DevanagariScriptProcessor extends IndicScriptProcessor { | |||
int nh = 0; | |||
do { | |||
// C | |||
if ( ( s + i ) < e ) { | |||
if ((s + i) < e) { | |||
c = ca [ s + i ]; | |||
if ( isC ( c ) ) { | |||
if (isC (c)) { | |||
i++; | |||
nc++; | |||
} else { | |||
@@ -254,29 +254,29 @@ public class DevanagariScriptProcessor extends IndicScriptProcessor { | |||
} | |||
} | |||
// N? | |||
if ( ( s + i ) < e ) { | |||
if ((s + i) < e) { | |||
c = ca [ s + 1 ]; | |||
if ( isN ( c ) ) { | |||
if (isN (c)) { | |||
i++; | |||
} | |||
} | |||
// H | |||
if ( ( s + i ) < e ) { | |||
if ((s + i) < e) { | |||
c = ca [ s + i ]; | |||
if ( isH ( c ) ) { | |||
if (isH (c)) { | |||
i++; | |||
nh++; | |||
} else { | |||
break; | |||
} | |||
} | |||
} while ( false ); | |||
return ( nc > 0 ) && ( nh > 0 ) ? s + i : -1; | |||
} while (false); | |||
return (nc > 0) && (nh > 0) ? s + i : -1; | |||
} | |||
} | |||
// L := ( (C|V) N? X* )?; where X = ( MATRA | ACCENT MARK | TONE MARK | OTHER MARK ) | |||
private int isLiveConsonant ( int[] ca, int s, int e ) { | |||
if ( s < 0 ) { | |||
private int isLiveConsonant (int[] ca, int s, int e) { | |||
if (s < 0) { | |||
return -1; | |||
} else { | |||
int c; | |||
@@ -286,12 +286,12 @@ public class DevanagariScriptProcessor extends IndicScriptProcessor { | |||
int nx = 0; | |||
do { | |||
// C | |||
if ( ( s + i ) < e ) { | |||
if ((s + i) < e) { | |||
c = ca [ s + i ]; | |||
if ( isC ( c ) ) { | |||
if (isC (c)) { | |||
i++; | |||
nc++; | |||
} else if ( isV ( c ) ) { | |||
} else if (isV (c)) { | |||
i++; | |||
nv++; | |||
} else { | |||
@@ -299,37 +299,37 @@ public class DevanagariScriptProcessor extends IndicScriptProcessor { | |||
} | |||
} | |||
// N? | |||
if ( ( s + i ) < e ) { | |||
if ((s + i) < e) { | |||
c = ca [ s + i ]; | |||
if ( isN ( c ) ) { | |||
if (isN (c)) { | |||
i++; | |||
} | |||
} | |||
// X* | |||
while ( ( s + i ) < e ) { | |||
while ((s + i) < e) { | |||
c = ca [ s + i ]; | |||
if ( isX ( c ) ) { | |||
if (isX (c)) { | |||
i++; | |||
nx++; | |||
} else { | |||
break; | |||
} | |||
} | |||
} while ( false ); | |||
} while (false); | |||
// if no X but has H, then ignore C|I | |||
if ( nx == 0 ) { | |||
if ( ( s + i ) < e ) { | |||
if (nx == 0) { | |||
if ((s + i) < e) { | |||
c = ca [ s + i ]; | |||
if ( isH ( c ) ) { | |||
if ( nc > 0 ) { | |||
if (isH (c)) { | |||
if (nc > 0) { | |||
nc--; | |||
} else if ( nv > 0 ) { | |||
} else if (nv > 0) { | |||
nv--; | |||
} | |||
} | |||
} | |||
} | |||
return ( ( nc > 0 ) || ( nv > 0 ) ) ? s + i : -1; | |||
return ((nc > 0) || (nv > 0)) ? s + i : -1; | |||
} | |||
} | |||
} | |||
@@ -486,18 +486,18 @@ public class DevanagariScriptProcessor extends IndicScriptProcessor { | |||
C_C // 0x097F // BBA (SINDHI) | |||
}; | |||
static int typeOf(int c) { | |||
if ( ( c >= ccaStart ) && ( c < ccaEnd ) ) { | |||
if ((c >= ccaStart) && (c < ccaEnd)) { | |||
return cca [ c - ccaStart ] & C_M_TYPE; | |||
} else { | |||
return C_U; | |||
} | |||
} | |||
static boolean isType(int c, int t) { | |||
return typeOf ( c ) == t; | |||
return typeOf (c) == t; | |||
} | |||
static boolean hasFlag(int c, int f) { | |||
if ( ( c >= ccaStart ) && ( c < ccaEnd ) ) { | |||
return ( cca [ c - ccaStart ] & f ) == f; | |||
if ((c >= ccaStart) && (c < ccaEnd)) { | |||
return (cca [ c - ccaStart ] & f) == f; | |||
} else { | |||
return false; | |||
} | |||
@@ -524,7 +524,7 @@ public class DevanagariScriptProcessor extends IndicScriptProcessor { | |||
return isType(c,C_M) && hasFlag(c,C_PRE); | |||
} | |||
static boolean isX(int c) { | |||
switch ( typeOf ( c ) ) { | |||
switch (typeOf (c)) { | |||
case C_M: // matra (combining vowel) | |||
case C_A: // accent mark | |||
case C_T: // tone mark |
@@ -42,8 +42,8 @@ public class GujaratiScriptProcessor extends IndicScriptProcessor { | |||
/** logging instance */ | |||
private static final Log log = LogFactory.getLog(GujaratiScriptProcessor.class); // CSOK: ConstantNameCheck | |||
GujaratiScriptProcessor ( String script ) { | |||
super ( script ); | |||
GujaratiScriptProcessor (String script) { | |||
super (script); | |||
} | |||
@Override | |||
@@ -53,12 +53,12 @@ public class GujaratiScriptProcessor extends IndicScriptProcessor { | |||
@Override | |||
// find rightmost pre-base matra | |||
protected int findPreBaseMatra ( GlyphSequence gs ) { | |||
protected int findPreBaseMatra (GlyphSequence gs) { | |||
int ng = gs.getGlyphCount(); | |||
int lk = -1; | |||
for ( int i = ng; i > 0; i-- ) { | |||
for (int i = ng; i > 0; i--) { | |||
int k = i - 1; | |||
if ( containsPreBaseMatra ( gs, k ) ) { | |||
if (containsPreBaseMatra (gs, k)) { | |||
lk = k; | |||
break; | |||
} | |||
@@ -68,15 +68,15 @@ public class GujaratiScriptProcessor extends IndicScriptProcessor { | |||
@Override | |||
// find leftmost pre-base matra target, starting from source | |||
protected int findPreBaseMatraTarget ( GlyphSequence gs, int source ) { | |||
protected int findPreBaseMatraTarget (GlyphSequence gs, int source) { | |||
int ng = gs.getGlyphCount(); | |||
int lk = -1; | |||
for ( int i = ( source < ng ) ? source : ng; i > 0; i-- ) { | |||
for (int i = (source < ng) ? source : ng; i > 0; i--) { | |||
int k = i - 1; | |||
if ( containsConsonant ( gs, k ) ) { | |||
if ( containsHalfConsonant ( gs, k ) ) { | |||
if (containsConsonant (gs, k)) { | |||
if (containsHalfConsonant (gs, k)) { | |||
lk = k; | |||
} else if ( lk == -1 ) { | |||
} else if (lk == -1) { | |||
lk = k; | |||
} else { | |||
break; | |||
@@ -86,39 +86,39 @@ public class GujaratiScriptProcessor extends IndicScriptProcessor { | |||
return lk; | |||
} | |||
private static boolean containsPreBaseMatra ( GlyphSequence gs, int k ) { | |||
GlyphSequence.CharAssociation a = gs.getAssociation ( k ); | |||
int[] ca = gs.getCharacterArray ( false ); | |||
for ( int i = a.getStart(), e = a.getEnd(); i < e; i++ ) { | |||
if ( isPreM ( ca [ i ] ) ) { | |||
private static boolean containsPreBaseMatra (GlyphSequence gs, int k) { | |||
GlyphSequence.CharAssociation a = gs.getAssociation (k); | |||
int[] ca = gs.getCharacterArray (false); | |||
for (int i = a.getStart(), e = a.getEnd(); i < e; i++) { | |||
if (isPreM (ca [ i ])) { | |||
return true; | |||
} | |||
} | |||
return false; | |||
} | |||
private static boolean containsConsonant ( GlyphSequence gs, int k ) { | |||
GlyphSequence.CharAssociation a = gs.getAssociation ( k ); | |||
int[] ca = gs.getCharacterArray ( false ); | |||
for ( int i = a.getStart(), e = a.getEnd(); i < e; i++ ) { | |||
if ( isC ( ca [ i ] ) ) { | |||
private static boolean containsConsonant (GlyphSequence gs, int k) { | |||
GlyphSequence.CharAssociation a = gs.getAssociation (k); | |||
int[] ca = gs.getCharacterArray (false); | |||
for (int i = a.getStart(), e = a.getEnd(); i < e; i++) { | |||
if (isC (ca [ i ])) { | |||
return true; | |||
} | |||
} | |||
return false; | |||
} | |||
private static boolean containsHalfConsonant ( GlyphSequence gs, int k ) { | |||
Boolean half = (Boolean) gs.getAssociation ( k ) . getPredication ( "half" ); | |||
return ( half != null ) ? half.booleanValue() : false; | |||
private static boolean containsHalfConsonant (GlyphSequence gs, int k) { | |||
Boolean half = (Boolean) gs.getAssociation (k) . getPredication ("half"); | |||
return (half != null) ? half.booleanValue() : false; | |||
} | |||
@Override | |||
protected int findReph ( GlyphSequence gs ) { | |||
protected int findReph (GlyphSequence gs) { | |||
int ng = gs.getGlyphCount(); | |||
int li = -1; | |||
for ( int i = 0; i < ng; i++ ) { | |||
if ( containsReph ( gs, i ) ) { | |||
for (int i = 0; i < ng; i++) { | |||
if (containsReph (gs, i)) { | |||
li = i; | |||
break; | |||
} | |||
@@ -127,58 +127,58 @@ public class GujaratiScriptProcessor extends IndicScriptProcessor { | |||
} | |||
@Override | |||
protected int findRephTarget ( GlyphSequence gs, int source ) { | |||
protected int findRephTarget (GlyphSequence gs, int source) { | |||
int ng = gs.getGlyphCount(); | |||
int c1 = -1; | |||
int c2 = -1; | |||
// first candidate target is after first non-half consonant | |||
for ( int i = 0; i < ng; i++ ) { | |||
if ( ( i != source ) && containsConsonant ( gs, i ) ) { | |||
if ( ! containsHalfConsonant ( gs, i ) ) { | |||
for (int i = 0; i < ng; i++) { | |||
if ((i != source) && containsConsonant (gs, i)) { | |||
if (! containsHalfConsonant (gs, i)) { | |||
c1 = i + 1; | |||
break; | |||
} | |||
} | |||
} | |||
// second candidate target is after last non-prebase matra after first candidate or before first syllable or vedic mark | |||
for ( int i = ( c1 >= 0 ) ? c1 : 0; i < ng; i++ ) { | |||
if ( containsMatra ( gs, i ) && ! containsPreBaseMatra ( gs, i ) ) { | |||
for (int i = (c1 >= 0) ? c1 : 0; i < ng; i++) { | |||
if (containsMatra (gs, i) && ! containsPreBaseMatra (gs, i)) { | |||
c2 = i + 1; | |||
} else if ( containsOtherMark ( gs, i ) ) { | |||
} else if (containsOtherMark (gs, i)) { | |||
c2 = i; | |||
break; | |||
} | |||
} | |||
if ( c2 >= 0 ) { | |||
if (c2 >= 0) { | |||
return c2; | |||
} else if ( c1 >= 0 ) { | |||
} else if (c1 >= 0) { | |||
return c1; | |||
} else { | |||
return source; | |||
} | |||
} | |||
private static boolean containsReph ( GlyphSequence gs, int k ) { | |||
Boolean rphf = (Boolean) gs.getAssociation ( k ) . getPredication ( "rphf" ); | |||
return ( rphf != null ) ? rphf.booleanValue() : false; | |||
private static boolean containsReph (GlyphSequence gs, int k) { | |||
Boolean rphf = (Boolean) gs.getAssociation (k) . getPredication ("rphf"); | |||
return (rphf != null) ? rphf.booleanValue() : false; | |||
} | |||
private static boolean containsMatra ( GlyphSequence gs, int k ) { | |||
GlyphSequence.CharAssociation a = gs.getAssociation ( k ); | |||
int[] ca = gs.getCharacterArray ( false ); | |||
for ( int i = a.getStart(), e = a.getEnd(); i < e; i++ ) { | |||
if ( isM ( ca [ i ] ) ) { | |||
private static boolean containsMatra (GlyphSequence gs, int k) { | |||
GlyphSequence.CharAssociation a = gs.getAssociation (k); | |||
int[] ca = gs.getCharacterArray (false); | |||
for (int i = a.getStart(), e = a.getEnd(); i < e; i++) { | |||
if (isM (ca [ i ])) { | |||
return true; | |||
} | |||
} | |||
return false; | |||
} | |||
private static boolean containsOtherMark ( GlyphSequence gs, int k ) { | |||
GlyphSequence.CharAssociation a = gs.getAssociation ( k ); | |||
int[] ca = gs.getCharacterArray ( false ); | |||
for ( int i = a.getStart(), e = a.getEnd(); i < e; i++ ) { | |||
switch ( typeOf ( ca [ i ] ) ) { | |||
private static boolean containsOtherMark (GlyphSequence gs, int k) { | |||
GlyphSequence.CharAssociation a = gs.getAssociation (k); | |||
int[] ca = gs.getCharacterArray (false); | |||
for (int i = a.getStart(), e = a.getEnd(); i < e; i++) { | |||
switch (typeOf (ca [ i ])) { | |||
case C_T: // tone (e.g., udatta, anudatta) | |||
case C_A: // accent (e.g., acute, grave) | |||
case C_O: // other (e.g., candrabindu, anusvara, visarga, etc) | |||
@@ -191,18 +191,18 @@ public class GujaratiScriptProcessor extends IndicScriptProcessor { | |||
} | |||
private static class GujaratiSyllabizer extends DefaultSyllabizer { | |||
GujaratiSyllabizer ( String script, String language ) { | |||
super ( script, language ); | |||
GujaratiSyllabizer (String script, String language) { | |||
super (script, language); | |||
} | |||
@Override | |||
// | C ... | |||
protected int findStartOfSyllable ( int[] ca, int s, int e ) { | |||
if ( ( s < 0 ) || ( s >= e ) ) { | |||
protected int findStartOfSyllable (int[] ca, int s, int e) { | |||
if ((s < 0) || (s >= e)) { | |||
return -1; | |||
} else { | |||
while ( s < e ) { | |||
while (s < e) { | |||
int c = ca [ s ]; | |||
if ( isC ( c ) ) { | |||
if (isC (c)) { | |||
break; | |||
} else { | |||
s++; | |||
@@ -213,29 +213,29 @@ public class GujaratiScriptProcessor extends IndicScriptProcessor { | |||
} | |||
@Override | |||
// D* L? | ... | |||
protected int findEndOfSyllable ( int[] ca, int s, int e ) { | |||
if ( ( s < 0 ) || ( s >= e ) ) { | |||
protected int findEndOfSyllable (int[] ca, int s, int e) { | |||
if ((s < 0) || (s >= e)) { | |||
return -1; | |||
} else { | |||
int nd = 0; | |||
int nl = 0; | |||
int i; | |||
// consume dead consonants | |||
while ( ( i = isDeadConsonant ( ca, s, e ) ) > s ) { | |||
while ((i = isDeadConsonant (ca, s, e)) > s) { | |||
s = i; | |||
nd++; | |||
} | |||
// consume zero or one live consonant | |||
if ( ( i = isLiveConsonant ( ca, s, e ) ) > s ) { | |||
if ((i = isLiveConsonant (ca, s, e)) > s) { | |||
s = i; | |||
nl++; | |||
} | |||
return ( ( nd > 0 ) || ( nl > 0 ) ) ? s : -1; | |||
return ((nd > 0) || (nl > 0)) ? s : -1; | |||
} | |||
} | |||
// D := ( C N? H )? | |||
private int isDeadConsonant ( int[] ca, int s, int e ) { | |||
if ( s < 0 ) { | |||
private int isDeadConsonant (int[] ca, int s, int e) { | |||
if (s < 0) { | |||
return -1; | |||
} else { | |||
int c; | |||
@@ -244,9 +244,9 @@ public class GujaratiScriptProcessor extends IndicScriptProcessor { | |||
int nh = 0; | |||
do { | |||
// C | |||
if ( ( s + i ) < e ) { | |||
if ((s + i) < e) { | |||
c = ca [ s + i ]; | |||
if ( isC ( c ) ) { | |||
if (isC (c)) { | |||
i++; | |||
nc++; | |||
} else { | |||
@@ -254,29 +254,29 @@ public class GujaratiScriptProcessor extends IndicScriptProcessor { | |||
} | |||
} | |||
// N? | |||
if ( ( s + i ) < e ) { | |||
if ((s + i) < e) { | |||
c = ca [ s + 1 ]; | |||
if ( isN ( c ) ) { | |||
if (isN (c)) { | |||
i++; | |||
} | |||
} | |||
// H | |||
if ( ( s + i ) < e ) { | |||
if ((s + i) < e) { | |||
c = ca [ s + i ]; | |||
if ( isH ( c ) ) { | |||
if (isH (c)) { | |||
i++; | |||
nh++; | |||
} else { | |||
break; | |||
} | |||
} | |||
} while ( false ); | |||
return ( nc > 0 ) && ( nh > 0 ) ? s + i : -1; | |||
} while (false); | |||
return (nc > 0) && (nh > 0) ? s + i : -1; | |||
} | |||
} | |||
// L := ( (C|V) N? X* )?; where X = ( MATRA | ACCENT MARK | TONE MARK | OTHER MARK ) | |||
private int isLiveConsonant ( int[] ca, int s, int e ) { | |||
if ( s < 0 ) { | |||
private int isLiveConsonant (int[] ca, int s, int e) { | |||
if (s < 0) { | |||
return -1; | |||
} else { | |||
int c; | |||
@@ -286,12 +286,12 @@ public class GujaratiScriptProcessor extends IndicScriptProcessor { | |||
int nx = 0; | |||
do { | |||
// C | |||
if ( ( s + i ) < e ) { | |||
if ((s + i) < e) { | |||
c = ca [ s + i ]; | |||
if ( isC ( c ) ) { | |||
if (isC (c)) { | |||
i++; | |||
nc++; | |||
} else if ( isV ( c ) ) { | |||
} else if (isV (c)) { | |||
i++; | |||
nv++; | |||
} else { | |||
@@ -299,37 +299,37 @@ public class GujaratiScriptProcessor extends IndicScriptProcessor { | |||
} | |||
} | |||
// N? | |||
if ( ( s + i ) < e ) { | |||
if ((s + i) < e) { | |||
c = ca [ s + i ]; | |||
if ( isN ( c ) ) { | |||
if (isN (c)) { | |||
i++; | |||
} | |||
} | |||
// X* | |||
while ( ( s + i ) < e ) { | |||
while ((s + i) < e) { | |||
c = ca [ s + i ]; | |||
if ( isX ( c ) ) { | |||
if (isX (c)) { | |||
i++; | |||
nx++; | |||
} else { | |||
break; | |||
} | |||
} | |||
} while ( false ); | |||
} while (false); | |||
// if no X but has H, then ignore C|I | |||
if ( nx == 0 ) { | |||
if ( ( s + i ) < e ) { | |||
if (nx == 0) { | |||
if ((s + i) < e) { | |||
c = ca [ s + i ]; | |||
if ( isH ( c ) ) { | |||
if ( nc > 0 ) { | |||
if (isH (c)) { | |||
if (nc > 0) { | |||
nc--; | |||
} else if ( nv > 0 ) { | |||
} else if (nv > 0) { | |||
nv--; | |||
} | |||
} | |||
} | |||
} | |||
return ( ( nc > 0 ) || ( nv > 0 ) ) ? s + i : -1; | |||
return ((nc > 0) || (nv > 0)) ? s + i : -1; | |||
} | |||
} | |||
} | |||
@@ -486,18 +486,18 @@ public class GujaratiScriptProcessor extends IndicScriptProcessor { | |||
C_U // 0x0AFF // UNASSIGNED | |||
}; | |||
static int typeOf(int c) { | |||
if ( ( c >= ccaStart ) && ( c < ccaEnd ) ) { | |||
if ((c >= ccaStart) && (c < ccaEnd)) { | |||
return cca [ c - ccaStart ] & C_M_TYPE; | |||
} else { | |||
return C_U; | |||
} | |||
} | |||
static boolean isType(int c, int t) { | |||
return typeOf ( c ) == t; | |||
return typeOf (c) == t; | |||
} | |||
static boolean hasFlag(int c, int f) { | |||
if ( ( c >= ccaStart ) && ( c < ccaEnd ) ) { | |||
return ( cca [ c - ccaStart ] & f ) == f; | |||
if ((c >= ccaStart) && (c < ccaEnd)) { | |||
return (cca [ c - ccaStart ] & f) == f; | |||
} else { | |||
return false; | |||
} | |||
@@ -524,7 +524,7 @@ public class GujaratiScriptProcessor extends IndicScriptProcessor { | |||
return isType(c,C_M) && hasFlag(c,C_PRE); | |||
} | |||
static boolean isX(int c) { | |||
switch ( typeOf ( c ) ) { | |||
switch (typeOf (c)) { | |||
case C_M: // matra (combining vowel) | |||
case C_A: // accent mark | |||
case C_T: // tone mark |
@@ -43,8 +43,8 @@ public class GurmukhiScriptProcessor extends IndicScriptProcessor { | |||
/** logging instance */ | |||
private static final Log log = LogFactory.getLog(GurmukhiScriptProcessor.class); // CSOK: ConstantNameCheck | |||
GurmukhiScriptProcessor ( String script ) { | |||
super ( script ); | |||
GurmukhiScriptProcessor (String script) { | |||
super (script); | |||
} | |||
@Override | |||
@@ -54,12 +54,12 @@ public class GurmukhiScriptProcessor extends IndicScriptProcessor { | |||
@Override | |||
// find rightmost pre-base matra | |||
protected int findPreBaseMatra ( GlyphSequence gs ) { | |||
protected int findPreBaseMatra (GlyphSequence gs) { | |||
int ng = gs.getGlyphCount(); | |||
int lk = -1; | |||
for ( int i = ng; i > 0; i-- ) { | |||
for (int i = ng; i > 0; i--) { | |||
int k = i - 1; | |||
if ( containsPreBaseMatra ( gs, k ) ) { | |||
if (containsPreBaseMatra (gs, k)) { | |||
lk = k; | |||
break; | |||
} | |||
@@ -69,15 +69,15 @@ public class GurmukhiScriptProcessor extends IndicScriptProcessor { | |||
@Override | |||
// find leftmost pre-base matra target, starting from source | |||
protected int findPreBaseMatraTarget ( GlyphSequence gs, int source ) { | |||
protected int findPreBaseMatraTarget (GlyphSequence gs, int source) { | |||
int ng = gs.getGlyphCount(); | |||
int lk = -1; | |||
for ( int i = ( source < ng ) ? source : ng; i > 0; i-- ) { | |||
for (int i = (source < ng) ? source : ng; i > 0; i--) { | |||
int k = i - 1; | |||
if ( containsConsonant ( gs, k ) ) { | |||
if ( containsHalfConsonant ( gs, k ) ) { | |||
if (containsConsonant (gs, k)) { | |||
if (containsHalfConsonant (gs, k)) { | |||
lk = k; | |||
} else if ( lk == -1 ) { | |||
} else if (lk == -1) { | |||
lk = k; | |||
} else { | |||
break; | |||
@@ -87,39 +87,39 @@ public class GurmukhiScriptProcessor extends IndicScriptProcessor { | |||
return lk; | |||
} | |||
private static boolean containsPreBaseMatra ( GlyphSequence gs, int k ) { | |||
GlyphSequence.CharAssociation a = gs.getAssociation ( k ); | |||
int[] ca = gs.getCharacterArray ( false ); | |||
for ( int i = a.getStart(), e = a.getEnd(); i < e; i++ ) { | |||
if ( isPreM ( ca [ i ] ) ) { | |||
private static boolean containsPreBaseMatra (GlyphSequence gs, int k) { | |||
GlyphSequence.CharAssociation a = gs.getAssociation (k); | |||
int[] ca = gs.getCharacterArray (false); | |||
for (int i = a.getStart(), e = a.getEnd(); i < e; i++) { | |||
if (isPreM (ca [ i ])) { | |||
return true; | |||
} | |||
} | |||
return false; | |||
} | |||
private static boolean containsConsonant ( GlyphSequence gs, int k ) { | |||
GlyphSequence.CharAssociation a = gs.getAssociation ( k ); | |||
int[] ca = gs.getCharacterArray ( false ); | |||
for ( int i = a.getStart(), e = a.getEnd(); i < e; i++ ) { | |||
if ( isC ( ca [ i ] ) ) { | |||
private static boolean containsConsonant (GlyphSequence gs, int k) { | |||
GlyphSequence.CharAssociation a = gs.getAssociation (k); | |||
int[] ca = gs.getCharacterArray (false); | |||
for (int i = a.getStart(), e = a.getEnd(); i < e; i++) { | |||
if (isC (ca [ i ])) { | |||
return true; | |||
} | |||
} | |||
return false; | |||
} | |||
private static boolean containsHalfConsonant ( GlyphSequence gs, int k ) { | |||
Boolean half = (Boolean) gs.getAssociation ( k ) . getPredication ( "half" ); | |||
return ( half != null ) ? half.booleanValue() : false; | |||
private static boolean containsHalfConsonant (GlyphSequence gs, int k) { | |||
Boolean half = (Boolean) gs.getAssociation (k) . getPredication ("half"); | |||
return (half != null) ? half.booleanValue() : false; | |||
} | |||
@Override | |||
protected int findReph ( GlyphSequence gs ) { | |||
protected int findReph (GlyphSequence gs) { | |||
int ng = gs.getGlyphCount(); | |||
int li = -1; | |||
for ( int i = 0; i < ng; i++ ) { | |||
if ( containsReph ( gs, i ) ) { | |||
for (int i = 0; i < ng; i++) { | |||
if (containsReph (gs, i)) { | |||
li = i; | |||
break; | |||
} | |||
@@ -128,58 +128,58 @@ public class GurmukhiScriptProcessor extends IndicScriptProcessor { | |||
} | |||
@Override | |||
protected int findRephTarget ( GlyphSequence gs, int source ) { | |||
protected int findRephTarget (GlyphSequence gs, int source) { | |||
int ng = gs.getGlyphCount(); | |||
int c1 = -1; | |||
int c2 = -1; | |||
// first candidate target is after first non-half consonant | |||
for ( int i = 0; i < ng; i++ ) { | |||
if ( ( i != source ) && containsConsonant ( gs, i ) ) { | |||
if ( ! containsHalfConsonant ( gs, i ) ) { | |||
for (int i = 0; i < ng; i++) { | |||
if ((i != source) && containsConsonant (gs, i)) { | |||
if (! containsHalfConsonant (gs, i)) { | |||
c1 = i + 1; | |||
break; | |||
} | |||
} | |||
} | |||
// second candidate target is after last non-prebase matra after first candidate or before first syllable or vedic mark | |||
for ( int i = ( c1 >= 0 ) ? c1 : 0; i < ng; i++ ) { | |||
if ( containsMatra ( gs, i ) && ! containsPreBaseMatra ( gs, i ) ) { | |||
for (int i = (c1 >= 0) ? c1 : 0; i < ng; i++) { | |||
if (containsMatra (gs, i) && ! containsPreBaseMatra (gs, i)) { | |||
c2 = i + 1; | |||
} else if ( containsOtherMark ( gs, i ) ) { | |||
} else if (containsOtherMark (gs, i)) { | |||
c2 = i; | |||
break; | |||
} | |||
} | |||
if ( c2 >= 0 ) { | |||
if (c2 >= 0) { | |||
return c2; | |||
} else if ( c1 >= 0 ) { | |||
} else if (c1 >= 0) { | |||
return c1; | |||
} else { | |||
return source; | |||
} | |||
} | |||
private static boolean containsReph ( GlyphSequence gs, int k ) { | |||
Boolean rphf = (Boolean) gs.getAssociation ( k ) . getPredication ( "rphf" ); | |||
return ( rphf != null ) ? rphf.booleanValue() : false; | |||
private static boolean containsReph (GlyphSequence gs, int k) { | |||
Boolean rphf = (Boolean) gs.getAssociation (k) . getPredication ("rphf"); | |||
return (rphf != null) ? rphf.booleanValue() : false; | |||
} | |||
private static boolean containsMatra ( GlyphSequence gs, int k ) { | |||
GlyphSequence.CharAssociation a = gs.getAssociation ( k ); | |||
int[] ca = gs.getCharacterArray ( false ); | |||
for ( int i = a.getStart(), e = a.getEnd(); i < e; i++ ) { | |||
if ( isM ( ca [ i ] ) ) { | |||
private static boolean containsMatra (GlyphSequence gs, int k) { | |||
GlyphSequence.CharAssociation a = gs.getAssociation (k); | |||
int[] ca = gs.getCharacterArray (false); | |||
for (int i = a.getStart(), e = a.getEnd(); i < e; i++) { | |||
if (isM (ca [ i ])) { | |||
return true; | |||
} | |||
} | |||
return false; | |||
} | |||
private static boolean containsOtherMark ( GlyphSequence gs, int k ) { | |||
GlyphSequence.CharAssociation a = gs.getAssociation ( k ); | |||
int[] ca = gs.getCharacterArray ( false ); | |||
for ( int i = a.getStart(), e = a.getEnd(); i < e; i++ ) { | |||
switch ( typeOf ( ca [ i ] ) ) { | |||
private static boolean containsOtherMark (GlyphSequence gs, int k) { | |||
GlyphSequence.CharAssociation a = gs.getAssociation (k); | |||
int[] ca = gs.getCharacterArray (false); | |||
for (int i = a.getStart(), e = a.getEnd(); i < e; i++) { | |||
switch (typeOf (ca [ i ])) { | |||
case C_T: // tone (e.g., udatta, anudatta) | |||
case C_A: // accent (e.g., acute, grave) | |||
case C_O: // other (e.g., candrabindu, anusvara, visarga, etc) | |||
@@ -192,18 +192,18 @@ public class GurmukhiScriptProcessor extends IndicScriptProcessor { | |||
} | |||
private static class GurmukhiSyllabizer extends DefaultSyllabizer { | |||
GurmukhiSyllabizer ( String script, String language ) { | |||
super ( script, language ); | |||
GurmukhiSyllabizer (String script, String language) { | |||
super (script, language); | |||
} | |||
@Override | |||
// | C ... | |||
protected int findStartOfSyllable ( int[] ca, int s, int e ) { | |||
if ( ( s < 0 ) || ( s >= e ) ) { | |||
protected int findStartOfSyllable (int[] ca, int s, int e) { | |||
if ((s < 0) || (s >= e)) { | |||
return -1; | |||
} else { | |||
while ( s < e ) { | |||
while (s < e) { | |||
int c = ca [ s ]; | |||
if ( isC ( c ) ) { | |||
if (isC (c)) { | |||
break; | |||
} else { | |||
s++; | |||
@@ -214,29 +214,29 @@ public class GurmukhiScriptProcessor extends IndicScriptProcessor { | |||
} | |||
@Override | |||
// D* L? | ... | |||
protected int findEndOfSyllable ( int[] ca, int s, int e ) { | |||
if ( ( s < 0 ) || ( s >= e ) ) { | |||
protected int findEndOfSyllable (int[] ca, int s, int e) { | |||
if ((s < 0) || (s >= e)) { | |||
return -1; | |||
} else { | |||
int nd = 0; | |||
int nl = 0; | |||
int i; | |||
// consume dead consonants | |||
while ( ( i = isDeadConsonant ( ca, s, e ) ) > s ) { | |||
while ((i = isDeadConsonant (ca, s, e)) > s) { | |||
s = i; | |||
nd++; | |||
} | |||
// consume zero or one live consonant | |||
if ( ( i = isLiveConsonant ( ca, s, e ) ) > s ) { | |||
if ((i = isLiveConsonant (ca, s, e)) > s) { | |||
s = i; | |||
nl++; | |||
} | |||
return ( ( nd > 0 ) || ( nl > 0 ) ) ? s : -1; | |||
return ((nd > 0) || (nl > 0)) ? s : -1; | |||
} | |||
} | |||
// D := ( C N? H )? | |||
private int isDeadConsonant ( int[] ca, int s, int e ) { | |||
if ( s < 0 ) { | |||
private int isDeadConsonant (int[] ca, int s, int e) { | |||
if (s < 0) { | |||
return -1; | |||
} else { | |||
int c; | |||
@@ -245,9 +245,9 @@ public class GurmukhiScriptProcessor extends IndicScriptProcessor { | |||
int nh = 0; | |||
do { | |||
// C | |||
if ( ( s + i ) < e ) { | |||
if ((s + i) < e) { | |||
c = ca [ s + i ]; | |||
if ( isC ( c ) ) { | |||
if (isC (c)) { | |||
i++; | |||
nc++; | |||
} else { | |||
@@ -255,29 +255,29 @@ public class GurmukhiScriptProcessor extends IndicScriptProcessor { | |||
} | |||
} | |||
// N? | |||
if ( ( s + i ) < e ) { | |||
if ((s + i) < e) { | |||
c = ca [ s + 1 ]; | |||
if ( isN ( c ) ) { | |||
if (isN (c)) { | |||
i++; | |||
} | |||
} | |||
// H | |||
if ( ( s + i ) < e ) { | |||
if ((s + i) < e) { | |||
c = ca [ s + i ]; | |||
if ( isH ( c ) ) { | |||
if (isH (c)) { | |||
i++; | |||
nh++; | |||
} else { | |||
break; | |||
} | |||
} | |||
} while ( false ); | |||
return ( nc > 0 ) && ( nh > 0 ) ? s + i : -1; | |||
} while (false); | |||
return (nc > 0) && (nh > 0) ? s + i : -1; | |||
} | |||
} | |||
// L := ( (C|V) N? X* )?; where X = ( MATRA | ACCENT MARK | TONE MARK | OTHER MARK ) | |||
private int isLiveConsonant ( int[] ca, int s, int e ) { | |||
if ( s < 0 ) { | |||
private int isLiveConsonant (int[] ca, int s, int e) { | |||
if (s < 0) { | |||
return -1; | |||
} else { | |||
int c; | |||
@@ -287,12 +287,12 @@ public class GurmukhiScriptProcessor extends IndicScriptProcessor { | |||
int nx = 0; | |||
do { | |||
// C | |||
if ( ( s + i ) < e ) { | |||
if ((s + i) < e) { | |||
c = ca [ s + i ]; | |||
if ( isC ( c ) ) { | |||
if (isC (c)) { | |||
i++; | |||
nc++; | |||
} else if ( isV ( c ) ) { | |||
} else if (isV (c)) { | |||
i++; | |||
nv++; | |||
} else { | |||
@@ -300,37 +300,37 @@ public class GurmukhiScriptProcessor extends IndicScriptProcessor { | |||
} | |||
} | |||
// N? | |||
if ( ( s + i ) < e ) { | |||
if ((s + i) < e) { | |||
c = ca [ s + i ]; | |||
if ( isN ( c ) ) { | |||
if (isN (c)) { | |||
i++; | |||
} | |||
} | |||
// X* | |||
while ( ( s + i ) < e ) { | |||
while ((s + i) < e) { | |||
c = ca [ s + i ]; | |||
if ( isX ( c ) ) { | |||
if (isX (c)) { | |||
i++; | |||
nx++; | |||
} else { | |||
break; | |||
} | |||
} | |||
} while ( false ); | |||
} while (false); | |||
// if no X but has H, then ignore C|I | |||
if ( nx == 0 ) { | |||
if ( ( s + i ) < e ) { | |||
if (nx == 0) { | |||
if ((s + i) < e) { | |||
c = ca [ s + i ]; | |||
if ( isH ( c ) ) { | |||
if ( nc > 0 ) { | |||
if (isH (c)) { | |||
if (nc > 0) { | |||
nc--; | |||
} else if ( nv > 0 ) { | |||
} else if (nv > 0) { | |||
nv--; | |||
} | |||
} | |||
} | |||
} | |||
return ( ( nc > 0 ) || ( nv > 0 ) ) ? s + i : -1; | |||
return ((nc > 0) || (nv > 0)) ? s + i : -1; | |||
} | |||
} | |||
} | |||
@@ -487,18 +487,18 @@ public class GurmukhiScriptProcessor extends IndicScriptProcessor { | |||
C_U // 0x0A7F // UNASSIGNED | |||
}; | |||
static int typeOf(int c) { | |||
if ( ( c >= ccaStart ) && ( c < ccaEnd ) ) { | |||
if ((c >= ccaStart) && (c < ccaEnd)) { | |||
return cca [ c - ccaStart ] & C_M_TYPE; | |||
} else { | |||
return C_U; | |||
} | |||
} | |||
static boolean isType(int c, int t) { | |||
return typeOf ( c ) == t; | |||
return typeOf (c) == t; | |||
} | |||
static boolean hasFlag(int c, int f) { | |||
if ( ( c >= ccaStart ) && ( c < ccaEnd ) ) { | |||
return ( cca [ c - ccaStart ] & f ) == f; | |||
if ((c >= ccaStart) && (c < ccaEnd)) { | |||
return (cca [ c - ccaStart ] & f) == f; | |||
} else { | |||
return false; | |||
} | |||
@@ -525,7 +525,7 @@ public class GurmukhiScriptProcessor extends IndicScriptProcessor { | |||
return isType(c,C_M) && hasFlag(c,C_PRE); | |||
} | |||
static boolean isX(int c) { | |||
switch ( typeOf ( c ) ) { | |||
switch (typeOf (c)) { | |||
case C_M: // matra (combining vowel) | |||
case C_A: // accent mark | |||
case C_T: // tone mark | |||
@@ -543,8 +543,8 @@ public class GurmukhiScriptProcessor extends IndicScriptProcessor { | |||
} | |||
@Override | |||
public GlyphSequence reorderCombiningMarks ( GlyphDefinitionTable gdef, GlyphSequence gs, int[][] gpa, String script, String language ) { | |||
return super.reorderCombiningMarks ( gdef, gs, gpa, script, language ); | |||
public GlyphSequence reorderCombiningMarks (GlyphDefinitionTable gdef, GlyphSequence gs, int[][] gpa, String script, String language) { | |||
return super.reorderCombiningMarks (gdef, gs, gpa, script, language); | |||
} | |||
} |
@@ -105,15 +105,15 @@ public class IndicScriptProcessor extends DefaultScriptProcessor { | |||
private static class SubstitutionScriptContextTester implements ScriptContextTester { | |||
private static Map/*<String,GlyphContextTester>*/ testerMap = new HashMap/*<String,GlyphContextTester>*/(); | |||
public GlyphContextTester getTester ( String feature ) { | |||
return (GlyphContextTester) testerMap.get ( feature ); | |||
public GlyphContextTester getTester (String feature) { | |||
return (GlyphContextTester) testerMap.get (feature); | |||
} | |||
} | |||
private static class PositioningScriptContextTester implements ScriptContextTester { | |||
private static Map/*<String,GlyphContextTester>*/ testerMap = new HashMap/*<String,GlyphContextTester>*/(); | |||
public GlyphContextTester getTester ( String feature ) { | |||
return (GlyphContextTester) testerMap.get ( feature ); | |||
public GlyphContextTester getTester (String feature) { | |||
return (GlyphContextTester) testerMap.get (feature); | |||
} | |||
} | |||
@@ -122,28 +122,28 @@ public class IndicScriptProcessor extends DefaultScriptProcessor { | |||
* @param script tag | |||
* @return script processor instance | |||
*/ | |||
public static ScriptProcessor makeProcessor ( String script ) { | |||
switch ( CharScript.scriptCodeFromTag ( script ) ) { | |||
public static ScriptProcessor makeProcessor (String script) { | |||
switch (CharScript.scriptCodeFromTag (script)) { | |||
case CharScript.SCRIPT_DEVANAGARI: | |||
case CharScript.SCRIPT_DEVANAGARI_2: | |||
return new DevanagariScriptProcessor ( script ); | |||
return new DevanagariScriptProcessor (script); | |||
case CharScript.SCRIPT_GUJARATI: | |||
case CharScript.SCRIPT_GUJARATI_2: | |||
return new GujaratiScriptProcessor ( script ); | |||
return new GujaratiScriptProcessor (script); | |||
case CharScript.SCRIPT_GURMUKHI: | |||
case CharScript.SCRIPT_GURMUKHI_2: | |||
return new GurmukhiScriptProcessor ( script ); | |||
return new GurmukhiScriptProcessor (script); | |||
// [TBD] implement other script processors | |||
default: | |||
return new IndicScriptProcessor ( script ); | |||
return new IndicScriptProcessor (script); | |||
} | |||
} | |||
private final ScriptContextTester subContextTester; | |||
private final ScriptContextTester posContextTester; | |||
IndicScriptProcessor ( String script ) { | |||
super ( script ); | |||
IndicScriptProcessor (String script) { | |||
super (script); | |||
this.subContextTester = new SubstitutionScriptContextTester(); | |||
this.posContextTester = new PositioningScriptContextTester(); | |||
} | |||
@@ -180,38 +180,38 @@ public class IndicScriptProcessor extends DefaultScriptProcessor { | |||
/** {@inheritDoc} */ | |||
@Override | |||
public GlyphSequence substitute ( GlyphSequence gs, String script, String language, GlyphTable.UseSpec[] usa, ScriptContextTester sct ) { | |||
public GlyphSequence substitute (GlyphSequence gs, String script, String language, GlyphTable.UseSpec[] usa, ScriptContextTester sct) { | |||
assert usa != null; | |||
// 1. syllabize | |||
GlyphSequence[] sa = syllabize ( gs, script, language ); | |||
GlyphSequence[] sa = syllabize (gs, script, language); | |||
// 2. process each syllable | |||
for ( int i = 0, n = sa.length; i < n; i++ ) { | |||
for (int i = 0, n = sa.length; i < n; i++) { | |||
GlyphSequence s = sa [ i ]; | |||
// apply basic shaping subs | |||
for ( int j = 0, m = usa.length; j < m; j++ ) { | |||
for (int j = 0, m = usa.length; j < m; j++) { | |||
GlyphTable.UseSpec us = usa [ j ]; | |||
if ( isBasicShapingUse ( us ) ) { | |||
s.setPredications ( true ); | |||
s = us.substitute ( s, script, language, sct ); | |||
if (isBasicShapingUse (us)) { | |||
s.setPredications (true); | |||
s = us.substitute (s, script, language, sct); | |||
} | |||
} | |||
// reorder pre-base matra | |||
s = reorderPreBaseMatra ( s ); | |||
s = reorderPreBaseMatra (s); | |||
// reorder reph | |||
s = reorderReph ( s ); | |||
s = reorderReph (s); | |||
// apply presentation subs | |||
for ( int j = 0, m = usa.length; j < m; j++ ) { | |||
for (int j = 0, m = usa.length; j < m; j++) { | |||
GlyphTable.UseSpec us = usa [ j ]; | |||
if ( isPresentationUse ( us ) ) { | |||
s.setPredications ( true ); | |||
s = us.substitute ( s, script, language, sct ); | |||
if (isPresentationUse (us)) { | |||
s.setPredications (true); | |||
s = us.substitute (s, script, language, sct); | |||
} | |||
} | |||
// record result | |||
sa [ i ] = s; | |||
} | |||
// 3. return reassembled substituted syllables | |||
return unsyllabize ( gs, sa ); | |||
return unsyllabize (gs, sa); | |||
} | |||
/** | |||
@@ -222,12 +222,12 @@ public class IndicScriptProcessor extends DefaultScriptProcessor { | |||
return null; | |||
} | |||
private GlyphSequence[] syllabize ( GlyphSequence gs, String script, String language ) { | |||
return Syllabizer.getSyllabizer ( script, language, getSyllabizerClass() ) . syllabize ( gs ); | |||
private GlyphSequence[] syllabize (GlyphSequence gs, String script, String language) { | |||
return Syllabizer.getSyllabizer (script, language, getSyllabizerClass()) . syllabize (gs); | |||
} | |||
private GlyphSequence unsyllabize ( GlyphSequence gs, GlyphSequence[] sa ) { | |||
return GlyphSequence.join ( gs, sa ); | |||
private GlyphSequence unsyllabize (GlyphSequence gs, GlyphSequence[] sa) { | |||
return GlyphSequence.join (gs, sa); | |||
} | |||
private static Set<String> basicShapingFeatures; | |||
@@ -247,14 +247,14 @@ public class IndicScriptProcessor extends DefaultScriptProcessor { | |||
}; | |||
static { | |||
basicShapingFeatures = new HashSet<String>(); | |||
for ( String s : basicShapingFeatureStrings ) { | |||
basicShapingFeatures.add ( s ); | |||
for (String s : basicShapingFeatureStrings) { | |||
basicShapingFeatures.add (s); | |||
} | |||
} | |||
private boolean isBasicShapingUse ( GlyphTable.UseSpec us ) { | |||
private boolean isBasicShapingUse (GlyphTable.UseSpec us) { | |||
assert us != null; | |||
if ( basicShapingFeatures != null ) { | |||
return basicShapingFeatures.contains ( us.getFeature() ); | |||
if (basicShapingFeatures != null) { | |||
return basicShapingFeatures.contains (us.getFeature()); | |||
} else { | |||
return false; | |||
} | |||
@@ -271,26 +271,26 @@ public class IndicScriptProcessor extends DefaultScriptProcessor { | |||
}; | |||
static { | |||
presentationFeatures = new HashSet<String>(); | |||
for ( String s : presentationFeatureStrings ) { | |||
presentationFeatures.add ( s ); | |||
for (String s : presentationFeatureStrings) { | |||
presentationFeatures.add (s); | |||
} | |||
} | |||
private boolean isPresentationUse ( GlyphTable.UseSpec us ) { | |||
private boolean isPresentationUse (GlyphTable.UseSpec us) { | |||
assert us != null; | |||
if ( presentationFeatures != null ) { | |||
return presentationFeatures.contains ( us.getFeature() ); | |||
if (presentationFeatures != null) { | |||
return presentationFeatures.contains (us.getFeature()); | |||
} else { | |||
return false; | |||
} | |||
} | |||
private GlyphSequence reorderPreBaseMatra ( GlyphSequence gs ) { | |||
private GlyphSequence reorderPreBaseMatra (GlyphSequence gs) { | |||
int source; | |||
if ( ( source = findPreBaseMatra ( gs ) ) >= 0 ) { | |||
if ((source = findPreBaseMatra (gs)) >= 0) { | |||
int target; | |||
if ( ( target = findPreBaseMatraTarget ( gs, source ) ) >= 0 ) { | |||
if ( target != source ) { | |||
gs = reorder ( gs, source, target ); | |||
if ((target = findPreBaseMatraTarget (gs, source)) >= 0) { | |||
if (target != source) { | |||
gs = reorder (gs, source, target); | |||
} | |||
} | |||
} | |||
@@ -302,7 +302,7 @@ public class IndicScriptProcessor extends DefaultScriptProcessor { | |||
* @param gs input sequence | |||
* @return index of pre-base matra or -1 if not found | |||
*/ | |||
protected int findPreBaseMatra ( GlyphSequence gs ) { | |||
protected int findPreBaseMatra (GlyphSequence gs) { | |||
return -1; | |||
} | |||
@@ -312,17 +312,17 @@ public class IndicScriptProcessor extends DefaultScriptProcessor { | |||
* @param source index of pre-base matra | |||
* @return index of pre-base matra target or -1 | |||
*/ | |||
protected int findPreBaseMatraTarget ( GlyphSequence gs, int source ) { | |||
protected int findPreBaseMatraTarget (GlyphSequence gs, int source) { | |||
return -1; | |||
} | |||
private GlyphSequence reorderReph ( GlyphSequence gs ) { | |||
private GlyphSequence reorderReph (GlyphSequence gs) { | |||
int source; | |||
if ( ( source = findReph ( gs ) ) >= 0 ) { | |||
if ((source = findReph (gs)) >= 0) { | |||
int target; | |||
if ( ( target = findRephTarget ( gs, source ) ) >= 0 ) { | |||
if ( target != source ) { | |||
gs = reorder ( gs, source, target ); | |||
if ((target = findRephTarget (gs, source)) >= 0) { | |||
if (target != source) { | |||
gs = reorder (gs, source, target); | |||
} | |||
} | |||
} | |||
@@ -334,7 +334,7 @@ public class IndicScriptProcessor extends DefaultScriptProcessor { | |||
* @param gs input sequence | |||
* @return index of reph or -1 if not found | |||
*/ | |||
protected int findReph ( GlyphSequence gs ) { | |||
protected int findReph (GlyphSequence gs) { | |||
return -1; | |||
} | |||
@@ -344,18 +344,18 @@ public class IndicScriptProcessor extends DefaultScriptProcessor { | |||
* @param source index of reph | |||
* @return index of reph target or -1 | |||
*/ | |||
protected int findRephTarget ( GlyphSequence gs, int source ) { | |||
protected int findRephTarget (GlyphSequence gs, int source) { | |||
return -1; | |||
} | |||
private GlyphSequence reorder ( GlyphSequence gs, int source, int target ) { | |||
return GlyphSequence.reorder ( gs, source, 1, target ); | |||
private GlyphSequence reorder (GlyphSequence gs, int source, int target) { | |||
return GlyphSequence.reorder (gs, source, 1, target); | |||
} | |||
/** {@inheritDoc} */ | |||
@Override | |||
public boolean position ( GlyphSequence gs, String script, String language, int fontSize, GlyphTable.UseSpec[] usa, int[] widths, int[][] adjustments, ScriptContextTester sct ) { | |||
boolean adjusted = super.position ( gs, script, language, fontSize, usa, widths, adjustments, sct ); | |||
public boolean position (GlyphSequence gs, String script, String language, int fontSize, GlyphTable.UseSpec[] usa, int[] widths, int[][] adjustments, ScriptContextTester sct) { | |||
boolean adjusted = super.position (gs, script, language, fontSize, usa, widths, adjustments, sct); | |||
return adjusted; | |||
} | |||
@@ -363,7 +363,7 @@ public class IndicScriptProcessor extends DefaultScriptProcessor { | |||
protected abstract static class Syllabizer implements Comparable { | |||
private String script; | |||
private String language; | |||
Syllabizer ( String script, String language ) { | |||
Syllabizer (String script, String language) { | |||
this.script = script; | |||
this.language = language; | |||
} | |||
@@ -373,21 +373,21 @@ public class IndicScriptProcessor extends DefaultScriptProcessor { | |||
* @param gs input glyph sequence | |||
* @return segmented syllabic glyph sequences | |||
*/ | |||
abstract GlyphSequence[] syllabize ( GlyphSequence gs ); | |||
abstract GlyphSequence[] syllabize (GlyphSequence gs); | |||
/** {@inheritDoc} */ | |||
public int hashCode() { | |||
int hc = 0; | |||
hc = 7 * hc + ( hc ^ script.hashCode() ); | |||
hc = 11 * hc + ( hc ^ language.hashCode() ); | |||
hc = 7 * hc + (hc ^ script.hashCode()); | |||
hc = 11 * hc + (hc ^ language.hashCode()); | |||
return hc; | |||
} | |||
/** {@inheritDoc} */ | |||
public boolean equals ( Object o ) { | |||
if ( o instanceof Syllabizer ) { | |||
public boolean equals (Object o) { | |||
if (o instanceof Syllabizer) { | |||
Syllabizer s = (Syllabizer) o; | |||
if ( ! s.script.equals ( script ) ) { | |||
if (! s.script.equals (script)) { | |||
return false; | |||
} else if ( ! s.language.equals ( language ) ) { | |||
} else if (! s.language.equals (language)) { | |||
return false; | |||
} else { | |||
return true; | |||
@@ -397,12 +397,12 @@ public class IndicScriptProcessor extends DefaultScriptProcessor { | |||
} | |||
} | |||
/** {@inheritDoc} */ | |||
public int compareTo ( Object o ) { | |||
public int compareTo (Object o) { | |||
int d; | |||
if ( o instanceof Syllabizer ) { | |||
if (o instanceof Syllabizer) { | |||
Syllabizer s = (Syllabizer) o; | |||
if ( ( d = script.compareTo ( s.script ) ) == 0 ) { | |||
d = language.compareTo ( s.language ); | |||
if ((d = script.compareTo (s.script)) == 0) { | |||
d = language.compareTo (s.language); | |||
} | |||
} else { | |||
d = -1; | |||
@@ -410,32 +410,32 @@ public class IndicScriptProcessor extends DefaultScriptProcessor { | |||
return d; | |||
} | |||
private static Map<String,Syllabizer> syllabizers = new HashMap<String,Syllabizer>(); | |||
static Syllabizer getSyllabizer ( String script, String language, Class<? extends Syllabizer> syllabizerClass ) { | |||
String sid = makeSyllabizerId ( script, language ); | |||
Syllabizer s = syllabizers.get ( sid ); | |||
if ( s == null ) { | |||
if ( ( s = makeSyllabizer ( script, language, syllabizerClass ) ) == null ) { | |||
s = new DefaultSyllabizer ( script, language ); | |||
static Syllabizer getSyllabizer (String script, String language, Class<? extends Syllabizer> syllabizerClass) { | |||
String sid = makeSyllabizerId (script, language); | |||
Syllabizer s = syllabizers.get (sid); | |||
if (s == null) { | |||
if ((s = makeSyllabizer (script, language, syllabizerClass)) == null) { | |||
s = new DefaultSyllabizer (script, language); | |||
} | |||
syllabizers.put ( sid, s ); | |||
syllabizers.put (sid, s); | |||
} | |||
return s; | |||
} | |||
static String makeSyllabizerId ( String script, String language ) { | |||
static String makeSyllabizerId (String script, String language) { | |||
return script + ":" + language; | |||
} | |||
static Syllabizer makeSyllabizer ( String script, String language, Class<? extends Syllabizer> syllabizerClass ) { | |||
static Syllabizer makeSyllabizer (String script, String language, Class<? extends Syllabizer> syllabizerClass) { | |||
Syllabizer s; | |||
try { | |||
Constructor<? extends Syllabizer> cf = syllabizerClass.getDeclaredConstructor ( new Class[] { String.class, String.class } ); | |||
s = (Syllabizer) cf.newInstance ( script, language ); | |||
} catch ( NoSuchMethodException e ) { | |||
Constructor<? extends Syllabizer> cf = syllabizerClass.getDeclaredConstructor (new Class[] { String.class, String.class }); | |||
s = (Syllabizer) cf.newInstance (script, language); | |||
} catch (NoSuchMethodException e) { | |||
s = null; | |||
} catch ( InstantiationException e ) { | |||
} catch (InstantiationException e) { | |||
s = null; | |||
} catch ( IllegalAccessException e ) { | |||
} catch (IllegalAccessException e) { | |||
s = null; | |||
} catch ( InvocationTargetException e ) { | |||
} catch (InvocationTargetException e) { | |||
s = null; | |||
} | |||
return s; | |||
@@ -444,18 +444,18 @@ public class IndicScriptProcessor extends DefaultScriptProcessor { | |||
/** Default syllabizer. */ | |||
protected static class DefaultSyllabizer extends Syllabizer { | |||
DefaultSyllabizer ( String script, String language ) { | |||
super ( script, language ); | |||
DefaultSyllabizer (String script, String language) { | |||
super (script, language); | |||
} | |||
/** {@inheritDoc} */ | |||
@Override | |||
GlyphSequence[] syllabize ( GlyphSequence gs ) { | |||
int[] ca = gs.getCharacterArray ( false ); | |||
GlyphSequence[] syllabize (GlyphSequence gs) { | |||
int[] ca = gs.getCharacterArray (false); | |||
int nc = gs.getCharacterCount(); | |||
if ( nc == 0 ) { | |||
if (nc == 0) { | |||
return new GlyphSequence[] { gs }; | |||
} else { | |||
return segmentize ( gs, segmentize ( ca, nc ) ); | |||
return segmentize (gs, segmentize (ca, nc)); | |||
} | |||
} | |||
/** | |||
@@ -464,30 +464,30 @@ public class IndicScriptProcessor extends DefaultScriptProcessor { | |||
* @param nc number of characters in sequence | |||
* @return array of syllable segments | |||
*/ | |||
protected Segment[] segmentize ( int[] ca, int nc ) { | |||
Vector<Segment> sv = new Vector<Segment> ( nc ); | |||
for ( int s = 0, e = nc; s < e; ) { | |||
protected Segment[] segmentize (int[] ca, int nc) { | |||
Vector<Segment> sv = new Vector<Segment> (nc); | |||
for (int s = 0, e = nc; s < e; ) { | |||
int i; | |||
if ( ( i = findStartOfSyllable ( ca, s, e ) ) > s ) { | |||
if ((i = findStartOfSyllable (ca, s, e)) > s) { | |||
// from s to i is non-syllable segment | |||
sv.add ( new Segment ( s, i, Segment.OTHER ) ); | |||
sv.add (new Segment (s, i, Segment.OTHER)); | |||
s = i; // move s to start of syllable | |||
} else if ( i > s ) { | |||
} else if (i > s) { | |||
// from s to e is non-syllable segment | |||
sv.add ( new Segment ( s, e, Segment.OTHER ) ); | |||
sv.add (new Segment (s, e, Segment.OTHER)); | |||
s = e; // move s to end of input sequence | |||
} | |||
if ( ( i = findEndOfSyllable ( ca, s, e ) ) > s ) { | |||
if ((i = findEndOfSyllable (ca, s, e)) > s) { | |||
// from s to i is syllable segment | |||
sv.add ( new Segment ( s, i, Segment.SYLLABLE ) ); | |||
sv.add (new Segment (s, i, Segment.SYLLABLE)); | |||
s = i; // move s to end of syllable | |||
} else { | |||
// from s to e is non-syllable segment | |||
sv.add ( new Segment ( s, e, Segment.OTHER ) ); | |||
sv.add (new Segment (s, e, Segment.OTHER)); | |||
s = e; // move s to end of input sequence | |||
} | |||
} | |||
return sv.toArray ( new Segment [ sv.size() ] ); | |||
return sv.toArray (new Segment [ sv.size() ]); | |||
} | |||
/** | |||
* Construct array of glyph sequences from original glyph sequence and segment array. | |||
@@ -495,28 +495,28 @@ public class IndicScriptProcessor extends DefaultScriptProcessor { | |||
* @param sa segment array | |||
* @return array of glyph sequences each belonging to an (ordered) segment in SA | |||
*/ | |||
protected GlyphSequence[] segmentize ( GlyphSequence gs, Segment[] sa ) { | |||
protected GlyphSequence[] segmentize (GlyphSequence gs, Segment[] sa) { | |||
int ng = gs.getGlyphCount(); | |||
int[] ga = gs.getGlyphArray ( false ); | |||
GlyphSequence.CharAssociation[] aa = gs.getAssociations ( 0, -1 ); | |||
int[] ga = gs.getGlyphArray (false); | |||
GlyphSequence.CharAssociation[] aa = gs.getAssociations (0, -1); | |||
Vector<GlyphSequence> nsv = new Vector<GlyphSequence>(); | |||
for ( int i = 0, ns = sa.length; i < ns; i++ ) { | |||
for (int i = 0, ns = sa.length; i < ns; i++) { | |||
Segment s = sa [ i ]; | |||
Vector<Integer> ngv = new Vector<Integer> ( ng ); | |||
Vector<GlyphSequence.CharAssociation> nav = new Vector<GlyphSequence.CharAssociation> ( ng ); | |||
for ( int j = 0; j < ng; j++ ) { | |||
Vector<Integer> ngv = new Vector<Integer> (ng); | |||
Vector<GlyphSequence.CharAssociation> nav = new Vector<GlyphSequence.CharAssociation> (ng); | |||
for (int j = 0; j < ng; j++) { | |||
GlyphSequence.CharAssociation ca = aa [ j ]; | |||
if ( ca.contained ( s.getOffset(), s.getCount() ) ) { | |||
ngv.add ( ga [ j ] ); | |||
nav.add ( ca ); | |||
if (ca.contained (s.getOffset(), s.getCount())) { | |||
ngv.add (ga [ j ]); | |||
nav.add (ca); | |||
} | |||
} | |||
if ( ngv.size() > 0 ) { | |||
nsv.add ( new GlyphSequence ( gs, null, toIntArray ( ngv ), null, null, nav.toArray ( new GlyphSequence.CharAssociation [ nav.size() ] ), null ) ); | |||
if (ngv.size() > 0) { | |||
nsv.add (new GlyphSequence (gs, null, toIntArray (ngv), null, null, nav.toArray (new GlyphSequence.CharAssociation [ nav.size() ]), null)); | |||
} | |||
} | |||
if ( nsv.size() > 0 ) { | |||
return nsv.toArray ( new GlyphSequence [ nsv.size() ] ); | |||
if (nsv.size() > 0) { | |||
return nsv.toArray (new GlyphSequence [ nsv.size() ]); | |||
} else { | |||
return new GlyphSequence[] { gs }; | |||
} | |||
@@ -528,7 +528,7 @@ public class IndicScriptProcessor extends DefaultScriptProcessor { | |||
* @param e end index | |||
* @return index of start or E if no start found | |||
*/ | |||
protected int findStartOfSyllable ( int[] ca, int s, int e ) { | |||
protected int findStartOfSyllable (int[] ca, int s, int e) { | |||
return e; | |||
} | |||
/** | |||
@@ -538,14 +538,14 @@ public class IndicScriptProcessor extends DefaultScriptProcessor { | |||
* @param e end index | |||
* @return index of start or S if no end found | |||
*/ | |||
protected int findEndOfSyllable ( int[] ca, int s, int e ) { | |||
protected int findEndOfSyllable (int[] ca, int s, int e) { | |||
return s; | |||
} | |||
private static int[] toIntArray ( Vector<Integer> iv ) { | |||
private static int[] toIntArray (Vector<Integer> iv) { | |||
int ni = iv.size(); | |||
int[] ia = new int [ iv.size() ]; | |||
for ( int i = 0, n = ni; i < n; i++ ) { | |||
ia [ i ] = (int) iv.get ( i ); | |||
for (int i = 0, n = ni; i < n; i++) { | |||
ia [ i ] = (int) iv.get (i); | |||
} | |||
return ia; | |||
} | |||
@@ -561,7 +561,7 @@ public class IndicScriptProcessor extends DefaultScriptProcessor { | |||
private int end; | |||
private int type; | |||
Segment ( int start, int end, int type ) { | |||
Segment (int start, int end, int type) { | |||
this.start = start; | |||
this.end = end; | |||
this.type = type; |
@@ -55,9 +55,9 @@ public abstract class ScriptProcessor { | |||
* Instantiate a script processor. | |||
* @param script a script identifier | |||
*/ | |||
protected ScriptProcessor ( String script ) { | |||
if ( ( script == null ) || ( script.length() == 0 ) ) { | |||
throw new IllegalArgumentException ( "script must be non-empty string" ); | |||
protected ScriptProcessor (String script) { | |||
if ((script == null) || (script.length() == 0)) { | |||
throw new IllegalArgumentException ("script must be non-empty string"); | |||
} else { | |||
this.script = script; | |||
this.assembledLookups = new HashMap/*<AssembledLookupsKey,GlyphTable.UseSpec[]>*/(); | |||
@@ -98,8 +98,8 @@ public abstract class ScriptProcessor { | |||
* @param lookups a mapping from lookup specifications to glyph subtables to use for substitution processing | |||
* @return the substituted (output) glyph sequence | |||
*/ | |||
public final GlyphSequence substitute ( GlyphSubstitutionTable gsub, GlyphSequence gs, String script, String language, Map/*<LookupSpec,List<LookupTable>>>*/ lookups ) { | |||
return substitute ( gs, script, language, assembleLookups ( gsub, getSubstitutionFeatures(), lookups ), getSubstitutionContextTester() ); | |||
public final GlyphSequence substitute (GlyphSubstitutionTable gsub, GlyphSequence gs, String script, String language, Map/*<LookupSpec,List<LookupTable>>>*/ lookups) { | |||
return substitute (gs, script, language, assembleLookups (gsub, getSubstitutionFeatures(), lookups), getSubstitutionContextTester()); | |||
} | |||
/** | |||
@@ -111,11 +111,11 @@ public abstract class ScriptProcessor { | |||
* @param sct a script specific context tester (or null) | |||
* @return the substituted (output) glyph sequence | |||
*/ | |||
public GlyphSequence substitute ( GlyphSequence gs, String script, String language, GlyphTable.UseSpec[] usa, ScriptContextTester sct ) { | |||
public GlyphSequence substitute (GlyphSequence gs, String script, String language, GlyphTable.UseSpec[] usa, ScriptContextTester sct) { | |||
assert usa != null; | |||
for ( int i = 0, n = usa.length; i < n; i++ ) { | |||
for (int i = 0, n = usa.length; i < n; i++) { | |||
GlyphTable.UseSpec us = usa [ i ]; | |||
gs = us.substitute ( gs, script, language, sct ); | |||
gs = us.substitute (gs, script, language, sct); | |||
} | |||
return gs; | |||
} | |||
@@ -132,7 +132,7 @@ public abstract class ScriptProcessor { | |||
* @param language a language identifier | |||
* @return the reordered (output) glyph sequence | |||
*/ | |||
public GlyphSequence reorderCombiningMarks ( GlyphDefinitionTable gdef, GlyphSequence gs, int[][] gpa, String script, String language ) { | |||
public GlyphSequence reorderCombiningMarks (GlyphDefinitionTable gdef, GlyphSequence gs, int[][] gpa, String script, String language) { | |||
return gs; | |||
} | |||
@@ -169,8 +169,8 @@ public abstract class ScriptProcessor { | |||
* with one 4-tuple for each element of glyph sequence | |||
* @return true if some adjustment is not zero; otherwise, false | |||
*/ | |||
public final boolean position ( GlyphPositioningTable gpos, GlyphSequence gs, String script, String language, int fontSize, Map/*<LookupSpec,List<LookupTable>>*/ lookups, int[] widths, int[][] adjustments ) { | |||
return position ( gs, script, language, fontSize, assembleLookups ( gpos, getPositioningFeatures(), lookups ), widths, adjustments, getPositioningContextTester() ); | |||
public final boolean position (GlyphPositioningTable gpos, GlyphSequence gs, String script, String language, int fontSize, Map/*<LookupSpec,List<LookupTable>>*/ lookups, int[] widths, int[][] adjustments) { | |||
return position (gs, script, language, fontSize, assembleLookups (gpos, getPositioningFeatures(), lookups), widths, adjustments, getPositioningContextTester()); | |||
} | |||
/** | |||
@@ -186,12 +186,12 @@ public abstract class ScriptProcessor { | |||
* @param sct a script specific context tester (or null) | |||
* @return true if some adjustment is not zero; otherwise, false | |||
*/ | |||
public boolean position ( GlyphSequence gs, String script, String language, int fontSize, GlyphTable.UseSpec[] usa, int[] widths, int[][] adjustments, ScriptContextTester sct ) { | |||
public boolean position (GlyphSequence gs, String script, String language, int fontSize, GlyphTable.UseSpec[] usa, int[] widths, int[][] adjustments, ScriptContextTester sct) { | |||
assert usa != null; | |||
boolean adjusted = false; | |||
for ( int i = 0, n = usa.length; i < n; i++ ) { | |||
for (int i = 0, n = usa.length; i < n; i++) { | |||
GlyphTable.UseSpec us = usa [ i ]; | |||
if ( us.position ( gs, script, language, fontSize, widths, adjustments, sct ) ) { | |||
if (us.position (gs, script, language, fontSize, widths, adjustments, sct)) { | |||
adjusted = true; | |||
} | |||
} | |||
@@ -206,22 +206,22 @@ public abstract class ScriptProcessor { | |||
* @param lookups a mapping from lookup specifications to lists of look tables from which to select lookup tables according to the specified features | |||
* @return ordered array of assembled lookup table use specifications | |||
*/ | |||
public final GlyphTable.UseSpec[] assembleLookups ( GlyphTable table, String[] features, Map/*<LookupSpec,List<LookupTable>>*/ lookups ) { | |||
AssembledLookupsKey key = new AssembledLookupsKey ( table, features, lookups ); | |||
public final GlyphTable.UseSpec[] assembleLookups (GlyphTable table, String[] features, Map/*<LookupSpec,List<LookupTable>>*/ lookups) { | |||
AssembledLookupsKey key = new AssembledLookupsKey (table, features, lookups); | |||
GlyphTable.UseSpec[] usa; | |||
if ( ( usa = assembledLookupsGet ( key ) ) != null ) { | |||
if ((usa = assembledLookupsGet (key)) != null) { | |||
return usa; | |||
} else { | |||
return assembledLookupsPut ( key, table.assembleLookups ( features, lookups ) ); | |||
return assembledLookupsPut (key, table.assembleLookups (features, lookups)); | |||
} | |||
} | |||
private GlyphTable.UseSpec[] assembledLookupsGet ( AssembledLookupsKey key ) { | |||
return (GlyphTable.UseSpec[]) assembledLookups.get ( key ); | |||
private GlyphTable.UseSpec[] assembledLookupsGet (AssembledLookupsKey key) { | |||
return (GlyphTable.UseSpec[]) assembledLookups.get (key); | |||
} | |||
private GlyphTable.UseSpec[] assembledLookupsPut ( AssembledLookupsKey key, GlyphTable.UseSpec[] usa ) { | |||
assembledLookups.put ( key, usa ); | |||
private GlyphTable.UseSpec[] assembledLookupsPut (AssembledLookupsKey key, GlyphTable.UseSpec[] usa) { | |||
assembledLookups.put (key, usa); | |||
return usa; | |||
} | |||
@@ -230,25 +230,25 @@ public abstract class ScriptProcessor { | |||
* @param script a script identifier | |||
* @return a script processor instance or null if none found | |||
*/ | |||
public static synchronized ScriptProcessor getInstance ( String script ) { | |||
public static synchronized ScriptProcessor getInstance (String script) { | |||
ScriptProcessor sp = null; | |||
assert processors != null; | |||
if ( ( sp = processors.get ( script ) ) == null ) { | |||
processors.put ( script, sp = createProcessor ( script ) ); | |||
if ((sp = processors.get (script)) == null) { | |||
processors.put (script, sp = createProcessor (script)); | |||
} | |||
return sp; | |||
} | |||
// [TBD] - rework to provide more configurable binding between script name and script processor constructor | |||
private static ScriptProcessor createProcessor ( String script ) { | |||
private static ScriptProcessor createProcessor (String script) { | |||
ScriptProcessor sp = null; | |||
int sc = CharScript.scriptCodeFromTag ( script ); | |||
if ( sc == CharScript.SCRIPT_ARABIC ) { | |||
sp = new ArabicScriptProcessor ( script ); | |||
} else if ( CharScript.isIndicScript ( sc ) ) { | |||
sp = IndicScriptProcessor.makeProcessor ( script ); | |||
int sc = CharScript.scriptCodeFromTag (script); | |||
if (sc == CharScript.SCRIPT_ARABIC) { | |||
sp = new ArabicScriptProcessor (script); | |||
} else if (CharScript.isIndicScript (sc)) { | |||
sp = IndicScriptProcessor.makeProcessor (script); | |||
} else { | |||
sp = new DefaultScriptProcessor ( script ); | |||
sp = new DefaultScriptProcessor (script); | |||
} | |||
return sp; | |||
} | |||
@@ -259,7 +259,7 @@ public abstract class ScriptProcessor { | |||
private final String[] features; | |||
private final Map/*<LookupSpec,List<LookupTable>>*/ lookups; | |||
AssembledLookupsKey ( GlyphTable table, String[] features, Map/*<LookupSpec,List<LookupTable>>*/ lookups ) { | |||
AssembledLookupsKey (GlyphTable table, String[] features, Map/*<LookupSpec,List<LookupTable>>*/ lookups) { | |||
this.table = table; | |||
this.features = features; | |||
this.lookups = lookups; | |||
@@ -268,21 +268,21 @@ public abstract class ScriptProcessor { | |||
/** {@inheritDoc} */ | |||
public int hashCode() { | |||
int hc = 0; | |||
hc = 7 * hc + ( hc ^ table.hashCode() ); | |||
hc = 11 * hc + ( hc ^ Arrays.hashCode ( features ) ); | |||
hc = 17 * hc + ( hc ^ lookups.hashCode() ); | |||
hc = 7 * hc + (hc ^ table.hashCode()); | |||
hc = 11 * hc + (hc ^ Arrays.hashCode (features)); | |||
hc = 17 * hc + (hc ^ lookups.hashCode()); | |||
return hc; | |||
} | |||
/** {@inheritDoc} */ | |||
public boolean equals ( Object o ) { | |||
if ( o instanceof AssembledLookupsKey ) { | |||
public boolean equals (Object o) { | |||
if (o instanceof AssembledLookupsKey) { | |||
AssembledLookupsKey k = (AssembledLookupsKey) o; | |||
if ( ! table.equals ( k.table ) ) { | |||
if (! table.equals (k.table)) { | |||
return false; | |||
} else if ( ! Arrays.equals ( features, k.features ) ) { | |||
} else if (! Arrays.equals (features, k.features)) { | |||
return false; | |||
} else if ( ! lookups.equals ( k.lookups ) ) { | |||
} else if (! lookups.equals (k.lookups)) { | |||
return false; | |||
} else { | |||
return true; |
@@ -36,10 +36,10 @@ public final class CharMirror { | |||
* @param s a string whose characters are to be mirrored | |||
* @return the resulting string | |||
*/ | |||
public static String mirror ( String s ) { | |||
StringBuffer sb = new StringBuffer ( s ); | |||
for ( int i = 0, n = sb.length(); i < n; i++ ) { | |||
sb.setCharAt ( i, (char) mirror ( sb.charAt ( i ) ) ); | |||
public static String mirror (String s) { | |||
StringBuffer sb = new StringBuffer (s); | |||
for (int i = 0, n = sb.length(); i < n; i++) { | |||
sb.setCharAt (i, (char) mirror (sb.charAt (i))); | |||
} | |||
return sb.toString(); | |||
} | |||
@@ -704,9 +704,9 @@ public final class CharMirror { | |||
0xFF62 | |||
}; | |||
private static int mirror ( int c ) { | |||
int i = Arrays.binarySearch ( mirroredCharacters, c ); | |||
if ( i < 0 ) { | |||
private static int mirror (int c) { | |||
int i = Arrays.binarySearch (mirroredCharacters, c); | |||
if (i < 0) { | |||
return c; | |||
} else { | |||
return mirroredCharactersMapping [ i ]; |
@@ -143,24 +143,24 @@ public final class CharScript { | |||
* @param c a character represented as a unicode scalar value | |||
* @return true if character is punctuation | |||
*/ | |||
public static boolean isPunctuation ( int c ) { | |||
if ( ( c >= 0x0021 ) && ( c <= 0x002F ) ) { // basic latin punctuation | |||
public static boolean isPunctuation (int c) { | |||
if ((c >= 0x0021) && (c <= 0x002F)) { // basic latin punctuation | |||
return true; | |||
} else if ( ( c >= 0x003A ) && ( c <= 0x0040 ) ) { // basic latin punctuation | |||
} else if ((c >= 0x003A) && (c <= 0x0040)) { // basic latin punctuation | |||
return true; | |||
} else if ( ( c >= 0x005F ) && ( c <= 0x0060 ) ) { // basic latin punctuation | |||
} else if ((c >= 0x005F) && (c <= 0x0060)) { // basic latin punctuation | |||
return true; | |||
} else if ( ( c >= 0x007E ) && ( c <= 0x007E ) ) { // basic latin punctuation | |||
} else if ((c >= 0x007E) && (c <= 0x007E)) { // basic latin punctuation | |||
return true; | |||
} else if ( ( c >= 0x007E ) && ( c <= 0x007E ) ) { // basic latin punctuation | |||
} else if ((c >= 0x007E) && (c <= 0x007E)) { // basic latin punctuation | |||
return true; | |||
} else if ( ( c >= 0x00A1 ) && ( c <= 0x00BF ) ) { // latin supplement punctuation | |||
} else if ((c >= 0x00A1) && (c <= 0x00BF)) { // latin supplement punctuation | |||
return true; | |||
} else if ( ( c >= 0x00D7 ) && ( c <= 0x00D7 ) ) { // latin supplement punctuation | |||
} else if ((c >= 0x00D7) && (c <= 0x00D7)) { // latin supplement punctuation | |||
return true; | |||
} else if ( ( c >= 0x00F7 ) && ( c <= 0x00F7 ) ) { // latin supplement punctuation | |||
} else if ((c >= 0x00F7) && (c <= 0x00F7)) { // latin supplement punctuation | |||
return true; | |||
} else if ( ( c >= 0x2000 ) && ( c <= 0x206F ) ) { // general punctuation | |||
} else if ((c >= 0x2000) && (c <= 0x206F)) { // general punctuation | |||
return true; | |||
} else { // [TBD] - not complete | |||
return false; | |||
@@ -172,8 +172,8 @@ public final class CharScript { | |||
* @param c a character represented as a unicode scalar value | |||
* @return true if character is a digit | |||
*/ | |||
public static boolean isDigit ( int c ) { | |||
if ( ( c >= 0x0030 ) && ( c <= 0x0039 ) ) { // basic latin digits | |||
public static boolean isDigit (int c) { | |||
if ((c >= 0x0030) && (c <= 0x0039)) { // basic latin digits | |||
return true; | |||
} else { // [TBD] - not complete | |||
return false; | |||
@@ -185,10 +185,10 @@ public final class CharScript { | |||
* @param c a character represented as a unicode scalar value | |||
* @return true if character belongs to hebrew script | |||
*/ | |||
public static boolean isHebrew ( int c ) { | |||
if ( ( c >= 0x0590 ) && ( c <= 0x05FF ) ) { // hebrew block | |||
public static boolean isHebrew (int c) { | |||
if ((c >= 0x0590) && (c <= 0x05FF)) { // hebrew block | |||
return true; | |||
} else if ( ( c >= 0xFB00 ) && ( c <= 0xFB4F ) ) { // hebrew presentation forms block | |||
} else if ((c >= 0xFB00) && (c <= 0xFB4F)) { // hebrew presentation forms block | |||
return true; | |||
} else { | |||
return false; | |||
@@ -200,8 +200,8 @@ public final class CharScript { | |||
* @param c a character represented as a unicode scalar value | |||
* @return true if character belongs to mongolian script | |||
*/ | |||
public static boolean isMongolian ( int c ) { | |||
if ( ( c >= 0x1800 ) && ( c <= 0x18AF ) ) { // mongolian block | |||
public static boolean isMongolian (int c) { | |||
if ((c >= 0x1800) && (c <= 0x18AF)) { // mongolian block | |||
return true; | |||
} else { | |||
return false; | |||
@@ -213,14 +213,14 @@ public final class CharScript { | |||
* @param c a character represented as a unicode scalar value | |||
* @return true if character belongs to arabic script | |||
*/ | |||
public static boolean isArabic ( int c ) { | |||
if ( ( c >= 0x0600 ) && ( c <= 0x06FF ) ) { // arabic block | |||
public static boolean isArabic (int c) { | |||
if ((c >= 0x0600) && (c <= 0x06FF)) { // arabic block | |||
return true; | |||
} else if ( ( c >= 0x0750 ) && ( c <= 0x077F ) ) { // arabic supplement block | |||
} else if ((c >= 0x0750) && (c <= 0x077F)) { // arabic supplement block | |||
return true; | |||
} else if ( ( c >= 0xFB50 ) && ( c <= 0xFDFF ) ) { // arabic presentation forms a block | |||
} else if ((c >= 0xFB50) && (c <= 0xFDFF)) { // arabic presentation forms a block | |||
return true; | |||
} else if ( ( c >= 0xFE70 ) && ( c <= 0xFEFF ) ) { // arabic presentation forms b block | |||
} else if ((c >= 0xFE70) && (c <= 0xFEFF)) { // arabic presentation forms b block | |||
return true; | |||
} else { | |||
return false; | |||
@@ -232,10 +232,10 @@ public final class CharScript { | |||
* @param c a character represented as a unicode scalar value | |||
* @return true if character belongs to greek script | |||
*/ | |||
public static boolean isGreek ( int c ) { | |||
if ( ( c >= 0x0370 ) && ( c <= 0x03FF ) ) { // greek (and coptic) block | |||
public static boolean isGreek (int c) { | |||
if ((c >= 0x0370) && (c <= 0x03FF)) { // greek (and coptic) block | |||
return true; | |||
} else if ( ( c >= 0x1F00 ) && ( c <= 0x1FFF ) ) { // greek extended block | |||
} else if ((c >= 0x1F00) && (c <= 0x1FFF)) { // greek extended block | |||
return true; | |||
} else { | |||
return false; | |||
@@ -247,30 +247,30 @@ public final class CharScript { | |||
* @param c a character represented as a unicode scalar value | |||
* @return true if character belongs to latin script | |||
*/ | |||
public static boolean isLatin ( int c ) { | |||
if ( ( c >= 0x0041 ) && ( c <= 0x005A ) ) { // basic latin upper case | |||
public static boolean isLatin (int c) { | |||
if ((c >= 0x0041) && (c <= 0x005A)) { // basic latin upper case | |||
return true; | |||
} else if ( ( c >= 0x0061 ) && ( c <= 0x007A ) ) { // basic latin lower case | |||
} else if ((c >= 0x0061) && (c <= 0x007A)) { // basic latin lower case | |||
return true; | |||
} else if ( ( c >= 0x00C0 ) && ( c <= 0x00D6 ) ) { // latin supplement upper case | |||
} else if ((c >= 0x00C0) && (c <= 0x00D6)) { // latin supplement upper case | |||
return true; | |||
} else if ( ( c >= 0x00D8 ) && ( c <= 0x00DF ) ) { // latin supplement upper case | |||
} else if ((c >= 0x00D8) && (c <= 0x00DF)) { // latin supplement upper case | |||
return true; | |||
} else if ( ( c >= 0x00E0 ) && ( c <= 0x00F6 ) ) { // latin supplement lower case | |||
} else if ((c >= 0x00E0) && (c <= 0x00F6)) { // latin supplement lower case | |||
return true; | |||
} else if ( ( c >= 0x00F8 ) && ( c <= 0x00FF ) ) { // latin supplement lower case | |||
} else if ((c >= 0x00F8) && (c <= 0x00FF)) { // latin supplement lower case | |||
return true; | |||
} else if ( ( c >= 0x0100 ) && ( c <= 0x017F ) ) { // latin extended a | |||
} else if ((c >= 0x0100) && (c <= 0x017F)) { // latin extended a | |||
return true; | |||
} else if ( ( c >= 0x0180 ) && ( c <= 0x024F ) ) { // latin extended b | |||
} else if ((c >= 0x0180) && (c <= 0x024F)) { // latin extended b | |||
return true; | |||
} else if ( ( c >= 0x1E00 ) && ( c <= 0x1EFF ) ) { // latin extended additional | |||
} else if ((c >= 0x1E00) && (c <= 0x1EFF)) { // latin extended additional | |||
return true; | |||
} else if ( ( c >= 0x2C60 ) && ( c <= 0x2C7F ) ) { // latin extended c | |||
} else if ((c >= 0x2C60) && (c <= 0x2C7F)) { // latin extended c | |||
return true; | |||
} else if ( ( c >= 0xA720 ) && ( c <= 0xA7FF ) ) { // latin extended d | |||
} else if ((c >= 0xA720) && (c <= 0xA7FF)) { // latin extended d | |||
return true; | |||
} else if ( ( c >= 0xFB00 ) && ( c <= 0xFB0F ) ) { // latin ligatures | |||
} else if ((c >= 0xFB00) && (c <= 0xFB0F)) { // latin ligatures | |||
return true; | |||
} else { | |||
return false; | |||
@@ -282,14 +282,14 @@ public final class CharScript { | |||
* @param c a character represented as a unicode scalar value | |||
* @return true if character belongs to cyrillic script | |||
*/ | |||
public static boolean isCyrillic ( int c ) { | |||
if ( ( c >= 0x0400 ) && ( c <= 0x04FF ) ) { // cyrillic block | |||
public static boolean isCyrillic (int c) { | |||
if ((c >= 0x0400) && (c <= 0x04FF)) { // cyrillic block | |||
return true; | |||
} else if ( ( c >= 0x0500 ) && ( c <= 0x052F ) ) { // cyrillic supplement block | |||
} else if ((c >= 0x0500) && (c <= 0x052F)) { // cyrillic supplement block | |||
return true; | |||
} else if ( ( c >= 0x2DE0 ) && ( c <= 0x2DFF ) ) { // cyrillic extended-a block | |||
} else if ((c >= 0x2DE0) && (c <= 0x2DFF)) { // cyrillic extended-a block | |||
return true; | |||
} else if ( ( c >= 0xA640 ) && ( c <= 0xA69F ) ) { // cyrillic extended-b block | |||
} else if ((c >= 0xA640) && (c <= 0xA69F)) { // cyrillic extended-b block | |||
return true; | |||
} else { | |||
return false; | |||
@@ -301,10 +301,10 @@ public final class CharScript { | |||
* @param c a character represented as a unicode scalar value | |||
* @return true if character belongs to georgian script | |||
*/ | |||
public static boolean isGeorgian ( int c ) { | |||
if ( ( c >= 0x10A0 ) && ( c <= 0x10FF ) ) { // georgian block | |||
public static boolean isGeorgian (int c) { | |||
if ((c >= 0x10A0) && (c <= 0x10FF)) { // georgian block | |||
return true; | |||
} else if ( ( c >= 0x2D00 ) && ( c <= 0x2D2F ) ) { // georgian supplement block | |||
} else if ((c >= 0x2D00) && (c <= 0x2D2F)) { // georgian supplement block | |||
return true; | |||
} else { | |||
return false; | |||
@@ -316,16 +316,16 @@ public final class CharScript { | |||
* @param c a character represented as a unicode scalar value | |||
* @return true if character belongs to hangul script | |||
*/ | |||
public static boolean isHangul ( int c ) { | |||
if ( ( c >= 0x1100 ) && ( c <= 0x11FF ) ) { // hangul jamo | |||
public static boolean isHangul (int c) { | |||
if ((c >= 0x1100) && (c <= 0x11FF)) { // hangul jamo | |||
return true; | |||
} else if ( ( c >= 0x3130 ) && ( c <= 0x318F ) ) { // hangul compatibility jamo | |||
} else if ((c >= 0x3130) && (c <= 0x318F)) { // hangul compatibility jamo | |||
return true; | |||
} else if ( ( c >= 0xA960 ) && ( c <= 0xA97F ) ) { // hangul jamo extended a | |||
} else if ((c >= 0xA960) && (c <= 0xA97F)) { // hangul jamo extended a | |||
return true; | |||
} else if ( ( c >= 0xAC00 ) && ( c <= 0xD7A3 ) ) { // hangul syllables | |||
} else if ((c >= 0xAC00) && (c <= 0xD7A3)) { // hangul syllables | |||
return true; | |||
} else if ( ( c >= 0xD7B0 ) && ( c <= 0xD7FF ) ) { // hangul jamo extended a | |||
} else if ((c >= 0xD7B0) && (c <= 0xD7FF)) { // hangul jamo extended a | |||
return true; | |||
} else { | |||
return false; | |||
@@ -337,8 +337,8 @@ public final class CharScript { | |||
* @param c a character represented as a unicode scalar value | |||
* @return true if character belongs to gurmukhi script | |||
*/ | |||
public static boolean isGurmukhi ( int c ) { | |||
if ( ( c >= 0x0A00 ) && ( c <= 0x0A7F ) ) { // gurmukhi block | |||
public static boolean isGurmukhi (int c) { | |||
if ((c >= 0x0A00) && (c <= 0x0A7F)) { // gurmukhi block | |||
return true; | |||
} else { | |||
return false; | |||
@@ -350,10 +350,10 @@ public final class CharScript { | |||
* @param c a character represented as a unicode scalar value | |||
* @return true if character belongs to devanagari script | |||
*/ | |||
public static boolean isDevanagari ( int c ) { | |||
if ( ( c >= 0x0900 ) && ( c <= 0x097F ) ) { // devangari block | |||
public static boolean isDevanagari (int c) { | |||
if ((c >= 0x0900) && (c <= 0x097F)) { // devangari block | |||
return true; | |||
} else if ( ( c >= 0xA8E0 ) && ( c <= 0xA8FF ) ) { // devangari extended block | |||
} else if ((c >= 0xA8E0) && (c <= 0xA8FF)) { // devangari extended block | |||
return true; | |||
} else { | |||
return false; | |||
@@ -365,8 +365,8 @@ public final class CharScript { | |||
* @param c a character represented as a unicode scalar value | |||
* @return true if character belongs to gujarati script | |||
*/ | |||
public static boolean isGujarati ( int c ) { | |||
if ( ( c >= 0x0A80 ) && ( c <= 0x0AFF ) ) { // gujarati block | |||
public static boolean isGujarati (int c) { | |||
if ((c >= 0x0A80) && (c <= 0x0AFF)) { // gujarati block | |||
return true; | |||
} else { | |||
return false; | |||
@@ -378,8 +378,8 @@ public final class CharScript { | |||
* @param c a character represented as a unicode scalar value | |||
* @return true if character belongs to bengali script | |||
*/ | |||
public static boolean isBengali ( int c ) { | |||
if ( ( c >= 0x0980 ) && ( c <= 0x09FF ) ) { // bengali block | |||
public static boolean isBengali (int c) { | |||
if ((c >= 0x0980) && (c <= 0x09FF)) { // bengali block | |||
return true; | |||
} else { | |||
return false; | |||
@@ -391,8 +391,8 @@ public final class CharScript { | |||
* @param c a character represented as a unicode scalar value | |||
* @return true if character belongs to oriya script | |||
*/ | |||
public static boolean isOriya ( int c ) { | |||
if ( ( c >= 0x0B00 ) && ( c <= 0x0B7F ) ) { // oriya block | |||
public static boolean isOriya (int c) { | |||
if ((c >= 0x0B00) && (c <= 0x0B7F)) { // oriya block | |||
return true; | |||
} else { | |||
return false; | |||
@@ -404,8 +404,8 @@ public final class CharScript { | |||
* @param c a character represented as a unicode scalar value | |||
* @return true if character belongs to tibetan script | |||
*/ | |||
public static boolean isTibetan ( int c ) { | |||
if ( ( c >= 0x0F00 ) && ( c <= 0x0FFF ) ) { // tibetan block | |||
public static boolean isTibetan (int c) { | |||
if ((c >= 0x0F00) && (c <= 0x0FFF)) { // tibetan block | |||
return true; | |||
} else { | |||
return false; | |||
@@ -417,8 +417,8 @@ public final class CharScript { | |||
* @param c a character represented as a unicode scalar value | |||
* @return true if character belongs to telugu script | |||
*/ | |||
public static boolean isTelugu ( int c ) { | |||
if ( ( c >= 0x0C00 ) && ( c <= 0x0C7F ) ) { // telugu block | |||
public static boolean isTelugu (int c) { | |||
if ((c >= 0x0C00) && (c <= 0x0C7F)) { // telugu block | |||
return true; | |||
} else { | |||
return false; | |||
@@ -430,8 +430,8 @@ public final class CharScript { | |||
* @param c a character represented as a unicode scalar value | |||
* @return true if character belongs to kannada script | |||
*/ | |||
public static boolean isKannada ( int c ) { | |||
if ( ( c >= 0x0C00 ) && ( c <= 0x0C7F ) ) { // kannada block | |||
public static boolean isKannada (int c) { | |||
if ((c >= 0x0C00) && (c <= 0x0C7F)) { // kannada block | |||
return true; | |||
} else { | |||
return false; | |||
@@ -443,8 +443,8 @@ public final class CharScript { | |||
* @param c a character represented as a unicode scalar value | |||
* @return true if character belongs to tamil script | |||
*/ | |||
public static boolean isTamil ( int c ) { | |||
if ( ( c >= 0x0B80 ) && ( c <= 0x0BFF ) ) { // tamil block | |||
public static boolean isTamil (int c) { | |||
if ((c >= 0x0B80) && (c <= 0x0BFF)) { // tamil block | |||
return true; | |||
} else { | |||
return false; | |||
@@ -456,8 +456,8 @@ public final class CharScript { | |||
* @param c a character represented as a unicode scalar value | |||
* @return true if character belongs to malayalam script | |||
*/ | |||
public static boolean isMalayalam ( int c ) { | |||
if ( ( c >= 0x0D00 ) && ( c <= 0x0D7F ) ) { // malayalam block | |||
public static boolean isMalayalam (int c) { | |||
if ((c >= 0x0D00) && (c <= 0x0D7F)) { // malayalam block | |||
return true; | |||
} else { | |||
return false; | |||
@@ -469,8 +469,8 @@ public final class CharScript { | |||
* @param c a character represented as a unicode scalar value | |||
* @return true if character belongs to sinhalese script | |||
*/ | |||
public static boolean isSinhalese ( int c ) { | |||
if ( ( c >= 0x0D80 ) && ( c <= 0x0DFF ) ) { // sinhala block | |||
public static boolean isSinhalese (int c) { | |||
if ((c >= 0x0D80) && (c <= 0x0DFF)) { // sinhala block | |||
return true; | |||
} else { | |||
return false; | |||
@@ -482,10 +482,10 @@ public final class CharScript { | |||
* @param c a character represented as a unicode scalar value | |||
* @return true if character belongs to burmese script | |||
*/ | |||
public static boolean isBurmese ( int c ) { | |||
if ( ( c >= 0x1000 ) && ( c <= 0x109F ) ) { // burmese (myanmar) block | |||
public static boolean isBurmese (int c) { | |||
if ((c >= 0x1000) && (c <= 0x109F)) { // burmese (myanmar) block | |||
return true; | |||
} else if ( ( c >= 0xAA60 ) && ( c <= 0xAA7F ) ) { // burmese (myanmar) extended block | |||
} else if ((c >= 0xAA60) && (c <= 0xAA7F)) { // burmese (myanmar) extended block | |||
return true; | |||
} else { | |||
return false; | |||
@@ -497,8 +497,8 @@ public final class CharScript { | |||
* @param c a character represented as a unicode scalar value | |||
* @return true if character belongs to thai script | |||
*/ | |||
public static boolean isThai ( int c ) { | |||
if ( ( c >= 0x0E00 ) && ( c <= 0x0E7F ) ) { // thai block | |||
public static boolean isThai (int c) { | |||
if ((c >= 0x0E00) && (c <= 0x0E7F)) { // thai block | |||
return true; | |||
} else { | |||
return false; | |||
@@ -510,10 +510,10 @@ public final class CharScript { | |||
* @param c a character represented as a unicode scalar value | |||
* @return true if character belongs to khmer script | |||
*/ | |||
public static boolean isKhmer ( int c ) { | |||
if ( ( c >= 0x1780 ) && ( c <= 0x17FF ) ) { // khmer block | |||
public static boolean isKhmer (int c) { | |||
if ((c >= 0x1780) && (c <= 0x17FF)) { // khmer block | |||
return true; | |||
} else if ( ( c >= 0x19E0 ) && ( c <= 0x19FF ) ) { // khmer symbols block | |||
} else if ((c >= 0x19E0) && (c <= 0x19FF)) { // khmer symbols block | |||
return true; | |||
} else { | |||
return false; | |||
@@ -525,8 +525,8 @@ public final class CharScript { | |||
* @param c a character represented as a unicode scalar value | |||
* @return true if character belongs to lao script | |||
*/ | |||
public static boolean isLao ( int c ) { | |||
if ( ( c >= 0x0E80 ) && ( c <= 0x0EFF ) ) { // lao block | |||
public static boolean isLao (int c) { | |||
if ((c >= 0x0E80) && (c <= 0x0EFF)) { // lao block | |||
return true; | |||
} else { | |||
return false; | |||
@@ -538,14 +538,14 @@ public final class CharScript { | |||
* @param c a character represented as a unicode scalar value | |||
* @return true if character belongs to ethiopic (amharic) script | |||
*/ | |||
public static boolean isEthiopic ( int c ) { | |||
if ( ( c >= 0x1200 ) && ( c <= 0x137F ) ) { // ethiopic block | |||
public static boolean isEthiopic (int c) { | |||
if ((c >= 0x1200) && (c <= 0x137F)) { // ethiopic block | |||
return true; | |||
} else if ( ( c >= 0x1380 ) && ( c <= 0x139F ) ) { // ethoipic supplement block | |||
} else if ((c >= 0x1380) && (c <= 0x139F)) { // ethoipic supplement block | |||
return true; | |||
} else if ( ( c >= 0x2D80 ) && ( c <= 0x2DDF ) ) { // ethoipic extended block | |||
} else if ((c >= 0x2D80) && (c <= 0x2DDF)) { // ethoipic extended block | |||
return true; | |||
} else if ( ( c >= 0xAB00 ) && ( c <= 0xAB2F ) ) { // ethoipic extended-a block | |||
} else if ((c >= 0xAB00) && (c <= 0xAB2F)) { // ethoipic extended-a block | |||
return true; | |||
} else { | |||
return false; | |||
@@ -557,18 +557,18 @@ public final class CharScript { | |||
* @param c a character represented as a unicode scalar value | |||
* @return true if character belongs to han (unified cjk) script | |||
*/ | |||
public static boolean isHan ( int c ) { | |||
if ( ( c >= 0x3400 ) && ( c <= 0x4DBF ) ) { | |||
public static boolean isHan (int c) { | |||
if ((c >= 0x3400) && (c <= 0x4DBF)) { | |||
return true; // cjk unified ideographs extension a | |||
} else if ( ( c >= 0x4E00 ) && ( c <= 0x9FFF ) ) { | |||
} else if ((c >= 0x4E00) && (c <= 0x9FFF)) { | |||
return true; // cjk unified ideographs | |||
} else if ( ( c >= 0xF900 ) && ( c <= 0xFAFF ) ) { | |||
} else if ((c >= 0xF900) && (c <= 0xFAFF)) { | |||
return true; // cjk compatibility ideographs | |||
} else if ( ( c >= 0x20000 ) && ( c <= 0x2A6DF ) ) { | |||
} else if ((c >= 0x20000) && (c <= 0x2A6DF)) { | |||
return true; // cjk unified ideographs extension b | |||
} else if ( ( c >= 0x2A700 ) && ( c <= 0x2B73F ) ) { | |||
} else if ((c >= 0x2A700) && (c <= 0x2B73F)) { | |||
return true; // cjk unified ideographs extension c | |||
} else if ( ( c >= 0x2F800 ) && ( c <= 0x2FA1F ) ) { | |||
} else if ((c >= 0x2F800) && (c <= 0x2FA1F)) { | |||
return true; // cjk compatibility ideographs supplement | |||
} else { | |||
return false; | |||
@@ -580,8 +580,8 @@ public final class CharScript { | |||
* @param c a character represented as a unicode scalar value | |||
* @return true if character belongs to bopomofo script | |||
*/ | |||
public static boolean isBopomofo ( int c ) { | |||
if ( ( c >= 0x3100 ) && ( c <= 0x312F ) ) { | |||
public static boolean isBopomofo (int c) { | |||
if ((c >= 0x3100) && (c <= 0x312F)) { | |||
return true; | |||
} else { | |||
return false; | |||
@@ -593,8 +593,8 @@ public final class CharScript { | |||
* @param c a character represented as a unicode scalar value | |||
* @return true if character belongs to hiragana script | |||
*/ | |||
public static boolean isHiragana ( int c ) { | |||
if ( ( c >= 0x3040 ) && ( c <= 0x309F ) ) { | |||
public static boolean isHiragana (int c) { | |||
if ((c >= 0x3040) && (c <= 0x309F)) { | |||
return true; | |||
} else { | |||
return false; | |||
@@ -606,10 +606,10 @@ public final class CharScript { | |||
* @param c a character represented as a unicode scalar value | |||
* @return true if character belongs to katakana script | |||
*/ | |||
public static boolean isKatakana ( int c ) { | |||
if ( ( c >= 0x30A0 ) && ( c <= 0x30FF ) ) { | |||
public static boolean isKatakana (int c) { | |||
if ((c >= 0x30A0) && (c <= 0x30FF)) { | |||
return true; | |||
} else if ( ( c >= 0x31F0 ) && ( c <= 0x31FF ) ) { | |||
} else if ((c >= 0x31F0) && (c <= 0x31FF)) { | |||
return true; | |||
} else { | |||
return false; | |||
@@ -622,68 +622,68 @@ public final class CharScript { | |||
* @param c the character to obtain script | |||
* @return an ISO15924 script code | |||
*/ | |||
public static int scriptOf ( int c ) { // [TBD] - needs optimization!!! | |||
if ( CharUtilities.isAnySpace ( c ) ) { | |||
public static int scriptOf (int c) { // [TBD] - needs optimization!!! | |||
if (CharUtilities.isAnySpace (c)) { | |||
return SCRIPT_UNDETERMINED; | |||
} else if ( isPunctuation ( c ) ) { | |||
} else if (isPunctuation (c)) { | |||
return SCRIPT_UNDETERMINED; | |||
} else if ( isDigit ( c ) ) { | |||
} else if (isDigit (c)) { | |||
return SCRIPT_UNDETERMINED; | |||
} else if ( isLatin ( c ) ) { | |||
} else if (isLatin (c)) { | |||
return SCRIPT_LATIN; | |||
} else if ( isCyrillic ( c ) ) { | |||
} else if (isCyrillic (c)) { | |||
return SCRIPT_CYRILLIC; | |||
} else if ( isGreek ( c ) ) { | |||
} else if (isGreek (c)) { | |||
return SCRIPT_GREEK; | |||
} else if ( isHan ( c ) ) { | |||
} else if (isHan (c)) { | |||
return SCRIPT_HAN; | |||
} else if ( isBopomofo ( c ) ) { | |||
} else if (isBopomofo (c)) { | |||
return SCRIPT_BOPOMOFO; | |||
} else if ( isKatakana ( c ) ) { | |||
} else if (isKatakana (c)) { | |||
return SCRIPT_KATAKANA; | |||
} else if ( isHiragana ( c ) ) { | |||
} else if (isHiragana (c)) { | |||
return SCRIPT_HIRAGANA; | |||
} else if ( isHangul ( c ) ) { | |||
} else if (isHangul (c)) { | |||
return SCRIPT_HANGUL; | |||
} else if ( isArabic ( c ) ) { | |||
} else if (isArabic (c)) { | |||
return SCRIPT_ARABIC; | |||
} else if ( isHebrew ( c ) ) { | |||
} else if (isHebrew (c)) { | |||
return SCRIPT_HEBREW; | |||
} else if ( isMongolian ( c ) ) { | |||
} else if (isMongolian (c)) { | |||
return SCRIPT_MONGOLIAN; | |||
} else if ( isGeorgian ( c ) ) { | |||
} else if (isGeorgian (c)) { | |||
return SCRIPT_GEORGIAN; | |||
} else if ( isGurmukhi ( c ) ) { | |||
return useV2IndicRules ( SCRIPT_GURMUKHI ); | |||
} else if ( isDevanagari ( c ) ) { | |||
return useV2IndicRules ( SCRIPT_DEVANAGARI ); | |||
} else if ( isGujarati ( c ) ) { | |||
return useV2IndicRules ( SCRIPT_GUJARATI ); | |||
} else if ( isBengali ( c ) ) { | |||
return useV2IndicRules ( SCRIPT_BENGALI ); | |||
} else if ( isOriya ( c ) ) { | |||
return useV2IndicRules ( SCRIPT_ORIYA ); | |||
} else if ( isTibetan ( c ) ) { | |||
} else if (isGurmukhi (c)) { | |||
return useV2IndicRules (SCRIPT_GURMUKHI); | |||
} else if (isDevanagari (c)) { | |||
return useV2IndicRules (SCRIPT_DEVANAGARI); | |||
} else if (isGujarati (c)) { | |||
return useV2IndicRules (SCRIPT_GUJARATI); | |||
} else if (isBengali (c)) { | |||
return useV2IndicRules (SCRIPT_BENGALI); | |||
} else if (isOriya (c)) { | |||
return useV2IndicRules (SCRIPT_ORIYA); | |||
} else if (isTibetan (c)) { | |||
return SCRIPT_TIBETAN; | |||
} else if ( isTelugu ( c ) ) { | |||
return useV2IndicRules ( SCRIPT_TELUGU ); | |||
} else if ( isKannada ( c ) ) { | |||
return useV2IndicRules ( SCRIPT_KANNADA ); | |||
} else if ( isTamil ( c ) ) { | |||
return useV2IndicRules ( SCRIPT_TAMIL ); | |||
} else if ( isMalayalam ( c ) ) { | |||
return useV2IndicRules ( SCRIPT_MALAYALAM ); | |||
} else if ( isSinhalese ( c ) ) { | |||
} else if (isTelugu (c)) { | |||
return useV2IndicRules (SCRIPT_TELUGU); | |||
} else if (isKannada (c)) { | |||
return useV2IndicRules (SCRIPT_KANNADA); | |||
} else if (isTamil (c)) { | |||
return useV2IndicRules (SCRIPT_TAMIL); | |||
} else if (isMalayalam (c)) { | |||
return useV2IndicRules (SCRIPT_MALAYALAM); | |||
} else if (isSinhalese (c)) { | |||
return SCRIPT_SINHALESE; | |||
} else if ( isBurmese ( c ) ) { | |||
} else if (isBurmese (c)) { | |||
return SCRIPT_BURMESE; | |||
} else if ( isThai ( c ) ) { | |||
} else if (isThai (c)) { | |||
return SCRIPT_THAI; | |||
} else if ( isKhmer ( c ) ) { | |||
} else if (isKhmer (c)) { | |||
return SCRIPT_KHMER; | |||
} else if ( isLao ( c ) ) { | |||
} else if (isLao (c)) { | |||
return SCRIPT_LAO; | |||
} else if ( isEthiopic ( c ) ) { | |||
} else if (isEthiopic (c)) { | |||
return SCRIPT_ETHIOPIC; | |||
} else { | |||
return SCRIPT_UNDETERMINED; | |||
@@ -696,9 +696,9 @@ public final class CharScript { | |||
* @param sc a V1 indic script code | |||
* @return either SC or the V2 flavor of SC if V2 indic rules apply | |||
*/ | |||
public static int useV2IndicRules ( int sc ) { | |||
if ( useV2Indic ) { | |||
return ( sc < 1000 ) ? ( sc + 1000 ) : sc; | |||
public static int useV2IndicRules (int sc) { | |||
if (useV2Indic) { | |||
return (sc < 1000) ? (sc + 1000) : sc; | |||
} else { | |||
return sc; | |||
} | |||
@@ -711,17 +711,17 @@ public final class CharScript { | |||
* @param cs the character sequence | |||
* @return a (possibly empty) array of script codes | |||
*/ | |||
public static int[] scriptsOf ( CharSequence cs ) { | |||
public static int[] scriptsOf (CharSequence cs) { | |||
Set s = new HashSet(); | |||
for ( int i = 0, n = cs.length(); i < n; i++ ) { | |||
s.add ( Integer.valueOf ( scriptOf ( cs.charAt ( i ) ) ) ); | |||
for (int i = 0, n = cs.length(); i < n; i++) { | |||
s.add (Integer.valueOf (scriptOf (cs.charAt (i)))); | |||
} | |||
int[] sa = new int [ s.size() ]; | |||
int ns = 0; | |||
for ( Iterator it = s.iterator(); it.hasNext();) { | |||
sa [ ns++ ] = ( (Integer) it.next() ) .intValue(); | |||
for (Iterator it = s.iterator(); it.hasNext();) { | |||
sa [ ns++ ] = ((Integer) it.next()) .intValue(); | |||
} | |||
Arrays.sort ( sa ); | |||
Arrays.sort (sa); | |||
return sa; | |||
} | |||
@@ -730,26 +730,26 @@ public final class CharScript { | |||
* @param cs the character sequence | |||
* @return the dominant script or SCRIPT_UNDETERMINED | |||
*/ | |||
public static int dominantScript ( CharSequence cs ) { | |||
public static int dominantScript (CharSequence cs) { | |||
Map m = new HashMap(); | |||
for ( int i = 0, n = cs.length(); i < n; i++ ) { | |||
int c = cs.charAt ( i ); | |||
int s = scriptOf ( c ); | |||
Integer k = Integer.valueOf ( s ); | |||
Integer v = (Integer) m.get ( k ); | |||
if ( v != null ) { | |||
m.put ( k, Integer.valueOf ( v.intValue() + 1 ) ); | |||
for (int i = 0, n = cs.length(); i < n; i++) { | |||
int c = cs.charAt (i); | |||
int s = scriptOf (c); | |||
Integer k = Integer.valueOf (s); | |||
Integer v = (Integer) m.get (k); | |||
if (v != null) { | |||
m.put (k, Integer.valueOf (v.intValue() + 1)); | |||
} else { | |||
m.put ( k, Integer.valueOf ( 0 ) ); | |||
m.put (k, Integer.valueOf (0)); | |||
} | |||
} | |||
int sMax = -1; | |||
int cMax = -1; | |||
for ( Iterator it = m.entrySet().iterator(); it.hasNext();) { | |||
for (Iterator it = m.entrySet().iterator(); it.hasNext();) { | |||
Map.Entry e = (Map.Entry) it.next(); | |||
Integer k = (Integer) e.getKey(); | |||
int s = k.intValue(); | |||
switch ( s ) { | |||
switch (s) { | |||
case SCRIPT_UNDETERMINED: | |||
case SCRIPT_UNCODED: | |||
break; | |||
@@ -758,7 +758,7 @@ public final class CharScript { | |||
Integer v = (Integer) e.getValue(); | |||
assert v != null; | |||
int c = v.intValue(); | |||
if ( c > cMax ) { | |||
if (c > cMax) { | |||
cMax = c; | |||
sMax = s; | |||
} | |||
@@ -766,7 +766,7 @@ public final class CharScript { | |||
} | |||
} | |||
} | |||
if ( sMax < 0 ) { | |||
if (sMax < 0) { | |||
sMax = SCRIPT_UNDETERMINED; | |||
} | |||
return sMax; | |||
@@ -779,8 +779,8 @@ public final class CharScript { | |||
* @param script a script tag | |||
* @return true if script tag is a designated 'Indic' script | |||
*/ | |||
public static boolean isIndicScript ( String script ) { | |||
return isIndicScript ( scriptCodeFromTag ( script ) ); | |||
public static boolean isIndicScript (String script) { | |||
return isIndicScript (scriptCodeFromTag (script)); | |||
} | |||
/** | |||
@@ -790,8 +790,8 @@ public final class CharScript { | |||
* @param script a script code | |||
* @return true if script code is a designated 'Indic' script | |||
*/ | |||
public static boolean isIndicScript ( int script ) { | |||
switch ( script ) { | |||
public static boolean isIndicScript (int script) { | |||
switch (script) { | |||
case SCRIPT_BENGALI: | |||
case SCRIPT_BENGALI_2: | |||
case SCRIPT_BURMESE: | |||
@@ -822,11 +822,11 @@ public final class CharScript { | |||
* @param code the script code | |||
* @return a script tag | |||
*/ | |||
public static String scriptTagFromCode ( int code ) { | |||
public static String scriptTagFromCode (int code) { | |||
Map<Integer,String> m = getScriptTagsMap(); | |||
if ( m != null ) { | |||
if (m != null) { | |||
String tag; | |||
if ( ( tag = m.get ( Integer.valueOf ( code ) ) ) != null ) { | |||
if ((tag = m.get (Integer.valueOf (code))) != null) { | |||
return tag; | |||
} else { | |||
return ""; | |||
@@ -841,11 +841,11 @@ public final class CharScript { | |||
* @param tag the script tag | |||
* @return a script code | |||
*/ | |||
public static int scriptCodeFromTag ( String tag ) { | |||
public static int scriptCodeFromTag (String tag) { | |||
Map<String,Integer> m = getScriptCodeMap(); | |||
if ( m != null ) { | |||
if (m != null) { | |||
Integer c; | |||
if ( ( c = m.get ( tag ) ) != null ) { | |||
if ((c = m.get (tag)) != null) { | |||
return (int) c; | |||
} else { | |||
return SCRIPT_UNDETERMINED; | |||
@@ -858,72 +858,72 @@ public final class CharScript { | |||
private static Map<Integer,String> scriptTagsMap = null; | |||
private static Map<String,Integer> scriptCodeMap = null; | |||
private static void putScriptTag ( Map tm, Map cm, int code, String tag ) { | |||
private static void putScriptTag (Map tm, Map cm, int code, String tag) { | |||
assert tag != null; | |||
assert tag.length() != 0; | |||
assert code >= 0; | |||
assert code < 2000; | |||
tm.put ( Integer.valueOf ( code ), tag ); | |||
cm.put ( tag, Integer.valueOf ( code ) ); | |||
tm.put (Integer.valueOf (code), tag); | |||
cm.put (tag, Integer.valueOf (code)); | |||
} | |||
private static void makeScriptMaps() { | |||
HashMap<Integer,String> tm = new HashMap<Integer,String>(); | |||
HashMap<String,Integer> cm = new HashMap<String,Integer>(); | |||
putScriptTag ( tm, cm, SCRIPT_HEBREW, "hebr" ); | |||
putScriptTag ( tm, cm, SCRIPT_MONGOLIAN, "mong" ); | |||
putScriptTag ( tm, cm, SCRIPT_ARABIC, "arab" ); | |||
putScriptTag ( tm, cm, SCRIPT_GREEK, "grek" ); | |||
putScriptTag ( tm, cm, SCRIPT_LATIN, "latn" ); | |||
putScriptTag ( tm, cm, SCRIPT_CYRILLIC, "cyrl" ); | |||
putScriptTag ( tm, cm, SCRIPT_GEORGIAN, "geor" ); | |||
putScriptTag ( tm, cm, SCRIPT_BOPOMOFO, "bopo" ); | |||
putScriptTag ( tm, cm, SCRIPT_HANGUL, "hang" ); | |||
putScriptTag ( tm, cm, SCRIPT_GURMUKHI, "guru" ); | |||
putScriptTag ( tm, cm, SCRIPT_GURMUKHI_2, "gur2" ); | |||
putScriptTag ( tm, cm, SCRIPT_DEVANAGARI, "deva" ); | |||
putScriptTag ( tm, cm, SCRIPT_DEVANAGARI_2, "dev2" ); | |||
putScriptTag ( tm, cm, SCRIPT_GUJARATI, "gujr" ); | |||
putScriptTag ( tm, cm, SCRIPT_GUJARATI_2, "gjr2" ); | |||
putScriptTag ( tm, cm, SCRIPT_BENGALI, "beng" ); | |||
putScriptTag ( tm, cm, SCRIPT_BENGALI_2, "bng2" ); | |||
putScriptTag ( tm, cm, SCRIPT_ORIYA, "orya" ); | |||
putScriptTag ( tm, cm, SCRIPT_ORIYA_2, "ory2" ); | |||
putScriptTag ( tm, cm, SCRIPT_TIBETAN, "tibt" ); | |||
putScriptTag ( tm, cm, SCRIPT_TELUGU, "telu" ); | |||
putScriptTag ( tm, cm, SCRIPT_TELUGU_2, "tel2" ); | |||
putScriptTag ( tm, cm, SCRIPT_KANNADA, "knda" ); | |||
putScriptTag ( tm, cm, SCRIPT_KANNADA_2, "knd2" ); | |||
putScriptTag ( tm, cm, SCRIPT_TAMIL, "taml" ); | |||
putScriptTag ( tm, cm, SCRIPT_TAMIL_2, "tml2" ); | |||
putScriptTag ( tm, cm, SCRIPT_MALAYALAM, "mlym" ); | |||
putScriptTag ( tm, cm, SCRIPT_MALAYALAM_2, "mlm2" ); | |||
putScriptTag ( tm, cm, SCRIPT_SINHALESE, "sinh" ); | |||
putScriptTag ( tm, cm, SCRIPT_BURMESE, "mymr" ); | |||
putScriptTag ( tm, cm, SCRIPT_THAI, "thai" ); | |||
putScriptTag ( tm, cm, SCRIPT_KHMER, "khmr" ); | |||
putScriptTag ( tm, cm, SCRIPT_LAO, "laoo" ); | |||
putScriptTag ( tm, cm, SCRIPT_HIRAGANA, "hira" ); | |||
putScriptTag ( tm, cm, SCRIPT_ETHIOPIC, "ethi" ); | |||
putScriptTag ( tm, cm, SCRIPT_HAN, "hani" ); | |||
putScriptTag ( tm, cm, SCRIPT_KATAKANA, "kana" ); | |||
putScriptTag ( tm, cm, SCRIPT_MATH, "zmth" ); | |||
putScriptTag ( tm, cm, SCRIPT_SYMBOL, "zsym" ); | |||
putScriptTag ( tm, cm, SCRIPT_UNDETERMINED, "zyyy" ); | |||
putScriptTag ( tm, cm, SCRIPT_UNCODED, "zzzz" ); | |||
putScriptTag (tm, cm, SCRIPT_HEBREW, "hebr"); | |||
putScriptTag (tm, cm, SCRIPT_MONGOLIAN, "mong"); | |||
putScriptTag (tm, cm, SCRIPT_ARABIC, "arab"); | |||
putScriptTag (tm, cm, SCRIPT_GREEK, "grek"); | |||
putScriptTag (tm, cm, SCRIPT_LATIN, "latn"); | |||
putScriptTag (tm, cm, SCRIPT_CYRILLIC, "cyrl"); | |||
putScriptTag (tm, cm, SCRIPT_GEORGIAN, "geor"); | |||
putScriptTag (tm, cm, SCRIPT_BOPOMOFO, "bopo"); | |||
putScriptTag (tm, cm, SCRIPT_HANGUL, "hang"); | |||
putScriptTag (tm, cm, SCRIPT_GURMUKHI, "guru"); | |||
putScriptTag (tm, cm, SCRIPT_GURMUKHI_2, "gur2"); | |||
putScriptTag (tm, cm, SCRIPT_DEVANAGARI, "deva"); | |||
putScriptTag (tm, cm, SCRIPT_DEVANAGARI_2, "dev2"); | |||
putScriptTag (tm, cm, SCRIPT_GUJARATI, "gujr"); | |||
putScriptTag (tm, cm, SCRIPT_GUJARATI_2, "gjr2"); | |||
putScriptTag (tm, cm, SCRIPT_BENGALI, "beng"); | |||
putScriptTag (tm, cm, SCRIPT_BENGALI_2, "bng2"); | |||
putScriptTag (tm, cm, SCRIPT_ORIYA, "orya"); | |||
putScriptTag (tm, cm, SCRIPT_ORIYA_2, "ory2"); | |||
putScriptTag (tm, cm, SCRIPT_TIBETAN, "tibt"); | |||
putScriptTag (tm, cm, SCRIPT_TELUGU, "telu"); | |||
putScriptTag (tm, cm, SCRIPT_TELUGU_2, "tel2"); | |||
putScriptTag (tm, cm, SCRIPT_KANNADA, "knda"); | |||
putScriptTag (tm, cm, SCRIPT_KANNADA_2, "knd2"); | |||
putScriptTag (tm, cm, SCRIPT_TAMIL, "taml"); | |||
putScriptTag (tm, cm, SCRIPT_TAMIL_2, "tml2"); | |||
putScriptTag (tm, cm, SCRIPT_MALAYALAM, "mlym"); | |||
putScriptTag (tm, cm, SCRIPT_MALAYALAM_2, "mlm2"); | |||
putScriptTag (tm, cm, SCRIPT_SINHALESE, "sinh"); | |||
putScriptTag (tm, cm, SCRIPT_BURMESE, "mymr"); | |||
putScriptTag (tm, cm, SCRIPT_THAI, "thai"); | |||
putScriptTag (tm, cm, SCRIPT_KHMER, "khmr"); | |||
putScriptTag (tm, cm, SCRIPT_LAO, "laoo"); | |||
putScriptTag (tm, cm, SCRIPT_HIRAGANA, "hira"); | |||
putScriptTag (tm, cm, SCRIPT_ETHIOPIC, "ethi"); | |||
putScriptTag (tm, cm, SCRIPT_HAN, "hani"); | |||
putScriptTag (tm, cm, SCRIPT_KATAKANA, "kana"); | |||
putScriptTag (tm, cm, SCRIPT_MATH, "zmth"); | |||
putScriptTag (tm, cm, SCRIPT_SYMBOL, "zsym"); | |||
putScriptTag (tm, cm, SCRIPT_UNDETERMINED, "zyyy"); | |||
putScriptTag (tm, cm, SCRIPT_UNCODED, "zzzz"); | |||
scriptTagsMap = tm; | |||
scriptCodeMap = cm; | |||
} | |||
private static Map<Integer,String> getScriptTagsMap() { | |||
if ( scriptTagsMap == null ) { | |||
if (scriptTagsMap == null) { | |||
makeScriptMaps(); | |||
} | |||
return scriptTagsMap; | |||
} | |||
private static Map<String,Integer> getScriptCodeMap() { | |||
if ( scriptCodeMap == null ) { | |||
if (scriptCodeMap == null) { | |||
makeScriptMaps(); | |||
} | |||
return scriptCodeMap; |
@@ -38,6 +38,6 @@ public interface GlyphContextTester { | |||
* @param flags that apply to lookup in scope | |||
* @return true if test is satisfied | |||
*/ | |||
boolean test ( String script, String language, String feature, GlyphSequence gs, int index, int flags ); | |||
boolean test (String script, String language, String feature, GlyphSequence gs, int index, int flags); | |||
} |
@@ -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); | |||
} |
@@ -31,6 +31,6 @@ public interface ScriptContextTester { | |||
* @param feature a feature identifier | |||
* @return a glyph context tester or null if none available for the specified feature | |||
*/ | |||
GlyphContextTester getTester ( String feature ); | |||
GlyphContextTester getTester (String feature); | |||
} |
@@ -46,35 +46,35 @@ public final class UTF32 { | |||
* @throws IllegalArgumentException if substitution required and errorOnSubstitution | |||
* is not false | |||
*/ | |||
public static Integer[] toUTF32 ( String s, int substitution, boolean errorOnSubstitution ) | |||
public static Integer[] toUTF32 (String s, int substitution, boolean errorOnSubstitution) | |||
throws IllegalArgumentException { | |||
int n; | |||
if ( ( n = s.length() ) == 0 ) { | |||
if ((n = s.length()) == 0) { | |||
return new Integer[0]; | |||
} else { | |||
Integer[] sa = new Integer [ n ]; | |||
int k = 0; | |||
for ( int i = 0; i < n; i++ ) { | |||
for (int i = 0; i < n; i++) { | |||
int c = (int) s.charAt(i); | |||
if ( ( c >= 0xD800 ) && ( c < 0xE000 ) ) { | |||
if ((c >= 0xD800) && (c < 0xE000)) { | |||
int s1 = c; | |||
int s2 = ( ( i + 1 ) < n ) ? (int) s.charAt ( i + 1 ) : 0; | |||
if ( s1 < 0xDC00 ) { | |||
if ( ( s2 >= 0xDC00 ) && ( s2 < 0xE000 ) ) { | |||
c = ( ( s1 - 0xD800 ) << 10 ) + ( s2 - 0xDC00 ) + 65536; | |||
int s2 = ((i + 1) < n) ? (int) s.charAt (i + 1) : 0; | |||
if (s1 < 0xDC00) { | |||
if ((s2 >= 0xDC00) && (s2 < 0xE000)) { | |||
c = ((s1 - 0xD800) << 10) + (s2 - 0xDC00) + 65536; | |||
i++; | |||
} else { | |||
if ( errorOnSubstitution ) { | |||
if (errorOnSubstitution) { | |||
throw new IllegalArgumentException | |||
( "isolated high (leading) surrogate" ); | |||
("isolated high (leading) surrogate"); | |||
} else { | |||
c = substitution; | |||
} | |||
} | |||
} else { | |||
if ( errorOnSubstitution ) { | |||
if (errorOnSubstitution) { | |||
throw new IllegalArgumentException | |||
( "isolated low (trailing) surrogate" ); | |||
("isolated low (trailing) surrogate"); | |||
} else { | |||
c = substitution; | |||
} | |||
@@ -82,11 +82,11 @@ public final class UTF32 { | |||
} | |||
sa[k++] = c; | |||
} | |||
if ( k == n ) { | |||
if (k == n) { | |||
return sa; | |||
} else { | |||
Integer[] na = new Integer [ k ]; | |||
System.arraycopy ( sa, 0, na, 0, k ); | |||
System.arraycopy (sa, 0, na, 0, k); | |||
return na; | |||
} | |||
} | |||
@@ -99,28 +99,28 @@ public final class UTF32 { | |||
* @throws IllegalArgumentException if an input scalar value is illegal, | |||
* e.g., a surrogate or out of range | |||
*/ | |||
public static String fromUTF32 ( Integer[] sa ) throws IllegalArgumentException { | |||
public static String fromUTF32 (Integer[] sa) throws IllegalArgumentException { | |||
StringBuffer sb = new StringBuffer(); | |||
for ( int s : sa ) { | |||
if ( s < 65535 ) { | |||
if ( ( s < 0xD800 ) || ( s > 0xDFFF ) ) { | |||
sb.append ( (char) s ); | |||
for (int s : sa) { | |||
if (s < 65535) { | |||
if ((s < 0xD800) || (s > 0xDFFF)) { | |||
sb.append ((char) s); | |||
} else { | |||
String ncr = CharUtilities.charToNCRef(s); | |||
throw new IllegalArgumentException | |||
( "illegal scalar value 0x" + ncr.substring(2, ncr.length() - 1) | |||
+ "; cannot be UTF-16 surrogate" ); | |||
("illegal scalar value 0x" + ncr.substring(2, ncr.length() - 1) | |||
+ "; cannot be UTF-16 surrogate"); | |||
} | |||
} else if ( s < 1114112 ) { | |||
int s1 = ( ( ( s - 65536 ) >> 10 ) & 0x3FF ) + 0xD800; | |||
int s2 = ( ( ( s - 65536 ) >> 0 ) & 0x3FF ) + 0xDC00; | |||
sb.append ( (char) s1 ); | |||
sb.append ( (char) s2 ); | |||
} else if (s < 1114112) { | |||
int s1 = (((s - 65536) >> 10) & 0x3FF) + 0xD800; | |||
int s2 = (((s - 65536) >> 0) & 0x3FF) + 0xDC00; | |||
sb.append ((char) s1); | |||
sb.append ((char) s2); | |||
} else { | |||
String ncr = CharUtilities.charToNCRef(s); | |||
throw new IllegalArgumentException | |||
( "illegal scalar value 0x" + ncr.substring(2, ncr.length() - 1) | |||
+ "; out of range for UTF-16" ); | |||
("illegal scalar value 0x" + ncr.substring(2, ncr.length() - 1) | |||
+ "; out of range for UTF-16"); | |||
} | |||
} | |||
return sb.toString(); |
@@ -50,7 +50,7 @@ public class Event extends EventObject { | |||
*/ | |||
public Event(Object source, String eventID, EventSeverity severity, Map<String, Object> params) | |||
{ | |||
this ( source, eventID, severity, Locale.getDefault(), params ); | |||
this (source, eventID, severity, Locale.getDefault(), params); | |||
} | |||
/** |
@@ -47,15 +47,15 @@ public final class EventFormatter { | |||
//utility class | |||
} | |||
private static ResourceBundle getBundle ( String groupID, Locale locale ) { | |||
private static ResourceBundle getBundle (String groupID, Locale locale) { | |||
ResourceBundle bundle; | |||
String baseName = ( groupID != null ) ? groupID : EventFormatter.class.getName(); | |||
String baseName = (groupID != null) ? groupID : EventFormatter.class.getName(); | |||
try { | |||
ClassLoader classLoader = EventFormatter.class.getClassLoader(); | |||
bundle = XMLResourceBundle.getXMLBundle ( baseName, locale, classLoader ); | |||
} catch ( MissingResourceException e ) { | |||
if ( log.isTraceEnabled() ) { | |||
log.trace ( "No XMLResourceBundle for " + baseName + " available." ); | |||
bundle = XMLResourceBundle.getXMLBundle (baseName, locale, classLoader); | |||
} catch (MissingResourceException e) { | |||
if (log.isTraceEnabled()) { | |||
log.trace ("No XMLResourceBundle for " + baseName + " available."); | |||
} | |||
bundle = null; | |||
} | |||
@@ -67,8 +67,8 @@ public final class EventFormatter { | |||
* @param event the event | |||
* @return the formatted message | |||
*/ | |||
public static String format ( Event event ) { | |||
return format ( event, event.getLocale() ); | |||
public static String format (Event event) { | |||
return format (event, event.getLocale()); | |||
} | |||
/** | |||
@@ -78,19 +78,19 @@ public final class EventFormatter { | |||
* @return the formatted message | |||
*/ | |||
public static String format(Event event, Locale locale) { | |||
return format ( event, getBundle ( event.getEventGroupID(), locale ) ); | |||
return format (event, getBundle (event.getEventGroupID(), locale)); | |||
} | |||
private static String format ( Event event, ResourceBundle bundle ) { | |||
private static String format (Event event, ResourceBundle bundle) { | |||
assert event != null; | |||
String key = event.getEventKey(); | |||
String template; | |||
if ( bundle != null ) { | |||
template = bundle.getString ( key ); | |||
if (bundle != null) { | |||
template = bundle.getString (key); | |||
} else { | |||
template = "Missing bundle. Can't lookup event key: '" + key + "'."; | |||
} | |||
return format ( event, processIncludes ( template, bundle ) ); | |||
return format (event, processIncludes (template, bundle)); | |||
} | |||
private static String processIncludes(String template, ResourceBundle bundle) { | |||
@@ -109,7 +109,7 @@ public final class EventFormatter { | |||
private static int processIncludesInner(CharSequence template, StringBuffer sb, | |||
ResourceBundle bundle) { | |||
int replacements = 0; | |||
if ( bundle != null ) { | |||
if (bundle != null) { | |||
Matcher m = INCLUDES_PATTERN.matcher(template); | |||
while (m.find()) { | |||
String include = m.group(); | |||
@@ -154,8 +154,8 @@ public final class EventFormatter { | |||
public void write(StringBuffer sb, Map params) { | |||
String groupID = (String) params.get("groupID"); | |||
Locale locale = (Locale) params.get("locale"); | |||
ResourceBundle bundle = getBundle ( groupID, locale ); | |||
if ( bundle != null ) { | |||
ResourceBundle bundle = getBundle (groupID, locale); | |||
if (bundle != null) { | |||
sb.append(bundle.getString(getKey(params))); | |||
} | |||
} |
@@ -438,8 +438,8 @@ public abstract class FONode implements Cloneable { | |||
* with the unabbreviated URI otherwise. | |||
*/ | |||
public static String getNodeString(String namespaceURI, String localName) { | |||
String prefix = getNodePrefix ( namespaceURI ); | |||
if ( prefix != null ) { | |||
String prefix = getNodePrefix (namespaceURI); | |||
if (prefix != null) { | |||
return prefix + ":" + localName; | |||
} else { | |||
return "(Namespace URI: \"" + namespaceURI + "\", " | |||
@@ -552,9 +552,9 @@ public abstract class FONode implements Cloneable { | |||
protected void invalidChildError(Locator loc, String parentName, String nsURI, String lName, | |||
String ruleViolated) | |||
throws ValidationException { | |||
String prefix = getNodePrefix ( nsURI ); | |||
String prefix = getNodePrefix (nsURI); | |||
QName qn; // qualified name of offending node | |||
if ( prefix != null ) { | |||
if (prefix != null) { | |||
qn = new QName(nsURI, prefix, lName); | |||
} else { | |||
qn = new QName(nsURI, lName); | |||
@@ -926,7 +926,7 @@ public abstract class FONode implements Cloneable { | |||
* @return true if indicated boundary (or boundaries) constitute a delimited text range | |||
* boundary. | |||
*/ | |||
public boolean isDelimitedTextRangeBoundary ( int boundary ) { | |||
public boolean isDelimitedTextRangeBoundary (int boundary) { | |||
return true; | |||
} | |||
@@ -936,23 +936,23 @@ public abstract class FONode implements Cloneable { | |||
* @param ranges a stack of delimited text ranges | |||
* @return the (possibly) updated stack of delimited text ranges | |||
*/ | |||
public Stack collectDelimitedTextRanges ( Stack ranges ) { | |||
public Stack collectDelimitedTextRanges (Stack ranges) { | |||
// if boundary before, then push new range | |||
if ( isRangeBoundaryBefore() ) { | |||
maybeNewRange ( ranges ); | |||
if (isRangeBoundaryBefore()) { | |||
maybeNewRange (ranges); | |||
} | |||
// get current range, if one exists | |||
DelimitedTextRange currentRange; | |||
if ( ranges.size() > 0 ) { | |||
if (ranges.size() > 0) { | |||
currentRange = (DelimitedTextRange) ranges.peek(); | |||
} else { | |||
currentRange = null; | |||
} | |||
// proceses this node | |||
ranges = collectDelimitedTextRanges ( ranges, currentRange ); | |||
ranges = collectDelimitedTextRanges (ranges, currentRange); | |||
// if boundary after, then push new range | |||
if ( isRangeBoundaryAfter() ) { | |||
maybeNewRange ( ranges ); | |||
if (isRangeBoundaryAfter()) { | |||
maybeNewRange (ranges); | |||
} | |||
return ranges; | |||
} | |||
@@ -965,9 +965,9 @@ public abstract class FONode implements Cloneable { | |||
* @param currentRange the current range or null (if none) | |||
* @return the (possibly) updated stack of delimited text ranges | |||
*/ | |||
protected Stack collectDelimitedTextRanges ( Stack ranges, DelimitedTextRange currentRange ) { | |||
for ( Iterator it = getChildNodes(); ( it != null ) && it.hasNext();) { | |||
ranges = ( (FONode) it.next() ).collectDelimitedTextRanges ( ranges ); | |||
protected Stack collectDelimitedTextRanges (Stack ranges, DelimitedTextRange currentRange) { | |||
for (Iterator it = getChildNodes(); (it != null) && it.hasNext();) { | |||
ranges = ((FONode) it.next()).collectDelimitedTextRanges (ranges); | |||
} | |||
return ranges; | |||
} | |||
@@ -992,23 +992,23 @@ public abstract class FONode implements Cloneable { | |||
* @param ranges stack of delimited text ranges | |||
* @return new range (if constructed and pushed onto stack) or current range (if any) or null | |||
*/ | |||
private DelimitedTextRange maybeNewRange ( Stack ranges ) { | |||
private DelimitedTextRange maybeNewRange (Stack ranges) { | |||
DelimitedTextRange rCur = null; // current range (top of range stack) | |||
DelimitedTextRange rNew = null; // new range to be pushed onto range stack | |||
if ( ranges.empty() ) { | |||
if ( isBidiRangeBlockItem() ) { | |||
if (ranges.empty()) { | |||
if (isBidiRangeBlockItem()) { | |||
rNew = new DelimitedTextRange(this); | |||
} | |||
} else { | |||
rCur = (DelimitedTextRange) ranges.peek(); | |||
if ( rCur != null ) { | |||
if ( !rCur.isEmpty() || !isSelfOrDescendent ( rCur.getNode(), this ) ) { | |||
if (rCur != null) { | |||
if (!rCur.isEmpty() || !isSelfOrDescendent (rCur.getNode(), this)) { | |||
rNew = new DelimitedTextRange(this); | |||
} | |||
} | |||
} | |||
if ( rNew != null ) { | |||
ranges.push ( rNew ); | |||
if (rNew != null) { | |||
ranges.push (rNew); | |||
} else { | |||
rNew = rCur; | |||
} | |||
@@ -1016,19 +1016,19 @@ public abstract class FONode implements Cloneable { | |||
} | |||
private boolean isRangeBoundaryBefore() { | |||
return isDelimitedTextRangeBoundary ( Constants.EN_BEFORE ); | |||
return isDelimitedTextRangeBoundary (Constants.EN_BEFORE); | |||
} | |||
private boolean isRangeBoundaryAfter() { | |||
return isDelimitedTextRangeBoundary ( Constants.EN_AFTER ); | |||
return isDelimitedTextRangeBoundary (Constants.EN_AFTER); | |||
} | |||
/** | |||
* Determine if node N2 is the same or a descendent of node N1. | |||
*/ | |||
private static boolean isSelfOrDescendent ( FONode n1, FONode n2 ) { | |||
for ( FONode n = n2; n != null; n = n.getParent() ) { | |||
if ( n == n1 ) { | |||
private static boolean isSelfOrDescendent (FONode n1, FONode n2) { | |||
for (FONode n = n2; n != null; n = n.getParent()) { | |||
if (n == n1) { | |||
return true; | |||
} | |||
} |
@@ -1503,32 +1503,32 @@ public final class FOPropertyMapping implements Constants { | |||
addPropertyMaker("fox:block-progression-unit", l); | |||
} | |||
private Property calcWritingModeDependent ( int pv, int wm ) { | |||
if ( pv == EN_LEFT ) { | |||
if ( wm == Constants.EN_LR_TB ) { | |||
private Property calcWritingModeDependent (int pv, int wm) { | |||
if (pv == EN_LEFT) { | |||
if (wm == Constants.EN_LR_TB) { | |||
pv = EN_START; | |||
} else if ( wm == Constants.EN_RL_TB ) { | |||
} else if (wm == Constants.EN_RL_TB) { | |||
pv = EN_END; | |||
} else { | |||
pv = EN_START; | |||
} | |||
} else if ( pv == EN_RIGHT ) { | |||
if ( wm == Constants.EN_LR_TB ) { | |||
} else if (pv == EN_RIGHT) { | |||
if (wm == Constants.EN_LR_TB) { | |||
pv = EN_END; | |||
} else if ( wm == Constants.EN_RL_TB ) { | |||
} else if (wm == Constants.EN_RL_TB) { | |||
pv = EN_START; | |||
} else { | |||
pv = EN_END; | |||
} | |||
} | |||
return makeWritingModeDependentEnum ( pv ); | |||
return makeWritingModeDependentEnum (pv); | |||
} | |||
private Property makeWritingModeDependentEnum ( int pv ) { | |||
if ( pv == EN_START ) { | |||
return getEnumProperty ( EN_START, "START" ); | |||
} else if ( pv == EN_END ) { | |||
return getEnumProperty ( EN_END, "END" ); | |||
private Property makeWritingModeDependentEnum (int pv) { | |||
if (pv == EN_START) { | |||
return getEnumProperty (EN_START, "START"); | |||
} else if (pv == EN_END) { | |||
return getEnumProperty (EN_END, "END"); | |||
} else { | |||
return null; | |||
} | |||
@@ -1623,11 +1623,11 @@ public final class FOPropertyMapping implements Constants { | |||
public Property get(int subpropId, PropertyList propertyList, | |||
boolean bTryInherit, boolean bTryDefault) throws PropertyException { | |||
Property p = super.get(subpropId, propertyList, bTryInherit, bTryDefault); | |||
if ( p != null ) { | |||
if (p != null) { | |||
int pv = p.getEnum(); | |||
if ( ( pv == EN_LEFT ) || ( pv == EN_RIGHT ) ) { | |||
if ((pv == EN_LEFT) || (pv == EN_RIGHT)) { | |||
p = calcWritingModeDependent | |||
( pv, propertyList.get(Constants.PR_WRITING_MODE).getEnum() ); | |||
(pv, propertyList.get(Constants.PR_WRITING_MODE).getEnum()); | |||
} | |||
} | |||
return p; | |||
@@ -1677,10 +1677,10 @@ public final class FOPropertyMapping implements Constants { | |||
return getEnumProperty(EN_CENTER, "CENTER"); | |||
} else if (correspondingValue == EN_LEFT) { | |||
return calcWritingModeDependent | |||
( EN_LEFT, propertyList.get(Constants.PR_WRITING_MODE).getEnum() ); | |||
(EN_LEFT, propertyList.get(Constants.PR_WRITING_MODE).getEnum()); | |||
} else if (correspondingValue == EN_RIGHT) { | |||
return calcWritingModeDependent | |||
( EN_RIGHT, propertyList.get(Constants.PR_WRITING_MODE).getEnum() ); | |||
(EN_RIGHT, propertyList.get(Constants.PR_WRITING_MODE).getEnum()); | |||
} else { | |||
return null; | |||
} |
@@ -114,15 +114,15 @@ public class FOText extends FONode implements CharSequence { | |||
PropertyList list, Locator locator) throws FOPException { | |||
if (charBuffer == null) { | |||
// buffer not yet initialized, do so now | |||
int newLength = ( length < 16 ) ? 16 : length; | |||
int newLength = (length < 16) ? 16 : length; | |||
charBuffer = CharBuffer.allocate(newLength); | |||
} else { | |||
// allocate a larger buffer, and transfer contents | |||
int requires = charBuffer.position() + length; | |||
int capacity = charBuffer.capacity(); | |||
if ( requires > capacity ) { | |||
if (requires > capacity) { | |||
int newCapacity = capacity * 2; | |||
if ( requires > newCapacity ) { | |||
if (requires > newCapacity) { | |||
newCapacity = requires; | |||
} | |||
CharBuffer newBuffer = CharBuffer.allocate(newCapacity); | |||
@@ -194,7 +194,7 @@ public class FOText extends FONode implements CharSequence { | |||
/** {@inheritDoc} */ | |||
public void endOfNode() throws FOPException { | |||
if ( charBuffer != null ) { | |||
if (charBuffer != null) { | |||
charBuffer.rewind(); | |||
} | |||
super.endOfNode(); | |||
@@ -664,7 +664,7 @@ public class FOText extends FONode implements CharSequence { | |||
/** {@inheritDoc} */ | |||
public String toString() { | |||
if ( charBuffer == null ) { | |||
if (charBuffer == null) { | |||
return ""; | |||
} else { | |||
CharBuffer cb = charBuffer.duplicate(); | |||
@@ -717,7 +717,7 @@ public class FOText extends FONode implements CharSequence { | |||
} | |||
@Override | |||
public boolean isDelimitedTextRangeBoundary ( int boundary ) { | |||
public boolean isDelimitedTextRangeBoundary (int boundary) { | |||
return false; | |||
} | |||
@@ -737,16 +737,16 @@ public class FOText extends FONode implements CharSequence { | |||
* @param start the starting index of interval | |||
* @param end the ending index of interval | |||
*/ | |||
public void setBidiLevel ( int level, int start, int end ) { | |||
if ( start < end ) { | |||
if ( bidiLevels == null ) { | |||
public void setBidiLevel (int level, int start, int end) { | |||
if (start < end) { | |||
if (bidiLevels == null) { | |||
bidiLevels = new int [ length() ]; | |||
} | |||
for ( int i = start, n = end; i < n; i++ ) { | |||
for (int i = start, n = end; i < n; i++) { | |||
bidiLevels [ i ] = level; | |||
} | |||
if ( parent != null ) { | |||
( (FObj) parent ).setBidiLevel ( level ); | |||
if (parent != null) { | |||
((FObj) parent).setBidiLevel (level); | |||
} | |||
} else { | |||
assert start < end; | |||
@@ -771,12 +771,12 @@ public class FOText extends FONode implements CharSequence { | |||
* @return a (possibly empty) array of bidi levels or null | |||
* in case no bidi levels have been assigned | |||
*/ | |||
public int[] getBidiLevels ( int start, int end ) { | |||
if ( this.bidiLevels != null ) { | |||
public int[] getBidiLevels (int start, int end) { | |||
if (this.bidiLevels != null) { | |||
assert start <= end; | |||
int n = end - start; | |||
int[] bidiLevels = new int [ n ]; | |||
for ( int i = 0; i < n; i++ ) { | |||
for (int i = 0; i < n; i++) { | |||
bidiLevels[i] = this.bidiLevels [ start + i ]; | |||
} | |||
return bidiLevels; | |||
@@ -794,10 +794,10 @@ public class FOText extends FONode implements CharSequence { | |||
* @throws IndexOutOfBoundsException if position is not non-negative integer | |||
* or is greater than or equal to length | |||
*/ | |||
public int bidiLevelAt ( int position ) throws IndexOutOfBoundsException { | |||
if ( ( position < 0 ) || ( position >= length() ) ) { | |||
public int bidiLevelAt (int position) throws IndexOutOfBoundsException { | |||
if ((position < 0) || (position >= length())) { | |||
throw new IndexOutOfBoundsException(); | |||
} else if ( bidiLevels != null ) { | |||
} else if (bidiLevels != null) { | |||
return bidiLevels [ position ]; | |||
} else { | |||
return -1; | |||
@@ -810,11 +810,11 @@ public class FOText extends FONode implements CharSequence { | |||
* @param end index in character buffer | |||
* @param mappedChars sequence of character codes denoting substituted characters | |||
*/ | |||
public void addMapping ( int start, int end, CharSequence mappedChars ) { | |||
if ( mappings == null ) { | |||
public void addMapping (int start, int end, CharSequence mappedChars) { | |||
if (mappings == null) { | |||
mappings = new java.util.HashMap(); | |||
} | |||
mappings.put ( new MapRange ( start, end ), mappedChars.toString() ); | |||
mappings.put (new MapRange (start, end), mappedChars.toString()); | |||
} | |||
/** | |||
@@ -824,8 +824,8 @@ public class FOText extends FONode implements CharSequence { | |||
* @return true if a mapping exist such that the mapping's interval is coincident to | |||
* [start,end) | |||
*/ | |||
public boolean hasMapping ( int start, int end ) { | |||
return ( mappings != null ) && ( mappings.containsKey ( new MapRange ( start, end ) ) ); | |||
public boolean hasMapping (int start, int end) { | |||
return (mappings != null) && (mappings.containsKey (new MapRange (start, end))); | |||
} | |||
/** | |||
@@ -835,9 +835,9 @@ public class FOText extends FONode implements CharSequence { | |||
* @return a string of characters representing the mapping over the interval | |||
* [start,end) | |||
*/ | |||
public String getMapping ( int start, int end ) { | |||
if ( mappings != null ) { | |||
return (String) mappings.get ( new MapRange ( start, end ) ); | |||
public String getMapping (int start, int end) { | |||
if (mappings != null) { | |||
return (String) mappings.get (new MapRange (start, end)); | |||
} else { | |||
return null; | |||
} | |||
@@ -849,9 +849,9 @@ public class FOText extends FONode implements CharSequence { | |||
* @param end index in character buffer | |||
* @return the length of the mapping (if present) or zero | |||
*/ | |||
public int getMappingLength ( int start, int end ) { | |||
if ( mappings != null ) { | |||
return ( (String) mappings.get ( new MapRange ( start, end ) ) ) .length(); | |||
public int getMappingLength (int start, int end) { | |||
if (mappings != null) { | |||
return ((String) mappings.get (new MapRange (start, end))) .length(); | |||
} else { | |||
return 0; | |||
} | |||
@@ -864,37 +864,37 @@ public class FOText extends FONode implements CharSequence { | |||
* @return a (possibly empty) array of bidi levels or null | |||
* in case no bidi levels have been assigned | |||
*/ | |||
public int[] getMappingBidiLevels ( int start, int end ) { | |||
if ( hasMapping ( start, end ) ) { | |||
public int[] getMappingBidiLevels (int start, int end) { | |||
if (hasMapping (start, end)) { | |||
int nc = end - start; | |||
int nm = getMappingLength ( start, end ); | |||
int[] la = getBidiLevels ( start, end ); | |||
if ( la == null ) { | |||
int nm = getMappingLength (start, end); | |||
int[] la = getBidiLevels (start, end); | |||
if (la == null) { | |||
return null; | |||
} else if ( nm == nc ) { // mapping is same length as mapped range | |||
} else if (nm == nc) { // mapping is same length as mapped range | |||
return la; | |||
} else if ( nm > nc ) { // mapping is longer than mapped range | |||
} else if (nm > nc) { // mapping is longer than mapped range | |||
int[] ma = new int [ nm ]; | |||
System.arraycopy ( la, 0, ma, 0, la.length ); | |||
for ( int i = la.length, | |||
n = ma.length, l = ( i > 0 ) ? la [ i - 1 ] : 0; i < n; i++ ) { | |||
System.arraycopy (la, 0, ma, 0, la.length); | |||
for (int i = la.length, | |||
n = ma.length, l = (i > 0) ? la [ i - 1 ] : 0; i < n; i++) { | |||
ma [ i ] = l; | |||
} | |||
return ma; | |||
} else { // mapping is shorter than mapped range | |||
int[] ma = new int [ nm ]; | |||
System.arraycopy ( la, 0, ma, 0, ma.length ); | |||
System.arraycopy (la, 0, ma, 0, ma.length); | |||
return ma; | |||
} | |||
} else { | |||
return getBidiLevels ( start, end ); | |||
return getBidiLevels (start, end); | |||
} | |||
} | |||
@Override | |||
protected Stack collectDelimitedTextRanges ( Stack ranges, DelimitedTextRange currentRange ) { | |||
if ( currentRange != null ) { | |||
currentRange.append ( charIterator(), this ); | |||
protected Stack collectDelimitedTextRanges (Stack ranges, DelimitedTextRange currentRange) { | |||
if (currentRange != null) { | |||
currentRange.append (charIterator(), this); | |||
} | |||
return ranges; | |||
} | |||
@@ -907,12 +907,12 @@ public class FOText extends FONode implements CharSequence { | |||
this.end = end; | |||
} | |||
public int hashCode() { | |||
return ( start * 31 ) + end; | |||
return (start * 31) + end; | |||
} | |||
public boolean equals ( Object o ) { | |||
if ( o instanceof MapRange ) { | |||
public boolean equals (Object o) { | |||
if (o instanceof MapRange) { | |||
MapRange r = (MapRange) o; | |||
return ( r.start == start ) && ( r.end == end ); | |||
return (r.start == start) && (r.end == end); | |||
} else { | |||
return false; | |||
} |
@@ -608,14 +608,14 @@ public abstract class FObj extends FONode implements Constants { | |||
*/ | |||
public void setBidiLevel(int bidiLevel) { | |||
assert bidiLevel >= 0; | |||
if ( bidiLevel >= 0 ) { | |||
if ( ( this.bidiLevel < 0 ) || ( bidiLevel < this.bidiLevel ) ) { | |||
if (bidiLevel >= 0) { | |||
if ((this.bidiLevel < 0) || (bidiLevel < this.bidiLevel)) { | |||
this.bidiLevel = bidiLevel; | |||
if ( parent != null ) { | |||
if (parent != null) { | |||
FObj foParent = (FObj) parent; | |||
int parentBidiLevel = foParent.getBidiLevel(); | |||
if ( ( parentBidiLevel < 0 ) || ( bidiLevel < parentBidiLevel ) ) { | |||
foParent.setBidiLevel ( bidiLevel ); | |||
if ((parentBidiLevel < 0) || (bidiLevel < parentBidiLevel)) { | |||
foParent.setBidiLevel (bidiLevel); | |||
} | |||
} | |||
} | |||
@@ -639,10 +639,10 @@ public abstract class FObj extends FONode implements Constants { | |||
* any ancestor | |||
*/ | |||
public int getBidiLevelRecursive() { | |||
for ( FONode fn = this; fn != null; fn = fn.getParent() ) { | |||
if ( fn instanceof FObj ) { | |||
int level = ( (FObj) fn).getBidiLevel(); | |||
if ( level >= 0 ) { | |||
for (FONode fn = this; fn != null; fn = fn.getParent()) { | |||
if (fn instanceof FObj) { | |||
int level = ((FObj) fn).getBidiLevel(); | |||
if (level >= 0) { | |||
return level; | |||
} | |||
} |
@@ -302,7 +302,7 @@ public abstract class PropertyList { | |||
propID = -1; | |||
break; | |||
} | |||
} catch ( PropertyException e ) { | |||
} catch (PropertyException e) { | |||
propID = -1; | |||
} | |||
return propID; | |||
@@ -311,7 +311,7 @@ public abstract class PropertyList { | |||
private String addAttributeToList(Attributes attributes, | |||
String attributeName) throws ValidationException { | |||
String attributeValue = attributes.getValue(attributeName); | |||
if ( attributeValue != null ) { | |||
if (attributeValue != null) { | |||
convertAttributeToProperty(attributes, attributeName, attributeValue); | |||
} | |||
return attributeValue; |
@@ -42,10 +42,10 @@ public class FromNearestSpecifiedValueFunction extends FunctionBase { | |||
@Override | |||
/** {@inheritDoc} */ | |||
public Property getOptionalArgDefault(int index, PropertyInfo pi) throws PropertyException { | |||
if ( index == 0 ) { | |||
return getPropertyName ( pi ); | |||
if (index == 0) { | |||
return getPropertyName (pi); | |||
} else { | |||
return super.getOptionalArgDefault ( index, pi ); | |||
return super.getOptionalArgDefault (index, pi); | |||
} | |||
} | |||
@@ -43,10 +43,10 @@ public class FromParentFunction extends FunctionBase { | |||
@Override | |||
/** {@inheritDoc} */ | |||
public Property getOptionalArgDefault(int index, PropertyInfo pi) throws PropertyException { | |||
if ( index == 0 ) { | |||
return getPropertyName ( pi ); | |||
if (index == 0) { | |||
return getPropertyName (pi); | |||
} else { | |||
return super.getOptionalArgDefault ( index, pi ); | |||
return super.getOptionalArgDefault (index, pi); | |||
} | |||
} | |||
@@ -51,10 +51,10 @@ public class FromTableColumnFunction extends FunctionBase { | |||
@Override | |||
/** {@inheritDoc} */ | |||
public Property getOptionalArgDefault(int index, PropertyInfo pi) throws PropertyException { | |||
if ( index == 0 ) { | |||
return getPropertyName ( pi ); | |||
if (index == 0) { | |||
return getPropertyName (pi); | |||
} else { | |||
return super.getOptionalArgDefault ( index, pi ); | |||
return super.getOptionalArgDefault (index, pi); | |||
} | |||
} | |||
@@ -35,9 +35,9 @@ public abstract class FunctionBase implements Function { | |||
/** {@inheritDoc} */ | |||
public Property getOptionalArgDefault(int index, PropertyInfo pi) throws PropertyException { | |||
if ( index >= getOptionalArgsCount() ) { | |||
PropertyException e = new PropertyException ( new IndexOutOfBoundsException ( "illegal optional argument index" ) ); | |||
e.setPropertyInfo ( pi ); | |||
if (index >= getOptionalArgsCount()) { | |||
PropertyException e = new PropertyException (new IndexOutOfBoundsException ("illegal optional argument index")); | |||
e.setPropertyInfo (pi); | |||
throw e; | |||
} else { | |||
return null; | |||
@@ -58,7 +58,7 @@ public abstract class FunctionBase implements Function { | |||
* @param pi property information instance that applies to property being evaluated | |||
* @return string property whose value is name of property being evaluated | |||
*/ | |||
protected final Property getPropertyName ( PropertyInfo pi ) { | |||
return StringProperty.getInstance ( pi.getPropertyMaker().getName() ); | |||
protected final Property getPropertyName (PropertyInfo pi) { | |||
return StringProperty.getInstance (pi.getPropertyMaker().getName()); | |||
} | |||
} |
@@ -42,10 +42,10 @@ public class InheritedPropFunction extends FunctionBase { | |||
@Override | |||
/** {@inheritDoc} */ | |||
public Property getOptionalArgDefault(int index, PropertyInfo pi) throws PropertyException { | |||
if ( index == 0 ) { | |||
return getPropertyName ( pi ); | |||
if (index == 0) { | |||
return getPropertyName (pi); | |||
} else { | |||
return super.getOptionalArgDefault ( index, pi ); | |||
return super.getOptionalArgDefault (index, pi); | |||
} | |||
} | |||
@@ -370,10 +370,10 @@ public final class PropertyParser extends PropertyTokenizer { | |||
while (true) { | |||
Property p = parseAdditiveExpr(); | |||
int i = args.size(); | |||
if ( ( i < numReq ) || ( ( i - numReq ) < numOpt ) || hasVar ) { | |||
args.add ( p ); | |||
if ((i < numReq) || ((i - numReq) < numOpt) || hasVar) { | |||
args.add (p); | |||
} else { | |||
throw new PropertyException ( "Unexpected function argument at index " + i ); | |||
throw new PropertyException ("Unexpected function argument at index " + i); | |||
} | |||
// ignore extra args | |||
if (currentToken != TOK_COMMA) { | |||
@@ -384,16 +384,16 @@ public final class PropertyParser extends PropertyTokenizer { | |||
expectRpar(); | |||
} | |||
int numArgs = args.size(); | |||
if ( numArgs < numReq ) { | |||
if (numArgs < numReq) { | |||
throw new PropertyException("Expected " + numReq + " required arguments, but only " + numArgs + " specified"); | |||
} else { | |||
for ( int i = 0; i < numOpt; i++ ) { | |||
if ( args.size() < ( numReq + i + 1 ) ) { | |||
args.add ( function.getOptionalArgDefault ( i, propInfo ) ); | |||
for (int i = 0; i < numOpt; i++) { | |||
if (args.size() < (numReq + i + 1)) { | |||
args.add (function.getOptionalArgDefault (i, propInfo)); | |||
} | |||
} | |||
} | |||
return (Property[]) args.toArray ( new Property [ args.size() ] ); | |||
return (Property[]) args.toArray (new Property [ args.size() ]); | |||
} | |||
/** |
@@ -79,7 +79,7 @@ class PropertyTokenizer { | |||
currentTokenValue = null; | |||
currentTokenStartIndex = exprIndex; | |||
boolean bSawDecimal; | |||
while ( true ) { | |||
while (true) { | |||
if (exprIndex >= exprLength) { | |||
currentToken = TOK_EOF; | |||
return; | |||
@@ -254,8 +254,8 @@ class PropertyTokenizer { | |||
} | |||
private void scanRestOfName() { | |||
while ( ++exprIndex < exprLength ) { | |||
if ( !isNameChar ( expr.charAt ( exprIndex ) ) ) { | |||
while (++exprIndex < exprLength) { | |||
if (!isNameChar (expr.charAt (exprIndex))) { | |||
break; | |||
} | |||
} |
@@ -254,14 +254,14 @@ public abstract class AbstractGraphics extends FObj | |||
public abstract Length getIntrinsicAlignmentAdjust(); | |||
@Override | |||
public boolean isDelimitedTextRangeBoundary ( int boundary ) { | |||
public boolean isDelimitedTextRangeBoundary (int boundary) { | |||
return false; | |||
} | |||
@Override | |||
protected Stack collectDelimitedTextRanges ( Stack ranges, DelimitedTextRange currentRange ) { | |||
if ( currentRange != null ) { | |||
currentRange.append ( CharUtilities.OBJECT_REPLACEMENT_CHARACTER, this ); | |||
protected Stack collectDelimitedTextRanges (Stack ranges, DelimitedTextRange currentRange) { | |||
if (currentRange != null) { | |||
currentRange.append (CharUtilities.OBJECT_REPLACEMENT_CHARACTER, this); | |||
} | |||
return ranges; | |||
} |
@@ -201,14 +201,14 @@ public abstract class AbstractPageNumberCitation extends FObj | |||
} | |||
@Override | |||
public boolean isDelimitedTextRangeBoundary ( int boundary ) { | |||
public boolean isDelimitedTextRangeBoundary (int boundary) { | |||
return false; | |||
} | |||
@Override | |||
protected Stack collectDelimitedTextRanges ( Stack ranges, DelimitedTextRange currentRange ) { | |||
if ( currentRange != null ) { | |||
currentRange.append ( CharUtilities.OBJECT_REPLACEMENT_CHARACTER, this ); | |||
protected Stack collectDelimitedTextRanges (Stack ranges, DelimitedTextRange currentRange) { | |||
if (currentRange != null) { | |||
currentRange.append (CharUtilities.OBJECT_REPLACEMENT_CHARACTER, this); | |||
} | |||
return ranges; | |||
} |
@@ -122,7 +122,7 @@ public abstract class AbstractRetrieveMarker extends FObjMixed { | |||
newPropertyList); | |||
addChildTo(newChild, newParent); | |||
newChild.startOfNode(); | |||
switch ( newChild.getNameId() ) { | |||
switch (newChild.getNameId()) { | |||
case FO_TABLE: | |||
Table t = (Table) child; | |||
cloneSubtree(t.getColumns().iterator(), |
@@ -97,27 +97,27 @@ public class BidiOverride extends Inline { | |||
} | |||
@Override | |||
protected Stack collectDelimitedTextRanges ( Stack ranges, DelimitedTextRange currentRange ) { | |||
protected Stack collectDelimitedTextRanges (Stack ranges, DelimitedTextRange currentRange) { | |||
char pfx = 0; | |||
char sfx = 0; | |||
int unicodeBidi = getUnicodeBidi(); | |||
int direction = getDirection(); | |||
if ( unicodeBidi == Constants.EN_BIDI_OVERRIDE ) { | |||
pfx = ( direction == Constants.EN_RTL ) ? CharUtilities.RLO : CharUtilities.LRO; | |||
if (unicodeBidi == Constants.EN_BIDI_OVERRIDE) { | |||
pfx = (direction == Constants.EN_RTL) ? CharUtilities.RLO : CharUtilities.LRO; | |||
sfx = CharUtilities.PDF; | |||
} else if ( unicodeBidi == Constants.EN_EMBED ) { | |||
pfx = ( direction == Constants.EN_RTL ) ? CharUtilities.RLE : CharUtilities.LRE; | |||
} else if (unicodeBidi == Constants.EN_EMBED) { | |||
pfx = (direction == Constants.EN_RTL) ? CharUtilities.RLE : CharUtilities.LRE; | |||
sfx = CharUtilities.PDF; | |||
} | |||
if ( currentRange != null ) { | |||
if ( pfx != 0 ) { | |||
currentRange.append ( pfx, this ); | |||
if (currentRange != null) { | |||
if (pfx != 0) { | |||
currentRange.append (pfx, this); | |||
} | |||
for ( Iterator it = getChildNodes(); ( it != null ) && it.hasNext();) { | |||
ranges = ( (FONode) it.next() ).collectDelimitedTextRanges ( ranges ); | |||
for (Iterator it = getChildNodes(); (it != null) && it.hasNext();) { | |||
ranges = ((FONode) it.next()).collectDelimitedTextRanges (ranges); | |||
} | |||
if ( sfx != 0 ) { | |||
currentRange.append ( sfx, this ); | |||
if (sfx != 0) { | |||
currentRange.append (sfx, this); | |||
} | |||
} | |||
return ranges; |
@@ -98,7 +98,7 @@ public class BlockContainer extends FObj implements BreakPropertySet, WritingMod | |||
referenceOrientation = pList.get(PR_REFERENCE_ORIENTATION).getNumeric(); | |||
span = pList.get(PR_SPAN).getEnum(); | |||
writingModeTraits = new WritingModeTraits | |||
( WritingMode.valueOf(pList.get(PR_WRITING_MODE).getEnum()) ); | |||
(WritingMode.valueOf(pList.get(PR_WRITING_MODE).getEnum())); | |||
disableColumnBalancing = pList.get(PR_X_DISABLE_COLUMN_BALANCING).getEnum(); | |||
} | |||
@@ -236,14 +236,14 @@ public class Character extends FObj implements StructureTreeElementHolder { | |||
} | |||
@Override | |||
public boolean isDelimitedTextRangeBoundary ( int boundary ) { | |||
public boolean isDelimitedTextRangeBoundary (int boundary) { | |||
return false; | |||
} | |||
@Override | |||
protected Stack collectDelimitedTextRanges ( Stack ranges, DelimitedTextRange currentRange ) { | |||
if ( currentRange != null ) { | |||
currentRange.append ( charIterator(), this ); | |||
protected Stack collectDelimitedTextRanges (Stack ranges, DelimitedTextRange currentRange) { | |||
if (currentRange != null) { | |||
currentRange.append (charIterator(), this); | |||
} | |||
return ranges; | |||
} |
@@ -96,7 +96,7 @@ public class InlineContainer extends FObj { | |||
overflow = pList.get(PR_OVERFLOW).getEnum(); | |||
referenceOrientation = pList.get(PR_REFERENCE_ORIENTATION).getNumeric(); | |||
writingModeTraits = new WritingModeTraits | |||
( WritingMode.valueOf(pList.get(PR_WRITING_MODE).getEnum()) ); | |||
(WritingMode.valueOf(pList.get(PR_WRITING_MODE).getEnum())); | |||
} | |||
/** | |||
@@ -252,7 +252,7 @@ public class InlineContainer extends FObj { | |||
} | |||
@Override | |||
public boolean isDelimitedTextRangeBoundary ( int boundary ) { | |||
public boolean isDelimitedTextRangeBoundary (int boundary) { | |||
return false; | |||
} | |||
@@ -113,7 +113,7 @@ public abstract class InlineLevel extends FObjMixed implements CommonAccessibili | |||
} | |||
@Override | |||
public boolean isDelimitedTextRangeBoundary ( int boundary ) { | |||
public boolean isDelimitedTextRangeBoundary (int boundary) { | |||
return false; | |||
} | |||
@@ -116,12 +116,12 @@ public class Leader extends InlineLevel { | |||
protected void validateChildNode(Locator loc, String nsURI, String localName) | |||
throws ValidationException { | |||
if (FO_URI.equals(nsURI)) { | |||
if ( localName.equals("leader") | |||
if (localName.equals("leader") | |||
|| localName.equals("inline-container") | |||
|| localName.equals("block-container") | |||
|| localName.equals("float") | |||
|| localName.equals("marker") | |||
|| !isInlineItem(nsURI, localName) ) { | |||
|| !isInlineItem(nsURI, localName)) { | |||
invalidChildError(loc, nsURI, localName); | |||
} | |||
} | |||
@@ -203,12 +203,12 @@ public class Leader extends InlineLevel { | |||
} | |||
@Override | |||
protected Stack collectDelimitedTextRanges ( Stack ranges, DelimitedTextRange currentRange ) { | |||
if ( currentRange != null ) { | |||
if ( leaderPattern == EN_USECONTENT ) { | |||
ranges = super.collectDelimitedTextRanges ( ranges, currentRange ); | |||
protected Stack collectDelimitedTextRanges (Stack ranges, DelimitedTextRange currentRange) { | |||
if (currentRange != null) { | |||
if (leaderPattern == EN_USECONTENT) { | |||
ranges = super.collectDelimitedTextRanges (ranges, currentRange); | |||
} else { | |||
currentRange.append ( CharUtilities.OBJECT_REPLACEMENT_CHARACTER, this ); | |||
currentRange.append (CharUtilities.OBJECT_REPLACEMENT_CHARACTER, this); | |||
} | |||
} | |||
return ranges; |
@@ -206,14 +206,14 @@ public class ListItem extends FObj implements BreakPropertySet, CommonAccessibil | |||
} | |||
@Override | |||
protected Stack collectDelimitedTextRanges ( Stack ranges, DelimitedTextRange currentRange ) { | |||
protected Stack collectDelimitedTextRanges (Stack ranges, DelimitedTextRange currentRange) { | |||
ListItemLabel label = getLabel(); | |||
if ( label != null ) { | |||
ranges = label.collectDelimitedTextRanges ( ranges ); | |||
if (label != null) { | |||
ranges = label.collectDelimitedTextRanges (ranges); | |||
} | |||
ListItemBody body = getBody(); | |||
if ( body != null ) { | |||
ranges = body.collectDelimitedTextRanges ( ranges ); | |||
if (body != null) { | |||
ranges = body.collectDelimitedTextRanges (ranges); | |||
} | |||
return ranges; | |||
} |
@@ -201,7 +201,7 @@ public class PageNumber extends FObj | |||
} | |||
@Override | |||
public boolean isDelimitedTextRangeBoundary ( int boundary ) { | |||
public boolean isDelimitedTextRangeBoundary (int boundary) { | |||
return false; | |||
} | |||
@@ -150,7 +150,7 @@ public class Wrapper extends FObjMixed implements CommonAccessibilityHolder { | |||
} | |||
@Override | |||
public boolean isDelimitedTextRangeBoundary ( int boundary ) { | |||
public boolean isDelimitedTextRangeBoundary (int boundary) { | |||
return false; | |||
} | |||
@@ -77,7 +77,7 @@ public class ColumnNumberManager { | |||
for (int i = 0; i < pendingSpans.size(); i++) { | |||
pSpan = (PendingSpan) pendingSpans.get(i); | |||
if (pSpan != null) { | |||
if ( pSpan.decrRowsLeft() == 0 ) { | |||
if (pSpan.decrRowsLeft() == 0) { | |||
pendingSpans.set(i, null); | |||
} else { | |||
usedColumnIndices.set(i); |
@@ -75,10 +75,10 @@ public class ConditionalBorder { | |||
*/ | |||
ConditionalBorder(BorderSpecification borderSpecification, | |||
CollapsingBorderModel collapsingBorderModel) { | |||
this ( borderSpecification, borderSpecification, | |||
this (borderSpecification, borderSpecification, | |||
borderSpecification.getBorderInfo().getWidth().isDiscard() | |||
? BorderSpecification.getDefaultBorder() : borderSpecification, | |||
collapsingBorderModel ); | |||
collapsingBorderModel); | |||
} | |||
/** |
@@ -48,7 +48,7 @@ class PendingSpan { | |||
* @return number of rows spanned after decrementing | |||
*/ | |||
public int decrRowsLeft() { | |||
if ( rowsLeft > 0 ) { | |||
if (rowsLeft > 0) { | |||
return --rowsLeft; | |||
} else { | |||
return 0; |