def SysFont(name, size, bold=0, italic=0):
    """pygame.font.SysFont(name, size, bold=0, italic=0) -> Font
       create a pygame Font from system font resources

       This will search the system fonts for the given font
       name. You can also enable bold or italic styles, and
       the appropriate system font will be selected if available.

       This will always return a valid Font object, and will
       fallback on the builtin pygame font if the given font
       is not found.

       Name can also be a comma separated list of names, in
       which case set of names will be searched in order. Pygame
       uses a small set of common font aliases, if the specific
       font you ask for is not available, a reasonable alternative
       may be used.
    """
    import pygame.font

    if not Sysfonts:
        initsysfonts()

    fontname = None
    if name:
        allnames = name
        for name in allnames.split(','):
            origbold = bold
            origitalic = italic
            name = _simplename(name)
            styles = Sysfonts.get(name)
            if not styles:
                styles = Sysalias.get(name)
            if styles:
                while not fontname:
                    fontname = styles.get((bold, italic))
                    if italic:
                        italic = 0
                    elif bold:
                        bold = 0
                    elif not fontname:
                        fontname = styles.values()[0]
            if fontname: break

    font = pygame.font.Font(fontname, size)
    if name:
        if origbold and not bold:
            font.set_bold(1)
        if origitalic and not italic:
            font.set_italic(1)
    else:
        if bold:
            font.set_bold(1)
        elif italic:
            font.set_italic(1)

    return font
Example #2
0
def SysFont(name, size, bold=0, italic=0):
    """pygame.font.SysFont(name, size, bold=0, italic=0) -> Font
       create a pygame Font from system font resources

       This will search the system fonts for the given font
       name. You can also enable bold or italic styles, and
       the appropriate system font will be selected if available.

       This will always return a valid Font object, and will
       fallback on the builtin pygame font if the given font
       is not found.

       Name can also be a comma separated list of names, in
       which case set of names will be searched in order. Pygame
       uses a small set of common font aliases, if the specific
       font you ask for is not available, a reasonable alternative
       may be used.
    """
    import pygame.font

    if not Sysfonts:
        initsysfonts()

    fontname = None
    if name:
        allnames = name
        for name in allnames.split(','):
            origbold = bold
            origitalic = italic
            name = _simplename(name)
            styles = Sysfonts.get(name)
            if not styles:
                styles = Sysalias.get(name)
            if styles:
                while not fontname:
                    fontname = styles.get((bold, italic))
                    if italic:
                        italic = 0
                    elif bold:
                        bold = 0
                    elif not fontname:
                        fontname = styles.values()[0]
            if fontname: break

    font = pygame.font.Font(fontname, size)
    if name:
        if origbold and not bold:
            font.set_bold(1)
        if origitalic and not italic:
            font.set_italic(1)
    else:
        if bold:
            font.set_bold(1)
        elif italic:
            font.set_italic(1)

    return font
Example #3
0
def font_constructor(fontpath, size, bold, italic):
    import pygame.font

    font = pygame.font.Font(fontpath, size)
    if bold:
        font.set_bold(1)
    if italic:
        font.set_italic(1)

    return font
Example #4
0
def font_constructor(fontpath, size, bold, italic):
    import pygame.font

    font = pygame.font.Font(fontpath, size)
    if bold:
        font.set_bold(1)
    if italic:
        font.set_italic(1)

    return font
Example #5
0
 def set_text(self, text):
     self.text = text
     font = self.font
     font.set_underline(self.underline)
     font.set_bold(self.bold)
     font.set_italic(self.italic)
     
     # required for font.render to function properly when None is
     # given for background
     if self.background == None:
         self.surface = font.render(text, self.antialias, self.color).convert_alpha()
     else:
         self.surface = font.render(text, self.antialias, self.color, self.background).convert()
Example #6
0
def font_options(font_ops, font):
    "lets you have bold and/or underline and/or italic fonts"
    if type(font_ops[0]) is StringType:
        if font_ops[0] == "bold":
            font.set_bold(1)
        if font_ops[0] == "underline":
            font.set_underline(1)
        if font_ops[0] == "italic":
            font.set_italic(1)
        if font_ops[0] == "transparent":
            gl.TEXT_TRANSPARENT = 1
    else:
        if font_ops[0][0] == "bold":
            font.set_bold(1)
        if font_ops[0][0] == "underline":
            font.set_underline(1)
        if font_ops[0][0] == "italic":
            font.set_italic(1)
        if font_ops[0][0] == "transparent":
            gl.TEXT_TRANSPARENT = 1

    if len(font_ops[0]) > 1:
        if font_ops[0][1] == "underline":
            font.set_underline(1)
        if font_ops[0][1] == "bold":
            font.set_bold(1)
        if font_ops[0][1] == "italic":
            font.set_italic(1)
        if font_ops[0][1] == "transparent":
            gl.TEXT_TRANSPARENT = 1
            
        if len(font_ops[0]) > 2:
            if font_ops[0][2] == "underline":
                font.set_underline(1)
            if font_ops[0][2] == "bold":
                font.set_bold(1)
            if font_ops[0][2] == "italic":
                font.set_italic(1)
            if font_ops[0][2] == "transparent":
                gl.TEXT_TRANSPARENT = 1