Forums > Dev

Font weight

December 11, 2010 | 7:21 pm

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?


December 17, 2010 | 9:44 pm

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

-Joshua


December 18, 2010 | 10:19 pm

Thanks for the feedback.



jml
May 25, 2011 | 12:03 am

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
May 25, 2011 | 12:52 am

Should I be using jtextlayout_draw() instead?



jml
May 25, 2011 | 1:14 am

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


Viewing 6 posts - 1 through 6 (of 6 total)