[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Pygame font issues
- To: pygame-users@xxxxxxxx
- Subject: Re: [pygame] Pygame font issues
- From: Jake b <ninmonkeys@xxxxxxxxx>
- Date: Fri, 1 May 2009 13:18:33 -0500
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: pygame-users-outgoing@xxxxxxxx
- Delivered-to: pygame-users@xxxxxxxx
- Delivery-date: Fri, 01 May 2009 14:18:35 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=yL053HDTqbrXNYYCk33gQpiVfmwDCn2ExSn6/XYiEdk=; b=sISWWfvV8QjnuHKSH1KSXw+iZ376ncPltbjx3UueXVwk0f0YTSgYZKe+Yox3f9eyWh JvzPemiCWYoJ9Ci4bpTstT1P2InRHMFP+QHSAvXIZec+qJiGnKaKqogpk5Y3zhhotAIu BjRZOYg2MFmYMxkbN8fJhp7rt6qfj6MHz0n4E=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=Iyct1WGnhPPv0mZUp/a+LpASGNDPgPaD/sdY9AngM/ZHAo+QMeHSwF6Hk4sQCOcDd7 ALPVyB2IWQdgUTFoQ8Z/2G/FpjEkJSuwlviw7uuBXWAY707axTy/J9wiz3Ks0sZ05wOq XYk3OeL0VAgWWCkmreHiuV7Vqm1AcIdmt7WIc=
- In-reply-to: <200904302319.15523.pete@xxxxxxxxxxxxxxx>
- References: <200904302319.15523.pete@xxxxxxxxxxxxxxx>
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
1) Are you using py2exe?
2) Copy-ing the font to the same folder as the game will probably work.
3) I ripped out my font name matching code, it might help. [It might
be easier if you want the whole font wrapper class.]
class Text(object):
"""...code..."""
def __init__(self, text=None, font=None, size=18,color="black",
bold=False, italic=False):
"""font can be:
1) filepath:
"ttf/arial.ttf"
2) list of names to search: ( calls self.match_font(list) )
"arial, verdana, freesans"
3) None
use default font
"""
self.screen = pygame.display.get_surface()
self.font_name = font
self.font_size = size
self.color = pygame.color.Color( color )
self.text = text
self.antialias = True
self.color_bg = None
self.rect = pygame.Rect(15,15,0,0)
self.match_font('bitstreamverasans, verdana, arial,lucidia console')
self._create_font()
def match_font(self, font_list, bold=False, italic=False):
"""pygame.font.match_font() wrapper, but also sets the font. You can
call with a commma deliminated list. It chooses the first valid font."""
filename = pygame.font.match_font(font_list, bold, italic)
if not filename: # if failed, fallback on one that works
filename = pygame.font.match_font('bitstreamverasans, verdana,
arial,lucidia console,freesans, freesansbold') # should at least have
freesans[bold] since it comes with pygame
if( filename ):
self.font_name = filename #was: font_list
self._create_font()
def _create_font(self, font=None):
"""create Font() object"""
try:
self.font = pygame.font.Font( self.font_name, self.font_size )
except IOError:
if font:
self.match_font(font) #, bold, italic)
--
Jake