Ken Krugler a �crit :
> > > When copying a string into a field, is there a quick and simple way to
> >> determine whether the copied string can actually be displayed in the
> >current
> >> field font? e.g. letters produce a hollow rectangle when displayed in the
> >LED
> >> font. I would like to exclude those undisplayable characters that
> >shouldn't be
> >> in the source string.
>
> Unfortunately there's no API for querying a given font's set of
> defined glyphs. On pre-Palm OS 5 you could roll your own by
> inspecting the font data, though I don't think that would work any
> longer when you're running under PACE, and it wouldn't work for
> Japanese, Chinese, or other non-Latin locales that use complex fonts.
>
> OTOH, the set of defined glyphs in the LED font hasn't changed much
> over time (maybe since 3.5?), so if that's the specific font that you
> need to deal with then that's a pretty simple check.
>
> Or, if you really needed a general solution, you could craft your own
> by drawing both a known invalid character and the target character to
> off-screen bitmaps and comparing the bits. Ugly, I know.
In the end, I wrote this:
Boolean FntCharExists( Char ch )
{
switch ( FntGetFont() )
{
case stdFont :
case boldFont :
case largeFont :
case largeBoldFont :
if ( ( ch <= 0x13 ) || ( ( ch >= 0x1b ) && ( ch <= 0x1f ) ) || ( ch ==
0x7f ) || ( ch == 0x81 ) || ( ch == 0x9d )
|| ( ch == 0x9e ) )
return false;
break;
case symbolFont :
if ( ( ch <= 2 ) || ( ch >= 0x1b ) )
return false;
break;
case symbol11Font :
if ( ch >= 7 )
return false;
break;
case symbol7Font :
if ( ( ch == 0 ) || ( ch >= 5 ) )
return false;
break;
case ledFont :
if ( ( ch <= 0x1f ) || ( ch >= 0x3a ) || ( ( ch >= 0x21 ) && ( ch <= 0x26
) ) || ( ( ch >= 0x28 ) && ( ch <= 0x2B )
) )
return false;
break;
}
return true;
}
--
Luc Le Blanc
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/