Palm OS/C/字体编程
外观
< Palm OS 编程 | C
使用以下方法使您的应用程序可以使用字体
FontPtr font = MemHandleLock( DmGetResource('NFNT', TinyFont));
FntDefineFont( 0x80, font);
..其中TinyFont是字体资源 ID,可使其可用。
要设置当前字体(由显式绘图函数遵守,但不会自动由所有控件使用,这些控件保存对它们应使用的字体的独立引用)
FntSetFont( 0x80);
- FntCharsWidth计算传递给它的文本的像素宽度
- FntCharHeight提供字体的 高度,它是 *升高* 和 *下降* 的总和,不包括您可能希望在文本行之间留出的任何空格
- FntAverageCharWidth尽管它的名字,但它提供了最宽字符的像素宽度。
此代码段依赖于 字体资源 。
#include <PalmOS.h>
#include "Fonts.h"
UInt32 PilotMain( UInt16 cmd, void *cmdPBP, UInt16 launchFlags)
{
EventType event;
FontPtr font;
char *msg;
UInt16 msgLen;
Coord y;
Coord x;
if ( sysAppLaunchCmdNormalLaunch == cmd)
{
font = MemHandleLock( DmGetResource('NFNT', TinyFont));
FntDefineFont( 0x80, font);
FntSetFont( 0x80);
// locate the text in the middle of the screen
msg = "Hello, world!";
msgLen = StrLen( msg);
x = (160 - FntCharsWidth(msg, msgLen)) / 2;
y = (160 - FntCharHeight()) / 2;
WinDrawChars( msg, msgLen, x, y);
do {
EvtGetEvent( &event, evtWaitForever);
SysHandleEvent( &event);
} while (event.eType != appStopEvent);
}
return 0;
}
有关可能对 Palm 程序员有用的字体的详细信息,请参见 Palm OS/小型字体 。