
    ]Mh2                         d dl Z d dlmZmZ d dlmZ d dl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 G d d          ZdS )    N)curve_to_quadraticcurves_to_quadratic)decomposeSuperBezierSegment)	FilterPenReverseContourPen)BasePointToSegmentPen)ReverseContourPointPenc                   :     e Zd ZdZ	 	 	 d fd	Z fdZd Z xZS )	Cu2QuPena	  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.
    FNTc                     |rt          |          }t                                          |           || _        || _        || _        d S N)r   super__init__max_errstatsall_quadratic)self	other_penr   reverse_directionr   r   	__class__s         W/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/fontTools/pens/cu2quPen.pyr   zCu2QuPen.__init__)   sN      	5))44I###
*    c                    | j         |||f}t          || j        | j                  }| j        Et          t          |          dz
            }| j                            |d          dz   | j        |<   | j        r | j        |dd            d S t          |          dk    r | j        |dd            d S t          |          dk    sJ  t                      j
        |dd            d S )N   r            )
current_ptr   r   r   r   strlengetqCurveTor   curveTo)r   pt1pt2pt3curveresultnr   s          r   _convert_curvezCu2QuPen._convert_curve8   s    #sC0#E4<9KLL:!CKK!O$$A JNN1a0014DJqM 	-DM6!"":&&&&6{{avabbz****6{{a'''',,,,r   c                     t          |          }|dk    r | j        |  d S |dk    rt          |          D ]} | j        |  d S  | j        |  d S )Nr   )r!   r+   r   r#   )r   pointsr*   segments       r   r$   zCu2QuPen.curveToG   s    KK66D((((UU6v>> . .##W---. . DM6""""r   FNT)__name__
__module____qualname____doc__r   r+   r$   __classcell__)r   s   @r   r   r      sz         (  + + + + + +- - - - -	# 	# 	# 	# 	# 	# 	#r   r   c                   ~    e Zd ZdZdej        fdej        fdej        fdej        f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 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(   FNTc                     t          j        |            |rt          |          | _        n|| _        || _        || _        || _        d S r   )r	   r   r
   penr   r   r   )r   other_point_penr   r   r   r   s         r   r   zCu2QuPointPen.__init__j   sQ     	&t,,, 	'-o>>DHH&DH
*r   c                    t          |          dk    sJ |d         d         dk    }g }|d         d         }|d         d         }|D ]h\  }}|dk    r6|                     |          D ]}|d         \  }	}
}}|d         d         |d         d         }}||||	g}t          || j        | j                  }| j        Et          t          |          dz
            }| j                            |d          dz   | j        |<   d |dd         D             }|                    |	|
||f           | j        st          |          dk    r|                    d|g           n|                    d|g           |d         d         }C|                    ||g           |d         d         }j|r|dd          |d d         z   }| 	                    |           d S )	Nr   r   r7   r(   r   c                     g | ]}|d di f	S )FN ).0pts     r   
<listcomp>z/Cu2QuPointPen._flushContour.<locals>.<listcomp>   s!    !M!M!MB2udB"7!M!M!Mr   r9   )
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*   
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\4CUVVDz-D		A..(,
q!(<(<q(@
1!M!M$qt*!M!M!MJ%%xv&FGGG) CS__-A-A$++Xz,BCCCC$++Wj,ABBB$.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 r@   r@   )rA   rB   _s      r   rC   z>Cu2QuPointPen._split_super_bezier_segments.<locals>.<listcomp>   s     ,J,J,JKB1aR,J,J,Jr   FTz$expected 2 control points, found: %d)r!   rE   	enumerater   AssertionError)r   r-   sub_segmentsr*   rN   rO   rP   rQ   num_sub_segmentsirM   new_segmentpoints                r   rD   z*Cu2QuPointPen._split_super_bezier_segments   s^   KK!O66''''UU-3BZ*HfdF 1u!*+,J,J6,J,J,JKK" " 1 1: !'_ A AE&&udB'?@@@@)A-..&&&$'GHHHH  &&
2dB'GHHH##K00001 !!G!!KLLLr   c           
      >   | j         }|                                 g }| j        }t          |          D ]\  }\  }}||v r||         \  }}	 |	t	          |          |          s J d|d| dt	          |                       |d d         }
|dk    r|
}n|
D ]\  }}}} |j        |d ||fi | |d         \  }}}}|	|dk    sJ  |j        ||||fi | t          d|z            |D ]\  }}}} |j        |d ||fi | |                                 d S )Nzillegal z segment point count: expected z, got r>   r   r9   zunexpected segment type: %r)r;   	beginPath_Cu2QuPointPen__points_requiredr[   r!   addPointr\   endPath)r   rG   r;   last_offcurvespoints_requiredr_   rL   r-   r*   op	offcurvesrB   rO   rP   rQ   s                  r   rF   zCu2QuPointPen._drawPoints   s   h0)28)<)< 	S 	S%A%f..'52r#f++q))  7| 7 7 !7 7),V7 7   #3B3K	66 &/NN4= G G0FD&$RvtFFvFFFF+1":(FD&:'83333  CL\64JJ6JJJJ$%B\%QRRR(6 	; 	;$BfCLT64::6::::r   c                 N    | j         J | j                            ||           d S r   )currentPathr;   addComponent)r   baseGlyphNametransformations      r   rm   zCu2QuPointPen.addComponent   s/    '''m^<<<<<r   r/   )r0   r1   r2   r3   operatoreqgerd   r   rW   rD   rF   rm   r@   r   r   r6   r6   S   s           HK HK hk"X[!	   + + + +"' ' 'B  8! ! !F= = = = =r   r6   c                   \    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 )Cu2QuMultiPena  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.
    Fc                 Z    |rd |D             }|| _         || _        d | _        d | _        d S )Nc                 0    g | ]}t          |d           S )T)outputImpliedClosingLiner   )rA   r;   s     r   rC   z*Cu2QuMultiPen.__init__.<locals>.<listcomp>   s5        "#EEE  r   )pensr   	start_ptscurrent_pts)r   
other_pensr   r   s       r   r   zCu2QuMultiPen.__init__   sM     	 %  J 	r   c                 2    | j         t          d          d S )NzmoveTo is requiredrz   r\   r   s    r   _check_contour_is_openz$Cu2QuMultiPen._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&Cu2QuMultiPen._check_contour_is_closed  s"    ' !CDDD ('r   c                 z    | j         3t          | j         | j                  D ]\  }} |j        |  d | _         d S d S r   )ry   ziprx   moveTo)r   rB   r;   s      r   _add_moveTozCu2QuMultiPen._add_moveTo  sM    >%t~ty99    C
B!DNNN &%r   c                 r    |                                   |x| _        | _        |                                  d S r   )r   ry   rz   r   )r   ptss     r   r   zCu2QuMultiPen.moveTo  s;    %%''',//)r   c                     |                                   |                                  t          || j                  D ]\  }} |j        |  || _        d S r   )r   r   r   rx   lineTorz   )r   r   rB   r;   s       r   r   zCu2QuMultiPen.lineTo  sb    ##%%%3	** 	 	GBCJOOOr   c                 ^   |                                   t          |d                   dk    r!|                     d |D                        d S |                                  g }t	          || j                  D ]+\  }} |j        |  |                    |d         f           ,|| _        d S )Nr   r   c                      g | ]}|d          fS )r   r@   )rA   r-   s     r   rC   z*Cu2QuMultiPen.qCurveTo.<locals>.<listcomp>  s    ???&&)???r   r>   )	r   r!   r   r   r   rx   r#   rE   rz   )r   
pointsListrz   r-   r;   s        r   r#   zCu2QuMultiPen.qCurveTo  s    ##%%%z!}""KK??J???@@@Fz4955 	. 	.KFCCL&!!r
}----&r   c                 .   g }t          | j        |          D ]\  }}|                    ||z              t          || j        gt          |          z            }g }|D ]}|                    |dd                      |                     |           d S )Nr   )r   rz   rE   r   r   r!   r#   )r   r   curvesr   r-   
quadratics	quadratics          r   _curves_to_quadraticz"Cu2QuMultiPen._curves_to_quadratic&  s    "%d&6
"C"C 	/ 	/JMM*v-....($,#f++1MNN

# 	- 	-Iim,,,,j!!!!!r   c                 X    |                                   |                     |           d S r   )r   r   )r   r   s     r   r$   zCu2QuMultiPen.curveTo0  s.    ##%%%!!*-----r   c                     |                                   | j        | j        D ]}|                                 d x| _        | _        d S r   )r   ry   rx   	closePathrz   r   r;   s     r   r   zCu2QuMultiPen.closePath4  sO    ##%%%>!y    ,004>>>r   c                     |                                   | j        | j        D ]}|                                 d x| _        | _        d S r   )r   ry   rx   rf   rz   r   s     r   rf   zCu2QuMultiPen.endPath;  sO    ##%%%>!y  ,004>>>r   c                     |                                   t          || j                  D ]\  }}|                    ||           d S r   )r   r   rx   rm   )r   	glyphNametransformationstransr;   s        r   rm   zCu2QuMultiPen.addComponentB  sV    %%'''oty99 	/ 	/JE3Y....	/ 	/r   N)F)r0   r1   r2   r3   r   r   r   r   r   r   r#   r   r$   r   rf   rm   r@   r   r   rt   rt      s         (	  	  	  	 7 7 7E E E" " "  
  
' 
' 
'" " ". . .1 1 11 1 1/ / / / /r   rt   )rp   fontTools.cu2qur   r   fontTools.pens.basePenr   fontTools.pens.filterPenr    fontTools.pens.reverseContourPenr   fontTools.pens.pointPenr	   r
   r   r6   rt   r@   r   r   <module>r      s    C C C C C C C C > > > > > > . . . . . . > > > > > > 9 9 9 9 9 9 : : : : : :8# 8# 8# 8# 8#y 8# 8# 8#vJ= J= J= J= J=) J= J= J=Ze/ e/ e/ e/ e/ e/ e/ e/ e/ e/r   