| 759 | } |
| 760 | |
| 761 | bool TextAtlas::Pack(unsigned char* pixels, int atlas_dims[2], |
| 762 | int font_face_id, int lowercase_font_face_id, |
| 763 | FontRenderer* font_renderer, std::vector<CharacterInfo>& alphabet) { |
| 764 | PROFILER_ZONE(g_profiler_ctx, "TextAtlas::Pack"); |
| 765 | |
| 766 | for (int i = 0, len = atlas_dims[0] * atlas_dims[1]; i < len; ++i) { |
| 767 | pixels[i] = 0; |
| 768 | } |
| 769 | int draw[] = {0, 0}; |
| 770 | int max_height = 0; |
| 771 | |
| 772 | std::vector<CharacterInfo>::iterator character = alphabet.begin(); |
| 773 | |
| 774 | for (; character != alphabet.end(); character++) { |
| 775 | bool lowercase = (character->lowercase && lowercase_font_face_id != -1); |
| 776 | FT_GlyphSlot slot = |
| 777 | font_renderer->RenderCharacterBitmap( |
| 778 | lowercase ? lowercase_font_face_id : font_face_id, |
| 779 | character->codepoint, FontRenderer::RCB_RENDER); |
| 780 | FT_Bitmap* bitmap = &slot->bitmap; |
| 781 | if (character->width + draw[0] > atlas_dims[0]) { |
| 782 | draw[0] = 0; |
| 783 | draw[1] += max_height; |
| 784 | max_height = 0; |
| 785 | } |
| 786 | character->pos[0] = draw[0]; |
| 787 | character->pos[1] = draw[1]; |
| 788 | max_height = max(max_height, character->height); |
| 789 | for (int x = 0; x < character->width; ++x) { |
| 790 | for (int y = 0; y < character->height; ++y) { |
| 791 | if (draw[0] + x < atlas_dims[0] && draw[1] + y < atlas_dims[1]) { |
| 792 | pixels[(draw[1] + y) * atlas_dims[0] + draw[0] + x] = bitmap->buffer[y * character->width + x]; |
| 793 | } else { |
| 794 | return false; |
| 795 | } |
| 796 | } |
| 797 | } |
| 798 | draw[0] += character->width; |
| 799 | } |
| 800 | return true; |
| 801 | } |
| 802 | |
| 803 | void TextAtlas::Create(const char* path, int _pixel_height, FontRenderer* font_renderer, int flags) { |
| 804 | PROFILER_ZONE(g_profiler_ctx, "TextAtlas::Create"); |
nothing calls this directly
no test coverage detected