| 377 | } |
| 378 | |
| 379 | FontResult GetOrCreateGlyphByIndex(dmRender::HFontMap font_map, HFont font, uint32_t glyph_index, FontGlyph** glyph) |
| 380 | { |
| 381 | uint64_t key = MakeGlyphIndexKey(font, glyph_index); |
| 382 | FontGlyph** pglyph = font_map->m_Glyphs.Get(key); |
| 383 | if (pglyph) |
| 384 | { |
| 385 | *glyph = *pglyph; |
| 386 | return FONT_RESULT_OK; |
| 387 | } |
| 388 | |
| 389 | FontResult r; |
| 390 | FontType type = FontGetType(font); |
| 391 | |
| 392 | if (type == FONT_TYPE_STBTTF) |
| 393 | { |
| 394 | // Since generating the SDF takes a long time (several milliseconds) |
| 395 | // we simply opt out of creating that data just-in-time |
| 396 | r = HandleCacheMiss(font_map, font, glyph_index, key, glyph); |
| 397 | if (FONT_RESULT_OK == r) |
| 398 | { |
| 399 | AddGlyph(font_map, key, *glyph); |
| 400 | return r; |
| 401 | } |
| 402 | return FONT_RESULT_ERROR; // we don't yet have the glyph |
| 403 | } |
| 404 | |
| 405 | // If we reached this point, it'a a .glyphbankc font |
| 406 | |
| 407 | FontGlyphOptions glyph_options; |
| 408 | glyph_options.m_Scale = 1.0f; // Glyph bank fonts are pre-rendered, so we use scale 1 for all its metrics |
| 409 | glyph_options.m_GenerateImage = true; // We want to get (or "generate" the glyphbank images) |
| 410 | |
| 411 | FontGlyph* out = new FontGlyph; |
| 412 | r = FontGetGlyphByIndex(font, glyph_index, &glyph_options, out); |
| 413 | if (FONT_RESULT_OK != r) |
| 414 | { |
| 415 | // Last chance to get the glyph just-in-time |
| 416 | r = HandleCacheMiss(font_map, font, glyph_index, key, glyph); |
| 417 | if (FONT_RESULT_OK == r) |
| 418 | { |
| 419 | AddGlyph(font_map, key, *glyph); |
| 420 | return r; |
| 421 | } |
| 422 | |
| 423 | delete out; |
| 424 | } |
| 425 | else |
| 426 | { |
| 427 | *glyph = out; |
| 428 | AddGlyph(font_map, key, *glyph); |
| 429 | } |
| 430 | |
| 431 | return r; |
| 432 | } |
| 433 | |
| 434 | // Used for test |
| 435 | FontResult GetOrCreateGlyph(dmRender::HFontMap font_map, HFont font, uint32_t codepoint, FontGlyph** glyph) |
no test coverage detected