File: font.py

package info (click to toggle)
snowballz 0.9.5.1-2
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 10,888 kB
  • ctags: 1,242
  • sloc: python: 7,511; makefile: 53; sh: 2
file content (35 lines) | stat: -rw-r--r-- 1,066 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import os
import pygame
import rabbyt.fonts


class Font:
    def __init__ (self, facename, pixel_height, invert_y=False):
        # We haven't yet allocated textures or display lists
        facename = os.path.join(*facename.split("/"))

        self.invert_y = invert_y
        self.m_font_height = pixel_height

        f = pygame.font.Font(facename, pixel_height)
        self.font = rabbyt.fonts.Font(f)
        self.sprite = rabbyt.fonts.FontSprite(self.font, "")

        if invert_y:
            for char in self.font.alphabet:
                l, t, r, b = self.font.coords[char]
                self.font.coords[char] = l, b, r, t


    def render(self, x, y, string, color=(1,1,1)):
        self.sprite.red = color[0]
        self.sprite.green = color[1]
        self.sprite.blue = color[2]
        if len(color) == 4:
            self.sprite.alpha = color[3]
        else:
            self.sprite.alpha = 1

        self.sprite.text = string
        self.sprite.xy = x, y+self.m_font_height
        self.sprite.render()