Immediate-Mode-UI / Immediate-Mode-UI/Nuklear
Is it possible to add BMFONT renderring support?
- Dominant language
- C
- Stars
- 11.4k
- Forks
- 686
- Avg merge
- 4d 1h
- Merged PRs (30d)
- 3
Description
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.
Contributor guide
Research direction
Start by reading the four named font paths: nk_draw_list_add_text, nk_font_text_width, nk_font_query_font_glyph, and nk_font_find_glyph. Compare how their existing font and glyph data are used, then determine the scope of an interface for user-provided glyph information and texture handles. Done would require an agreed design and a complete implementation path for both dynamic and static font rendering.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100