############################################################################# ## This file is part of the Ostendo Resource Manager. ## ##-------------------------------------------------------------------------## ## Copyright 2007-2008 Bryce Schroeder ## ## bryce.schroeder@gmail.com ## ## http://www.ferazelhosting.net/~bryce/ ## ##-------------------------------------------------------------------------## ## This program is free software: you can redistribute it and/or modify ## ## it under the terms of the GNU General Public License as published by ## ## the Free Software Foundation, either version 3 of the License, or ## ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## ## along with this program. If not, see . ## ############################################################################# #TODO - determine if this is finished or not! from .standard_interpreters import Resource, R import cStringIO import pygame class Font(Resource): MANDATORY = ['font'] #OPTIONAL = ['meta'] def init(self): self.meta = {} if self.parts.has_key('meta'): self.meta = self.process_meta(self.parts['meta']) def pygame_font(self,size): # FIXME # This is causing a segfault. Pygame mailing list informed. # pending a fix, it will use a system font... #return pygame.font.Font(cStringIO.StringIO( # self.parts['font']), size) return pygame.font.SysFont("Times New Roman", size) #temporary hack def wrap_text(self, size, text, width): font = self.pygame_font(size) if font.size(text)[0] <= width: return [text] lines, curline = [], [] for word in text.split(): if font.size(' '.join(curline + [word]))[0] > width: lines.append(' '.join(curline)) curline = [word] else: curline.append(word) if curline: lines.append(' '.join(curline)) return lines