[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
|
[news.eclipse.platform.swt] Re: How to calculate character widths?
|
I wasn't aware that single characters have a 'true width'. You can write a
string of characters and find out how wide it is, or calculate same without
drawing. But except for mono-space fonts, the result is not the same, in
general, as adding up the widths of the individual characters.
Bob
"Stefan Matthias Aust" <sma@xxxxxxxxx> wrote in message
news:b819vv$jv4$1@xxxxxxxxxxxxxxxx
> 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
>