Re: TextWidth() Alternative?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



"Dan Barclay" <Dan@xxxxxxxx> wrote in message news:ulHJm%23dqGHA.3820@xxxxxxxxxxxxxxxxxxxxxxx

I think you might want to restrict that to cases where you *really*
needed the exact width for some reason (that escapes me<g>).

How about if you want to send some fully justified text to the printer and you want the right edge as neat as possible. In that case the best method would be to use GetTextExtentPoint32A in order to get the exact width of the line of text so that you could calculate the correct value to pass to the SetTextJustification API.

Doing it this way requires that it look up width of each character.

Doing it what way? I suggested getting the width of an entire string (or substring if you're checking for word wrap) in one go using the GetTextExtentPoint32 API. I specifically advised *against* getting individual character by character (or word by word) widths and adding them up. (Unless of course you mean that the API routine itself will need to check every character in the string, in which case I'd love to know what method you are suggesting that doesn't need to do that!)

I don't know if that API supports fonts with kerning or not

Yes it does.

. . . but if it does then you'll *really* chew up some CPU.

No you wouldn't.

Agreed. Every time I have to handle text in any detail the
circumstances are different. So, you really need to look for
that issue when you're doing it.

I'm pleased to note that we do at least agree on something ;-)

Actually, the OP still hasn't told us what he is doing and, often more importantly, why he is doing it. Perhaps when he does we will be able to give him some more specific advice.

Mike



.



Relevant Pages

  • Re: Get User at login
    ... What's returned by the API call is padded with a Null character at the end. ... API actually changes the value of that field to be the length of the string ... > Dim strBufferString As String ...
    (microsoft.public.access.modulesdaovba)
  • Re: How to Wrap Text
    ... Where each line width is 20 character. ... And Suppose my String is 80 ... The API provides text wrapping, but again it is based on area, ... Private Sub Form_Load ...
    (microsoft.public.vb.general.discussion)
  • Re: A simple question - how to convert from UTF8 to wide char (wchar_t) on linux
    ... To get a complete list for to and from do 'iconv --list' ... I need to convert a string from UTF8 to wide character. ... in linux this API is not available. ...
    (comp.lang.c)
  • Re: TextWidth() Alternative?
    ... needed the exact width for some reason. ... Using the API requires that it looks up width of each character (unless it's ... string, in which case I'd love to know what method you are suggesting that ...
    (microsoft.public.vb.general.discussion)
  • text centered within text box
    ... I need to have the text box adjust to the exact size of the text ... string. ... I need to place the text exactly without any dead space between the ... character and text box handle. ...
    (microsoft.public.visio.general)