Question

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)
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top