Manpreet Singh wrote:
> I am new to creating fonts. please anybody help. How can I create a new
> font? Can I integrate it with the constructor, so that it displays this font
> when the user selects font property of a control e.g a text box at design
> time.
Here is one way to do it:
(1) Create the font data using whatever tool you prefer.
(2) Put the font in the resource file.
(3) Use DmGetResource() to get a handle to the font data.
(4) Use MemHandleLock() to get a pointer to that handle.
(5) Cast the pointer to a (FontType *).
(6) Call FntDefineFont() to load the font into the system.
For the first argument (the FontID), you must use a
number greater than or equal to fntAppFontCustomBase.
(7) If FntDefineFont() succeeded, the FontID you passed to
it can now be used in FntSetFont() or in FldSetFont().
(8) When your FORM loads (i.e. in the frmOpenEvent handler),
ensure that all the above happens or already happened,
and use FldSetFont() to set the field's font.
(9) AFTER the font is no longer used by anything at all,
i.e. after the form has closed, unlock the handle
using MemHandleUnlock() and release the PRC record
using DmReleaseResource().
(10) As far as I know, there is NO WAY to unload the
font once it has been loaded! You can do
FntDefineFont (fontid, NULL), but it does not work
on OS 4.x and newer. Thankfully, it is OK to exit
the app without unloading the font.
Also, there is one additional complication to this whole
thing: older devices can only support traditional fonts,
but newer devices (those that have the High-Density Display
Feature Set) can handle font families. A font family has
a standard-density and a high-density version of the same
font in it. If you want your font to look good on 320x320
devices (etc.), then you should define a plain old-style
font AND a high-density font. Then use FtrGet() to determine
if you are on a device that has the High-Density Display
Feature Set. If you are, use DmGetResource() to load the
new style (font family); otherwise, load the old style of
font (single font).
The font family situation is similar to the bitmap family
situation, but there is a difference: because of a clever
trick on Palm's part, all devices -- even very old devices --
can handle the newest bitmap families, because in essence
they know which parts to ignore. But the same is not
true with font families. You cannot load a font family
on a device that's too old, so you must check manually
which the device supports before you load it.
Hope that helps.
- Logan
--
For information on using the Palm Developer Forums, or to unsubscribe, please
see http://www.palmos.com/dev/support/forums/