Forums > Dev

JGraphics transforms and text display – possibly a bug (?)

June 25, 2012 | 10:02 am

Dear List,

I’ve been trying to apply matrix transformations to UI objects displaying texts and I ran into some very weird experience. It seems that there are some bugs with the transformations of texts and t_jtextlayout objects. To illustrate the problems, I made two minimal code examples (you can try them by replacing the paint method of the uisimp example). Both will display a "Hello World!" message and a line without transform and then they will draw the same ‘painting’, but transformed. The transformation in both cases consists of a translation to (40, 40) and a rotation by 60 degrees. The first example uses jgraphics_text_show to display the texts:

void uisimp_paint ( t_uisimp * x, t_object * patcherview ) {
	const char * text = "Hello World!";
	t_jgraphics *g = ( t_jgraphics * ) patcherview_get_jgraphics ( patcherview );
	t_jfont * font = jfont_create ( "Arial", JGRAPHICS_FONT_SLANT_NORMAL, JGRAPHICS_FONT_WEIGHT_NORMAL, 12.0 );
	t_jmatrix transform;

	// Init variables
	jgraphics_matrix_init ( & transform, 0.5, 0.866, -0.866, 0.5, 40, 40 );

	// Draw stuff before transformation
	jgraphics_move_to ( g, 20, 20 );
	jgraphics_show_text ( g, text );
	jgraphics_line_to ( g, 100, 20 );

	// Apply transformation
	jgraphics_transform ( g, & transform );

	// Draw stuff after transformation
	jgraphics_move_to ( g, 20, 20 );
	jgraphics_show_text ( g, text );
	jgraphics_line_to ( g, 100, 20 );

	// Clean up
	jgraphics_stroke ( g );
	jfont_destroy ( font );

}

If you check the result (text.png), you’ll notice that, although the line will be transformed correctly, the text will only rotate correctly; the linear translation is much bigger than expected.

In my other example, I was using a t_jtextlayout object to display the text:

void uisimp_paint ( t_uisimp * x, t_object * patcherview ) {
	const char * text = "Hello World!";
	t_jgraphics *g =  ( t_jgraphics * ) patcherview_get_jgraphics ( patcherview );
	t_jfont * font = jfont_create ( "Arial", JGRAPHICS_FONT_SLANT_NORMAL, JGRAPHICS_FONT_WEIGHT_NORMAL, 12.0 );
	t_jtextlayout * textLayout = jtextlayout_create ( );
	double width, height;
	t_jmatrix transform;

	// Init variables
	jfont_text_measure ( font, text, & width, & height );
	jgraphics_matrix_init ( & transform, 0.5, 0.866, -0.866, 0.5, 40, 40 );

	// Draw stuff before transformation
	jtextlayout_set ( textLayout, text, font, 20, 20, width, height, JGRAPHICS_TEXT_JUSTIFICATION_LEFT, JGRAPHICS_TEXTLAYOUT_NOWRAP );
	jtextlayout_draw ( textLayout, g );
	jgraphics_move_to ( g, 20, 20 );
	jgraphics_line_to ( g, 100, 20 );

	// Apply transformation
	jgraphics_transform ( g, & transform );

	// Draw stuff after transformation
	jtextlayout_set ( textLayout, text, font, 20, 20, width, height, JGRAPHICS_TEXT_JUSTIFICATION_LEFT, JGRAPHICS_TEXTLAYOUT_NOWRAP );
	jtextlayout_draw ( textLayout, g );
	jgraphics_move_to ( g, 20, 20 );
	jgraphics_line_to ( g, 100, 20 );

	// Clean up
	jgraphics_stroke ( g );
	jfont_destroy ( font );
	jtextlayout_destroy ( textLayout );

}

The resulting image (textlayout.png) shows that the line was again transformed correctly, however, the textlayout is completely misplaced and even the rotation is bad.

Is this a bug of the matrix transformations or am I completely misunderstanding something?

Thanks for any help in advance,
Ádám

[attachment=197576,4086] [attachment=197576,4087]

Attachments:
  1. textlayout.png

June 26, 2012 | 10:20 pm

bump?


June 27, 2012 | 5:08 pm

Hi Nicolas,

thanks for trying it out! It’s nice to see that this bug is system dependent. I’m on Mac OS X 10.6.8 with Max 5.1.9 and SDK 5.1.7. Is there anybody at Cycling ’74 that could give me some advice on how to go on? I’m really stuck with this…

Thanks,
Ádám


June 28, 2012 | 10:09 pm

OK, finally I fired an official bug report. Maybe that would help us in getting this solved…


June 29, 2012 | 9:36 pm

I just tested your code above and it worked fine for me in Max 6 on OSX.

Are you able to test this on your system in both Max 5 and Max 6?

Also you might want to see if it makes a difference if you turn on/off the Native Text Rendering setting in your Max Prefs.

Rob


June 29, 2012 | 10:36 pm

Hi Rob,

thank you a lot for your answer. I didn’t know about the ‘Native Text Rendering’ setting. Now I turned it off and I can report that I on Max 5 I get the same results than those of Nicholas: the first version will still display the mentioned bug, however, the textlayout version works fine. In Max 6 the bug seems to be gone in both cases, regardless of the value of Native Text Rendering, which is good news, although I need to keep this project Max 5 compatible. Still, it’s good to know that disabling native text rendering and using textlayouts helps in Max 5 for this. I guess this would mean that text rendering will require more CPU (as compared to the native rendering), but at least, now I have a solution that I can use.

Thanks again,
Ádám


June 30, 2012 | 11:13 pm

Hi guys,

sorry for jumping in a little late.
I wrote about the Native Text Rendering bug a while ago but nobody cared to reply…

http://cycling74.com/forums/topic.php?id=32036

- Luigi


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