Source

pygame / examples / freetype_misc.py

import sys, os
import pygame
from pygame.locals import *

try:
    import pygame.freetype as freetype
except ImportError:
    print ("No FreeType support compiled")
    sys.exit ()

colors = {
    "grey_light"    :   pygame.Color(200, 200, 200),
    "grey_dark"     :   pygame.Color(100, 100, 100),
    "green"         :   pygame.Color(50, 255, 63),
    "red"           :   pygame.Color(220, 30, 30),
    "blue"          :   pygame.Color(50, 75, 245)
}

def run():
    pygame.init()

    fontdir = os.path.dirname(os.path.abspath (__file__))
    font = freetype.Font(os.path.join (fontdir, "sans.ttf"))

    screen = pygame.display.set_mode((800, 600))
    screen.fill (colors["grey_light"])

    font.render((screen, 32, 32), "Hello World", colors["red"], colors['grey_dark'],
            ptsize=64, style=freetype.STYLE_UNDERLINE|freetype.STYLE_ITALIC)

    font.render((screen, 32, 128), "abcdefghijklm", colors["grey_dark"], colors["green"],
            ptsize=64)

    font.vertical = True
    font.render((screen, 32, 190), "Vertical?", colors["blue"], None, ptsize=32)
    font.vertical = False

    font.render((screen, 64, 190), "Let's spin!", colors["red"], None,
            ptsize=48, rotation=55)

    font.render((screen, 150, 270), "All around!", colors["green"], None,
            ptsize=48, rotation=-55)

    font.render((screen, 250, 220), "and BLEND", pygame.Color(255, 0, 0, 128), None,
            ptsize=64)

    font.render((screen, 258, 237), "or BLAND!", pygame.Color(0, 0xCC, 28, 128), None,
            ptsize=64)

    font.render((screen, 298, 320), "I \u2665 Unicode", pygame.Color(0, 0xCC, 0xDD), None,
            ptsize=64)

    font.render((screen, 480, 32), "\u2665", colors["grey_light"], colors["red"],
            ptsize=148)

    font.render((screen, 380, 380), "...yes, this is a SDL surface", pygame.Color(0, 0, 0), None,
            ptsize=24, style=freetype.STYLE_BOLD)

    pygame.display.flip()

    while 1:
        if pygame.event.wait().type in (QUIT, KEYDOWN, MOUSEBUTTONDOWN):
            break

    pygame.quit()

if __name__ == "__main__":
    run ()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.