관리-도구
편집 파일: rtf.cpython-38.pyc
U &?�f�. � @ sZ d Z ddlmZ ddlmZ ddlmZ ddlmZm Z m Z mZ dgZG dd� de�Z dS ) z� pygments.formatters.rtf ~~~~~~~~~~~~~~~~~~~~~~~ A formatter that generates RTF files. :copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. � )�OrderedDict)� Formatter)�_ansimap)�get_bool_opt�get_int_opt�get_list_opt� surrogatepair�RtfFormatterc @ s� e Zd ZdZdZdgZdgZdd� Zdd� Zd d � Z e dd� �Zd d� Zdd� Z edd� �Zedd� �Zedd� �Zdd� ZdS )r a� Format tokens as RTF markup. This formatter automatically outputs full RTF documents with color information and other useful stuff. Perfect for Copy and Paste into Microsoft(R) Word(R) documents. Please note that ``encoding`` and ``outencoding`` options are ignored. The RTF format is ASCII natively, but handles unicode characters correctly thanks to escape sequences. .. versionadded:: 0.6 Additional options accepted: `style` The style to use, can be a string or a Style subclass (default: ``'default'``). `fontface` The used font family, for example ``Bitstream Vera Sans``. Defaults to some generic font which is supposed to have fixed width. `fontsize` Size of the font used. Size is specified in half points. The default is 24 half-points, giving a size 12 font. .. versionadded:: 2.0 `linenos` Turn on line numbering (default: ``False``). .. versionadded:: 2.18 `lineno_fontsize` Font size for line numbers. Size is specified in half points (default: `fontsize`). .. versionadded:: 2.18 `lineno_padding` Number of spaces between the (inline) line numbers and the source code (default: ``2``). .. versionadded:: 2.18 `linenostart` The line number for the first line (default: ``1``). .. versionadded:: 2.18 `linenostep` If set to a number n > 1, only every nth line number is printed. .. versionadded:: 2.18 `lineno_color` Color for line numbers specified as a hex triplet, e.g. ``'5e5e5e'``. Defaults to the style's line number color if it is a hex triplet, otherwise ansi bright black. .. versionadded:: 2.18 `hl_lines` Specify a list of lines to be highlighted, as line numbers separated by spaces, e.g. ``'3 7 8'``. The line numbers are relative to the input (i.e. the first line is line 1) unless `hl_linenostart` is set. .. versionadded:: 2.18 `hl_color` Color for highlighting the lines specified in `hl_lines`, specified as a hex triplet (default: style's `highlight_color`). .. versionadded:: 2.18 `hl_linenostart` If set to ``True`` line numbers in `hl_lines` are specified relative to `linenostart` (default ``False``). .. versionadded:: 2.18 ZRTFZrtfz*.rtfc K sJ t j| f|� |�d�pd| _t|dd�| _t|dd�| _t|d| j�| _t|dd �| _ t t|d d��| _t t|dd��| _t|d d�| _ |�dd�| _| js�| jj| _g | _t|dg �D ]F}z,t|�}| j r�|| j d }| j�|� W q� tk r� Y q�X q�|�dd�| _| j�s<| jjdk�r2td | _n | jj| _| �� | _dS )a� Additional options accepted: ``fontface`` Name of the font used. Could for example be ``'Courier New'`` to further specify the default which is ``'\fmodern'``. The RTF specification claims that ``\fmodern`` are "Fixed-pitch serif and sans serif fonts". Hope every RTF implementation thinks the same about modern... �fontface� �fontsizer �linenosF�lineno_fontsize�lineno_padding� �linenostart� � linenostep�hl_linenostart�hl_color�hl_lines�lineno_color�inherit�ansibrightblackN)r �__init__�getr r r r r r r �absr r r r �style�highlight_colorr r �int�append� ValueErrorr �line_number_colorr �_create_color_mapping� color_mapping)�self�options�lineno� r( �Q/opt/hc_python/lib/python3.8/site-packages/pip/_vendor/pygments/formatters/rtf.pyr i s: � zRtfFormatter.__init__c C s |� dd�� dd�� dd�S )N�\z\\�{z\{�}z\})�replace)r% �textr( r( r) �_escape� s � �zRtfFormatter._escapec C s� |sdS | � |�}g }|D ]f}t|�}|dk r>|�t|�� qd| krRdk rfn n|�d| � qd|kr|�dt|� � qd�|��dd�S )Nr � i z{\u%d}z{\u%d}{\u%d}� z\par)r/ �ordr �strr �joinr- )r% r. �buf�cZcnr( r( r) �_escape_text� s zRtfFormatter._escape_textc C sP | d dkr| dd � } dt | dd� d�t | dd� d�t | dd� d�f S ) Nr �#r z\red%d\green%d\blue%d;r � � � )r )� hex_colorr( r( r) �hex_to_rtf_color� s �zRtfFormatter.hex_to_rtf_colorc c sz |D ]p\}}|dkr ||fV qd|krj|� d�}|dd� D ]}||d fV q>|d rt||d fV q||fV qdS )z� Split tokens containing newline characters into multiple token each representing a line of the input file. Needed for numbering lines of e.g. multiline comments. r1 N���)�split)r% �tokensource�ttype�value�lines�liner( r( r) �_split_tokens_on_newlines� s z&RtfFormatter._split_tokens_on_newlinesc C s� t � }d}| jr"||| j<