Ñò Žf¯Jc@sÃdZddkZddklZddklZddklZlZl Z y.ddk Z ddk Z ddk Z e ZWnej o eZnXyddkZWnej o eZnXdddd gZhd d d d ddgd6ddgd6dgd6ddgd6ZdZdZdefd„ƒYZdefd„ƒYZdefd „ƒYZdefd!„ƒYZdefd"„ƒYZdefd#„ƒYZd efd$„ƒYZdS(%sÏ pygments.formatters.img ~~~~~~~~~~~~~~~~~~~~~~~ Formatter for Pixmap output. :copyright: Copyright 2006-2009 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. iÿÿÿÿN(tgetstatusoutput(t Formatter(t get_bool_optt get_int_opttget_choice_opttImageFormattertGifImageFormattertJpgImageFormattertBmpImageFormatterttRomantBooktNormaltRegulartMediumtNORMALtObliquetItalictITALICtBoldtBOLDs Bold Obliques Bold Italict BOLDITALICsBitstream Vera Sans Monos Courier NewtPilNotAvailablecBseZdZRS(s,When Python imaging library is not available(t__name__t __module__t__doc__(((s;/usr/lib/python2.6/site-packages/pygments/formatters/img.pyR/st FontNotFoundcBseZdZRS(s(When there are no usable fonts specified(RRR(((s;/usr/lib/python2.6/site-packages/pygments/formatters/img.pyR3st FontManagercBsSeZdZdd„Zd„Zd„Zed„Zd„Zd„Z d„Z RS( s> Manages a set of fonts: normal, italic, bold, etc... icCs{||_||_h|_d|_tiidƒo"|p t|_n|i ƒn|p t |_n|i ƒdS(Ntwin( t font_namet font_sizetfontstNonetencodingtsystplatformt startswithtDEFAULT_FONT_NAME_WINt _create_wintDEFAULT_FONT_NAME_NIXt _create_nix(tselfRR((s;/usr/lib/python2.6/site-packages/pygments/formatters/img.pyt__init__<s      cCs\td||fƒ\}}|p5|iƒ}|o|diƒidƒ}|SndS(Nsfc-list "%s:style=%s" fileit:(Rt splitlineststrip(R)tnametstyletexittouttlinestpath((s;/usr/lib/python2.6/site-packages/pygments/formatters/img.pyt_get_nix_font_pathJs cCsxhtdD]I}|i|i|ƒ}|dj o!ti||iƒ|idd||od||f}ti||ƒ\}} |SWqtj o qqXqWqW|otd||dfƒ‚ndSdS(NR s (TrueType)s%s%s%st s"Font %s (%s) not found in registryi(R s (TrueType)(t_winregt QueryValueExtEnvironmentErrorRR ( R)tkeytbasenametstylestfailtsuffixR/tvalnametvalt_((s;/usr/lib/python2.6/site-packages/pygments/formatters/img.pyt _lookup_winhsc CsKytitidƒ}WnNtj oBytitidƒ}Wqjtj otdƒ‚qjXnXzÌ|i||itdtƒ}t i ||i ƒ|i d Get the font based on bold and italic flags. RRRRN(R(R)tboldtoblique((s;/usr/lib/python2.6/site-packages/pygments/formatters/img.pytget_font˜s   ( RRRR*R4R(tFalseRER&RLRO(((s;/usr/lib/python2.6/site-packages/pygments/formatters/img.pyR7s     cBsÔeZdZdZdddgZdgZeZdZd„Z dd„Z d„Z d „Z d „Z d „Zd „Zd „Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„ZRS(s Create a PNG image from source code. This uses the Python Imaging Library to generate a pixmap from the source code. *New in Pygments 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" `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_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 timgtIMGtpngs*.pngcKs tptdƒ‚nti||t|iƒ|_|iidjo d|_n|ii|_t |dddddg|i dt ƒ|_ t |d d ƒ|_t |d d ƒ|_t |d dƒ}t|iddƒ|ƒ|_|iiƒ\|_|_|iddƒ|_|iddƒ|_t |dd ƒ|_t|dtƒ|_t|dtƒ|_t |ddƒ|_t|dt ƒ|_t|dt ƒ|_t |ddƒ|_ |io"|i|i|id |_!n d|_!g|_"dS( sE See the class docstring for explanation of options. s5Python Imaging Library is required for this formatters#ffft image_formatRStjpegtgiftbmptnormcaset image_padi tline_padiRiRR tline_number_fgs#886tline_number_bgs#eedtline_number_charstline_number_boldtline_number_italictline_number_padit line_numberstline_number_separatortline_number_stepiiN(#t pil_availableRRR*tdictR/R?tbackground_colorR Rtdefault_image_formatRHRTRRYRZRtgetRRLtfontwtfonthR[R\R]RRPR^R_R`RaRbRctline_number_widtht drawables(R)toptionstfontsize((s;/usr/lib/python2.6/site-packages/pygments/formatters/img.pyR*sD     R cCstdƒ‚dS(NsWThe -S option is meaningless for the image formatter. Use -O style= instead.(tNotImplementedError(R)targ((s;/usr/lib/python2.6/site-packages/pygments/formatters/img.pytget_style_defs5scCs|i|iS(s+ Get the height of a line. (RjRZ(R)((s;/usr/lib/python2.6/site-packages/pygments/formatters/img.pyt_get_line_height9scCs||iƒ|iS(s8 Get the Y coordinate of a line number. (RrRY(R)tlineno((s;/usr/lib/python2.6/site-packages/pygments/formatters/img.pyt _get_line_y?scCs|iS(s/ Get the width of a character. (Ri(R)((s;/usr/lib/python2.6/site-packages/pygments/formatters/img.pyt_get_char_widthEscCs||i|i|iS(s? Get the X coordinate of a character position. (RiRYRk(R)tcharno((s;/usr/lib/python2.6/site-packages/pygments/formatters/img.pyt _get_char_xKscCs|i|ƒ|i|ƒfS(sL Get the actual position for a character and line position. (RwRt(R)RvRs((s;/usr/lib/python2.6/site-packages/pygments/formatters/img.pyt _get_text_posQscCs|i|i|ƒfS(sI Get the actual position for the start of a line number. (RYRt(R)Rs((s;/usr/lib/python2.6/site-packages/pygments/formatters/img.pyt_get_linenumber_posWscCs-|ddj od|d}nd}|S(sE Get the correct color for the token from the style. tcolort#s#000N(R (R)R/tfill((s;/usr/lib/python2.6/site-packages/pygments/formatters/img.pyt_get_text_color]scCs|ii|d|dƒS(s5 Get the correct font for the style. RMtitalic(RRO(R)R/((s;/usr/lib/python2.6/site-packages/pygments/formatters/img.pyt_get_style_fontgscCs.|i|ƒ|i|i|dƒ|ifS(s. Get the required image size. i(RwRYRt(R)t maxcharnot maxlineno((s;/usr/lib/python2.6/site-packages/pygments/formatters/img.pyt_get_image_sizemscCsW|i|i|ƒt|dƒi|iƒd|ii|i|iƒd|i ƒdS(sA Remember a line number drawable to paint later. itfontR|N( t _draw_textRytstrtrjustR]RROR^R_R[(R)Rs((s;/usr/lib/python2.6/site-packages/pygments/formatters/img.pyt_draw_linenumberts   cKs |ii||||fƒdS(sB Remember a single drawable tuple to paint later. N(Rltappend(R)tposttextRƒtkw((s;/usr/lib/python2.6/site-packages/pygments/formatters/img.pyR„€sc Cs;d}}}x|D] \}}x||ijo |i}q$W|i|}|idƒ}|itƒ}x±t|ƒD]£\} } | idƒ} | o]|i|i||ƒ| d|i |ƒd|i |ƒƒ|t | ƒ7}t ||ƒ}n| i dƒod}|d7}qzqzWqW||_||_dS(s9 Create drawables for the token content. iis RƒR|iN(R?tparentt expandtabsR,RHt enumeratetrstripR„RxRR}tlentmaxtendswithR€R( R)t tokensourceRsRvR€tttypetvalueR/R2titlinettemp((s;/usr/lib/python2.6/site-packages/pygments/formatters/img.pyt_create_drawables†s2    cCsV|ipdSx@t|iƒD]/}|d|idjo|i|ƒqqWdS(s8 Create drawables for the line numbers. Nii(RatxrangeRRcR‡(R)R–((s;/usr/lib/python2.6/site-packages/pygments/formatters/img.pyt_draw_line_numbers§s  cCs¨|ipdS|idjodSti|ƒ}|id}|i|i|i}|i d||fgd|i ƒ|i |df||fgd|iƒ~dS(s@ Paint the line number background on the image. NiÿÿÿÿiR|(ii( RaR[R t ImageDrawtDrawtsizeRYRkR`t rectangleR\R—(R)timtdrawtrecthtrectw((s;/usr/lib/python2.6/site-packages/pygments/formatters/img.pyt_paint_line_number_bg±s    (c Cs³|i|ƒ|iƒtid|i|i|iƒ|iƒ}|i|ƒt i |ƒ}x6|i D]+\}}}}|i ||d||qgW|i ||iiƒƒdS(s  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. tRGBRƒN(R™R›tImagetnewR‚R€RRfR¤RœRRlRŠtsaveRTtupper( R)R“toutfileR R¡R‰R•RƒR‹((s;/usr/lib/python2.6/site-packages/pygments/formatters/img.pytformatÂs     (RRRR.taliasest filenamesRPt unicodeoutputRgR*RqRrRtRuRwRxRyR}RR‚R‡R„R™R›R¤R«(((s;/usr/lib/python2.6/site-packages/pygments/formatters/img.pyR¦s.W  -           ! cBs,eZdZdZdgZdgZdZRS(s  Create a GIF image from source code. This uses the Python Imaging Library to generate a pixmap from the source code. *New in Pygments 1.0.* (You could create GIF images before by passing a suitable `image_format` option to the `ImageFormatter`.) timg_gifRVs*.gif(RRRR.R¬R­Rg(((s;/usr/lib/python2.6/site-packages/pygments/formatters/img.pyRÛs   cBs/eZdZdZddgZdgZdZRS(s Create a JPEG image from source code. This uses the Python Imaging Library to generate a pixmap from the source code. *New in Pygments 1.0.* (You could create JPEG images before by passing a suitable `image_format` option to the `ImageFormatter`.) timg_jpgtjpgRUs*.jpg(RRRR.R¬R­Rg(((s;/usr/lib/python2.6/site-packages/pygments/formatters/img.pyRês   cBs/eZdZdZddgZdgZdZRS(s Create a bitmap image from source code. This uses the Python Imaging Library to generate a pixmap from the source code. *New in Pygments 1.0.* (You could create bitmap images before by passing a suitable `image_format` option to the `ImageFormatter`.) timg_bmpRWtbitmaps*.bmp(RRRR.R¬R­Rg(((s;/usr/lib/python2.6/site-packages/pygments/formatters/img.pyRùs   ( RR"tcommandsRtpygments.formatterRt pygments.utilRRRR¦RœR6RHRdt ImportErrorRPR:R t__all__R5R'R%Rt ExceptionRtobjectRRRRR(((s;/usr/lib/python2.6/site-packages/pygments/formatters/img.pyt s< $       oÿ6