]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Use CharUtilities instead of CharClass
authorKaren Lease <klease@apache.org>
Mon, 25 Feb 2002 21:28:28 +0000 (21:28 +0000)
committerKaren Lease <klease@apache.org>
Mon, 25 Feb 2002 21:28:28 +0000 (21:28 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194673 13f79535-47bb-0310-9956-ffa450edef68

src/org/apache/fop/fo/FONode.java
src/org/apache/fop/fo/InlineCharIterator.java
src/org/apache/fop/fo/flow/Block.java
src/org/apache/fop/util/CharUtilities.java

index 9f2d5aae5484ce065d7b256bc7874ee3627d0212..55fde4fee3481fca455af1fdb49dc131c4d03445 100644 (file)
@@ -11,6 +11,7 @@ package org.apache.fop.fo;
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.apps.StreamRenderer;
 import org.apache.fop.layout.Area;
+import org.apache.fop.util.CharUtilities;
 
 import org.apache.log.Logger;
 
@@ -121,7 +122,7 @@ abstract public class FONode {
     }
 
     public CharIterator charIterator() {
-       return new OneCharIterator(CharClass.CODE_EOT);
+       return new OneCharIterator(CharUtilities.CODE_EOT);
     }
 
 }
index f8d048814e6f58e57584882bf02f4fa9726bb315..fe2a8eeda2105f9dcd91dcd3af81cca97706b22d 100644 (file)
@@ -1,6 +1,7 @@
 package org.apache.fop.fo;
 
 import org.apache.fop.layout.BorderAndPadding;
+import org.apache.fop.util.CharUtilities;
 import java.util.Iterator;
 import java.util.ListIterator;
 import java.util.NoSuchElementException;
@@ -36,7 +37,7 @@ public class InlineCharIterator extends RecursiveCharIterator {
     public char nextChar() throws NoSuchElementException {
        if (bStartBoundary) {
            bStartBoundary=false;
-           return CharClass.CODE_EOT;
+           return CharUtilities.CODE_EOT;
        }
        try {
            return super.nextChar();
@@ -46,7 +47,7 @@ public class InlineCharIterator extends RecursiveCharIterator {
            // Check end boundary char
            if (bEndBoundary) {
                bEndBoundary=false;
-               return CharClass.CODE_EOT;
+               return CharUtilities.CODE_EOT;
            }
            else throw e;
        }
index ba1b22ec4dbefebc30caca1da65a3a2aff38b28e..3dc075b974783f11e96e1bed4243a97fcac89101 100644 (file)
@@ -15,6 +15,7 @@ import org.apache.fop.datatypes.*;
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.layoutmgr.LayoutManager;
 import org.apache.fop.layoutmgr.BlockLayoutManager;
+import org.apache.fop.util.CharUtilities;
 
 import org.xml.sax.Attributes;
 
@@ -406,8 +407,8 @@ public class Block extends FObjMixed {
            LFchecker lfCheck = new LFchecker(charIter);
 
            while (charIter.hasNext()) {
-               switch (CharClass.classOf(charIter.nextChar())) {
-               case CharClass.XMLWHITESPACE:
+               switch (CharUtilities.classOf(charIter.nextChar())) {
+               case CharUtilities.XMLWHITESPACE:
                    /* Some kind of whitespace character, except linefeed. */
                    boolean bIgnore=false;
                    
@@ -440,7 +441,7 @@ public class Block extends FObjMixed {
                    }
                    break;
 
-               case CharClass.LINEFEED:
+               case CharUtilities.LINEFEED:
                    /* A linefeed */
                    lfCheck.reset();
                    bPrevWasLF=true; // for following whitespace
@@ -468,14 +469,14 @@ public class Block extends FObjMixed {
                    }
                    break;
 
-               case CharClass.EOT:
+               case CharUtilities.EOT:
                    //   A "boundary" objects such as non-character inline
                    // or nested block object was encountered.
                    // If any whitespace run in progress, finish it.
                    // FALL THROUGH
 
-               case CharClass.UCWHITESPACE: // Non XML-whitespace
-               case CharClass.NONWHITESPACE:
+               case CharUtilities.UCWHITESPACE: // Non XML-whitespace
+               case CharUtilities.NONWHITESPACE:
                    /* Any other character */
                    bInWS = bPrevWasLF=false;
                    lfCheck.reset();
@@ -503,7 +504,8 @@ public class Block extends FObjMixed {
                        bNextIsLF=true;
                        break;
                    }
-                   else if (CharClass.classOf(c)!=CharClass.XMLWHITESPACE) {
+                   else if (CharUtilities.classOf(c) !=
+                            CharUtilities.XMLWHITESPACE) {
                        break;
                    }
                }
index f8bcc7edc60ec3250d47a209cdb054c7c785c275..14187a5ea6f65da154ef728d5c8fab0bbe81eb09 100644 (file)
@@ -10,9 +10,36 @@ package org.apache.fop.util;
 import org.apache.fop.layout.FontState;
 
 /**
+ * This class provides utilities to distinguish various kinds of Unicode
+ * whitespace and to get character widths in a given FontState.
  */
 public class CharUtilities {
 
+    /** Character code used to signal a character boundary in
+     * inline content, such as an inline with borders and padding
+     * or a nested block object.
+     */
+    public static final char CODE_EOT=0;
+
+    public static final int UCWHITESPACE=0; // unicode white space
+    public static final int LINEFEED=1;
+    public static final int EOT=2; // Boundary beteween text runs
+    public static final int NONWHITESPACE=3;
+    public static final int XMLWHITESPACE=4;
+
+
+    /**
+     * Return the appropriate CharClass constant for the type
+     * of the passed character.
+     */
+    public static int classOf(char c) {
+       if (c == CODE_EOT) return EOT;
+       if (c == '\n') return LINEFEED;
+       if ( c==' '|| c == '\r' || c=='\t' ) return XMLWHITESPACE;
+       if (isAnySpace(c)) return UCWHITESPACE;
+       return NONWHITESPACE;
+    }
+
     /**
      * Helper method for getting the width of a unicode char
      * from the current fontstate.
@@ -76,21 +103,20 @@ public class CharUtilities {
      * it's not non-breaking
      */
     public static boolean isSpace(char c) {
-        if (c == ' ' || c == '\u2000' ||    // en quad
-        c == '\u2001' ||                    // em quad
-        c == '\u2002' ||                    // en space
-        c == '\u2003' ||                    // em space
-        c == '\u2004' ||                    // three-per-em space
-        c == '\u2005' ||                    // four--per-em space
-        c == '\u2006' ||                    // six-per-em space
-        c == '\u2007' ||                    // figure space
-        c == '\u2008' ||                    // punctuation space
-        c == '\u2009' ||                    // thin space
-        c == '\u200A' ||                    // hair space
-        c == '\u200B')                      // zero width space
-            return true;
-        else
-            return false;
+        return (c == ' ' ||
+               (c >= '\u2000' && c <= '\u200B'));
+//         c == '\u2000'                   // en quad
+//         c == '\u2001'                   // em quad
+//         c == '\u2002'                   // en space
+//         c == '\u2003'                   // em space
+//         c == '\u2004'                   // three-per-em space
+//         c == '\u2005'                   // four--per-em space
+//         c == '\u2006'                   // six-per-em space
+//         c == '\u2007'                   // figure space
+//         c == '\u2008'                   // punctuation space
+//         c == '\u2009'                   // thin space
+//         c == '\u200A'                   // hair space
+//         c == '\u200B'                   // zero width space
     }
 
     /**