
    hW                         S r SSKrSSKJrJrJrJr  SSKJr  SSK	J
r
JrJr  SSKJrJr  / SQr " S S	5      r " S
 S\5      r " S S\5      r " S S\
5      r " S S\5      r " S S\5      r " S S\\5      rg)a  
=========
PointPens
=========

Where **SegmentPens** have an intuitive approach to drawing
(if you're familiar with postscript anyway), the **PointPen**
is geared towards accessing all the data in the contours of
the glyph. A PointPen has a very simple interface, it just
steps through all the points in a call from glyph.drawPoints().
This allows the caller to provide more data for each point.
For instance, whether or not a point is smooth, and its name.
    N)AnyOptionalTupleDict)LogMixin)AbstractPenMissingComponentErrorPenError)DecomposedTransformIdentity)AbstractPointPenBasePointToSegmentPenPointToSegmentPenSegmentToPointPenGuessSmoothPointPenReverseContourPointPenc                      \ rS rSrSrSS\\   S\SS4S jjrSS jr	    SS	\
\\4   S
\\   S\S\\   S\\   S\SS4S jjr SS\S\
\\\\\\4   S\\   S\SS4
S jjr SS\S\S\\\4   S\\   S\SS4S jjrSrg)r       zBaseclass for all PointPens.N
identifierkwargsreturnc                     [         e)zStart a new sub path.NotImplementedErrorselfr   r   s      I/var/www/html/env/lib/python3.13/site-packages/fontTools/pens/pointPen.py	beginPathAbstractPointPen.beginPath#       !!    c                     [         e)zEnd the current sub path.r   r   s    r   endPathAbstractPointPen.endPath'   r    r!   ptsegmentTypesmoothnamec                     [         e)z$Add a point to the current sub path.r   r   r&   r'   r(   r)   r   r   s          r   addPointAbstractPointPen.addPoint+   s
     "!r!   baseGlyphNametransformationc                     [         e)zAdd a sub glyph.r   )r   r.   r/   r   r   s        r   addComponentAbstractPointPen.addComponent7   s
     "!r!   	glyphNamelocationc                     [         e)zAdd a VarComponent sub glyph. The 'transformation' argument
must be a DecomposedTransform from the fontTools.misc.transform module,
and the 'location' argument must be a dictionary mapping axis tags
to their locations.
)AttributeErrorr   r3   r/   r4   r   r   s         r   addVarComponent AbstractPointPen.addVarComponentA   s
     r!    N)r   NNFNN)__name__
__module____qualname____firstlineno____doc__r   strr   r   r$   r   floatboolr,   r1   r   r   r8   __static_attributes__r:   r!   r   r   r       s:   &"HSM "C "D "" &*"$(
"%,
" c]
" 	
"
 sm
" SM
" 
" 

"  %)	"" eUE5%FG" SM	"
 " 
" %) , sEz"	
 SM  
 r!   r   c                   @    \ rS rSrSrS rS
S jrS rS r SS jr	S	r
g)r   R   a  
Base class for retrieving the outline in a segment-oriented
way. The PointPen protocol is simple yet also a little tricky,
so when you need an outline presented as segments but you have
as points, do use this base implementation as it properly takes
care of all the edge cases.
c                     S U l         g r;   currentPathr#   s    r   __init__BasePointToSegmentPen.__init__[   s
    r!   Nc                 B    U R                   b  [        S5      e/ U l         g )NzPath already begun.)rJ   r
   r   s      r   r   BasePointToSegmentPen.beginPath^   s"    '011r!   c                     [         e)a)  Override this method.

It will be called for each non-empty sub path with a list
of segments: the 'segments' argument.

The segments list contains tuples of length 2:
        (segmentType, points)

segmentType is one of "move", "line", "curve" or "qcurve".
"move" may only occur as the first segment, and it signifies
an OPEN path. A CLOSED path does NOT start with a "move", in
fact it will not contain a "move" at ALL.

The 'points' field in the 2-tuple is a list of point info
tuples. The list has 1 or more items, a point tuple has
four items:
        (point, smooth, name, kwargs)
'point' is an (x, y) coordinate pair.

For a closed path, the initial moveTo point is defined as
the last point of the last segment.

The 'points' list of "move" and "line" segments always contains
exactly one point tuple.
r   )r   segmentss     r   _flushContour#BasePointToSegmentPen._flushContourc   s
    4 "!r!   c                    U R                   c  [        S5      eU R                   nS U l         U(       d  g [        U5      S:X  a#  US   u  p#pEnSX$XV4/4/nU R                  U5        g / nUS   S   S:X  a1  US   u  p#pEnUR	                  SX$XV4/45        UR                  S5        OPS n[        [        U5      5       H  n	X   S   nUc  M  U	n  O   Uc  UR	                  S5        OXS-   S  US US-    -   n/ n
U H3  u  p#pEnU
R	                  X$XV45        Uc  M  UR	                  X:45        / n
M5     U R                  U5        g )NzPath not begun.   r   move)NqcurveNNN)rJ   r
   lenrQ   appendpoprange)r   pointsr&   r'   r(   r)   r   rP   firstOnCurveicurrentSegments              r   r$   BasePointToSegmentPen.endPath   s   #,--!!v;!4:1I1BV62t"<!=>?Hx(!9Q<6! 5;1I1BV6OOVr4&@%ABCJJqM
  L3v;'$il*#$L	 (
 # @Aq 0 23f=O|a?O6PP5;1BV6!!2t"<="OO[9:N 6< 	8$r!   c                 p    U R                   c  [        S5      eU R                   R                  XX4U45        g NPath not begun)rJ   r
   rX   r+   s          r   r,   BasePointToSegmentPen.addPoint   s7     #+,,& GHr!   rI   r;   r<   )r=   r>   r?   r@   rA   rK   r   rQ   r$   r,   rE   r:   r!   r   r   r   R   s)     
"8.%b IMIr!   r   c                   2    \ rS rSrSrSS jrS rS	S jrSrg)
r      z
Adapter class that converts the PointPen protocol to the
(Segment)Pen protocol.

NOTE: The segment pen does not support and will drop point names, identifiers
and kwargs.
c                 F    [         R                  U 5        Xl        X l        g r;   )r   rK   penoutputImpliedClosingLine)r   
segmentPenrh   s      r   rK   PointToSegmentPen.__init__   s    &&t,(@%r!   c           	      b   U(       d  [        S5      eU R                  nUS   S   S:X  a>  SnUS   S   n[        U5      S:w  a  [        S[        U5       35      eUS   u  n    nUS	 OSnUS   u  ptUS   u  n    nUc  OUR                  U5        U R                  n[        U5      n	Un
[        U	5       H  nX   u  ptU VVs/ s H	  u  n    olPM     nnnUS	:X  a^  [        U5      S:w  a  [        S
[        U5       35      eUS   nUS-   U	:w  d  U(       d  U(       a  X:X  a  UR                  U5        Un
M  M  US:X  a  UR                  " U6   US   n
M  US:X  a  UR                  " U6   US   n
M  [        SU 35      e   U(       a  UR                  5         g UR                  5         g s  snnf )NzMust have at least one segment.r   rU   FrT   z"Illegal move segment point count: Tlinez"Illegal line segment point count: curverV   zIllegal segmentType: )r
   rg   rW   moveTorh   rZ   lineTocurveToqCurveTo	closePathr$   )r   rP   rg   closedr[   movePt_r'   rh   	nSegmentslastPtr]   r&   s                r   rQ   PointToSegmentPen._flushContour   s   <==hhA;q>V#Fa[^F6{a!CCK=QRR$QiOFAq! F"*2,K$RjOFAq!> JJv#'#@#@ M	y!A"*+K,23F[RAqbFF3f$v;!#"%GF}#UVVAY EY&/!|JJrNF $ 'V$(f%!6{mDEE? "@ MMOKKMC 4s   F+Nc                 >    AAU R                   R                  X5        g r;   )rg   r1   r   r3   	transformr   r   s        r   r1   PointToSegmentPen.addComponent  s    i3r!   )rh   rg   )Fr;   )	r=   r>   r?   r@   rA   rK   rQ   r1   rE   r:   r!   r   r   r      s    A
?B4r!   r   c                   R    \ rS rS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g)r   i  zQ
Adapter class that converts the (Segment)Pen protocol to the
PointPen protocol.
c                 N    U(       a  [        U5      U l        OXl        S U l        g r;   )r   rg   contour)r   pointPenguessSmooths      r   rK   SegmentToPointPen.__init__  s    *84DHHr!   c                     U R                   nUR                  5         U R                   H  u  p#UR                  X#S9  M     UR	                  5         g )N)r'   )rg   r   r   r,   r$   )r   rg   r&   r'   s       r   rQ   SegmentToPointPen._flushContour  s;    hh#||OBLLL5  ,r!   c                 L    / U l         U R                   R                  US45        g )NrU   )r   rX   r   r&   s     r   ro   SegmentToPointPen.moveTo   s    RL)r!   c                 n    U R                   c  [        S5      eU R                   R                  US45        g )N'Contour missing required initial moveTorm   )r   r
   rX   r   s     r   rp   SegmentToPointPen.lineTo$  s.    <<DEERL)r!   c                     U(       d  [        S5      eU R                  c  [        S5      eUS S  H   nU R                  R                  US 45        M"     U R                  R                  US   S45        g )NMust pass in at least one pointr   rl   rn   	TypeErrorr   r
   rX   r   ptsr&   s      r   rq   SegmentToPointPen.curveTo)  sh    =>><<DEEcr(BLLT
+ SWg./r!   c                    U(       d  [        S5      eUS   c  / U l        OU R                  c  [        S5      eUS S  H   nU R                  R                  US 45        M"     US   b!  U R                  R                  US   S45        g g )Nr   rl   r   rV   r   r   s      r   rr   SegmentToPointPen.qCurveTo2  s    =>>r7?DL||#HIIcr(BLLT
+ r7LLR( 34 r!   c                    U R                   c  [        S5      e[        U R                   5      S:  aP  U R                   S   S   U R                   S   S   :X  a*  U R                   S   U R                   S'   U R                   S	 O(U R                   S   u  pUS:X  a  US4U R                   S'   U R                  5         S U l         g )Nr   rT   r   rl   rU   rm   )r   r
   rW   rQ   )r   r&   tps      r   rs   SegmentToPointPen.closePath?  s    <<DEEt||q T\\!_Q%74<<;KA;N%N"ll2.DLLOR  \\!_FBV|"$f*Qr!   c                 b    U R                   c  [        S5      eU R                  5         S U l         g )Nr   )r   r
   rQ   r#   s    r   r$   SegmentToPointPen.endPathN  s+    <<DEEr!   c                 j    U R                   b  [        S5      eU R                  R                  X5        g )N1Components must be added before or after contours)r   r
   rg   r1   )r   r3   r|   s      r   r1   SegmentToPointPen.addComponentT  s*    <<#NOOi3r!   )r   rg   N)T)r=   r>   r?   r@   rA   rK   rQ   ro   rp   rq   rr   rs   r$   r1   rE   r:   r!   r   r   r     s4    
**
054r!   r   c                   Z    \ rS rSrSrSS jrS rSS jrS r SS jr	SS	 jr
 SS
 jrSrg)r   iZ  z
Filtering PointPen that tries to determine whether an on-curve point
should be "smooth", ie. that it's a "tangent" point or a "curve" point.
c                 *    Xl         X l        S U l        g r;   )_outPen_error_points)r   outPenerrors      r   rK   GuessSmoothPointPen.__init__`  s    r!   c                    U R                   c  [        S5      eU R                   n[        U5      nU(       d  g US   S   S:X  a  [        SUS-
  5      nOUS:  a  [        SUS-
  5      nO/ nU H  nX   u  pVpxn	Uc  M  US-
  n
US-   nX   S   b
  X   S   b  M,  X   S   nX   S   nX   S   nX\:w  d  MH  X]:w  d  MO  US   US   -
  US   US   -
  pUS   US   -
  US   US   -
  nn[        R
                  " X5      n[        R
                  " UU5      n[        UU-
  5      U R                  :  d  M  XVSX4X'   M     U H&  u  pVnpU R                  R                  " XVUU40 U	D6  M(     g )Nrb   r   rT   rU   rl   T)
r   r
   rW   rZ   mathatan2absr   r   r,   )r   r[   nPointsindicesr]   r&   r'   rv   r)   r   prevnextprevPtnextPtdx1dy1dx2dy2a1a2r(   s                        r   rQ   !GuessSmoothPointPen._flushContoure  s   <<+,,f+!9Q<6!Aw{+Gq[ B!,G GA/5y,BQf"q5Dq5D|A*v|A/J1B\!_F\!_F|a56!9,befQi.?S!!9r!u,fQi"Q%.?SZZ)ZZS)rBw<$++- "t CFI% ( 6<1BVTLL!!"64J6J 6<r!   Nc                     U R                   b  [        S5      e/ U l         Ub  XS'   U R                  R                  " S0 UD6  g )NPath already begunr   r:   )r   r
   r   r   r   s      r   r   GuessSmoothPointPen.beginPath  sB    <<#/00!#-< ((r!   c                 f    U R                  5         U R                  R                  5         S U l        g r;   )rQ   r   r$   r   r#   s    r   r$   GuessSmoothPointPen.endPath  s%    r!   c                 ~    U R                   c  [        S5      eUb  XVS'   U R                   R                  XSXF45        g )Nrb   r   F)r   r
   rX   r+   s          r   r,   GuessSmoothPointPen.addPoint  sA     <<+,,!#-< ReTBCr!   c                 |    U R                   b  [        S5      eUb  X4S'   U R                  R                  " X40 UD6  g Nr   r   )r   r
   r   r1   )r   r3   r/   r   r   s        r   r1    GuessSmoothPointPen.addComponent  s=    <<#NOO!#-< !!)FvFr!   c                 ~    U R                   b  [        S5      eUb  XES'   U R                  R                  " XU40 UD6  g )Nz4VarComponents must be added before or after contoursr   )r   r
   r   r8   r7   s         r   r8   #GuessSmoothPointPen.addVarComponent  sA     <<#QRR!#-< $$YSFSr!   )r   r   r   )g?r;   r<   )r=   r>   r?   r@   rA   rK   rQ   r   r$   r,   r1   r8   rE   r:   r!   r   r   r   Z  s<    

&KP) IMDG ?CTr!   r   c                   J    \ rS rSrSrS rS rSS jrS r SS jr	SS	 jr
S
rg)r   i  a  
This is a PointPen that passes outline data to another PointPen, but
reversing the winding direction of all contours. Components are simply
passed through unchanged.

Closed contours are reversed in such a way that the first point remains
the first point.
c                     Xl         S U l        g r;   )rg   currentContour)r   outputPointPens     r   rK   ReverseContourPointPen.__init__  s    !"r!   c                    U R                   nU R                  nU(       d*  UR                  U R                  S9  UR	                  5         g US   S   S:g  nU(       d  SnOVUR                  UR                  S5      5        S n[        [        U5      5       H  nX&   S   c  M  Un  O   Uc  S nOX%   S   nUR                  5         U(       d%  US   S   c  UR                  S5        US   S   c  M  UR                  U R                  S9  U H'  u  pxpnUb  UnUnOS nUR                  " U4XU
S.UD6  M)     UR	                  5         g )N)r   r   rT   rU   )r'   r(   r)   )rg   r   r   currentContourIdentifierr$   rX   rY   rZ   rW   reverser,   )r   rg   r   rt   lastSegmentTyper\   r]   r&   nextSegmentTyper(   r)   r   r'   s                r   rQ   $ReverseContourPointPen._flushContour  sP   hh%%MMT%B%BMCKKMA&($O NN7;;q>*L3w<(:a=,#$L ) # #'")"7": !*Q-'A !*Q-'!>!>?9@5Bv*-"1"LL +IO :A 	r!   Nc                 \    U R                   b  [        S5      e/ U l         Xl        / U l        g )Nr   )r   r
   r   onCurver   s      r   r    ReverseContourPointPen.beginPath  s/    */00 (2%r!   c                 b    U R                   c  [        S5      eU R                  5         S U l         g ra   )r   r
   rQ   r#   s    r   r$   ReverseContourPointPen.endPath  s.    &+,,"r!   c                 ~    U R                   c  [        S5      eUb  XVS'   U R                   R                  XX4U45        g )Nrb   r   )r   r
   rX   r+   s          r   r,   ReverseContourPointPen.addPoint  sE     &+,,!#-< ""BV6#JKr!   c                 r    U R                   b  [        S5      eU R                  R                  " X4SU0UD6  g r   )r   r
   rg   r1   r{   s        r   r1   #ReverseContourPointPen.addComponent  s6    *NOOiTzTVTr!   )r   r   r   rg   r;   r<   )r=   r>   r?   r@   rA   rK   rQ   r   r$   r,   r1   rE   r:   r!   r   r   r     s/    #
0d# IMLUr!   r   c                   H   ^  \ rS rSrSrSr\rSSS.U 4S jjrS
S jrS	r	U =r
$ )DecomposingPointPeni  a  Implements a 'addComponent' method that decomposes components
(i.e. draws them onto self as simple contours).
It can also be used as a mixin class (e.g. see DecomposingRecordingPointPen).

You must override beginPath, addPoint, endPath. You may
additionally override addVarComponent and addComponent.

By default a warning message is logged when a base glyph is missing;
set the class variable ``skipMissingComponents`` to False if you want
all instances of a sub-class to raise a :class:`MissingComponentError`
exception by default.
TNF)skipMissingComponentsreverseFlippedc                ~   > [         TU ]  " U0 UD6  Xl        Uc  U R                  R                  OUU l        X0l        g)a  Takes a 'glyphSet' argument (dict), in which the glyphs that are referenced
as components are looked up by their name.

If the optional 'reverseFlipped' argument is True, components whose transformation
matrix has a negative determinant will be decomposed with a reversed path direction
to compensate for the flip.

The optional 'skipMissingComponents' argument can be set to True/False to
override the homonymous class attribute for a given pen instance.
N)superrK   glyphSet	__class__r   r   )r   r   r   r   argsr   r   s         r   rK   DecomposingPointPen.__init__#  sF    $ 	$)&)  %, NN00& 	"
 -r!   c                    SSK Jn   U R                  U   nU nU[        :w  a  U" Xr5      nU R                  (       a)  USS u  ppX-  X-  -
  nX-  X-  -
  S:  a  [        U5      nUR                  U5        g! [         a=    U R                  (       d  [        U5      eU R                  R                  SU-  5         gf = f)z|Transform the points of the base glyph and draw it onto self.

The `identifier` parameter and any extra kwargs are ignored.
r   )TransformPointPenN   z,glyph '%s' is missing from glyphSet; skipped)fontTools.pens.transformPenr   r   r   r   r   
drawPointsKeyErrorr   r	   logwarning)r   r.   r/   r   r   r   glyphrg   abcddets                r   r1    DecomposingPointPen.addComponent>  s    
 	B	"MM-0E C)'<"" ,BQ/
aeaem515=1$05CS!#  	--+M::HH>N	s   A7 7AB>=B>)r   r   r   r;   )r=   r>   r?   r@   rA   r   r	   rK   r1   rE   __classcell__)r   s   @r   r   r     s2     !1 #- -6" "r!   r   )rA   r   typingr   r   r   r   fontTools.misc.loggingToolsr   fontTools.pens.basePenr   r	   r
   fontTools.misc.transformr   r   __all__r   r   r   r   r   r   r   r:   r!   r   <module>r      s     - - 0 O O B/ /dbI, bIJR4- R4jK4 K4\WT* WTtZU- ZUzG"($4 G"r!   