
    h2                         S SK r S SKJrJ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   " S S	\5      r " S
 S\5      r " S S5      rg)    N)curve_to_quadraticcurves_to_quadratic)decomposeSuperBezierSegment)	FilterPen)ReverseContourPen)BasePointToSegmentPen)ReverseContourPointPenc                   H   ^  \ rS rSrSr   SU 4S jjrU 4S jrS rSrU =r	$ )Cu2QuPen   a  A filter pen to convert cubic bezier curves to quadratic b-splines
using the FontTools SegmentPen protocol.

Args:

    other_pen: another SegmentPen used to draw the transformed outline.
    max_err: maximum approximation error in font units. For optimal results,
        if you know the UPEM of the font, we recommend setting this to a
        value equal, or close to UPEM / 1000.
    reverse_direction: flip the contours' direction but keep starting point.
    stats: a dictionary counting the point numbers of quadratic segments.
    all_quadratic: if True (default), only quadratic b-splines are generated.
        if False, quadratic curves or cubic curves are generated depending
        on which one is more economical.
c                 l   > U(       a  [        U5      n[        TU ]	  U5        X l        X@l        XPl        g N)r   super__init__max_errstatsall_quadratic)self	other_penr   reverse_directionr   r   	__class__s         I/var/www/html/env/lib/python3.13/site-packages/fontTools/pens/cu2quPen.pyr   Cu2QuPen.__init__)   s/     ))4I#
*    c                   > U R                   XU4n[        X@R                  U R                  5      nU R                  bC  [        [        U5      S-
  5      nU R                  R                  US5      S-   U R                  U'   U R                  (       a  U R                  " USS  6   g [        U5      S:X  a  U R                  " USS  6   g [        U5      S:X  d   e[        TU ](  " USS  6   g )N   r            )
current_ptr   r   r   r   strlengetqCurveTor   curveTo)r   pt1pt2pt3curveresultnr   s          r   _convert_curveCu2QuPen._convert_curve8   s    #C0#E<<9K9KL::!CK!O$A JJNN1a014DJJqMMM6!":&6{avabz*6{a''',r   c                     [        U5      nUS:X  a  U R                  " U6   g US:  a"  [        U5       H  nU R                  " U6   M     g U R                  " U6   g )Nr   )r"   r,   r   r$   )r   pointsr+   segments       r   r%   Cu2QuPen.curveToG   sR    K6(U6v>##W- ? MM6"r   )r   r   r   FNT)
__name__
__module____qualname____firstlineno____doc__r   r,   r%   __static_attributes____classcell__)r   s   @r   r   r      s'    (  +-	# 	#r   r   c                       \ rS rSrSrS\R                  4S\R                  4S\R                  4S\R                  4S.r   SS jr	S	 r
S
 rS rS rSrg)Cu2QuPointPenS   a  A filter pen to convert cubic bezier curves to quadratic b-splines
using the FontTools PointPen protocol.

Args:
    other_point_pen: another PointPen used to draw the transformed outline.
    max_err: maximum approximation error in font units. For optimal results,
        if you know the UPEM of the font, we recommend setting this to a
        value equal, or close to UPEM / 1000.
    reverse_direction: reverse the winding direction of all contours.
    stats: a dictionary counting the point numbers of quadratic segments.
    all_quadratic: if True (default), only quadratic b-splines are generated.
        if False, quadratic curves or cubic curves are generated depending
        on which one is more economical.
r   r   r   )movelineqcurver)   Nc                     [         R                  " U 5        U(       a  [        U5      U l        OXl        X l        X@l        XPl        g r   )r   r   r	   penr   r   r   )r   other_point_penr   r   r   r   s         r   r   Cu2QuPointPen.__init__j   s6     	&&t,-o>DH&H
*r   c           	      R   [        U5      S:  d   eUS   S   S:g  n/ nUS   S   nUS   S   nU GHJ  u  pgUS:X  Ga#  U R                  U5       GH
  nUS   u  ppUS   S   US   S   pX]X/n[        XR                  U R                  5      nU R
                  bC  [        [        U5      S-
  5      nU R
                  R                  US5      S-   U R
                  U'   USS  Vs/ s H	  nUSS 0 4PM     nnUR                  XX45        U R                  (       d  [        U5      S:X  a  UR                  SU/5        OUR                  SU/5        US   S   nGM     GM0  UR                  Xg/5        US   S   nGMM     U(       a  USS  US S -   nU R                  U5        g s  snf )	Nr   r   r=   r)   r   Fr?   )
r"   _split_super_bezier_segmentsr   r   r   r   r!   r#   append_drawPoints)r   segmentsclosednew_segmentsprev_pointsprev_on_curvesegment_typer/   
sub_pointson_curvesmoothnamekwargsbcp1bcp2cubicquadr+   pt
new_pointss                       r   _flushContourCu2QuPointPen._flushContour{   s   8}!!!!Q6)rl1o#B*$, Lw&"&"C"CF"KJ5?^2Hd!+Aq!1:a=3C$*$AE-e\\4CUCUVDzz-D	A.(,

q!(<q(@

1BFq*!M*B2udB"7*J!M%%x&FG))S_-A$++Xz,BC$++Wj,AB$.rN1$5M #L  ##\$:; &r
1' %-(  (,|CR/@@L& "Ns   %F$c                    / n[        U5      S-
  nUS:X  a  UR                  U5        U$ US:  a  US   u  pEpgUS-
  n[        [        U V	V
s/ s H	  u  n	    oPM     sn
n	5      5       Hm  u  p/ nUS S  H  nUR                  USS 0 45        M     XS-
  :X  a  UR                  XEXg45        OUR                  US   SS 0 45        UR                  U5        Mo     U$ [	        SU-  5      es  sn
n	f )Nr   r   rE   FTz$expected 2 control points, found: %d)r"   rG   	enumerater   AssertionError)r   r/   sub_segmentsr+   rP   rQ   rR   rS   num_sub_segmentsrX   _irO   new_segmentpoints                  r   rF   *Cu2QuPointPen._split_super_bezier_segments   s   K!O6'( ' U-3BZ*Hd 1u!*+6,J6KB1aR6,JK" !'_E&&udB'?@ -A-.&&$'GH  &&
2dB'GH##K0"  !!G!!KLL -Ks   C)c           
      ,   U R                   nUR                  5         / nU R                  n[        U5       H  u  nu  pgXd;   a  XF   u  pU	" [	        U5      U5      (       d   SU< SU S[	        U5       35       eUS S n
US:X  a  U
nO!U
 H  u  ppUR
                  " US X40 UD6  M     US   u  ppUc
  US:X  d   eM  UR
                  " XX40 UD6  M  [        SU-  5      e   U H  u  ppUR
                  " US X40 UD6  M     UR                  5         g )Nzillegal z segment point count: expected z, got rE   r   r?   zunexpected segment type: %r)rA   	beginPath_Cu2QuPointPen__points_requiredr]   r"   addPointr^   endPath)r   rI   rA   last_offcurvespoints_requiredrb   rN   r/   r+   op	offcurvesrX   rQ   rR   rS   s                  r   rH   Cu2QuPointPen._drawPoints   sB   hh00)28)<%A%.'5#f+q)) |. /  !s&V7) #3BK	6 &/N4=0DRvFvF 5>+1":(D:'8333 LL6J6J$%B\%QRR3 *=4 )7$BLLT6:6: )7r   c                 X    U R                   b   eU R                  R                  X5        g r   )currentPathrA   addComponent)r   baseGlyphNametransformations      r   rr   Cu2QuPointPen.addComponent   s&    '''m<r   )r   r   rA   r   r2   )r3   r4   r5   r6   r7   operatoreqgerh   r   rZ   rF   rH   rr   r8    r   r   r;   r;   S   sg      HKK HKK hkk"X[[!	  +"'B8!F=r   r;   c                   d    \ 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S rS rSrg)Cu2QuMultiPen   a  A filter multi-pen to convert cubic bezier curves to quadratic b-splines
in a interpolation-compatible manner, using the FontTools SegmentPen protocol.

Args:

    other_pens: list of SegmentPens used to draw the transformed outlines.
    max_err: maximum approximation error in font units. For optimal results,
        if you know the UPEM of the font, we recommend setting this to a
        value equal, or close to UPEM / 1000.
    reverse_direction: flip the contours' direction but keep starting point.

This pen does not follow the normal SegmentPen protocol. Instead, its
moveTo/lineTo/qCurveTo/curveTo methods take a list of tuples that are
arguments that would normally be passed to a SegmentPen, one item for
each of the pens in other_pens.
c                     U(       a  U Vs/ s H  n[        USS9PM     nnXl        X l        S U l        S U l        g s  snf )NT)outputImpliedClosingLine)r   pensr   	start_ptscurrent_pts)r   
other_pensr   r   rA   s        r   r   Cu2QuMultiPen.__init__   sN     &%C "#E%   	s   =c                 4    U R                   c  [        S5      eg )NzmoveTo is requiredr   r^   r   s    r   _check_contour_is_open$Cu2QuMultiPen._check_contour_is_open   s    # !566 $r   c                 4    U R                   b  [        S5      eg )Nz closePath or endPath is requiredr   r   s    r   _check_contour_is_closed&Cu2QuMultiPen._check_contour_is_closed  s    ' !CDD (r   c                     U R                   b@  [        U R                   U R                  5       H  u  pUR                  " U6   M     S U l         g g r   )r   zipr   moveTo)r   rX   rA   s      r   _add_moveToCu2QuMultiPen._add_moveTo  s>    >>%t~~tyy9

B :!DN &r   c                 `    U R                  5         U=U l        U l        U R                  5         g r   )r   r   r   r   )r   ptss     r   r   Cu2QuMultiPen.moveTo  s)    %%',//)r   c                     U R                  5         U R                  5         [        XR                  5       H  u  p#UR                  " U6   M     Xl        g r   )r   r   r   r   lineTor   )r   r   rX   rA   s       r   r   Cu2QuMultiPen.lineTo  s@    ##%3		*GBJJO +r   c                 R   U R                  5         [        US   5      S:X  a&  U R                  U Vs/ s H  o"S   4PM
     sn5        g U R                  5         / n[	        XR
                  5       H)  u  p$UR                  " U6   UR                  US   45        M+     X0l        g s  snf )Nr   r   rE   )	r   r"   r   r   r   r   r$   rG   r   )r   
pointsListr/   r   rA   s        r   r$   Cu2QuMultiPen.qCurveTo  s    ##%z!}"KKJ?J&)J?@z995KFLL&!r
}- 6 ' @s   B$c                    / n[        U R                  U5       H  u  p4UR                  X4-   5        M     [        X R                  /[        U5      -  5      n/ nU H  nUR                  USS  5        M     U R                  U5        g )Nr   )r   r   rG   r   r   r"   r$   )r   r   curvesr    r/   
quadratics	quadratics          r   _curves_to_quadratic"Cu2QuMultiPen._curves_to_quadratic&  sy    "%d&6&6
"CJMM*-. #D(,,#f+1MN

#Iim, $j!r   c                 F    U R                  5         U R                  U5        g r   )r   r   )r   r   s     r   r%   Cu2QuMultiPen.curveTo0  s    ##%!!*-r   c                     U R                  5         U R                  c#  U R                   H  nUR                  5         M     S =U l        U l        g r   )r   r   r   	closePathr   r   rA   s     r   r   Cu2QuMultiPen.closePath4  s>    ##%>>!yy !,004>r   c                     U R                  5         U R                  c#  U R                   H  nUR                  5         M     S =U l        U l        g r   )r   r   r   rj   r   r   s     r   rj   Cu2QuMultiPen.endPath;  s>    ##%>>!yy !,004>r   c                     U R                  5         [        X R                  5       H  u  p4UR                  X5        M     g r   )r   r   r   rr   )r   	glyphNametransformationstransrA   s        r   rr   Cu2QuMultiPen.addComponentB  s1    %%'oyy9JEY. :r   )r   r   r   r   N)F)r3   r4   r5   r6   r7   r   r   r   r   r   r   r$   r   r%   r   rj   rr   r8   ry   r   r   r{   r{      sD    (	 7E"

'".11/r   r{   )rv   fontTools.cu2qur   r   fontTools.pens.basePenr   fontTools.pens.filterPenr    fontTools.pens.reverseContourPenr   fontTools.pens.pointPenr   r	   r   r;   r{   ry   r   r   <module>r      sE     C > . > 9 :8#y 8#vJ=) J=Ze/ e/r   