Font weight

Peter Castine's icon

Is there a simple, light-weight way to switch between bold and roman font weights?

Looking at the API docs, it seems as if I have to create two different t_jfonts and switch between them. Something like (untested code) :

t_jfont* myFont = jfont_create(g, "Somefont", JGRAPHICS_FONT_SLANT_NORMAL, JGRAPHICS_FONT_WEIGHT_NORMAL, 31.4);
t_jfont* myBoldFont = jfont_create(g, "Somefont", JGRAPHICS, JGRAPHICS_FONT_WEIGHT_BOLD, 31.4);
Boolean bold = false;

while (somecondition) {
// yadayada, conditionally set bold flag

jtextlayout_set(myLayout, myStr, bold ? myBoldFont : myFont, yadayadayada);
jtextlayout_draw(myLayout, iGContext);
}

Seems like there ought to be calls along the lines of jfont_setweight() but I'm not finding any. Is there a better way?

Joshua Kit Clayton's icon

Your solution is the way to go. Or just recreate the font each time (shouldn't be very heavyweight).

-Joshua

Peter Castine's icon

Thanks for the feedback.

jml's icon

Along these lines, I am trying to update the font info that any text is drawn in my patcherview (via jgraphics_show_text()) when the user selects a given font face via the inspector. Would I need to use a notify method to obtain this information, or should I be storing the font attr info (weight, size, family, etc) in my object's struct?

Thanks
jml

jml's icon

Should I be using jtextlayout_draw() instead?

jml's icon

Nevermind. I was passing the wrong arguments to my get methods.