Re: [DirectPython] Calculating Text Sizes
Status: Inactive
Brought to you by:
hsalo
From: Heikki S. <ho...@gm...> - 2007-08-29 17:11:08
|
> -----Original Message----- > From: David [mailto:dp...@sh...] > Sent: 29. elokuuta 2007 18:36 > To: ho...@gm... > Subject: Re: [DirectPython] Calculating Text Sizes > > Thanks for the reply, > > I actually already figured out about the height being the same. > And I have make a function to guess the number of lines by > adding a word at a time until it is too big, at that point it > assumes that the DrawTexts function would have wrapped it. > My problem is that the width of the text that it is returning > is larger then it really is, one of the lines says it is 1050 > px, and DrawTexts fits it into one line, and my resolution is > 1024 x 768 so the text width must be <= 1024. > > I've also check that I am using the same font, and I am. > > Any thing about why it is doing this would be great. > > Thanks, > > David Mack > After some investigation I noticed that the COM-object responsible for the rendering ignores spaces (and probably some other whitespace too) when it renders the text. They are rendered, but they don't increase the width of the string. The getTextSize() uses normal Windows API and it does count whitespace, so there is some difference between the results. So the more you have whitespace in the string, the more the results will differ. There really is no fix for this because I can't modify the underlying COM-object. Fortunately the "do it yourself" method (EditBox etc.) is not affected by this, so if you implement a similar solution it should work OK. You can also count the whitespace in the string and make an educated guess about how much you should tweak the resulting width in order to get better results. -- Heikki Salo |