
    <`*                     ~    d dl mZ d dlmZmZ d dlmZ d dlmZ d dlm	Z	  G d de          Z
 G d d	e          Zd
S )    )curve_to_quadratic)AbstractPendecomposeSuperBezierSegment)ReverseContourPen)BasePointToSegmentPen)ReverseContourPointPenc                   `    e Zd ZdZ	 	 ddZd Zd Zd Zd Zd	 Z	d
 Z
d Zd Zd Zd Zd ZdS )Cu2QuPena   A filter pen to convert cubic bezier curves to quadratic b-splines
    using the FontTools SegmentPen protocol.

    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.
    ignore_single_points: don't emit contours containing only a single point

    NOTE: The "ignore_single_points" argument is deprecated since v1.3.0,
    which dropped Robofab subpport. It's no longer needed to special-case
    UFO2-style anchors (aka "named points") when using ufoLib >= 2.0,
    as these are no longer drawn onto pens as single-point contours,
    but are handled separately as anchors.
    FNc                     |rt          |          | _        n|| _        || _        || _        |r!dd l}|                    dt          d           || _        d | _        d | _	        d S )Nr   zIignore_single_points is deprecated and will be removed in future versions   )
stacklevel)
r   penmax_errstatswarningswarnUserWarningignore_single_pointsstart_pt
current_pt)self	other_penr   reverse_directionr   r   r   s          7lib/python3.11/site-packages/fontTools/pens/cu2quPen.py__init__zCu2QuPen.__init__)   s     	!(33DHH DH
 	5OOOMM ?%!  5 5 5 %9!    c                 2    | j         t          d          d S )NzmoveTo is requiredr   AssertionErrorr   s    r   _check_contour_is_openzCu2QuPen._check_contour_is_open:   s!    ?" !5666 #"r   c                 2    | j         t          d          d S )Nz closePath or endPath is requiredr   r    s    r   _check_contour_is_closedz!Cu2QuPen._check_contour_is_closed>   s!    ?& !CDDD '&r   c                 d    | j         (| j                            | j                    d | _         d S d S N)r   r   moveTor    s    r   _add_moveTozCu2QuPen._add_moveToB   s3    =$HOODM*** DMMM %$r   c                     |                                   |x| _        | _        | j        s|                                  d S d S r%   )r#   r   r   r   r'   r   pts     r   r&   zCu2QuPen.moveToG   sO    %%'''*,,( 		 	r   c                     |                                   |                                  | j                            |           || _        d S r%   )r!   r'   r   lineTor   r)   s     r   r,   zCu2QuPen.lineToM   sE    ##%%%r   c                 "   |                                   t          |          }|dk    r|                     |d                    d S |dk    r2|                                   | j        j        |  |d         | _        d S t          d|z            )N   r   &illegal qcurve segment point count: %d)r!   lenr,   r'   r   qCurveTor   r   )r   pointsns      r   r2   zCu2QuPen.qCurveToS   s    ##%%%KK66KKq	"""""UUDHv&&$RjDOOO !IA!MNNNr   c                    | j         |||f}t          || j                  }| j        Et	          t          |          dz
            }| j                            |d          dz   | j        |<    | j        |dd            d S )Nr   r   r.   )r   r   r   r   strr1   getr2   )r   pt1pt2pt3curve	quadraticr4   s          r   _curve_to_quadraticzCu2QuPen._curve_to_quadratic_   s    #sC0&udl;;	:!C	NNQ&''A JNN1a0014DJqMy}%%%%r   c                 B   |                                   t          |          }|dk    r | j        |  d S |dk    rt          |          D ]} | j        |  d S |dk    r | j        |  d S |dk    r|                     |d                    d S t          d|z            )N   r   r.   r   z%illegal curve segment point count: %d)r!   r1   r=   r   r2   r,   r   )r   r3   r4   segments       r   curveTozCu2QuPen.curveTog   s    ##%%%KK66$D$f----UU6v>> 3 3(('2223 3!VVDM6""""!VVKKq	""""" !H1!LMMMr   c                     |                                   | j        | j                                         d x| _        | _        d S r%   )r!   r   r   	closePathr   r    s    r   rC   zCu2QuPen.closePathw   sB    ##%%%= H   *..$---r   c                     |                                   | j        | j                                         d x| _        | _        d S r%   )r!   r   r   endPathr   r    s    r   rE   zCu2QuPen.endPath~   sB    ##%%%= H*..$---r   c                 d    |                                   | j                            ||           d S r%   )r#   r   addComponent)r   	glyphNametransformations      r   rG   zCu2QuPen.addComponent   s2    %%'''i88888r   )FNF)__name__
__module____qualname____doc__r   r!   r#   r'   r&   r,   r2   r=   rA   rC   rE   rG    r   r   r
   r
      s         $ >C27   "7 7 7E E E! ! !
    
O 
O 
O& & &N N N / / // / /9 9 9 9 9r   r
   c                   6    e Zd ZdZ	 	 d	dZd Zd Zd Zd ZdS )
Cu2QuPointPena   A filter pen to convert cubic bezier curves to quadratic b-splines
    using the RoboFab PointPen protocol.

    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.
    FNc                     t          j        |            |rt          |          | _        n|| _        || _        || _        d S r%   )r   r   r   r   r   r   )r   other_point_penr   r   r   s        r   r   zCu2QuPointPen.__init__   sE    &t,,, 	'-o>>DHH&DH


r   c                 J   t          |          dk    sJ |d         d         dk    }g }|d         d         }|d         d         }|D ]-\  }}|dk    r|                     |          D ]}|d         \  }	}
}}|d         d         |d         d         }}||||	g}t          || j                  }| j        Et          t          |          dz
            }| j                            |d          dz   | j        |<   d |dd         D             }|                    |	|
||f           |                    d|g           |d         d         }|                    ||g           |d         d         }/|r|dd          |d d         z   }|                     |           d S )	Nr.   r   mover/   r;   r   c                     g | ]}|d di f	S FNrN   ).0r*   s     r   
<listcomp>z/Cu2QuPointPen._flushContour.<locals>.<listcomp>   s!    !M!M!MB2udB"7!M!M!Mr   qcurve)	r1   _split_super_bezier_segmentsr   r   r   r6   r7   append_drawPoints)r   segmentsclosednew_segmentsprev_pointsprev_on_curvesegment_typer3   
sub_pointson_curvesmoothnamekwargsbcp1bcp2cubicquadr4   
new_pointss                      r   _flushContourzCu2QuPointPen._flushContour   s   8}}!!!!!Q6)rl1o#B*$, 	. 	. L&w&&"&"C"CF"K"K 6 6J5?^2HfdF!+Aq!1:a=3C$D*D$AE-eT\BBDz-D		A..(,
q!(<(<q(@
1!M!M$qt*!M!M!MJ%%xv&FGGG '':(>???$.rN1$5MM6 ##\6$:;;; &r
1 	A (,|CRC/@@L&&&&&r   c                    g }t          |          dz
  }|dk    r|                    |           n|dk    r|d         \  }}}}|dz
  }t          t          d |D                                 D ]\  }	}
g }|
d d         D ]}|                    |dd i f           |	|dz
  k    r|                    ||||f           n|                    |
d         dd i f           |                    |           nt	          d|z            |S )Nr.   r   r/   c                     g | ]	\  }}}}|
S rN   rN   )rW   r*   _s      r   rX   z>Cu2QuPointPen._split_super_bezier_segments.<locals>.<listcomp>   s3     H2 H2 H2&2q!QBH2 H2 H2r   FTz$expected 2 control points, found: %d)r1   r[   	enumerater   r   )r   r3   sub_segmentsr4   rd   re   rf   rg   num_sub_segmentsirc   new_segmentpoints                r   rZ   z*Cu2QuPointPen._split_super_bezier_segments   sv   KK!O66''''UU-3BZ*HfdF 1u!*+F H2 H2*0H2 H2 H2 ,3 ,3 "4 "4 1 1: '_ A AE&&udB'?@@@@)A-..&&&$'GHHHH  &&
2dB'GHHH##K00001 !6:< < <r   c                    | j         }|                                 g }t          |          D ]\  }\  }}|dv rLt          |          dk    sJ dt          |          z              |d         \  }}}	}
 |j        ||||	fi |
 X|dk    rt          |          dk    sJ dt          |          z              |d d         }|r$|dk    r|}n|D ]\  }}}	}
 |j        |d ||	fi |
 |d         \  }}}	}
| |j        ||||	fi |
 t          d	|z            |D ]\  }}}	}
 |j        |d ||	fi |
 |                                 d S )
N)rT   liner.   z$illegal line segment point count: %dr   rY   r   r0   r/   zunexpected segment type: %r)r   	beginPathrq   r1   addPointr   rE   )r   r]   r   last_offcurvesrt   rb   r3   r*   re   rf   rg   	offcurvess               r   r\   zCu2QuPointPen._drawPoints   s   h)28)<)< 	B 	B%A%f///6{{a''':S[[H (''+1!9(FD&RvtFFvFFFF))6{{a'''<s6{{J (''"3B3K	 KAvv *3:C K K6Rv(CLT64JJ6JJJJ+1":(FD&:  CL\64JJ6JJJJ %1L@B B B*8 	; 	;&RvCLT64::6::::r   c                 N    | j         J | j                            ||           d S r%   )currentPathr   rG   )r   baseGlyphNamerI   s      r   rG   zCu2QuPointPen.addComponent   s/    '''m^<<<<<r   rV   )	rJ   rK   rL   rM   r   rm   rZ   r\   rG   rN   r   r   rP   rP      sy        	 	 DI   ' ' '<  8$ $ $L= = = = =r   rP   N)fontTools.cu2qur   fontTools.pens.basePenr   r    fontTools.pens.reverseContourPenr   fontTools.pens.pointPenr   r   r
   rP   rN   r   r   <module>r      s    / . . . . . K K K K K K K K > > > > > > 9 9 9 9 9 9 : : : : : :p9 p9 p9 p9 p9{ p9 p9 p9fx= x= x= x= x=) x= x= x= x= x=r   