| 1 | /*************************************************************** |
|---|
| 2 | ** (c)2009 Broadcom Corporation |
|---|
| 3 | ** |
|---|
| 4 | ** This program is the proprietary software of Broadcom Corporation and/or its licensors, |
|---|
| 5 | ** and may only be used, duplicated, modified or distributed pursuant to the terms and |
|---|
| 6 | ** conditions of a separate, written license agreement executed between you and Broadcom |
|---|
| 7 | ** (an "Authorized License"). Except as set forth in an Authorized License, Broadcom grants |
|---|
| 8 | ** no license (express or implied), right to use, or waiver of any kind with respect to the |
|---|
| 9 | ** Software, and Broadcom expressly reserves all rights in and to the Software and all |
|---|
| 10 | ** intellectual property rights therein. IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU |
|---|
| 11 | ** HAVE NO RIGHT TO USE THIS SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY |
|---|
| 12 | ** NOTIFY BROADCOM AND DISCONTINUE ALL USE OF THE SOFTWARE. |
|---|
| 13 | ** |
|---|
| 14 | ** Except as expressly set forth in the Authorized License, |
|---|
| 15 | ** |
|---|
| 16 | ** 1. This program, including its structure, sequence and organization, constitutes the valuable trade |
|---|
| 17 | ** secrets of Broadcom, and you shall use all reasonable efforts to protect the confidentiality thereof, |
|---|
| 18 | ** and to use this information only in connection with your use of Broadcom integrated circuit products. |
|---|
| 19 | ** |
|---|
| 20 | ** 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS" |
|---|
| 21 | ** AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, REPRESENTATIONS OR |
|---|
| 22 | ** WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO |
|---|
| 23 | ** THE SOFTWARE. BROADCOM SPECIFICALLY DISCLAIMS ANY AND ALL IMPLIED WARRANTIES |
|---|
| 24 | ** OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, |
|---|
| 25 | ** LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION |
|---|
| 26 | ** OR CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT OF |
|---|
| 27 | ** USE OR PERFORMANCE OF THE SOFTWARE. |
|---|
| 28 | ** |
|---|
| 29 | ** 3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR ITS |
|---|
| 30 | ** LICENSORS BE LIABLE FOR (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR |
|---|
| 31 | ** EXEMPLARY DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO YOUR |
|---|
| 32 | ** USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM HAS BEEN ADVISED OF |
|---|
| 33 | ** THE POSSIBILITY OF SUCH DAMAGES; OR (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT |
|---|
| 34 | ** ACTUALLY PAID FOR THE SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE |
|---|
| 35 | ** LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF ESSENTIAL PURPOSE OF |
|---|
| 36 | ** ANY LIMITED REMEDY. |
|---|
| 37 | ** |
|---|
| 38 | ** Created: 8/22/2002 by Jeffrey P. Fisher |
|---|
| 39 | ** |
|---|
| 40 | ** $brcm_Workfile: bgfx_font.h $ |
|---|
| 41 | ** $brcm_Revision: Refsw_7550/2 $ |
|---|
| 42 | ** $brcm_Date: 9/25/09 12:54p $ |
|---|
| 43 | ** |
|---|
| 44 | ** Revision History: |
|---|
| 45 | ** |
|---|
| 46 | ** $brcm_Log: /nexus/lib/softgfx/src/bgfx_font.h $ |
|---|
| 47 | ** |
|---|
| 48 | ** Refsw_7550/2 9/25/09 12:54p kagrawal |
|---|
| 49 | ** SW7550-50: Performance optimized gfx from 7003 latest |
|---|
| 50 | ** |
|---|
| 51 | ** Refsw_7550/1 9/7/09 5:04p kagrawal |
|---|
| 52 | ** SW7550-3: Initial check-in for Soft Graphics |
|---|
| 53 | ** |
|---|
| 54 | ****************************************************************/ |
|---|
| 55 | |
|---|
| 56 | #ifndef __sgil_font_h__ |
|---|
| 57 | #define __sgil_font_h__ |
|---|
| 58 | |
|---|
| 59 | #include "bgfx_types.h" |
|---|
| 60 | |
|---|
| 61 | /* Uncomment to build with freetype support */ |
|---|
| 62 | /* #define CONFIG_FREETYPE */ |
|---|
| 63 | |
|---|
| 64 | #ifdef CONFIG_FREETYPE |
|---|
| 65 | #include <freetype/freetype.h> |
|---|
| 66 | #include <freetype/ftglyph.h> |
|---|
| 67 | #endif /* CONFIG_FREETYPE */ |
|---|
| 68 | /* |
|---|
| 69 | * Definitions |
|---|
| 70 | */ |
|---|
| 71 | |
|---|
| 72 | /* |
|---|
| 73 | * font flags |
|---|
| 74 | */ |
|---|
| 75 | #define SGL_MONO (1 << 0) |
|---|
| 76 | #define SGL_CACHE_GLYPHS (1 << 1) |
|---|
| 77 | #define SGL_PRELOAD_GLYPHS (1 << 2) |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | #ifdef __cplusplus |
|---|
| 81 | extern "C" { |
|---|
| 82 | #endif |
|---|
| 83 | |
|---|
| 84 | /**************************************************************** |
|---|
| 85 | * Initialize global font management structures. |
|---|
| 86 | * Called by sgil_init. |
|---|
| 87 | ****************************************************************/ |
|---|
| 88 | int bgfx_font_init(void); |
|---|
| 89 | /**************************************************************** |
|---|
| 90 | * Cleanup global font management structures. |
|---|
| 91 | * Called by sgil_done. |
|---|
| 92 | ****************************************************************/ |
|---|
| 93 | void bgfx_font_done(void); |
|---|
| 94 | |
|---|
| 95 | /**************************************************************** |
|---|
| 96 | * Create a new font give an typeface name and size. |
|---|
| 97 | * The font_p should be a pointer to an allocated |
|---|
| 98 | * but uninitialized bgfx_font_t structure. The typeface must be |
|---|
| 99 | * a valid full path name to the font file. Valid flags can be any |
|---|
| 100 | * combination of SGL_MONO,SGL_CACHE_GLYPHS and SGL_PRELOAD_GLYPHS |
|---|
| 101 | * REQUIRES FREETYPE SUPPORT |
|---|
| 102 | ****************************************************************/ |
|---|
| 103 | int bgfx_new_font( bgfx_font_t *font_p, /* reference to allocated uninitialized bgfx_font_t structure */ |
|---|
| 104 | const char *typeface_name, /* full path name of the typeface file */ |
|---|
| 105 | unsigned char height, /* font size in pixels */ |
|---|
| 106 | unsigned long flags /* font format and handling flags */ |
|---|
| 107 | ); |
|---|
| 108 | /**************************************************************** |
|---|
| 109 | * Free all resources associated with the font |
|---|
| 110 | * It is important to free fonts when done using them to return memory |
|---|
| 111 | * resources consumed by the font cache and Freetype. |
|---|
| 112 | ****************************************************************/ |
|---|
| 113 | void bgfx_free_font( bgfx_font_t *font_p /* reference to initialized bgfx_font_t structure */ |
|---|
| 114 | ); |
|---|
| 115 | |
|---|
| 116 | /**************************************************************** |
|---|
| 117 | * Get a glyph from the glyph cache if it exists or by rendering it |
|---|
| 118 | * with Freetype |
|---|
| 119 | * The font_p should be a pointer to an initialized bgfx_font_t structure. |
|---|
| 120 | * Called internally by sgil. |
|---|
| 121 | ****************************************************************/ |
|---|
| 122 | bgfx_glyph_t *bgfx_get_glyph(bgfx_font_t *font_p, /* reference to initialized bgfx_font_t structure */ |
|---|
| 123 | unsigned long a_char /* 32-bit unicode character */ |
|---|
| 124 | ); |
|---|
| 125 | |
|---|
| 126 | /**************************************************************** |
|---|
| 127 | * Calculate the width and height of the null terminated string. |
|---|
| 128 | * Calculate the bounding rectangle for the null terminated string. |
|---|
| 129 | ****************************************************************/ |
|---|
| 130 | void bgfx_string_info(bgfx_font_t *font_p, /* initialized font structure */ |
|---|
| 131 | const unsigned long *str_p, /* array of single 32-bit unicode characters */ |
|---|
| 132 | int str_len, /* number of 32-bit characters in string */ |
|---|
| 133 | int *w, /* width in pixels */ |
|---|
| 134 | int *h /* height in pixels */ |
|---|
| 135 | ); |
|---|
| 136 | |
|---|
| 137 | /**************************************************************** |
|---|
| 138 | * Load the entire set of font info and glyph cache from a file. |
|---|
| 139 | * The file must have been produced by the bgfx_save_font function. |
|---|
| 140 | * This is the only way to draw text when there is no |
|---|
| 141 | * Freetype support. |
|---|
| 142 | ****************************************************************/ |
|---|
| 143 | int bgfx_load_font(bgfx_font_t *font_p, /* reference to initialized bgfx_font_t structure */ |
|---|
| 144 | void *file_p /* open initialized file pointer to read font from */ |
|---|
| 145 | ); |
|---|
| 146 | |
|---|
| 147 | /**************************************************************** |
|---|
| 148 | * External function required to load SGIL bitmap font files. |
|---|
| 149 | ****************************************************************/ |
|---|
| 150 | extern long bgfx_read(void *buffer, long size, long count, void *fp ); |
|---|
| 151 | |
|---|
| 152 | /**************************************************************** |
|---|
| 153 | * External functions to lock and unlock access to global data structures |
|---|
| 154 | * Required for freetype support only |
|---|
| 155 | ****************************************************************/ |
|---|
| 156 | #ifdef CONFIG_FREETYPE |
|---|
| 157 | extern void bgfx_lock(void); |
|---|
| 158 | extern void bgfx_unlock(void); |
|---|
| 159 | #endif /* CONFIG_FREETYPE */ |
|---|
| 160 | |
|---|
| 161 | #ifdef __cplusplus |
|---|
| 162 | } |
|---|
| 163 | #endif |
|---|
| 164 | |
|---|
| 165 | #endif /* __sgil_font_h__ */ |
|---|
| 166 | |
|---|