📄 cpw_font.h
字号:
typedef pVoid CpwFontFace;
/* */
/*************************************************************************/
/*************************************************************************/
/* */
/* <Enum> */
/* */
/* <Description> */
/* Font file location constants. Used by cpwLoadFont to locate a */
/* font file. */
/* */
enum
{
CPW_FONTLOC_HOST = 1, /* use localhost fonts for search */
CPW_FONTLOC_RELATIVE = 2, /* custom path to font directory */
};
/* */
/*************************************************************************/
/*************************************************************************/
/* */
/* <Function> */
/* cpwLoadFont */
/* */
/* <Description> */
/* Load a font face into memory. 'fontname' is the file name */
/* of the True Type font. 'location' is either CPW_FONTLOC_HOST */
/* or CPW_FONTLOC_RELATIVE. If CPW_FONTLOC_RELATIVE is specified, */
/* 'fontpath' should contains a valid application relative */
/* directory name where the font file is located. If CPW_FONTLOC_HOST */
/* is specified, Cpw looks for the font in the localhost's default */
/* font directory if one exists. 'cachelist' should be null. */
/* */
CPW_API CpwFontFace
cpwLoadFont( pCpw cpw,
pChar fontname,
uint_32 location,
pChar fontpath,
pChar cachelist );
/* */
/*************************************************************************/
/*************************************************************************/
/* */
/* <Function> */
/* cpwUnloadFont */
/* */
/* <Description> */
/* Unloads a font face from memory. */
/* */
CPW_API bool
cpwUnloadFont( pCpw cpw, CpwFontFace font );
/* */
/*************************************************************************/
/*************************************************************************/
/* */
/* <Function> */
/* cpwDrawFont */
/* */
/* <Description> */
/* Draws a font string and advances the raster position. */
/* 'string' should be a null terminated string. if 'drawflag' */
/* is true, drawing will occur. If it is false, drawing will */
/* not occur but the raster position will be advanced accordingly. */
/* */
/* Use cpwFontMode to set the FontRenderMode, FontAlignMode and */
/* any FontOption's that apply. CPW_FONTOPT_PIXELMAP is currently */
/* the only render mode supported. You must set the */
/* CPW_FONTOPT_PIXELMAP_GLFORMAT for rendering pixel map fonts. */
/* CPW_FONTOPT_PIXELMAP_GLFORMAT can be set to any of the valid */
/* OpenGL formats available in the glDrawPixels call. */
/* */
/* Future support will be available for outline and mesh font render */
/* modes. Use cpwDrawBufferedFont to generate textures for texture */
/* mapped font drawing. */
/* */
/* Anyone care to add outline or mesh support? :) */
/* */
CPW_API bool
cpwDrawFont( pCpw cpw,
CpwFontFace font,
pChar string,
bool drawflag );
/* */
/*************************************************************************/
/*************************************************************************/
/* */
/* <Struct> */
/* CpwFontBBox */
/* */
/* <Description> */
/* A structure used to hold a font string's bounding box, i.e., the */
/* width and maximum height of the string in pixels. 'offset' is the */
/* space from the lower left of the box to the baseline of the */
/* of the string. The baseline is the 'virtual' line drawn through */
/* the text which all characters in the string rest on. */
/* */
struct _CpwFontBBox
{
int_32 width;
int_32 height;
int_32 offsetx;
int_32 offsety;
};
typedef struct _CpwFontBBox CpwFontBBox;
/* */
/*************************************************************************/
/*************************************************************************/
/* */
/* <Function> */
/* cpwGetFontBBox */
/* */
/* <Description> */
/* Fills a CpwFontBBox with the specified string's dimensions based */
/* on the current font options and alignment. */
/* */
CPW_API bool
cpwGetFontBBox( pCpw cpw,
CpwFontFace font,
pChar string,
CpwFontBBox * bbox );
/* */
/*************************************************************************/
/*************************************************************************/
/* */
/* <Struct> */
/* CpwFontBuffer */
/* */
/* <Description> */
/* Used by cpwDrawBufferedFont. Holds a font buffer's information */
/* and buffer data. */
/* */
struct _CpwFontBuffer
{
char* data; /* buffer */
uint_32 w; /* width of buffer based on glformat */
uint_32 h; /* height of buffer based on glformat */
int_32 glformat; /* the glformat of the buffer data */
};
typedef struct _CpwFontBuffer CpwFontBuffer;
/* */
/*************************************************************************/
/*************************************************************************/
/* */
/* <Function> */
/* cpwDrawBufferedFont */
/* */
/* <Description> */
/* Creates a new buffer suitable for holding an image of the string, */
/* and renders the string into the buffer. 'glformat' is a valid */
/* OpenGL format used in glDrawPixels. Pass a vilid pointer to a */
/* CpwFontBuffer structure. */
/* */
/* Note! You must free a buffer returned by cpwDrawBufferedFont with */
/* cpwFreeBufferedFont. */
/* */
CPW_API bool
cpwDrawBufferedFont( pCpw cpw,
CpwFontFace font,
pChar string,
CpwFontBuffer * buffer );
/* */
/*************************************************************************/
/*************************************************************************/
/* */
/* <Function> */
/* cpwFreeBufferedFont */
/* */
/* <Description> */
/* Frees the data contained within a CpwFontBuffer by calling cpwfree */
/* on the buffer's 'data' member. */
/* */
CPW_API bool
cpwFreeBufferedFont( pCpw cpw,
CpwFontBuffer * buffer );
/* */
/*************************************************************************/
/*************************************************************************/
/* */
/* internal functions and definitions */
/* */
/*************************************************************************/
#ifdef CPW_INTERN
#include CPW_FREETYPE_H /* freetype main include header */
/* #include FT_GLYPH_H needed for bounding box calculations */
/*************************************************************************/
/* */
/* <Struct> */
/* CpwFontState */
/* */
/* <Description> */
/* */
struct _CpwFontState
{
FT_Library library;
FontRenderMode renderMode;
uint_32 fontSize;
FontAlignMode alignMode;
bool kerning;
bool layoutdebug;
int_32 spacingMulti;
GLenum pixmap_format;
int_32 screenWidth;
int_32 screenHeight;
char* pixelbuffer;
uint_32 pixelbuffersize;
};
typedef struct _CpwFontState CpwFontState;
/* */
/*************************************************************************/
bool cpw_font_init( pCpw cpw );
void cpw_font_exit( pCpw cpw );
void cpw_font_pixelmap_convertfree( CpwFontState * cfs );
#endif /* CPW_INTERN */
CPW_END_HEADER
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -