Immediate-Mode-UI / Nuklear

A single-header ANSI C immediate mode cross-platform GUI library
https://immediate-mode-ui.github.io/Nuklear/doc/index.html
Other
9.17k stars 553 forks source link

Is it possible to add BMFONT renderring support? #111

Open mindoff6502 opened 4 years ago

mindoff6502 commented 4 years ago

Read the source code,find a little hard to replace nuklear font with my font.

The reason why I request a bmfont support is the bake font system work well for ANSI few font characters,not good for unicode like chinese font characters with lots of glyphs.

So if bmfont supported,I can easily connect SDF font,which will solve font size problem once for all. Font rendering won't need to care about font size any more.Bigger font size won't be problem.

And I check the source code for font renderring part.

There are 4 main function related to font calculation.

//add font renderring info to render nk_draw_list_add_text

//calculate text total width nk_font_text_width

//get baked glyph info nk_font_query_font_glyph

//search font glyph info from total_glyphs nk_font_find_glyph

from what I read from other font renderring system, such as fontstash and SFML,

these info can be shared from other font renderring system.

Which means with proper interface or struct exposed,

It should be possible to get other font renderring system render font glyph dynamicly and pass font renderring info back to nuklear.

So do you think this will be possible?

I think nuklear may want to keep things as easy as possible.

Not sure if such thing will be supported or not.

So I just want to ask.

Thanks.

OK, I think maybe a custom glyph support is better,no need for bmfont support

general speaking,font renderring seems all care about glyph info and texture handle.

So if a custom glyph info filled and a macro define called ENABLE_CUSTOM_GLYPH_WORKFLOW is defined

nuklear process user provided glyph,else use original process.

something like this.

struct nk_custom_glyph_info { struct nk_font_glyph *glyphs; nk_handle texture; float fontsize; };

NK_API nk_custom_glyph_info* nk_get_custom_glyph_info ( nk_rune codepoint, float fontsize ) { myglyph = create_custom_glyph_info();

myglyph->glyphs->codepoint = codepoint;
myglyph->glyphs->fontsize = fontsize;

... user process

myglyph->glyphs->xadvance = cal_from_user;
myglyph->glyphs->x0 = cal_from_user;
myglyph->glyphs->y0 = cal_from_user;
myglyph->glyphs->x1 = cal_from_user;
myglyph->glyphs->y1 = cal_from_user;
myglyph->glyphs->w = cal_from_user;
myglyph->glyphs->h = cal_from_user;
myglyph->glyphs->u0 = cal_from_user;
myglyph->glyphs->v0 = cal_from_user;
myglyph->glyphs->v1 = cal_from_user;
myglyph->glyphs->v1 = cal_from_user;

myglyph->glyphs->texture = cal_from_user;

return myglyph;

}

Then inside nk_draw_list_add_text function,

use user glyph info to calculate font mesh size and texture to draw.

with custom glyph both dynamic like fontstash and static like bmfont can work.

Use ENABLE_CUSTOM_GLYPH_WORKFLOW and just ignor all nuklear original font process, init or bake or anything else.

dumblob commented 4 years ago

Hm, I always thought it shouldn't be that hard to swap the stb_truetype baking process with one supporting bitmap fonts (stb_truetype probably won't support them) and thus allowing transparent use of bitmap fonts. But according to what you write it's not so easy.

Feel free to make a PR and we'll definitely take a look at that.