ó
óßÒ\c           @   s  d  d l  m Z d  d l m Z d  d l m Z m Z d  d l m Z m	 Z	 d  d l
 m Z d  d l j Z d  d l m Z d  d l m Z m Z d  d	 l m Z d  d l Z e ƒ  Z d
 d d d d d d d d d d d d d g Z d „  Z d d d „  ƒ  YZ d S(   iÿÿÿÿ(   t   TextPath(   t	   PathPatch(   t   Affine2Dt   Bbox(   t   FontManagert   FontProperties(   t   to_rgbN(   t   Axes(   t   checkt   handle_errors(   t   get_rgbt
   ultralightt   lightt   normalt   regulart   bookt   mediumt   romant   semiboldt   demiboldt   demit   boldt   heavys
   extra boldt   blackc          C   s[   t  g  t j D] }  |  j |  j f ^ q ƒ } t | j ƒ  ƒ } | j d ƒ | j ƒ  | S(   s  
    Returns a list of valid font_name options for use in Glyph or
    Logo constructors.

    parameters
    ----------
    None.

    returns
    -------
    fontnames: (list)
        List of valid font_name names. This will vary from system to system.

    t   sans(	   t   dictt   font_managert   ttflistt   namet   fnamet   listt   keyst   appendt   sort(   t   ft   fontnames_dictt	   fontnames(    (    s   ../../logomaker/src/Glyph.pyt   list_font_names   s
    .
t   Glyphc           B   sk   e  Z d  Z e d d d d d d d d d e e d d d d	 „ ƒ Z d
 „  Z d „  Z d „  Z	 d „  Z
 RS(   s“
  
    A Glyph represents a character, drawn on a specified axes at a specified
    position, rendered using specified styling such as color and font_name.

    attributes
    ----------

    p: (number)
        x-coordinate value on which to center the Glyph.

    c: (str)
        The character represented by the Glyph.

    floor: (number)
        y-coordinate value where the bottom of the Glyph extends to.
        Must be < ceiling.

    ceiling: (number)
        y-coordinate value where the top of the Glyph extends to.
        Must be > floor.

    ax: (matplotlib Axes object)
        The axes object on which to draw the Glyph.

    width: (number > 0)
        x-coordinate span of the Glyph.

    vpad: (number in [0,1])
        Amount of whitespace to leave within the Glyph bounding box above
        and below the actual Glyph. Specifically, in a glyph with
        height h = ceiling-floor, a margin of size h*vpad/2 will be left blank
        both above and below the rendered character.

    font_name: (str)
        The name of the font to use when rendering the Glyph. This is
        the value passed as the 'family' parameter when calling the
        matplotlib.font_manager.FontProperties constructor.

    font_weight: (str or number)
        The font weight to use when rendering the Glyph. Specifically, this is
        the value passed as the 'weight' parameter in the
        matplotlib.font_manager.FontProperties constructor.
        From matplotlib documentation: "weight: A numeric
        value in the range 0-1000 or one of 'ultralight', 'light',
        'normal', 'regular', 'book', 'medium', 'roman', 'semibold',
        'demibold', 'demi', 'bold', 'heavy', 'extra bold', 'black'."

    color: (matplotlib color)
        Color to use for Glyph face.

    edgecolor: (matplotlib color)
        Color to use for Glyph edge.

    edgewidth: (number >= 0)
        Width of Glyph edge.

    dont_stretch_more_than: (str)
        This parameter limits the amount that a character will be
        horizontally stretched when rendering the Glyph. Specifying a
        wide character such as 'W' corresponds to less potential stretching,
        while specifying a narrow character such as '.' corresponds to more
        stretching.

    flip: (bool)
        If True, the Glyph will be rendered upside down.

    mirror: (bool)
        If True, a mirror image of the Glyph will be rendered.

    zorder: (number)
        Placement of Glyph within the z-stack of ax.

    alpha: (number in [0,1])
        Opacity of the rendered Glyph.

    figsize: ([float, float]):
        The default figure size for the rendered glyph; only used if ax is
        not supplied by the user.
    gffffffî?g        R   R   t   grayR   t   Ei   c         C   sö   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _	 | |  _
 | |  _ |
 |  _ | |  _ | |  _ | |  _ |	 |  _ | |  _ |  j ƒ  |  j d  k rè t j d d d |  j ƒ\ } } | |  _ n  |  j ƒ  d  S(   Ni   t   figsize(   t   pt   ct   floort   ceilingt   axt   widtht   vpadt   flipt   mirrort   zordert   dont_stretch_more_thant   alphat   colort	   edgecolort	   edgewidtht	   font_namet   font_weightR)   t   _input_checkst   Nonet   pltt   subplotst   _make_patch(   t   selfR*   R+   R,   R-   R.   R/   R0   R9   R:   R6   R7   R8   R4   R1   R2   R3   R5   R)   t   fig(    (    s   ../../logomaker/src/Glyph.pyt   __init__}   s.    																		
!c         K   s„   |  j  d k	 r1 |  j  j d k	 r1 |  j  j ƒ  n  xB | j ƒ  D]4 \ } } | d k re t | ƒ } n  | |  j | <q> W|  j ƒ  d S(   s¤   
        Safe way to set the attributes of a Glyph object

        parameters
        ----------
        **kwargs:
            Attributes and their values.
        R6   R7   N(   s   colors	   edgecolor(   t   patchR<   t   axest   removet   itemsR   t   __dict__R?   (   R@   t   kwargst   keyt   value(    (    s   ../../logomaker/src/Glyph.pyt   set_attributes±   s    !c         C   s)   |  j  d k	 r% |  j j |  j  ƒ n  d S(   s›   
        Draws Glyph given current parameters.

        parameters
        ----------
        None.

        returns
        -------
        None.
        N(   RC   R<   R.   t	   add_patch(   R@   (    (    s   ../../logomaker/src/Glyph.pyt   drawÌ   s    c         C   sr  |  j  |  j } | d k r) d |  _ d S|  j |  j d } |  j |  j | d } |  j } | |  j | } t j | | | | ƒ } t	 d |  j
 d |  j ƒ } t d |  j d d d | ƒ} t d |  j d d d | ƒ}	 |  j rt ƒ  j d	 d d
 d ƒ }
 |
 j | ƒ } n  |  j rJt ƒ  j d	 d d
 d ƒ }
 |
 j | ƒ } n  | j ƒ  } |	 j ƒ  } | j | j } | j | j } t | | ƒ } | | j } | j | d } | j | j } t ƒ  j d | j d | j ƒ j d	 | d
 | ƒ j d | j | d | j ƒ }
 |
 j | ƒ } t | d |  j d |  j d |  j d |  j d |  j ƒ|  _ |  j  j! |  j ƒ d S(   sb   
        Returns an appropriately scaled patch object corresponding to
        the Glyph.
        g        g       @t   familyt   weighti    t   sizei   t   propt   sxt   syiÿÿÿÿt   txt   tyt	   facecolorR3   R5   R7   t	   linewidthN(   i    i    (   i    i    ("   R-   R,   R<   RC   R*   R/   R0   R   t   from_boundsR   R9   R:   R    R+   R4   R1   R   t   scalet   transform_pathR2   t   get_extentst   mint   heightt	   translatet   xmint   yminR   R6   R3   R5   R7   R8   R.   RL   (   R@   R]   t	   char_xmint	   char_ymint
   char_widtht   char_heightt   bboxt   font_propertiest   tmp_patht   msc_patht   transformationt   tmp_bboxt   msc_bboxt   hstretch_tmpt   hstretch_msct   hstretcht
   char_shiftt   vstretcht	   char_path(    (    s   ../../logomaker/src/Glyph.pyR?   Ý   sX    													c         C   s‚  t  t t |  j ƒ t t f ƒ d t |  j ƒ ƒ t  t |  j t ƒ d t |  j ƒ ƒ t  t |  j t t f ƒ d t |  j ƒ ƒ t |  j ƒ |  _ t  t |  j	 t t f ƒ d t |  j	 ƒ ƒ t |  j	 ƒ |  _	 t  |  j |  j	 k d |  j |  j	 f ƒ t  |  j
 d k pt |  j
 t ƒ d ƒ t  t |  j t t f ƒ d t |  j ƒ ƒ t  |  j d k d	 |  j ƒ t  t |  j t t f ƒ d
 t |  j ƒ ƒ t  |  j d k d |  j ƒ t  t |  j t ƒ d t |  j ƒ ƒ t  |  j t ƒ  k d ƒ t  t |  j t t f ƒ d t |  j ƒ ƒ t |  j t ƒ rQt  |  j t k d t ƒ n; t |  j t ƒ rŒt  d |  j k o€d k n d ƒ n  t |  j ƒ |  _ t |  j ƒ |  _ t  t |  j t t f ƒ d t |  j ƒ ƒ t |  j ƒ |  _ t  |  j d k d |  j ƒ t  t |  j t ƒ d t |  j ƒ ƒ t  t |  j ƒ d k d t |  j ƒ ƒ t  t |  j t t j f ƒ d t |  j ƒ ƒ t |  j ƒ |  _ t  t |  j t t j f ƒ d t |  j ƒ ƒ t |  j ƒ |  _ |  j d k	 rt  t |  j t t f ƒ d t |  j ƒ ƒ n  t  t |  j t t f ƒ d t |  j ƒ ƒ t |  j ƒ |  _ t  d |  j k oud k n d ƒ d S(   sP   
        check input parameters in the Logo constructor for correctness
        s   type(p) = %s must be a numbers"   type(c) = %s; must be of type str s!   type(floor) = %s must be a numbers#   type(ceiling) = %s must be a numbers;   must have floor <= ceiling. Currently, floor=%f, ceiling=%fs3   ax must be either a matplotlib Axes object or None.s/   type(width) = %s; must be of type float or int i    s   width = %d must be >= 0 s.   type(vpad) = %s; must be of type float or int s   vpad = %d must be >= 0 s(   type(font_name) = %s must be of type strsc   Invalid choice for font_name. For a list of valid choices, please call logomaker.list_font_names().s:   type(font_weight) = %s should either be a string or an ints   font_weight must be one of %siè  s%   font_weight must be in range [0,1000]s%   type(edgewidth) = %s must be a numbers    edgewidth must be >= 0; is %fs7   type(dont_stretch_more_than) = %s; must be of type str i   sS   dont_stretch_more_than must have length 1; currently len(dont_stretch_more_than)=%ds&   type(flip) = %s; must be of type bool s(   type(mirror) = %s; must be of type bool s0   type(zorder) = %s; must be of type float or int s'   type(alpha) = %s must be a float or intg      ð?s-   alpha must be between 0.0 and 1.0 (inclusive)N(    R   t
   isinstancet   intR*   t   floatt   typeR+   t   strR,   R-   R.   R<   R   R/   R0   R9   R%   R:   t   VALID_FONT_WEIGHT_STRINGSR
   R6   R7   R8   R4   t   lenR1   t   boolt   npt   bool_R2   R3   R5   (   R@   (    (    s   ../../logomaker/src/Glyph.pyR;   =  sˆ    !
N(   i   i   (   t   __name__t
   __module__t   __doc__R	   R<   t   FalseRB   RK   RM   R?   R;   (    (    (    s   ../../logomaker/src/Glyph.pyR&   ,   s(   O!			`(    (   t   matplotlib.textpathR    t   matplotlib.patchesR   t   matplotlib.transformsR   R   t   matplotlib.font_managerR   R   t   matplotlib.colorsR   t   matplotlib.pyplott   pyplotR=   t   matplotlib.axesR   t   logomaker.src.error_handlingR   R	   t   logomaker.src.colorsR
   t   numpyRz   R   Rw   R%   R&   (    (    (    s   ../../logomaker/src/Glyph.pyt   <module>   s   		