[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.platform.swt] How to calculate character widths?

I'd like to determine the true width of single characters.

I try to find a way to create a packed bitmap with all characters to use that as a texture for OpenGL. However, I've trouble to measure the font.

There's GC#getCharWidth() but on Windows, this method only returns the "B" width of a character. As documented, this is the width without leading or trailing whitespace or overhang. However, some fonts have such an overhang. Let's assume an uppercase A which has some tail-thingy as shown below:

     /\
    /__\
   /    \_ uto _
          -__-
 ^ ^            ^
 '-'------------'
  A    B ^------^
            -C

This character has a small "A" leading, a large "B" width that includes the "tail" and a negative "C" which tells the renderer where to start the next character - "u" in my example.

How do I get the other two values besides B? ...without directly calling the OS.GetCharABCWidths() method? Is there a platform independent way to get the width "A" or "C"? Can I safely assume that GC#getAdvanceWidth() will always return A+B+C?


Interestingly, getAdvanceWidth() uses OS.GetCharWidth(). MSDN however says, that this method cannot be used for truetype fonts. Why does this work then?



bye -- Stefan Matthias Aust // www.3plus4software.de // Inter Deum Et Diabolum Semper Musica Est