| 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: SGIL bit map font library |
|---|
| 12 | ** |
|---|
| 13 | ** Created: 8/22/2002 by Jeffrey P. Fisher |
|---|
| 14 | ** |
|---|
| 15 | ** |
|---|
| 16 | ** |
|---|
| 17 | ****************************************************************/ |
|---|
| 18 | |
|---|
| 19 | /** include files **/ |
|---|
| 20 | #include "bgfx.h" |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | static bgfx_glyph_t *bgfx_init_glyph(bgfx_font_t *font_p, FT_ULong a_char, int glyph_idx); |
|---|
| 24 | |
|---|
| 25 | /* global SGL structure */ |
|---|
| 26 | typedef struct bgfx_t |
|---|
| 27 | { |
|---|
| 28 | #ifdef CONFIG_FREETYPE |
|---|
| 29 | FT_Library ft_library; |
|---|
| 30 | #endif |
|---|
| 31 | int dummy; |
|---|
| 32 | }bgfx_t; |
|---|
| 33 | |
|---|
| 34 | #ifdef CONFIG_FREETYPE |
|---|
| 35 | static bgfx_t g_bgfx = { NULL }; |
|---|
| 36 | #endif |
|---|
| 37 | |
|---|
| 38 | /****************************************************************} |
|---|
| 39 | * INPUTS: none |
|---|
| 40 | * OUTPUTS: none |
|---|
| 41 | * RETURNS: non-zero on failure |
|---|
| 42 | * FUNCTION: Initialize the SGIL font library |
|---|
| 43 | * |
|---|
| 44 | ****************************************************************/ |
|---|
| 45 | int bgfx_font_init() |
|---|
| 46 | { |
|---|
| 47 | int result = 0; |
|---|
| 48 | |
|---|
| 49 | BGFX_TRACE(("font_init\n")); |
|---|
| 50 | #ifdef CONFIG_FREETYPE |
|---|
| 51 | bgfx_lock(); |
|---|
| 52 | { |
|---|
| 53 | FT_Error err; |
|---|
| 54 | err = FT_Init_FreeType( &g_bgfx.ft_library ); |
|---|
| 55 | if (err) |
|---|
| 56 | { |
|---|
| 57 | g_bgfx.ft_library = NULL; |
|---|
| 58 | result = -1; |
|---|
| 59 | BGFX_DEBUG(("font_init - FT_Init_FreeType(%d)\n",err)); |
|---|
| 60 | } |
|---|
| 61 | } |
|---|
| 62 | bgfx_unlock(); |
|---|
| 63 | #endif |
|---|
| 64 | BGFX_TRACE(("font_init - done\n")); |
|---|
| 65 | return result; |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | /****************************************************************} |
|---|
| 69 | * INPUTS: none |
|---|
| 70 | * OUTPUTS: none |
|---|
| 71 | * RETURNS: non-zero on failure |
|---|
| 72 | * FUNCTION: release sgl global resources, primarily for handling freetype |
|---|
| 73 | * |
|---|
| 74 | ****************************************************************/ |
|---|
| 75 | void bgfx_font_done() |
|---|
| 76 | { |
|---|
| 77 | BGFX_TRACE(("font_done\n")); |
|---|
| 78 | #ifdef CONFIG_FREETYPE |
|---|
| 79 | bgfx_lock(); |
|---|
| 80 | |
|---|
| 81 | if (g_bgfx.ft_library) |
|---|
| 82 | FT_Done_FreeType( g_bgfx.ft_library ); |
|---|
| 83 | g_bgfx.ft_library = NULL; |
|---|
| 84 | bgfx_unlock(); |
|---|
| 85 | #endif |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | #ifdef CONFIG_FREETYPE |
|---|
| 89 | /**************************************************************** |
|---|
| 90 | * INPUTS: fr_p - font ripper parameters |
|---|
| 91 | * OUTPUTS: none |
|---|
| 92 | * RETURNS: number of glyph entries |
|---|
| 93 | * DESCRIPTION: Get the maximum number of glyph index entries. |
|---|
| 94 | * |
|---|
| 95 | ****************************************************************/ |
|---|
| 96 | |
|---|
| 97 | int get_max_glyph_index(bgfx_font_t *font_p) |
|---|
| 98 | { |
|---|
| 99 | FT_ULong charcode; |
|---|
| 100 | FT_UInt gindex; |
|---|
| 101 | int cnt = 0; |
|---|
| 102 | |
|---|
| 103 | charcode = FT_Get_First_Char( font_p->face, &gindex ); |
|---|
| 104 | while ( gindex != 0 ) |
|---|
| 105 | { |
|---|
| 106 | ++cnt; |
|---|
| 107 | charcode = FT_Get_Next_Char( font_p->face, charcode, &gindex ); |
|---|
| 108 | } |
|---|
| 109 | return cnt; |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | /**************************************************************** |
|---|
| 113 | * INPUTS: font_p - font definition |
|---|
| 114 | * OUTPUTS: none |
|---|
| 115 | * RETURNS: none-zero on failure |
|---|
| 116 | * FUNCTION: create the charmap. |
|---|
| 117 | * |
|---|
| 118 | ****************************************************************/ |
|---|
| 119 | int bgfx_create_char_map(bgfx_font_t *font_p) |
|---|
| 120 | { |
|---|
| 121 | int i = 0; |
|---|
| 122 | FT_ULong charcode; |
|---|
| 123 | FT_UInt gindex; |
|---|
| 124 | |
|---|
| 125 | font_p->cache_size = get_max_glyph_index(font_p); |
|---|
| 126 | if (font_p->char_map_size <= 0) |
|---|
| 127 | { |
|---|
| 128 | BGFX_DEBUG(("bgfx_create_char_map failed, no unicode encoding for this font.\n")); |
|---|
| 129 | return -1; |
|---|
| 130 | } |
|---|
| 131 | font_p->char_map = (bgfx_glyph_t**)BGFX_MALLOC(sizeof(bgfx_glyph_t*) * font_p->cache_size ); |
|---|
| 132 | |
|---|
| 133 | if (!font_p->glyph_cache) |
|---|
| 134 | { |
|---|
| 135 | BGFX_DEBUG(("bgfx_create_char_map failed, could not allocate memory for char map.\n")); |
|---|
| 136 | return -1; |
|---|
| 137 | } |
|---|
| 138 | |
|---|
| 139 | bgfx_lock(); |
|---|
| 140 | charcode = FT_Get_First_Char( font_p->face, &gindex ); |
|---|
| 141 | while ( gindex != 0 ) |
|---|
| 142 | { |
|---|
| 143 | font_p->char_map[i++] = charcode; |
|---|
| 144 | |
|---|
| 145 | charcode = FT_Get_Next_Char( font_p->face, charcode, &gindex ); |
|---|
| 146 | } |
|---|
| 147 | bgfx_unlock(); |
|---|
| 148 | BGFX_TRACE(("bgfx_create_char_map - %d chars.\n",i)); |
|---|
| 149 | |
|---|
| 150 | return 0; |
|---|
| 151 | } |
|---|
| 152 | #endif /* CONFIG_FREETYPE */ |
|---|
| 153 | |
|---|
| 154 | /**************************************************************** |
|---|
| 155 | * INPUTS: font_p - font definition |
|---|
| 156 | * typeface_name - name of the typeface |
|---|
| 157 | * height - font height |
|---|
| 158 | * OUTPUTS: none |
|---|
| 159 | * RETURNS: none-zero on failure |
|---|
| 160 | * FUNCTION: Load the font typeface. |
|---|
| 161 | * |
|---|
| 162 | * The general usage convention in SGIL is to avoid memory allocation |
|---|
| 163 | * in SGIL functions. For example before calling bgfx_new_font a |
|---|
| 164 | * valid font_t structure must be created and passed to bgfx_new_font. |
|---|
| 165 | * The font_t structure is modified but not allocated by bgfx_new_font. |
|---|
| 166 | * A primary exception is that the glyph cache and glyphs are |
|---|
| 167 | * allocated and manage internally. Therefore, it is important to |
|---|
| 168 | * call bgfx_free_font to allow SGIL to perform cleanup on the glyph cache. |
|---|
| 169 | ****************************************************************/ |
|---|
| 170 | int bgfx_new_font(bgfx_font_t *font_p, |
|---|
| 171 | const char *typeface_name, unsigned char height,unsigned long flags) |
|---|
| 172 | { |
|---|
| 173 | BGFX_TRACE(("bgfx_new_font - %s:%d,%ld\n",typeface_name,height,flags)); |
|---|
| 174 | #ifdef CONFIG_FREETYPE |
|---|
| 175 | { |
|---|
| 176 | FT_Error err; |
|---|
| 177 | unsigned long i; |
|---|
| 178 | bgfx_glyph_t *glyph; |
|---|
| 179 | |
|---|
| 180 | bgfx_lock(); |
|---|
| 181 | |
|---|
| 182 | err = FT_New_Face( g_bgfx.ft_library, typeface_name,0, &font_p->face ); |
|---|
| 183 | if (err) |
|---|
| 184 | { |
|---|
| 185 | BGFX_DEBUG(("bgfx_new_font could not open typeface %s\n",typeface_name)); |
|---|
| 186 | bgfx_unlock(); |
|---|
| 187 | return -1; |
|---|
| 188 | } |
|---|
| 189 | |
|---|
| 190 | err = FT_Select_Charmap( font_p->face, ft_encoding_unicode ); |
|---|
| 191 | #if FREETYPE_MINOR > 0 |
|---|
| 192 | if (err) |
|---|
| 193 | { |
|---|
| 194 | BGFX_DEBUG(("bgfx_new_font could not open unicode charmap, default to latin\n")); |
|---|
| 195 | err = FT_Select_Charmap( font_p->face, ft_encoding_latin_1 ); |
|---|
| 196 | } |
|---|
| 197 | #endif |
|---|
| 198 | if (err) |
|---|
| 199 | { |
|---|
| 200 | BGFX_DEBUG(("bgfx_new_font could not select charmap for font %s\n",typeface_name)); |
|---|
| 201 | bgfx_unlock(); |
|---|
| 202 | return -1; |
|---|
| 203 | } |
|---|
| 204 | err = FT_Set_Pixel_Sizes( font_p->face, 0, height); |
|---|
| 205 | if (err) |
|---|
| 206 | { |
|---|
| 207 | BGFX_DEBUG(("bgfx_new_font could set font height to %d\n",height)); |
|---|
| 208 | FT_Done_Face( font_p->face ); |
|---|
| 209 | bgfx_unlock(); |
|---|
| 210 | return -1; |
|---|
| 211 | } |
|---|
| 212 | if (flags & BGFX_MONO) |
|---|
| 213 | font_p->face->generic.data = (void *) (FT_LOAD_DEFAULT | FT_LOAD_MONOCHROME); |
|---|
| 214 | else |
|---|
| 215 | font_p->face->generic.data = (void *) FT_LOAD_DEFAULT; |
|---|
| 216 | font_p->ascender = font_p->face->size->metrics.ascender >> 6; |
|---|
| 217 | font_p->descender = font_p->face->size->metrics.descender >> 6; |
|---|
| 218 | font_p->height = (font_p->face->size->metrics.ascender - |
|---|
| 219 | font_p->face->size->metrics.descender) >> 6; |
|---|
| 220 | font_p->maxadvance = font_p->face->size->metrics.max_advance >> 6; |
|---|
| 221 | |
|---|
| 222 | /* create glyph cache */ |
|---|
| 223 | if (flags & BGFX_CACHE_GLYPHS) |
|---|
| 224 | { |
|---|
| 225 | font_p->cache_size = font_p->face->num_glyphs; |
|---|
| 226 | font_p->glyph_cache = (bgfx_glyph_t**)BGFX_MALLOC(sizeof(bgfx_glyph_t*) * font_p->cache_size); |
|---|
| 227 | if (font_p->glyph_cache) |
|---|
| 228 | BGFX_MEMSET(font_p->glyph_cache,0,sizeof(bgfx_glyph_t*) * font_p->cache_size); |
|---|
| 229 | else |
|---|
| 230 | font_p->cache_size = 0; |
|---|
| 231 | } |
|---|
| 232 | else |
|---|
| 233 | { |
|---|
| 234 | font_p->cache_size = 0; |
|---|
| 235 | font_p->glyph_cache = NULL; |
|---|
| 236 | } |
|---|
| 237 | font_p->format = flags; |
|---|
| 238 | bgfx_unlock(); |
|---|
| 239 | |
|---|
| 240 | if (bgfx_create_char_map(font_p) != 0) |
|---|
| 241 | { |
|---|
| 242 | BGFX_DEBUG(("bgfx_new_font could not create charmap\n")); |
|---|
| 243 | FT_Done_Face( font_p->face ); |
|---|
| 244 | return -1; |
|---|
| 245 | } |
|---|
| 246 | |
|---|
| 247 | if (flags & BGFX_PRELOAD_GLYPHS) |
|---|
| 248 | { |
|---|
| 249 | for (i = 0; i < font_p->cache_size; ++i) |
|---|
| 250 | glyph = bgfx_init_glyph(font_p,font_p->char_map[i],i); |
|---|
| 251 | } |
|---|
| 252 | } |
|---|
| 253 | return 0; |
|---|
| 254 | #else |
|---|
| 255 | return -1; /* must load fonts when there is no freetype support */ |
|---|
| 256 | #endif |
|---|
| 257 | } |
|---|
| 258 | /**************************************************************** |
|---|
| 259 | * INPUTS: font_p - font definition |
|---|
| 260 | * OUTPUTS: none |
|---|
| 261 | * RETURNS: none |
|---|
| 262 | * FUNCTION: Free font typeface. |
|---|
| 263 | * |
|---|
| 264 | ****************************************************************/ |
|---|
| 265 | void bgfx_free_font(bgfx_font_t *font_p) |
|---|
| 266 | { |
|---|
| 267 | if (font_p->glyph_cache[0]->buf) |
|---|
| 268 | BGFX_FREE(font_p->glyph_cache[0]->buf); |
|---|
| 269 | if (font_p->glyph_cache[0]) |
|---|
| 270 | BGFX_FREE(font_p->glyph_cache[0]); |
|---|
| 271 | if (font_p->char_map) |
|---|
| 272 | BGFX_FREE(font_p->char_map); |
|---|
| 273 | if (font_p->glyph_cache) |
|---|
| 274 | BGFX_FREE(font_p->glyph_cache); |
|---|
| 275 | #if 0 |
|---|
| 276 | int i; |
|---|
| 277 | for (i = 0; i < font_p->cache_size; ++i) |
|---|
| 278 | { |
|---|
| 279 | bgfx_glyph_t *glyph = font_p->glyph_cache[i]; |
|---|
| 280 | if (glyph) |
|---|
| 281 | { |
|---|
| 282 | BGFX_FREE(glyph->buf); |
|---|
| 283 | BGFX_FREE(glyph); |
|---|
| 284 | font_p->glyph_cache[i] = NULL; |
|---|
| 285 | } |
|---|
| 286 | } |
|---|
| 287 | BGFX_FREE(font_p->glyph_cache); |
|---|
| 288 | #ifdef CONFIG_FREETYPE |
|---|
| 289 | FT_Done_Face (font_p->face); |
|---|
| 290 | #endif |
|---|
| 291 | #endif |
|---|
| 292 | } |
|---|
| 293 | |
|---|
| 294 | /**************************************************************** |
|---|
| 295 | * INPUTS: font_p - font |
|---|
| 296 | * a_char - the character |
|---|
| 297 | * glyph_idx - glyph index |
|---|
| 298 | * OUTPUTS: info - return char info |
|---|
| 299 | * RETURNS: glyph reference |
|---|
| 300 | * FUNCTION: Initialize a glyph data structure (FREETYPE ONLY). |
|---|
| 301 | * |
|---|
| 302 | ****************************************************************/ |
|---|
| 303 | static bgfx_glyph_t *bgfx_init_glyph(bgfx_font_t *font_p, FT_ULong a_char, int glyph_idx) |
|---|
| 304 | { |
|---|
| 305 | #ifdef CONFIG_FREETYPE |
|---|
| 306 | FT_Error err; |
|---|
| 307 | FT_Int ld_flags; |
|---|
| 308 | FT_UInt index; |
|---|
| 309 | bgfx_glyph_t *new_glyph; |
|---|
| 310 | unsigned long nbytes; |
|---|
| 311 | |
|---|
| 312 | BGFX_TRACE(("bgfx_init_glyph 0x%08lx\n",a_char)); |
|---|
| 313 | |
|---|
| 314 | bgfx_lock(); |
|---|
| 315 | |
|---|
| 316 | index = FT_Get_Char_Index(font_p->face,a_char); |
|---|
| 317 | if (index == 0) |
|---|
| 318 | { |
|---|
| 319 | BGFX_DEBUG(("bgfx_init_glyph could not find char 0x%08lx in FreeType char map\n",a_char)); |
|---|
| 320 | bgfx_unlock(); |
|---|
| 321 | return NULL; |
|---|
| 322 | } |
|---|
| 323 | |
|---|
| 324 | ld_flags = (FT_Int) font_p->face->generic.data; |
|---|
| 325 | ld_flags |= FT_LOAD_RENDER; |
|---|
| 326 | err = FT_Load_Glyph( font_p->face, index, ld_flags ); |
|---|
| 327 | if (err) |
|---|
| 328 | { |
|---|
| 329 | BGFX_DEBUG(("bgfx_init_glyph could not load glyph %d\n",index)); |
|---|
| 330 | bgfx_unlock(); |
|---|
| 331 | return NULL; |
|---|
| 332 | } |
|---|
| 333 | |
|---|
| 334 | /* allocate memory for glyph */ |
|---|
| 335 | |
|---|
| 336 | new_glyph = (bgfx_glyph_t*)BGFX_MALLOC(sizeof(bgfx_glyph_t)); |
|---|
| 337 | if (!new_glyph) |
|---|
| 338 | { |
|---|
| 339 | BGFX_DEBUG(("bgfx_init_glyph could allocate memory for glyph\n")); |
|---|
| 340 | bgfx_unlock(); |
|---|
| 341 | return NULL; |
|---|
| 342 | } |
|---|
| 343 | new_glyph->left = font_p->face->glyph->bitmap_left; |
|---|
| 344 | new_glyph->top = font_p->face->glyph->bitmap_top; |
|---|
| 345 | new_glyph->advance = font_p->face->glyph->advance.x >> 6; |
|---|
| 346 | new_glyph->width = font_p->face->glyph->bitmap.width; |
|---|
| 347 | new_glyph->height = font_p->face->glyph->bitmap.rows; |
|---|
| 348 | new_glyph->pitch = font_p->face->glyph->bitmap.pitch; |
|---|
| 349 | |
|---|
| 350 | nbytes = font_p->face->glyph->bitmap.pitch * font_p->face->glyph->bitmap.rows; |
|---|
| 351 | new_glyph->buf = (unsigned char*)BGFX_MALLOC(nbytes); |
|---|
| 352 | |
|---|
| 353 | if (!new_glyph->buf) |
|---|
| 354 | { |
|---|
| 355 | BGFX_FREE(new_glyph); |
|---|
| 356 | BGFX_DEBUG(("bgfx_init_glyph could allocate memory for glyph\n")); |
|---|
| 357 | bgfx_unlock(); |
|---|
| 358 | return NULL; |
|---|
| 359 | } |
|---|
| 360 | |
|---|
| 361 | /* copy glyph data */ |
|---|
| 362 | BGFX_MEMCPY(new_glyph->buf, font_p->face->glyph->bitmap.buffer,nbytes); |
|---|
| 363 | font_p->glyph_cache[glyph_idx] = new_glyph; |
|---|
| 364 | |
|---|
| 365 | bgfx_unlock(); |
|---|
| 366 | return new_glyph; |
|---|
| 367 | #else |
|---|
| 368 | return NULL; |
|---|
| 369 | #endif |
|---|
| 370 | } |
|---|
| 371 | /**************************************************************** |
|---|
| 372 | * INPUTS: font_p - font |
|---|
| 373 | * a_char - char value |
|---|
| 374 | * OUTPUTS: none |
|---|
| 375 | * RETURNS: glyph cache index or -1 on failure |
|---|
| 376 | * FUNCTION: Get a glyph cache index from the char_map. |
|---|
| 377 | * |
|---|
| 378 | ****************************************************************/ |
|---|
| 379 | static inline int bgfx_map_char(bgfx_font_t *font_p, unsigned long a_char) |
|---|
| 380 | { |
|---|
| 381 | register int i; |
|---|
| 382 | for (i = 0; i < font_p->cache_size; ++i) |
|---|
| 383 | { |
|---|
| 384 | if (font_p->char_map[i] == a_char) |
|---|
| 385 | return i; |
|---|
| 386 | } |
|---|
| 387 | return -1; |
|---|
| 388 | } |
|---|
| 389 | /**************************************************************** |
|---|
| 390 | * INPUTS: font_p - font |
|---|
| 391 | * a_char - char value |
|---|
| 392 | * OUTPUTS: info - return char info |
|---|
| 393 | * RETURNS: glyph reference |
|---|
| 394 | * FUNCTION: Get a glyph from the glyph cache or a fresh rendering. |
|---|
| 395 | * |
|---|
| 396 | ****************************************************************/ |
|---|
| 397 | bgfx_glyph_t *bgfx_get_glyph(bgfx_font_t *font_p, unsigned long a_char) |
|---|
| 398 | { |
|---|
| 399 | int cache_index; |
|---|
| 400 | BGFX_TRACE(("bgfx_get_glyph 0x%08lx\n",a_char)); |
|---|
| 401 | |
|---|
| 402 | /* Check for glyph in glyph cache */ |
|---|
| 403 | cache_index = bgfx_map_char(font_p,a_char); |
|---|
| 404 | if (cache_index < 0) |
|---|
| 405 | { |
|---|
| 406 | BGFX_DEBUG(("bgfx_get_glyph failed 0x%08lx not in font.\n",a_char)); |
|---|
| 407 | return NULL; |
|---|
| 408 | } |
|---|
| 409 | |
|---|
| 410 | BGFX_TRACE(("bgfx_get_glyph find char in cache 0x%08lx (%ld)\n",cache_index,cache_index)); |
|---|
| 411 | if (font_p->glyph_cache[cache_index] != NULL) |
|---|
| 412 | { |
|---|
| 413 | BGFX_TRACE(("bgfx_get_glyph found char in cache\n")); |
|---|
| 414 | return font_p->glyph_cache[cache_index]; |
|---|
| 415 | } |
|---|
| 416 | return bgfx_init_glyph(font_p,a_char,cache_index); |
|---|
| 417 | } |
|---|
| 418 | /**************************************************************** |
|---|
| 419 | * INPUTS: font_p - font definition |
|---|
| 420 | * str_p - array of single 32-bit unicode characters |
|---|
| 421 | * str_len - number of 32-bit characters in string |
|---|
| 422 | * OUTPUTS: w,h - width and height in pixels of the string |
|---|
| 423 | * RETURNS: none |
|---|
| 424 | * FUNCTION: Caclulate the bound rectangle for the string. |
|---|
| 425 | * |
|---|
| 426 | ****************************************************************/ |
|---|
| 427 | |
|---|
| 428 | void bgfx_string_info(bgfx_font_t *font_p, /* initialized font structure */ |
|---|
| 429 | const unsigned long *str_p, /* array of single 32-bit unicode characters */ |
|---|
| 430 | int str_len, /* number of 32-bit characters in string */ |
|---|
| 431 | int *w, /* width in pixels */ |
|---|
| 432 | int *h /* height in pixels */ |
|---|
| 433 | ) |
|---|
| 434 | { |
|---|
| 435 | unsigned long current; |
|---|
| 436 | int offset; |
|---|
| 437 | bgfx_glyph_t * bgfx_glyph; |
|---|
| 438 | #ifdef CONFIG_FREETYPE |
|---|
| 439 | bgfx_glyph_t info; |
|---|
| 440 | FT_Error err; |
|---|
| 441 | FT_Int ld_flags; |
|---|
| 442 | FT_UInt index; |
|---|
| 443 | #endif |
|---|
| 444 | *w = 0; *h = 0; |
|---|
| 445 | bgfx_glyph = NULL; |
|---|
| 446 | BGFX_TRACE(("bgfx_string_info %s\n",str_p)); |
|---|
| 447 | |
|---|
| 448 | *h = font_p->height; |
|---|
| 449 | for (offset = 0; offset < str_len; offset++) |
|---|
| 450 | { |
|---|
| 451 | current = str_p[offset]; |
|---|
| 452 | BGFX_TRACE(("bgfx_string_info (0x%08lx)\n",current)); |
|---|
| 453 | |
|---|
| 454 | /* if using glyph cache use the get glyph rather than render directly to surface buffer */ |
|---|
| 455 | if (font_p->cache_size > 0) |
|---|
| 456 | { |
|---|
| 457 | bgfx_glyph = bgfx_get_glyph(font_p,current); |
|---|
| 458 | } |
|---|
| 459 | #ifdef CONFIG_FREETYPE |
|---|
| 460 | if (!bgfx_glyph) |
|---|
| 461 | { |
|---|
| 462 | bgfx_lock(); |
|---|
| 463 | bgfx_glyph = &info; |
|---|
| 464 | |
|---|
| 465 | index = FT_Get_Char_Index( font_p->face, current ); |
|---|
| 466 | BGFX_TRACE(("bgfx_string_info %d\n",index)); |
|---|
| 467 | |
|---|
| 468 | ld_flags = (FT_Int) font_p->face->generic.data; |
|---|
| 469 | ld_flags |= FT_LOAD_RENDER; |
|---|
| 470 | err = FT_Load_Glyph( font_p->face, index, ld_flags ); |
|---|
| 471 | if (err) |
|---|
| 472 | { |
|---|
| 473 | BGFX_DEBUG(("bgfx_string_info could not load glyph %p\n",bgfx_glyph)); |
|---|
| 474 | bgfx_unlock(); |
|---|
| 475 | return; |
|---|
| 476 | } |
|---|
| 477 | bgfx_unlock(); |
|---|
| 478 | |
|---|
| 479 | bgfx_glyph->left = font_p->face->glyph->bitmap_left; |
|---|
| 480 | bgfx_glyph->top = font_p->face->glyph->bitmap_top; |
|---|
| 481 | |
|---|
| 482 | bgfx_glyph->advance = font_p->face->glyph->advance.x >> 6; |
|---|
| 483 | bgfx_glyph->width = font_p->face->glyph->bitmap.width; |
|---|
| 484 | |
|---|
| 485 | bgfx_glyph->height = font_p->face->glyph->bitmap.rows; |
|---|
| 486 | |
|---|
| 487 | bgfx_glyph->buf = font_p->face->glyph->bitmap.buffer; |
|---|
| 488 | bgfx_glyph->pitch = font_p->face->glyph->bitmap.pitch; |
|---|
| 489 | } |
|---|
| 490 | #endif |
|---|
| 491 | if (!bgfx_glyph) |
|---|
| 492 | { |
|---|
| 493 | BGFX_DEBUG(("bgfx_string_info could not load glyph for char 0x%08lx\n",current)); |
|---|
| 494 | return; |
|---|
| 495 | } |
|---|
| 496 | *w += bgfx_glyph->advance; |
|---|
| 497 | } |
|---|
| 498 | } |
|---|
| 499 | #if 1 |
|---|
| 500 | /**************************************************************** |
|---|
| 501 | * INPUTS: font_p - font definition |
|---|
| 502 | * file_p - file descriptor |
|---|
| 503 | * OUTPUTS: none |
|---|
| 504 | * RETURNS: none-zero on failure |
|---|
| 505 | * FUNCTION: Load the font typeface from a binary file. |
|---|
| 506 | * |
|---|
| 507 | ****************************************************************/ |
|---|
| 508 | static int bgfx_calc_mem_font(bgfx_font_t *font_p,void *file_p) |
|---|
| 509 | { |
|---|
| 510 | int err,size; |
|---|
| 511 | unsigned long i; |
|---|
| 512 | int result = -1; |
|---|
| 513 | |
|---|
| 514 | size = 0; |
|---|
| 515 | size += sizeof(FT_ULong) * font_p->cache_size; |
|---|
| 516 | |
|---|
| 517 | /* Load bitmaps */ |
|---|
| 518 | for (i = 0; i < font_p->cache_size; ++i) |
|---|
| 519 | { |
|---|
| 520 | bgfx_glyph_t glyph; |
|---|
| 521 | |
|---|
| 522 | BGFX_IO_CHECK (bgfx_read((void*)&glyph.left,1,sizeof(glyph.left),file_p)); |
|---|
| 523 | BGFX_IO_CHECK (bgfx_read((void*)&glyph.top,1,sizeof(glyph.top),file_p)); |
|---|
| 524 | BGFX_IO_CHECK (bgfx_read((void*)&glyph.advance,1,sizeof(glyph.advance),file_p)); |
|---|
| 525 | BGFX_IO_CHECK (bgfx_read((void*)&glyph.width,1,sizeof(glyph.width),file_p)); |
|---|
| 526 | BGFX_IO_CHECK (bgfx_read((void*)&glyph.height,1,sizeof(glyph.height),file_p)); |
|---|
| 527 | BGFX_IO_CHECK (bgfx_read((void*)&glyph.pitch,1,sizeof(glyph.pitch),file_p)); |
|---|
| 528 | BGFX_TRACE(("bgfx_load_font glyph %ld\n",i)); |
|---|
| 529 | BGFX_TRACE(("bgfx_load_font glyph->pitch %d\n",glyph.pitch)); |
|---|
| 530 | BGFX_TRACE(("bgfx_load_font glyph->height %d\n",glyph.height)); |
|---|
| 531 | BGFX_TRACE(("bgfx_load_font glyph->left %d\n",glyph.left)); |
|---|
| 532 | if ((glyph.pitch * glyph.height) > 0) |
|---|
| 533 | { |
|---|
| 534 | size += glyph.pitch * glyph.height; |
|---|
| 535 | bgfx_set(file_p,bgfx_tell(file_p) + (glyph.pitch * glyph.height), 0); |
|---|
| 536 | } |
|---|
| 537 | } |
|---|
| 538 | result = 0; |
|---|
| 539 | done: |
|---|
| 540 | if (result != 0) |
|---|
| 541 | return -1; |
|---|
| 542 | return size; |
|---|
| 543 | } |
|---|
| 544 | |
|---|
| 545 | /**************************************************************** |
|---|
| 546 | * INPUTS: font_p - font definition |
|---|
| 547 | * file_p - file descriptor |
|---|
| 548 | * OUTPUTS: none |
|---|
| 549 | * RETURNS: none-zero on failure |
|---|
| 550 | * FUNCTION: Load the font typeface from a binary file. |
|---|
| 551 | * |
|---|
| 552 | ****************************************************************/ |
|---|
| 553 | int bgfx_load_font(bgfx_font_t *font_p,void *file_p) |
|---|
| 554 | { |
|---|
| 555 | int result = -1; |
|---|
| 556 | int err; |
|---|
| 557 | unsigned long i,fsize,pos; |
|---|
| 558 | bgfx_glyph_t *glyph_bufs = NULL; |
|---|
| 559 | bgfx_glyph_t *glyph = NULL; |
|---|
| 560 | unsigned char* fbuf = NULL; |
|---|
| 561 | |
|---|
| 562 | /* write font header */ |
|---|
| 563 | BGFX_MEMSET(font_p,0,sizeof(bgfx_font_t)); |
|---|
| 564 | BGFX_IO_CHECK (bgfx_read((void*)&font_p->ascender,1, sizeof(font_p->ascender),file_p)); |
|---|
| 565 | font_p->ascender = BGFX_SWAP_INT(font_p->ascender); |
|---|
| 566 | BGFX_IO_CHECK (bgfx_read((void*)&font_p->descender,1, sizeof(font_p->descender),file_p)); |
|---|
| 567 | font_p->descender = BGFX_SWAP_INT(font_p->descender); |
|---|
| 568 | BGFX_IO_CHECK (bgfx_read((void*)&font_p->height,1, sizeof(font_p->height),file_p)); |
|---|
| 569 | font_p->height = BGFX_SWAP_INT(font_p->height); |
|---|
| 570 | BGFX_IO_CHECK (bgfx_read((void*)&font_p->maxadvance,1, sizeof(font_p->maxadvance),file_p)); |
|---|
| 571 | font_p->maxadvance = BGFX_SWAP_INT(font_p->maxadvance); |
|---|
| 572 | BGFX_IO_CHECK (bgfx_read((void*)&font_p->format,1, sizeof(font_p->format),file_p)); |
|---|
| 573 | font_p->format = BGFX_SWAP_ULONG(font_p->format); |
|---|
| 574 | BGFX_IO_CHECK (bgfx_read((void*)&font_p->cache_size,1, sizeof(font_p->cache_size),file_p)); |
|---|
| 575 | font_p->cache_size = BGFX_SWAP_INT(font_p->cache_size); |
|---|
| 576 | |
|---|
| 577 | if (font_p->height % 2) |
|---|
| 578 | { |
|---|
| 579 | font_p->ascender += 1; |
|---|
| 580 | } |
|---|
| 581 | font_p->glyph_cache = (bgfx_glyph_t**)BGFX_MALLOC(sizeof(bgfx_glyph_t*) * font_p->cache_size ); |
|---|
| 582 | |
|---|
| 583 | BGFX_MEMSET(font_p->glyph_cache,0,sizeof(bgfx_glyph_t*) * font_p->cache_size); |
|---|
| 584 | |
|---|
| 585 | glyph_bufs = (bgfx_glyph_t*)BGFX_MALLOC(sizeof(bgfx_glyph_t) * font_p->cache_size ); |
|---|
| 586 | font_p->char_map = (FT_ULong*)BGFX_MALLOC(sizeof(FT_ULong) * font_p->cache_size ); |
|---|
| 587 | |
|---|
| 588 | if (!font_p->char_map || !glyph_bufs || !font_p->glyph_cache) |
|---|
| 589 | goto done; |
|---|
| 590 | |
|---|
| 591 | /* load character map */ |
|---|
| 592 | for (i = 0; i < font_p->cache_size; ++i) |
|---|
| 593 | { |
|---|
| 594 | BGFX_IO_CHECK (bgfx_read((void*)&(font_p->char_map[i]),1, sizeof(FT_ULong), file_p )); |
|---|
| 595 | font_p->char_map[i] = BGFX_SWAP_ULONG(font_p->char_map[i]); |
|---|
| 596 | } |
|---|
| 597 | |
|---|
| 598 | pos = bgfx_tell(file_p); |
|---|
| 599 | fsize = bgfx_calc_mem_font(font_p,file_p); |
|---|
| 600 | bgfx_set(file_p,pos,0); |
|---|
| 601 | |
|---|
| 602 | fbuf = BGFX_MALLOC(fsize); |
|---|
| 603 | if ((fsize <= 0) || !fbuf) |
|---|
| 604 | goto done; |
|---|
| 605 | |
|---|
| 606 | /* Load bitmaps */ |
|---|
| 607 | for (i = 0; i < font_p->cache_size; ++i) |
|---|
| 608 | { |
|---|
| 609 | BGFX_MEMSET(glyph_bufs,0,sizeof(bgfx_glyph_t)); |
|---|
| 610 | glyph = glyph_bufs++; |
|---|
| 611 | font_p->glyph_cache[i] = glyph; |
|---|
| 612 | BGFX_IO_CHECK (bgfx_read((void*)&glyph->left,1,sizeof(glyph->left),file_p)); |
|---|
| 613 | BGFX_IO_CHECK (bgfx_read((void*)&glyph->top,1,sizeof(glyph->top),file_p)); |
|---|
| 614 | BGFX_IO_CHECK (bgfx_read((void*)&glyph->advance,1,sizeof(glyph->advance),file_p)); |
|---|
| 615 | BGFX_IO_CHECK (bgfx_read((void*)&glyph->width,1,sizeof(glyph->width),file_p)); |
|---|
| 616 | BGFX_IO_CHECK (bgfx_read((void*)&glyph->height,1,sizeof(glyph->height),file_p)); |
|---|
| 617 | BGFX_IO_CHECK (bgfx_read((void*)&glyph->pitch,1,sizeof(glyph->pitch),file_p)); |
|---|
| 618 | BGFX_TRACE(("bgfx_load_font glyph %ld\n",i)); |
|---|
| 619 | BGFX_TRACE(("bgfx_load_font glyph->pitch %d\n",glyph->pitch)); |
|---|
| 620 | BGFX_TRACE(("bgfx_load_font glyph->height %d\n",glyph->height)); |
|---|
| 621 | BGFX_TRACE(("bgfx_load_font glyph->left %d\n",glyph->left)); |
|---|
| 622 | if ((glyph->pitch * glyph->height) > 0) |
|---|
| 623 | { |
|---|
| 624 | glyph->buf = (char*)fbuf; |
|---|
| 625 | BGFX_IO_CHECK (bgfx_read(glyph->buf,1, (glyph->pitch * glyph->height),file_p)); |
|---|
| 626 | fbuf += (glyph->pitch * glyph->height); |
|---|
| 627 | } |
|---|
| 628 | BGFX_TRACE(("bgfx_load_font glyph->buf %p\n",glyph->buf)); |
|---|
| 629 | } |
|---|
| 630 | result = 0; |
|---|
| 631 | done: |
|---|
| 632 | if (result != 0) |
|---|
| 633 | { |
|---|
| 634 | if (font_p->glyph_cache) |
|---|
| 635 | BGFX_FREE(font_p->glyph_cache); |
|---|
| 636 | if (font_p->char_map) |
|---|
| 637 | BGFX_FREE(font_p->char_map); |
|---|
| 638 | if (glyph_bufs) |
|---|
| 639 | BGFX_FREE(glyph_bufs); |
|---|
| 640 | if (fbuf) |
|---|
| 641 | BGFX_FREE(fbuf); |
|---|
| 642 | } |
|---|
| 643 | return result; |
|---|
| 644 | } |
|---|
| 645 | #else |
|---|
| 646 | |
|---|
| 647 | /**************************************************************** |
|---|
| 648 | * INPUTS: font_p - font definition |
|---|
| 649 | * file_p - file descriptor |
|---|
| 650 | * OUTPUTS: none |
|---|
| 651 | * RETURNS: none-zero on failure |
|---|
| 652 | * FUNCTION: Load the font typeface from a binary file. |
|---|
| 653 | * |
|---|
| 654 | ****************************************************************/ |
|---|
| 655 | int bgfx_load_font(bgfx_font_t *font_p,void *file_p) |
|---|
| 656 | { |
|---|
| 657 | int result = -1; |
|---|
| 658 | int err; |
|---|
| 659 | unsigned long i; |
|---|
| 660 | bgfx_glyph_t *glyph; |
|---|
| 661 | unsigned int size; |
|---|
| 662 | |
|---|
| 663 | /* write font header */ |
|---|
| 664 | BGFX_MEMSET(font_p,0,sizeof(bgfx_font_t)); |
|---|
| 665 | BGFX_IO_CHECK (bgfx_read((void*)&font_p->ascender,1, sizeof(font_p->ascender),file_p)); |
|---|
| 666 | font_p->ascender = BGFX_SWAP_INT(font_p->ascender); |
|---|
| 667 | BGFX_IO_CHECK (bgfx_read((void*)&font_p->descender,1, sizeof(font_p->descender),file_p)); |
|---|
| 668 | font_p->descender = BGFX_SWAP_INT(font_p->descender); |
|---|
| 669 | BGFX_IO_CHECK (bgfx_read((void*)&font_p->height,1, sizeof(font_p->height),file_p)); |
|---|
| 670 | font_p->height = BGFX_SWAP_INT(font_p->height); |
|---|
| 671 | BGFX_IO_CHECK (bgfx_read((void*)&font_p->maxadvance,1, sizeof(font_p->maxadvance),file_p)); |
|---|
| 672 | font_p->maxadvance = BGFX_SWAP_INT(font_p->maxadvance); |
|---|
| 673 | BGFX_IO_CHECK (bgfx_read((void*)&font_p->format,1, sizeof(font_p->format),file_p)); |
|---|
| 674 | font_p->format = BGFX_SWAP_ULONG(font_p->format); |
|---|
| 675 | BGFX_IO_CHECK (bgfx_read((void*)&font_p->cache_size,1, sizeof(font_p->cache_size),file_p)); |
|---|
| 676 | font_p->cache_size = BGFX_SWAP_INT(font_p->cache_size); |
|---|
| 677 | |
|---|
| 678 | font_p->glyph_cache = (bgfx_glyph_t**)BGFX_MALLOC(sizeof(bgfx_glyph_t*) * font_p->cache_size ); |
|---|
| 679 | size = sizeof(bgfx_glyph_t*) * font_p->cache_size; |
|---|
| 680 | BGFX_TRACE(("%s:%d size = %d\n",__FUNCTION__,__LINE__,size)); |
|---|
| 681 | |
|---|
| 682 | if (!font_p->glyph_cache) |
|---|
| 683 | goto done; |
|---|
| 684 | |
|---|
| 685 | BGFX_MEMSET(font_p->glyph_cache,0,sizeof(bgfx_glyph_t*) * font_p->cache_size); |
|---|
| 686 | |
|---|
| 687 | font_p->char_map = (FT_ULong*)BGFX_MALLOC(sizeof(FT_ULong) * font_p->cache_size ); |
|---|
| 688 | size += sizeof(FT_ULong) * font_p->cache_size; |
|---|
| 689 | BGFX_TRACE(("%s:%d size = %d\n",__FUNCTION__,__LINE__,size)); |
|---|
| 690 | |
|---|
| 691 | if (!font_p->char_map) |
|---|
| 692 | goto done; |
|---|
| 693 | |
|---|
| 694 | /* load character map */ |
|---|
| 695 | for (i = 0; i < font_p->cache_size; ++i) |
|---|
| 696 | { |
|---|
| 697 | BGFX_IO_CHECK (bgfx_read((void*)&(font_p->char_map[i]),1, sizeof(FT_ULong), file_p )); |
|---|
| 698 | font_p->char_map[i] = BGFX_SWAP_ULONG(font_p->char_map[i]); |
|---|
| 699 | } |
|---|
| 700 | |
|---|
| 701 | /* Load bitmaps */ |
|---|
| 702 | for (i = 0; i < font_p->cache_size; ++i) |
|---|
| 703 | { |
|---|
| 704 | glyph = (bgfx_glyph_t*)BGFX_MALLOC(sizeof(bgfx_glyph_t)); |
|---|
| 705 | size += sizeof(bgfx_glyph_t); |
|---|
| 706 | BGFX_TRACE(("%s:%d size = %d\n",__FUNCTION__,__LINE__,size)); |
|---|
| 707 | |
|---|
| 708 | if (!glyph) |
|---|
| 709 | goto done; |
|---|
| 710 | |
|---|
| 711 | BGFX_MEMSET(glyph,0,sizeof(bgfx_glyph_t)); |
|---|
| 712 | font_p->glyph_cache[i] = glyph; |
|---|
| 713 | |
|---|
| 714 | BGFX_IO_CHECK (bgfx_read((void*)&glyph->left,1,sizeof(glyph->left),file_p)); |
|---|
| 715 | BGFX_IO_CHECK (bgfx_read((void*)&glyph->top,1,sizeof(glyph->top),file_p)); |
|---|
| 716 | BGFX_IO_CHECK (bgfx_read((void*)&glyph->advance,1,sizeof(glyph->advance),file_p)); |
|---|
| 717 | BGFX_IO_CHECK (bgfx_read((void*)&glyph->width,1,sizeof(glyph->width),file_p)); |
|---|
| 718 | BGFX_IO_CHECK (bgfx_read((void*)&glyph->height,1,sizeof(glyph->height),file_p)); |
|---|
| 719 | BGFX_IO_CHECK (bgfx_read((void*)&glyph->pitch,1,sizeof(glyph->pitch),file_p)); |
|---|
| 720 | BGFX_TRACE(("bgfx_load_font glyph %ld\n",i)); |
|---|
| 721 | BGFX_TRACE(("bgfx_load_font glyph->pitch %d\n",glyph->pitch)); |
|---|
| 722 | BGFX_TRACE(("bgfx_load_font glyph->height %d\n",glyph->height)); |
|---|
| 723 | BGFX_TRACE(("bgfx_load_font glyph->left %d\n",glyph->left)); |
|---|
| 724 | if ((glyph->pitch * glyph->height) > 0) |
|---|
| 725 | { |
|---|
| 726 | glyph->buf = (char*)BGFX_MALLOC((glyph->pitch * glyph->height)); |
|---|
| 727 | size += glyph->pitch * glyph->height; |
|---|
| 728 | BGFX_TRACE(("%s:%d size = %d(%d,%d)\n",__FUNCTION__,__LINE__,size,glyph->pitch,glyph->height)); |
|---|
| 729 | if (!glyph->buf) |
|---|
| 730 | goto done; |
|---|
| 731 | BGFX_IO_CHECK (bgfx_read(glyph->buf,1, (glyph->pitch * glyph->height),file_p)); |
|---|
| 732 | } |
|---|
| 733 | BGFX_TRACE(("bgfx_load_font glyph->buf %p\n",glyph->buf)); |
|---|
| 734 | } |
|---|
| 735 | result = 0; |
|---|
| 736 | |
|---|
| 737 | done: |
|---|
| 738 | if (result != 0) |
|---|
| 739 | { |
|---|
| 740 | if (font_p->char_map) |
|---|
| 741 | free(font_p->char_map); |
|---|
| 742 | for (i = 0; i < font_p->cache_size; ++i) |
|---|
| 743 | { |
|---|
| 744 | if (font_p->glyph_cache[i]) |
|---|
| 745 | { |
|---|
| 746 | if (font_p->glyph_cache[i]->buf) |
|---|
| 747 | BGFX_FREE(font_p->glyph_cache[i]->buf); |
|---|
| 748 | BGFX_FREE(font_p->glyph_cache[i]); |
|---|
| 749 | } |
|---|
| 750 | } |
|---|
| 751 | } |
|---|
| 752 | return result; |
|---|
| 753 | } |
|---|
| 754 | |
|---|
| 755 | #endif |
|---|
| 756 | |
|---|
| 757 | void bgfx_scroll_info(bgfx_font_t *font_p, const unsigned long *str_p, |
|---|
| 758 | int str_len, unsigned char *char_width) |
|---|
| 759 | { |
|---|
| 760 | unsigned long current; |
|---|
| 761 | int offset; |
|---|
| 762 | bgfx_glyph_t *bgfx_glyph; |
|---|
| 763 | #ifdef CONFIG_FREETYPE |
|---|
| 764 | bgfx_glyph_t info; |
|---|
| 765 | FT_Error err; |
|---|
| 766 | FT_Int ld_flags; |
|---|
| 767 | FT_UInt index; |
|---|
| 768 | #endif |
|---|
| 769 | bgfx_glyph = NULL; |
|---|
| 770 | |
|---|
| 771 | for (offset = 0; offset < str_len; offset++) |
|---|
| 772 | { |
|---|
| 773 | current = str_p[offset]; |
|---|
| 774 | |
|---|
| 775 | /* if using glyph cache use the get glyph rather than render directly to surface buffer */ |
|---|
| 776 | if (font_p->cache_size > 0) |
|---|
| 777 | { |
|---|
| 778 | bgfx_glyph = bgfx_get_glyph(font_p,current); |
|---|
| 779 | } |
|---|
| 780 | #ifdef CONFIG_FREETYPE |
|---|
| 781 | if (!bgfx_glyph) |
|---|
| 782 | { |
|---|
| 783 | bgfx_lock(); |
|---|
| 784 | bgfx_glyph = &info; |
|---|
| 785 | |
|---|
| 786 | index = FT_Get_Char_Index( font_p->face, current ); |
|---|
| 787 | |
|---|
| 788 | ld_flags = (FT_Int) font_p->face->generic.data; |
|---|
| 789 | ld_flags |= FT_LOAD_RENDER; |
|---|
| 790 | err = FT_Load_Glyph( font_p->face, index, ld_flags ); |
|---|
| 791 | if (err) |
|---|
| 792 | { |
|---|
| 793 | bgfx_unlock(); |
|---|
| 794 | return; |
|---|
| 795 | } |
|---|
| 796 | bgfx_unlock(); |
|---|
| 797 | |
|---|
| 798 | bgfx_glyph->left = font_p->face->glyph->bitmap_left; |
|---|
| 799 | bgfx_glyph->top = font_p->face->glyph->bitmap_top; |
|---|
| 800 | |
|---|
| 801 | bgfx_glyph->advance = font_p->face->glyph->advance.x >> 6; |
|---|
| 802 | bgfx_glyph->width = font_p->face->glyph->bitmap.width; |
|---|
| 803 | |
|---|
| 804 | bgfx_glyph->height = font_p->face->glyph->bitmap.rows; |
|---|
| 805 | |
|---|
| 806 | bgfx_glyph->buf = font_p->face->glyph->bitmap.buffer; |
|---|
| 807 | bgfx_glyph->pitch = font_p->face->glyph->bitmap.pitch; |
|---|
| 808 | } |
|---|
| 809 | #endif |
|---|
| 810 | if (!bgfx_glyph) |
|---|
| 811 | { |
|---|
| 812 | /* if glyph is not available for this character, set length as 0 and continue */ |
|---|
| 813 | *(char_width+offset) = 0; |
|---|
| 814 | continue; |
|---|
| 815 | } |
|---|
| 816 | *(char_width+offset) = bgfx_glyph->advance; |
|---|
| 817 | } |
|---|
| 818 | *(char_width+str_len) = 0; |
|---|
| 819 | } |
|---|