]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
move static methods getCharWidth and getWordWidth from util.CharUtilities to instance...
authorWilliam Victor Mote <vmote@apache.org>
Fri, 10 Oct 2003 15:56:57 +0000 (15:56 +0000)
committerWilliam Victor Mote <vmote@apache.org>
Fri, 10 Oct 2003 15:56:57 +0000 (15:56 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@196954 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/fo/flow/PageNumberCitation.java
src/java/org/apache/fop/fonts/Font.java
src/java/org/apache/fop/layoutmgr/AddLMVisitor.java
src/java/org/apache/fop/layoutmgr/TextLayoutManager.java
src/java/org/apache/fop/util/CharUtilities.java

index 005bfa620e0d73d222cf3ace4e5cb13e912a6d01..d82f400ef1dfb370ff1c502bacd6c2b4c8a71e24 100644 (file)
@@ -96,8 +96,7 @@ public class PageNumberCitation extends FObj {
     public int getStringWidth(String str) {
         int width = 0;
         for (int count = 0; count < str.length(); count++) {
-            width += CharUtilities.getCharWidth(str.charAt(count),
-                                                fontState);
+            width += fontState.getCharWidth(str.charAt(count));
         }
         return width;
     }
index b23b58f720888aca0065e6f3f87e0e708985ce14..8874628099fe573c8e04f47f9dc4f8cb09bc13d3 100644 (file)
@@ -207,7 +207,102 @@ public class Font {
         sbuf.append(')');
         return sbuf.toString();
     }
-}
 
+    /**
+     * Helper method for getting the width of a unicode char
+     * from the current fontstate.
+     * This also performs some guessing on widths on various
+     * versions of space that might not exists in the font.
+     * @param c character to inspect
+     * @param fs FontState to use
+     * @return the width of the character
+     */
+    public int getCharWidth(char c) {
+        int width;
+
+        if ((c == '\n') || (c == '\r') || (c == '\t') || (c == '\u00A0')) {
+            width = getCharWidth(' ');
+        } else {
+            width = getWidth(mapChar(c));
+            if (width <= 0) {
+                // Estimate the width of spaces not represented in
+                // the font
+                int em = getWidth(mapChar('m'));
+                int en = getWidth(mapChar('n'));
+                if (em <= 0) {
+                    em = 500 * getFontSize();
+                }
+                if (en <= 0) {
+                    en = em - 10;
+                }
+
+                if (c == ' ') {
+                    width = em;
+                }
+                if (c == '\u2000') {
+                    width = en;
+                }
+                if (c == '\u2001') {
+                    width = em;
+                }
+                if (c == '\u2002') {
+                    width = em / 2;
+                }
+                if (c == '\u2003') {
+                    width = getFontSize();
+                }
+                if (c == '\u2004') {
+                    width = em / 3;
+                }
+                if (c == '\u2005') {
+                    width = em / 4;
+                }
+                if (c == '\u2006') {
+                    width = em / 6;
+                }
+                if (c == '\u2007') {
+                    width = getCharWidth(' ');
+                }
+                if (c == '\u2008') {
+                    width = getCharWidth('.');
+                }
+                if (c == '\u2009') {
+                    width = em / 5;
+                }
+                if (c == '\u200A') {
+                    width = 5;
+                }
+                if (c == '\u200B') {
+                    width = 100;
+                }
+                if (c == '\u202F') {
+                    width = getCharWidth(' ') / 2;
+                }
+                if (c == '\u3000') {
+                    width = getCharWidth(' ') * 2;
+                }
+            }
+        }
+
+        return width;
+    }
+
+    /**
+     * Calculates the word width.
+     */
+    public int getWordWidth(String word) {
+        if (word == null)
+            return 0;
+        int wordLength = word.length();
+        int width = 0;
+        char[] characters = new char[wordLength];
+        word.getChars(0, wordLength, characters, 0);
+        for (int i = 0; i < wordLength; i++) {
+            width += getCharWidth(characters[i]);
+        }
+        return width;
+    }
+
+}
 
 
index 0537c3ec829b46ed770125496eee1baaa19cd23f..bd5e83644a9d5390e789fb8e1998d1a3fb638266 100644 (file)
@@ -387,7 +387,7 @@ public class AddLMVisitor implements FOTreeVisitor {
                               new Integer(node.getFontState().getFontSize()));
              // set offset of dot within inline parent
              w.setOffset(node.getFontState().getAscender());
-             int width = CharUtilities.getCharWidth(dot, node.getFontState());
+             int width = node.getFontState().getCharWidth(dot);
              Space spacer = null;
              if (node.getPatternWidth() > width) {
                  spacer = new Space();
@@ -742,8 +742,8 @@ public class AddLMVisitor implements FOTreeVisitor {
                          String str = parentLM.getCurrentPageNumber();
                          int width = 0;
                      for (int count = 0; count < str.length(); count++) {
-                             width += CharUtilities.getCharWidth(
-                                        str.charAt(count), node.getFontState());
+                             width += node.getFontState().getCharWidth(
+                                        str.charAt(count));
                          }
                          inline.setWord(str);
                          inline.setIPD(width);
index 53254e6040b0062fd21cf1b92602ea086c373950..46a72f224a3d56be0c6dfc6f225127a0351ed927 100644 (file)
@@ -134,9 +134,9 @@ public class TextLayoutManager extends AbstractLayoutManager {
         this.vecAreaInfo = new java.util.ArrayList();
 
         // With CID fonts, space isn't neccesary currentFontState.width(32)
-        spaceCharIPD = CharUtilities.getCharWidth(' ', textInfo.fs);
+        spaceCharIPD = textInfo.fs.getCharWidth(' ');
         // Use hyphenationChar property
-        hyphIPD = CharUtilities.getCharWidth('-', textInfo.fs);
+        hyphIPD = textInfo.fs.getCharWidth('-');
         // Make half-space: <space> on either side of a word-space)
         SpaceVal ws = textInfo.wordSpacing;
         halfWS = new SpaceVal(MinOptMax.multiply(ws.getSpace(), 0.5),
@@ -237,7 +237,7 @@ public class TextLayoutManager extends AbstractLayoutManager {
 
         for (; iNextStart < iStopIndex; iNextStart++) {
             char c = chars[iNextStart];
-            hyphIPD.opt += CharUtilities.getCharWidth(c, textInfo.fs);
+            hyphIPD.opt += textInfo.fs.getCharWidth(c);
             // letter-space?
         }
         // Need to include hyphen size too, but don't count it in the
@@ -344,7 +344,7 @@ public class TextLayoutManager extends AbstractLayoutManager {
                 bSawNonSuppressible = true;
                 spaceIPD.add(pendingSpace.resolve(false));
                 pendingSpace.clear();
-                wordIPD += CharUtilities.getCharWidth(c, textInfo.fs);
+                wordIPD += textInfo.fs.getCharWidth(c);
             }
         }
 
@@ -381,8 +381,7 @@ public class TextLayoutManager extends AbstractLayoutManager {
                     if (c != SPACE) {
                         iNextStart++;
                         if (c != NEWLINE) {
-                            wordIPD += CharUtilities.getCharWidth(c,
-                                                                  textInfo.fs);
+                            wordIPD += textInfo.fs.getCharWidth(c);
                         } else {
                             iFlags |= BreakPoss.FORCE;
                         }
@@ -402,7 +401,7 @@ public class TextLayoutManager extends AbstractLayoutManager {
                                          context.getLeadingSpace(), null, iFlags,
                                          iWScount);
                 }
-                wordIPD += CharUtilities.getCharWidth(c, textInfo.fs);
+                wordIPD += textInfo.fs.getCharWidth(c);
                 // Note, if a normal non-breaking space, is it stretchable???
                 // If so, keep a count of these embedded spaces.
             }
index d8b5a3ab0d06b3fd561c1c4c2079deb6956d3d1e..c03c407ba398982382adc029cd6d09e12d076b80 100644 (file)
@@ -108,100 +108,6 @@ public class CharUtilities {
         return NONWHITESPACE;
     }
 
-    /**
-     * Helper method for getting the width of a unicode char
-     * from the current fontstate.
-     * This also performs some guessing on widths on various
-     * versions of space that might not exists in the font.
-     * @param c character to inspect
-     * @param fs FontState to use
-     * @return the width of the character
-     */
-    public static int getCharWidth(char c, Font fs) {
-        int width;
-
-        if ((c == '\n') || (c == '\r') || (c == '\t') || (c == '\u00A0')) {
-            width = getCharWidth(' ', fs);
-        } else {
-            width = fs.getWidth(fs.mapChar(c));
-            if (width <= 0) {
-                // Estimate the width of spaces not represented in
-                // the font
-                int em = fs.getWidth(fs.mapChar('m'));
-                int en = fs.getWidth(fs.mapChar('n'));
-                if (em <= 0) {
-                    em = 500 * fs.getFontSize();
-                }
-                if (en <= 0) {
-                    en = em - 10;
-                }
-
-                if (c == ' ') {
-                    width = em;
-                }
-                if (c == '\u2000') {
-                    width = en;
-                }
-                if (c == '\u2001') {
-                    width = em;
-                }
-                if (c == '\u2002') {
-                    width = em / 2;
-                }
-                if (c == '\u2003') {
-                    width = fs.getFontSize();
-                }
-                if (c == '\u2004') {
-                    width = em / 3;
-                }
-                if (c == '\u2005') {
-                    width = em / 4;
-                }
-                if (c == '\u2006') {
-                    width = em / 6;
-                }
-                if (c == '\u2007') {
-                    width = getCharWidth(' ', fs);
-                }
-                if (c == '\u2008') {
-                    width = getCharWidth('.', fs);
-                }
-                if (c == '\u2009') {
-                    width = em / 5;
-                }
-                if (c == '\u200A') {
-                    width = 5;
-                }
-                if (c == '\u200B') {
-                    width = 100;
-                }
-                if (c == '\u202F') {
-                    width = getCharWidth(' ', fs) / 2;
-                }
-                if (c == '\u3000') {
-                    width = getCharWidth(' ', fs) * 2;
-                }
-            }
-        }
-
-        return width;
-    }
-
-    /**
-     * Calculates the word width.
-     */
-    public static int getWordWidth(String word, Font fs) {
-        if (word == null)
-            return 0;
-        int wordLength = word.length();
-        int width = 0;
-        char[] characters = new char[wordLength];
-        word.getChars(0, wordLength, characters, 0);
-        for (int i = 0; i < wordLength; i++) {
-            width += getCharWidth(characters[i], fs);
-        }
-        return width;
-    }
 
     /**
      * Helper method to determine if the character is a