hZdZddlZddlZddlmZddlmZmZmZm Z ddl Z ddl m Z m Z mZdZn #e$rdZYnwxYw ddlZn#e$r ddlZn #e$rdZYnwxYwYnwxYwgdZgd d d gd gd dgdZdZdZdZGddeZGddeZGddZGddeZGddeZGddeZGdd eZdS)!z pygments.formatters.img ~~~~~~~~~~~~~~~~~~~~~~~ Formatter for Pixmap output. :copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. N) Formatter) get_bool_opt get_int_opt get_list_optget_choice_opt)Image ImageDraw ImageFontTF)ImageFormatterGifImageFormatterJpgImageFormatterBmpImageFormatter)RomanBookNormalRegularMediumObliqueItalicBoldz Bold Obliquez Bold Italic)NORMALITALICBOLD BOLDITALICzDejaVu Sans Monoz Courier NewMenloceZdZdZdS)PilNotAvailablez,When Python imaging library is not availableN__name__ __module__ __qualname____doc__/builddir/build/BUILD/imunify360-venv-2.5.2/opt/imunify360/venv/lib/python3.11/site-packages/pip/_vendor/pygments/formatters/img.pyrr4s6666r%rceZdZdZdS) FontNotFoundz(When there are no usable fonts specifiedNrr$r%r&r(r(8s2222r%r(cXeZdZdZddZdZdZdZdZdd Z d Z d Z d Z d Z dZdS) FontManagerz> Manages a set of fonts: normal, italic, bold, etc... ch||_||_i|_d|_d|_t |dst j|r7tj ||j}d|_tD] }||j|< dStj dr$|s t|_|dStj dr$|s t"|_|dS|s t&|_|dS)NFreadTwindarwin) font_name font_sizefontsencodingvariablehasattrospathisfiler truetypeSTYLESsysplatform startswithDEFAULT_FONT_NAME_WIN _create_winDEFAULT_FONT_NAME_MAC _create_macDEFAULT_FONT_NAME_NIX _create_nix)selfr0r1fontstyles r&__init__zFontManager.__init__As/""   9f % %  )B)B %i@@D DM ) )$( 5!! F < " "5 ) )  7!6         \ $ $X . .  7!6         7!6        r%c|tjd|d|dgtjd}|\}}|jdkrp|}|D]W}|dr|d}|r|cSXdSdS)Nzfc-listz:style=file)stdoutstderrrsFontconfig warning::) subprocessPopenPIPE communicate returncode splitlinesr=decodestrip) rDnamerFprocrJ_linesliner7s r&_get_nix_font_pathzFontManager._get_nix_font_path\st,C,CE,C,CV L'1tEEE$$&&  ?a  %%''E  ??#9::{{}}**,,22377 KKK 4 r%ctdD]C}||j|}|$tj||j|jd<nDtd|jddD]}t|D]C}||j|}|$tj||j|j|<n2D|dkr|jd|j|<o|jd|j|<dS)NrNo usable fonts named: ""rrrrr)r:rZr0r r9r1r2r()rDrUr7rF stylenames r&rCzFontManager._create_nixjs8$ M MD**4>4@@D'0'9$'O'O 8$ K$.KKKLL L5 = =E#E] = = ..t~yII#(1(:4(P(PDJu%E$L(((, 6(:DJu%%(, 8(>@@AAAr%ci}tjtjddddfD]5|fdtjD6t dD]D}|||j|}|$tj ||j |j d<nEtd|jdd D]}t |D]D}|||j|}|$tj ||j |j |<n2E|d kr|j d |j |<p|j d|j |<dS) NHOMEzLibrary/Fonts/z/Library/Fonts/z/System/Library/Fonts/c3K|]}|d)tj|dtj|fVdS))ttfttcrN)rcendswithr6r7splitextjoin).0ffont_dirs r& z*FontManager._create_mac..s777799%%n557!!!$$Q'--//h1J1JK777777r%rr\r]r^rr)r6r7rmgetenvupdatelistdirr:rer0r r9r1r2r()rDrdrUr7rFr_rps @r&rAzFontManager._create_macsbi&7&79IJJ*,DF 7 7H OO7777H--777 7 7 7 7 8$ M MD**8T^TJJD'0'9$'O'O 8$ K$.KKKLL L5 = =E#E] = = ..xSS#(1(:4(P(PDJu%E$L(((, 6(:DJu%%(, 8(E!EE! E<!E77E<< F  F c,|dS)z) Get the character size. M) get_text_sizerDs r& get_char_sizezFontManager.get_char_sizes!!#&&&r%c|jd}t|dr||ddS||S)z4 Get the text size (width, height). rgetbbox)r2r5rgetsize)rDtextrEs r&rzFontManager.get_text_sizesOz(# 4 # # &<<%%ac* *<<%% %r%cZ|r+|r)|jr|dS|jdS|r)|jr|dS|jdS|r)|jr|dS|jdS|jr|dS|jdS)z> Get the font based on bold and italic flags. rrrr)r4 get_styler2)rDboldobliques r&get_fontzFontManager.get_fonts  (G (} 4~~l333:l+ +  (} .~~f---:f% %  (} 0~~h///:h' '} 0~~h///:h' 'r%c|j|}t|D]:} |||cS#t$rY(t$r|cYcSwxYw|S)z} Get the specified style of the font if it is a variable font. If not found, return the normal font. )r2r:set_variation_by_name ValueErrorry)rDrFrE style_names r&rzFontManager.get_styles z%  -  J **:666          s7 A AAN)r+)F)r r!r"r#rGrZrCrerArr?rrrrr$r%r&r*r*<s6   ===(BBB===8    %H%H%HN''' &&&(((2r%r*ceZdZdZdZgdZdgZdZdZdZ dd Z d Z d Z d Z d ZdZdZdZdZdZdZdZdZdZdZdZdZdS)r a; 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. If a filename or a file-like object is specified, the user must provide different styles of the font. Default: "Courier New" on Windows, "Menlo" on Mac OS, and "DejaVu Sans Mono" 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 img)rIMGpngz*.pngFrc ftstdtj|fi|d|_t |j|_|jjd|_n|jj|_t|dgd|j d|_ t|d d |_ t|d d |_t|d d}t|dd||_|j\|_|_|dd|_|dd|_t|dd |_t1|dd|_t1|dd|_t|dd|_t1|dd|_t1|dd|_t|dd|_t|dd|_|jr |j|jz|jd zz|_ nd |_ g|_!tE|d!g}|D]:} |j!#tI|+#tJ$rY7wxYw|d"|jj&pd#|_'g|_(dS)$zE See the class docstring for explanation of options. z5Python Imaging Library is required for this formatterlatin1Nz#fff image_format)rjpeggifbmpT)normcase image_pad line_padrr1r+r0rline_number_fgz#886line_number_bgz#eedline_number_charsline_number_boldFline_number_italicline_number_pad line_numbersline_number_separatorline_number_stepline_number_startrhl_lineshl_colorz#f90)) pil_availablerrrGr3dictrFr|background_colorrdefault_image_formatrrrrr*rbr2rfontwfonthrrrrrrrrrrrline_number_widthrrappendintrhighlight_colorr drawables)rDoptionsfontsize hl_lines_strrYs r&rGzImageFormatter.__init__s I!GII I4++7+++  4:&& : & .$*D ! !$(J$?D !* ^%B%B%B  %666%Wk2>>#GZ;; w R88 ["!=!=xHH !%!9!9!;!; DJ%kk*:FCC%kk*:FCC!,W-@!"E"E ,W-?!H!H".w/CU#L#L*74EqII(.$GG%1'2I4&Q&Q" +G5G K K!,W6I1!M!M   '&*j43I&I&*&:Q&>'?D " "&'D " #GZ<<    D  $$SYY////     J$(J$>@@JCI s 'I33 J?Jrc td)NzWThe -S option is meaningless for the image formatter. Use -O style= instead.)NotImplementedError)rDargs r&get_style_defszImageFormatter.get_style_defss!#QRR Rr%c |j|jzS)z+ Get the height of a line. )rrrs r&_get_line_heightzImageFormatter._get_line_heightszDM))r%c@||z|jzS)z8 Get the Y coordinate of a line number. )rrrDlinenos r& _get_line_yzImageFormatter._get_line_ys"--///$.@@r%c|jS)z/ Get the width of a character. )rrs r&_get_char_widthzImageFormatter._get_char_widths zr%c&||jz|jzS)z? Get the X coordinate of a character position. )rr)rD linelengths r& _get_char_xzImageFormatter._get_char_xsDN*T-CCCr%cV||||fS)zL Get the actual position for a character and line position. )rr)rDrrs r& _get_text_poszImageFormatter._get_text_poss+ ++T-=-=f-E-EEEr%c:|j||fS)zI Get the actual position for the start of a line number. )rrrs r&_get_linenumber_posz"ImageFormatter._get_linenumber_poss 0 0 8 899r%c2|d d|dz}nd}|S)zE Get the correct color for the token from the style. colorN#z#000r$)rDrFfills r&_get_text_colorzImageFormatter._get_text_colors( > %w'DDD r%c2|d d|dz}nd}|S)zP Get the correct background color for the token from the style. bgcolorNrr$)rDrFbg_colors r&_get_text_bg_colorz!ImageFormatter._get_text_bg_colors*   'U9--HHHr%cP|j|d|dS)z5 Get the correct font for the style. ritalic)r2r)rDrFs r&_get_style_fontzImageFormatter._get_style_fonts$z""5=%/BBBr%c||||jz||dz|jzfS)z. Get the required image size. r)rrr)rD maxlinelength maxlinenos r&_get_image_sizezImageFormatter._get_image_sizesD  //$.@  Q//$.@B Br%c|||t||j|j|j|j|j ddS)zA Remember a line number drawable to paint later. NrEtext_fgtext_bg) _draw_textrstrrjustrr2rrrr)rDposnors r&_draw_linenumberzImageFormatter._draw_linenumbers}   $ $U + + KK  d4 5 5$$T%:%)%<>>'      r%cD|j|||||fdS)zB Remember a single drawable tuple to paint later. N)rr)rDposrrErrs r&rzImageFormatter._draw_texts+ sD$ABBBBBr%c dx}x}}dx}}|D][\}}||jvr|j}||jv|j|} |d}|d} t | D]\} } | d} | r||||| || | | | | |j | \}}||z }t||}|t| z }t||}| dr d}d}|dz }]||_||_||_dS)z9 Create drawables for the token content. rrT rrN)r|parent expandtabsrR enumeraterstriprrrrrr2rmaxlenrkr maxcharnor)rD tokensourcercharnorrrttypevaluerFrXirYtemp temp_widthrWs r&_create_drawablesz ImageFormatter._create_drawabless'('')%&& '  LE5t{** t{**K&E$$Q''E$$T**E$U++  4{{4(( 7OO**:v>>#33E::"&"6"6u"="="&"9"9%"@"@ $%)J$<$29LI M M M DDr%c |||tjd||j|j|j}||tj |}|j r|j |j z|jz dz}|}|jd|z }|j D]B}||dz } ||| f||z| |zfg|jC|jD]\} } } } }|rt+|dr|| | }n| | dd}|| d| d| d|dz| d|dzg||| | | | |||jdS) 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. RGBrrrtextsize)rrErN)rEr)rr rnewrrrrrr rrrrrrrrrrrr5rrrsaverupper)rDroutfilerrxrr linenumberyrrrErr text_sizes r&rvzImageFormatter.format]s  {+++ !!! Y   !3T^ D D  !   ""2&&&~b!! = 3!77$:NNQRRA))++EGAJNE"m 3 3 $$Z!^44AUAI(>?$(M333326. ; ; .Cgw m4,,8 $ 5t D DII $ U 3 3ABB 7IAAA10Es1vPYZ[P\G\]dklll IIc5t'I : : : : *002233333r%N)r)r r!r"r#rUaliases filenames unicodeoutputrrGrrrrrrrrrrrrrrr rrvr$r%r&r r spll^ D###G IM 666pRRRR*** AAA  DDD FFF ::: CCC BBB    CCC & & & P , , ,"#4#4#4#4#4r%r c&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 img_gifrz*.gifNr r!r"r#rUr#r$rr$r%r&r r s5 DgG I r%r c(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 img_jpgjpgrz*.jpgNr(r$r%r&r r s7 DfoG I!r%r c(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 img_bmprbitmapz*.bmpNr(r$r%r&rrs8 DhG I r%r) r#r6r;pip._vendor.pygments.formatterrpip._vendor.pygments.utilrrrrrMPILrr r r ImportErrorrwwinreg__all__r:rBr>r@r Exceptionr(r*r r r rr$r%r&r6s 444444//////////MMMMMNNNN          GFFh'(!=1   +%77777k777333339333NNNNNNNNbs4s4s4s4s4Ys4s4s4r ! ! ! ! ! ! ! ! " " " " " " " " ! ! ! ! ! ! ! ! ! !sA /99AAA  A AAAAA