It seems you can get (more or less) the correct height by:
IDimension dim = GraphitiUi.getUiLayoutService(
int height = 2 + (dim.getHeight() * val.split("\n").length));
(I guess using "\n" is platform dependent and you should grab the correct value from properties though). The 2 at the start probably just represents the margin; I found the text was very slightly clipped if I didn't use it.
I'm not sure how to find the correct value for width