
`9Sc           @   s   d  Z  d d l Z d d l Z d d l Z d d l Td d l Td Z d   Z d e j j	 f d     YZ	 d e
 f d	     YZ d
 e f d     YZ d S(   s   A paint engine to produce EMF exports.

Requires: PyQt-x11-gpl-4.6-snapshot-20090906.tar.gz
          sip-4.9-snapshot-20090906.tar.gz
          pyemf
iN(   t   *gffffff9@c         C   s   |  d @d k S(   s   Is this a stock windows object.l        i    (    (   t   obj(    (    s+   code\common\utils\third_party\emf_export.pyt   isStockObject&   s    t   _EXTCREATEPENc           B   sh   e  Z d  Z d d d d d d d d d d d g Z e j d d g  d  Z d   Z d   Z d   Z	 RS(   s4   Extended pen creation record with custom line style.t   it   handlei    t   offBmit   cbBmit   offBitst   cbBitst   stylet   penwidtht
   brushstylet   colort
   brushhatcht   numstyleentriesi   c         C   s~   t  j j j |   | |  _ | |  _ t  j |  |  _ d |  _ | t  j	 @d k r_ g  |  _
 n	 | |  _
 t |  j
  |  _ d S(   sG   Create pen.
          styleentries is a list of dash and space lengths.i    N(   t   pyemft   _EMRR   t   __init__R
   R   t   _normalizeColorR   R   t   PS_USERSTYLEt   styleentriest   lenR   (   t   selfR
   t   widthR   R   (    (    s+   code\common\utils\third_party\emf_export.pyR   :   s    				c         C   s   t  j d  t |  j  S(   NR   (   t   structt   calcsizeR   R   (   R   (    (    s+   code\common\utils\third_party\emf_export.pyt	   sizeExtraL   s    c         C   s   |  j  | d |  j  d  S(   NR   (   t   serializeListR   (   R   t   fh(    (    s+   code\common\utils\third_party\emf_export.pyt   serializeExtraO   s    c         C   s   t  S(   N(   t   True(   R   (    (    s+   code\common\utils\third_party\emf_export.pyt	   hasHandleR   s    (   R   s   handlei    (   R   R   i    (   R   R   i    (   R   R   i    (   R   R	   i    (   R   s   style(   R   s   penwidth(   R   s
   brushstyle(   R   s   color(   R   R   i    (   R   s   numstyleentries(
   t   __name__t
   __module__t   __doc__t   emr_typedefR   t   PS_SOLIDR   R   R   R    (    (    (    s+   code\common\utils\third_party\emf_export.pyR   *   s"   			t   EMFPaintEnginec           B   s   e  Z d  Z d d  Z d   Z d   Z d   Z d   Z d   Z d   Z	 d	   Z
 d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   s   Custom EMF paint engine.iK   c         C   s   t  j |  t  j t  j Bt  j Bt  j Bt  j B | |  _ | |  _ | |  _	 t
 |  j |  |  _ t
 |  j |  |  _ t   |  _ d  S(   N(   t   QPaintEngineR   t   Antialiasingt   PainterPathst   PrimitiveTransformt   PaintOutsidePaintEventt   PatternBrusht   width_int	   height_int   dpit   intR   t   heightt   QMatrixt   transformMatrix(   R   R-   R.   R/   (    (    s+   code\common\utils\third_party\emf_export.pyR   X   s    				c         C   sg   t  j |  j |  j |  j  |  _ |  j j t  j  |  _ d |  _	 |  j j t  j
  |  _ | |  _ t S(   Ni    (   i    i    i    (   R   t   EMFR-   R.   R/   t   emft   GetStockObjectt	   BLACK_PENt   pent   pencolort
   NULL_BRUSHt   brusht   paintdeviceR   (   R   R<   (    (    s+   code\common\utils\third_party\emf_export.pyt   beging   s    !		c         C   sO   xH | D]@ } |  j  j | j   | j   f | j   | j   f g  q Wd S(   s   Draw lines to emf output.N(   R5   t   Polylinet   x1t   y1t   x2t   y2(   R   t   linest   line(    (    s+   code\common\utils\third_party\emf_export.pyt	   drawLinesp   s    	c         C   sZ   xS | D]K } |  j  j | j   | j   | j   | j   | j   | j    q Wd  S(   N(   R5   t	   Rectanglet   xt   yR   R1   (   R   t   rectst   rect(    (    s+   code\common\utils\third_party\emf_export.pyt	   drawRectsx   s    c         C   s   g  | D] } | j    | j   f ^ q } | t j k rM |  j j |  nK |  j j i t j t j	 6t j
 t j 6t j t j 6|  |  j j |  d S(   s   Draw polygon on output.N(   RG   RH   R'   t   PolylineModeR5   R>   t   SetPolyFillModeR   t   WINDINGt   WindingModet	   ALTERNATEt   OddEvenModet
   ConvexModet   Polygon(   R   t   pointst   modet   pt   pts(    (    s+   code\common\utils\third_party\emf_export.pyt   drawPolygon}   s    +c         C   sr   | j    | j   | j   | j   | j    | j   | j    | j   f } |  j j |   |  j j |   d S(   s   Draw an ellipse.N(   t   leftt   topt   rightt   bottomR5   t   Piet   Arc(   R   RJ   t   args(    (    s+   code\common\utils\third_party\emf_export.pyt   drawEllipse   s    c      
   C   so   xh | D]` } | j    d | j   d } } |  j j | | | j    d | j   d | | | |  q Wd S(   s   Draw points.g      ?N(   RG   RH   R5   R]   (   R   RT   t   ptRG   RH   (    (    s+   code\common\utils\third_party\emf_export.pyt
   drawPoints   s
    !c         C   s  t    } t |  } | j t j  | j | d  t | j    } | d } t j	 d | d d ! \ } t j	 d | d d ! \ }	 t j	 d | d d ! \ }
 t
 j j   } | j   | _ | j   | _ | j   | _ | j   | _ | j   | _ | j   | _ | j   | _ | j   | _ | j   | _ | j   | _ | j   | _ | j   | _ d | _ | j    | _! | | _" | j    |	 d | _# |
 | _$ d	 | _% | | _& |  j' j( |  d
 S(   s   Draw pixmap to display.t   BMPi   s   <ii   i
   i"   i&   i   i    N()   t
   QByteArrayt   QBuffert   opent	   QIODevicet	   WriteOnlyt   savet   strt   dataR   t   unpackR   R   t   _STRETCHDIBITSRY   t   rclBounds_leftRZ   t   rclBounds_topR[   t   rclBounds_rightR\   t   rclBounds_bottomt   xDestt   yDestR   t   cxDestR1   t   cyDestt   xSrct   ySrct   cxSrct   cySrct   dwRopt   serializeOffsett	   offBmiSrct   cbBmiSrct
   offBitsSrct	   cbBitsSrct	   iUsageSrct   unhandleddataR5   t   _append(   R   t   rt   pixmapt   srt   bytest   buffert   bmpt   dibt   hdrsizet	   dataindext   datasizet   epix(    (    s+   code\common\utils\third_party\emf_export.pyt
   drawPixmap   s<    	
					c         C   sS  |  j  j   | j   } d } x| | k  r4| j |  } | j t j k rk |  j  j | j | j	  n | j t j
 k r |  j  j | j | j	  n | j t j k r| j | d  } | j | d  } |  j  j | j | j	 f | j | j	 f | j | j	 f f  | d 7} n t s't  | d 7} q" W|  j  j   |  j  j   d S(   s   Convert qt path to emf pathi    i   i   N(   R5   t	   BeginPatht   elementCountt	   elementAtt   typet   QPainterPatht   MoveToElementt   MoveToRG   RH   t   LineToElementt   LineTot   CurveToElementt   PolyBezierTot   Falset   AssertionErrort   CloseFiguret   EndPath(   R   t   patht   countR   t   et   e1t   e2(    (    s+   code\common\utils\third_party\emf_export.pyt   _createPath   s*    	c         C   s   |  j  |  |  j j   d S(   s   Draw a path on the output.N(   R   R5   t   StrokeAndFillPath(   R   R   (    (    s+   code\common\utils\third_party\emf_export.pyt   drawPath   s    c         C   s   t    } | j | | j   | j    |  j j |  j  } |  j j |  |  j |  |  j j	   |  j j |  j
  |  j j |  d S(   s.   Convert text to a path and draw it.
          N(   R   t   addTextt   fontt   textR5   t   CreateSolidBrushR9   t   SelectObjectR   t   FillPathR;   t   DeleteObject(   R   Ra   t   textitemR   t   fill(    (    s+   code\common\utils\third_party\emf_export.pyt   drawTextItem   s    	c         C   s   t  S(   N(   R   (   R   (    (    s+   code\common\utils\third_party\emf_export.pyt   end   s    c         C   s   |  j  j |  d  S(   N(   R5   Ri   (   R   t   filename(    (    s+   code\common\utils\third_party\emf_export.pyt   saveFile   s    c   	   	   C   s  i t  j t j 6t  j t j 6t  j t j 6t  j t j	 6t  j
 t j 6t  j t j 6t  j t j 6| j   } | i t  j t j 6t  j t j 6t  j t j 6| j   O} | i t  j t j 6t  j t j 6t  j t j 6t  j t j 6| j   O} | t  j  O} | j!   } | j"   } | j#   | j$   | j%   f } | |  _& | j   t j @rg  | j'   D] } | | ^ q]} |  j( j) t* | d | d | d |  } n |  j( j+ | | |  } |  j( j, |  t- |  j.  s|  j( j/ |  j.  n  | |  _. d S(   s-   Update the pen to the currently selected one.R   R   R   N(0   R   t   PS_NULLt   Qtt   NoPenR%   t	   SolidLinet   PS_DASHt   DashLinet   PS_DOTt   DotLinet
   PS_DASHDOTt   DashDotLinet   PS_DASHDOTDOTt   DashDotDotLineR   t   CustomDashLineR
   t   PS_ENDCAP_FLATt   FlatCapt   PS_ENDCAP_SQUAREt	   SquareCapt   PS_ENDCAP_ROUNDt   RoundCapt   capStylet   PS_JOIN_MITERt	   MiterJoint   PS_JOIN_BEVELt	   BevelJoint   PS_JOIN_ROUNDt	   RoundJoint   SvgMiterJoint	   joinStylet   PS_GEOMETRICt   widthFR   t   redt   greent   blueR9   t   dashPatternR5   t   _appendHandleR   t	   CreatePenR   R   R8   R   (	   R   R8   R
   R   t   qcR   t   ft   dasht   newpen(    (    s+   code\common\utils\third_party\emf_export.pyt
   _updatePen  s<    !	#		c         C   sc  | j    } | j   } | j   | j   | j   f } | t j k r] |  j j |  } n | t j	 k r |  j j
 t j  } n yb i t j t j 6t j t j 6t j t j 6t j t j 6t j t j 6t j t j 6| j    } Wn# t k
 r|  j j |  } n X|  j j | |  } |  j j |  t |  j  sV|  j j |  j  n  | |  _ d S(   s   Update to selected brush.N(   R
   R   R   R   R   R   t   SolidPatternR5   R   t   NoBrushR6   R   R:   t   HS_HORIZONTALt
   HorPatternt   HS_VERTICALt
   VerPatternt   HS_CROSSt   CrossPatternt   HS_BDIAGONALt   BDiagPatternt   HS_FDIAGONALt   FDiagPatternt   HS_DIAGCROSSt   DiagCrossPatternt   KeyErrort   CreateHatchBrushR   R   R;   R   (   R   R;   R
   R   R   t   newbrusht   hatch(    (    s+   code\common\utils\third_party\emf_export.pyt   _updateBrush1  s*    !c         C   s[  | t  j k rc |  j |  i t j t  j 6t j t  j 6t j t  j	 6| } |  j
 j d |  n |  j j   s |  j
 j d d d d d d  n  |  j
 j   |  j
 j d d  |  j } |  j } |  j
 j | d  |  j
 j | |  |  j
 j d |  |  j
 j   |  j
 j   t j } |  j
 j d |  |  j j   sW|  j |  j  n  d S(   s   Update clipping path.RU   g      ?g        i    N(   R   t   NoClipR   R   t   RGN_COPYt   ReplaceClipt   RGN_ANDt   IntersectClipt   RGN_ORt	   UniteClipR5   t   SelectClipPathR3   t
   isIdentityt   SetWorldTransformR   R   R   R1   R   R   R   t   _updateTransform(   R   R   t	   operationt   clipmodet   wt   h(    (    s+   code\common\utils\third_party\emf_export.pyt   _updateClipPathP  s,    "			c         C   sP   |  j  j | j   | j   | j   | j   | j   | j    | |  _ d S(   s   Update transformation.N(	   R5   R   t   m11t   m12t   m21t   m22t   dxt   dyR3   (   R   t   m(    (    s+   code\common\utils\third_party\emf_export.pyR   o  s    c         C   s   | j    } | t j @r/ |  j | j    n  | t j @rR |  j | j    n  | t j @r~ |  j	 | j
   | j    n  | t j @r t   } | j | j    |  j	 | | j    n  | t j @r |  j | j    n  d S(   s?   Examine what has changed in state and call apropriate function.N(   t   stateR'   t   DirtyPenR   R8   t
   DirtyBrushR   R;   t   DirtyClipPathR   t   clipPatht   clipOperationt   DirtyClipRegionR   t	   addRegiont
   clipRegiont   DirtyTransformR   t   matrix(   R   R  t   ssR   (    (    s+   code\common\utils\third_party\emf_export.pyt   updateState{  s    	c         C   s   t  j S(   N(   R'   t
   PostScript(   R   (    (    s+   code\common\utils\third_party\emf_export.pyR     s    (   R!   R"   R#   R   R=   RE   RK   RX   R`   Rb   R   R   R   R   R   R   R   R   R   R   R  R   (    (    (    s+   code\common\utils\third_party\emf_export.pyR&   U   s(   						
	
	+						0				t   EMFPaintDevicec           B   s   e  Z d  Z d d  Z d   Z d   Z d   Z d   Z d   Z d   Z	 d	   Z
 d
   Z d   Z d   Z d   Z d   Z RS(   s"   Paint device for EMF paint engine.iK   c         C   s)   t  j |   t | | d | |  _ d  S(   NR/   (   t   QPaintDeviceR   R&   t   engine(   R   R-   R.   R/   (    (    s+   code\common\utils\third_party\emf_export.pyR     s    c         C   s   |  j  S(   N(   R  (   R   (    (    s+   code\common\utils\third_party\emf_export.pyt   paintEngine  s    c         C   s
   |  j  j S(   N(   R  R   (   R   (    (    s+   code\common\utils\third_party\emf_export.pyR     s    c         C   s   t  |  j j t  S(   N(   R0   R  R-   t   inch_mm(   R   (    (    s+   code\common\utils\third_party\emf_export.pyt   widthMM  s    c         C   s
   |  j  j S(   N(   R  R1   (   R   (    (    s+   code\common\utils\third_party\emf_export.pyR1     s    c         C   s   t  |  j j t  S(   N(   R0   R  R.   R  (   R   (    (    s+   code\common\utils\third_party\emf_export.pyt   heightMM  s    c         C   s
   |  j  j S(   N(   R  R/   (   R   (    (    s+   code\common\utils\third_party\emf_export.pyt   logicalDpiX  s    c         C   s
   |  j  j S(   N(   R  R/   (   R   (    (    s+   code\common\utils\third_party\emf_export.pyt   logicalDpiY  s    c         C   s
   |  j  j S(   N(   R  R/   (   R   (    (    s+   code\common\utils\third_party\emf_export.pyt   physicalDpiX  s    c         C   s
   |  j  j S(   N(   R  R/   (   R   (    (    s+   code\common\utils\third_party\emf_export.pyt   physicalDpiY  s    c         C   s   d S(   Ni   (    (   R   (    (    s+   code\common\utils\third_party\emf_export.pyt   depth  s    c         C   s   d S(   Ni(    (   R   (    (    s+   code\common\utils\third_party\emf_export.pyt	   numColors  s    c         C   s   | t  j k r |  j   S| t  j k r2 |  j   S| t  j k rK |  j   S| t  j k rd |  j   S| t  j	 k r} |  j
   S| t  j k r |  j   S| t  j k r |  j   S| t  j k r |  j   S| t  j k r |  j   S| t  j k r |  j   Sd  S(   N(   R  t   PdmWidthR   t	   PdmHeightR1   t
   PdmWidthMMR  t   PdmHeightMMR  t   PdmNumColorsR   t   PdmDepthR  t   PdmDpiXR  t   PdmDpiYR  t   PdmPhysicalDpiXR  t   PdmPhysicalDpiYt   physcialDpiY(   R   R  (    (    s+   code\common\utils\third_party\emf_export.pyt   metric  s(    








(   R!   R"   R#   R   R  R   R  R1   R  R  R  R  R  R  R   R,  (    (    (    s+   code\common\utils\third_party\emf_export.pyR    s   											(   R#   t   sysR   R   t   PyQt4.QtCoret   PyQt4.QtGuiR  R   R   R   R'   R&   R  R  (    (    (    s+   code\common\utils\third_party\emf_export.pyt   <module>   s   

	+ ;