You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-dev@xmlgraphics.apache.org by Jeremias Maerki <de...@jeremias-maerki.ch> on 2006/02/27 18:57:02 UTC

Character widths

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


Re: Character widths

Posted by Simon Pepping <sp...@leverkruid.nl>.
On Mon, Feb 27, 2006 at 06:57:02PM +0100, Jeremias Maerki wrote:
> 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.

Donald Knuth in The TeX Book, page 60, says this:

em is the width of a "quad" in the current font. Each font defines its
own em and ex values. In olden days an "em" was the width of an `M',
but this is no longer true; ems are simply arbitrary units that come
with a font, and so are exes. Indeed, Knuth's Computer Modern fonts
contain a quantity called quad width.

For en space he uses .5 em.

Regards, Simon

-- 
Simon Pepping
home page: http://www.leverkruid.nl


Re: Character widths

Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
Well, it's just that this is code that's been in there for a long time
and someone must have given it some thought. I simply want to make sure
I did not miss anything obvious. Thanks for looking at it.

On 27.02.2006 19:42:36 Andreas L Delmelle wrote:
> On Feb 27, 2006, at 18:57, Jeremias Maerki wrote:
> 
> Hi Jeremias,
> 
> > I need a second pair of eyes (or more) for a change I've done in
> > Font-java.
> <snip />
> >
> > Before I commit this change, can anyone tell me in case I got  
> > something
> > wrong here. Thanks.
> 
> Your changes seem fine to me... Any doubts in particular?


Jeremias Maerki


Re: Character widths

Posted by Andreas L Delmelle <a_...@pandora.be>.
On Feb 27, 2006, at 18:57, Jeremias Maerki wrote:

Hi Jeremias,

> I need a second pair of eyes (or more) for a change I've done in
> Font-java.
<snip />
>
> Before I commit this change, can anyone tell me in case I got  
> something
> wrong here. Thanks.

Your changes seem fine to me... Any doubts in particular?

Cheers,

Andreas