Add a way to specify text style in text codes, such as bold or italic
As per discord discussion, so far this made a lot of sense:
cf_text_effect_set_font(const char* effect_name, const char* font);
We can add a font field to the internal effect that gets registered:
struct CF_TextEffectDefinition {
const char* font_override;
CF_TextEffectFn fn;
}
For a particular effect that has not been registered, we can just auto-register a stub function pointer to get the text code working. Example use:
cf_text_effect_set_font("b", "calibri bold");
// ...
cf_draw_text("<b>bold</b>", ...);
Currently the text xadvance is though a lambda, would we be able to override the xadvance / kerning in text effect callbacks to handle bold and italics fonts since those can have different values?
auto advance_to_next_glyph = [&](CF_Glyph* last_glyph) {
// Max bound covers the entire glyph without kerning so we use w instead
// of xadvance
max_x = max(max_x, x + last_glyph->w);
if (vertical) {
min_y = min(min_y, y + font->descent * scale);
y -= line_height;
} else {
x += last_glyph->xadvance;
}
};
Maybe those local variables need to put into a struct, and have a couple instances of that struct for different fonts. Then pass in the style param struct into the lambda (or capture it maybe). What do you think?
I think that would work for bold and italics case, would that support something like below or would this be out of scope?
cf_push_font_size(48);
cf_draw_text("what the <font name=\"some_exaggerated_font\" size=64><b><i>COW!?</i></b></font>", cf_v2(0, 0), -1);
cf_pop_font_size();
i don't have a usage case for this but not sure if anyone is doing any heavy text based some like a visual novel where they would need this.
I think we should treat bold and italic like any other font, so yes definitely support swapping fonts like that