PyGame中的中文unicode字体 [英] Chinese unicode fonts in PyGame

查看:68
本文介绍了PyGame中的中文unicode字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 PyGame 中显示汉字?什么是用于此目的的好的免费/自由字体?

How can I display Chinese characters in PyGame? And what's a good free/libre font to use for this purpose?

推荐答案

pygame 使用 SDL_ttf 进行渲染,因此您应该在渲染过程中处于良好状态.

pygame uses SDL_ttf for rendering, so you should be in fine shape as rendering goes.

unifont.org 似乎有一些关于开源字体的广泛资源,用于一系列脚本.

unifont.org appears to have some extensive resources on Open-Source fonts for a range of scripts.

我抓取了 Cyber​​bit pan-unicode 字体并提取了包含的 ttf.以下在我的机器上运行"是 Windows Vista Home Basic 和 Python 2.6:

I grabbed the Cyberbit pan-unicode font and extracted the encluded ttf. The folowing 'worked on my machine' which is a Windows Vista Home Basic and Python 2.6:

# -*- coding: utf-8 -*-

import pygame, sys


unistr = u"黒澤 明"
pygame.font.init()
srf = pygame.display.set_mode((640,480))
f = pygame.font.Font("Cyberbit.ttf",20)
srf.blit(f.render(unistr,True,(0,0,0)),(0,0))
pygame.display.flip()

while True:
    srf.blit(f.render(unistr,True,(255,255,255)),(0,0))
    for e in pygame.event.get():
        if e.type == pygame.QUIT:
            pygame.quit()
            sys.exit()

只要您只是显示 unicode 文本,您就应该处于极好的状态.但是,如果您想真正读取用户的 unicode 输入,情况就更加糟糕了.Pygame 没有任何类型的输入法.

As long as you're just displaying unicode text, you should be in fantastic shape. If, however, you want to actually read unicode input from the user, the situation is much more bleak. Pygame has no input methods of any sort.

这篇关于PyGame中的中文unicode字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆