| 3079 | |
| 3080 | |
| 3081 | LfTextProps lf_text_render_wchar(vec2s pos, const wchar_t* str, LfFont font, LfColor color, |
| 3082 | int32_t wrap_point, vec2s stop_point, bool no_render, bool render_solid, int32_t start_index, int32_t end_index) { |
| 3083 | bool culled = item_should_cull((LfAABB){.pos = (vec2s){pos.x, pos.y + get_current_font().font_size}, .size = (vec2s){-1, -1}}); |
| 3084 | |
| 3085 | // Retrieving the texture index |
| 3086 | float tex_index = -1.0f; |
| 3087 | if (!culled && !no_render) { |
| 3088 | if (state.render.tex_count - 1 >= MAX_TEX_COUNT_BATCH - 1) { |
| 3089 | renderer_flush(); |
| 3090 | renderer_begin(); |
| 3091 | } |
| 3092 | for (uint32_t i = 0; i < state.render.tex_count; i++) { |
| 3093 | if (state.render.textures[i].id == font.bitmap.id) { |
| 3094 | tex_index = (float)i; |
| 3095 | break; |
| 3096 | } |
| 3097 | } |
| 3098 | if (tex_index == -1.0f) { |
| 3099 | tex_index = (float)state.render.tex_index; |
| 3100 | LfTexture tex = font.bitmap; |
| 3101 | state.render.textures[state.render.tex_count++] = tex; |
| 3102 | state.render.tex_index++; |
| 3103 | } |
| 3104 | } |
| 3105 | |
| 3106 | // Local variables needed for rendering |
| 3107 | LfTextProps ret = {0}; |
| 3108 | float x = pos.x; |
| 3109 | float y = pos.y; |
| 3110 | |
| 3111 | int32_t max_descended_char_height = get_max_char_height_font(font); |
| 3112 | |
| 3113 | float last_x = x; |
| 3114 | |
| 3115 | float height = get_max_char_height_font(font); |
| 3116 | float width = 0; |
| 3117 | |
| 3118 | uint32_t i = 0; |
| 3119 | while (str[i] != L'\0') { |
| 3120 | if (str[i] >= font.num_glyphs) { |
| 3121 | i++; |
| 3122 | continue; |
| 3123 | } |
| 3124 | if (stbtt_FindGlyphIndex((const stbtt_fontinfo*)font.font_info, str[i] - 32) == 0 && |
| 3125 | str[i] != L' ' && str[i] != L'\n' && str[i] != L'\t' && !iswdigit(str[i]) && !iswpunct(str[i])) { |
| 3126 | i++; |
| 3127 | continue; |
| 3128 | } |
| 3129 | if (i >= end_index && end_index != -1) { |
| 3130 | break; |
| 3131 | } |
| 3132 | |
| 3133 | // Calculate the width of the next word |
| 3134 | float word_width = 0; |
| 3135 | uint32_t j = i; |
| 3136 | while (str[j] != L' ' && str[j] != L'\n' && str[j] != L'\0') { |
| 3137 | stbtt_aligned_quad q; |
| 3138 | stbtt_GetBakedQuad((stbtt_bakedchar*)font.cdata, font.tex_width, font.tex_height, str[j] - 32, &word_width, &y, &q, 0); |
no test coverage detected