views:

42

answers:

1

Pyglet only seems to use points. Is there a way to convert easily? Surely there must be a simple way because it's something obviously important, to be able to use pixels for text height.

class Font():
    def __init__(self,font,size):
        self.size = size
        self.font = font
    def return_surface(self,label):
        surface = Surface((label.content_width,label.content_height))
        surface.set_background_alpha(0)
        setup_framebuffer(surface,True)
        label.draw()
        end_framebuffer()
        return surface
    def render(self,text,colour):
        colour = fix_colour(colour)
        label = pyglet.text.Label(text,font_name=self.font,font_size=self.size,color = colour,dpi=72)
        return self.return_surface(label)
    def render_wordwrap(self,text,width,colour,alignment):
        if alignment == 0:
            alignment = 'left'
        elif alignment == 1:
            alignment = 'center'
        else:
            alignment = 'right'
        colour = fix_colour(colour)
        label = pyglet.text.Label(text,font_name=self.font,font_size=self.size,color = colour,width=width,halign=alignment, multiline=True,dpi=72)
        return self.return_surface(label)
A: 

The number of pixels taken up by a certain point size will depend on your screens DPI. For example, "14pt" is the distance covering 14 points, which at a default DPI of 96 is around 18 pixels.

This site give a good explanation of converting point sizes to pixels.

Alastair
Thank you for the answer. I've tried using 72 for the dpi to cancel out the ppi or whatever so pixels are the same as points.For some reason the text is showing as much smaller than it should.I'll add the class I made...
Matthew Mitchell
Found some more information on the Pyglet site which might be useful for you.http://www.pyglet.org/doc/programming_guide/font_sizes.html
Alastair
Thank you very much.Unfortunately pyglet seems to be using completely wrong pixel sizes for the text and I will make a new question relating to this problem.But it's good information.
Matthew Mitchell