| 654 | } |
| 655 | |
| 656 | TextMetrics ASTextContext::ASGetTextAtlasMetrics2(const std::string& path, int pixel_height, int flags, const std::string& txt, uint32_t char_limit) { |
| 657 | TextMetrics metrics; |
| 658 | |
| 659 | if (!text_atlas_renderer_setup) { |
| 660 | text_atlas_renderer.Init(); |
| 661 | text_atlas_renderer_setup = true; |
| 662 | } |
| 663 | if (path.length() >= CachedTextAtlas::kPathSize) { |
| 664 | DisplayError("Error", "Font path is too long"); |
| 665 | } else { |
| 666 | int found = -1; |
| 667 | for (int i = 0; i < atlases.num_atlases; ++i) { |
| 668 | CachedTextAtlas& cached = atlases.cached[i]; |
| 669 | if (strcmp(cached.path, path.c_str()) == 0 && |
| 670 | pixel_height == cached.pixel_height && |
| 671 | flags == cached.flags) { |
| 672 | found = i; |
| 673 | } |
| 674 | } |
| 675 | if (found == -1) { |
| 676 | if (atlases.num_atlases >= CachedTextAtlases::kMaxAtlases) { |
| 677 | DisplayError("Error", "Too many cached text atlases"); |
| 678 | } else { |
| 679 | found = atlases.num_atlases++; |
| 680 | CachedTextAtlas* new_atlas = &atlases.cached[found]; |
| 681 | strncpy(new_atlas->path, path.c_str(), CachedTextAtlas::kPathSize); |
| 682 | new_atlas->pixel_height = pixel_height; |
| 683 | new_atlas->flags = flags; |
| 684 | new_atlas->atlas.Create(path.c_str(), pixel_height, |
| 685 | font_renderer, flags); |
| 686 | } |
| 687 | } |
| 688 | if (found != -1) { |
| 689 | TextAtlas* atlas = &atlases.cached[found].atlas; |
| 690 | |
| 691 | text_atlas_renderer.num_characters = 0; |
| 692 | |
| 693 | metrics = text_atlas_renderer.GetMetrics(atlas, txt.c_str(), font_renderer, char_limit); |
| 694 | } |
| 695 | } |
| 696 | |
| 697 | return metrics; |
| 698 | } |
| 699 | |
| 700 | // TODO: this should not be a global variable right here |
| 701 | ASTextContext g_as_text_context; |
nothing calls this directly
no test coverage detected