Re: TextWidth() Alternative?
- From: "Dan Barclay" <Dan@xxxxxxxx>
- Date: Mon, 17 Jul 2006 22:31:28 -0500
"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
.
- Prev by Date: Re: TextWidth() Alternative?
- Next by Date: Re: TextWidth() Alternative?
- Previous by thread: Re: TextWidth() Alternative?
- Next by thread: Re: TextWidth() Alternative?
- Index(es):
Relevant Pages
|