Your IP : 216.73.216.213


Current Path : /opt/alt/python37/lib/python3.7/site-packages/pygments/formatters/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/pygments/formatters/__pycache__/img.cpython-37.pyc

B

ͽ�\EM�@srdZddlZddlZddlmZddlmZmZmZm	Z	m
Z
ddlZyddlm
Z
mZmZdZWnek
rxdZYnXyddlZWn:ek
r�yddlZWnek
r�dZYnXYnXdd	d
dgZdd
ddddgddgdgddgd�ZdZdZdZGdd�de�ZGdd�de�ZGdd�de�ZGd d�de�ZGd!d	�d	e�ZGd"d
�d
e�Z Gd#d�de�Z!dS)$z�
    pygments.formatters.img
    ~~~~~~~~~~~~~~~~~~~~~~~

    Formatter for Pixmap output.

    :copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS.
    :license: BSD, see LICENSE for details.
�N)�	Formatter)�get_bool_opt�get_int_opt�get_list_opt�get_choice_opt�xrange)�Image�	ImageDraw�	ImageFontTF�ImageFormatter�GifImageFormatter�JpgImageFormatter�BmpImageFormatter�ZRomanZBookZNormalZRegularZMediumZObliqueZItalicZBoldzBold ObliquezBold Italic)�NORMAL�ITALIC�BOLD�
BOLDITALICzBitstream Vera Sans MonozCourier Newc@seZdZdZdS)�PilNotAvailablez,When Python imaging library is not availableN)�__name__�
__module__�__qualname__�__doc__�rr�H/opt/alt/python37/lib/python3.7/site-packages/pygments/formatters/img.pyr6src@seZdZdZdS)�FontNotFoundz(When there are no usable fonts specifiedN)rrrrrrrrr:src@s\eZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zddd�Z	dd�Z
dd�Zdd�ZdS)�FontManagerz>
    Manages a set of fonts: normal, italic, bold, etc...
    �cCsn||_||_i|_d|_tj�d�r8|s.t|_|��n2tj�d�rX|sNt	|_|�
�n|sbt|_|��dS)N�win�darwin)
�	font_name�	font_size�fonts�encoding�sys�platform�
startswith�DEFAULT_FONT_NAME_WIN�_create_win�DEFAULT_FONT_NAME_MAC�_create_mac�DEFAULT_FONT_NAME_NIX�_create_nix)�selfr r!rrr�__init__Cs

zFontManager.__init__c	Csztjdd||fdgtjdd�}|��\}}|jdkrv|��}x2|D]*}|�d�rTqD|�����d�}|rD|SqDWdSdS)Nzfc-listz%s:style=%s�file)�stdout�stderrrsFontconfig warning:�:)	�
subprocess�Popen�PIPE�communicate�
returncode�
splitlinesr&�decode�strip)	r-�name�style�procr0�_�lines�line�pathrrr�_get_nix_font_pathUs


zFontManager._get_nix_font_pathcCs�xJtdD]0}|�|j|�}|dk	r
t�||j�|jd<Pq
Wtd|j��xtdD]l}xft|D]0}|�|j|�}|dk	r`t�||j�|j|<Pq`W|dkr�|jd|j|<qR|jd|j|<qRWdS)NrzNo usable fonts named: "%s")rrrrr)�STYLESrBr r
�truetyper!r"r)r-r;rAr<�	stylenamerrrr,cs 

zFontManager._create_nixcCs|�|d|�����S)N� )�getr:�lower)r-�font_mapr;r<rrr�_get_mac_font_pathxszFontManager._get_mac_font_pathcsi}x@tj�t�d�d�ddfD]"�|��fdd�t���D��q WxLtdD]2}|�||j|�}|dk	rPt	�
||j�|jd<PqPWt
d|j��xvd	D]n}xht|D]2}|�||j|�}|dk	r�t	�
||j�|j|<Pq�W|d
kr�|jd|j|<q�|jd|j|<q�WdS)N�HOMEzLibrary/Fonts/z/Library/Fonts/z/System/Library/Fonts/c3s>|]6}|���d�rtj�|�d��tj��|�fVqdS)ZttfrN)rH�endswith�osrA�splitext�join)�.0�f)�font_dirrr�	<genexpr>�sz*FontManager._create_mac.<locals>.<genexpr>rzNo usable fonts named: "%s")rrrrr)rMrArO�getenv�update�listdirrCrJr r
rDr!r"r)r-rIr;rAr<rEr)rRrr*{s,


zFontManager._create_macFc

Cs~xxdD]T}xN|D]F}y*d||o$d||f}t�||�\}}	|Stk
rTwYqXqWqW|rvtd||df��dSdS)N)rz (TrueType)z%s%s%srFz"Font %s (%s) not found in registryr)�_winreg�QueryValueEx�EnvironmentErrorr)
r-�key�basename�stylesZfail�suffixr<Zvalname�valr>rrr�_lookup_win�s

zFontManager._lookup_wincCs�yt�tjd�}WnDtk
rVyt�tjd�}Wntk
rPtd��YnXYnXz�|�||jtdd�}t�	||j
�|jd<xddD]\}|�||jt|�}|r�t�	||j
�|j|<q�|dkr�|jd|j|<q�|jd|j|<q�WWdt�|�XdS)	Nz2Software\Microsoft\Windows NT\CurrentVersion\Fontsz/Software\Microsoft\Windows\CurrentVersion\Fontsz$Can't open Windows font registry keyrT)rrrrr)
rW�OpenKey�HKEY_LOCAL_MACHINErYrr_r rCr
rDr!r"�CloseKey)r-rZrAr<rrrr(�s,


zFontManager._create_wincCs|jd�d�S)z)
        Get the character size.
        r�M)r"�getsize)r-rrr�
get_char_size�szFontManager.get_char_sizecCs<|r|r|jdS|r |jdS|r.|jdS|jdSdS)z>
        Get the font based on bold and italic flags.
        rrrrN)r")r-�boldZobliquerrr�get_font�s


zFontManager.get_fontN)r)F)
rrrrr.rBr,rJr*r_r(rergrrrrr>s

rc@s�eZdZdZdZdddgZdgZdZdZdd�Z	d+d
d�Z
dd
�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*S),ra�	
    Create a PNG image from source code. This uses the Python Imaging Library to
    generate a pixmap from the source code.

    .. versionadded:: 0.10

    Additional options accepted:

    `image_format`
        An image format to output to that is recognised by PIL, these include:

        * "PNG" (default)
        * "JPEG"
        * "BMP"
        * "GIF"

    `line_pad`
        The extra spacing (in pixels) between each line of text.

        Default: 2

    `font_name`
        The font name to be used as the base font from which others, such as
        bold and italic fonts will be generated.  This really should be a
        monospace font to look sane.

        Default: "Bitstream Vera Sans Mono" on Windows, Courier New on \*nix

    `font_size`
        The font size in points to be used.

        Default: 14

    `image_pad`
        The padding, in pixels to be used at each edge of the resulting image.

        Default: 10

    `line_numbers`
        Whether line numbers should be shown: True/False

        Default: True

    `line_number_start`
        The line number of the first line.

        Default: 1

    `line_number_step`
        The step used when printing line numbers.

        Default: 1

    `line_number_bg`
        The background colour (in "#123456" format) of the line number bar, or
        None to use the style background color.

        Default: "#eed"

    `line_number_fg`
        The text color of the line numbers (in "#123456"-like format).

        Default: "#886"

    `line_number_chars`
        The number of columns of line numbers allowable in the line number
        margin.

        Default: 2

    `line_number_bold`
        Whether line numbers will be bold: True/False

        Default: False

    `line_number_italic`
        Whether line numbers will be italicized: True/False

        Default: False

    `line_number_separator`
        Whether a line will be drawn between the line number area and the
        source code area: True/False

        Default: True

    `line_number_pad`
        The horizontal padding (in pixels) between the line number margin, and
        the source code area.

        Default: 6

    `hl_lines`
        Specify a list of lines to be highlighted.

        .. versionadded:: 1.2

        Default: empty list

    `hl_color`
        Specify the color for highlighting lines.

        .. versionadded:: 1.2

        Default: highlight color of the selected style
    ZimgZIMG�pngz*.pngFc	Ks�tstd��tj|f|�d|_t|j�|_|jjdkr@d|_n
|jj|_t	|ddddd	g|j
d
d�|_t|dd
�|_
t|dd�|_t|dd�}t|�dd�|�|_|j��\|_|_|�dd�|_|�dd�|_t|dd�|_t|dd�|_t|dd�|_t|dd�|_t|dd
�|_t|dd
�|_t|d d!�|_t|d"d!�|_|j�rd|j|j|jd|_ nd#|_ g|_!t"|d$g�}x:|D]2}y|j!�#t$|��Wnt%k
�r�YnX�q�W|�d%|jj&��p�d&|_'g|_(dS)'zE
        See the class docstring for explanation of options.
        z5Python Imaging Library is required for this formatter�latin1Nz#fff�image_formatrh�jpeg�gif�bmpT)�normcase�	image_pad�
�line_pad�r!rr r�line_number_fgz#886�line_number_bgz#eed�line_number_chars�line_number_boldF�line_number_italic�line_number_pad��line_numbers�line_number_separator�line_number_step��line_number_startr�hl_lines�hl_colorz#f90))�
pil_availablerrr.r#�dictr<r\�background_colorr�default_image_formatrjrrorqrrGr"re�fontw�fonthrsrtrurrvrwrxrzr{r|r~�line_number_widthrr�append�int�
ValueErrorZhighlight_colorr��	drawables)r-�optionsZfontsizeZhl_lines_strr@rrrr.JsZ






zImageFormatter.__init__rcCstd��dS)NzWThe -S option is meaningless for the image formatter. Use -O style=<stylename> instead.)�NotImplementedError)r-�argrrr�get_style_defs�szImageFormatter.get_style_defscCs|j|jS)z+
        Get the height of a line.
        )r�rq)r-rrr�_get_line_height�szImageFormatter._get_line_heightcCs||��|jS)z8
        Get the Y coordinate of a line number.
        )r�ro)r-�linenorrr�_get_line_y�szImageFormatter._get_line_ycCs|jS)z/
        Get the width of a character.
        )r�)r-rrr�_get_char_width�szImageFormatter._get_char_widthcCs||j|j|jS)z?
        Get the X coordinate of a character position.
        )r�ror�)r-�charnorrr�_get_char_x�szImageFormatter._get_char_xcCs|�|�|�|�fS)zL
        Get the actual position for a character and line position.
        )r�r�)r-r�r�rrr�
_get_text_pos�szImageFormatter._get_text_poscCs|j|�|�fS)zI
        Get the actual position for the start of a line number.
        )ror�)r-r�rrr�_get_linenumber_pos�sz"ImageFormatter._get_linenumber_poscCs"|ddk	rd|d}nd}|S)zE
        Get the correct color for the token from the style.
        ZcolorN�#z#000r)r-r<�fillrrr�_get_text_color�szImageFormatter._get_text_colorcCs|j�|d|d�S)z5
        Get the correct font for the style.
        rfZitalic)r"rg)r-r<rrr�_get_style_font�szImageFormatter._get_style_fontcCs$|�|�|j|�|d�|jfS)z.
        Get the required image size.
        r)r�ror�)r-�	maxcharno�	maxlinenorrr�_get_image_size�szImageFormatter._get_image_sizecCs8|j|�|�t|��|j�|j�|j|j�|j	d�dS)zA
        Remember a line number drawable to paint later.
        )�fontr�N)
�
_draw_textr��str�rjustrur"rgrvrwrs)r-Zposnor�rrr�_draw_linenumber�s
zImageFormatter._draw_linenumbercKs|j�||||f�dS)zB
        Remember a single drawable tuple to paint later.
        N)r�r�)r-�pos�textr��kwrrrr��szImageFormatter._draw_textc	Cs�d}}}x�|D]�\}}x||jkr.|j}qW|j|}|�d�}|�d�}xtt|�D]h\}	}
|
�d�}|r�|j|�||�||�|�|�	|�d�|t
|�7}t||�}|
�d�rXd}|d7}qXWqW||_
||_dS)z9
        Create drawables for the token content.
        r�T�
)r�r�r}N)r\�parent�
expandtabsr8�	enumerate�rstripr�r�r�r��len�maxrLr�r�)r-�tokensourcer�r�r�Zttype�valuer<r?�ir@�temprrr�_create_drawables�s,







z ImageFormatter._create_drawablescCsF|js
dSx6t|j�D](}||j}||jdkr|�||�qWdS)z8
        Create drawables for the line numbers.
        Nr)rzrr�r~r|r�)r-�p�nrrr�_draw_line_numbers�s
z!ImageFormatter._draw_line_numberscCsx|js
dS|jdkrdSt�|�}|jd}|j|j|j}|jd||fg|j	d�|j
|df||fg|jd�~dS)z@
        Paint the line number background on the image.
        N���)rr)r�r)rzrsr	�Draw�sizeror�rx�	rectanglertr@)r-�im�draw�recth�rectwrrr�_paint_line_number_bg�s



z$ImageFormatter._paint_line_number_bgcCs�|�|�|��t�d|�|j|j�|j�}|�|�t	�
|�}|jr�|j|j
|jd}|��}|jd|}x@|jD]6}|�|d�}	|j||	f|||	|fg|jd�q|Wx.|jD]$\}
}}}
|j|
|fd|i|
��q�W|�||j���dS)a 
        Format ``tokensource``, an iterable of ``(tokentype, tokenstring)``
        tuples and write it into ``outfile``.

        This implementation calculates where it should draw each token on the
        pixmap, then calculates the required pixmap size and draws the items.
        ZRGBr}r)r�r�N)r�r�r�newr�r�r�r�r�r	r�rror�rxr�r�r�r�r�r�r�Zsaverj�upper)r-r��outfiler�r��xr�r�Z
linenumber�yr�r�r�r�rrr�formats&


zImageFormatter.formatN)r)rrrrr;�aliases�	filenamesZ
unicodeoutputr�r.r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr�s.j
8

!c@s$eZdZdZdZdgZdgZdZdS)rz�
    Create a GIF image from source code. This uses the Python Imaging Library to
    generate a pixmap from the source code.

    .. versionadded:: 1.0
    Zimg_gifrlz*.gifN)rrrrr;r�r�r�rrrrr1s
c@s&eZdZdZdZddgZdgZdZdS)r
z�
    Create a JPEG image from source code. This uses the Python Imaging Library to
    generate a pixmap from the source code.

    .. versionadded:: 1.0
    Zimg_jpgZjpgrkz*.jpgN)rrrrr;r�r�r�rrrrr
?s
c@s&eZdZdZdZddgZdgZdZdS)rz�
    Create a bitmap image from source code. This uses the Python Imaging Library to
    generate a pixmap from the source code.

    .. versionadded:: 1.0
    Zimg_bmprmZbitmapz*.bmpN)rrrrr;r�r�r�rrrrrMs
)"rrMr$Zpygments.formatterrZ
pygments.utilrrrrrr3ZPILrr	r
r��ImportErrorrW�winreg�__all__rCr+r'r)r�	Exceptionr�objectrrrr
rrrrr�<module>
sH
^