views:

742

answers:

2

Using a certain font, I use Java's FontLayout to determine its ascent, descent, and leading. (see Java's FontLayout tutorial here)

In my specific case I'm using Arial Unicode MS, font size 8. Using the following code:

    Font font = new Font("Arial Unicode MS", 0, 8);
    TextLayout layout = new TextLayout("Pp", font,
                               new FontRenderContext(null, true, true));
    System.out.println( "Ascent: "+layout.getAscent());
    System.out.println( "Descent: "+layout.getDescent());
    System.out.println( "Leading: "+layout.getLeading());

Java gives me the following values:

    Ascent: 8.550781
    Descent: 2.1679688
    Leading: 0.0

So far so good. However if I use the sum of these values as my line spacing for various lines of text, this differs by quite a bit from the line spacing used in OpenOffice, Microsoft Word, etc.: it is smaller. When using default single line spacing Word and OO seem to have a line spacing of around 13.7pt (instead of 10.7pt like I computed using Java's font metrics above).

Any idea

  1. why this is?
  2. whether I can somehow access the font information Word and OpenOffice seem to be accessing which leads to this different line spacing?


Things I've tried so far:

  • adding all glyphs to a glyph vector with font.getNumGlyphs() etc. - still get the same font metrics values
  • using multiple lines as described here - each line I get has the same font metrics as outlined above.
  • using FontMetrics' methods such as getLeading()
A: 

Are Word and OO including the white space between lines, while Java isn't?

So in Word / OO, your number is Ascent + Descent + Whitespace, while in Java you just have Ascent + Descent?

Zarkonnen
+1 This isn't as wrong as it appears.
banjollity
+6  A: 
banjollity