
    h"                     r    d Z ddlZ	 ddlZddlmZ ddlmZ ddl	m
Z  G d de      Zy# e$ r ddlZY )w xY w))GState    N)toColor)mmult)Imagec                   D   e Zd ZdZd%dZed        Zed        Zed        Z	e	j                  d        Z	ed        Zej                  d        Zed	        Zej                  d
        Zed        Zej                  d        Zed        Zej                  d        Zed        Zej                  d        Zed        Zej                  d        Zed        Zej                  d        Zd Zd Zd Zd Zd&dZd Zd Zd Zd Zd Zd  Zd! Zd" Zed'd#       Z 	 d(d$Z!y))r   )   r   c                     | _         t        j                   j                  |      ||       _        | _        | _        t        j                   j                        x _        |dk(  rfd _	        n|dk(  rfd _	        nt        d|z        j                  t        j                         ddddd|fx _         _        d	 _        | _        j#                  dd||        j%                           j'                          d x _         _         fd
}| _        t/        j0                  j2                  j4                  j6                         _        d _        y )NRGB24c                 >     j                   | j                          S N)set_source_rgbrgbcctxs    @/home/dcms/DCMS/lib/python3.12/site-packages/rlPyCairo/gstate.py<lambda>z!GState.__init__.<locals>.<lambda>   s    1C1C1CQUUW1M     ARGB32c                 >     j                   | j                          S r   )set_source_rgbargbar   s    r   r   z!GState.__init__.<locals>.<lambda>   s    1D1D1Daffh1O r   zBad fmt=%r for rlPyCairo.GStater   r   )r   r   r   r   r   r   c                    	 ddl mm}  |       	fd}|	_         || ||      S # t        $ rN 	 ddlm} n4# t        $ r( 	 ddlm} n# t        $ r}t        d      |d }~ww xY wY nw xY wddl m  |dd      Y nw xY w)Nr   )text2PathDescription
FTTextPath)gstatezJfreetype-py is not installed and no libart based _renderPM can be imported)r   r   c           	      J     | ||j                   j                  d      S )NF)xyfontNamefontSizetruncategsr!   r"   )textr   r    r$   selfr   s      r   _text2PathDescriptionzMGState.__init__.<locals>._text2PathDescription.<locals>._text2PathDescription3   s)    + $Q)-).2" "r   )reportlab.graphics.utilsr   r   ImportError_rl_renderPMr   reportlab.graphics._renderPMr(   )
r&   r   r    r   r   _er(   r$   r   r'   s
          @@r   r(   z.GState.__init__.<locals>._text2PathDescription%   s    !U\" *?D&(q!44#  	!@3" @@G& @)*vw}@ H@
 JAa[	!sS   , 	B=B	A.AA.	A(A##A((A.+B-A..BB)moveTolineTocurveTo	closePath)_fmtcairoImageSurface_GState__str2formatsurfacewidthheightContextr   __set_source_color__
ValueErrorset_antialiasANTIALIAS_BEST_in_transform_out_transformctm	fillColor	rectanglepathFill	pathBegin_GState__fillColor_GState__strokeColorr(   dictmove_toline_tocurve_to
close_path__pathOpMap__textRenderMode)r'   r7   r8   bgfmtr(   r   s   `     @r   __init__zGState.__init__   s7   	))$*;*;C*@%P
t||443<(MD%(](OD%>DEE%../45a"Qv3FFT0 a%'0444-	5, &;"!{{{{..	  r   c                 (    t        t        d| z         S )NFORMAT_)getattrr3   )rO   s    r   __str2formatzGState.__str2formatD   s    uYs]++r   c           	         | j                   j                         }t        |      }t        j                  dk(  r<t        dt        |      d      D ]"  }t        t        |||dz                |||dz    $ n8t        dt        |      d      D ]  }||   ||dz   |dz    c||dz   <   |||dz    ! | j                  dk(  r|dd d= t        |      S )Nlittler         r   r
   )
r6   get_data	bytearraysys	byteorderrangelenreversedr2   bytes)r'   bais      r   pixBufzGState.pixBufH   s    \\""$r]==("1SWQ' ;%hr!AaCy&9:1QqS	; 1SWQ' 6$&qE"QqS1+!1Q31QqS	699g14a4Ryr   c                 p    t        | j                  t        | j                  j	                                     S r   )r   r?   tupler   
get_matrixr'   s    r   r@   z
GState.ctmY   s'    T((txx/B/B/D)EFFr   c                     t        | j                  |      }| j                  j                  t	        j
                  |        y r   )r   r>   r   
set_matrixr3   Matrix)r'   mxnctms      r   r@   z
GState.ctm]   s/    T''+ELL$/0r   c                     | j                   S r   )rE   rg   s    r   rA   zGState.fillColorb   s    r   c                 8    |t        |      | _        y || _        y r   )r   rE   r'   r   s     r   rA   zGState.fillColorf   s    )*71:Ar   c                     | j                   S r   )rF   rg   s    r   strokeColorzGState.strokeColorj   s    !!!r   c                 8    |t        |      | _        y || _        y r   )r   rF   ro   s     r   rq   zGState.strokeColorn   s    +,=WQZar   c                 6    | j                   j                         S r   )r   get_line_widthrg   s    r   strokeWidthzGState.strokeWidthr   s    xx&&((r   c                 8    | j                   j                  |      S r   )r   set_line_width)r'   ws     r   ru   zGState.strokeWidthv   s    xx&&q))r   c                 6    | j                   j                         S r   )r   get_dashrg   s    r   	dashArrayzGState.dashArrayz   s    xx  ""r   c                     |rt        |t        t        f      sd}n#t        |d   t        t        f      r
|d   |d   f}| j                  j	                  |d   |d         S )N)r    r   r   )
isinstancelistre   r   set_dash)r'   das     r   r{   zGState.dashArray~   sY    BU|4B"Q%e-U2a5[xx  A1..r   c                 H    t        | j                  j                               S r   )intr   get_line_caprg   s    r   lineCapzGState.lineCap   s    488((*++r   c                 J    | j                   j                  t        |            S r   )r   set_line_capr   r'   vs     r   r   zGState.lineCap   s    xx$$SV,,r   c                 H    t        | j                  j                               S r   )r   r   get_line_joinrg   s    r   lineJoinzGState.lineJoin   s    488))+,,r   c                 J    | j                   j                  t        |            S r   )r   set_line_joinr   r   s     r   r   zGState.lineJoin   s    xx%%c!f--r   c                 b    | j                   t        | j                  j                                  S r   )_GState__fill_rule_valuesr   r   get_fill_rulerg   s    r   fillModezGState.fillMode   s%    &&s488+A+A+C'DEEr   c                 d    | j                   j                  | j                  t        |               S r   )r   set_fill_ruler   r   r   s     r   r   zGState.fillMode   s&    xx%%d&=&=c!f&EFFr   c                 8    | j                   j                          y r   r   new_pathrg   s    r   	beginPathzGState.beginPath       r   c                 `    | j                   j                  t        |      t        |             y r   )r   rH   floatr'   r   r    s      r   r.   zGState.moveTo       q58,r   c                 `    | j                   j                  t        |      t        |             y r   )r   rI   r   r   s      r   r/   zGState.lineTo   r   r   c                 8    | j                   j                          y r   )r   rK   rg   s    r   	pathClosezGState.pathClose       r   Nc                     | j                   r`|| j                  }||k7  r|| _        | j                  | j                          | j                  j	                          ||k7  r|| _        y y y y r   )rE   r   r:   r   fill_preserve)r'   r   ofms      r   rC   zGState.pathFill   sg    #mm=($-%%d&6&67HH""$#Xst}# r   c                     | j                   rF| j                  dkD  r6| j                  | j                          | j                  j	                          y y y )Nr   )rF   ru   r:   r   stroke_preserverg   s    r   
pathStrokezGState.pathStroke   sD    $"2"21"4%%d&8&89HH$$& #5r   c           
          | j                   j                  t        |      t        |      t        |      t        |      t        |      t        |             y r   )r   rJ   r   )r'   x1y1x2y2x3y3s          r   r0   zGState.curveTo   s7    %)U2YuRy%)E"IuUWyYr   c                 8    | j                   j                          y r   r   rg   s    r   rD   zGState.pathBegin   r   r   c                 8    | j                   j                          y r   )r   
reset_cliprg   s    r   clipPathClearzGState.clipPathClear   r   r   c                     | j                   }|j                         }|j                          |j                          |j	                  |       y r   )r   	copy_pathclipr   append_path)r'   r   oPaths      r   clipPathSetzGState.clipPathSet   s4    hh
r   c                 8    | j                   j                          y r   )r   clip_preserverg   s    r   clipPathAddzGState.clipPathAdd   s     r   c                      || _         || _        y r   r%   )r'   r!   r"   s      r   setFontzGState.setFont   s      r   c                    | j                   }| j                  j                         }| j                  }| j                  }	 | j                  j                          | j                  |||      D ]  } ||d      |dd     |dv r| j                  d       |dv r| j                          |dk\  r| j                  j                          | j                  j                          | j                  j                  |       || _        y # | j                  j                          | j                  j                  |       || _        w xY w)Nr   r   )r      rW      )r   r      r   rW   )rL   r   r   r   rM   r   r(   rC   r   r   r   )	r'   r   r    r&   opMapr   oFMtRMops	            r   
drawStringzGState.drawString   s   """"$mm!!	 HH00q!< &bebf%& ia i!Av&&(HHHH  'DM HHHH  'DMs    BD >Ec           
         |j                   }|j                         }|dk(  }|dk(  r6|j                  t        |dz               |dk7  r|r|j	                  d      }n|dk(  s|r3|r|j                  t        |dz               |r\|j	                  d      }nJ|dk(  s|rC|rA|j	                  d      }|j                  t        |dz               |r|j	                  d      }| j                  |      }t        j                  dk(  r|j                  dd	      }n^t        |j                  dd            }t        d
t        |      d      D ]  }||dz      |||dz    c||<   ||dz   |dz    ! t        |      }t        j                  j                  t        |      ||j                   |j"                  t        j                  j%                  ||j                               S )Nr   RGB   r   RGBaRGBArV   rawBGRar   rW   rX   )modecopyputalphar   convertr5   r[   r\   tobytesrZ   r]   r^   r`   r3   r4   create_for_datar7   r8   format_stride_for_width)	clsimrO   alpha
forceAlphar   argbra   rb   s	            r   	__fromPILzGState.__fromPIL   s   wwWWYH};KKECK()axDrzz&'9"6\ZC,-"**V,R6\ZZZ'C,-bjj0s#==("E&)B2::eF34B1SWQ' 6$&qsGBq1I!1b1QqSk6rB!!11)B-RXXryy""::3rxxH 	r   c	                    | j                   }	|	j                          |	j                  t        j                         |	j                  t        j                         |	j                  |||z          |	j                  |t        |      z  | t        |      z         |	j                  | j                  || j                  d             |	j                          |	j                          y )NF)r   )r   saver<   r3   ANTIALIAS_DEFAULTset_operatorOPERATOR_OVER	translatescaler   set_source_surface_GState__fromPILr2   paintrestore)
r'   r   r    dstWdstHdatasrcWsrcHplanesr   s
             r   	_aapixbufzGState._aapixbuf  s     hh
%112,,-a$		$uT{"D5t#45t~~d499~OP		r   )r   r   whiter
   r   )r
   g      ?F)rX   )"__name__
__module____qualname__r   rP   staticmethodr5   propertyrc   r@   setterrA   rq   ru   r{   r   r   r   r   r.   r/   r   rC   r   r0   rD   r   r   r   r   r   classmethodr   r   r}   r   r   r   r      s   1 f , ,    G G 	ZZ1 1     > > " " @ @ ) ) * * # # / / , , ^^- - - - __. . F F __G G--K'
Z!! *  > ./r   r   )__all__r[   	cairocffir3   r*   reportlab.lib.colorsr   reportlab.graphics.transformr   PILr   PILImageobjectr   r}   r   r   <module>r      sF   
  ) . !DV D  s   * 	66