I need a second pair of eyes (or more) for a change I've done in
Font-java.

I think there are a number of bugs in the getCharWidth() method:
- The widths for special spaces were never returned as getWidth()
automatically replaced them with "#".
- The value for "em" was taken from the width of the small "m".
WikiPedia says to use the width of the big "M", or rather, today, the
size of the font in use (like in the XSL-FO spec).
- A similar problem with "en". It is defined by WikiPedia as em/2.
- I changed the widths of 200A and 200B to better match the description
in http://www.unicode.org/charts/PDF/U2000.pdf. I actually used half the
width of a thin space for hair space and set the width of the zwsp to
zero which surprisingly it wasn't.

Before I commit this change, can anyone tell me in case I got something
wrong here. Thanks.

Index: C:/Dev/FOP/main/xml-fop-patching/src/java/org/apache/fop/fonts/Font.java
===================================================================
--- C:/Dev/FOP/main/xml-fop-patching/src/java/org/apache/fop/fonts/Font.java    
(revision 381073)
+++ C:/Dev/FOP/main/xml-fop-patching/src/java/org/apache/fop/fonts/Font.java    
(working copy)
@@ -206,62 +206,46 @@
         if ((c == '\n') || (c == '\r') || (c == '\t') || (c == '\u00A0')) {
             width = getCharWidth(' ');
         } else {
-            width = getWidth(mapChar(c));
+            if (hasChar(c)) {
+                width = getWidth(mapChar(c));
+            } else {
+                width = -1;
+            }
             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;
-                }
+                int em = getFontSize(); 
//http://en.wikipedia.org/wiki/Em_(typography)
+                int en = em / 2; //http://en.wikipedia.org/wiki/En_(typography)
 
                 if (c == ' ') {
                     width = em;
-                }
-                if (c == '\u2000') {
+                } else if (c == '\u2000') {
                     width = en;
-                }
-                if (c == '\u2001') {
+                } else if (c == '\u2001') {
                     width = em;
-                }
-                if (c == '\u2002') {
+                } else if (c == '\u2002') {
                     width = em / 2;
-                }
-                if (c == '\u2003') {
+                } else if (c == '\u2003') {
                     width = getFontSize();
-                }
-                if (c == '\u2004') {
+                } else if (c == '\u2004') {
                     width = em / 3;
-                }
-                if (c == '\u2005') {
+                } else if (c == '\u2005') {
                     width = em / 4;
-                }
-                if (c == '\u2006') {
+                } else if (c == '\u2006') {
                     width = em / 6;
-                }
-                if (c == '\u2007') {
+                } else if (c == '\u2007') {
                     width = getCharWidth(' ');
-                }
-                if (c == '\u2008') {
+                } else if (c == '\u2008') {
                     width = getCharWidth('.');
-                }
-                if (c == '\u2009') {
+                } else if (c == '\u2009') {
                     width = em / 5;
-                }
-                if (c == '\u200A') {
-                    width = 5;
-                }
-                if (c == '\u200B') {
-                    width = 100;
-                }
-                if (c == '\u202F') {
+                } else if (c == '\u200A') {
+                    width = em / 10;
+                } else if (c == '\u200B') {
+                    width = 0;
+                } else if (c == '\u202F') {
                     width = getCharWidth(' ') / 2;
-                }
-                if (c == '\u3000') {
+                } else if (c == '\u3000') {
                     width = getCharWidth(' ') * 2;
                 }
             }


Jeremias Maerki

Reply via email to