
    ,h.                     `    d Z ddlmZ ddlmZ ddlmZ ddlmZm	Z	m
Z
mZ dgZ G d de      Zy)	z
    pygments.formatters.rtf
    ~~~~~~~~~~~~~~~~~~~~~~~

    A formatter that generates RTF files.

    :copyright: Copyright 2006-2025 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                       e Zd ZdZdZdgZdgZd Zd Zd Z	e
d        Zd	 Zd
 Zed        Zed        Zed        Zd Zy)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
    RTFrtfz*.rtfc                    t        j                  | fi | |j                  d      xs d| _        t	        |dd      | _        t        |dd      | _        t	        |d| j
                        | _        t	        |dd	      | _	        t        t	        |d
d            | _        t        t	        |dd            | _        t        |dd      | _        |j                  dd      | _        | j                  s| j                  j                   | _        g | _        t%        |dg       D ]G  }	 t'        |      }| j                  r|| j                  z
  dz   }| j"                  j)                  |       I |j                  dd      | _        | j,                  sC| j                  j.                  dk(  rt0        d   | _        n| j                  j.                  | _        | j3                         | _        y# t*        $ r Y w xY w)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linenos      Y/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/pygments/formatters/rtf.pyr   zRtfFormatter.__init__i   s    	4+7+J/52#GZ;#GY>*74E+/== :)'3CQG{7M1EFk'<CD*74DeLJ3}} JJ66DM"7J; 	FV&&#d&6&66:F$$V,	 $KK;  

,,	9 %-->$?! %)JJ$@$@!!779  s   !AG##	G/.G/c                 f    |j                  dd      j                  dd      j                  dd      S )N\z\\{z\{}z\})replace)r*   texts     r-   _escapezRtfFormatter._escape   s-    ||D&)GC'GC'	(    c                 `   |sy| j                  |      }g }|D ]s  }t        |      }|dk  r|j                  t        |             .d|cxk  rdk  rn n|j                  d|z         Qd|k  sW|j                  dt	        |      z         u dj                  |      j                  dd      S )Nr      i   z{\u%d}z{\u%d}{\u%d}
z\par)r4   ordr%   strr	   joinr2   )r*   r3   bufccns        r-   _escape_textzRtfFormatter._escape_text   s     ||D! 	AAQBT{

3q6"2''

9r>*B 

+mB.??@	A wws|##D'22r5   c                 z    | d   dk(  r| dd  } dt        | dd d      t        | dd d      t        | dd d      fz  S )	Nr   #r   z\red%d\green%d\blue%d;r            )r$   )	hex_colors    r-   hex_to_rtf_colorzRtfFormatter.hex_to_rtf_color   s[    Q<3!!"I*IaNB/IaNB/IaNB/.  	r5   c              #      K   |D ]O  \  }}|dk(  r||f d|v r4|j                  d      }|dd D ]  }||dz   f  |d   s@||d   f J||f Q yw)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.
        r8   N)split)r*   tokensourcettypevaluelineslines         r-   _split_tokens_on_newlinesz&RtfFormatter._split_tokens_on_newlines   s      ( 
	%LE5}en$D)!#2J -D $t),,-9 %),,en$
	%s   AAAc                    t               }d}| j                  r||| j                  <   |dz  }| j                  r||| j                  <   |dz  }| j
                  D ]*  \  }}|d   |d   |d   fD ]  }|s||vs|||<   |dz  } , |S )zf
        Create a mapping of style hex colors to index/offset in
        the RTF color table.
        r   colorbgcolorborder)r   r   r   r   r   r"   )r*   r)   offset_r"   rQ   s         r-   r(   z"RtfFormatter._create_color_mapping   s    
 $<</5M$++,aKF==+1M$--(aKF

 	 HAuwy)95?J  U-7+1M%(aKF 	  r5   c                 "   | j                   | j                  k7  rAdj                  | j                   | j                  | j                     d| j
                  z        S dj                  | j                  | j                     d| j
                  z        S )Nz{{\fs{} \cf{} %s{}}} z{{\cf{} %s{}}})r   r   formatr)   r   r   r*   s    r-   _lineno_templatezRtfFormatter._lineno_template   s    4==0+2243G3G,,T->->? 3 335 5 !''(:(:4;L;L(MD///1 	1r5   c                 <    d| j                   | j                      dS )Nz{\highlightrW   )r)   r   rY   s    r-   _hl_open_strzRtfFormatter._hl_open_str   s!    t11$--@ACCr5   c                    g }|j                  d| j                  xr d| j                  | j                        z   xs dz         |j                  d       | j                  j	                         D ]%  \  }}|j                  | j                  |             ' |j                  d       |j                  d       | j                  r|j                  d| j                  z         |j                  d       |S )	Nz?{\rtf1\ansi\uc0\deff0{\fonttbl{\f0\fmodern\fprq1\fcharset0%s;}}rW   r   z{\colortbl;r1   z\f0\sa0z\fs%dz\dntblnsbdb)r%   r   r4   r)   itemsrF   r   )r*   rM   rQ   rU   s       r-   _rtf_headerzRtfFormatter._rtf_header   s     G 6#,,t}}5+6 <9;= 	> 	^$**002 	7HE1LL..u56	7S 	[!==LLDMM12
 	^$r5   c                    | j                   D ]  }|j                  |dz           | j                  |      }| j                  r^d}g }|D ]/  \  }}|j	                  ||f       |j                  d      s+|dz  }1 t        t        || j                  z   dz
              }|}d}	d}
|D ]  \  }}|
r)|	| j                  v r|j                  | j                         |
r| j                  r~|	| j                  z
  dz   | j                  z  dk(  r-|	| j                  z   dz
  }t        |      j                        }ndj                        }|j                  | j                  |z         | j                  j                  |      s@|j                   r4|j                   }| j                  j                  |      s|j                   r4| j                  j#                  |      }g }|d   r$|j	                  d| j$                  |d      z         |d   r$|j	                  d	| j$                  |d      z         |d
   r|j	                  d       |d   r|j	                  d       |d   r|j	                  d       |d   r$|j	                  d| j$                  |d      z         dj'                  |      }|r|j                  d| d       |j                  | j)                  |             |r|j                  d       d}
|j                  d      sc|	| j                  v r|j                  d       |j                  d       d}
|	dz  }	 |j                  d       y )Nr8   r   r   Tr   rR   z\cb%drQ   z\cf%dboldz\bitalicz\i	underlinez\ulrS   z\chbrdr\chcfpat%dr0   rW   r1   Fz}
)r_   writerO   r   r%   endswithlenr:   r   r   r\   r   rjustrZ   r"   styles_tokenparentstyle_for_tokenr)   r;   r?   )r*   rJ   outfilerN   
line_counttokensrK   rL   linenos_widthr,   start_new_linecurrent_lineno
lineno_strr"   r<   starts                   r-   format_unencodedzRtfFormatter.format_unencoded  s   $$ 	'DMM$+&	' 44[A <<JF + $uuen->>$'!OJ$  Jt/?/?$?$A BCM K ' .	LE5&DMM"9d//0$,,4+++A-t>!C%+d.>.>%>%BN!$^!4!:!:=!IJ!#-!8Jd33j@Ajj--e4 jj--e4JJ..u5ECY

8d&8&8y9I&JJKW~

8d&8&8w&HHIV}

5!X

5![!

6"X

0--eHo>? @GGCLE5'm,MM$++E23c""N ~~d#T]]*MM#&d#!%!].	` 	er5   N)__name__
__module____qualname____doc__namealiases	filenamesr   r4   r?   staticmethodrF   rO   r(   propertyrZ   r\   r_   rs    r5   r-   r
   r
      s    O` DgG	I0:d(
30  %$0 1 1 D D  4Gr5   N)rw   collectionsr   pygments.formatterr   pygments.styler   pygments.utilr   r   r   r	   __all__r
   r}   r5   r-   <module>r      s3    $ ( # P P 
I9 Ir5   