At 12:00am -0700 01-07-16, Palm Developer Forum digest wrote:
>Subject: Re: WinGlueDrawTruncChars() of SDK3.5's PalmOSGlue on Visor
>From: Steve Mann <[EMAIL PROTECTED]>
>Date: Sun, 15 Jul 2001 20:01:30 -0700
>X-Message-Number: 21
>
> >I modified my program, but I still got a white rectangle.
>
>Here's some code that should work on all OS versions.
[snip]
There are four problems with the code snippet:
>void UTTruncateString
>(
> Char * strP, // ( in/out ) the string to truncate
> Int16 width, // ( in ) the max # of pixels to allow
> FontID font // ( in ) the font to calculate the width in
>)
>{
> Int16 strLength = StrLen ( strP );
> Int16 strWidth = width;
> FontID oldFont = FntSetFont ( font );
> Boolean truncated;
>
>// Get the max # chars that can be displayed
>
> FntCharsInWidth ( strP, &strWidth, &strLength, &truncated );
> FntSetFont ( oldFont );
>
>// Truncate the title and add trailing ellipsis.
>
> if ( strLength < StrLen ( strP ))
> {
> strP [ strLength - 1 ] = 24; // ellipsis
1. This assumes that '24' is the character code of a horizontal
ellipsis, but that's only true on Palm OS 3.1 or later. So you'd
still wind up with the missing character glyph on 3.0, for example.
2. If the character immediately preceding the <strLength> offset is a
double-byte character, then jamming 24 into the low byte will trash
the character.
3. If <width> is less than the width of the first character in the
string, then <strLength> will be zero, so <strLength> - 1 will be an
invalid index into the string.
4. The goal of the routine is to return a modified <strP> whose width
fits in <width> pixels. If the width of the ellipsis is wider than
the width of the character at <strLength> - 1, then you might still
wind up with a string that's wider than <width> pixels.
I'd suggest he use the 4.0 SDK, which has a corrected version for
WinGlueDrawTruncChars.
-- Ken
Ken Krugler
TransPac Software, Inc.
<http://www.transpac.com>
+1 530-470-9200
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/