Browse Source

Merged revisions 665740,665793,665995 via svnmerge from

https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk

........
  r665740 | adelmelle | 2008-06-09 17:20:08 +0100 (Mon, 09 Jun 2008) | 1 line
  
  Minor update: make the codegen-unicode target create LineBreakUtils.java at the appropriate place in the source tree
........
  r665793 | adelmelle | 2008-06-09 18:27:51 +0100 (Mon, 09 Jun 2008) | 9 lines
  
  Some updates (improvements?) in the UAX#14-related files:
  - LineBreakPairTable.txt: replace tabs with spaces to make the file a bit easier to read (constant column-width, instead of depending on an editor's settings for tabs)
  - GenerateLineBreakUtils.java:
    - generate a public final utility class
    - add some spacing in the generated file, after commas and before/after '=' (same styling as manually created files)
    - use Java 1.4 String.split() to tokenize lines, instead of StringTokenizer
    - add javadoc comments for public constants and methods
  - LineBreakUtils.java: regenerated after the above updates
........
  r665995 | maxberger | 2008-06-10 08:52:36 +0100 (Tue, 10 Jun 2008) | 1 line
  
  Replaced getLast() calls with calls to listUtil
........


git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AFPGOCAResources@666048 13f79535-47bb-0310-9956-ffa450edef68
tags/fop-1_0
Adrian Cumiskey 16 years ago
parent
commit
f25d75a80c

+ 7
- 4
build.xml View File

@@ -1418,9 +1418,10 @@ NOTE:

<!-- =================================================================== -->
<!-- Helper task to generate source files that have already been -->
<!-- checked into CVS. For these files, CVS version is the official one -->
<!-- and may have updates that will *not* be generated by below. This -->
<!-- target should never be part of the normal build process. -->
<!-- checked into the repository. For these files, the version in the -->
<!-- in the repository is the official one and may have updates that will-->
<!-- *not* be generated by below. -->
<!-- This target should never be part of the normal build process. -->
<!-- =================================================================== -->
<target name="codegen-unicode" >
<mkdir dir="${build.codegen-classes.dir}"/>
@@ -1429,7 +1430,9 @@ NOTE:
source="${javac.source}" target="${javac.target}">
<src path="${src.codegen.dir}/unicode/java"/>
</javac>
<java classname="org.apache.fop.text.linebreak.GenerateLineBreakUtils" classpath="${build.codegen-classes.dir}" />
<java classname="org.apache.fop.text.linebreak.GenerateLineBreakUtils" classpath="${build.codegen-classes.dir}">
<arg line="-o ${src.dir}/java/org/apache/fop/text/linebreak/LineBreakUtils.java" />
</java>
</target>

<!-- =================================================================== -->

+ 28
- 28
src/codegen/unicode/data/LineBreakPairTable.txt View File

@@ -1,28 +1,28 @@
OP CL QU GL NS EX SY IS PR PO NU AL ID IN HY BA BB B2 ZW CM WJ H2 H3 JL JV JT
OP ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ @ ^ ^ ^ ^ ^ ^
CL _ ^ % % ^ ^ ^ ^ % % % % _ _ % % _ _ ^ # ^ _ _ _ _ _
QU ^ ^ % % % ^ ^ ^ % % % % % % % % % % ^ # ^ % % % % %
GL % ^ % % % ^ ^ ^ % % % % % % % % % % ^ # ^ % % % % %
NS _ ^ % % % ^ ^ ^ _ _ _ _ _ _ % % _ _ ^ # ^ _ _ _ _ _
EX _ ^ % % % ^ ^ ^ _ _ _ _ _ _ % % _ _ ^ # ^ _ _ _ _ _
SY _ ^ % % % ^ ^ ^ _ _ % _ _ _ % % _ _ ^ # ^ _ _ _ _ _
IS _ ^ % % % ^ ^ ^ _ _ % % _ _ % % _ _ ^ # ^ _ _ _ _ _
PR % ^ % % % ^ ^ ^ _ _ % % % _ % % _ _ ^ # ^ % % % % %
PO % ^ % % % ^ ^ ^ _ _ % % _ _ % % _ _ ^ # ^ _ _ _ _ _
NU % ^ % % % ^ ^ ^ % % % % _ % % % _ _ ^ # ^ _ _ _ _ _
AL % ^ % % % ^ ^ ^ _ _ % % _ % % % _ _ ^ # ^ _ _ _ _ _
ID _ ^ % % % ^ ^ ^ _ % _ _ _ % % % _ _ ^ # ^ _ _ _ _ _
IN _ ^ % % % ^ ^ ^ _ _ _ _ _ % % % _ _ ^ # ^ _ _ _ _ _
HY _ ^ % % % ^ ^ ^ _ _ % _ _ _ % % _ _ ^ # ^ _ _ _ _ _
BA _ ^ % % % ^ ^ ^ _ _ _ _ _ _ % % _ _ ^ # ^ _ _ _ _ _
BB % ^ % % % ^ ^ ^ % % % % % % % % % % ^ # ^ % % % % %
B2 _ ^ % % % ^ ^ ^ _ _ _ _ _ _ % % _ ^ ^ # ^ _ _ _ _ _
ZW _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ^ _ _ _ _ _ _ _
CM _ ^ % % % ^ ^ ^ _ _ % % _ % % % _ _ ^ # ^ _ _ _ _ _
WJ % ^ % % % ^ ^ ^ % % % % % % % % % % ^ # ^ % % % % %
H2 _ ^ % % % ^ ^ ^ _ % _ _ _ % % % _ _ ^ # ^ _ _ _ % %
H3 _ ^ % % % ^ ^ ^ _ % _ _ _ % % % _ _ ^ # ^ _ _ _ _ %
JL _ ^ % % % ^ ^ ^ _ % _ _ _ % % % _ _ ^ # ^ % % % % _
JV _ ^ % % % ^ ^ ^ _ % _ _ _ % % % _ _ ^ # ^ _ _ _ % %
JT _ ^ % % % ^ ^ ^ _ % _ _ _ % % % _ _ ^ # ^ _ _ _ _ %
OP CL QU GL NS EX SY IS PR PO NU AL ID IN HY BA BB B2 ZW CM WJ H2 H3 JL JV JT
OP ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ @ ^ ^ ^ ^ ^ ^
CL _ ^ % % ^ ^ ^ ^ % % % % _ _ % % _ _ ^ # ^ _ _ _ _ _
QU ^ ^ % % % ^ ^ ^ % % % % % % % % % % ^ # ^ % % % % %
GL % ^ % % % ^ ^ ^ % % % % % % % % % % ^ # ^ % % % % %
NS _ ^ % % % ^ ^ ^ _ _ _ _ _ _ % % _ _ ^ # ^ _ _ _ _ _
EX _ ^ % % % ^ ^ ^ _ _ _ _ _ _ % % _ _ ^ # ^ _ _ _ _ _
SY _ ^ % % % ^ ^ ^ _ _ % _ _ _ % % _ _ ^ # ^ _ _ _ _ _
IS _ ^ % % % ^ ^ ^ _ _ % % _ _ % % _ _ ^ # ^ _ _ _ _ _
PR % ^ % % % ^ ^ ^ _ _ % % % _ % % _ _ ^ # ^ % % % % %
PO % ^ % % % ^ ^ ^ _ _ % % _ _ % % _ _ ^ # ^ _ _ _ _ _
NU % ^ % % % ^ ^ ^ % % % % _ % % % _ _ ^ # ^ _ _ _ _ _
AL % ^ % % % ^ ^ ^ _ _ % % _ % % % _ _ ^ # ^ _ _ _ _ _
ID _ ^ % % % ^ ^ ^ _ % _ _ _ % % % _ _ ^ # ^ _ _ _ _ _
IN _ ^ % % % ^ ^ ^ _ _ _ _ _ % % % _ _ ^ # ^ _ _ _ _ _
HY _ ^ % % % ^ ^ ^ _ _ % _ _ _ % % _ _ ^ # ^ _ _ _ _ _
BA _ ^ % % % ^ ^ ^ _ _ _ _ _ _ % % _ _ ^ # ^ _ _ _ _ _
BB % ^ % % % ^ ^ ^ % % % % % % % % % % ^ # ^ % % % % %
B2 _ ^ % % % ^ ^ ^ _ _ _ _ _ _ % % _ ^ ^ # ^ _ _ _ _ _
ZW _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ^ _ _ _ _ _ _ _
CM _ ^ % % % ^ ^ ^ _ _ % % _ % % % _ _ ^ # ^ _ _ _ _ _
WJ % ^ % % % ^ ^ ^ % % % % % % % % % % ^ # ^ % % % % %
H2 _ ^ % % % ^ ^ ^ _ % _ _ _ % % % _ _ ^ # ^ _ _ _ % %
H3 _ ^ % % % ^ ^ ^ _ % _ _ _ % % % _ _ ^ # ^ _ _ _ _ %
JL _ ^ % % % ^ ^ ^ _ % _ _ _ % % % _ _ ^ # ^ % % % % _
JV _ ^ % % % ^ ^ ^ _ % _ _ _ % % % _ _ ^ # ^ _ _ _ % %
JT _ ^ % % % ^ ^ ^ _ % _ _ _ % % % _ _ ^ # ^ _ _ _ _ %

+ 98
- 62
src/codegen/unicode/java/org/apache/fop/text/linebreak/GenerateLineBreakUtils.java View File

@@ -30,7 +30,6 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

/**
* <p>Utility for generating a Java class representing line break properties
@@ -55,6 +54,7 @@ public class GenerateLineBreakUtils {
private static final byte COMBINING_PROHIBITED_BREAK = 3; // @ in table
private static final byte PROHIBITED_BREAK = 4; // ^ in table
private static final byte EXPLICIT_BREAK = 5; // ! in rules
private static final String BREAK_CLASS_TOKENS = "_%#@^!";
private static final String notInPairTable[] = { "AI", "BK", "CB", "CR", "LF", "NL", "SA", "SG", "SP", "XX" };

private static final byte lineBreakProperties[] = new byte[0x10000];
@@ -103,27 +103,32 @@ public class GenerateLineBreakUtils {
BufferedReader b = new BufferedReader(new FileReader(breakPairFileName));
String line = b.readLine();
int lineNumber = 1;
String[] lineTokens;
String name;
// read header
if (line != null) {
StringTokenizer tok = new StringTokenizer(line);
lineTokens = line.split("\\s+");
byte columnNumber = 0;
while (tok.hasMoreTokens()) {
String name = tok.nextToken();
if (columnNumber >= columnHeader.length) {
throw new Exception(breakPairFileName + ':' + lineNumber + ": unexpected column header " + name);
}
if (notInPairTableMap.get(name) != null) {
throw new Exception(breakPairFileName + ':' + lineNumber + ": invalid column header " + name);
}
Byte v = (Byte)lineBreakPropertyValues.get(name);
if (v != null) {
byte vv = v.byteValue();
columnHeader[columnNumber] = vv;
columnMap[vv] = columnNumber;
} else {
throw new Exception(breakPairFileName + ':' + lineNumber + ": unknown column header " + name);
for (int i = 0; i < lineTokens.length; ++i) {
name = lineTokens[i];
if (name.length() > 0) {
if (columnNumber >= columnHeader.length) {
throw new Exception(breakPairFileName + ':' + lineNumber + ": unexpected column header " + name);
}
if (notInPairTableMap.get(name) != null) {
throw new Exception(breakPairFileName + ':' + lineNumber + ": invalid column header " + name);
}
Byte v = (Byte)lineBreakPropertyValues.get(name);
if (v != null) {
byte vv = v.byteValue();
columnHeader[columnNumber] = vv;
columnMap[vv] = columnNumber;
} else {
throw new Exception(breakPairFileName + ':' + lineNumber + ": unknown column header " + name);
}
columnNumber++;
}
columnNumber++;
}
if (columnNumber < columnHeader.length) {
StringBuffer missing = new StringBuffer();
@@ -156,9 +161,9 @@ public class GenerateLineBreakUtils {
throw new Exception(breakPairFileName + ':' + lineNumber + ": unexpected row " + line);
}
pairTable[rowNumber] = new byte[tableSize];
StringTokenizer tok = new StringTokenizer(line);
if (tok.hasMoreTokens()) {
String name = tok.nextToken();
lineTokens = line.split("\\s+");
if (lineTokens.length > 0) {
name = lineTokens[0];
if (notInPairTableMap.get(name) != null) {
throw new Exception(breakPairFileName + ':' + lineNumber + ": invalid row header " + name);
}
@@ -174,27 +179,15 @@ public class GenerateLineBreakUtils {
throw new Exception(breakPairFileName + ':' + lineNumber + ": can't read row header");
}
int columnNumber = 0;
while (tok.hasMoreTokens()) {
String token = tok.nextToken();
String token;
for (int i = 1; i < lineTokens.length; ++i) {
token = lineTokens[i];
if (token.length() == 1) {
switch (token.charAt(0)) {
case '^' :
pairTable[rowNumber][columnNumber] = PROHIBITED_BREAK;
break;
case '%' :
pairTable[rowNumber][columnNumber] = INDIRECT_BREAK;
break;
case '_' :
pairTable[rowNumber][columnNumber] = DIRECT_BREAK;
break;
case '#' :
pairTable[rowNumber][columnNumber] = COMBINING_INDIRECT_BREAK;
break;
case '@' :
pairTable[rowNumber][columnNumber] = COMBINING_PROHIBITED_BREAK;
break;
default :
throw new Exception(breakPairFileName + ':' + lineNumber + ": unexpected token: " + token);
byte tokenBreakClass = (byte)BREAK_CLASS_TOKENS.indexOf(token.charAt(0));
if (tokenBreakClass >= 0) {
pairTable[rowNumber][columnNumber] = tokenBreakClass;
} else {
throw new Exception(breakPairFileName + ':' + lineNumber + ": unexpected token: " + token);
}
} else {
throw new Exception(breakPairFileName + ':' + lineNumber + ": token too long: " + token);
@@ -255,23 +248,35 @@ public class GenerateLineBreakUtils {
out.println("package org.apache.fop.text.linebreak;");
out.println();
out.println("/* ");
out.println(" * This is a generated file, DO NOT CHANGE!");
out.println(" * !!! THIS IS A GENERATED FILE !!! ");
out.println(" * If updates to the source are needed, then:");
out.println(" * - apply the necessary modifications to ");
out.println(" * 'src/codegen/unicode/java/org/apache/fop/text/linebreak/GenerateLineBreakUtils.java'");
out.println(" * - run 'ant codegen-unicode', which will generate a new LineBreakUtils.java");
out.println(" * in 'src/java/org/apache/fop/text/linebreak'");
out.println(" * - commit BOTH changed files");
out.println(" */");
out.println();
out.println("class LineBreakUtils {");
out.println("public final class LineBreakUtils {");
out.println();
out.println(" /** Break class constant */");
out.println(" public static final byte DIRECT_BREAK = " + DIRECT_BREAK + ';');
out.println(" /** Break class constant */");
out.println(" public static final byte INDIRECT_BREAK = " + INDIRECT_BREAK + ';');
out.println(" /** Break class constant */");
out.println(" public static final byte COMBINING_INDIRECT_BREAK = " + COMBINING_INDIRECT_BREAK + ';');
out.println(" /** Break class constant */");
out.println(" public static final byte COMBINING_PROHIBITED_BREAK = " + COMBINING_PROHIBITED_BREAK + ';');
out.println(" /** Break class constant */");
out.println(" public static final byte PROHIBITED_BREAK = " + PROHIBITED_BREAK + ';');
out.println(" /** Break class constant */");
out.println(" public static final byte EXPLICIT_BREAK = " + EXPLICIT_BREAK + ';');
out.println();
out.println(" private static final byte PAIR_TABLE[][] = {");
boolean printComma = false;
for (int i = 1; i <= lineBreakPropertyValueCount; i++) {
if (printComma) {
out.println(',');
out.println(", ");
} else {
printComma = true;
}
@@ -279,7 +284,7 @@ public class GenerateLineBreakUtils {
boolean localPrintComma = false;
for (int j = 1; j <= lineBreakPropertyValueCount; j++) {
if (localPrintComma) {
out.print(',');
out.print(", ");
} else {
localPrintComma = true;
}
@@ -313,7 +318,7 @@ public class GenerateLineBreakUtils {
found = true;
doStaticLinkCode.append(" lineBreakProperties[");
doStaticLinkCode.append(i);
doStaticLinkCode.append("]=lineBreakProperties[");
doStaticLinkCode.append("] = lineBreakProperties[");
doStaticLinkCode.append(j);
doStaticLinkCode.append("];\n");
break;
@@ -322,7 +327,7 @@ public class GenerateLineBreakUtils {
}
if (!found) {
if (rowsPrinted >= 64) {
out.println(" };");
out.println(" }");
out.println();
initSections++;
out.println(" private static void init_" + initSections + "() {");
@@ -334,7 +339,7 @@ public class GenerateLineBreakUtils {
for (int k = 0; k < blocksize; k++) {
row[i][k] = lineBreakProperties[idx + k];
if (printLocalComma) {
out.print(',');
out.print(", ");
} else {
printLocalComma = true;
}
@@ -345,20 +350,21 @@ public class GenerateLineBreakUtils {
}
idx += blocksize;
}
out.println(" };");
out.println(" }");
out.println();
out.println(" static {");
for (int i = 0; i <= initSections; i++) {
out.println(" init_" + i + "();");
}
out.print(doStaticLinkCode);
out.println(" };");
out.println(" }");
out.println();
for (int i = 0; i < lineBreakPropertyShortNames.size(); i++) {
String shortName = (String)lineBreakPropertyShortNames.get(i);
out.println(" /** Linebreak property constant */");
out.print(" public static final byte LINE_BREAK_PROPERTY_");
out.print(shortName);
out.print('=');
out.print(" = ");
out.print(i + 1);
out.println(';');
}
@@ -368,9 +374,9 @@ public class GenerateLineBreakUtils {
int lineLength = shortNamePrefix.length();
printComma = false;
for (int i = 0; i < lineBreakPropertyShortNames.size(); i++) {
String name = (String)lineBreakPropertyShortNames.get(i);
name = (String)lineBreakPropertyShortNames.get(i);
if (printComma) {
out.print(',');
out.print(", ");
lineLength++;
} else {
printComma = true;
@@ -392,7 +398,7 @@ public class GenerateLineBreakUtils {
lineLength = longNamePrefix.length();
printComma = false;
for (int i = 0; i < lineBreakPropertyLongNames.size(); i++) {
String name = (String)lineBreakPropertyLongNames.get(i);
name = (String)lineBreakPropertyLongNames.get(i);
if (printComma) {
out.print(',');
lineLength++;
@@ -411,32 +417,62 @@ public class GenerateLineBreakUtils {
}
out.println("};");
out.println();
out.println(" /**");
out.println(" * Return the short name for the linebreak property corresponding ");
out.println(" * to the given symbolic constant.");
out.println(" *");
out.println(" * @param i the numeric value of the linebreak property");
out.println(" * @return the short name of the linebreak property");
out.println(" */");
out.println(" public static String getLineBreakPropertyShortName(byte i) {");
out.println(" if (i>0 && i<=lineBreakPropertyShortNames.length) {");
out.println(" return lineBreakPropertyShortNames[i-1];");
out.println(" if (i > 0 && i <= lineBreakPropertyShortNames.length) {");
out.println(" return lineBreakPropertyShortNames[i - 1];");
out.println(" } else {");
out.println(" return null;");
out.println(" }");
out.println(" }");
out.println();
out.println(" /**");
out.println(" * Return the long name for the linebreak property corresponding ");
out.println(" * to the given symbolic constant.");
out.println(" *");
out.println(" * @param i the numeric value of the linebreak property");
out.println(" * @return the long name of the linebreak property");
out.println(" */");
out.println(" public static String getLineBreakPropertyLongName(byte i) {");
out.println(" if (i>0 && i<=lineBreakPropertyLongNames.length) {");
out.println(" return lineBreakPropertyLongNames[i-1];");
out.println(" if (i > 0 && i <= lineBreakPropertyLongNames.length) {");
out.println(" return lineBreakPropertyLongNames[i - 1];");
out.println(" } else {");
out.println(" return null;");
out.println(" }");
out.println(" }");
out.println();
out.println(" /**");
out.println(" * Return the linebreak property constant for the given <code>char</code>");
out.println(" *");
out.println(" * @param c the <code>char</code> whose linebreak property to return");
out.println(" * @return the constant representing the linebreak property");
out.println(" */");
out.println(" public static byte getLineBreakProperty(char c) {");
out.println(" return lineBreakProperties[c/" + blocksize + "][c%" + blocksize + "];");
out.println(" return lineBreakProperties[c / " + blocksize + "][c % " + blocksize + "];");
out.println(" }");
out.println();
out.println(" /**");
out.println(" * Return the break class constant for the given pair of linebreak ");
out.println(" * property constants.");
out.println(" *");
out.println(" * @param lineBreakPropertyBefore the linebreak property for the first character");
out.println(" * in a two-character sequence");
out.println(" * @param lineBreakPropertyAfter the linebreak property for the second character");
out.println(" * in a two-character sequence");
out.println(" * @return the constant representing the break class");
out.println(" */");
out.println(
" public static byte getLineBreakPairProperty(int lineBreakPropertyBefore,int lineBreakPropertyAfter) {");
out.println(" return PAIR_TABLE[lineBreakPropertyBefore-1][lineBreakPropertyAfter-1];");
" public static byte getLineBreakPairProperty(int lineBreakPropertyBefore, int lineBreakPropertyAfter) {");
out.println(" return PAIR_TABLE[lineBreakPropertyBefore - 1][lineBreakPropertyAfter - 1];");
out.println(" }");
out.println();
out.println("};");
out.println("}");
out.flush();
out.close();
}

+ 14
- 14
src/java/org/apache/fop/layoutmgr/AbstractBreaker.java View File

@@ -28,6 +28,7 @@ import org.apache.commons.logging.LogFactory;

import org.apache.fop.fo.Constants;
import org.apache.fop.traits.MinOptMax;
import org.apache.fop.util.ListUtil;

/**
* Abstract base class for breakers (page breakers, static region handlers etc.).
@@ -116,8 +117,8 @@ public abstract class AbstractBreaker {
public KnuthSequence endSequence(Position breakPosition) {
// remove glue and penalty item at the end of the paragraph
while (this.size() > ignoreAtStart
&& !((KnuthElement)this.get(this.size() - 1)).isBox()) {
this.remove(this.size() - 1);
&& !((KnuthElement) ListUtil.getLast(this)).isBox()) {
ListUtil.removeLast(this);
}
if (this.size() > ignoreAtStart) {
// add the elements representing the space at the end of the last line
@@ -215,7 +216,7 @@ public abstract class AbstractBreaker {

/** @return true if there's no content that could be handled. */
public boolean isEmpty() {
return (this.blockLists.size() == 0);
return (this.blockLists.isEmpty());
}
protected void startPart(BlockSequence list, int breakClass) {
@@ -551,7 +552,7 @@ public abstract class AbstractBreaker {
BlockSequence blockList;
List returnedList = getNextKnuthElements(childLC, alignment);
if (returnedList != null) {
if (returnedList.size() == 0) {
if (returnedList.isEmpty()) {
nextSequenceStartsOn = handleSpanChange(childLC, nextSequenceStartsOn);
return nextSequenceStartsOn;
}
@@ -561,10 +562,9 @@ public abstract class AbstractBreaker {
nextSequenceStartsOn = handleSpanChange(childLC, nextSequenceStartsOn);
Position breakPosition = null;
if (((KnuthElement) returnedList.get(returnedList.size() - 1))
.isForcedBreak()) {
KnuthPenalty breakPenalty = (KnuthPenalty) returnedList
.remove(returnedList.size() - 1);
if (((KnuthElement) ListUtil.getLast(returnedList)).isForcedBreak()) {
KnuthPenalty breakPenalty = (KnuthPenalty) ListUtil
.removeLast(returnedList);
breakPosition = breakPenalty.getPosition();
switch (breakPenalty.getBreakClass()) {
case Constants.EN_PAGE:
@@ -745,12 +745,12 @@ public abstract class AbstractBreaker {
if (!bBoxSeen) {
// this is the first box met in this page
bBoxSeen = true;
} else if (unconfirmedList.size() > 0) {
// glue items in unconfirmedList were not after
// the last box
// in this page; they must be added to
// blockSpaceList
while (unconfirmedList.size() > 0) {
} else {
while (!unconfirmedList.isEmpty()) {
// glue items in unconfirmedList were not after
// the last box
// in this page; they must be added to
// blockSpaceList
KnuthGlue blockSpace = (KnuthGlue) unconfirmedList
.removeFirst();
spaceMaxAdjustment.max += ((KnuthGlue) blockSpace)

+ 10
- 8
src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java View File

@@ -39,6 +39,7 @@ import org.apache.fop.fo.flow.BlockContainer;
import org.apache.fop.fo.properties.CommonAbsolutePosition;
import org.apache.fop.traits.MinOptMax;
import org.apache.fop.traits.SpaceVal;
import org.apache.fop.util.ListUtil;

/**
* LayoutManager for a block-container FO.
@@ -285,7 +286,7 @@ public class BlockContainerLayoutManager extends BlockStackingLayoutManager

// get elements from curLM
returnedList = curLM.getNextKnuthElements(childLC, alignment);
if (contentList.size() == 0 && childLC.isKeepWithPreviousPending()) {
if (contentList.isEmpty() && childLC.isKeepWithPreviousPending()) {
//Propagate keep-with-previous up from the first child
context.updateKeepWithPreviousPending(childLC.getKeepWithPreviousPending());
childLC.clearKeepWithPreviousPending();
@@ -317,12 +318,12 @@ public class BlockContainerLayoutManager extends BlockStackingLayoutManager
addInBetweenBreak(contentList, context, childLC);
}
contentList.addAll(returnedList);
if (returnedList.size() == 0) {
if (returnedList.isEmpty()) {
//Avoid NoSuchElementException below (happens with empty blocks)
continue;
}
if (((ListElement) returnedList
.get(returnedList.size() - 1)).isForcedBreak()) {
if (((ListElement) ListUtil.getLast(returnedList))
.isForcedBreak()) {
// a descendant of this block has break-after
if (curLM.isFinished()) {
// there is no other content in this block;
@@ -754,7 +755,7 @@ public class BlockContainerLayoutManager extends BlockStackingLayoutManager
// pos was created by this BCLM and was inside an element
// representing space before or after
// this means the space was not discarded
if (positionList.size() == 0 && bcpos == null) {
if (positionList.isEmpty() && bcpos == null) {
// pos was in the element representing space-before
bSpaceBefore = true;
} else {
@@ -801,9 +802,10 @@ public class BlockContainerLayoutManager extends BlockStackingLayoutManager
// // between consecutive pages
List splitList = new LinkedList();
int splitLength = 0;
int iFirst = ((MappingPosition) positionList.get(0)).getFirstIndex();
int iLast = ((MappingPosition) positionList.get(positionList
.size() - 1)).getLastIndex();
int iFirst = ((MappingPosition) positionList.get(0))
.getFirstIndex();
int iLast = ((MappingPosition) ListUtil.getLast(positionList))
.getLastIndex();
// copy from storedList to splitList all the elements from
// iFirst to iLast
ListIterator storedListIterator = storedList.listIterator(iFirst);

+ 15
- 15
src/java/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java View File

@@ -36,6 +36,7 @@ import org.apache.fop.fo.properties.SpaceProperty;
import org.apache.fop.layoutmgr.inline.InlineLayoutManager;
import org.apache.fop.layoutmgr.inline.LineLayoutManager;
import org.apache.fop.traits.MinOptMax;
import org.apache.fop.util.ListUtil;

/**
* Base LayoutManager class for all areas which stack their child
@@ -296,7 +297,7 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager

// get elements from curLM
returnedList = curLM.getNextKnuthElements(childLC, alignment);
if (contentList.size() == 0 && childLC.isKeepWithPreviousPending()) {
if (contentList.isEmpty() && childLC.isKeepWithPreviousPending()) {
//Propagate keep-with-previous up from the first child
context.updateKeepWithPreviousPending(childLC.getKeepWithPreviousPending());
childLC.clearKeepWithPreviousPending();
@@ -312,7 +313,7 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
break;
}

if (contentList.size() == 0) {
if (contentList.isEmpty()) {
// Empty fo:block, zero-length box makes sure the IDs and/or markers
// are registered and borders/padding are painted.
returnList.add(new KnuthBox(0, notifyPos(new Position(this)), false));
@@ -339,17 +340,17 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
// before the one handled by curLM
addInBetweenBreak(contentList, context, childLC);
}
if (returnedList == null || returnedList.size() == 0) {
if (returnedList == null || returnedList.isEmpty()) {
//Avoid NoSuchElementException below (happens with empty blocks)
continue;
}
contentList.addAll(returnedList);
if (((ListElement) returnedList.get(returnedList.size() - 1))
if (((ListElement) ListUtil.getLast(returnedList))
.isForcedBreak()) {
// a descendant of this block has break-after
if (curLM.isFinished() && !hasNextChildLM()) {
forcedBreakAfterLast = (BreakElement) contentList
.remove(contentList.size() - 1);
forcedBreakAfterLast = (BreakElement) ListUtil
.removeLast(contentList);
context.clearPendingMarks();
break;
}
@@ -381,7 +382,7 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
/* end of extension */

returnedList = new LinkedList();
if (contentList.size() > 0) {
if (!contentList.isEmpty()) {
wrapPositionElements(contentList, returnList);
} else if (forcedBreakAfterLast == null) {
// Empty fo:block, zero-length box makes sure the IDs and/or markers
@@ -440,8 +441,7 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
return;
}
ListElement last = (ListElement) contentList
.get(contentList.size() - 1);
ListElement last = (ListElement) ListUtil.getLast(contentList);
if (last.isGlue()) {
// the last element in contentList is a glue;
// it is a feasible breakpoint, there is no need to add
@@ -695,8 +695,8 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
returnedList.add(new KnuthPenalty(0, KnuthElement.INFINITE, false,
new Position(this), false));
} else if (bSomethingAdded
&& !((KnuthElement) returnedList.get(returnedList
.size() - 1)).isGlue()) {
&& !((KnuthElement) ListUtil.getLast(returnedList))
.isGlue()) {
// add a null penalty to allow a break between blocks
returnedList.add(new KnuthPenalty(0, 0, false, new Position(this), false));
}
@@ -715,8 +715,8 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
// currLM == this
// there are no more elements to add
// remove the last penalty added to returnedList
if (returnedList.size() > 0) {
returnedList.remove(returnedList.size() - 1);
if (!returnedList.isEmpty()) {
ListUtil.removeLast(returnedList);
}
//log.debug(" BLM.getChangedKnuthElements> elementi propri, ignorati, da "
// + fromIndex + " a " + workList.size());
@@ -1407,7 +1407,7 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
oldList.remove(0);
}
if (adjustedSpaceAfter > 0) {
oldList.remove(oldList.size() - 1);
ListUtil.removeLast(oldList);
}

// if space-before.conditionality is "discard", correct newList
@@ -1464,7 +1464,7 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
newList.addLast(new KnuthBox(wrongBox.getW() - decreasedLength,
wrongBox.getPosition(), false));
// add preserved elements
if (preserveList.size() > 0) {
if (!preserveList.isEmpty()) {
newList.addAll(preserveList);
}
// insert the correct glue

+ 8
- 4
src/java/org/apache/fop/layoutmgr/ElementListUtils.java View File

@@ -19,16 +19,20 @@

package org.apache.fop.layoutmgr;

import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;

import org.apache.fop.traits.MinOptMax;
import org.apache.fop.util.ListUtil;

/**
* Utilities for Knuth element lists.
*/
public class ElementListUtils {
public final class ElementListUtils {
private ElementListUtils() {
// Utility class.
}

/**
* Removes legal breaks in an element list. A constraint can be specified to limit the
@@ -185,7 +189,7 @@ public class ElementListUtils {
* @return true if the list ends with a forced break
*/
public static boolean endsWithForcedBreak(List elems) {
ListElement last = (ListElement) elems.get(elems.size() - 1);
ListElement last = (ListElement) ListUtil.getLast(elems);
return last.isForcedBreak();
}

@@ -196,7 +200,7 @@ public class ElementListUtils {
* @return true if the list ends with a non-infinite penalty
*/
public static boolean endsWithNonInfinitePenalty(List elems) {
ListElement last = (ListElement) elems.get(elems.size() - 1);
ListElement last = (ListElement) ListUtil.getLast(elems);
if (last.isPenalty() && ((KnuthPenalty)last).getP() < KnuthElement.INFINITE) {
return true;
} else if (last instanceof BreakElement

+ 10
- 9
src/java/org/apache/fop/layoutmgr/StaticContentLayoutManager.java View File

@@ -38,6 +38,7 @@ import org.apache.fop.layoutmgr.PageBreakingAlgorithm.PageBreakingLayoutListener
import org.apache.fop.layoutmgr.inline.InlineLevelLayoutManager;
import org.apache.fop.layoutmgr.inline.TextLayoutManager;
import org.apache.fop.traits.MinOptMax;
import org.apache.fop.util.ListUtil;

/**
* LayoutManager for an fo:flow object.
@@ -142,7 +143,7 @@ public class StaticContentLayoutManager extends BlockStackingLayoutManager {
returnList.addAll(returnedList);
return returnList;
} else {
if (returnList.size() > 0) {
if (!returnList.isEmpty()) {
// there is a block before this one
if (prevLM.mustKeepWithNext()
|| curLM.mustKeepWithPrevious()) {
@@ -150,16 +151,16 @@ public class StaticContentLayoutManager extends BlockStackingLayoutManager {
returnList.add(new KnuthPenalty(0,
KnuthElement.INFINITE, false,
new Position(this), false));
} else if (!((KnuthElement) returnList.get(returnList
.size() - 1)).isGlue()) {
} else if (!((KnuthElement) ListUtil.getLast(returnList))
.isGlue()) {
// add a null penalty to allow a break between blocks
returnList.add(new KnuthPenalty(0, 0, false, new Position(this), false));
}
}
/*LF*/ if (returnedList.size() > 0) { // controllare!
/*LF*/ if (!returnedList.isEmpty()) { // controllare!
returnList.addAll(returnedList);
final KnuthElement last = (KnuthElement) returnedList
.get(returnedList.size() - 1);
final KnuthElement last = (KnuthElement) ListUtil
.getLast(returnedList);
if (last.isPenalty()
&& ((KnuthPenalty) last).getP() == -KnuthElement.INFINITE) {
// a descendant of this flow has break-after
@@ -173,10 +174,10 @@ public class StaticContentLayoutManager extends BlockStackingLayoutManager {

setFinished(true);

if (returnList.size() > 0) {
return returnList;
} else {
if (returnList.isEmpty()) {
return null;
} else {
return returnList;
}
}

+ 7
- 7
src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java View File

@@ -56,6 +56,7 @@ import org.apache.fop.layoutmgr.SpaceSpecifier;
import org.apache.fop.layoutmgr.TraitSetter;
import org.apache.fop.traits.MinOptMax;
import org.apache.fop.traits.SpaceVal;
import org.apache.fop.util.ListUtil;

/**
* LayoutManager for objects which stack children in the inline direction,
@@ -312,11 +313,11 @@ public class InlineLayoutManager extends InlineStackingLayoutManager {
// get KnuthElements from curLM
returnedList = curLM.getNextKnuthElements(childLC, alignment);
if (returnList.size() == 0 && childLC.isKeepWithPreviousPending()) {
if (returnList.isEmpty() && childLC.isKeepWithPreviousPending()) {
childLC.clearKeepWithPreviousPending();
}
if (returnedList == null
|| returnedList.size() == 0) {
|| returnedList.isEmpty()) {
// curLM returned null or an empty list, because it finished;
// just iterate once more to see if there is another child
continue;
@@ -335,7 +336,7 @@ public class InlineLayoutManager extends InlineStackingLayoutManager {
returnedList.remove(0);
}
// add border and padding to the first complete sequence of this LM
if (!borderAdded && returnedList.size() != 0) {
if (!borderAdded && !returnedList.isEmpty()) {
addKnuthElementsForBorderPaddingStart((KnuthSequence) returnedList.get(0));
borderAdded = true;
}
@@ -367,8 +368,7 @@ public class InlineLayoutManager extends InlineStackingLayoutManager {
context.updateKeepWithNextPending(childLC.getKeepWithNextPending());
childLC.clearKeepsPending();
}
lastSequence = (KnuthSequence) returnList
.get(returnList.size() - 1);
lastSequence = (KnuthSequence) ListUtil.getLast(returnList);
lastChildLM = curLM;
}
@@ -379,7 +379,7 @@ public class InlineLayoutManager extends InlineStackingLayoutManager {
setFinished(true);
log.trace(trace);
if (returnList.size() == 0) {
if (returnList.isEmpty()) {
/*
* if the FO itself is empty, but has an id specified
* or associated fo:markers, then we still need a dummy
@@ -396,7 +396,7 @@ public class InlineLayoutManager extends InlineStackingLayoutManager {
}
}
return returnList.size() == 0 ? null : returnList;
return returnList.isEmpty() ? null : returnList;
}

/**

+ 3
- 2
src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java View File

@@ -46,6 +46,7 @@ import org.apache.fop.text.linebreak.LineBreakStatus;
import org.apache.fop.traits.MinOptMax;
import org.apache.fop.traits.SpaceVal;
import org.apache.fop.util.CharUtilities;
import org.apache.fop.util.ListUtil;

/**
* LayoutManager for text (a sequence of characters) which generates one
@@ -624,9 +625,9 @@ public class TextLayoutManager extends LeafNodeLayoutManager {
sequence = this.processLinebreak(returnList, sequence);
}

if (((List) returnList.get(returnList.size() - 1)).isEmpty()) {
if (((List) ListUtil.getLast(returnList)).isEmpty()) {
//Remove an empty sequence because of a trailing newline
returnList.remove(returnList.size() - 1);
ListUtil.removeLast(returnList);
}
this.setFinished(true);

+ 6
- 6
src/java/org/apache/fop/layoutmgr/table/TableCellLayoutManager.java View File

@@ -27,7 +27,6 @@ import org.apache.commons.logging.LogFactory;
import org.apache.fop.area.Area;
import org.apache.fop.area.Block;
import org.apache.fop.area.Trait;
import org.apache.fop.fo.flow.ListItem;
import org.apache.fop.fo.flow.table.ConditionalBorder;
import org.apache.fop.fo.flow.table.GridUnit;
import org.apache.fop.fo.flow.table.PrimaryGridUnit;
@@ -53,6 +52,7 @@ import org.apache.fop.layoutmgr.SpaceResolver;
import org.apache.fop.layoutmgr.TraitSetter;
import org.apache.fop.traits.BorderProps;
import org.apache.fop.traits.MinOptMax;
import org.apache.fop.util.ListUtil;

/**
* LayoutManager for a table-cell FO.
@@ -152,7 +152,7 @@ public class TableCellLayoutManager extends BlockStackingLayoutManager
if (childLC.isKeepWithNextPending()) {
log.debug("child LM signals pending keep with next");
}
if (contentList.size() == 0 && childLC.isKeepWithPreviousPending()) {
if (contentList.isEmpty() && childLC.isKeepWithPreviousPending()) {
primaryGridUnit.setKeepWithPreviousStrength(childLC.getKeepWithPreviousPending());
childLC.clearKeepWithPreviousPending();
}
@@ -163,7 +163,7 @@ public class TableCellLayoutManager extends BlockStackingLayoutManager
addInBetweenBreak(contentList, context, childLC);
}
contentList.addAll(returnedList);
if (returnedList.size() == 0) {
if (returnedList.isEmpty()) {
//Avoid NoSuchElementException below (happens with empty blocks)
continue;
}
@@ -177,7 +177,7 @@ public class TableCellLayoutManager extends BlockStackingLayoutManager
primaryGridUnit.setKeepWithNextStrength(context.getKeepWithNextPending());

returnedList = new LinkedList();
if (contentList.size() > 0) {
if (!contentList.isEmpty()) {
wrapPositionElements(contentList, returnList);
} else {
// In relaxed validation mode, table-cells having no children are authorised.
@@ -193,8 +193,8 @@ public class TableCellLayoutManager extends BlockStackingLayoutManager
returnList.remove(0);
assert !returnList.isEmpty();
}
final KnuthElement lastItem = (KnuthElement) returnList
.get(returnList.size() - 1);
final KnuthElement lastItem = (KnuthElement) ListUtil
.getLast(returnList);
if (((KnuthElement) lastItem).isForcedBreak()) {
KnuthPenalty p = (KnuthPenalty) lastItem;
primaryGridUnit.setBreakAfter(p.getBreakClass());

+ 678
- 600
src/java/org/apache/fop/text/linebreak/LineBreakUtils.java
File diff suppressed because it is too large
View File


+ 55
- 0
src/java/org/apache/fop/util/ListUtil.java View File

@@ -0,0 +1,55 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/* $Id$ */

package org.apache.fop.util;

import java.util.List;

/**
* Provides helper functions for {@link java.util.List}.
*
*/
public final class ListUtil {

private ListUtil() {
// Utility class.
}

/**
* Retrieve the last element from a list.
*
* @param list
* The list to work on
* @return last element
*/
public static Object getLast(List list) {
return list.get(list.size() - 1);
}

/**
* Retrieve and remove the last element from a list.
*
* @param list
* The list to work on
* @return previous last element
*/
public static Object removeLast(List list) {
return list.remove(list.size() - 1);
}
}

Loading…
Cancel
Save