
    jke                     F    d dl mZ d dlmZ d dlmZ d dlZ G d de      Zy)    )quadratic_to_curves)ContourFilterPen)ReverseContourPenNc                   6     e Zd ZdZ	 	 	 d fd	Zd Zd Z xZS )Qu2CuPena5  A filter pen to convert quadratic bezier splines to cubic curves
    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 cubic segments.
    c                 h    |rt        |      }t        | 	  |       || _        || _        || _        y )N)r   super__init__	all_cubicmax_errstats)self	other_penr   r   reverse_directionr   	__class__s         9/usr/lib/python3/dist-packages/fontTools/pens/qu2cuPen.pyr
   zQu2CuPen.__init__$   s4     ))4I#"
    c              #   L  K   t        || j                  | j                        }| j                  J|D ]E  }t	        t        |      dz
        }| j                  j                  |d      dz   | j                  |<   G |D ]#  }t        |      dk(  r
d|dd  f d|dd  f % y w)N)r      r         curveToqCurveTo)r   r   r   r   strlenget)r   qcurvescurvens        r   _quadratics_to_curvezQu2CuPen._quadratics_to_curve3   s     $QO::! 9E
Q' $

q! 4q 8

19  	.E5zQ %),,!59--		.s   B"B$c                    g }d }g }|D ]  \  }}|dk(  rE| j                   st        |      dkD  r+|d   &|d   t        d      |j                  |f|z          n7|r"|j	                  | j                  |             g }|j                  ||f       |r|d   nd } |r |j	                  | j                  |             | j                   s|}g }|D ]  \  }}|dk(  r|r|d   d   dk(  r|d   d   d   }|d   d   d   }|d   }	|ft        j                  |	d   |d   z
  |d   |d   z
        r>t        j                  |	d   |d   z
  |d   |d   z
        r|d   d   d d |z   }
||
f|d<   |j                  ||f        |S )Nr   r   z4oncurve-less contours with all_cubic not implementedr   r   )r   r   NotImplementedErrorappendextendr!   mathisclose)r   contour
quadratics	currentPt
newContouropargspt0pt1pt2newArgss              r   filterContourzQu2CuPen.filterContour?   s   
	
 	3HBZ3t9q=T"X5I8#-N  !!9,"56%%d&?&?
&KL!#J!!2t*-$(RdI	3 d77
CD~~ GJ# .D#
z"~a7HJ7V$R.+B/C$R.+B/Cq'C LLQ#a&#a&3q6/J LLQ#a&#a&3q6/J",R."3CR"84"?*,g
2 !!2t*-.  r   )FFN)__name__
__module____qualname____doc__r
   r!   r4   __classcell__)r   s   @r   r   r      s"    " 
.*r   r   )fontTools.qu2cur   fontTools.pens.filterPenr    fontTools.pens.reverseContourPenr   r(   r    r   r   <module>r>      s"     0 5 > S Sr   