r/pygame•
Admicos

Display non-monospaced font as monospaced.

So, i am trying to render a font to the screen. I can render the font, but the spacing is weird, which is probably because it's not a monospaced font.

How can i display it as a monospaced font?


Current Screenshot (Left: mine, Right: how i want it to look):

https://i.sli.mg/pnTEp3.png


Character rendering code:

def render_char(self, x, y, char):
    if char[1] is not DisplayColors.TRANSPARENT:
        font = self.font.render(char[0], False, char[1], char[2])
        size = self.font.size(char[0])
        offset = 0

        # Failed attempt to fix the issue:
        # if size[0] < 12:
        #     offset = 12 - size[0]

        self.surface.blit(font, ((x - offset) * 12, y * size[1]))

The font used:

http://www.dafont.com/minecraftia.font

Posted Aug 29, 2016, 11:39 PM UTC

26
Loading comments…