| 1 | /*************************************************************** |
|---|
| 2 | ** |
|---|
| 3 | ** Broadcom Corp. Confidential |
|---|
| 4 | ** Copyright 2002 Broadcom Corp. All Rights Reserved. |
|---|
| 5 | ** |
|---|
| 6 | ** THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED |
|---|
| 7 | ** SOFTWARE LICENSE AGREEMENT BETWEEN THE USER AND BROADCOM. |
|---|
| 8 | ** YOU HAVE NO RIGHT TO USE OR EXPLOIT THIS MATERIAL EXCEPT |
|---|
| 9 | ** SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 10 | ** |
|---|
| 11 | ** Description: BGFX bit map font library |
|---|
| 12 | ** |
|---|
| 13 | ** Created: 8/22/2002 by Jeffrey P. Fisher |
|---|
| 14 | ** |
|---|
| 15 | ** |
|---|
| 16 | ** |
|---|
| 17 | ****************************************************************/ |
|---|
| 18 | |
|---|
| 19 | #ifndef __bgfx_font_h__ |
|---|
| 20 | #define __bgfx_font_h__ |
|---|
| 21 | |
|---|
| 22 | #include "bgfx_types.h" |
|---|
| 23 | |
|---|
| 24 | /* Uncomment to build with freetype support */ |
|---|
| 25 | /* #define CONFIG_FREETYPE */ |
|---|
| 26 | |
|---|
| 27 | #ifdef CONFIG_FREETYPE |
|---|
| 28 | #include <freetype/freetype.h> |
|---|
| 29 | #include <freetype/ftglyph.h> |
|---|
| 30 | #endif /* CONFIG_FREETYPE */ |
|---|
| 31 | /* |
|---|
| 32 | * Definitions |
|---|
| 33 | */ |
|---|
| 34 | |
|---|
| 35 | /* |
|---|
| 36 | * font flags |
|---|
| 37 | */ |
|---|
| 38 | #define BGFX_MONO (1 << 0) |
|---|
| 39 | #define BGFX_CACHE_GLYPHS (1 << 1) |
|---|
| 40 | #define BGFX_PRELOAD_GLYPHS (1 << 2) |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | #ifdef __cplusplus |
|---|
| 44 | extern "C" { |
|---|
| 45 | #endif |
|---|
| 46 | |
|---|
| 47 | /**************************************************************** |
|---|
| 48 | * Initialize global font management structures. |
|---|
| 49 | * Called by bgfx_init. |
|---|
| 50 | ****************************************************************/ |
|---|
| 51 | int bgfx_font_init(void); |
|---|
| 52 | /**************************************************************** |
|---|
| 53 | * Cleanup global font management structures. |
|---|
| 54 | * Called by bgfx_done. |
|---|
| 55 | ****************************************************************/ |
|---|
| 56 | void bgfx_font_done(void); |
|---|
| 57 | |
|---|
| 58 | /**************************************************************** |
|---|
| 59 | * Create a new font give an typeface name and size. |
|---|
| 60 | * The font_p should be a pointer to an allocated |
|---|
| 61 | * but uninitialized bgfx_font_t structure. The typeface must be |
|---|
| 62 | * a valid full path name to the font file. Valid flags can be any |
|---|
| 63 | * combination of BGFX_MONO,BGFX_CACHE_GLYPHS and BGFX_PRELOAD_GLYPHS |
|---|
| 64 | * REQUIRES FREETYPE SUPPORT |
|---|
| 65 | ****************************************************************/ |
|---|
| 66 | int bgfx_new_font( bgfx_font_t *font_p, /* reference to allocated uninitialized bgfx_font_t structure */ |
|---|
| 67 | const char *typeface_name, /* full path name of the typeface file */ |
|---|
| 68 | unsigned char height, /* font size in pixels */ |
|---|
| 69 | unsigned long flags /* font format and handling flags */ |
|---|
| 70 | ); |
|---|
| 71 | /**************************************************************** |
|---|
| 72 | * Free all resources associated with the font |
|---|
| 73 | * It is important to free fonts when done using them to return memory |
|---|
| 74 | * resources consumed by the font cache and Freetype. |
|---|
| 75 | ****************************************************************/ |
|---|
| 76 | void bgfx_free_font( bgfx_font_t *font_p /* reference to initialized bgfx_font_t structure */ |
|---|
| 77 | ); |
|---|
| 78 | |
|---|
| 79 | /**************************************************************** |
|---|
| 80 | * Get a glyph from the glyph cache if it exists or by rendering it |
|---|
| 81 | * with Freetype |
|---|
| 82 | * The font_p should be a pointer to an initialized bgfx_font_t structure. |
|---|
| 83 | * Called internally by bgfx. |
|---|
| 84 | ****************************************************************/ |
|---|
| 85 | bgfx_glyph_t *bgfx_get_glyph(bgfx_font_t *font_p, /* reference to initialized bgfx_font_t structure */ |
|---|
| 86 | unsigned long a_char /* 32-bit unicode character */ |
|---|
| 87 | ); |
|---|
| 88 | |
|---|
| 89 | /**************************************************************** |
|---|
| 90 | * Calculate the width and height of the null terminated string. |
|---|
| 91 | * Calculate the bounding rectangle for the null terminated string. |
|---|
| 92 | ****************************************************************/ |
|---|
| 93 | void bgfx_string_info(bgfx_font_t *font_p, /* initialized font structure */ |
|---|
| 94 | const unsigned long *str_p, /* array of single 32-bit unicode characters */ |
|---|
| 95 | int str_len, /* number of 32-bit characters in string */ |
|---|
| 96 | int *w, /* width in pixels */ |
|---|
| 97 | int *h /* height in pixels */ |
|---|
| 98 | ); |
|---|
| 99 | |
|---|
| 100 | /**************************************************************** |
|---|
| 101 | * Load the entire set of font info and glyph cache from a file. |
|---|
| 102 | * The file must have been produced by the bgfx_save_font function. |
|---|
| 103 | * This is the only way to draw text when there is no |
|---|
| 104 | * Freetype support. |
|---|
| 105 | ****************************************************************/ |
|---|
| 106 | int bgfx_load_font(bgfx_font_t *font_p, /* reference to initialized bgfx_font_t structure */ |
|---|
| 107 | void *file_p /* open initialized file pointer to read font from */ |
|---|
| 108 | ); |
|---|
| 109 | |
|---|
| 110 | /**************************************************************** |
|---|
| 111 | * External function required to load BGFX bitmap font files. |
|---|
| 112 | ****************************************************************/ |
|---|
| 113 | extern long bgfx_read(void *buffer, long size, long count, void *fp ); |
|---|
| 114 | |
|---|
| 115 | /**************************************************************** |
|---|
| 116 | * External functions to lock and unlock access to global data structures |
|---|
| 117 | * Required for freetype support only |
|---|
| 118 | ****************************************************************/ |
|---|
| 119 | #ifdef CONFIG_FREETYPE |
|---|
| 120 | extern void bgfx_lock(void); |
|---|
| 121 | extern void bgfx_unlock(void); |
|---|
| 122 | #endif /* CONFIG_FREETYPE */ |
|---|
| 123 | |
|---|
| 124 | #ifdef __cplusplus |
|---|
| 125 | } |
|---|
| 126 | #endif |
|---|
| 127 | |
|---|
| 128 | #endif /* __bgfx_font_h__ */ |
|---|
| 129 | |
|---|