Font weight

Dec 11, 2010 at 7:21pm

Font weight

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?

Dec 17, 2010 at 9:44pm

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


Dec 18, 2010 at 10:19pm

Thanks for the feedback.

May 25, 2011 at 12:03am

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?


May 25, 2011 at 12:52am

Should I be using jtextlayout_draw() instead?

May 25, 2011 at 1:14am

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


You must be logged in to reply to this topic.