ó
l2RTc           @   s^   d  Z  d d l m Z d d l m Z m Z d g Z d „  Z i  Z d e f d „  ƒ  YZ	 d S(   sÌ   
    pygments.formatters.svg
    ~~~~~~~~~~~~~~~~~~~~~~~

    Formatter for SVG output.

    :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS.
    :license: BSD, see LICENSE for details.
iÿÿÿÿ(   t	   Formatter(   t   get_bool_optt   get_int_optt   SvgFormatterc         C   s@   |  j  d d ƒ j  d d ƒ j  d d ƒ j  d d ƒ j  d	 d
 ƒ S(   s<   Escape &, <, > as well as single and double quotes for HTML.t   &s   &amp;t   <s   &lt;t   >s   &gt;t   "s   &quot;t   's   &#39;(   t   replace(   t   text(    (    s;   /usr/lib/python2.7/dist-packages/pygments/formatters/svg.pyt   escape_html   s
    c           B   sA   e  Z d  Z d Z d g Z d g Z d „  Z d „  Z d „  Z RS(   sk  
    Format tokens as an SVG graphics file.  This formatter is still experimental.
    Each line of code is a ``<text>`` element with explicit ``x`` and ``y``
    coordinates containing ``<tspan>`` elements with the individual token styles.

    By default, this formatter outputs a full SVG document including doctype
    declaration and the ``<svg>`` root element.

    .. versionadded:: 0.9

    Additional options accepted:

    `nowrap`
        Don't wrap the SVG ``<text>`` elements in ``<svg><g>`` elements and
        don't add a XML declaration and a doctype.  If true, the `fontfamily`
        and `fontsize` options are ignored.  Defaults to ``False``.

    `fontfamily`
        The value to give the wrapping ``<g>`` element's ``font-family``
        attribute, defaults to ``"monospace"``.

    `fontsize`
        The value to give the wrapping ``<g>`` element's ``font-size``
        attribute, defaults to ``"14px"``.

    `xoffset`
        Starting offset in X direction, defaults to ``0``.

    `yoffset`
        Starting offset in Y direction, defaults to the font size if it is given
        in pixels, or ``20`` else.  (This is necessary since text coordinates
        refer to the text baseline, not the top edge.)

    `ystep`
        Offset to add to the Y coordinate for each subsequent line.  This should
        roughly be the text size plus 5.  It defaults to that value if the text
        size is given in pixels, or ``25`` else.

    `spacehack`
        Convert spaces in the source to ``&#160;``, which are non-breaking
        spaces.  SVG provides the ``xml:space`` attribute to control how
        whitespace inside tags is handled, in theory, the ``preserve`` value
        could be used to keep all whitespace as-is.  However, many current SVG
        viewers don't obey that rule, so this option is provided as a workaround
        and defaults to ``True``.
    t   SVGt   svgs   *.svgc         K   s  t  j |  |  t | d t ƒ |  _ | j d d ƒ |  _ | j d d ƒ |  _ t | d d ƒ |  _	 |  j j
 ƒ  } | j d ƒ r• | d	  j
 ƒ  } n  y t | ƒ } Wn d
 } n Xt | d | ƒ |  _ t | d | d ƒ |  _ t | d t ƒ |  _ i  |  _ d  S(   Nt   nowrapt
   fontfamilyt	   monospacet   fontsizet   14pxt   xoffseti    t   pxiþÿÿÿi   t   yoffsett   ystepi   t	   spacehack(   R    t   __init__R   t   FalseR   t   getR   R   R   R   t   stript   endswitht   intR   R   t   TrueR   t   _stylecache(   t   selft   optionst   fst   int_fs(    (    s;   /usr/lib/python2.7/dist-packages/pygments/formatters/svg.pyR   P   s      
c         C   s»  |  j  } |  j } |  j s‚ |  j r; | j d |  j ƒ n | j d ƒ | j d ƒ | j d ƒ | j d |  j |  j f ƒ n  | j d | | f ƒ xõ | D]í \ } } |  j | ƒ } | rÏ d | d pÒ d	 } | rá d
 pä d	 }	 t | ƒ } |  j	 r| j
 ƒ  j d d ƒ } n  | j d ƒ }
 xK |
 d  D]? } | j | | |	 ƒ | |  j 7} | j d | | f ƒ q1W| j | |
 d |	 ƒ q  W| j d ƒ |  j s·| j d ƒ n  d S(   sÏ   
        Format ``tokensource``, an iterable of ``(tokentype, tokenstring)``
        tuples and write it into ``outfile``.

        For our implementation we put all lines in their own 'line group'.
        s$   <?xml version="1.0" encoding="%s"?>
s   <?xml version="1.0"?>
sk   <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
s)   <svg xmlns="http://www.w3.org/2000/svg">
s$   <g font-family="%s" font-size="%s">
s)   <text x="%s" y="%s" xml:space="preserve">s   <tspanR   t    s   </tspan>t    s   &#160;s   
iÿÿÿÿs1   </text>
<text x="%s" y="%s" xml:space="preserve">s   </text>s   </g></svg>
N(   R   R   R   t   encodingt   writeR   R   t
   _get_styleR   R   t
   expandtabsR	   t   splitR   (   R    t   tokensourcet   outfilet   xt   yt   ttypet   valuet   stylet   tspant   tspanendt   partst   part(    (    s;   /usr/lib/python2.7/dist-packages/pygments/formatters/svg.pyt   format_unencodeda   s:    									c         C   s¸   | |  j  k r |  j  | S| } x |  j j | ƒ sA | j } q# W|  j j | ƒ } d } | d ry d | d d } n  | d r | d 7} n  | d r§ | d 7} n  | |  j  | <| S(	   NR$   t   colors    fill="#R   t   bolds    font-weight="bold"t   italics    font-style="italic"(   R   R1   t   styles_tokent   parentt   style_for_token(   R    t	   tokentypet
   otokentypeR0   t   result(    (    s;   /usr/lib/python2.7/dist-packages/pygments/formatters/svg.pyR(   Š   s    


(	   t   __name__t
   __module__t   __doc__t   namet   aliasest	   filenamesR   R6   R(   (    (    (    s;   /usr/lib/python2.7/dist-packages/pygments/formatters/svg.pyR      s   .				)N(
   RB   t   pygments.formatterR    t   pygments.utilR   R   t   __all__R   t   class2styleR   (    (    (    s;   /usr/lib/python2.7/dist-packages/pygments/formatters/svg.pyt   <module>
   s   			