Re: TextWidth() Alternative?

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




"Stefan Berglund" <sorry.no.koolaid@xxxxxx> wrote in message
news:oc4ob2lt6argt741bbijdumjar1tc62mpn@xxxxxxxxxx
On Mon, 17 Jul 2006 15:29:03 -0500, "Dan Barclay" <Dan@xxxxxxxx> wrote:
in <ulHJm#dqGHA.3820@xxxxxxxxxxxxxxxxxxxx>


"Mike Williams" <Mike@xxxxxxxxxxxxxxxxx> wrote in message
news:u1PPazdqGHA.2232@xxxxxxxxxxxxxxxxxxxxxxx


For almost all other jobs the VB TextWidth method is fine and although
we
still don't know what Jim is actually doing I suspect his problem is
that
he is failing to split up the string in a suitable manner during
testing.

However, if I really ever did want to get the width of a very long
string
I would use the GetTextExtentPoint32A API to get the width, preferably
in
one go.

I think you might want to restrict that to cases where you *really* needed
the exact width for some reason (that escapes me<g>). Doing it this way
requires that it look up width of each character. I don't know if that
API
supports fonts with kerning or not, but if it does then you'll *really*
chew
up some CPU.

Again, unless you need exact size, pick a representative chunk of text and
get the exact width on that. Then compute an average character width and
deduce the width of the rest of the string.

I would definitely advise against repeated use of the VB TextWidth
method
to add up the width of a number of smaller substrings for various
reasons,
one of which is the cumulative errors that can occur on devices that do
not use a whole number of twips per device pixel.

That shouldn't be a problem, unless they're computing width for something
far more wide than a line at a time. The cumulative errors won't be as
much
as they'll introduce with line breaks.

Screens are okay in this respect, but printers are generally not and
even
though the cumulative error of the VB TextWidth (and TextHeight) method
is
fairly small it can definitely be a problem under certain circumstances.

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. What you're saying is that it seldom matters, but it could. True
'nuff.

Dan

As a for instance, I've run into this when attempting to print large
blocks of text that are constrained to fit in a portion of the page
that's not necessarily the entire page width. To wit the legal
disclaimer here:

http://www.horseshowtime.com/images/It's_ShowTime!_EntryForm.pdf

Yup, I do that sort of thing regularly (though not equine stuff). My point
is that you can use the API calls for the times you need exact size, but for
those times you need approximate sizes (particularly if large segments of
text are involved) you can approach it in another way.

Dan



.



Relevant Pages

  • Re: TextWidth() Alternative?
    ... For almost all other jobs the VB TextWidth method is fine and although we ... he is failing to split up the string in a suitable manner during testing. ... the exact width for some reason. ... one of which is the cumulative errors that can occur on devices that do ...
    (microsoft.public.vb.general.discussion)
  • Re: TextWidth() Alternative?
    ... For almost all other jobs the VB TextWidth method is fine and although we ... he is failing to split up the string in a suitable manner during testing. ... the exact width for some reason. ... one of which is the cumulative errors that can occur on devices that do ...
    (microsoft.public.vb.general.discussion)
  • Re: TextWidth() Alternative?
    ... 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. ... I suggested getting the width of an entire string in one go using the GetTextExtentPoint32 API. ... I specifically advised *against* getting individual character by character widths and adding them up. ...
    (microsoft.public.vb.general.discussion)
  • Re: Synchronous Queue in VC++
    ... These exact ... APIs, as well as the doubly-linked equivalents, have been available in the ... Sometimes it's beyond me why it takes ages for useful API to surface. ...
    (microsoft.public.vc.language)
  • Trapping Events using C++
    ... in Microsoft Office (MS Word and Excel to be exact) that doesn't require the ... Anyone know what that API call is? ...
    (microsoft.public.office.developer.vba)