@@ -34,7 +34,7 @@ ekg::gpu::sampler_t *ekg::draw::font_renderer::get_sampler_texture() {
3434}
3535
3636float ekg::draw::font_renderer::get_text_width (std::string_view text, int32_t &lines) {
37- if (text.empty ()) {
37+ if (text.empty () || (! this -> font_face_text . font_face_loaded && ! this -> font_face_emoji . font_face_loaded ) ) {
3838 return 0 .0f ;
3939 }
4040
@@ -101,7 +101,7 @@ float ekg::draw::font_renderer::get_text_width(std::string_view text, int32_t &l
101101}
102102
103103float ekg::draw::font_renderer::get_text_width (std::string_view text) {
104- if (text.empty ()) {
104+ if (text.empty () || (! this -> font_face_text . font_face_loaded && ! this -> font_face_emoji . font_face_loaded ) ) {
105105 return 0 .0f ;
106106 }
107107
@@ -168,15 +168,15 @@ float ekg::draw::font_renderer::get_text_height() {
168168}
169169
170170void ekg::draw::font_renderer::set_font (std::string_view path) {
171- if (this ->font_face_text .font_path != path) {
171+ if (!path. empty () && this ->font_face_text .font_path != path) {
172172 this ->font_face_text .font_path = path;
173173 this ->font_face_text .font_face_changed = true ;
174174 this ->reload ();
175175 }
176176}
177177
178178void ekg::draw::font_renderer::set_font_emoji (std::string_view path) {
179- if (this ->font_face_emoji .font_path != path) {
179+ if (!path. empty () && this ->font_face_emoji .font_path != path) {
180180 this ->font_face_emoji .font_path = path;
181181 this ->font_face_emoji .font_face_changed = true ;
182182 this ->reload ();
@@ -192,24 +192,35 @@ void ekg::draw::font_renderer::set_size(uint32_t size) {
192192}
193193
194194void ekg::draw::font_renderer::reload () {
195- if (this ->font_size == 0 ) {
195+ if (this ->font_size == 0 || ( this -> font_face_text . font_path . empty () && this -> font_face_emoji . font_path . empty ()) ) {
196196 return ;
197197 }
198198
199199 if (
200- (!this ->font_face_text .font_path .empty () && ekg::draw::reload_font_face (&this ->font_face_text , this ->font_size_changed , this ->font_size )) ||
201- (!this ->font_face_emoji .font_path .empty () && ekg::draw::reload_font_face (&this ->font_face_emoji , this ->font_size_changed , this ->font_size ))
200+ (
201+ !this ->font_face_text .font_path .empty ()
202+ &&
203+ ekg::draw::reload_font_face (&this ->font_face_text , this ->font_size_changed , this ->font_size )
204+ )
205+ ||
206+ (
207+ !this ->font_face_emoji .font_path .empty ()
208+ &&
209+ ekg::draw::reload_font_face (&this ->font_face_emoji , this ->font_size_changed , this ->font_size )
210+ )
202211 ) {
203212 ekg::log () << " Failed to load font face, text: " << this ->font_face_text .font_face_loaded << " , emoji: " << this ->font_face_emoji .font_face_loaded ;
204213 return ;
205214 }
206215
207216 this ->font_size_changed = false ;
208217
209- /* Phase of getting bitmap texture bounds. */
210218 this ->full_width = 0 ;
211219 this ->full_height = 0 ;
212220
221+ this ->font_face_text .highest_glyph_size = FT_Vector {};
222+ this ->font_face_emoji .highest_glyph_size = FT_Vector {};
223+
213224 this ->ft_bool_kerning = FT_HAS_KERNING (this ->font_face_text .ft_face );
214225 this ->font_face_text .ft_glyph_slot = this ->font_face_text .ft_face ->glyph ;
215226
@@ -219,22 +230,25 @@ void ekg::draw::font_renderer::reload() {
219230
220231 FT_GlyphSlot ft_glyph_slot {};
221232 FT_Face ft_face {};
222-
223233 ekg::flags flags {};
224234
235+ ekg::draw::font_face_t *p_font_face_picked {};
236+
225237 for (char32_t &char32 : this ->loaded_sampler_generate_list ) {
226238 switch (char32 < 256 || !this ->font_face_emoji .font_face_loaded ) {
227239 case true : {
228240 ft_face = this ->font_face_text .ft_face ;
229241 ft_glyph_slot = this ->font_face_text .ft_face ->glyph ;
230242 flags = FT_LOAD_RENDER;
243+ p_font_face_picked = &this ->font_face_text ;
231244 break ;
232245 }
233246
234247 default : {
235248 ft_face = this ->font_face_emoji .ft_face ;
236249 ft_glyph_slot = this ->font_face_emoji .ft_face ->glyph ;
237250 flags = FT_LOAD_RENDER | FT_LOAD_COLOR;
251+ p_font_face_picked = &this ->font_face_emoji ;
238252 break ;
239253 }
240254 }
@@ -253,7 +267,17 @@ void ekg::draw::font_renderer::reload() {
253267 char_data.wsize = static_cast <float >(static_cast <int32_t >(ft_glyph_slot->advance .x >> 6 ));
254268
255269 this ->full_width += static_cast <int32_t >(char_data.w );
256- this ->full_height = std::max (this ->full_height , static_cast <int32_t >(ft_glyph_slot->bitmap .rows ));
270+ this ->full_height = ekg_min (this ->full_height , static_cast <int32_t >(char_data.h ));
271+
272+ p_font_face_picked->highest_glyph_size .x = ekg_min (
273+ p_font_face_picked->highest_glyph_size .x ,
274+ static_cast <int32_t >(char_data.w )
275+ );
276+
277+ p_font_face_picked->highest_glyph_size .y = ekg_min (
278+ p_font_face_picked->highest_glyph_size .y ,
279+ static_cast <int32_t >(char_data.h )
280+ );
257281 }
258282
259283 this ->text_height = static_cast <float >(this ->font_size );
@@ -420,19 +444,27 @@ void ekg::draw::font_renderer::blit(std::string_view text, float x, float y, con
420444void ekg::draw::font_renderer::flush () {
421445 uint64_t size {this ->loaded_sampler_generate_list .size ()};
422446 if (this ->last_sampler_generate_list_size != size) {
447+ ekg::log () << " Sampler updated from-to: " << this ->last_sampler_generate_list_size << " " << size;
448+
423449 this ->reload ();
424450 this ->last_sampler_generate_list_size = size;
425451 ekg::ui::redraw = true ;
426452 }
427453}
428454
429455void ekg::draw::font_renderer::init () {
456+ if (this ->was_initialized ) {
457+ return ;
458+ }
459+
460+ this ->was_initialized = true ;
461+
430462 this ->loaded_sampler_generate_list .resize (256 );
431463 for (char32_t char32 {}; char32 < 256 ; char32++) {
432464 this ->loaded_sampler_generate_list [char32] = char32;
433465 }
434466
435- ekg::log () << " Initializing 256 chars rendereable " ;
467+ ekg::log () << " Initializing 256 default chars! " ;
436468}
437469
438470void ekg::draw::font_renderer::quit () {
0 commit comments