ó
X–Tc           @   sX   d  Z  d d l Z d d l m Z m Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   sH   
This module defines Font objects, used for rendering text into Images.
iÿÿÿÿN(   t   Imaget   Vec2Dt
   _FontImagec           B   s   e  Z d  Z d „  Z RS(   s  
    A wrapper for Images that came from rendering a font. This is necessary
    since the rendering returns a surface, which the Image API is built to hide.

    :param surf: The pygame Surface that will be stored in this _FontImage.
    :type surf: :class:`pygame.Surface`
    c         C   s   | |  _  d  |  _ d |  _ d  S(   Ni   (   t   _surft   Nonet   _namet   _version(   t   selft   surf(    (    s/   /usr/lib/python2.7/site-packages/spyral/font.pyt   __init__   s    		(   t   __name__t
   __module__t   __doc__R	   (    (    (    s/   /usr/lib/python2.7/site-packages/spyral/font.pyR      s   t   Fontc           B   s•   e  Z d  Z d
 d „ Z d e e e d „ Z d „  Z e e ƒ Z	 d „  Z
 e e
 ƒ Z d „  Z e e ƒ Z d „  Z e e ƒ Z d „  Z d	 „  Z RS(   si  
    Font objects are how you get text onto the screen. They are loaded from
    TrueType Font files (\*.ttf); system fonts are not supported for asthetic
    reasons. If you need direction on what the different size-related
    properties of a Font object, check out the Font example.

    :param str font_path: The location of the \*.ttf file.
    :param int size: The size of the font; font sizes refer to the height of the
                     font in pixels.
    :param color: A three-tuple of RGB values ranging from 0-255. Defaults to
                  black ``(0, 0, 0)``.
    :type color: A three-tuple.
    i    c         C   s4   t  | ƒ |  _ t j j | | ƒ |  _ | |  _ d  S(   N(   t   intt   sizet   pygamet   fontR   t   default_color(   R   t	   font_pathR   R   (    (    s/   /usr/lib/python2.7/site-packages/spyral/font.pyR	   #   s    c         C   s¡   | d k r |  j } n  |  j j | ƒ |  j j | ƒ |  j j | ƒ |  j j | t | ƒ j ƒ  } t	 j
 | j ƒ  t	 j ƒ } | j | d ƒ t | j ƒ  ƒ S(   sò  
        Renders the given *text*. Italicizing and bolding are artificially
        added, and may not look good for many fonts. It is preferable to load a
        bold or italic font where possible instead of using these options.

        :param str text: The text to render. Some characters might not be able
                         to be rendered (e.g., "\\n").
        :param color: A three-tuple of RGB values ranging from 0-255. Defaults
                      to the default Font color.
        :type color: A three-tuple.
        :param bool underline: Whether to underline this text. Note that the
                               line will always be 1 pixel wide, no matter the
                               font size.
        :param bool italic: Whether to artificially italicize this font by
                            angling it.
        :param bool bold: Whether to artificially embolden this font by
                          stretching it.
        :rtype: :class:`Image <spyral.Image>`
        i    N(   i    i    (   R   R   R   t   set_underlinet   set_boldt
   set_italict   rendert   Truet   convert_alphaR   t   Surfacet   get_sizet   SRCALPHAt   blitR   (   R   t   textt   colort	   underlinet   italict   boldt   text_surfacet   background_surface(    (    s/   /usr/lib/python2.7/site-packages/spyral/font.pyR   (   s    c         C   s   |  j  j ƒ  S(   N(   R   t
   get_height(   R   (    (    s/   /usr/lib/python2.7/site-packages/spyral/font.pyt   _get_heightH   s    c         C   s   |  j  j ƒ  S(   N(   R   t
   get_ascent(   R   (    (    s/   /usr/lib/python2.7/site-packages/spyral/font.pyt   _get_ascentM   s    c         C   s   |  j  j ƒ  S(   N(   R   t   get_descent(   R   (    (    s/   /usr/lib/python2.7/site-packages/spyral/font.pyt   _get_descentS   s    c         C   s   |  j  j ƒ  S(   N(   R   t   get_linesize(   R   (    (    s/   /usr/lib/python2.7/site-packages/spyral/font.pyt   _get_linesizeY   s    c         C   s   |  j  j | ƒ S(   s¾  
        Returns a list containing the font metrics for each character
        in the text. The metrics is a tuple containing the
        minimum x offset, maximum x offset, minimum y offset, maximum
        y offset, and the advance offset of the character. ``[(minx, maxx, miny,
        maxy, advance), (minx, maxx, miny, maxy, advance), ...]``

        :param str text: The text to gather metrics on.
        :rtype: `list` of tuples.
        (   R   t   get_metrics(   R   R   (    (    s/   /usr/lib/python2.7/site-packages/spyral/font.pyR-   _   s    c         C   s   t  |  j j | ƒ ƒ S(   sˆ  
        Returns the size needed to render the text without actually
        rendering the text. Useful for word-wrapping. Remember to
        keep in mind font kerning may be used.

        :param str text: The text to get the size of.
        :returns: The size (width and height) of the text as it would be
                  rendered.
        :rtype: :class:`Vec2D <spyral.Vec2D>`
        (   R   R   R   (   R   R   (    (    s/   /usr/lib/python2.7/site-packages/spyral/font.pyR   l   s    (   i    i    i    N(   R
   R   R   R	   R   t   FalseR   R&   t   propertyt   heightR(   t   ascentR*   t   descentR,   t   linesizeR-   R   (    (    (    s/   /usr/lib/python2.7/site-packages/spyral/font.pyR      s   					(   R   R   t   spyralR    R   R   t   objectR   (    (    (    s/   /usr/lib/python2.7/site-packages/spyral/font.pyt   <module>   s   