ó
jÜxec           @   sA  d  d l  Z  e  j d d k r; d  d l Z e j d ƒ n  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ÿÿÿÿNi    i   t   TkAgg(   t   TextPath(   t	   PathPatch(   t   Affine2Dt   Bbox(   t   FontManagert   FontProperties(   t   to_rgb(   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(    (    s8   /tmp/pip-install-l3LICk/logomaker/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/   R0   R1   R:   R;   R7   R8   R9   R5   R2   R3   R4   R6   R*   t   fig(    (    s8   /tmp/pip-install-l3LICk/logomaker/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.
        R7   R8   N(   R7   R8   (   t   patchR=   t   axest   removet   itemsR   t   __dict__R@   (   RA   t   kwargst   keyt   value(    (    s8   /tmp/pip-install-l3LICk/logomaker/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(   RD   R=   R/   t	   add_patch(   RA   (    (    s8   /tmp/pip-install-l3LICk/logomaker/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	   facecolorR4   R6   R8   t	   linewidthN(   i    i    (   i    i    ("   R.   R-   R=   RD   R+   R0   R1   R   t   from_boundsR   R:   R;   R   R,   R5   R2   R   t   scalet   transform_pathR3   t   get_extentst   mint   heightt	   translatet   xmint   yminR   R7   R4   R6   R8   R9   R/   RM   (   RA   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(    (    s8   /tmp/pip-install-l3LICk/logomaker/logomaker/src/Glyph.pyR@   ä   sX    													c         C   s-  d d l  m } 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 d
 |  j k oÇd k  n d |  j ƒ t t |  j t	 ƒ d t |  j ƒ ƒ t t |  j t	 t f ƒ d t |  j ƒ ƒ t |  j t	 ƒ rX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 o|d k n d ƒ t t |  j! t" t# t j$ f ƒ d t |  j! ƒ ƒ t" |  j! ƒ |  _! t t |  j! ƒ d k d  ƒ t t% g  |  j! D]' } t | t t f ƒ o| d
 k ^ qõƒ d! ƒ d" S(#   sP   
        check input parameters in the Logo constructor for correctness
        iÿÿÿÿ(   t   Numbers   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 i   s   vpad = %d must be >= 0 and < 1 s(   type(font_name) = %s must be of type strs:   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 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)s/   type(figsize) = %s; figsize must be array-like.i   s   figsize must have length two.s2   all elements of figsize array must be numbers > 0.N(&   t   numbersRs   R	   t
   isinstancet   intR+   t   floatt   typeR,   t   strR-   R.   R/   R=   R   R0   R1   R:   R;   t   VALID_FONT_WEIGHT_STRINGSR   R7   R8   R9   R5   t   lenR2   t   boolt   npt   bool_R3   R4   R6   R*   t   tupleR   t   ndarrayt   all(   RA   Rs   t   n(    (    s8   /tmp/pip-install-l3LICk/logomaker/logomaker/src/Glyph.pyR<   D  s–    !"
	4N(   i   i   (   t   __name__t
   __module__t   __doc__R
   R=   t   FalseRC   RL   RN   R@   R<   (    (    (    s8   /tmp/pip-install-l3LICk/logomaker/logomaker/src/Glyph.pyR'   3   s(   O!			`(    (    t   syst   version_infot
   matplotlibt   uset   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   numpyR}   R   Rz   R&   R'   (    (    (    s8   /tmp/pip-install-l3LICk/logomaker/logomaker/src/Glyph.pyt   <module>   s&   		