aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache
diff options
context:
space:
mode:
authorAndreas L. Delmelle <adelmelle@apache.org>2008-06-07 15:09:42 +0000
committerAndreas L. Delmelle <adelmelle@apache.org>2008-06-07 15:09:42 +0000
commitff51233ed95afb0a54a6e47c6bed5890af5b5304 (patch)
treedfd06c3371f7b03d91fa190e483f3b8adac14e74 /src/java/org/apache
parentbcf8379cf44f09ed3a78873fda6241f944b6d461 (diff)
downloadxmlgraphics-fop-ff51233ed95afb0a54a6e47c6bed5890af5b5304.tar.gz
xmlgraphics-fop-ff51233ed95afb0a54a6e47c6bed5890af5b5304.zip
Improve code-readability; add some clarifying comments
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@664350 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache')
-rw-r--r--src/java/org/apache/fop/text/linebreak/LineBreakStatus.java139
1 files changed, 81 insertions, 58 deletions
diff --git a/src/java/org/apache/fop/text/linebreak/LineBreakStatus.java b/src/java/org/apache/fop/text/linebreak/LineBreakStatus.java
index 2f513c59c..44b27889a 100644
--- a/src/java/org/apache/fop/text/linebreak/LineBreakStatus.java
+++ b/src/java/org/apache/fop/text/linebreak/LineBreakStatus.java
@@ -73,76 +73,99 @@ public class LineBreakStatus {
* @return the break action to be taken
*/
public byte nextChar(char c) {
+
byte currentClass = LineBreakUtils.getLineBreakProperty(c);
+
if (currentClass == LineBreakUtils.LINE_BREAK_PROPERTY_AI
|| leftClass == LineBreakUtils.LINE_BREAK_PROPERTY_XX) {
+ //current "Ambiguous" or previous "Unknown":
+ // assume current "Alphabetic"
currentClass = LineBreakUtils.LINE_BREAK_PROPERTY_AL;
- } else if (currentClass == LineBreakUtils.LINE_BREAK_PROPERTY_NL) {
- currentClass = LineBreakUtils.LINE_BREAK_PROPERTY_BK;
}
- if (leftClass == -1) {
- if (currentClass == LineBreakUtils.LINE_BREAK_PROPERTY_LF) {
- leftClass = LineBreakUtils.LINE_BREAK_PROPERTY_BK;
- } else {
+
+ /** Check 1: initial character after a reset/mandatory break? */
+ switch (leftClass) {
+ case -1:
+ //first character after a reset()
leftClass = currentClass;
if (leftClass == LineBreakUtils.LINE_BREAK_PROPERTY_CM) {
leftClass = LineBreakUtils.LINE_BREAK_PROPERTY_ID;
}
- }
- // LB 2a
- return PROHIBITED_BREAK;
- } else if (!(leftClass != LineBreakUtils.LINE_BREAK_PROPERTY_BK
- && (leftClass != LineBreakUtils.LINE_BREAK_PROPERTY_CR
- || currentClass == LineBreakUtils.LINE_BREAK_PROPERTY_LF)
- )) {
- reset();
- if (currentClass == LineBreakUtils.LINE_BREAK_PROPERTY_LF) {
- leftClass = LineBreakUtils.LINE_BREAK_PROPERTY_BK;
- }
- return EXPLICIT_BREAK;
- } else if (currentClass == LineBreakUtils.LINE_BREAK_PROPERTY_BK
- || currentClass == LineBreakUtils.LINE_BREAK_PROPERTY_LF) {
- leftClass = LineBreakUtils.LINE_BREAK_PROPERTY_BK;
- return PROHIBITED_BREAK;
- } else if (currentClass == LineBreakUtils.LINE_BREAK_PROPERTY_CR) {
- leftClass = LineBreakUtils.LINE_BREAK_PROPERTY_CR;
- return PROHIBITED_BREAK;
- } else if (currentClass == LineBreakUtils.LINE_BREAK_PROPERTY_SP) {
- hadSpace = true;
- return PROHIBITED_BREAK;
- } else {
- boolean savedHadSpace = hadSpace;
- hadSpace = false;
- switch (LineBreakUtils.getLineBreakPairProperty(leftClass, currentClass)) {
- case LineBreakUtils.PROHIBITED_BREAK :
- leftClass = currentClass;
+ // LB 2a
+ return PROHIBITED_BREAK;
+
+ case LineBreakUtils.LINE_BREAK_PROPERTY_BK:
+ case LineBreakUtils.LINE_BREAK_PROPERTY_LF:
+ case LineBreakUtils.LINE_BREAK_PROPERTY_NL:
+ //first character after mandatory break
+ reset();
+ leftClass = currentClass;
+ return EXPLICIT_BREAK;
+
+ case LineBreakUtils.LINE_BREAK_PROPERTY_CR:
+ //first character after a carriage return:
+ // explicit break if it is not a linefeed
+ if (currentClass != LineBreakUtils.LINE_BREAK_PROPERTY_LF) {
+ reset();
+ return EXPLICIT_BREAK;
+ }
+
+ default:
+ //nop
+ }
+
+ /** Check 2: current is a mandatory break or space? */
+ switch (currentClass) {
+ case LineBreakUtils.LINE_BREAK_PROPERTY_BK:
+ case LineBreakUtils.LINE_BREAK_PROPERTY_LF:
+ case LineBreakUtils.LINE_BREAK_PROPERTY_NL:
+ case LineBreakUtils.LINE_BREAK_PROPERTY_CR:
+ leftClass = currentClass;
+ return PROHIBITED_BREAK;
+
+ case LineBreakUtils.LINE_BREAK_PROPERTY_SP:
+ hadSpace = true;
+ return PROHIBITED_BREAK;
+
+ default:
+ //nop
+ }
+
+ /** Normal treatment, if the first two checks did not return */
+ boolean savedHadSpace = hadSpace;
+ hadSpace = false;
+ byte breakAction = LineBreakUtils.getLineBreakPairProperty(leftClass, currentClass);
+ switch (breakAction) {
+ case PROHIBITED_BREAK:
+ case DIRECT_BREAK:
+ leftClass = currentClass;
+ return breakAction;
+
+ case INDIRECT_BREAK:
+ leftClass = currentClass;
+ if (savedHadSpace) {
+ return INDIRECT_BREAK;
+ } else {
return PROHIBITED_BREAK;
- case LineBreakUtils.DIRECT_BREAK :
+ }
+
+ case COMBINING_INDIRECT_BREAK:
+ if (savedHadSpace) {
leftClass = currentClass;
- return DIRECT_BREAK;
- case LineBreakUtils.INDIRECT_BREAK :
+ return COMBINING_INDIRECT_BREAK;
+ } else {
+ return PROHIBITED_BREAK;
+ }
+
+ case COMBINING_PROHIBITED_BREAK:
+ if (savedHadSpace) {
leftClass = currentClass;
- if (savedHadSpace) {
- return INDIRECT_BREAK;
- } else {
- return PROHIBITED_BREAK;
- }
- case LineBreakUtils.COMBINING_INDIRECT_BREAK :
- if (savedHadSpace) {
- leftClass = currentClass;
- return COMBINING_INDIRECT_BREAK;
- } else {
- return PROHIBITED_BREAK;
- }
- case LineBreakUtils.COMBINING_PROHIBITED_BREAK :
- if (savedHadSpace) {
- leftClass = currentClass;
- }
- return COMBINING_PROHIBITED_BREAK;
- default :
- throw new RuntimeException("duh");
- }
-
+ }
+ return COMBINING_PROHIBITED_BREAK;
+
+ default:
+ assert false;
+ return breakAction;
}
}