[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Font height



Brian Fisher wrote:
On 5/10/06, Mike Wyatt <mwyatt@xxxxxxxxx> wrote:
That's not really my problem.  I'm talking about the extra spacing added above and below the font when it is rendered.  Take a look at the attached screenshot.  I render the text "Xj()~'" in the upper-left corner at position (0,0), with a height of 24.  The text is drawn 54 pixels in height, but font.size() returns (46,35), resulting in my font being drawn 9 pixels below the desired positon.  Drawing a larger font results in the font being drawn even lower

Here are some other results:

Desired size[1] True Pixel
8 6 12
16 14 23
20 19 29
32 29 45
35 33 50
60 55 85
80 74 112
100 93 140
200 185 280
Desired = Height value passed to Font constructor
size[1] = height value in tuple returned by font.size()
True Pixel = True height of the rendered font in pixels



The true pixel sizes seem predictable at least, they seem to be desired height * 1.4 rounded up... So I would guess there is some kind of (fairly) simple model that makes sense...

Could you send the font you are getting the numbers for that table with? and maybe send a small sample showing the problem?

No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.1.392 / Virus Database: 268.5.5/335 - Release Date: 5/9/2006
text = "Hello world!"
name = "arial"
bold = False
italic = False
height = 24
font = pygame.font.Font(pygame.font.match_font(name, bold, italic), height)
size = self.pgFont.size(text)   # returns (46,35)
surface = font.pgFont.render(text, False, (255,0,0,255))

The top 9 rows of pixels in the surface returned by render() are all black.

The height values vary for different fonts (verdana, courier, times, system), but there is always a band of empty space above the text.

The only solution I can think of is to come up with some formula to determine the number of pixels to move the text rendering up.  It seems as though the formula would be different for each font, though.