
    i92i                    j   % S r SSKrSSKrSSKJr  SSKJr  SSKJr  SSK	J
r
  SSKJrJrJrJrJrJrJr  SSKJrJrJrJrJrJrJrJrJrJrJr  S	S
KJ r J!r!J"r"J#r#J$r$J%r%J&r&J'r'J(r(J)r)J*r*  S	SK+J,r,J-r-J.r.J/r/J0r0J1r1J2r2  S	SK3J4r4J5r5  S	SK6J7r7  SSK8J9r9  \(       a  S	SK:J;r;  S r< " S S5      r= " S S\=5      r> " S S\5      r? " S S5      r@\ " S S\5      5       rAS\S\B4S jrCS\S\B4S jrDS\S \S!\S\B4S" jrE " S# S$\5      rF " S% S&\5      rG " S' S(\5      rH " S) S*\5      rI " S+ S,\5      rJ " S- S.\5      rK " S/ S0\5      rL " S1 S2\5      rMS3\NS4\NS5\NS6\NS7\NS\N4S8 jrO SS4\NS5\NS6\NS7\NS9\NS\P\N   4S: jjrQ " S; S<\5      rR " S= S>\5      rS " S? S@\5      rT " SA SB\5      rU " SC SD\5      rV " SE SF\5      rW " SG SH\5      rX " SI SJ\5      rY " SK SL\5      rZ " SM SN\5      r[ " SO SP\5      r\ " SQ SR\5      r] " SS ST\5      r^\(       Ga  \F" \" SS5      SU9r_\A\`SV'   \G" \" SS5      SU9ra\A\`SW'   \H" \" SS5      SU9rb\A\`SX'   \I" \" SS5      SU9rc\A\`SY'   \J" SSZ9rd\A\`S['   \K" SSZ9re\A\`S\'   \L" SS]9rf\A\`S^'   \M" SS]9rg\A\`S_'   \R" \" SS5      \" SS5      \" SS5      S`9rh\A\`Sa'   \S" \" SS5      \" SS5      \" SS5      S`9ri\A\`Sb'   \T" \" SS5      \" SS5      Sc9rj\A\`Sd'   \U" \" SS5      \" SS5      Sc9rk\A\`Se'   \V" \" SS5      SSfSf\" SS5      Sg9rl\A\`Sh'   \W" \" SS5      SSfSf\" SS5      Sg9rm\A\`Si'   \X" \" SS5      \" SS5      Sj9rn\A\`Sk'   \Y" \" SS5      \" SS5      \" SS5      Sl9ro\A\`Sm'   \Z" \" SS5      \" SS5      Sn9rp\A\`So'   \\" SS\[" SpSqSpSrSs94St9rq\A\`Su'   \]" 5       rr\A\`Sv'   \^" 5       rs\A\`Sw'    " Sx Sy5      rt " Sz S{5      ru " S| S}\u5      rv " S~ S5      rw " S S5      rxS ryS\\u\w4   SS4S jrzS r{ " S S5      r| " S S5      r} " S S5      r~ " S S\95      r " S S\5      rg)aQ  
Vector drawing: managing colors, graphics states, paths, transforms...

The contents of this module are internal to fpdf2, and not part of the public API.
They may change at any time without prior warning or any deprecation period,
in non-backward-compatible ways.

Usage documentation at: <https://py-pdf.github.io/fpdf2/Drawing.html>
    N)OrderedDict)contextmanager)deepcopy)	dataclass)TYPE_CHECKING	Generator
NamedTupleOptionalProtocolUnionruntime_checkable)
DeviceCMYK
DeviceGray	DeviceRGBNumberNumberClassPoint	Transformcheck_rangecolor_from_hex_stringforce_nodocumentnumber_to_str   )	BlendModeClippingPathIntersectionRuleCompositingOperationGradientSpreadMethodGradientUnitsIntersectionRulePathPaintRulePDFResourceTypePDFStyleKeysStrokeCapStyleStrokeJoinStyle)GradientPatternLinearGradientRadialGradientSweepGradientshape_linear_gradientshape_radial_gradient)NameRaw)escape_parens)BasePen)ResourceCatalogc                    [        U [        5      (       a  U $ [        [        U SS5      5      (       a  U R	                  5       nGOpU c  SnGOi[        U [
        5      (       a  S[        U 5       S3nGOC[        U [        5      (       a  SU R                  5        S3nGO[        U [        5      (       a  SS	/U    nO[        U [        5      (       a  [        U 5      nO[        U [        [        45      (       a  S
SR                  S U  5       5      -   S-   nO[        U [        5      (       a|  / nU R!                  5        HN  u  p4[        U["        5      (       d  [%        S5      eUR'                  [)        U5      S-   [)        U5      -   5        MP     SSR                  U5      -   S-   nO[+        SU < 35      e[        U5      $ )a  
Render a Python value as a PDF primitive type.

Container types (tuples/lists and dicts) are rendered recursively. This supports
values of the type Name, str, bytes, numbers, booleans, list/tuple, and dict.

Any custom type can be passed in as long as it provides a `serialize` method that
takes no arguments and returns a string. The primitive object is returned directly
if it is an instance of the `Raw` class. Otherwise, The existence of the `serialize`
method is checked before any other type checking is performed, so, for example, a
`dict` subclass with a `serialize` method would be converted using its `pdf_repr`
method rather than the built-in `dict` conversion process.

Args:
    primitive: the primitive value to convert to its PDF representation.

Returns:
    Raw-wrapped str of the PDF representation.

Raises:
    ValueError: if a dictionary key is not a Name.
    TypeError: if `primitive` does not have a known conversion to a PDF
        representation.
	serializeNnull()<>falsetrue[ c              3   8   #    U  H  n[        U5      v   M     g 7fN)render_pdf_primitive).0vals     F/home/james-whalen/.local/lib/python3.13/site-packages/fpdf/drawing.py	<genexpr>'render_pdf_primitive.<locals>.<genexpr>s   s     OYc 4S 9 9Ys   ]zdict keys must be Namesz<< 
z >>z,cannot produce PDF representation for value )
isinstancer-   callablegetattrr2   strr.   byteshexboolr   r   listtuplejoindictitemsr,   
ValueErrorappendr>   	TypeError)	primitiveoutput	item_listkeyr@   s        rA   r>   r>   I   s   4 )S!!	;566$$&			Is	#	#]9-.a0	Iu	%	%Y]]_%Q'	It	$	$6"9-	I{	+	+y)	Ie}	-	-sxxOYOOORUU	It	$	$	!)HCc4(( !:;;$S)C/2Fs2KK	 * 9--5FymTUUv;    c                   
   \ rS rSrSrSr\R                  SSS4SSS\\\	4   S	\
S
   S\S\
\\	\4      4
S jjrS\
S   SS
4S jrSS
S\	4S jrS\
S   S\	4S jrS\
S   S\	4S jrS\4S jrSS
SSS\	4S jrSSS\4S jrSrg)GradientPaint   z"Fill/stroke paint using a gradient)gradientunitsgradient_transformapply_page_ctm
skip_alphaspread_methodNTr]   r%   r^   r_   r   r`   rb   c                    Xl         [        R                  " U5      U l        U=(       d    [        R
                  " 5       U l        X@l        SU l        Ub  [        R                  " U5      U l        g [        R                  U l        g NF)r]   r   coercer^   r   identityr_   r`   ra   r   PADrb   )selfr]   r^   r_   r`   rb   s         rA   __init__GradientPaint.__init__   sq     !"))%0
"4"L	8J8J8L, ( !''6 	 &)) 	rY   bboxBoundingBoxreturnc           	          U R                   [        R                  :X  aS  Uc  [        S5      e[	        UR
                  SSUR                  UR                  UR                  S9nU R                  U-  $ U R                  $ )zCReturn the final /Matrix for this gradient, given an optional bbox.z7GradientPaint requires bbox for objectBoundingBox unitsr   )abcdef)
r^   r   OBJECT_BOUNDING_BOXRuntimeErrorr   widthheightx0y0r_   )rh   rk   matrix_bboxs      rA   _matrix_forGradientPaint._matrix_for   sq    :::::|"M  $**Q$++DGGK **[88&&&rY   matrixc                     UR                  [        R                  US5        [        U5      R	                  U5      nUR                  U R                  5        UR                  [        R                  US5      $ )zVCreate a Pattern with the given matrix, register shading+pattern, return pattern name.N)addr!   SHADINGr&   
set_matrixset_apply_page_ctmr`   PATTERN)rh   resource_catalogr]   r~   patterns        rA   _register_patternGradientPaint._register_pattern   s^    _44hE(#..v6""4#6#67##O$;$;WdKKrY   c                     U R                   [        R                  :X  a  [        SSSS5      OUnU R	                  U5      nU R                  U5      nU R                  XU5      nSU S3$ N              ?z/Pattern cs /z scnr^   r   ru   rl    _get_gradient_with_spread_methodr|   r   rh   r   rk   domain_bboxr]   r~   pattern_names          rA   	emit_fillGradientPaint.emit_fill   r     zz]>>> S#s+ 	
 88E!!$'--.>&Q|nD11rY   c                     U R                   [        R                  :X  a  [        SSSS5      OUnU R	                  U5      nU R                  U5      nU R                  XU5      nSU S3$ Nr   r   z/Pattern CS /z SCNr   r   s          rA   emit_strokeGradientPaint.emit_stroke   r   rY   c                     U R                   =(       a2    U R                   R                  5       =(       a    U R                  (       + $ r=   )r]   	has_alphara   rh   s    rA   r   GradientPaint.has_alpha   s*    }}R!8!8!:R4???RRrY   c                 .   U R                   R                  U5      nUc  [        S5      eUR                  [        R
                  US 5        [        U5      R                  U5      nUR                  S5        UR                  [        R                  US 5      $ )Nz0Alpha gradient requested but no alpha ramp foundF)
r]   get_alpha_shading_objectrv   r   r!   r   r&   r   r   r   )rh   r   r~   rk   alpha_shadingalpha_patterns         rA   _register_alpha_pattern%GradientPaint._register_alpha_pattern   s     >>tD QRR_44mTJ.99&A((/##O$;$;]DQQrY   c                    [        U R                  [        5      (       a6  U R                  U R                  l        U R                  R	                  U5      $ U R                  [
        R                  :X  a  U R                  $ [        U R                  [        5      (       a  U R                  R                  u  p#pE[        U R                  SS5      nUcV  U R                  R                  nU R                  R                  nSUS   4/[        [        XSS 5      5      -   SUS   4/-   n	OUn	Un
UbU  U R                  [        R                   :X  a7  U R"                  b*   UR%                  U R"                  R'                  5       5      n
[+        UUUUU	U R                  U
S9$ [        U R                  [,        5      (       Ga  U R                  R                  u  ppnn[        U R                  SS5      nUcV  U R                  R                  nU R                  R                  nSUS   4/[        [        XSS 5      5      -   SUS   4/-   n	OUn	Un
UbU  U R                  [        R                   :X  a7  U R"                  b*   UR%                  U R"                  R'                  5       5      n
[/        UUUU	UUUU R                  U
S	9	$ U R                  $ ! [(         a    Un
 GNVf = f! [(         a    Un
 NHf = f)
zu
Now that the bbox is known, we can construct a new gradient stop line to apply
the spread method reflect or repeat.
	raw_stopsNr   r   r   r   )rb   rk   )fxfyfrrb   rk   )rF   r]   r)   rb   get_shading_objectr   rg   r'   coordsrH   colorsboundsrM   zipr^   r   USER_SPACE_ON_USEr_   transformedinverserR   r*   r(   r+   )rh   rk   x1y1x2y2r   r   r   stopsspread_bboxr   r   r   cxcyrs                    rA   r   .GradientPaint._get_gradient_with_spread_method   s    dmm]33*.*<*<DMM'==33D99!5!9!99== dmm^44!]]11NBB{DAI ----6!9%&3va|456VBZ()*  "K JJ-"A"AA++7'"&"2"243J3J3R3R3T"UK )"00   dmm^44&*mm&:&:#RRR{DAI ----6!9%&3va|456VBZ()*  "K JJ-"A"AA++7'"&"2"243J3J3R3R3T"UK )"00 
 
 }}c " '"&K'D " '"&K's$   )K ;)K KKK-,K-)r`   r]   r_   ra   rb   r^   )__name__
__module____qualname____firstlineno____doc__	__slots__r   r   r   rI   r
   rL   r   ri   r|   r   r   r   r   r   r%   r   __static_attributes__ rY   rA   r[   r[      s   ,I ,9+J+J48#DH

 ]C'(
 %[1	

 
  c+?&? @A
&' 7 'K 'LK LTW L	20G 	2C 	2	2(=2I 	2c 	2S4 S
R(3
R;H
R	
RT] Tx TrY   r[   c                   F    \ rS rSrSSS\4S jrSSS\4S jrS\4S jrSr	g	)
_AlphaGradientPainti6  rk   rl   rm   c                     U R                   [        R                  :X  a  [        SSSS5      OUnU R	                  U5      nU R                  XU5      nSU S3$ r   r^   r   ru   rl   r|   r   rh   r   rk   r   r~   r   s         rA   r   _AlphaGradientPaint.emit_fill8  f     zz]>>> S#s+ 	
 !!$'33k
 |nD11rY   c                     U R                   [        R                  :X  a  [        SSSS5      OUnU R	                  U5      nU R                  XU5      nSU S3$ r   r   r   s         rA   r   _AlphaGradientPaint.emit_strokeD  r   rY   c                     grd   r   r   s    rA   r   _AlphaGradientPaint.has_alphaP  s    rY   r   N)
r   r   r   r   rI   r   r   rL   r   r   r   rY   rA   r   r   6  s4    
2 
2# 
2
2- 
2C 
24 rY   r   c                      \ rS rSr% Sr\\S'   \\S'   \\S'   \\S'   \S'S j5       rS\	4S	 jr
\S
\\   SS 4S j5       rS(S jrS\SS 4S jrS)S\S\\   SS 4S jjr S*SSS\\\4   SS 4S jjrS\\\\\4   4S jrS\4S jrS\\\\4   \\\4   \\\4   \\\4   4   4S jrS\S\S\S\S\\\\4   4
S jrS\S\S\4S  jr\S\4S! j5       r\S\4S" j5       rS\4S# jrS\S\	4S$ jr S\!4S% jr"S&r#g)+rl   iT  zSRepresents a bounding box, with utility methods for creating and manipulating them.ry   rz   r   r   rm   c                 `    U " [        S5      [        S5      [        S5      [        S5      5      $ )zL
Return an 'empty' bounding box with extreme values that collapse on merge.
inf-inf)float)clss    rA   emptyBoundingBox.empty\  s%    
 5<uuV}eFmLLrY   c                 t    U R                   U R                  :*  =(       a    U R                  U R                  :*  $ )z-Return True if the bounding box is not empty.)ry   r   rz   r   r   s    rA   is_validBoundingBox.is_validc  s'    ww$''!8dgg&88rY   pointsc                    U Vs/ s H  n[        UR                  5      PM     nnU Vs/ s H  n[        UR                  5      PM     nnU " [        U5      [        U5      [	        U5      [	        U5      5      $ s  snf s  snf )zEGiven a list of points, create a bounding box that encloses them all.)r   xyminmax)r   r   pxsyss        rA   from_pointsBoundingBox.from_pointsg  se     #))&QeACCj&)"()&QeACCj&)3r7CGSWc"g66 *)s
   A:A?otherc           	      j   U R                  5       (       d  U$ UR                  5       (       d  U $ [        [        U R                  UR                  5      [        U R                  UR                  5      [        U R                  UR                  5      [        U R                  UR                  5      5      $ )z0Expand this bounding box to include another one.)r   rl   r   ry   rz   r   r   r   )rh   r   s     rA   mergeBoundingBox.mergen  sy    }}L~~K""""	
 	
rY   tfc                 Z   [        U R                  U R                  5      [        U R                  U R                  5      [        U R                  U R                  5      [        U R                  U R                  5      /nU Vs/ s H  o3U-  PM	     nn[
        R                  U5      $ s  snf )zL
Return a new bounding box resulting from applying a transform to this one.
)r   ry   rz   r   r   rl   r   )rh   r   cornerspttransformed_pointss        rA   r   BoundingBox.transformed{  s    
 $''477#$''477#$''477#$''477#	
 188"2g8&&'9:: 9s   B(Ndxdyc                     Uc  Un[        U R                  U-
  U R                  U-
  U R                  U-   U R                  U-   5      $ )zJReturn a new bounding box expanded by the given amounts in each direction.)rl   ry   rz   r   r   rh   r   r   s      rA   expandedBoundingBox.expanded  s=    :B477R<2tww|TWWr\RRrY   styleGraphicsStyle	row_normsc                    UR                  5       [        R                  [        R                  [        R                  4;  a  U $ [        US[        R                  5      nU[        R                  La  Ub   [        U5      S::  a  U $  UR                  b  UR                  [        R                  L a  SOUR                  n[        U5      nUS:X  a  U $ SU-  nUu  pgU R                  XV-  XW-  5      $ ! [        [        4 a     N|f = f)zDExpand this bbox to include stroke coverage, given a graphics style.stroke_opacityr   r         ?)resolve_paint_ruler    STROKESTROKE_FILL_NONZEROSTROKE_FILL_EVENODDrH   r   INHERITr   rT   rR   stroke_widthr   )rh   r   r   sowr   nxnys           rA   expanded_to_strokeBoundingBox.expanded_to_stroke  s    '')  ----.
 

 K U,m.C.CDm+++".9#K $ !!)U-?-?=CXCX-X ## 	

 !H8K!G }}QVQV,,! z* s   6C2 2DDc                 ^    U R                   U R                  U R                  U R                  4$ )z"Convert bounding box to a 4-tuple.ry   rz   r   r   r   s    rA   to_tupleBoundingBox.to_tuple  s!    $''47733rY   c           
          S[        U R                  5       S[        U R                  5       S[        U R                  5       S[        U R                  5       S3	$ )z+Convert bounding box to a PDF array string.r:   r;   rD   )r   ry   rz   r   r   r   s    rA   to_pdf_arrayBoundingBox.to_pdf_array  sT    =)*!M$'',B+C1]SWSZSZE[D\\]^klplsls^t]uuvwwrY   c                     U R                   U R                  4U R                  U R                  4U R                  U R                  4U R                   U R                  44$ )z9Clockwise corners (x,y): (x0,y0),(x1,y0),(x1,y1),(x0,y1).r  r   s    rA   r   BoundingBox.corners  sN     WWdggWWdggWWdggWWdgg	
 	
rY   r   r   c                     X1-
  XB-
  pe[         R                  " XV5      nUS:X  a  gXW-  Xg-  p/ n
U R                  5        H$  u  pX-
  X-
  pU
R                  X-  X-  -   5        M&     [	        U
5      [        U
5      U4$ )z
Project bbox corners onto the axis from (x1,y1) to (x2,y2).
Returns (tmin, tmax, L) where:
  - L is the axis length
  - t are distances along the axis with t=0 at (x1,y1)
r   )r   r   r   )mathhypotr   rS   r   r   )rh   r   r   r   r   vxvyLuxuytsXYr   r   s                  rA   project_interval_on_axis$BoundingBox.project_interval_on_axis  s     'RWBJJr8 BLLNDAfIIbg'( # 2wB""rY   r   r   c                 N   ^^ [        UU4S jU R                  5        5       5      $ )z7Max Euclidean distance from (cx,cy) to any bbox corner.c              3   b   >#    U  H$  u  p[         R                  " UT-
  UT-
  5      v   M&     g 7fr=   )r  r  )r?   r  r  r   r   s      rA   rB   4BoundingBox.max_distance_to_point.<locals>.<genexpr>  s)     KN&14::a"fa"f--Ns   ,/)r   r   )rh   r   r   s    ``rA   max_distance_to_point!BoundingBox.max_distance_to_point  s    KDLLNKKKrY   c                 4    U R                   U R                  -
  $ )z%Return the width of the bounding box.)r   ry   r   s    rA   rw   BoundingBox.width       ww  rY   c                 4    U R                   U R                  -
  $ )z&Return the height of the bounding box.)r   rz   r   s    rA   rx   BoundingBox.height  r#  rY   c           	      p    SU R                    SU R                   SU R                   SU R                   S3	$ )NzBoundingBox(z, r5   r  r   s    rA   __str__BoundingBox.__str__  s3    dggYb	DGG9BtwwiqIIrY   c                    [        U[        5      (       d  gSn[        U R                  UR                  -
  5      U:  =(       a}    [        U R                  UR                  -
  5      U:  =(       aQ    [        U R
                  UR
                  -
  5      U:  =(       a%    [        U R                  UR                  -
  5      U:  $ )NFgư>)rF   rl   absry   rz   r   r   )rh   r   	tolerances      rA   __eq__BoundingBox.__eq__  s    %--	%(("#i/ 4DGGehh&')34DGGehh&')34 DGGehh&')3		
rY   c           	          [        [        U R                  S5      [        U R                  S5      [        U R                  S5      [        U R
                  S5      45      $ )N   )hashroundry   rz   r   r   r   s    rA   __hash__BoundingBox.__hash__  sL    dggq!dggq!dggq!dggq!	
 	
rY   r   )rm   rl   )r   rl   rm   rl   r=   ))r   r   )$r   r   r   r   r   r   __annotations__classmethodr   rL   r   rM   r   r   r   r   r   r
   r   rN   r  r  rI   r  r   r  r  propertyrw   rx   r'  objectr,  intr2  r   r   rY   rA   rl   rl   T  s   ]IIIIM M9$ 9 7e 7 7 7
;i ;M ;S5 Shuo S S HR#-$#-16ue|1D#-	#-J4%ueU :; 4xc x
	eUleUleUleUl	

 ##"#(-#38#	ueU"	##(L L5 LU L !u ! ! ! ! !J J	
F 	
t 	
	
# 	
rY   rl   c                   X  ^  \ rS rSrSrSr\\" S \ 5       5      -   rSr	 Sr
 \R                  R                  \R                  R                  \R                  R                  \R                  R                  4r / S \ 5       Q7r \" 0 5      \R(                  \" S15      \R*                  \" S	\R.                  15      \R0                  \" S	\R2                  15      \R4                  \" SS	\R.                  15      \R6                  \" SS	\R2                  15      \R8                  0r \S2S j5       rS r S r!U 4S jr"\#S 5       r$\$RJ                  U 4S j5       r$\#S 5       r&\&RJ                  U 4S j5       r&\#S 5       r'\'RJ                  U 4S j5       r'\#S 5       r(\(RJ                  U 4S j5       r(\#S 5       r)\)RJ                  U 4S j5       r)\#S 5       r*\*RJ                  U 4S j5       r*\#S 5       r+\+RJ                  U 4S j5       r+\#S 5       r,\,RJ                  U 4S j5       r,\#S 5       r-\-RJ                  U 4S  j5       r-\#S! 5       r.\.RJ                  U 4S" j5       r.\#S# 5       r/\/RJ                  U 4S$ j5       r/\#S% 5       r0\0RJ                  U 4S& j5       r0\#S' 5       r1\1RJ                  U 4S( j5       r1\#S) 5       r2\2RJ                  U 4S* j5       r2\#S+ 5       r3\3RJ                  U 4S, j5       r3\#S- 5       r4\4RJ                  U 4S. j5       r4S
\5\6   4S/ jr7\8S
\4S0 j5       r9S1r:U =r;$ )3r   i  a  
A class representing various style attributes that determine drawing appearance.

This class uses the convention that the global Python singleton ellipsis (`...`) is
exclusively used to represent values that are inherited from the parent style. This
is to disambiguate the value None which is used for several values to signal an
explicitly disabled style. An example of this is the fill/stroke color styles,
which use None as hints to the auto paint style detection code.
)_allow_transparency_auto_close_fill_color_intersection_rule_paint_rule_stroke_color_stroke_dash_pattern_stroke_dash_phasec              #   d   #    U  H&  nU[         R                  Ld  M  UR                  v   M(     g 7fr=   r"   STROKE_DASH_PATTERNvaluer?   ks     rA   rB   GraphicsStyle.<genexpr>  s+      'AL444 	s   00.)
paint_ruleallow_transparency
auto_closeintersection_rule
fill_colorfill_opacitystroke_colorr   
blend_moder   stroke_cap_stylestroke_join_stylestroke_miter_limitstroke_dash_patternstroke_dash_phase	soft_maskc              #   b   #    U  H%  o[         R                  Ld  M  UR                  v   M'     g 7fr=   rC  rF  s     rA   rB   rH  F  s!     	U<aL4T4T+T'!''<s   //strokefillrm   c           	          U " 5       nU R                    H?  n[        X$5      nXPR                  L a  [        X4[        X5      5        M3  [        X4U5        MA     U$ )a  
Merge parent and child into a single GraphicsStyle.

The result contains the properties of the parent as overridden by any properties
explicitly set on the child. If both the parent and the child specify to
inherit a given property, that property will preserve the inherit value.
)MERGE_PROPERTIESrH   r   setattr)r   parentchildnewpropcvals         rA   r   GraphicsStyle.mergeX  sO     e((D5'D{{"76#894( ) 
rY   c                 $   U R                   U l        U R                   U l        U R                   U l        U R                   U l        U R                   U l        U R                   U l        U R                   U l        U R                   U l        U R                   U l	        U R                   U l
        U R                   U l        U R                   U l        U R                   U l        U R                   U l        U R                   U l        U R                   U l        g r=   )r   rJ  rI  rK  rL  rM  rN  rO  r   rP  r   rQ  rR  rS  rT  rU  rV  r   s    rA   ri   GraphicsStyle.__init__k  s    "&,,,,,,!%,, LL LL"ll,, LL $!%"&,,#'<< !%rY   c           
      4   U R                   nUR                  U5      nUR                   H-  n[        R	                  X4[        XUR                  5      5        M/     UR                   H-  n[        R	                  X5[        XUR                  5      5        M/     U$ r=   )	__class____new___PRIVATE_SLOTSr7  __setattr__rH   r   PDF_STYLE_KEYS)rh   memor   r_  srX   s         rA   __deepcopy__GraphicsStyle.__deepcopy__}  sv    nnkk###Aswt'DE $ %%CsCKK)HI &
rY   c                    > [        U R                  U5      (       d  [        U R                   SU S35      e[        TU ]  X5        g )Nz does not have style "z" (a typo?))hasattrrf  AttributeErrorsuperri  )rh   namerE  rf  s      rA   ri  GraphicsStyle.__setattr__  sF    t~~t,, >>""8kJ  	D(rY   c                     U R                   $ r=   )r:  r   s    rA   rJ   GraphicsStyle.allow_transparency  s    '''rY   c                 $   > [         TU ]  SU5      $ )Nr:  )rr  ri  rh   r_  rf  s     rA   rJ  rv    s    w"#8#>>rY   c                     U R                   $ )z*The paint rule to use for this path/group.)r>  r   s    rA   rI  GraphicsStyle.paint_rule       rY   c                    > Uc  [         TU ]  S[        R                  5        g XR                  L a  [         TU ]  SU5        g [         TU ]  S[        R
                  " U5      5        g )Nr>  )rr  ri  r    
DONT_PAINTr   re   rx  s     rA   rI  rz    sP    ;G}/G/GHLL Gs3G}/C/CC/HIrY   c                     U R                   $ )zEIf True, unclosed paths will be automatically closed before stroking.)r;  r   s    rA   rK  GraphicsStyle.auto_close  r{  rY   c                 h   > USSU R                   1;  a  [        SU 35      e[        TU ]  SU5        g )NTFz/auto_close must be a bool or self.INHERIT, not r;  )r   rT   rr  ri  rx  s     rA   rK  r    s8    tUDLL11McUSTTM3/rY   c                     U R                   $ )z2The desired intersection rule for this path/group.)r=  r   s    rA   rL  GraphicsStyle.intersection_rule       &&&rY   c                    > XR                   L a  [        TU ]	  SU5        g [        TU ]	  S[        R                  " U5      5        g )Nr=  )r   rr  ri  r   re   rx  s     rA   rL  r    s;     ,,G 4c:G 46F6M6Mc6RSrY   c                     U R                   $ )z
The desired fill color for this path/group.

When setting this property, if the color specifies an opacity value, that will
be used to set the fill_opacity property as well.
)r<  r   s    rA   rM  GraphicsStyle.fill_color  s     rY   c                 P  > [        U[        5      (       a  [        U5      n[        U[        [        [
        [        45      (       a1  [        TU ]!  SU5        [        USS 5      b  UR                  U l        g g Ub  XR                  L a  [        TU ]!  SU5        g [        U S35      e)Nr<  ro   " doesn't look like a drawing color)rF   rI   r   r   r   r   r[   rr  ri  rH   ro   rN  r   rT   rh   colorrf  s     rA   rM  r    s    eS!!)%0EeiZOPPGu5uc4(4$)GG! 5 m,,!6Gu5 ug%GHIIrY   c                 J    [        U [        R                  R                  5      $ )z-The desired fill opacity for this path/group.)rH   r"   
FILL_ALPHArE  r   s    rA   rN  GraphicsStyle.fill_opacity       t\44::;;rY   c                    > US U R                   1;  a  [        U5        [        TU ]  [        R
                  R                  U5        g r=   )r   r   rr  ri  r"   r  rE  rx  s     rA   rN  r    s7    tT\\**L33993?rY   c                     U R                   $ )z
The desired stroke color for this path/group.

When setting this property, if the color specifies an opacity value, that will
be used to set the fill_opacity property as well.
)r?  r   s    rA   rO  GraphicsStyle.stroke_color  s     !!!rY   c                   > [        U[        5      (       a  [        U5      n[        U[        [        [
        [        45      (       aQ  [        TU ]!  SU5        [        USS 5      b  UR                  U l        U R                  U R                  L a  SU l        g g Ub  XR                  L a  [        TU ]!  SU5        g [        U S35      e)Nr?  ro   r   r  )rF   rI   r   r   r   r   r[   rr  ri  rH   ro   r   r   r   rT   r  s     rA   rO  r    s    eS!!)%0EeiZOPPG7uc4(4&+gg#  DLL0$%! 1 m,,!6G7 ug%GHIIrY   c                 J    [        U [        R                  R                  5      $ )z/The desired stroke opacity for this path/group.)rH   r"   STROKE_ALPHArE  r   s    rA   r   GraphicsStyle.stroke_opacity       t\66<<==rY   c                    > US U R                   1;  a  [        U5        [        TU ]  [        R
                  R                  U5        g r=   )r   r   rr  ri  r"   r  rE  rx  s     rA   r   r    s7    tT\\**L55;;SArY   c                 J    [        U [        R                  R                  5      $ )z+The desired blend mode for this path/group.)rH   r"   
BLEND_MODErE  r   s    rA   rP  GraphicsStyle.blend_mode  r  rY   c                    > XR                   L a)  [        TU ]	  [        R                  R
                  U5        g [        TU ]	  [        R                  R
                  [        R                  " U5      R
                  5        g r=   )r   rr  ri  r"   r  rE  r   re   rh   rE  rf  s     rA   rP  r    sW    LL G 7 7 = =uEG''--y/?/?/F/L/LrY   c                 J    [        U [        R                  R                  5      $ )z-The desired stroke width for this path/group.)rH   r"   STROKE_WIDTHrE  r   s    rA   r   GraphicsStyle.stroke_width   r  rY   c           
        > [        U[        [        [        R                  [        S 5      [        U R                  5      45      (       d  [        S[        U5       35      e[        TU ]%  [        R                  R                  U5        g )Nz#stroke_width must be a number, not )rF   r8  r   decimalDecimaltyper   rT   rr  ri  r"   r  rE  )rh   rw   rf  s     rA   r   r  %  sf    %$t*d4<<6HI
 
 A$u+OPPL55;;UCrY   c                 J    [        U [        R                  R                  5      $ )z1The desired stroke cap style for this path/group.)rH   r"   STROKE_CAP_STYLErE  r   s    rA   rQ  GraphicsStyle.stroke_cap_style/  s     t\::@@AArY   c                    > XR                   L a)  [        TU ]	  [        R                  R
                  U5        g [        TU ]	  [        R                  R
                  [        R                  " U5      5        g r=   )r   rr  ri  r"   r  rE  r#   re   r  s     rA   rQ  r  4  sQ    LL G = = C CUKG--33^5J5J55QrY   c                 J    [        U [        R                  R                  5      $ )z2The desired stroke join style for this path/group.)rH   r"   STROKE_JOIN_STYLErE  r   s    rA   rR  GraphicsStyle.stroke_join_style=  s     t\;;AABBrY   c                    > XR                   L a)  [        TU ]	  [        R                  R
                  U5        g [        TU ]	  [        R                  R
                  [        R                  " U5      5        g r=   )r   rr  ri  r"   r  rE  r$   re   r  s     rA   rR  r  B  sR    LL G > > D DeLG..44&&u-rY   c                 J    [        U [        R                  R                  5      $ )z3The desired stroke miter limit for this path/group.)rH   r"   STROKE_MITER_LIMITrE  r   s    rA   rS   GraphicsStyle.stroke_miter_limitL  s     t\<<BBCCrY   c                    > XR                   L d  [        U[        5      (       a)  [        TU ]  [
        R                  R                  U5        g [        U S35      e)Nz is not a number)	r   rF   r   rr  ri  r"   r  rE  rT   r  s     rA   rS  r  Q  sG    \\!j&D&DG ? ? E EuMug%5677rY   c                     U R                   $ )z4The desired stroke dash pattern for this path/group.)r@  r   s    rA   rT  !GraphicsStyle.stroke_dash_patternX  s     (((rY   c                 N  > Uc  SnOpXR                   L a  UnO_[        U[        5      (       a  U4nOF / nU H8  n[        U[        5      (       d  [        SU S35      eUR	                  U5        M:     / UQ7n[
        TU ]  SU5        g ! [         a    [        SU S35      S ef = f)Nr   zstroke_dash_pattern z sequence has non-numeric valuez( must be a number or sequence of numbersr@  )r   rF   r   rT   rS   rr  ri  )rh   rE  resultaccumitemrf  s        rA   rT  r  ]  s    =Fll"F{++XF!D%dK88'25'9XY  LL& " uYF2F;  *5'1YZs   A B	 	B$c                     U R                   $ )zAThe desired stroke dash pattern phase offset for this path/group.)rA  r   s    rA   rU  GraphicsStyle.stroke_dash_phasev  r  rY   c                    > XR                   L d  [        U[        5      (       a  [        TU ]  SU5      $ [        U S35      e)NrA  z( isn't a number or GraphicsStyle.INHERIT)r   rF   r   rr  ri  rT   r  s     rA   rU  r  {  s?    LL Juk$B$B7&';UCC5'!IJKKrY   c                 J    [        U [        R                  R                  5      $ r=   )rH   r"   	SOFT_MASKrE  r   s    rA   rV  GraphicsStyle.soft_mask  s    t\3399::rY   c                    > XR                   L d  [        U[        5      (       a(  [        TU ]  [
        R                  R                  U5      $ [        U S35      e)Nz/ isn't a PaintSoftMask or GraphicsStyle.INHERIT)	r   rF   PaintSoftMaskrr  ri  r"   r  rE  rT   r  s     rA   rV  r    sJ    LL Jum$D$D7&|'='='C'CUKK5'!PQRRrY   c                     [        5       nU R                   H2  n[        XU R                  5      nX0R                  Ld  M)  Uc  M.  X1U'   M4     U R                  (       aL  U R                  U R                  La3  U R                  U R
                  /U[        R                  R                  '   U R                  SL a  U R                   H  nX!;   d  M
  X	 M     U(       a3  [        S5      n[        S5      X'   UR                  USS9  [        U5      $ g)z{
Convert this style object to a PDF dictionary with appropriate style keys.

Only explicitly specified values are emitted.
NFType	ExtGState)last)r   rj  rH   r   rT  rU  r"   rD  rE  rJ  TRANSPARENCY_KEYSr,   move_to_endr>   )rh   r  rX   rE  	type_names        rA   r2   GraphicsStyle.serialize  s     &&CDt||4E\\)0A $s ' ##(@(@(T((&&>F<3399:
 ""e+--= .  VI $[ 1Fyu5'// rY   c                     U R                   [        R                  L a  [        5       nU R                  b  U R
                  b  UR                  S5        U R                  b;  UR                  S5        U R                  c   eUR                  U R                  5         U R                  [        U5         nU$ U R                   U R                  L a  [        R                  nU$ U R                   nU$ ! [         a    [        R                  n U$ f = f)zt
Resolve `PathPaintRule.AUTO` to a real paint rule based on this style.

Returns:
    the resolved `PathPaintRule`.
rX  rY  )rI  r    AUTOsetr   rO  r   rM  rL  _PAINT_RULE_LOOKUP	frozensetKeyErrorr   r   )rh   wantrules      rA   r    GraphicsStyle.resolve_paint_rule  s     ??m0005D  ,1B1B1N"*  --999//09..y?  __, !44D
  ??D  9 %88 9s   C/ /DD)rJ  rK  rP  rM  rN  rL  rI  rV  rQ  rO  rT  rU  rR  rS  r   r   )r]  r   r^  r   rm   r   )<r   r   r   r   r   rh  rN   r"   r   r   r[  r  rE  r  r  r  r  rj  r  r    r}  r   r   NONZEROFILL_NONZEROEVENODDFILL_EVENODDr   r   r  r5  r   ri   rm  ri  r6  rJ  setterrI  rK  rL  rM  rN  rO  r   rP  r   rQ  rR  rS  rT  rU  rV  r
   r-   r2   r   r   r   __classcell__rf  s   @rA   r   r     s   	N  '' " I G]$ V 	%%!!''%%$$	 S	U<	UN U 	"}//8*}336+3345}7Q7Q6+3345}7Q7Qv/778	
,,v/778	
,, : $&$	) ( ( ? ?     J J     0 0 ' ' T T     J J < < @ @ " " J J" > > B B < <   > > D D B B   C C   D D 8 8 ) ) <  <0 ' ' L L ; ; S S
(8C= (T "M " "rY   r   c                   ^    \ rS rSrSrSSS\SS S\S\\S \4   4
S	 jr	S
\S\\
\4   4S jrSrg)
Renderablei  zo
Structural type for things that can render themselves into PDF operators
and report a geometric bounding box.
resource_registryr0   r   	last_iteminitial_pointrm   c                     g r=   r   rh   r  r   r  r  s        rA   renderRenderable.render  s     +.rY   startc                     g r=   r   rh   r  s     rA   bounding_boxRenderable.bounding_box  s    srY   r   N)r   r   r   r   r   r   r   rN   rI   r  rl   r  r   r   rY   rA   r  r    sb    
.,. .  	.
 . 
sL%'	(. K%JE+u2D,EJrY   r  r   rm   c                 (    U R                  5        S3$ )Nz mr  r   s    rA   _render_mover        iik]"rY   c                 (    U R                  5        S3$ )Nz lr  r  s    rA   _render_liner    r  rY   ctrl1ctrl2endc                 l    U R                  5        SUR                  5        SUR                  5        S3$ )Nr;   z cr  )r  r  r  s      rA   _render_curver    s/    llnQu||~.a

~R@@rY   c                       \ rS rSr% Sr\\S'    \S\4S j5       rS\	\
\4   4S jr\SSS	\S
\S\S\	\\\4   4
S j5       r\S 5       rSrg)Movei  z
A path move element.

If a path has been created but not yet painted, this will create a new subpath.

See: `PaintedPath.move_to`
r   rm   c                     U R                   $ z#The end point of this path element.r  r   s    rA   	end_pointMove.end_point       wwrY   c                 D    [         R                  5       nX R                  4$ r=   rl   r   r   )rh   r  rk   s      rA   r  Move.bounding_box  s      "WW}rY   r  r0   r   r  r  c                 D    [        U R                  5      X R                  4$ a  
Render this path element to its PDF representation.

Args:
    resource_registry (ResourceCatalog): the owner's graphics state
        dictionary registry.
    style (GraphicsStyle): the current resolved graphics style
    last_item: the previous path element.
    initial_point: last position set by a "M" or "m" command

Returns:
    a tuple of `(str, new_last_item)`, where `new_last_item` is `self`
)r  r   r  s        rA   r  Move.render  s    * DGG$dGG33rY   c                 n    U R                  XX45      u  pxnUR                  [        U 5      S-   5        XxU4$ )a  
Render this path element to its PDF representation and produce debug
information.

Args:
    resource_registry (ResourceCatalog): the owner's graphics state
        dictionary registry.
    style (GraphicsStyle): the current resolved graphics style
    last_item: the previous path element.
    initial_point: last position set by a "M" or "m" command
    debug_stream (io.TextIO): the stream to which the debug output should be
        written. This is not guaranteed to be seekable (e.g. it may be stdout or
        stderr).
    pfx (str): the current debug output prefix string (only needed if emitting
        more than one line).

Returns:
    The same tuple as `Move.render`.
rE   r  writerI   	rh   r  r   r  r  debug_streampfxrenderedresolveds	            rA   render_debugMove.render_debug(  s@    . -1KKi-
)M 	3t9t+,=00rY   r   Nr   r   r   r   r   r   r4  r6  r  rN   rl   r  r   r   r  rI   r  r  r   r   rY   rA   r  r    s     	I%5  
U;+=%>  4,4 4 	4
 4 
sJ%	&4 4. 1 1rY   r  c                       \ rS rSr% Sr\\S'    S\S\\\4   4S jr	\
SSS	\S
\S\S\\\\4   4
S j5       r\
S 5       rSrg)RelativeMoveiG  z
A path move element with an end point relative to the end of the previous path
element.

If a path has been created but not yet painted, this will create a new subpath.

See: `PaintedPath.move_relative`
r   r  rm   c                 F    [         R                  5       XR                  -   4$ )z>RelativeMove doesn't draw anything, so it has no bounding box.r  r  s     rA   r  RelativeMove.bounding_boxT  s      "EGGO33rY   r  r0   r   r  r  c                 b    UR                   U R                  -   n[        U5      [        U5      U4$ )a  
Render this path element to its PDF representation.

Args:
    resource_registry (ResourceCatalog): the owner's graphics state
        dictionary registry.
    style (GraphicsStyle): the current resolved graphics style
    last_item: the previous path element.
    initial_point: last position set by a "M" or "m" command

Returns:
    a tuple of `(str, new_last_item)`, where `new_last_item` is the resolved
    `Move`
)r  r   r  r  rh   r  r   r  r  points         rA   r  RelativeMove.renderX  s.    . ##dgg-E"DK66rY   c                 b    U R                  XX45      u  pxnUR                  U  SU S35        XxU4$ )a  
Render this path element to its PDF representation and produce debug
information.

Args:
    resource_registry (ResourceCatalog): the owner's graphics state
        dictionary registry.
    style (GraphicsStyle): the current resolved graphics style
    last_item: the previous path element.
    initial_point: last position set by a "M" or "m" command
    debug_stream (io.TextIO): the stream to which the debug output should be
        written. This is not guaranteed to be seekable (e.g. it may be stdout or
        stderr).
    pfx (str): the current debug output prefix string (only needed if emitting
        more than one line).

Returns:
    The same tuple as `RelativeMove.render`.
 resolved to rE   r  r  r   s	            rA   r  RelativeMove.render_debugr  D    0 -1KKi-
)M 	dV=
"=>=00rY   r   Nr   r   r   r   r   r   r4  rN   rl   r  r   r   r  rI   r  r  r   r   rY   rA   r	  r	  G  s     	I&4% 4E+u2D,E 4 7,7 7 	7
 7 
sJ%	&7 72 1 1rY   r	  c                       \ rS rSr% Sr\\S'    \S\4S j5       rS\S\	\
\4   4S jr\SS	S
\S\S\S\	\\\4   4
S j5       r\S 5       rSrg)Linei  z
A path line element.

This draws a straight line from the end point of the previous path element to the
point specified by `pt`.

See: `PaintedPath.line_to`
r   rm   c                     U R                   $ r  r  r   s    rA   r  Line.end_point  r  rY   r  c                 Z    [         R                  XR                  /5      U R                  4$ )zICompute the bounding box of a line from the start point to the end point.rl   r   r   r  s     rA   r  Line.bounding_box  s#    &&ww'78$''AArY   r  r0   r   r  r  c                 0    [        U R                  5      X4$ r  )r  r   r  s        rA   r  Line.render  s    , DGG$d99rY   c                 n    U R                  XX45      u  pxnUR                  [        U 5      S-   5        XxU4$ )a  
Render this path element to its PDF representation and produce debug
information.

Args:
    resource_registry (ResourceCatalog): the owner's graphics state
        dictionary registry.
    style (GraphicsStyle): the current resolved graphics style
    last_item: the previous path element.
    initial_point: last position set by a "M" or "m" command
    debug_stream (io.TextIO): the stream to which the debug output should be
        written. This is not guaranteed to be seekable (e.g. it may be stdout or
        stderr).
    pfx (str): the current debug output prefix string (only needed if emitting
        more than one line).

Returns:
    The same tuple as `Line.render`.
rE   r  r   s	            rA   r  Line.render_debug  @    0 -1KKi-
)M 	3t9t+,=00rY   r   Nr  r   rY   rA   r  r    s     	I/5  B% BE+u2D,E B :,: : 	:
 : 
sJ%	&: :. 1 1rY   r  c                       \ rS rSr% Sr\\S'    S\S\\\4   4S jr	\
SSS	\S
\S\S\\\\4   4
S j5       r\
S 5       rSrg)RelativeLinei  aL  
A path line element with an endpoint relative to the end of the previous element.

This draws a straight line from the end point of the previous path element to the
point specified by `last_item.end_point + pt`. The absolute coordinates of the end
point are resolved during the rendering process.

See: `PaintedPath.line_relative`
r   r  rm   c                 d    [         R                  XU R                  -   /5      XR                  -   4$ )zVCompute the bounding box of a relative line from the start point to the new end point.r  r  s     rA   r  RelativeLine.bounding_box  s)    &&tww'?@%''/QQrY   r  r0   r   r  r  c                 b    UR                   U R                  -   n[        U5      [        U5      U4$ )  
Render this path element to its PDF representation.

Args:
    resource_registry (ResourceCatalog): the owner's graphics state
        dictionary registry.
    style (GraphicsStyle): the current resolved graphics style
    last_item: the previous path element.
    initial_point: last position set by a "M" or "m" command

Returns:
    a tuple of `(str, new_last_item)`, where `new_last_item` is the resolved
    `Line`.
)r  r   r  r  r  s         rA   r  RelativeLine.render  s.    . ##dgg-E"DK>>rY   c                 b    U R                  XX45      u  pxnUR                  U  SU S35        XxU4$ )a  
Render this path element to its PDF representation and produce debug
information.

Args:
    resource_registry (ResourceCatalog): the owner's graphics state
        dictionary registry.
    style (GraphicsStyle): the current resolved graphics style
    last_item: the previous path element.
    initial_point: last position set by a "M" or "m" command
    debug_stream (io.TextIO): the stream to which the debug output should be
        written. This is not guaranteed to be seekable (e.g. it may be stdout or
        stderr).
    pfx (str): the current debug output prefix string (only needed if emitting
        more than one line).

Returns:
    The same tuple as `RelativeLine.render`.
r  rE   r  r   s	            rA   r  RelativeLine.render_debug  r  rY   r   Nr  r   rY   rA   r#  r#    s     	IIR% RE+u2D,E R ?,? ? 	?
 ? 
sJ%	&? ?2 1 1rY   r#  c                       \ rS rSr% Sr\\S'    S\S\\	\4   4S jr
\SSS	\S
\S\S\\\\4   4
S j5       r\S 5       rSrg)HorizontalLinei,  zz
A path line element that takes its ordinate from the end of the previous element.

See: `PaintedPath.horizontal_line_to`
r   r  rm   c                     [        [        U R                  5      UR                  5      n[        R                  X/5      U4$ )zPCompute the bounding box of a horizontal line from the start point to the new x.r   r   r   r   rl   r   )rh   r  r  s      rA   r  HorizontalLine.bounding_box6  s2    E$&&M577+&&|4c99rY   r  r0   r   r  r  c                     [        U R                  UR                  R                  S9n[	        U5      [        U5      U4$ r'  r   r   )r   r   r  r   r  r  rh   r  r   r  r  r  s         rA   r  HorizontalLine.render;  s6    . DFFi&9&9&;&;<	I&YFFrY   c                 b    U R                  XX45      u  pxnUR                  U  SU S35        XxU4$ )a  
Render this path element to its PDF representation and produce debug
information.

Args:
    resource_registry (ResourceCatalog): the owner's graphics state
        dictionary registry.
    style (GraphicsStyle): the current resolved graphics style
    last_item: the previous path element.
    initial_point: last position set by a "M" or "m" command
    debug_stream (io.TextIO): the stream to which the debug output should be
        written. This is not guaranteed to be seekable (e.g. it may be stdout or
        stderr).
    pfx (str): the current debug output prefix string (only needed if emitting
        more than one line).

Returns:
    The same tuple as `HorizontalLine.render`.
r  rE   r  r   s	            rA   r  HorizontalLine.render_debugU  r  rY   r   Nr   r   r   r   r   r   r4  r   rN   rl   r  r   r   r  rI   r  r  r   r   rY   rA   r,  r,  ,  s     I::% :E+u2D,E :
 G,G G 	G
 G 
sJ%	&G G2 1 1rY   r,  c                       \ rS rSr% Sr\\S'    S\S\\	\4   4S jr
\SSS	\S
\S\S\\\\4   4
S j5       r\S 5       rSrg)RelativeHorizontalLineiu  z
A path line element that takes its ordinate from the end of the previous element and
computes its abscissa offset from the end of that element.

See: `PaintedPath.horizontal_line_relative`
r   r  rm   c                     [        [        UR                  5      [        U R                  5      -   UR                  5      n[        R                  X/5      nX24$ )z7Compute the bounding box of a relative horizontal line.r.  rh   r  r  rk   s       rA   r  #RelativeHorizontalLine.bounding_box  sA    E%''NU466]2EGG<&&|4yrY   r  r0   r   r  r  c                     [        UR                  R                  U R                  -   UR                  R                  S9n[	        U5      [        U5      U4$ r1  r   r  r   r   r  r  r3  s         rA   r  RelativeHorizontalLine.render  sG    . I//11DFF:i>Q>Q>S>ST	I&YFFrY   c                 b    U R                  XX45      u  pxnUR                  U  SU S35        XxU4$ )a  
Render this path element to its PDF representation and produce debug
information.

Args:
    resource_registry (ResourceCatalog): the owner's graphics state
        dictionary registry.
    style (GraphicsStyle): the current resolved graphics style
    last_item: the previous path element.
    initial_point: last position set by a "M" or "m" command
    debug_stream (io.TextIO): the stream to which the debug output should be
        written. This is not guaranteed to be seekable (e.g. it may be stdout or
        stderr).
    pfx (str): the current debug output prefix string (only needed if emitting
        more than one line).

Returns:
    The same tuple as `RelativeHorizontalLine.render`.
r  rE   r  r   s	            rA   r  #RelativeHorizontalLine.render_debug  r  rY   r   Nr7  r   rY   rA   r9  r9  u  s     I
% E+u2D,E  G,G G 	G
 G 
sJ%	&G G2 1 1rY   r9  c                       \ rS rSr% Sr\\S'    S\S\\	\4   4S jr
\SSS	\S
\S\S\\\\4   4
S j5       r\S 5       rSrg)VerticalLinei  zx
A path line element that takes its abscissa from the end of the previous element.

See: `PaintedPath.vertical_line_to`
r   r  rm   c                     [        UR                  [        U R                  5      5      n[        R                  X/5      nX24$ )z/Compute the bounding box of this vertical line.r   r   r   r   rl   r   r;  s       rA   r  VerticalLine.bounding_box  s4    EGGU466]+&&|4yrY   r  r0   r   r  r  c                     [        UR                  R                  [        U R                  5      S9n[        U5      [        U5      U4$ r1  )r   r  r   r   r   r  r  r3  s         rA   r  VerticalLine.render  s:    . I//11U466]C	I&YFFrY   c                 b    U R                  XX45      u  pxnUR                  U  SU S35        XxU4$ )a  
Render this path element to its PDF representation and produce debug
information.

Args:
    resource_registry (ResourceCatalog): the owner's graphics state
        dictionary registry.
    style (GraphicsStyle): the current resolved graphics style
    last_item: the previous path element.
    initial_point: last position set by a "M" or "m" command
    debug_stream (io.TextIO): the stream to which the debug output should be
        written. This is not guaranteed to be seekable (e.g. it may be stdout or
        stderr).
    pfx (str): the current debug output prefix string (only needed if emitting
        more than one line).

Returns:
    The same tuple as `VerticalLine.render`.
r  rE   r  r   s	            rA   r  VerticalLine.render_debug  r  rY   r   Nr7  r   rY   rA   rC  rC    s     I8% E+u2D,E  G,G G 	G
 G 
sJ%	&G G2 1 1rY   rC  c                       \ rS rSr% Sr\\S'    S\S\\	\4   4S jr
\SSS	\S
\S\S\\\\4   4
S j5       r\S 5       rSrg)RelativeVerticalLinei  z
A path line element that takes its abscissa from the end of the previous element and
computes its ordinate offset from the end of that element.

See: `PaintedPath.vertical_line_relative`
r   r  rm   c                     [        UR                  [        UR                  5      [        U R                  5      -   5      n[        R                  X/5      nX24$ )z8Compute the bounding box of this relative vertical line.rE  r;  s       rA   r  !RelativeVerticalLine.bounding_box  sA    EGGU577^eDFFm;<&&|4yrY   r  r0   r   r  r  c                     [        UR                  R                  UR                  R                  U R                  -   S9n[	        U5      [        U5      U4$ r1  r>  r3  s         rA   r  RelativeVerticalLine.render!  sG    . I//11Y5H5H5J5JTVV5ST	I&YFFrY   c                 b    U R                  XX45      u  pxnUR                  U  SU S35        XxU4$ )a  
Render this path element to its PDF representation and produce debug
information.

Args:
    resource_registry (ResourceCatalog): the owner's graphics state
        dictionary registry.
    style (GraphicsStyle): the current resolved graphics style
    last_item: the previous path element.
    initial_point: last position set by a "M" or "m" command
    debug_stream (io.TextIO): the stream to which the debug output should be
        written. This is not guaranteed to be seekable (e.g. it may be stdout or
        stderr).
    pfx (str): the current debug output prefix string (only needed if emitting
        more than one line).

Returns:
    The same tuple as `RelativeVerticalLine.render`.
r  rE   r  r   s	            rA   r  !RelativeVerticalLine.render_debug<  D    . -1KKi-
)M 	dV=
"=>=00rY   r   Nr7  r   rY   rA   rL  rL    s     I
% E+u2D,E  G,G G 	G
 G 
sJ%	&G G4 1 1rY   rL  tp0p1p2p3c                 n    SU -
  nXU-  U-  U-  SXU-  -  U -  U-  -   SU-  X -  -  U-  -   X -  U -  U-  -   $ )u/   Cubic Bézier scalar evaluation at t ∈ [0,1].r      r   )rT  rU  rV  rW  rX  us         rA   _eval_cubic_bezier_1dr\  [  sc     	
AA	
b
qu+/B
	
a%15/B
	 519
	rY   epsc                    SU -  SU-  -   SU-  -
  SU-  -   nSU -  SU-  -
  SU-  -   nSU -  SU-  -   n/ n[        U5      U:  a9  [        U5      U:  a(  U* U-  n	SU	s=:  a  S:  a  O  U$ UR                  U	5        U$ Xf-  SU-  U-  -
  n
U
S:  aH  U
S	-  nU* U-   S
U-  -  U* U-
  S
U-  -  4 H'  n	SU	s=:  a  S:  d  M  O  M  UR                  U	5        M)     U$ )uH   t ∈ (0,1) where d/dt of the cubic Bézier equals 0 (possible extrema).	   rZ  r/     r   r      r      )r*  rS   )rU  rV  rW  rX  r]  ro   rp   rq   r  rT  discr   s               rA   _cubic_bezier_critical_ts_1dre  h  s    	R!b&1r6!AF*A	Bb1r6!A
R!b&A	B
1v|q6C<QA1yqy I 		! I uq1uqy 19c	ArAv!a%(A26a!e*<=q9199IIaL > IrY   c                       \ rS rSr% Sr\\S'    \\S'    \\S'    \S\4S j5       rS\S\	\
\4   4S	 jr\S
SS\S\S\S\	\\\4   4
S j5       r\S 5       rSrg)BezierCurvei  u   
A cubic Bézier curve path element.

This draws a Bézier curve parameterized by the end point of the previous path
element, two off-curve control points, and an end point.

See: `PaintedPath.curve_to`
c1c2r  rm   c                     U R                   $ r  r  r   s    rA   r  BezierCurve.end_point       xxrY   r  c                 h   UR                   U R                  R                   U R                  R                   U R                  R                   /nUR                  U R                  R                  U R                  R                  U R                  R                  /nSS/[        U6 -   nSS/[        U6 -   nU Vs/ s H  n[        U/UQ76 PM     nnU Vs/ s H  n[        U/UQ76 PM     nn[        [        U5      [        U5      [        U5      [        U5      5      n	XR                  4$ s  snf s  snf )u5   Compute the bounding box of this cubic Bézier curve.r   r   )
r   rh  ri  r  r   re  r\  rl   r   r   )
rh   r  pxpytxtyrT  r   r   rk   s
             rA   r  BezierCurve.bounding_box  s     ggtwwyy$''))TXXZZ8ggtwwyy$''))TXXZZ8V2B77V2B77578R#A++R8578R#A++R83r7CGSWc"g>XX~	 98s   7D*D/r  r0   r   r  r  c                 \    [        U R                  U R                  U R                  5      X4$ r  )r  rh  ri  r  r  s        rA   r  BezierCurve.render  s$    , TWWdggtxx8$MMrY   c                 n    U R                  XX45      u  pxnUR                  [        U 5      S-   5        XxU4$ )a  
Render this path element to its PDF representation and produce debug
information.

Args:
    resource_registry (ResourceCatalog): the owner's graphics state
        dictionary registry.
    style (GraphicsStyle): the current resolved graphics style
    last_item: the previous path element.
    initial_point: last position set by a "M" or "m" command
    debug_stream (io.TextIO): the stream to which the debug output should be
        written. This is not guaranteed to be seekable (e.g. it may be stdout or
        stderr).
    pfx (str): the current debug output prefix string (only needed if emitting
        more than one line).

Returns:
    The same tuple as `BezierCurve.render`.
rE   r  r   s	            rA   r  BezierCurve.render_debug  r!  rY   r   Nr  r   rY   rA   rg  rg    s     	I*I+	J 5  % E+u2D,E   N,N N 	N
 N 
sJ%	&N N. 1 1rY   rg  c                       \ rS rSr% Sr\\S'    \\S'    \\S'    S\S\\\4   4S jr	\
S	S
S\S\S\S\\\\4   4
S j5       r\
S 5       rSrg)RelativeBezierCurvei  u   
A cubic Bézier curve path element whose points are specified relative to the end
point of the previous path element.

See: `PaintedPath.curve_relative`
rh  ri  r  r  rm   c                 p   UnXR                   -   nXR                  -   nXR                  -   nSS/[        UR                  UR                  UR                  UR                  5      -   nSS/[        UR
                  UR
                  UR
                  UR
                  5      -   nU Vs/ s H^  n[        U[        UR                  5      [        UR                  5      [        UR                  5      [        UR                  5      5      PM`     n	nU Vs/ s H^  n[        U[        UR
                  5      [        UR
                  5      [        UR
                  5      [        UR
                  5      5      PM`     n
n[        [        U	5      [        U
5      [        U	5      [        U
5      5      nX4$ s  snf s  snf )uI  
Compute the bounding box of this relative cubic Bézier curve.

Args:
    start (Point): The starting point of the curve (i.e., the end of the previous path element).

Returns:
    A tuple containing:
        - BoundingBox: the axis-aligned bounding box containing the entire curve.
        - Point: the end point of the curve.
r   r   )rh  ri  r  re  r   r   r\  r   rl   r   r   )rh   r  rU  rV  rW  rX  rq  rr  rT  r   r   rk   s               rA   r   RelativeBezierCurve.bounding_box  sV    WW_WW_XXV2244rttRTTJJV2244rttRTTJJ 
 "!U244[%+uRTT{ERTRVRVKX 	 
 
 "!U244[%+uRTT{ERTRVRVKX 	 

 3r7CGSWc"g>x

s   'A%F.A%F3r  r0   r   r  r  c                     UR                   nXPR                  -   nXPR                  -   nXPR                  -   n[	        XgU5      [        XgUS9U4$ )a  
Render this path element to its PDF representation.

Args:
    resource_registry (ResourceCatalog): the owner's graphics state
        dictionary registry.
    style (GraphicsStyle): the current resolved graphics style
    last_item: the previous path element.
    initial_point: last position set by a "M" or "m" command

Returns:
    a tuple of `(str, new_last_item)`, where `new_last_item` is the resolved
    `BezierCurve`.
rh  ri  r  )r  rh  ri  r  r  rg  )	rh   r  r   r  r  
last_pointrh  ri  r  s	            rA   r  RelativeBezierCurve.render  sV    . ((
''!''!88# "#&2#.
 	
rY   c                 b    U R                  XX45      u  pxnUR                  U  SU S35        XxU4$ )a  
Render this path element to its PDF representation and produce debug
information.

Args:
    resource_registry (ResourceCatalog): the owner's graphics state
        dictionary registry.
    style (GraphicsStyle): the current resolved graphics style
    last_item: the previous path element.
    initial_point: last position set by a "M" or "m" command
    debug_stream (io.TextIO): the stream to which the debug output should be
        written. This is not guaranteed to be seekable (e.g. it may be stdout or
        stderr).
    pfx (str): the current debug output prefix string (only needed if emitting
        more than one line).

Returns:
    The same tuple as `RelativeBezierCurve.render`.
r  rE   r  r   s	            rA   r   RelativeBezierCurve.render_debug4  r  rY   r   Nr  r   rY   rA   ry  ry    s     	I 	I 
JQ% E+u2D,E B  
, 
  
 	 

  
 
sJ%	& 
  
D 1 1rY   ry  c                       \ rS rSr% Sr\\S'    \\S'    \S\4S j5       rS\S\	4S jr
S	\S\\\4   4S
 jr\SSS\S\S\S\\\\4   4
S j5       r\S 5       rSrg)QuadraticBezierCurveiT  u   
A quadratic Bézier curve path element.

This draws a Bézier curve parameterized by the end point of the previous path
element, one off-curve control point, and an end point.

See: `PaintedPath.quadratic_curve_to`
ctrlr  rm   c                     U R                   $ r  rk  r   s    rA   r  QuadraticBezierCurve.end_pointc  rm  rY   start_pointc                    U R                   nU R                  n[        UR                  SUR                  UR                  -
  -  S-  -   UR                  SUR                  UR                  -
  -  S-  -   S9n[        UR                  SUR                  UR                  -
  -  S-  -   UR                  SUR                  UR                  -
  -  S-  -   S9n[        XEU5      $ )Nrc  rZ  r2  )r  r  r   r   r   rg  )rh   r  r  r  r  r  s         rA   to_cubic_curve#QuadraticBezierCurve.to_cubic_curveh  s    yyhhmma466KMM#9:Q>>mma466KMM#9:Q>>
 eea466CEE>*Q..eea466CEE>*Q..

 5--rY   r  c                 F    U R                  U5      nUR                  U5      $ )u]   Compute the bounding box of this quadratic Bézier curve by converting it to a cubic Bézier.)r  r  )rh   r  cubics      rA   r  !QuadraticBezierCurve.bounding_boxw  s#    ##E*!!%((rY   r  r0   r   r  r  c                 d    U R                  UR                  5      R                  XX45      S   U U4$ )a  
Render this path element to its PDF representation.

Args:
    resource_registry (ResourceCatalog): the owner's graphics state
        dictionary registry.
    style (GraphicsStyle): the current resolved graphics style
    last_item: the previous path element.
    initial_point: last position set by a "M" or "m" command

Returns:
    a tuple of `(str, new_last_item)`, where `new_last_item` is `self`.
r   )r  r  r  r  s        rA   r  QuadraticBezierCurve.render|  sB    , 	 3 34;;!) 
 	
rY   c                     U R                  XX45      u  pxnUR                  U  SU R                  UR                  5       S35        XxU4$ )a  
Render this path element to its PDF representation and produce debug
information.

Args:
    resource_registry (ResourceCatalog): the owner's graphics state
        dictionary registry.
    style (GraphicsStyle): the current resolved graphics style
    last_item: the previous path element.
    initial_point: last position set by a "M" or "m" command
    debug_stream (io.TextIO): the stream to which the debug output should be
        written. This is not guaranteed to be seekable (e.g. it may be stdout or
        stderr).
    pfx (str): the current debug output prefix string (only needed if emitting
        more than one line).

Returns:
    The same tuple as `QuadraticBezierCurve.render`.
r  rE   r  r  r  r  r   s	            rA   r  !QuadraticBezierCurve.render_debug  s[    0 -1KKi-
)M 	fM$"5"5i6I6I"J!K2N	
 =00rY   r   N)r   r   r   r   r   r   r4  r6  r  rg  r  rN   rl   r  r   r   r  rI   r  r  r   r   rY   rA   r  r  T  s     K$	J 5  .% .K .)% )E+u2D,E )
 
,
 
 	

 
 
sJ%	&
 
8 1 1rY   r  c                       \ rS rSr% Sr\\S'    \\S'    S\S\\\4   4S jr	\
SS	S
\S\S\S\\\\4   4
S j5       r\
S 5       rSrg)RelativeQuadraticBezierCurvei  u   
A quadratic Bézier curve path element whose points are specified relative to the end
point of the previous path element.

See: `PaintedPath.quadratic_curve_relative`
r  r  r  rm   c                 j    XR                   -   nXR                  -   n[        X#S9R                  U5      $ )uB   Compute the bounding box of this relative quadratic Bézier curve.r  r  )r  r  r  r  )rh   r  r  r  s       rA   r  )RelativeQuadraticBezierCurve.bounding_box  s0    yy hh#7DDUKKrY   r  r0   r   r  r  c                     UR                   nXPR                  -   nXPR                  -   n[        XgS9nUR	                  XX45      $ )a  
Render this path element to its PDF representation.

Args:
    resource_registry (ResourceCatalog): the owner's graphics state
        dictionary registry.
    style (GraphicsStyle): the current resolved graphics style
    last_item: the previous path element.
    initial_point: last position set by a "M" or "m" command

Returns:
    a tuple of `(str, new_last_item)`, where `new_last_item` is the resolved
    `QuadraticBezierCurve`.
r  )r  r  r  r  r  )	rh   r  r   r  r  r~  r  r  absolutes	            rA   r  #RelativeQuadraticBezierCurve.render  sC    , ((
II%88#'T;0RRrY   c           	          U R                  XX45      u  pxnUR                  U  SU SUR                  UR                  5       S35        XxU4$ )a  
Render this path element to its PDF representation and produce debug
information.

Args:
    resource_registry (ResourceCatalog): the owner's graphics state
        dictionary registry.
    style (GraphicsStyle): the current resolved graphics style
    last_item: the previous path element.
    initial_point: last position set by a "M" or "m" command
    debug_stream (io.TextIO): the stream to which the debug output should be
        written. This is not guaranteed to be seekable (e.g. it may be stdout or
        stderr).
    pfx (str): the current debug output prefix string (only needed if emitting
        more than one line).

Returns:
    The same tuple as `RelativeQuadraticBezierCurve.render`.
r  z	 then to rE   r  r   s	            rA   r  )RelativeQuadraticBezierCurve.render_debug  sh    0 -1KKi-
)M 	fM( ,..y/B/BCDBH	

 =00rY   r   Nr  r   rY   rA   r  r    s     KU	JQL% LE+u2D,E L S,S S 	S
 S 
sJ%	&S S: 1 1rY   r  c                      \ rS rSr% Sr\\S'    \\S'    \\S'    \\S'    \\S'    \	\
S\S	\\\\\4   S
S
4   4S j5       5       rS\S	\\   4S jrS\S	\\\4   4S jr\
SSS\S\S\S	\\\\4   4
S j5       r\
S 5       rSrg
)Arci  z
An elliptical arc path element.

The arc is drawn from the end of the current path element to its specified end point
using a number of parameters to determine how it is constructed.

See: `PaintedPath.arc_to`
radiirotationlargesweepr  sweep_anglerm   Nc              #     #    [        U 5      n U n[        R                  S-  n[        R                  " X-  5      nX-  n[        R                  " U5      n[        R
                  " U5      nS[        R                  " US-  5      -  n[        SU5      n[        XWU-  -   XgU-  -
  5      n	[        XV5      n
[        U5       H.  nX-
  n[        R                  " U5      nX-  X-  X-  4v   X-  nM0     g7f)u  
A generator that subdivides a swept angle into segments no larger than a quarter
turn.

Any sweep that is larger than a quarter turn is subdivided into as many equally
sized segments as necessary to prevent any individual segment from being larger
than a quarter turn.

This is used for approximating a circular curve segment using cubic Bézier
curves. This computes the parameters used for the Bézier approximation up
front, as well as the transform necessary to place the segment in the correct
position.

Args:
    sweep_angle (float): the angle to subdivide.

Yields:
    A tuple of (ctrl1, ctrl2, end) representing the control and end points of
    the cubic Bézier curve approximating the segment as a unit circle centered
    at the origin.
rc  gUUUUUU?rb  r   N)r*  r  piceilcossintanr   ranger   r  )r  
sweep_leftquarterturnchunkssweep_segmentcos_tsin_tkappar  r  r  _offset	transforms                 rA   subdivide_sweepArc.subdivide_sweep&  s     4 +& 
ggk;45#,''!233aeem+UU]-BCE!vA -F!**62I#U%6GG'J s   C0C2r  c           	         U R                   n[        R                  " U R                  * 5      n[        R                  " U R                  5      nUR                  U R                  -
  S-  U-  nUR
                  UR
                  -  S-  UR                  UR                  -  S-  -   nUS:  a*  [        US-  UR
                  -  US-  UR                  -  S9nU R                  U R                  :g  U R                  U R                  :H  -
  nUR
                  UR                  -  S-  nUR
                  UR                  -  S-  n	UR                  UR
                  -  S-  n
U[        R                  " [        X-
  U
-
  S5      X-   -  5      -  [        UR
                  UR                  -  UR                  -  UR                  * UR
                  -  UR
                  -  S9-  nX-  UR                  U R                  -   S-  -   n[        UR
                  UR
                  -
  UR
                  -  UR                  UR                  -
  UR                  -  S9n[        UR
                  * UR
                  -
  UR
                  -  UR                  * UR                  -
  UR                  -  S9n[        SS5      R                  U5      nUR                  U5      nU R                  SL a  US:  a  U[        R                  -  nO(U R                  SL a  US:  a  U[        R                  -  nUS:  US:  -
  n[        R                  " SUS9R!                  U5      R#                  UR
                  UR                  5      R!                  U R                  5      R%                  UR
                  UR                  5      n/ nU R'                  U5       H,  u  nnnUR)                  [+        UU-  UU-  UU-  5      5        M.     U$ )	z
Approximate this arc with a sequence of `BezierCurve`.

Args:
    last_item: the previous path element (used for its end point)

Returns:
    a list of `BezierCurve`.
r   rc  r   r2     r   FT)r  r   r  r  r  r   r   r   r  r  r  sqrtr1  angletauscalingrotatescale	translater  rS   rg  )rh   r  r  reverseforwardprimelam_dasignrxry2rxpy2rypx2centerprimecenterarcstartarcendtheta
deltatheta
sweep_signfinal_tfcurvesr  r  r  s                          rA   _approximate_arcArc._approximate_arcW  sI    

$$dmm^4$$T]]3%%0C77B''EGG#)UWWuww->1,DDA:VS[EGG3uww7NOE

djj(TZZ4::-EF577"q(577"q(577"q( iieme3Q75=IJK''EGG#egg-77(UWW$uww. 	 'Y-@-@488-Ks,RSww&%''1ww&%''1
 x+--'5772x+--'5772

 a!!(+^^F+
JJ%j1n$(("JjjD zA~$(("J Ao*q.9
Z0VE]U577EGG$VDMM"Yvxx* 	 !%!5!5j!AE5#MMEH,eh.>hO "B
 rY   r  c                     [         R                  5       n[        U5      nU R                  U5       H3  nUR	                  UR
                  5      u  pVUR                  U5      nUnM5     X R                  4$ )z
Compute the bounding box of this arc by approximating it with a series of
Bezier curves and aggregating their bounding boxes.
)rl   r   r  r  r  r  r   r  )rh   r  rk   prevcurvesegment_bboxr  s          rA   r  Arc.bounding_box  sg    
   "E{**40E#00@OL::l+DD 1
 XX~rY   r  r0   r   r  c           	         ^^^ U R                  U5      nU(       d  SUT4$ SR                  UUU4S j[        U/USS QU5       5       5      US   T4$ )  
Render this path element to its PDF representation.

Args:
    resource_registry (ResourceCatalog): the owner's graphics state
        dictionary registry.
    style (GraphicsStyle): the current resolved graphics style
    last_item: the previous path element.
    initial_point: last position set by a "M" or "m" command

Returns:
    a tuple of `(str, new_last_item)`, where `new_last_item` is a resolved
    `BezierCurve`.
 r;   c              3   V   >#    U  H  u  pUR                  TTUT5      S    v   M      g7fr   Nr  r?   r  r  r  r  r   s      rA   rB   Arc.render.<locals>.<genexpr>  s/      #IKD .t]KAN#I   &)Nr   )r  rO   r   )rh   r  r   r  r  r  s    `` ` rA   r  
Arc.render  sk    , &&y1y-// HH #&	'@F3BK'@&#I  2J
 	
rY   c                   ^^^ U R                  U5      nUR                  U  S35        U(       d  UR                  US-   5        SUT4$ U/nUSS  H,  n	UR                  U	5        UR                  USU	 S3-   5        M.     UR                  USUS    S3-   5        S	R                  UUU4S
 j[	        X5       5       5      US   T4$ )a  
Render this path element to its PDF representation and produce debug
information.

Args:
    resource_registry (ResourceCatalog): the owner's graphics state
        dictionary registry.
    style (GraphicsStyle): the current resolved graphics style
    last_item: the previous path element.
    initial_point: last position set by a "M" or "m" command
    debug_stream (io.TextIO): the stream to which the debug output should be
        written. This is not guaranteed to be seekable (e.g. it may be stdout or
        stderr).
    pfx (str): the current debug output prefix string (only needed if emitting
        more than one line).

Returns:
    The same tuple as `Arc.render`.
 resolved to:
    └─ nothing
r  Nr       ├─ rE       └─ r;   c              3   V   >#    U  H  u  pUR                  TTUT5      S    v   M      g7fr  r  r  s      rA   rB   #Arc.render_debug.<locals>.<genexpr>  s/      #8KD .t]KAN#8r  )r  r  rS   rO   r   )
rh   r  r   r  r  r  r  r  previousr  s
    `` `     rA   r  Arc.render_debug  s    . &&y1dV?34s%889y-//;CR[EOOE"sxwb%99: ! 	38F2J<r!::; HH #&x#8  2J
 	
rY   r   )r   r   r   r   r   r   r4  r   rL   staticmethodr   r   r   rN   r  r  rM   rg  r  rl   r  r   rI   r  r  r   r   rY   rA   r  r    s    L VKTKF	J#-(-(	5u,-tT9	:-(  -(^G* Gk9J GR% E+u2D,E  !
,!
 !
 	!

 !
 
sJ%	&!
 !
F *
 *
rY   r  c                       \ rS rSr% Sr\\S'    \\S'    \\S'    \\S'    \\S'    S\S	\	\
\4   4S
 jr\SSS\S\S\S	\	\\\4   4
S j5       r\S 5       rSrg)RelativeArci	  z
An elliptical arc path element.

The arc is drawn from the end of the current path element to its specified end point
using a number of parameters to determine how it is constructed.

See: `PaintedPath.arc_relative`
r  r  r  r  r  r  rm   c                     XR                   -   n[        U R                  U R                  U R                  U R
                  US9nUR                  U5      $ )zHCompute the bounding box of the resolved arc from the given start point.r  r  r  r  r  )r  r  r  r  r  r  r  )rh   r  r  arcs       rA   r  RelativeArc.bounding_box	  sJ    HH$	**]]****
 &&rY   r  r0   r   r  r  c                     [        U R                  U R                  U R                  U R                  UR
                  U R                  -   5      R                  XX45      $ )r  )r  r  r  r  r  r  r  r  r  s        rA   r  RelativeArc.render$	  sO    , JJMMJJJJ$((*
 &"9
D	ErY   c                     UR                  U  S35        [        U R                  U R                  U R                  U R
                  UR                  U R                  -   5      R                  XX4XV5      $ )a  
Render this path element to its PDF representation and produce debug
information.

Args:
    resource_registry (ResourceCatalog): the owner's graphics state
        dictionary registry.
    style (GraphicsStyle): the current resolved graphics style
    last_item: the previous path element.
    initial_point: last position set by a "M" or "m" command
    debug_stream (io.TextIO): the stream to which the debug output should be
        written. This is not guaranteed to be seekable (e.g. it may be stdout or
        stderr).
    pfx (str): the current debug output prefix string (only needed if emitting
        more than one line).

Returns:
    The same tuple as `RelativeArc.render`.
r  )	r  r  r  r  r  r  r  r  r  rh   r  r   r  r  r  r  s          rA   r  RelativeArc.render_debugB	  sg    0 	dV=12JJMMJJJJ$((*
 ,i
	
rY   r   N)r   r   r   r   r   r   r4  r   rL   rN   rl   r  r   r   r  rI   r  r  r   r   rY   rA   r  r  	  s     L VKTKF	JT
'% 
'E+u2D,E 
' E,E E 	E
 E 
sJ%	&E E: !
 !
rY   r  c                       \ rS rSr% Sr\\S'    \\S'    SS\\\4   4S jjr	\
SS	S
\S\S\S\\\\4   4
S j5       r\
S 5       rSrg)	Rectangleig	  zA pdf primitive rectangle.orgsizeNrm   c           	         U R                   R                  U R                   R                  p2[        U5      [        U R                  R                  5      -   n[        U5      [        U R                  R                  5      -   n[
        R                  [        X#5      [        XC5      [        X%5      [        XE5      /5      nX`R                   4$ )z+Compute the bounding box of this rectangle.)r  r   r   r   r  rl   r   r   )rh   r  ry   rz   r   r   rk   s          rA   r  Rectangle.bounding_boxp	  s    TXXZZB2Ytyy{{++2Ytyy{{++&&bbbb	
 XX~rY   r  r0   r   r  r  c                     U R                   R                  5        SU R                  R                  5        S3[        U R                   5      U4$ )a  
Render this path element to its PDF representation.

Args:
    resource_registry (ResourceCatalog): the owner's graphics state
        dictionary registry.
    style (GraphicsStyle): the current resolved graphics style
    last_item: the previous path element.
    initial_point: last position set by a "M" or "m" command

Returns:
    a tuple of `(str, new_last_item)`, where `new_last_item` is a `Line` back to
    the rectangle's origin.
r;   z re)r  r  r  r  r  s        rA   r  Rectangle.render	  sF    0 xx !499#3#3#5"6c:N
 	
rY   c                 b    U R                  XX45      u  pxnUR                  U  SU S35        XxU4$ )a  
Render this path element to its PDF representation and produce debug
information.

Args:
    resource_registry (ResourceCatalog): the owner's graphics state
        dictionary registry.
    style (GraphicsStyle): the current resolved graphics style
    last_item: the previous path element.
    initial_point: last position set by a "M" or "m" command
    debug_stream (io.TextIO): the stream to which the debug output should be
        written. This is not guaranteed to be seekable (e.g. it may be stdout or
        stderr).
    pfx (str): the current debug output prefix string (only needed if emitting
        more than one line).

Returns:
    The same tuple as `Rectangle.render`.
r  rE   r  r   s	            rA   r  Rectangle.render_debug	  rS  rY   r   r=   r  r   rY   rA   r  r  g	  s    $	J/
K0%U0B*C   
,
 
 	

 
 
sJ%	&
 
8 1 1rY   r  c                       \ rS rSr% Sr\\S'    \\S'    \\S'    S\\   4S jr	S\S\
\\4   4S	 jr\S
SS\S\S\S\
\\\4   4
S j5       r\S 5       rSrg)RoundedRectanglei	  zA
A rectangle with rounded corners.

See: `PaintedPath.rectangle`
r  r  corner_radiirm   c                    / nU R                   R                  S:X  a  U R                   R                  S:X  a   U$ U R                   R                  S:X  d  U R                   R                  S:X  ap  UR                  [	        U R
                  5      5        UR                  [        U R
                  U R                   -   5      5        UR                  [        5       5        U$ U R                  R                  S:X  d  U R                  R                  S:X  a1  UR                  [        U R
                  U R                   5      5        U$ U R
                  u  p#U R                   u  pEU R                  u  pgU R                   R                  S:  U R                   R                  S:  -
  nU R                   R                  S:  U R                   R                  S:  -
  n	[        U5      [        U5      :  a  U R                   R                  n[        U5      [        U5      :  a  U R                   R                  nU[        U5      -  nU	[        U5      -  n[        Xg5      n
UR                  [	        [        X&-   U5      5      5        UR                  [        [        X$-   U-
  U5      5      5        UR                  [        U
SSS[        X$-   X7-   5      5      5        UR                  [        [        X$-   X5-   U-
  5      5      5        UR                  [        U
SSS[        X$-   U-
  X5-   5      5      5        UR                  [        [        X&-   X5-   5      5      5        UR                  [        U
SSS[        X#U-   U-
  5      5      5        UR                  [        [        X#U-   5      5      5        UR                  [        U
SSS[        X&-   U5      5      5        UR                  [        5       5        U$ Nr   FT)r  r   r   rS   r  r  r  Closer  r  r*  r   r  )rh   rQ   r   r   r  hrxry
sign_widthsign_heightarc_rads              rA   
_decomposeRoundedRectangle._decompose	  s   IIKK1499;;!#3F E iikkQDIIKK1$4LLdhh(LLdhh234LL!> = !!Q&D,=,=,?,?1,DLL488TYY78: 7 88DA99DA&&FB))++*tyy{{Q?J99;;!+		a@K2wQYY[[2wQYY[[c"g%Bs2w&BBmGLLeAFA./0LLeAEBJ234LLWaeAE166JKLLLeAE152:678LLWaeAEBJ6NOPLLeAFAE234LLWaeA1urz6JKLLLeA2v./0LLWaeAFA6FGHLL!rY   r  c                     [         R                  5       nUnU R                  5        H'  nUR                  U5      u  pSUR	                  U5      nM)     X R
                  4$ )z
Compute the bounding box of this rounded rectangle by decomposing into primitives
and merging their individual bounding boxes.
)rl   r   r  r  r   r  rh   r  rk   current_pointr  rp   s         rA   r  RoundedRectangle.bounding_box	  sV    
   "OO%D#00?A::a=D & XX~rY   r  r0   r   r  r  c                     U R                  5       nU(       d  SX44$ / nU H)  nUR                  XX45      u  pnUR                  U5        M+     SR                  U5      [	        U R
                  5      U4$ )a  
Render this path element to its PDF representation.

Args:
    resource_registry (ResourceCatalog): the owner's graphics state
        dictionary registry.
    style (GraphicsStyle): the current resolved graphics style
    last_item: the previous path element.
    initial_point: last position set by a "M" or "m" command

Returns:
    a tuple of `(str, new_last_item)`, where `new_last_item` is a resolved
    `Line`.
r  r;   )r  r  rS   rO   r  r  	rh   r  r   r  r  
componentsrender_listr  r  s	            rA   r  RoundedRectangle.render
  su    , __&
y//D15!)2.H x(	  xx$d488nmCCrY   c                    U R                  5       nUR                  U  S35        U(       d  UR                  US-   5        SX44$ / nUSS  HA  n	U	R                  XX45      u  pnUR                  USU	 S3-   5        UR                  U
5        MC     US   R                  XX45      u  pnUR                  USUS    S3-   5        UR                  U
5        S	R	                  U5      [        U R                  5      U4$ )
a  
Render this path element to its PDF representation and produce debug
information.

Args:
    resource_registry (ResourceCatalog): the owner's graphics state
        dictionary registry.
    style (GraphicsStyle): the current resolved graphics style
    last_item: the previous path element.
    initial_point: last position set by a "M" or "m" command
    debug_stream (io.TextIO): the stream to which the debug output should be
        written. This is not guaranteed to be seekable (e.g. it may be stdout or
        stderr).
    pfx (str): the current debug output prefix string (only needed if emitting
        more than one line).

Returns:
    The same tuple as `RoundedRectangle.render`.
r  r  r  Nr   r  rE   r  r;   )r  r  r  rS   rO   r  r  rh   r  r   r  r  r  r  r  r  r  r  s              rA   r  RoundedRectangle.render_debug%
  s   . __&
dV?34s%889y//sOD15!)2.H sxvR%889x( $ .8^-B-Bi.
*] 	38JrN+;2!>>?8$xx$d488nmCCrY   r   Nr   r   r   r   r   r   r4  rM   r  r  rN   rl   r  r   r   rI   r  r  r   r   rY   rA   r  r  	  s     
J/
K0-'D, 'R% E+u2D,E  !D,!D !D 	!D
 !D 
sJ%	&!D !DF +D +DrY   r  c                       \ rS rSr% Sr\\S'    \\S'    S\\   4S jr	S\S\
\\4   4S jr\S	S
S\S\S\S\
\\\4   4
S j5       r\S 5       rSrg)EllipseiT
  z)
An ellipse.

See: `PaintedPath.ellipse`
r  r  rm   c                    / n[        U R                  R                  5      n[        U R                  R                  5      nU R                  u  pE[        X#5      nUS:w  a  US:w  a  UR                  [        [        XB-   U5      5      5        UR                  [        USSS[        XEU-   5      5      5        UR                  [        USSS[        XB-
  U5      5      5        UR                  [        USSS[        XEU-
  5      5      5        UR                  [        USSS[        XB-   U5      5      5        UR                  [        5       5        U$ r  )
r*  r  r   r   r  r   rS   r  r  r  )rh   rQ   r  r  r   r   r  s          rA   r  Ellipse._decompose`
  s   - !G"'LLeBGR012LLWaeBR6HIJLLWaeBGR6HIJLLWaeBR6HIJLLWaeBGR6HIJLL!rY   r  c                     [         R                  5       nUnU R                  5        H'  nUR                  U5      u  pSUR	                  U5      nM)     X R
                  4$ )zn
Compute the bounding box of this ellipse by decomposing it and merging the bounding boxes
of its components.
)rl   r   r  r  r   r  r  s         rA   r  Ellipse.bounding_boxu
  sW    
   "OO%D#00?A::a=D & [[  rY   r  r0   r   r  r  c                     U R                  5       nU(       d  SX44$ / nU H)  nUR                  XX45      u  pnUR                  U5        M+     SR                  U5      [	        U R
                  5      U4$ )a  
Render this path element to its PDF representation.

Args:
    resource_registry (ResourceCatalog): the owner's graphics state
        dictionary registry.
    style (GraphicsStyle): the current resolved graphics style
    last_item: the previous path element.
    initial_point: last position set by a "M" or "m" command

Returns:
    a tuple of `(str, new_last_item)`, where `new_last_item` is a resolved
    `Move` to the center of the ellipse.
r  r;   )r  r  rS   rO   r  r  r  s	            rA   r  Ellipse.render
  sv    , __&
y//D15!)2.H x(	  xx$d4;;&7FFrY   c                    U R                  5       nUR                  U  S35        U(       d  UR                  US-   5        SX44$ / nUSS  HA  n	U	R                  XX45      u  pnUR                  USU	 S3-   5        UR                  U
5        MC     US   R                  XX45      u  pnUR                  USUS    S3-   5        UR                  U
5        S	R	                  U5      [        U R                  5      U4$ )
a  
Render this path element to its PDF representation and produce debug
information.

Args:
    resource_registry (ResourceCatalog): the owner's graphics state
        dictionary registry.
    style (GraphicsStyle): the current resolved graphics style
    last_item: the previous path element.
    initial_point: last position set by a "M" or "m" command
    debug_stream (io.TextIO): the stream to which the debug output should be
        written. This is not guaranteed to be seekable (e.g. it may be stdout or
        stderr).
    pfx (str): the current debug output prefix string (only needed if emitting
        more than one line).

Returns:
    The same tuple as `Ellipse.render`.
r  r  r  Nr   r  rE   r  r;   )r  r  r  rS   rO   r  r  r  s              rA   r  Ellipse.render_debug
  s   . __&
dV?34s%889y//sOD15!)2.H sxvR%889x( $ .8^-B-Bi.
*] 	38JrN+;2!>>?8$xx$d4;;&7FFrY   r   Nr  r   rY   rA   r  r  T
  s     L+M@D, *!% !E+u2D,E ! !G,!G !G 	!G
 !G 
sJ%	&!G !GF +G +GrY   r  c                       \ rS rSr% \\S'   \\S'   \\S'   \\S'   Sr\\S'   Sr\\S'   S	r	\
\   \S
'   S	r\
\   \S'   S	r\
\   \S'   S	r\
\   \S'   Srg	)TextRuni
  textfamilyemphasisr  r   r   r   Nabs_xabs_yr  	run_styler   )r   r   r   r   rI   r4  r   r   r   r*  r
   r+  r  r   r,  r   r   r   rY   rA   r&  r&  
  sb    
IKM
KBOBO!E8E?!!E8E?!%)Ix	"))-Ix&-rY   r&  c                       \ rS rSr% Sr\\S'   \\S'   \\S4   \S'   Sr	\
\S'   S	\\\\\\4      \4   4S
 jrS\\\\\4      S	\4S jrS\S	\S\4   4S jr\SSSSSSS\S	\\
S\4   4
S j5       r\S 5       rSrg)Texti
  z
SVG-like text renderable.
Stores the anchor position (x, y) and one or more TextRuns that include
relative positioning offsets. Accurate glyph positioning is resolved
during rendering once font metrics are available.
r   r   .	text_runsr  text_anchorrm   c                    / nU R                   nU R                  nUnUnU R                   H  nUR                  b  UR                  nUR                  b  UR                  nX&R
                  -  nX6R                  -  nSUR                  -  [        S[        UR                  5      5      -  nUR                  X#U45        [        XR5      n[        XBU-   5      nX'-  nM     XE-
  nX4$ )z
Produce an approximate layout for bounding-box estimation.

Returns:
    A tuple of (per-run layout list, total width estimate).  Each layout
    entry is (x, y, width) in user space.
r   r   )r   r   r/  r*  r+  r   r   r  r   lenr'  rS   r   )	rh   	positionspen_xpen_y	max_rightmin_leftrunapprox_widthtotal_widths	            rA   _approximate_layoutText._approximate_layout
  s     79		>>Cyy$		yy$		VVOEVVOE>C3sxx=,AALeL9:8+HI|';<I!E "  *%%rY   r3  c                 B   U(       d  g[        S U R                   5       5      (       a  g[        S U 5       5      n[        S U 5       5      nU R                  S:X  a  U R
                  X#-   S-  -
  $ U R                  S:X  a  U R
                  U-
  $ U R
                  U-
  $ )z:Compute anchor offset for the provided approximate layout.r   c              3   <   #    U  H  oR                   S Lv   M     g 7fr=   r*  )r?   r8  s     rA   rB   &Text._anchor_offset.<locals>.<genexpr>  s     ?yy$s   c              3   *   #    U  H	  oS    v   M     g7fr  r   r?   poss     rA   rB   r@    s     0isFis   c              3   6   #    U  H  oS    US   -   v   M     g7f)r   rc  Nr   rB  s     rA   rB   r@    s     9yFSVOys   middle       @r  )anyr/  r   r   r0  r   )rh   r3  min_xmax_xs       rA   _anchor_offsetText._anchor_offset  s    ????0i009y99x'66U]c111u$66E>!vv~rY   rl   c                    U R                   (       d  [        R                  5       U4$ U R                  5       u  p#U R	                  U5      n[        S5      n[        S5      n[        S5      n[        S5      n[        X R                   5       H_  u  u  ppX-   nSUR                  -  nSUR                  -  n[        X]5      n[        XmU-   5      n[        XzU-
  5      n[        XU-   5      nMa     U[        S5      :X  a  [        R                  5       U4$ UnUnUnUn[        R                  [        UU5      [        UU5      /5      U4$ )z
Compute a conservative bbox for the text.

Font metrics are not available at this stage so the layout relies on
approximate glyph widths proportional to the run font size. The actual
layout is computed precisely in render().
r   r   皙?皙?)r/  rl   r   r;  rJ  r   r   r  r   r   r   r   )rh   r  r3  r  anchor_offsetrH  rI  min_ymax_yrun_xrun_y	run_widthr8  adj_xascdescry   r   rz   r   s                       rA   r  Text.bounding_box   s3    ~~$$&--//1	++I6efef.1)^^.L*%U9)E.C>D%Ey01Es{+Et|,E /M E%L $$&--&&b"uR}'EFMMrY   r  r0   r   r   r  r  r  c                 	   U R                   (       d  SX44$ / nU R                  nU R                  nUnUn	U R                    H  n
UR                  U
R                  U
R
                  5      nUR                  U
R                  U
R                  S5      u  pU
R                  b  U
R                  nU
R                  b  U
R                  nXjR                  -  nXzR                  -  n[        X5      n[        XU-   5      n	UR                  XgXU45        Xm-  nM     [!        S U 5       5      nU(       a\  U(       dU  U R"                  S:X  a  U R                  X-   S-  -
  nO2U R"                  S:X  a  U R                  U	-
  nOU R                  U-
  nOSn/ nS[$        R&                  4nU GH  u  nnpnU
R(                  b  [$        R+                  X*R(                  5      OUnUR-                  5       nU[.        R0                  [.        R2                  4;   a  SnO?U[.        R4                  L a  S	nO)U[.        R6                  [.        R8                  4;   a  S
nOSn/ nU
R(                  Gb  UnUR;                  U5      nUb  UR                  [=        U5       S35        UR>                  nUR@                  n[B        RE                  [G        UU-   USU
R                  -  -
  5      [G        UU-   U-   USU
R                  -  -   5      /5      nUU;  ad  [I        U[J        5      (       a"  UR                  URM                  UU5      5        O-UR                  URO                  5       RQ                  5       5        UU;  ad  [I        U[J        5      (       a"  UR                  URS                  UU5      5        O-UR                  URO                  5       RU                  5       5        URV                  nURX                  nUU;  a*  UR                  [=        U5      S[[        U5       S3-   5        UR]                  SSUR^                   S[[        U
R                  5       S3[[        U5       S3S[[        UU-   5       S[[        U5       S3URa                  U
R                  5      S/5        U
R(                  b
  S/U-   S/-   nUR]                  U5        GM     SRc                  U5      X44$ )z
Emit PDF text operators:

  BT
    <font_id> <font_size> Tf
    Tr <mode>               (map from GraphicsStyle->PathPaintRule)
    1 0 0 1 x y Tm
    (escaped-text) Tj
  ET
r  Nc              3   F   #    U  H  u      poR                   S Lv   M     g 7fr=   r?  )r?   r  r8  s      rA   rB   Text.render.<locals>.<genexpr>p  s     O_Q1199D0s   !rE  rF  r  r   r   r   rc  rZ   gsrM  rN  r;    dBTz/Fz Tfz Trz	1 0 0 -1 z TmETqQ)2r/  r   r   get_font_from_familyr(  r)  get_text_widthr'  r  r*  r+  r   r   r   r   rS   rG  r0  r   r   r,  r   r   r    r  r  r   r   r   register_graphics_styler>   rM  rO  rl   r   r   rF   r[   r   r2   lowerr   upperrT  rU  r   extendiencode_textrO   )rh   r  r   r  r  layoutr4  r5  rH  rI  r8  fontr  rw   has_absoluterO  opsNO_EMIT_SETrR  rS  effective_styler  trrun_opsmerged_stylestyle_dict_namerM  rO  run_bboxdash_pattern
dash_phases                                  rA   r  Text.renderF  ss   $ ~~y// EG>>C$99#**cllSD**388SXXtDHAyy$		yy$		VVOEVVOE%Eu}-EMM5T:;NE " OOO,8+ $%-3)> >!!U* $ $M]223.4*E5%d ==, ##E==9  #557D22M4N4NOO---1111  !#G}}(."3"K"K # #.NN&:?&K%LC#PQ)44
+88&22em3US388^5KLem3e;US388^=ST [0!*m<<&001BHM  z';';'='C'C'EF{2!,>>(445FQ  |'='='?'E'E'GH+??);;
{2NN,\:mJ78;<
 NN-"9!:#>$R()-em.C DEQ}UZG[F\\_`$$SXX.	 }}(%'/SE1JJw_ /5b xx}i66rY   c                 n    U R                  XX45      u  pxnUR                  [        U 5      S-   5        XxU4$ )NrE   r  r   s	            rA   r  Text.render_debug  s@     -1KKi-
)M 	3t9t+,=00rY   r   N)r   r   r   r   r   r   r4  rN   r&  r0  rI   rM   r;  rJ  r   r  r   r  r  r   r   rY   rA   r.  r.  
  s    HHWc\""K&U4eUE6I0J+KU+R%S &>U5%3F-G(H U "$N% $NE-2F,G $NL I7,I7 I7  	I7
 I7 
sL%'	(I7 I7X 1 1rY   r.  c                   x    \ rS rSrSrS\S\\\4   4S jr\	SSS\
S	\S
\S\\\\4   4
S j5       r\	S 5       rSrg)ImplicitClosei  zk
A path close element that is conditionally rendered depending on the value of
`GraphicsStyle.auto_close`.
r  rm   c                 .    [         R                  5       U4$ zAReturn an empty bounding box; Close does not affect the geometry.rl   r   r  s     rA   r  ImplicitClose.bounding_box        "E))rY   r  r0   r   r  r  c                 4    UR                   (       a  SX44$ SX44$ )  
Render this path element to its PDF representation.

Args:
    resource_registry (ResourceCatalog): the owner's graphics state
        dictionary registry.
    style (GraphicsStyle): the current resolved graphics style
    last_item: the previous path element.
    initial_point: last position set by a "M" or "m" command

Returns:
    a tuple of `(str, new_last_item)`, where `new_last_item` is whatever the old
    last_item was.
r  r  )rK  r  s        rA   r  ImplicitClose.render  s#    . 	009++rY   c                 b    U R                  XX45      u  pxnUR                  U  SU S35        XxU4$ )a  
Render this path element to its PDF representation and produce debug
information.

Args:
    resource_registry (ResourceCatalog): the owner's graphics state
        dictionary registry.
    style (GraphicsStyle): the current resolved graphics style
    last_item: the previous path element.
    initial_point: last position set by a "M" or "m" command
    debug_stream (io.TextIO): the stream to which the debug output should be
        written. This is not guaranteed to be seekable (e.g. it may be stdout or
        stderr).
    pfx (str): the current debug output prefix string (only needed if emitting
        more than one line).

Returns:
    The same tuple as `ImplicitClose.render`.
r  rE   r  r   s	            rA   r  ImplicitClose.render_debug  r  rY   r   Nr   r   r   r   r   r   rN   rl   r  r   r   r  rI   r  r  r   r   rY   rA   r{  r{    s    *% *E+u2D,E *
 ,,, , 	,
 , 
sJ%	&, ,6 1 1rY   r{  c                   x    \ rS rSrSrS\S\\\4   4S jr\	SSS\
S	\S
\S\\\\4   4
S j5       r\	S 5       rSrg)r  i&  z
A path close element.

Instructs the renderer to draw a straight line from the end of the last path element
to the start of the current path.

See: `PaintedPath.close`
r  rm   c                 .    [         R                  5       U4$ r}  r~  r  s     rA   r  Close.bounding_box1  r  rY   r  r0   r   r  r  c                     S[        U5      U4$ )r  r  )r  r  s        rA   r  Close.render6  s    . D'66rY   c                 n    U R                  XX45      u  pxnUR                  [        U 5      S-   5        XxU4$ )a  
Render this path element to its PDF representation and produce debug
information.

Args:
    resource_registry (ResourceCatalog): the owner's graphics state
        dictionary registry.
    style (GraphicsStyle): the current resolved graphics style
    last_item: the previous path element.
    initial_point: last position set by a "M" or "m" command
    debug_stream (io.TextIO): the stream to which the debug output should be
        written. This is not guaranteed to be seekable (e.g. it may be stdout or
        stderr).
    pfx (str): the current debug output prefix string (only needed if emitting
        more than one line).

Returns:
    The same tuple as `Close.render`.
rE   r  r   s	            rA   r  Close.render_debugO  r!  rY   r   Nr  r   rY   rA   r  r  &  s    *% *E+u2D,E *
 7,7 7 	7
 7 
sJ%	&7 70 1 1rY   r  r  moverelative_movelinerelative_line)r   horizontal_linerelative_horizontal_line)r   vertical_linerelative_vertical_liner}  bezier_curverelative_bezier_curver  quadratic_bezier_curverelative_quadratic_bezier_curveFr  r  relative_arc)r  r  	rectangle)r  r  r  rounded_rectangle)r  r  ellipser  z
Sans serif      (@r'  r(  r)  r  )r   r   r/  r'  implicit_closeclosec                       \ rS rSrSrSrS r SS\S   S\SS	4S
 jjr	\
S\S\S\S\\\   \\4   4S j5       rSSS\S\S\S\S\4S jrS rSrg	)DrawingContexti  z
Base context for a drawing in a PDF

This context is not stylable and is mainly responsible for transforming path
drawing coordinates into user coordinates (i.e. it ensures that the output drawing
is correctly scaled).
	_subitemsc                     / U l         g r=   r  r   s    rA   ri   DrawingContext.__init__  s	    TVrY   r  )GraphicsContextPaintedPathPaintComposite_copyrm   Nc                     [        U[        [        [        45      (       d  [	        U S35      eU(       a  [        U5      nU R                  R                  U5        g)ag  
Append an item to this drawing context

Args:
    item (GraphicsContext, PaintedPath): the item to be appended.
    _copy (bool): if true (the default), the item will be copied before being
        appended. This prevents modifications to a referenced object from
        "retroactively" altering its style/shape and should be disabled with
        caution.
z# doesn't belong in a DrawingContextN)rF   r  r  r  rT   r   r  rS   rh   r  r  s      rA   add_itemDrawingContext.add_item  sI      $+~ NOOtf$GHIID>Dd#rY   first_pointr  rx   c                    SU l         [        R                  U l        [        R
                  U l        [        U5      n[        R                  " SSS9R                  SUS-  S9R                  U5      R                  U5      u  p$SU/nXPU4$ )NTr   r   r2  r   rc  r`  )rK  r    r  rI  r   r  rL  r  r   r  aboutr  r  )r   r  r  rx   r  r  s         rA   _setup_render_prereqs$DrawingContext._setup_render_prereqs  s      (--"2":":%	R(UQ&1*U%U5\VI	 	 El9,,rY   r  r0   starting_stylec                    U R                   (       d  gU R                  XRX45      u  pgnU R                    H2  n	U	R                  XX5      u  pnU
(       d  M!  UR                  U
5        M4     [	        U5      S:X  a  gUR
                  (       aa  UR
                  [        R                  LaD  UR
                  R                  S:X  a*  UR                  UR
                  5      UR
                  l        UR                  U5      nUb]  UR                  S[        U5       S35        UR                  S[        UR                  5      S[        UR                  5       S3-   5        UR                  S5        SR!                  U5      $ )	a  
Render the drawing context to PDF format.

Args:
    resource_registry (ResourceCatalog): the parent document's graphics
        state registry.
    first_point (Point): the starting point to use if the first path element is
        a relative element.
    scale (Number): the scale factor to convert from PDF pt units into the
        document's semantic units (e.g. mm or in).
    height (Number): the page height. This is used to remap the coordinates to
        be from the top-left corner of the page (matching fpdf's behavior)
        instead of the PDF native behavior of bottom-left.
    starting_style (GraphicsStyle): the base style for this drawing context,
        derived from the document's current style defaults.

Returns:
    A string composed of the PDF representation of all the paths and groups in
    this context (an empty string is returned if there are no paths or groups)
r  rc  r   r\  rZ  r;   r]  ra  )r  r  r  rS   r2  rV  r   r   	object_idregister_soft_maskrd  insertr>   rT  r   rU  rO   )rh   r  r  r  rx   r  r  r   r  r  r  rs  s               rA   r  DrawingContext.render  sT   8 ~~(,(B(B)
%I NND/3{{!)0,H x""8, # {q  OO}'<'<<))Q.(9(L(L)EOO% ,CCEJ&q%9/%J$K3"OP$U%>%>?mE$;$;<=R@A 	3xx$$rY   c                    U R                  XRX45      u  pxn	UR                  S5        U R                  SS  HC  n
UR                  S5        U
R                  XXS5      u  pU(       d  M2  UR	                  U5        ME     U R                  (       Gab  UR                  S5        U R                  S   R                  XXUS5      u  pnU(       a  UR	                  U5        [        U5      S:X  a  g	UR                  (       aa  UR                  [        R                  LaD  UR                  R                  S
:X  a*  UR                  UR                  5      UR                  l	        UR                  U5      nUb]  UR                  S[        U5       S35        UR                  S[        UR                  5      S[        UR                   5       S3-   5        UR	                  S5        SR#                  U5      $ g	)a  
Render the drawing context to PDF format.

Args:
    resource_registry (ResourceCatalog): the parent document's graphics
        state registry.
    first_point (Point): the starting point to use if the first path element is
        a relative element.
    scale (Number): the scale factor to convert from PDF pt units into the
        document's semantic units (e.g. mm or in).
    height (Number): the page height. This is used to remap the coordinates to
        be from the top-left corner of the page (matching fpdf's behavior)
        instead of the PDF native behavior of bottom-left.
    starting_style (GraphicsStyle): the base style for this drawing context,
        derived from the document's current style defaults.
    debug_stream (TextIO): a text stream to which a debug representation of the
        drawing structure will be written.

Returns:
    A string composed of the PDF representation of all the paths and groups in
    this context (an empty string is returned if there are no paths or groups)
zROOT
Nr   r      │  r      rc  r  r   r\  rZ  r;   r]  ra  )r  r  r  r  rS   r2  rV  r   r   r  r  rd  r  r>   rT  r   rU  rO   )rh   r  r  r  rx   r  r  r  r   r  r^  r  rs  s                rA   r  DrawingContext.render_debug  s   > )-(B(B)
%I 	8$^^CR(Ez*"'"4"4!)8#H x""8, ) >>>z*/3~~b/A/N/N!),PV0,H ""8, ;1$ OO=+@+@@OO--2,=,P,POO-) 0GGNO*""1)=o)N(Os&ST""()B)BC-(?(?@ADE s#88K((rY   T)r   r   r   r   r   r   ri   r   rL   r  r  r   r   rN   rM   rI   r   r  r  r  r  r   r   rY   rA   r  r    s     IW $FG$ $ 
	$0 -!-*/-9>-	tCy-3	4- -&B%,B% B% 	B%
 B% &B% 
B%HNrY   r  c                      \ rS rSrSrSrS=S\S\SS4S jjrS	 r\	S\
4S
 j5       r\	S\\   4S j5       r\R                  S\SS4S j5       r\	S\4S j5       r\R                  S\SS4S j5       r\	S\4S j5       r\R                  S\SS4S j5       r\	S 5       r\R                  S 5       rS r\S>S j5       r\S 5       rS>S jrS rS=S jrS rS rS rS rS  r S! r!S" r"S# r#S$ r$S% r%S& r&S' r'S( r(S) r)S* r*S+ r+S,S-S.S/S0.S\S\S1\,S2\,S3\,S4\S5\,4S6 jjr-S7 r.S8 r/ S>S/\0S\1\2\04   4S9 jjr3  S?S: jr4S; r5S<r6g)@r  ih  aJ  
A path to be drawn by the PDF renderer.

A painted path is defined by a style and an arbitrary sequence of path elements,
which include the primitive path elements (`Move`, `Line`, `BezierCurve`, ...) as
well as arbitrarily nested `GraphicsContext` containing their own sequence of
primitive path elements and `GraphicsContext`.
)_root_graphics_context_graphics_context_closed_close_context_starter_mover   r   rm   Nc                     [        5       U l        U R                  U l        SU l        U R                  U l        [        [        X5      5      U l        g )NT)r  r  r  r  r  r  r   r  rh   r   r   s      rA   ri   PaintedPath.__init__z  sA    7F7H#262M2M!/3/E/E)-eAk):rY   c                    U R                   U R                  La  [        SU  S35      eU R                  5       n[	        U R                  U5      Ul        UR                  Ul         U R
                  Ul        UR                   Ul        U$ )Nzcannot copy path z while it is being modified)r  r  rv   rf  r   r  r  rh   rk  copieds      rA   rm  PaintedPath.__deepcopy__  s{     !!)D)DD!24&8STUU!(01L1Ld(S%#)#@#@  & 8 8rY   c                 .    U R                   R                  $ )z9The `GraphicsStyle` applied to all elements of this path.)r  r   r   s    rA   r   PaintedPath.style  s     **000rY   c                 .    U R                   R                  $ )zAThe `Transform` that applies to all of the elements of this path.r  r  r   s    rA   r  PaintedPath.transform  s     **444rY   r   c                 $    XR                   l        g r=   r  rh   r   s     rA   r  r    s    02##-rY   c                 .    U R                   R                  $ )zDIf true, the path should automatically close itself before painting.r   rK  r   s    rA   rK  PaintedPath.auto_close       zz$$$rY   shouldc                 $    XR                   l        g r=   r  )rh   r  s     rA   rK  r    s     &

rY   c                 .    U R                   R                  $ )zCManually specify the `PathPaintRule` to use for rendering the path.r   rI  r   s    rA   rI  PaintedPath.paint_rule  r  rY   r   c                 $    XR                   l        g r=   r  )rh   r   s     rA   rI  r    s     %

rY   c                 .    U R                   R                  $ )z$Set the clipping path for this path.r  clipping_pathr   s    rA   r  PaintedPath.clipping_path  s     **888rY   c                 $    XR                   l        g r=   r  rh   new_clipaths     rA   r  r    s    4?##1rY   c                     U R                   $ r=   )r  r   s    rA   get_graphics_context PaintedPath.get_graphics_context  s    %%%rY   c              #      #    U R                   n[        5       nX0l          Uv   U(       a  UR                  U5        X l         g ! X l         f = f7fr=   )r  r  r  )rh   _attachold_graphics_contextnew_graphics_contexts       rA   _new_graphics_context!PaintedPath._new_graphics_context  sJ     #55.0!5	:&&$--.BC%9"%9"s   AA AAAc              #   t   #    U R                  5        nXl        U v   SSS5        g! , (       d  f       g= f7f)zI
Apply the provided `Transform` to all points added within this context.
N)r  r  )rh   r  ctxts      rA   transform_groupPaintedPath.transform_group  s*     
 '')T&NJ *))s   8'	8
58c                     U R                   bC  SU l        U R                  R                  U R                   SS9  U R                  U l        SU l         U R                  R                  XS9  g)aY  
Add the given element as a path item of this path.

Args:
    item: the item to add to this path.
    _copy (bool): if true (the default), the item will be copied before being
        appended. This prevents modifications to a referenced object from
        "retroactively" altering its style/shape and should be disabled with
        caution.
NFr  )r  r  r  r  r  r  s      rA   add_path_elementPaintedPath.add_path_element  sc     ) DL""++D,>,>e+L"&"8"8D!%D''':rY   c                 8    U R                   R                  5         g r=   )r  remove_last_itemr   s    rA   remove_last_path_element$PaintedPath.remove_last_path_element  s    //1rY   c           
          U R                  5         U R                  [        [        X5      [        X45      [        XV5      5      SS9  SU l        U R                  X5        U $ )aR  
Append a rectangle as a closed subpath to the current path.

If the width or the height are 0, the rectangle will be collapsed to a line
(unless they're both 0, in which case it's collapsed to nothing).

Args:
    x (Number): the abscissa of the starting corner of the rectangle.
    y (Number): the ordinate of the starting corner of the rectangle.
    w (Number): the width of the rectangle (if 0, the rectangle will be
        rendered as a vertical line).
    h (Number): the height of the rectangle (if 0, the rectangle will be
        rendered as a horizontal line).
    rx (Number): the x-radius of the rectangle rounded corner (if 0 the corners
        will not be rounded).
    ry (Number): the y-radius of the rectangle rounded corner (if 0 the corners
        will not be rounded).

Returns:
    The path, to allow chaining method calls.
Fr  T)_insert_implicit_close_if_openr  r  r   r  move_to)rh   r   r   r  r  r  r  s          rA   r  PaintedPath.rectangle  sW    . 	++-U1[%+uR}EU 	 	
 QrY   c                 &    U R                  XX35      $ )a  
Append a circle as a closed subpath to the current path.

Args:
    cx (Number): the abscissa of the circle's center point.
    cy (Number): the ordinate of the circle's center point.
    r (Number): the radius of the circle.

Returns:
    The path, to allow chaining method calls.
)r  )rh   r   r   r   s       rA   circlePaintedPath.circle	  s     ||BA))rY   c           	          U R                  5         U R                  [        [        X45      [        X5      5      SS9  SU l        U R                  X5        U $ )aQ  
Append an ellipse as a closed subpath to the current path.

Args:
    cx (Number): the abscissa of the ellipse's center point.
    cy (Number): the ordinate of the ellipse's center point.
    rx (Number): the x-radius of the ellipse.
    ry (Number): the y-radius of the ellipse.

Returns:
    The path, to allow chaining method calls.
Fr  T)r  r  r  r   r  r  )rh   r   r   r  r  s        rA   r  PaintedPath.ellipse  sJ     	++-geBmU2]C5QRrY   c                 X    U R                  5         [        [        X5      5      U l        U $ )a  
Start a new subpath or move the path starting point.

If no path elements have been added yet, this will change the path starting
point. If path elements have been added, this will insert an implicit close in
order to start a new subpath.

Args:
    x (Number): abscissa of the (sub)path starting point.
    y (Number): ordinate of the (sub)path starting point.

Returns:
    The path, to allow chaining method calls.
)r  r  r   r  r  s      rA   r  PaintedPath.move_to+  s&     	++-!%+.rY   c                     U R                  5         U R                  b<  SU l        U R                  R	                  U R                  SS9  U R                  U l        [        [        X5      5      U l        U $ )a  
Start a new subpath or move the path start point relative to the previous point.

If no path elements have been added yet, this will change the path starting
point. If path elements have been added, this will insert an implicit close in
order to start a new subpath.

This will overwrite an absolute move_to as long as no non-move path items have
been appended. The relative position is resolved from the previous item when
the path is being rendered, or from 0, 0 if it is the first item.

Args:
    x (Number): abscissa of the (sub)path starting point relative to the previous point.
    y (Number): ordinate of the (sub)path starting point relative to the previous point.
Fr  )r  r  r  r  r  r  r	  r   r  s      rA   move_relativePaintedPath.move_relative>  sf      	++-) DL""++D,>,>e+L"&"8"8D)%+6rY   c                 J    U R                  [        [        X5      5      SS9  U $ )z
Append a straight line to this path.

Args:
    x (Number): abscissa the line's end point.
    y (Number): ordinate of the line's end point.

Returns:
    The path, to allow chaining method calls.
Fr  )r  r  r   r  s      rA   line_toPaintedPath.line_toV  s%     	d5;/u=rY   c                 J    U R                  [        [        X5      5      SS9  U $ )a  
Append a straight line whose end is computed as an offset from the end of the
previous path element.

Args:
    x (Number): abscissa the line's end point relative to the end point of the
        previous path element.
    y (Number): ordinate of the line's end point relative to the end point of
        the previous path element.

Returns:
    The path, to allow chaining method calls.
Fr  )r  r#  r   r   s      rA   line_relativePaintedPath.line_relatived  s%     	l5=9GrY   c                 8    U R                  [        U5      SS9  U $ )z
Append a straight horizontal line to the given abscissa. The ordinate is
retrieved from the end point of the previous path element.

Args:
    x (Number): abscissa of the line's end point.

Returns:
    The path, to allow chaining method calls.
Fr  )r  r,  )rh   r   s     rA   horizontal_line_toPaintedPath.horizontal_line_tou  s!     	nQ/u=rY   c                 8    U R                  [        U5      SS9  U $ )aR  
Append a straight horizontal line to the given offset from the previous path
element. The ordinate is retrieved from the end point of the previous path
element.

Args:
    x (Number): abscissa of the line's end point relative to the end point of
        the previous path element.

Returns:
    The path, to allow chaining method calls.
Fr  )r  r9  )rh   r   s     rA   horizontal_line_relative$PaintedPath.horizontal_line_relative  s"     	4R8FrY   c                 8    U R                  [        U5      SS9  U $ )z
Append a straight vertical line to the given ordinate. The abscissa is
retrieved from the end point of the previous path element.

Args:
    y (Number): ordinate of the line's end point.

Returns:
    The path, to allow chaining method calls.
Fr  )r  rC  )rh   r   s     rA   vertical_line_toPaintedPath.vertical_line_to  s      	l1oU;rY   c                 8    U R                  [        U5      SS9  U $ )aP  
Append a straight vertical line to the given offset from the previous path
element. The abscissa is retrieved from the end point of the previous path
element.

Args:
    y (Number): ordinate of the line's end point relative to the end point of
        the previous path element.

Returns:
    The path, to allow chaining method calls.
Fr  )r  rL  )rh   r   s     rA   vertical_line_relative"PaintedPath.vertical_line_relative  s"     	226eDrY   c                 |    [        X5      n[        X45      n[        XV5      n	U R                  [        XxU	5      SS9  U $ )u  
Append a cubic Bézier curve to this path.

Args:
    x1 (Number): abscissa of the first control point
    y1 (Number): ordinate of the first control point
    x2 (Number): abscissa of the second control point
    y2 (Number): ordinate of the second control point
    x3 (Number): abscissa of the end point
    y3 (Number): ordinate of the end point

Returns:
    The path, to allow chaining method calls.
Fr  )r   r  rg  )
rh   r   r   r   r   x3y3r  r  r  s
             rA   curve_toPaintedPath.curve_to  s>     bbBmk%<EJrY   c                 |    [        X5      n[        X45      n[        XV5      n	U R                  [        XxU	5      SS9  U $ )u  
Append a cubic Bézier curve whose points are expressed relative to the
end point of the previous path element.

E.g. with a start point of (0, 0), given (1, 1), (2, 2), (3, 3), the output
curve would have the points:

(0, 0) c1 (1, 1) c2 (3, 3) e (6, 6)

Args:
    dx1 (Number): abscissa of the first control point relative to the end point
        of the previous path element
    dy1 (Number): ordinate of the first control point relative to the end point
        of the previous path element
    dx2 (Number): abscissa offset of the second control point relative to the
        end point of the previous path element
    dy2 (Number): ordinate offset of the second control point relative to the
        end point of the previous path element
    dx3 (Number): abscissa offset of the end point relative to the end point of
        the previous path element
    dy3 (Number): ordinate offset of the end point relative to the end point of
        the previous path element

Returns:
    The path, to allow chaining method calls.
Fr  )r   r  ry  )
rh   dx1dy1dx2dy2dx3dy3c1dc2dr  s
             rA   curve_relativePaintedPath.curve_relative  s?    6 CoCoCo1#C@NrY   c                 d    [        X5      n[        X45      nU R                  [        XV5      SS9  U $ )uB  
Append a cubic Bézier curve mimicking the specified quadratic Bézier curve.

Args:
    x1 (Number): abscissa of the control point
    y1 (Number): ordinate of the control point
    x2 (Number): abscissa of the end point
    y2 (Number): ordinate of the end point

Returns:
    The path, to allow chaining method calls.
Fr  )r   r  r  )rh   r   r   r   r   r  r  s          rA   quadratic_curve_toPaintedPath.quadratic_curve_to  s4     R}Bm24=UKrY   c                 d    [        X5      n[        X45      nU R                  [        XV5      SS9  U $ )uP  
Append a cubic Bézier curve mimicking the specified quadratic Bézier curve.

Args:
    dx1 (Number): abscissa of the control point relative to the end point of
        the previous path element
    dy1 (Number): ordinate of the control point relative to the end point of
        the previous path element
    dx2 (Number): abscissa offset of the end point relative to the end point of
        the previous path element
    dy2 (Number): ordinate offset of the end point relative to the end point of
        the previous path element

Returns:
    The path, to allow chaining method calls.
Fr  )r   r  r  )rh   r   r!  r"  r#  r  r  s          rA   quadratic_curve_relative$PaintedPath.quadratic_curve_relative  s4    " SCo:4EUSrY   c           	          US:X  d  US:X  a  U R                  Xg5      $ [        [        U5      [        U5      5      n[        U5      n[        R
                  " U5      n[        U5      n[        Xg5      n	U R                  [        XXEU	5      SS9  U $ )u  
Append an elliptical arc from the end of the previous path point to the
specified end point.

The arc is approximated using Bézier curves, so it is not perfectly accurate.
However, the error is small enough to not be noticeable at any reasonable
(and even most unreasonable) scales, with a worst-case deviation of around 3‱.

Notes:
    - The signs of the radii arguments (`rx` and `ry`) are ignored (i.e. their
      absolute values are used instead).
    - If either radius is 0, then a straight line will be emitted instead of an
      arc.
    - If the radii are too small for the arc to reach from the current point to
      the specified end point (`x` and `y`), then they will be proportionally
      scaled up until they are big enough, which will always result in a
      half-ellipse arc (i.e. an 180 degree sweep)

Args:
    rx (Number): radius in the x-direction.
    ry (Number): radius in the y-direction.
    rotation (Number): angle (in degrees) that the arc should be rotated
        clockwise from the principle axes. This parameter does not have
        a visual effect in the case that `rx == ry`.
    large_arc (bool): if True, the arc will cover a sweep angle of at least 180
        degrees. Otherwise, the sweep angle will be at most 180 degrees.
    positive_sweep (bool): if True, the arc will be swept over a positive angle,
        i.e. clockwise. Otherwise, the arc will be swept over a negative
        angle.
    x (Number): abscissa of the arc's end point.
    y (Number): ordinate of the arc's end point.
r   Fr  )r	  r   r*  rL   r  radiansr  r  )
rh   r  r  r  	large_arcpositive_sweepr   r   r  r  s
             rA   arc_toPaintedPath.arc_to  s    D 7bAg<<%%c"gs2w'O	<<)n-AkC@ 	 	
 rY   c           	          US:X  d  US:X  a  U R                  Xg5      $ [        [        U5      [        U5      5      n[        U5      n[        R
                  " U5      n[        U5      n[        Xg5      n	U R                  [        XXEU	5      SS9  U $ )u~  
Append an elliptical arc from the end of the previous path point to an offset
point.

The arc is approximated using Bézier curves, so it is not perfectly accurate.
However, the error is small enough to not be noticeable at any reasonable
(and even most unreasonable) scales, with a worst-case deviation of around 3‱.

Notes:
    - The signs of the radii arguments (`rx` and `ry`) are ignored (i.e. their
      absolute values are used instead).
    - If either radius is 0, then a straight line will be emitted instead of an
      arc.
    - If the radii are too small for the arc to reach from the current point to
      the specified end point (`x` and `y`), then they will be proportionally
      scaled up until they are big enough, which will always result in a
      half-ellipse arc (i.e. an 180 degree sweep)

Args:
    rx (Number): radius in the x-direction.
    ry (Number): radius in the y-direction.
    rotation (Number): angle (in degrees) that the arc should be rotated
        clockwise from the principle axes. This parameter does not have
        a visual effect in the case that `rx == ry`.
    large_arc (bool): if True, the arc will cover a sweep angle of at least 180
        degrees. Otherwise, the sweep angle will be at most 180 degrees.
    positive_sweep (bool): if True, the arc will be swept over a positive angle,
        i.e. clockwise. Otherwise, the arc will be swept over a negative
        angle.
    dx (Number): abscissa of the arc's end point relative to the end point of
        the previous path element.
    dy (Number): ordinate of the arc's end point relative to the end point of
        the previous path element.
r   Fr  )r  r   r*  rL   r  r1  r  r  )
rh   r  r  r  r2  r3  r   r   r  r  s
             rA   arc_relativePaintedPath.arc_relativeA  s    F 7bAg%%b--c"gs2w'O	<<)n-BmCHPU 	 	
 rY   	helveticar  r  r  )font_family
font_style	font_sizer0  contentr:  r;  r<  r0  c                    SR                  [        UR                  5       5      5      nU R                  [	        UU[        UUUUS94US9SS9  U $ )a$  
Append a text run at (x, y) to this path.

The baseline is at (x, y). `text_anchor` controls alignment about x.
`font_style` accepts "", "B", "I", or "BI". `font_family` can be a single
name or a comma-separated fallback list (handled at render-time).

Returns:
    self (to allow chaining)
r  r  )r   r   r/  r0  Fr  )rO   sortedrf  r  r.  r&  )	rh   r   r   r=  r:  r;  r<  r0  rl  s	            rA   r'  PaintedPath.textr  sk    , GGF:++-./$*!"&	 (  	 	
  rY   c                 f    U R                  [        5       SS9  SU l        U R                  SS5        g)z)
Explicitly close the current (sub)path.
Fr  Tr   N)r  r  r  r  r   s    rA   r  PaintedPath.close  s0     	egU31a rY   c                     U R                   (       d;  U R                  R                  [        5       SS9  U R                  U l        SU l         g g )NFr  T)r  r  r  r{  r  r   s    rA   r  *PaintedPath._insert_implicit_close_if_open  s>    ||(((F"&"8"8DDL rY   c                 J    U R                   R                  XR                  US9$ )z]Compute the bounding box of this painted path, including nested contexts and transformations.expand_for_stroke)r  r  r   )rh   r  rG  s      rA   r  PaintedPath.bounding_box  s,     **77::1B 8 
 	
rY   c                    U R                  5         U R                  R                  XX4XV5      u  nnn[        R	                  X R
                  5      R                  5       nUR                  SUR                  5        SR                  U5      X44$ )Nr   r;   )
r  r  build_render_listr   r   r   r   r  rE  rO   )	rh   r  r   r  r  r  r  r  rI  s	            rA   r  PaintedPath.render  s     	++- ''99i
		

 #((

;NNP
2z//0xx$i>>rY   c                 (    U R                  XX4XV5      $ )a  
Render this path element to its PDF representation and produce debug
information.

Args:
    resource_registry (ResourceCatalog): the owner's graphics state
        dictionary registry.
    style (GraphicsStyle): the current resolved graphics style
    last_item: the previous path element.
    initial_point: last position set by a "M" or "m" command
    debug_stream (io.TextIO): the stream to which the debug output should be
        written. This is not guaranteed to be seekable (e.g. it may be stdout or
        stderr).
    pfx (str): the current debug output prefix string (only needed if emitting
        more than one line).

Returns:
    The same tuple as `PaintedPath.render`.
r  r  s          rA   r  PaintedPath.render_debug  s    , {{i
 	
rY   )r  r  r  r  r  r   r   r  NN)7r   r   r   r   r   r   r   ri   rm  r6  r   r   r
   r   r  r  rL   rK  r    rI  r  r  r   r  r  r  r  r  r  r  r  r  r	  r  r  r  r  r  r  r(  r+  r.  r4  r7  rI   r'  r  r  r   rN   rl   r  r  r  r   r   rY   rA   r  r  h  sn   I;% ; ;d ; 1} 1 1 58I. 5 5 3I 3$ 3 3 %D % % ' '$ ' ' %M % % & &$ & & 9 9 @ @& 	: 	:  ;&2@*(&0"  , D$,.`/n '"(( ( 	( ( ( ( (T!  /3

	{E!	"
 ?.
rY   r  c                   H   ^  \ rS rSrSrSrSU 4S jjr  S	S jrS rSr	U =r
$ )
ClippingPathi  a  
The PaintedPath API but to be used to create clipping paths.

.. warning::
    Unless you really know what you're doing, changing attributes of the clipping
    path style is likely to produce unexpected results. This is because the
    clipping path styles override implicit style inheritance of the `PaintedPath`
    it applies to.

    For example, `clippath.style.stroke_width = 2` can unexpectedly override
    `paintpath.style.stroke_width = GraphicsStyle.INHERIT` and cause the painted
    path to be rendered with a stroke of 2 instead of what it would have normally
    inherited. Because a `ClippingPath` can be painted like a normal `PaintedPath`,
    it would be overly restrictive to remove the ability to style it, so instead
    this warning is here.
r   c                 J   > [         TU ]  XS9  [        R                  U l        g )Nr2  )rr  ri   r    r}  rI  )rh   r   r   rf  s      rA   ri   ClippingPath.__init__  s     1"'22rY   c           
         U(       a  UR                  S5        U R                  R                  UUUUUUSS9u  nnn[        R	                  X R
                  5      nUR                  n	XR                  L a  [        R                  n	O[        U	R                     n	UR                  5       n
UR                  U	R                  5        UR                  U
R                  5        SR                  U5      X44$ )Nz<ClippingPath> F_push_stackr;   )r  r  rJ  r   r   r   rL  r   r   r  rs  r   rS   rE  rO   )rh   r  r   r  r  r  r  r  rr  rL  rI  s              rA   r  ClippingPath.render  s      01 ''99 : 
		
 %**5**=(:: 4 44 < D D <!&&! "446
,223:++,xx$i>>rY   c                 (    U R                  XX4XV5      $ )av  
Render this path element to its PDF representation and produce debug
information.

Args:
    resource_registry (ResourceCatalog): the owner's graphics state
        dictionary registry.
    style (GraphicsStyle): the current resolved graphics style
    last_item: the previous path element.
    debug_stream (io.TextIO): the stream to which the debug output should be
        written. This is not guaranteed to be seekable (e.g. it may be stdout or
        stderr).
    pfx (str): the current debug output prefix string (only needed if emitting
        more than one line).

Returns:
    The same tuple as `ClippingPath.render`.
r  r  s          rA   r  ClippingPath.render_debug8  s    * {{i
 	
rY   )rI  rN  rO  )r   r   r   r   r   r   ri   r  r  r   r  r  s   @rA   rQ  rQ    s,    " I3 0?d
 
rY   rQ  c                      \ rS rSrSrSrS rS r\S\	\
   4S j5       r\R                  S\
SS	4S
 j5       r\S\	\   4S j5       r\R                  S\SS	4S j5       rS"S\S\SS	4S jjrS#S jrS$S jr\   S%SSS\S\S\S\	\   S\4S jj5       r   S&S\S\	\   S\S\S\\\4   4
S jjr   S%SSS\S\S\S\\\\4   4
S jjr S"S  jrS!rg	)'r  iR  uO  
Page-level container that collects drawable items and renders them into a PDF
content stream.

Converts model coordinates to PDF user space by applying the provided
`scale` and a vertical flip so (0, 0) is the top-left of the page.

Wraps output in a saved graphics state (`q … Q`) and registers any
required resources (graphics state dictionaries, soft masks, dash pattern).

Child items are typically `GraphicsContext`, `PaintedPath`, or `PaintComposite`
objects added via `add_item()`. By default, items are deep-copied on insert to
avoid later mutations affecting the emitted stream.
)r   
path_items
_transform_clipping_pathc                 L    [        5       U l        / U l        S U l        S U l        g r=   )r   r   r[  r\  r]  r   s    rA   ri   GraphicsContext.__init__d  s!    $1O
,./36:rY   c                     U R                  5       n[        U R                  U5      Ul        [        U R                  U5      Ul        [        U R                  U5      Ul        [        U R                  U5      Ul        U$ r=   )rf  r   r   r[  r  r\  r  r]  r  s      rA   rm  GraphicsContext.__deepcopy__k  s`    !

D1$T__d;$T^^T: (););T BrY   rm   c                     U R                   $ r=   r\  r   s    rA   r  GraphicsContext.transforms  s    rY   r   Nc                     Xl         g r=   rc  r  s     rA   r  rd  w  s    rY   c                     U R                   $ )z-The `ClippingPath` for this graphics context.r]  r   s    rA   r  GraphicsContext.clipping_path{  s     """rY   r  c                     Xl         g r=   rg  r  s     rA   r  rh    s    )rY   r  r  c                 ^    U(       a  [        U5      nU R                  R                  U5        g)a  
Add a path element to this graphics context.

Args:
    item: the path element to add. May be a primitive element or another
        `GraphicsContext` or a `PaintedPath`.
    _copy (bool): if true (the default), the item will be copied before being
        appended. This prevents modifications to a referenced object from
        "retroactively" altering its style/shape and should be disabled with
        caution.
N)r   r[  rS   r  s      rA   r  GraphicsContext.add_item  s"     D>Dt$rY   c                     U R                   S	 g )Nr   )r[  r   s    rA   r   GraphicsContext.remove_last_item  s    OOBrY   c                 N    U R                   R                  UR                   5        g)z:Copy another `GraphicsContext`'s path items into this one.N)r[  rg  )rh   other_contexts     rA   r   GraphicsContext.merge  s    }778rY   r  r0   r   r  r  r  rV  c           
      D  ^ ^^^ / nT R                   (       Ga  Ub&  UR                  T R                  R                   5        UR                  R	                  UT R
                  5      n	UGb  T R                  (       a  UR                  ST R                   S35        / n
U	R                   H^  n[        X5      nXR                  Ld  M  [        T R
                  U5      U	R                  L a  SnOSnU
R                  U SU U 35        M`     U
(       ae  UR                  S5        U
 H9  nUR                  US-   5        UR                  U5        UR                  S	5        M;     UR                  US
-   5        OUR                  S	5        SU	R                  4nT R
                  mU	R                  T R
                  R                  :w  a&  [        T R
                  5      mU	R                  Tl        U	R                  nU	R                  nSnUUR                  :w  d  UUR                  :w  a,  TT R
                  L a  [        T5      mUTl        UTl        UU4nTR                  (       aa  TR                  [         R                  LaD  TR                  R"                  S:X  a*  TR%                  TR                  5      TR                  l        T R'                  TT R
                  SS9S   nS[(        4UUUU 4S jjn[+        TR,                  [(        5      (       a=  TR                  S[         R                  4;   a  U" T R
                  R,                  5        O[[+        TR.                  [(        5      (       a<  TR                  S[         R                  4;   a  U" T R
                  R.                  5        TR1                  T5      nUb  UR                  [3        U5       S35        T R
                  R,                  nT R
                  R.                  nUU;  ad  [+        U[(        5      (       a"  UR                  UR5                  TU5      5        O-UR                  UR7                  5       R9                  5       5        UU;  ad  [+        U[(        5      (       a"  UR                  UR;                  TU5      5        O-UR                  UR7                  5       R=                  5       5        Ub0  UR                  [3        US   5      S[?        US   5       S3-   5        U(       Ga  T R@                  bS  UR                  US-   5        T R@                  RC                  TU	UTUUS-   5      u  nnnU(       a  UR                  U5        T R                   SS  HN  nUR                  US-   5        URC                  TU	UTUUS-   5      u  nnmU(       d  M=  UR                  U5        MP     UR                  US-   5        T R                   S   RC                  TU	UTUUS-   5      u  nnmU(       a  UR                  U5        OT R@                  b9  T R@                  RE                  TXT5      u  nnnU(       a  UR                  U5        T R                    H4  nURE                  TXT5      u  nnmU(       d  M#  UR                  U5        M6     T RF                  b.  URI                  ST RF                  RE                  U5      S   5        U(       a#  URI                  SS5        UR                  S5        XT4$ )aG  
Build a list composed of all all the individual elements rendered.

This is used by `PaintedPath` and `ClippingPath` to reuse the `GraphicsContext`
rendering process while still being able to inject some path specific items
(e.g. the painting directive) before the render is collapsed into a single
string.

Args:
    resource_registry (ResourceCatalog): the owner's graphics state
        dictionary registry.
    style (GraphicsStyle): the current resolved graphics style
    last_item: the previous path element.
    initial_point: last position set by a "M" or "m" command
    debug_stream (io.TextIO): the stream to which the debug output should be
        written. This is not guaranteed to be seekable (e.g. it may be stdout or
        stderr).
    pfx (str): the current debug output prefix string (only needed if emitting
        more than one line).
    _push_stack (bool): if True, wrap the resulting render list in a push/pop
        graphics stack directive pair.

Returns:
    `tuple[list[str], last_item]` where `last_item` is the past path element in
    this `GraphicsContext`
Nr4   r5   z (inherited)r  z: z {
r  rE   u   }┐
r   Fr   rG  	paint_objc                 h  > [        U [        5      (       d  g U R                  5       (       d  g T	R                  TT	R                  SSS9S   n[        5       nUR                  UR                  UR                  UR                  UR                  5        [        U R                  U R                  U R                  S9nU R                  Ul        X2R                  l        S UR                  l        SUR                  l        [&        R(                  UR                  l        [-        5       nUR/                  USS9  [1        USSU R                  S9nTR2                  SL a  g TT	R                  L a  [5        T	R                  5      mUTl        TR9                  TR6                  5      TR6                  l        g )NF)r   rG  r   r   )r_   r  T)invertuse_luminosityr~   )rF   r[   r   r  r   r  r  ry   rz   rw   rx   r   r]   r^   r_   r`   rM  rO  r   r    r  rI  r  r  r  rJ  r   rV  r  r  )
rs  bbox_for_units	mask_rectalpha_paintmask_gcsm
emit_styler  r  rh   s
         rA   _attach_alpha_mask_if_neededGGraphicsContext.build_render_list.<locals>._attach_alpha_mask_if_needed  s   !)];; **,,!%!2!2!**&+ %	 "3 "
 " (M	##"%%"%%"(("))	 2&&OO'0'C'C
 .7-E-E*-8*/3	,/0	,-:-G-G	*)+  % 8 # #'$77	 00E9+!)$**!5J')
$1B1U1U((2
$$.rY   r\  r;   r   r]  r  r  r   r  r`  ra  )%r[  r  rf  r   r   r   r\  r[  rH   r   rS   rJ  r   rT  rU  rV  r   r  r  r  r[   rF   rM  rO  rd  r>   r   r2   re  r   rf  r   r  r  r  r  r  )rh   r  r   r  r  r  r  rV  r  rr  
styles_dbgattrr@   	inheritedstyle_dbg_linern  ru  rv  	emit_dashrw  r}  rs  rM  rO  rendered_cpathr  __r  r  r|  s   ``  `                        @rA   rJ  !GraphicsContext.build_render_list  sa   J ???'""dnn&=&=%>@ ??00

CL'?? &&4??*;1'=>
(99D!,5C"6"66"4::t48L8LL(6I(*I"))TF"SE)*EF :  &&v.*4$**3<8$**>:$**40 +5
 !&&sX~6 &&t,!5!56KJ..$**2O2OO%djj1
0<0O0O
- (;;L%77JI 9 99!8!88+!)*!5J1=
./9
,):6	 $$((0E0EE((22a71B1U1U((2
$$.
 "..TZZ5 / N3 3 3n *//??$$}/D/D(EE,TZZ-B-BCJ33]CC$$}/D/D(EE,TZZ-D-DE/GG
SO*""&:?&K%LC#PQ ..J::22L,j-88&&",,->O  &&z';';'='C'C'EF;.lM::&&$001BNS  &&|'='='?'E'E'GH$""(16-	!56b9:
 %%1 &&sZ'78,0,>,>,K,K)$!%$h-)NAr &#**>: OOCR0D &&sZ'789=9J9J)$!%$h:6Hi  x#**84 1 ""3#3459__R5H5U5U% ! &L62)] &&x0 %%1,0,>,>,E,E)<M-)NAr &#**>: OOD9=)<M:6Hi  x#**84 , ~~)""1dnn&;&;I&Fq&IJ""1c*""3'}44rY   r  rG  r   c                 z  ^^^ [         R                  " 5       mSSS[        S[        [           S[         S[
        [        [        [        [        4   4
UUU4S jjmT" XUT5      u  pVpxUn	U(       aI  U(       a%  UR                  R                  X R                  5      OU R                  n
UR                  XU4S9n	X4$ )	z
Compute bbox of all path items. We:
1) recurse with accumulated CTM,
2) merge child bboxes already transformed to this level,
3) at the end, expand once for stroke using the worst-case CTM row norms.
ctxr  r  ambient_styleaccum_tfrm   c                 V  > [         R                  5       nX0R                  =(       d    T-  nT(       d  TnU(       a%  UR                  R	                  X R
                  5      OU R
                  nUR                  5       u  pxU R                   H  n	[        U	[        5      (       a7  T" XXe5      u  ppUR	                  U
5      nUn[        X|5      n[        X5      nMO  [        U	S5      (       d  Mb  U	R                  U5      u  pUR	                  UR                  U5      5      nUnM     XAXx4$ )Nr  )rl   r   r  rf  r   r   r   r[  rF   r  r   rp  r  r   )r  r  r  r  rk   r   rr  max_nxmax_nyr  
child_bboxr  cnxcny	item_bboxrf   r   walks                  rA   r  *GraphicsContext.bounding_box.<locals>.walk  s	    $$&D]]6h7B ! ''--mYYGYY   \\^NFdO446:\73J3  ::j1D$-M -F -FT>22+/+<+<]+K(I::i&;&;B&?@D$-M ' 66rY   )r   )r   rf   r   r
   r   rN   rl   r   rf  r   r   r  )rh   r  r   rG  r   	geom_bboxend_ptr  r  
final_bboxro  rf   r  s       `      @@rA   r  GraphicsContext.bounding_box  s     %%'!	7"!	7 !	7 $M2!	7  	!	7
 ;ue34!	7 !	7H %)eX$F!	2
 =B%%eZZ8tzz  #558 6 J !!rY   c           
      X    U R                  UUUUUUUS9u  pnSR                  U5      X44$ )NrU  r;   )rJ  rO   )	rh   r  r   r  r  r  r  rV  r  s	            rA   r  GraphicsContext.render  sJ     150F0F# 1G 1
- xx$i>>rY   c           
      ,    U R                  UUUUUUUS9$ )NrU  r  )rh   r  r   r  r  r  r  rV  s           rA   r  GraphicsContext.render_debug  s/     {{#  
 	
rY   )r]  r\  r[  r   r  )rm   N)ro  r  rm   N)NNT)NTT)r   r   r   r   r   r   ri   rm  r6  r
   r   r  r  rQ  r  r  rL   r  r  r   r   r   r   rI   rJ  rN   rl   r  r  r  r   r   rY   rA   r  r  R  s    HI; 8I.   I $   #x5 # # * *$ * *%Z % % %" 9  ! L5,L5 L5 	L5
 L5 c]L5 L5 L5b *."& ?"?" &?"  	?"
 ?" 
{E!	"?"N ?,? ? 	?
 ? 
sJ%	&?< 
rY   r  c                       \ rS rSrSrSrSS\R                  " 5       4S\\	\
4   S\4S jjrS rS	\\\\\4   4S
 jrS rS r\S\\	\
4   S	\\	\
4   4S j5       r\S	\\
   4S j5       r\ SS\\
   S\\	\
4   S\S\S   S	S 4
S jj5       rSrg)r  i  u  
Wraps a vector path as a PDF soft mask (SMask) that can be attached to a
graphics state.

The provided `mask_path` is deep-copied and forced to render as an opaque
grayscale fill (white, alpha=1, nonzero rule, transparency disabled). During
rendering, the mask’s content stream is generated and its resource
dictionary is collected so it can be embedded as a Form XObject and
referenced from an ExtGState.
)	mask_pathru  	resourcesrv  r  r~   Fr  ru  c                 V   [        U5      U l        X l        X0l        [	        5       U l        SU l        X@l        U R                  (       d`  [        R                  U R                  R                  l        SU R                  R                  l        SU R                  R                  l        g g )Nr   r   #ffffff)r   r  ru  rv  r  r  r  r~   r    r  r   rI  rN  rM  )rh   r  ru  rv  r~   s        rA   ri   PaintSoftMask.__init__,  sz     "),,"".;.H.HDNN  +01DNN  -.7DNN  +	 #rY   c                     U R                   (       a  SOSnU R                  (       a  SOSnSU SU R                   SU S3$ )	NzH /TR <</FunctionType 2 /Domain [0 1] /Range [0 1] /C0 [1] /C1 [0] /N 1>>r  z/Luminosityz/Alphaz<</S z /G  0 R>>)ru  rv  r  )rh   rp  	mask_types      rA   r2   PaintSoftMask.serialize@  sJ     {{ W 	
 &*%8%8Mh	ykdnn%5T"R@@rY   rm   c                 p    U R                   R                  [        SS5      5      u  pUR                  5       $ )Nr   )r  r  r   r  )rh   r  r  s      rA   get_bounding_boxPaintSoftMask.get_bounding_boxI  s-    ..55eAqkB$$&&rY   c           
      d  ^^ 0 nU R                    H8  u  pEUR                  UR                  [        5       5      R	                  U5        M:     / nSU;   a`  US   (       aV  UR                  [        S5      R                  5       S-   SR                  U4S j[        US   5       5       5      -   S-   5        SU;   a`  US   (       aV  UR                  [        S5      R                  5       S-   SR                  U4S j[        US   5       5       5      -   S-   5        SSR                  U5      -   S-   $ )zMBuild the resource dictionary for this soft mask, resolving GS & Pattern ids.r  <<r  c              3   |   >#    U  H1  n[        U5      R                  5        S TU   R                   S3v   M3     g7fr;   r  Nr,   r2   id)r?   gs_namegfxstate_objs_per_names     rA   rB   8PaintSoftMask.get_resource_dictionary.<locals>.<genexpr>Z  sA      #L G}..013I'3R3U3U2VVZ[#L   9<r  r&   c              3   |   >#    U  H1  n[        U5      R                  5        S TU   R                   S3v   M3     g7fr  r  )r?   pat_namepattern_objs_per_names     rA   rB   r  f  sA      $K H~//12!4I(4S4V4V3WW[\$Kr  )
r  
setdefaultrE  r  r   rS   r,   r2   rO   r?  )rh   r  r  resources_registeredresource_typeresource_idpartss    ``    rA   get_resource_dictionary%PaintSoftMask.get_resource_dictionaryM  s3   02*...&M ++M,?,?GKKKX +9  ..3G3TLL[!++-'' #)*>{*K#L   ,,1Ei1PLLY))+'' $*+?	+J$K   bggen$t++rY   c           	          U R                   R                  U[        5       S [        SS5      S9u  n  nUR	                  U5      U l        U$ Nr   )r   r  r  )r  r  r   r   scan_streamr  rh   r  streamr  s       rA   r  PaintSoftMask.rendern  sN    ~~,,/1+	 - 
1 +66v>rY   nodec                    ^ S[         4U4S jjm[        U 5      n[        U[         5      (       a  UOUR                  5       nT" U5        U$ )u  
Return a deep-copied version of *node* whose appearance encodes only its
geometric coverage: every shape is converted to an **opaque white fill**
(nonzero rule), with **no stroke**, no soft mask, and inherited blend mode.

The transform/clipping/structure of the original node is preserved; only
paint-related attributes are normalized. This is intended for building the
“B” term of soft-mask expressions (coverage), where inside = 1 and
outside = 0.
gcc                   > [         R                  U R                  l        SU R                  l        SU R                  l        S U R                  l        [        R                  U R                  l	        [        R                  U R                  l
        U R                   H  n[        U[        5      (       a
  T" U5        M"  [        U[        5      (       d  M9  [         R                  UR                  l        SUR                  l        SUR                  l        S UR                  l        [        R                  UR                  l	        [        R                  UR                  l
        M     g )Nr  r   )r    r  r   rI  rM  rN  rO  r   r   rP  rV  r[  rF   r  r  )r  r^  _force_whites     rA   r  2PaintSoftMask.coverage_white.<locals>._force_white  s    "/"<"<BHH"+BHH$%BHH!$(BHH!"/"7"7BHH!.!6!6BHH e_55 '{33-:-G-GEKK*-6EKK*/0EKK,/3EKK,-:-B-BEKK*,9,A,AEKK) 'rY   )r  clone_structurerF   r  )r  new_noder  r  s      @rA   coverage_whitePaintSoftMask.coverage_whitex  sQ    	B_ 	B* #4( (O44 ..0 	
 	RrY   c           	      `   / n[        U 5       GH  n[        U[        5      (       d  M  UR                  R                  UR                  R
                  4 GH  n[        U[        5      (       d  M  UR                  (       d  M.  UR                  R                  5       (       d  MO  UR                  [        SS5      SS9S   nUR                  S::  d  UR                  S::  a  M  [        5       nUR                  UR                  UR                  UR                  UR                  5        [!        UR                  UR"                  UR$                  UR&                  S9nXeR                  l        SUR                  l        SUR                  l        [*        R,                  UR                  l        [1        5       nUR3                  USS9  [4        R6                  UR                  l        UR;                  U5        GM     GM     U(       d  g[1        5       nU H  n	UR3                  U	5        M     U$ )u  
Build a GraphicsContext that encodes the *alpha ramps* contributed by any
`GradientPaint` used by *node*. Each contributing PaintedPath yields one
rectangle covering its content-space bounding box; that rectangle is filled
with an `_AlphaGradientPaint` (the gradient’s *alpha channel only*).
Rectangles are stacked with `BM=Multiply` so multiple alpha sources
combine multiplicatively.
r   FrF  )r]   r^   r_   r`   Nr  )_iter_nodesrF   r  r   rM  rO  r[   r]   r   r  r   rw   rx   r  ry   rz   r   r^   r_   r`   r   r    r  rI  r  r  r   MULTIPLYrP  rS   )
r  layersnpaintbbrectry  layer_gcAlayers
             rA   alpha_layers_fromPaintSoftMask.alpha_layers_from  s    T"A![))gg00!''2F2FGE"5-88!NNN!NN4466^^E!QK5^QRST88q=BIIN$*}ruubeeRXXryyI&9%*^^"'++/4/G/G+0+?+?	' 1<

-26

/23

/0=0J0J

-#2#4 ))$e)<4=4F4F1h/5 H #< EJJu rY   Nr  Bregion_bboxrl   c                 0   Ub  UnOYU(       a  UR                  [        SS5      SS9S   OSnUR                  [        SS5      SS9S   nUc  UOUR                  U5      n[        5       n	[	        5       n
U
R                  UR                  UR                  UR                  UR                  5        U(       d  SOSU
R                  l        SU
R                  l        SU
R                  l        U	R                  U
5        U(       a  [        R                   UR                  l        U	R                  U5        Ub0  [        R$                  UR                  l        U	R                  U5        U " U	SSS	9nUR'                  U5      nUR)                  U5      Ul        U$ )
uH  
Construct a **luminosity soft mask** from two ingredients:

- **A**: Optional GraphicsContext encoding alpha ramps (e.g., the result of
:meth:`alpha_layers_from`). If ``None``, the effective alpha is 1.
- **B**: Coverage term (e.g., the result of :meth:`coverage_white`).

The mask luminance is:
    - ``A × B``        when ``invert = False``
    - ``A × (1 − B)``  when ``invert = True``

Implementation outline:
1. Compute the union bbox of A and B (no stroke expansion).
2. Paint a background rectangle: **black** for ``A×B`` or **white** for
``A×(1−B)``.
3. Paint **B**; when ``invert=True``, set ``BM=Difference`` to obtain
``1−B`` from the white background.
4. If A is present, paint it with ``BM=Multiply`` to apply the alpha ramp.
5. Wrap the result as a Form XObject and attach it as ``/SMask`` with
``/S /Luminosity``.
Nr   FrF  z#000000r  r   T)ru  rv  )r  r   r   r  r  r  ry   rz   rw   rx   r   rM  rN  rO  r  r   
DIFFERENCErP  r  r  r  r  )r   r  r  ru  registryr  unionbb_Abb_Bcanvasbgr{  r  s                rA   from_ABPaintSoftMask.from_AB  sN   @ "E LMuQ{eDQGRV  >>%1+>GJD LDdjj.>E " ]
UXXuxxellC/5i9 ! $ !*!5!5AGG =!*!3!3AGGOOAd;IIh2226	rY   )ru  r  r~   r  r  rv  r=   )r   r   r   r   r   r   r   rf   r   r  r  rL   ri   r2   rN   r   r  r  r  r  r  r
   r  r5  r  r   r   rY   rA   r  r    s%   	I !!#8o568 8(A'%ueU(B"C ',B *K01*	{O+	,* *X .8O#< . .`  04?O$? o-.? 	? m,? 
? ?rY   r  c              #     #    [        U [        5      (       aX  U v   U R                  5       nUR                   H3  n[        U[        [        45      (       d  M   [        U5       S h  vN   M5     g [        U [        5      (       aH  U v   U R                   H3  n[        U[        [        45      (       d  M   [        U5       S h  vN   M5     g g  Ng N7fr=   )rF   r  r  r[  r  r  )r  root_gcchs      rA   r  r    s     $$$
++-$$B"<==&r?** % 
D/	*	*
//B"<==&r?** " 
+ +
 +s1   ACC&C'A
C5CCCCr  c                 8   [        U 5       H  n[        U[        5      (       d  M  S Hk  n[        UR                  U5      n[        U[
        5      (       d  M0  UR                  (       d  MC  UR                  R                  5       (       d  Md  SUl        Mm     M     g )N)rM  rO  T)	r  rF   r  rH   r   r[   r]   r   ra   )r  r  r  cols       rA   _disable_auto_alphar  (  sg    a%%6aggt,c=11|||(>(>(@(@)- 7 rY   c                    [        U [        5      (       a  [        5       n[        U R                  5      Ul        U R                  Ul        U R
                  Ul        U R                   Vs/ s H+  n[        U[        [        45      (       a  [        U5      OUPM-     snUl        U$ [        U [        5      (       a  [        R                  [        5      n[        U R                  5       5      n[        R                  USU5        [        R                  USU5        [        R                  USU R                  5        [        R                  USU5        [        R                  USU R                  5        U$ U $ s  snf )Nr  r  r  r  r  )rF   r  r   r   r  r  r[  r  r  rg  r  r7  ri  r  r  )r  r_  r  roots       rA   r  r  4  s7   $((TZZ(	 .. oo
 & b?K"@AA  # &
 
$$$!!+.t88:;3 8$?3 3T:3	4<<83 0$731C1CD
K%
s   *2E8c                      \ rS rSr\" SS9 " S S5      5       r\R                  \" SS5      4\R                  \" SS5      4\R                  \" SS5      \" SS5      4\R                  \" SS5      \" SS5      4\R                  \" SS5      4\R                  \" SS5      4\R                  \" SSS5      4\R                  \" SSS5      4\R                  \" SSS5      \" SS5      4\R                   \" SSS5      \" SS5      4\R"                  \" SSS5      \" SSS5      4\R$                  \" 5       0rS	\4S
 jr\S\\\4   S\\\4   S\S\\\4   4S j5       rS\S\\\4   4S jr  SS jrS rSr g)r  iO  T)frozenc                   >    \ rS rSr% \\S'   \\   \S'   Sr\\S'   Sr	g)PaintComposite._StepiQ  draw	mask_fromFru  r   N)
r   r   r   r   rI   r4  r
   ru  rL   r   r   rY   rA   _Stepr  Q  s    	C= rY   r  sourceNbackdrop	operationc                 $   [        U[        [        45      (       a  [        U[        [        45      (       d  [        S5      eXl        X l        X0l        U R                  U R                  ;  a#  [        SU R                  R                   S35      eg )Nz2PaintComposite requires two PaintedPath instances.zCompositing mode 'z' is not yet supported.)
rF   r  r  rT   r  r  mode_MODESNotImplementedErrorrE  )rh   r  r  r  s       rA   ri   PaintComposite.__init__u  s    ([/$BCC:[/2L
 L
 PQQ 	99DKK'%$TYY__$55LM  (rY   pathr  ru  rm   c                 f   [        U5      n[        R                  U5      n[        R                  U5      nUR	                  [        SS5      SS9S   nUR	                  [        SS5      SS9S   n	UR                  U	5      n
[        R                  XgX4U
S9nXR                  l	        [        U5        U$ )Nr   FrF  )r  )r   r  r  r  r  r   r   r  r   rV  r  )r   r  r  ru  r  r   r  r  bb_pr  r  r{  s               rA   
_with_maskPaintComposite._with_mask  s     TN++A.((3~~eAqkU~CAF~~eAqkU~CAFjj&""& # 
 ArY   whichc                 >    US:X  a  U R                   $ U R                  $ )Nr  )r  r  )rh   r  s     rA   _pickPaintComposite._pick  s    #x/t{{BT]]BrY   c           	         U R                   U R                     nU(       d  SX44$ / nU H  n	U R                  U	R                  5      n
U	R                  b6  U R                  XR                  U	R                  5      U	R                  U5      n
U
R                  XX4XV5      u  pnUR                  U5        M     SR                  U5      X44$ )Nr  r;   )
r  r  r  r  r  r  ru  r  rS   rO   )rh   r  r   r  r  r  r  stepsr  str  rl  s               rA   r  PaintComposite.render  s     DII&y//B::bgg&D||'**R\\2BII?P +/++!)L+'A- LLO  xx	88rY   c                 j    UR                  U SU R                   S35        U R                  XX4XV5      $ )Nz<PaintComposite mode=>
)r  r  r  r  s          rA   r  PaintComposite.render_debug  s<     	cU"7		{#FG{{i
 	
rY   )r  r  r  rO  )!r   r   r   r   r   r  r   SOURCEDESTINATIONSOURCE_OVERDESTINATION_OVER	SOURCE_INDESTINATION_IN
SOURCE_OUTDESTINATION_OUTSOURCE_ATOPDESTINATION_ATOPXORCLEARrN   r  ri   r5  r   r  r  rL   r  rI   r  r  r  r   r   rY   rA   r  r  O  s	   d   	##eHd&;%=((5T+B*D((*d#(D!+
 	--(D!*d#0
 	&&x)D(F++eJ.I-K''%*d*K)M,,uZ4/P.R((*h-(J'+
 	--(J-*h'0
 	  (J-*h-#
 	""EG7F<4H  K01 o56 	 
{O+	, .C3 C5o)E#F C 94
rY   r  c                   R    \ rS rSrSrS\S\4S jrS rS\	\
\
\
\
4   4S jrS	 rS
rg)_BlendGroupi  )context
base_styler  r  r  c                 N    Xl         [        U5      U l        [        5       U l        g r=   )r  r   r  r  r  )rh   r  r  s      rA   ri   _BlendGroup.__init__  s    ":.rY   c           	          U R                   R                  UU R                  S [        SS5      S9u  n  nUR	                  U5      U l        U$ r  )r  r  r  r   r  r  r  s       rA   r  _BlendGroup.render  sP    ||**//1+	 + 
1 +66v>rY   rm   c                     U R                   R                  [        SS5      U R                  SS9u  pUR	                  5       (       d  gUR                  5       $ )Nr   Trr  )r   r   r   r   )r  r  r   r  r   r  )rh   rk   r  s      rA   r  _BlendGroup.get_bounding_box  sJ    ,,++!QKt$ , 
 }}'}}rY   c                   ^^^^^ 0 nU R                    H.  u  pxUR                  U[        5       5      R                  U5        M0     / n	UR	                  [
        R                  5      n
U
(       aY  SR                  U4S j[        U
5       5       5      nU(       a.  U	R                  [        S5      R                  5        SU S35        UR	                  [
        R                  5      nU(       aY  SR                  U4S j[        U5       5       5      nU(       a.  U	R                  [        S5      R                  5        SU S35        UR	                  [
        R                  5      nU(       aY  SR                  U4S j[        U5       5       5      nU(       a.  U	R                  [        S	5      R                  5        SU S35        UR	                  [
        R                  5      nU(       aY  SR                  U4S
 j[        U5       5       5      nU(       a.  U	R                  [        S5      R                  5        SU S35        UR	                  [
        R                  5      nU(       aY  SR                  U4S j[        U5       5       5      nU(       a.  U	R                  [        S5      R                  5        SU S35        U	(       a  SSR                  U	5      -   S-   $ S$ )Nr  c              3      >#    U  H9  nUT;   d  M  [        U5      R                  5        S TU   R                   S3v   M;     g7fr  r  )r?   rs  r  s     rA   rB   6_BlendGroup.get_resource_dictionary.<locals>.<genexpr>  sL      !0D11 R4:'')*!,B4,H,K,K+LDQ0
   
A3Ar  r  r  c              3      >#    U  H9  nUT;   d  M  [        U5      R                  5        S TU   R                   S3v   M;     g7fr  r  )r?   rs  r  s     rA   rB   r&    L      !,D00 Q4:'')*!,A$,G,J,J+K4P,r'  r&   c              3      >#    U  H9  nUT;   d  M  [        U5      R                  5        S TU   R                   S3v   M;     g7fr  r  )r?   rs  shading_objs_per_names     rA   rB   r&    r)  r'  Shadingc              3      >#    U  H<  nUT;   d  M  [        S U 35      R                  5        STU   R                   S3v   M>     g7f)Fr;   r  Nr  )r?   idxfont_objs_per_indexs     rA   rB   r&  	  sR      !(C-- S4!C5	?,,./q1DS1I1L1L0MTR(
   
A6AFontc              3      >#    U  H<  nUT;   d  M  [        S U 35      R                  5        STU   R                   S3v   M>     g7f)Ir;   r  Nr  )r?   r/  img_objs_per_indexs     rA   rB   r&    sR      !+C,, R4!C5	?,,./q1CC1H1K1K0LDQ+r1  XObjectz<<>>)r  r  r  r   getr!   EXT_G_STATErO   r?  rS   r,   r2   r   r   FONTX_OBJECT)rh   r  r  r+  r0  r5  r  rtyper  r  ext_g_states
serializedpatternsshadingsfontsxobjectss    `````          rA   r  #_BlendGroup.get_resource_dictionary  sX    <>"&..E ++E359==kJ #1 +//0K0KL !"<0! J
 [ 1 ; ; =>bBOP'++O,C,CD !"8,! J
 Y 9 9 ;<Bzl"MN'++O,C,CD !"8,! J
 Y 9 9 ;<Bzl"MN$(()=)=> !!%=! J
 V 6 6 89J<rJK'++O,D,DE !!(+! J
 Y 9 9 ;<Bzl"MN/4tbggen$t+@&@rY   )r  r  r  N)r   r   r   r   r   r  r   ri   r  rN   r   r  r  r   r   rY   rA   r  r    s@    6I ] 
%ueU(B"C @ArY   r  c                   h    \ rS rSrSrS\\\4   S\\\4   S\4S jr	S\
S\4S	 jr  SS jrS rSrg
)PaintBlendCompositei  )r  r  rP  _form_indexr  r  rP  c                     [        U[        [        45      (       a  [        U[        [        45      (       d  [        S5      eXl        X l        X0l        S U l        g )NzEPaintBlendComposite requires PaintedPath or GraphicsContext operands.)rF   r  r  rT   r  r  rP  rE  )rh   r  r  rP  s       rA   ri   PaintBlendComposite.__init__!  sY     ([/$BCC:[/2L
 L
 W  !$*.rY   r  rm   c                 8   U R                   b  U R                   $ [        5       nU R                  nU R                  n[	        US5      (       aS  U R
                  UR                  l        UR                  R                  SL a  [        R                  UR                  l        UR                  USS9  UR                  USS9  [        U[        5      (       a  UO	[        5       n[        X65      nUR                  U5      U l         S U l        S U l        U R                   $ )Nr   Fr  )rE  r  r  r  rp  rP  r   rJ  r   r   r  rF   r  register_blend_form)rh   r  r  groupbackdrop_nodesource_nodero  blend_groups           rA   _ensure_form_index&PaintBlendComposite._ensure_form_index2  s    '###!kk;((+/??K(  33u<7D7L7L!!4}E2{%0 %Z??J]_ 	 "%9,@@MrY   Nc                 8    U R                  X5      nSU S3nXU4$ )Nzq /Iz Do Q)rN  )	rh   r  r   r  r  r  r  
form_indexr  s	            rA   r  PaintBlendComposite.renderL  s.     ,,->F
*U+M11rY   c                 j    UR                  U SU R                   S35        U R                  XX4XV5      $ )Nz<PaintBlendComposite mode=r  )r  rP  r  r  s          rA   r   PaintBlendComposite.render_debugY  s=     	cU"<T__<MSQR{{i
 	
rY   )rE  r  rP  r  rO  )r   r   r   r   r   r   r  r  r   ri   r   r8  rN  r  r  r   r   rY   rA   rD  rD    sc    CI/45/ o{23/ 	/"   RU  @ 2
rY   rD  c                   L   ^  \ rS rSrU 4S jrS rS rS rS rS r	S r
S	rU =r$ )
PathPenib  c                 N   > Xl         SU l        S U l        [        TU ]  " U0 UD6  g rd   )pdf_pathlast_was_line_tofirst_is_moverr  ri   )rh   rX  argskwargsrf  s       rA   ri   PathPen.__init__c  s*      %!$)&)rY   c                 n    U R                   R                  " U6   SU l        U R                  c  SU l        g g )NFT)rX  r  rY  rZ  rh   r   s     rA   _moveToPathPen._moveToi  s5    r" %%!%D &rY   c                 n    U R                   R                  " U6   SU l        U R                  c  SU l        g g )NTF)rX  r	  rY  rZ  r_  s     rA   _lineToPathPen._lineToo  s5    r" $%!&D &rY   c           	          U R                   R                  US   US   US   US   US   US   S9  SU l        U R                  c  SU l        g g )Nr   r   )r   r   r   r   r  r  F)rX  r  rY  rZ  )rh   pt1pt2pt3s       rA   _curveToOnePathPen._curveToOneu  sa    1v#a&SVA3q6c!f 	 	
 !&%!&D &rY   c                     U R                   R                  US   US   US   US   S9  SU l        U R                  c  SU l        g g )Nr   r   )r   r   r   r   F)rX  r+  rY  rZ  )rh   rf  rg  s      rA   _qCurveToOnePathPen._qCurveToOne}  sO    ((CFs1v#a&SQRV(T %%!&D &rY   c           
          U R                   R                  UUUUUUS   US   S9  SU l        U R                  c  SU l        g g )Nr   r   )r  r  r  r2  r3  r   r   F)rX  r4  rY  rZ  )rh   r  r  r  r  r  r  s          rA   arcToPathPen.arcTo  sY     !f!f 	 	
 !&%!&D &rY   c                     U R                   (       a  U R                  R                  5         U R                  R                  5         g r=   )rY  rX  r  r  r   s    rA   
_closePathPathPen._closePath  s-       MM224rY   )rZ  rY  rX  )r   r   r   r   ri   r`  rc  ri  rl  ro  rr  r   r  r  s   @rA   rV  rV  b  s+    *&'''' rY   rV  c                       \ rS rSrSrS rSrg)GlyphPathPeni  z;A pen that can be used to draw glyphs into a `PaintedPath`.c                 8    U R                   R                  5         g)z
The difference between GlyphPathPen and PathPen is that GlyphPathPen does not
remove the last path element before closing the path.
This last line back to start point is necessary for correctly rendering glyphs.
N)rX  r  r   s    rA   rr  GlyphPathPen._closePath  s     	rY   r   N)r   r   r   r   r   rr  r   r   rY   rA   ru  ru    s
    ErY   ru  )g-q=)r   r  r  collectionsr   
contextlibr   copyr   dataclassesr   typingr   r   r	   r
   r   r   r   fpdf.drawing_primitivesr   r   r   r   r   r   r   r   r   r   r   enumsr   r   r   r   r   r   r    r!   r"   r#   r$   r   r%   r&   r'   r(   r)   r*   r+   syntaxr,   r-   utilr.   fontTools.pens.basePenr/   rV   r0   r>   r[   r   rl   r   r  rI   r  r  r  r  r	  r  r#  r,  r9  rC  rL  r   r\  rM   re  rg  ry  r  r  r  r  r  r  r  r&  r.  r{  r  r  r4  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r'  r  r  r  r  rQ  r  r  r  r  r  r  r  rD  rV  ru  r   rY   rA   <module>r     s     # %  !             *'9xn nb- <p
* p
fR Rj K K K"U s U s A Au A5 AS AJ1: J1ZH1: H1VK1: K1\I1: I1XF1Z F1RK1Z K1\G1: G1TK1: K1\


"
(-
38


 >C#).5:	%[.[1* [1|t1* t1nd1: d1NQ1: Q1ho
* o
dc
* c
LR1
 R1jUDz UDpGj GD
.j 
.x1: x1vE1J E1PF1J F1R uQ{+D*+ ,a <M:<uQ{+D*+ ,a <M:<"01"5OZ5+AA+FjF ,q 1M:1)=)BJB*A;5A;E!QK L*  )<A;5A;E!QK):  *>1a[eAqk*J  3O1a[eAqk3#Z  AqkAU%U1a[C   +AqkAU%U1a[ L*  &%1+E!QKHIzH$4!QKeAqka%z  "aE!QKHGZH

<"4PRD* 
 "/NJ0E:L L^y	
 y	
xk
; k
\B
 B
J D+.eK$@A .d .6o
 o
dZA ZAzA
 A
H4g 4n	7 	rY   