Thank you both - it's working nicely! (Yes that 5.0 was for example only, because I didn't remember about the baseline calculation issue - so double thanks for catching that too!!). On Tue, Nov 15, 2011 at 3:51 PM, Stephan Aßmus <superstippi@xxxxxx> wrote: > On 15.11.2011 14:40, Rene Gollent wrote: > >> On Tue, Nov 15, 2011 at 8:36 AM, Stephan Aßmus<superstippi@xxxxxx> >> wrote: >> >>> What is "5.0"? This won't work. The vertical coordinate passed to >>> DrawString >>> >> >> The 5.0 was from his original example, I assumed he simply meant >> horizontally centered since all he was asking about was the width >> calculation. >> > > No problem. Some APIs like SWT use the top-left coordinate of the string > bounds for their drawing operation. (Which only works, though, if the > string bounds are based on the maximum height a string can have in the > given font, not on the actual height of a particular string...) I thought > maybe you mixed up another API. :-) In any case, his original code would > have worked only for extremly small font sizes where the ascent is below 5 > pixels height. Otherwise the font would have been cut off at the top. Or > maybe he did not use the view bounds, but some modified rectangle layouted > somewhere inside the view with room above. > > Best regards, > -Stephan > > > >