ó `Û3Lc@ sdZddlmZyddlZWnek rEedƒ‚nXddlZddlZddlZddlZddl m Z m Z m Z ddl mZddlmZmZmZmZddlmZdd lmZdd lmZmZdd lmZmZmZmZdd l m!Z!dd lm"Z"ddl#m$Z$iZ%e&Z'e&Z(e&Z)defd„ƒYZ*dfd„ƒYZ+dfd„ƒYZ,defd„ƒYZ-defd„ƒYZ.d„Z/d„Z0d„Z1defd„ƒYZ2defd„ƒYZ3e3Z4dS( sZ Enhanced Metafile backend. See http://pyemf.sourceforge.net for the EMF driver library. iÿÿÿÿ(tdivisionNs5You must first install pyemf from http://pyemf.sf.net(tverboset __version__trcParams(tGcf(t RendererBasetGraphicsContextBasetFigureManagerBasetFigureCanvasBase(tFigure(tBbox(tfindfonttFontProperties(tFT2FonttKERNING_UNFITTEDtKERNING_DEFAULTtKERNING_UNSCALED(tPath(tAffine2D(t quad2cubictEMFFontPropertiescB s5eZd„Zd„Zd„Zd„Zd„ZRS(cC sPtj||jƒ|jƒ|jƒ|jƒ|jƒ|jƒƒ||_dS(N( R t__init__t get_familyt get_stylet get_variantt get_weightt get_stretchtget_sizet_angle(tselftothertangle((sR/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/backends/backend_emf.pyR*s     cC sttj|ƒ|jfƒS(N(thashR t__hash__R(R((sR/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/backends/backend_emf.pyR!3scC sttj|ƒ|jfƒS(N(tstrR t__str__R(R((sR/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/backends/backend_emf.pyR#6scC s ||_dS(N(R(RR((sR/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/backends/backend_emf.pyt set_angle9scC s|jS(N(R(R((sR/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/backends/backend_emf.pyt get_angle<s(t__name__t __module__RR!R#R$R%(((sR/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/backends/backend_emf.pyR)s    tEMFPencB s,eZd„Zd„Zd„Zd„ZRS(cC s¼||_||_|jƒ\}}}t|dƒ|_t|dƒ|_t|dƒ|_t|jƒƒ|_d|_ |j ƒt r¸d|j |j|j|j|jfGHndS(Niÿis(EMFPen: style=%d width=%d rgb=(%d,%d,%d)( temftgctget_rgbtinttrtgtbt get_linewidthtwidthtstylet set_linestylet debugHandle(RR)R*R-R.R/((sR/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/backends/backend_emf.pyRAs    cC s(t|j|j|j|j|jfƒS(N(R R2R1R-R.R/(R((sR/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/backends/backend_emf.pyR!OscC sœ|jdkrtj|_nzitjd6tjd6tjd6tjd6}|jj dƒ}t rpd|GHn||krŒ|||_n tj|_dS(NitsolidtdashedtdashdottdottedsEMFPen: style=%s( R1tpyemftPS_NULLR2tPS_SOLIDtPS_DASHt PS_DASHDOTtPS_DOTR*t get_linestyleR4(RtstylesR2((sR/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/backends/backend_emf.pyR3Rs  cC s4|jj|j|j|j|j|jfƒ}|S(N(R)t CreatePenR2R1R-R.R/(Rthandle((sR/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/backends/backend_emf.pyt get_handleas0(R&R'RR!R3RC(((sR/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/backends/backend_emf.pyR(@s   tEMFBrushcB s#eZd„Zd„Zd„ZRS(cC sy||_|\}}}t|dƒ|_t|dƒ|_t|dƒ|_trud|j|j|jfGHndS(NiÿsEMFBrush: rgb=(%d,%d,%d)(R)R,R-R.R/R4(RR)trgbR-R.R/((sR/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/backends/backend_emf.pyRgs cC st|j|j|jfƒS(N(R R-R.R/(R((sR/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/backends/backend_emf.pyR!oscC s(|jj|j|j|jfƒ}|S(N(R)tCreateSolidBrushR-R.R/(RRB((sR/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/backends/backend_emf.pyRCrs$(R&R'RR!RC(((sR/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/backends/backend_emf.pyRDfs  t RendererEMFcB sÐeZdZiejd6ejd6ejd6ejd6ejd6ejd6ejd6ejd6ejd 6ejd 6ejd 6ejd 6ejd 6ej d6ejd6ej d6ej d6ej d6Z d„Zd„Zd„Zd„Zd„Zd/d„Zd/d/d„Zd„Zd„Zd„Zd„Zd„Zed„Zd „Zd!„Zd"„Zd#„Z d$„Z!d%„Z"d&„Z#d'„Z$d(„Z%d)„Z&d*„Z'd+„Z(d,„Z)d-„Z*d.„Z+RS(0s] The renderer handles drawing/rendering operations through a pyemf.EMF instance. idiÈi,iiôiXi¼i i„t ultralighttlighttnormaltmediumtsemiboldtboldtheavyt ultraboldtblackcC s÷||_i|_i|_idd6dd6dd6|_tj|||dƒ|_t||ƒ|_t||ƒ|_ ||_ |d|_ d|_ |jj tjƒ|jjtjtjBƒd |_tród|j|j ||fGHnd S( s0Initialize the renderer with a gd image instanceiÿÿÿÿtfonttpentbrushtingR@g@sRendererEMF: (%f,%f) %s dpi=%fN(toutfilet_cachedt _fontHandlet lastHandleR9tEMFR)R,R1theighttdpit pointstodpithackPointsForMathExponentt SetBkModet TRANSPARENTt SetTextAlignt TA_BOTTOMtTA_LEFTtNonet _lastClipRectt debugPrint(RRUR1RZR[((sR/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/backends/backend_emf.pyR”s       cC s|jj|jƒdS(N(R)tsaveRU(R((sR/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/backends/backend_emf.pyRf³sc C smtr$d||||||fGHn|j|ƒ} |j|ƒ} |d} |d} t||dƒ}t||dƒ}| rx|jjt|| ƒt|j|| ƒt|| ƒt|j|| ƒt|tj|tj dƒ| ƒt|j|tj |tj dƒ| ƒt|tj|tj dƒ| ƒt|j|tj |tj dƒ| ƒƒnñ|jj t|| ƒt|j|| ƒt|| ƒt|j|| ƒt|tj|tj dƒ| ƒt|j|tj |tj dƒ| ƒt|tj|tj dƒ| ƒt|j|tj |tj dƒ| ƒƒdS(s Draw an arc using GraphicsContext instance gcEdge, centered at x,y, with width and height and angles from 0.0 to 360.0 0 degrees is at 3-o'clock positive angles are anti-clockwise If the color rgbFace is not None, fill the arc with it. s,draw_arc: (%f,%f) angles=(%f,%f) w,h=(%f,%f)ig€f@N( Ret select_pent select_brushR,R)tPieRZtmathtcostpitsintArc(RtgcEdgetrgbFacetxtyR1RZtangle1tangle2trotationRRRSthwthhtx1ty1((sR/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/backends/backend_emf.pytdraw_arc¶s   ôcC s||jƒ}|dk r$|j}n|j|krx||_|dkrodd|j|jf\}}}}n|\}}}}|jjƒ|jjt |ƒt |j|ƒƒ|jj t |ƒt |ƒt |j|ƒƒ|jj t |ƒt |ƒt |j|ƒt |ƒƒ|jj t |ƒt |j|ƒt |ƒƒ|jj ƒ|jj ƒ|jj ƒndS(Ni(tget_clip_rectangleRctboundsRdR1RZR)t BeginPathtMoveToR,tLineTot CloseFiguretEndPathtSelectClipPath(RR*t new_boundsRqRrR1RZ((sR/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/backends/backend_emf.pythandle_clip_rectangleÒs      ' &0:0  cC sT|jjƒd}x-|jƒD]\}}|tjkrN|jj|Œnë|tjkrp|jj|ŒnÉ|tj krÕt t |dƒt |ƒŒ}|jj t |ddd…|ddd…ƒƒnd|tjkr|jj t |ddd…|ddd…ƒƒn|tjkr9|jjƒn|}q W|jjƒdS(Niþÿÿÿiii(R)R}Rct iter_segmentsRtMOVETOR~tLINETORtCURVE3Rtlistt PolyBezierTotziptCURVE4t CLOSEPOLYR€R(Rttpatht last_pointstpointstcode((sR/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/backends/backend_emf.pyt convert_pathçs   66 cC s¨|j|ƒ|jd |_|j|ƒ|j|ƒ|tƒjddƒjd|jƒ}|j|ƒ}|j |ƒ|dkr—|j j ƒn |j j ƒdS(sk Draws a :class:`~matplotlib.path.Path` instance using the given affine transform. igð?gð¿gN(R„t_rgbRgRhRtscalet translateRZttransform_pathR’RcR)t StrokePathtStrokeAndFillPath(RR*tpatht transformRpRŽ((sR/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/backends/backend_emf.pyt draw_pathús   (  cC sdS(sˆ Draw the Image instance into the current axes; x is the distance in pixels from the left hand side of the canvas. y is the distance from the origin. That is, if origin is upper, y is the distance from top. If origin is lower, y is the distance from bottom bbox is a matplotlib.transforms.BBox instance for clipping, or None N((RRqRrtimtbboxtclippathtclippath_trans((sR/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/backends/backend_emf.pyt draw_image scC sštrd||||fGHn|j|ƒrx|jjt|ƒt|j|ƒft|ƒt|j|ƒfgƒntr–d||||fGHndS(s8 Draw a single line from x1,y1 to x2,y2 sdraw_line: (%f,%f) - (%f,%f)s,draw_line: optimizing away (%f,%f) - (%f,%f)N(ReRgR)tPolylinetlongRZ(RR*RxRytx2ty2((sR/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/backends/backend_emf.pyt draw_lines KcC sŠtrdtt|ƒƒGHn|j|ƒr†gtt|ƒƒD]-}t||ƒt|j||ƒf^q@}|jj|ƒndS(sc x and y are equal length arrays, draw lines connecting each point in x, y sdraw_lines: %d pointsN( RetlenR"RgtrangeR¢RZR)R¡(RR*RqRrtiR((sR/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/backends/backend_emf.pyt draw_lines(s FcC sitrd||fGHnt|j|ƒ}|jjt|ƒt|j|ƒ|j|j|jfƒdS(s| Draw a single point at x,y Where 'point' is a device-unit point (or pixel), not a matplotlib point sdraw_point: (%f,%f)N( ReR(R)tSetPixelR¢RZR-R.R/(RR*RqRrRR((sR/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/backends/backend_emf.pyt draw_point5scC sítrdt|ƒGHn|j|ƒ}|j|ƒ}|sB|rg|D]+\}}t|ƒt|j|ƒf^qI}|jj|ƒn\g|D]+\}}t|ƒt|j|ƒf^q”}trédt|ƒt|ƒfGHndS(sç Draw a polygon using the GraphicsContext instance gc. points is a len vertices tuple, each element giving the x,y coords a vertex If the color rgbFace is not None, fill the polygon with it sdraw_polygon: %d pointss5draw_polygon: optimizing away polygon: %d points = %sN( ReR¦RgRhR¢RZR)tPolygonR"(RRoRpRRRRSRqRr((sR/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/backends/backend_emf.pyt draw_polygonAs 88c C sÀtrd||||fGHn|j|ƒ}|j|ƒ}|sH|rž|jjt|ƒt|j|ƒt|ƒt|ƒt|j|ƒt|ƒƒntr¼d||||fGHndS(sË Draw a non-filled rectangle using the GraphicsContext instance gcEdge, with lower left at x,y with width and height. If rgbFace is not None, fill the rectangle with it. s!draw_rectangle: (%f,%f) w=%f,h=%fs1draw_rectangle: optimizing away (%f,%f) w=%f,h=%fN(ReRgRhR)t RectangleR,RZ( RRoRpRqRrR1RZRRRS((sR/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/backends/backend_emf.pytdraw_rectangleVs VcC s®|r|j|ƒ}n|j|ƒ|jj|jƒd ƒ|j||ƒt|tƒr”y|jddƒj dƒ}Wq”t k rq”Xn|jj |||ƒdS(s- Draw the text.Text instance s at x,y (display coords) with font properties instance prop at angle in degrees, using GraphicsContext gc **backend implementers note** When you are trying to determine if you have gotten your bounding box right (which is what enables the text layout/alignment to work properly), it helps to change the line in text.py if 0: bbox_artist(self, renderer) to if 1, and then the actual bounding box will be blotted along with your text. iu−t-s iso-8859-1N( t strip_mathR„R)t SetTextColorR+t select_fontt isinstancetunicodetreplacetencodetUnicodeEncodeErrortTextOut(RR*RqRrtstpropRtismath((sR/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/backends/backend_emf.pyt draw_textis  c C sÌtrd||||fGHntr6dt|ƒGHn|j||ƒd}tj|tjdƒ||jd}tj|tjdƒ||jd} |jj t ||ƒt || ƒ|ƒdS(sE Draw a text string verbatim; no conversion is done. s)draw_plain_text: (%f,%f) %d degrees: '%s's properties: i g€f@gÀr@N( t debugTextR"R³RjRmRlR[RkR)R¹R¢( RR*RqRrRºR»Rthackoffsetper300dpitxhacktyhack((sR/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/backends/backend_emf.pytdraw_plain_text†s))c C sCtrd||||fGHn|dd!}tjd|ƒ}|r#|jdƒ}trdd|GHn|j|ƒ} | jddƒ| jƒ\} } | d} | d} |j|||d||ƒ|jƒ} | j |j ƒd ƒ|j||| |j |j ƒ|| d || |ƒn|j||||||ƒd S( sµ Draw a subset of TeX, currently handles exponents only. Since pyemf doesn't have any raster functionality yet, the texmanager.get_rgba won't help. s(draw_math_text: (%f,%f) %d degrees: '%s'iiÿÿÿÿs 10\^\{(.+)\}s exponent=%st10ggP@gš™™™™™é?iN( R¾tretmatchtgroupt _get_font_ttftset_texttget_width_heightRÂtcopytset_sizetget_size_in_pointstpoints_to_pixelsR]( RR*RqRrRºR»RRÅtexpRQtwthtpropexp((sR/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/backends/backend_emf.pytdraw_math_text™s$     ;cC s^trdGHn|dd!}tjd|ƒ}|r9|jdƒ}trTd|GHn|j|ƒ}|jddƒ|jƒ\}}|jƒ}|j|j ƒdƒ|j|ƒ} | j|dƒ| jƒ\} } || } || d } | d } | d } | |j |j ƒ7} trTd || | fGHqTn|j ||t ƒ\} } | | fS( sÌ get the width and height in display coords of the string s with FontPropertry prop, ripped right out of backend_ps. This method must be kept in sync with draw_math_text. sget_math_text_width_height:iiÿÿÿÿs 10\^\{(.+)\}s exponent=%sRÃggš™™™™™é?igP@s math string=%s w,h=(%f,%f)(R¾RÄRÅRÆRÇRÈRÉRÊRËRÌRÍR]tget_text_width_heighttFalse(RRºR»RÅRÎRQtw1th1RÑtfontexptw2th2RÏRÐ((sR/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/backends/backend_emf.pytget_math_text_width_height³s2      cC s€|r|j|ƒ}n|j|ƒ}|j|dƒ|jƒ\}}|d}|d}|jƒ}|d}|||fS(sl get the width and height in display coords of the string s with FontPropertry prop ggP@(R±RÇRÈRÉt get_descent(RRºR»R¼RQRÏRÐtd((sR/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/backends/backend_emf.pytget_text_width_height_descentÓs    cC stS(s‚return true if y small numbers are top for renderer Is used for drawing text (text.py) and images (image.py) only (tTrue(R((sR/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/backends/backend_emf.pytflipyãscC s|j|jfS(sF return the canvas width and height in display coords (R1RZ(R((sR/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/backends/backend_emf.pytget_canvas_width_heightêscC s7|j||kr3|jj|ƒ||j|s@ 0""&ÿý