L i2ddlZddlmZmZddlmZddlmZddlm Z ddl m Z ddl m Z Gdd eZ Gd d e ZGd d Zy)N)curve_to_quadraticcurves_to_quadratic)decomposeSuperBezierSegment) FilterPen)ReverseContourPen)BasePointToSegmentPen)ReverseContourPointPenc:eZdZdZ dfd ZfdZdZxZS)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. ch|r t|}t| |||_||_||_yN)rsuper__init__max_errstats all_quadratic)self other_penrreverse_directionrr __class__s ]/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/fontTools/pens/cu2quPen.pyrzCu2QuPen.__init__)s5 ))4I #  *c|j|||f}t||j|j}|jCt t |dz }|jj|ddz|j|<|jr|j|ddyt |dk(r|j|ddyt |dk(sJt|(|ddy)Nr) current_ptrrrrstrlengetqCurveTorcurveTo)rpt1pt2pt3curveresultnrs r_convert_curvezCu2QuPen._convert_curve8s#sC0#E4<<9K9KL :: !CK!O$A JJNN1a014DJJqM    DMM6!": &6{a vabz*6{a''',rct|}|dk(r|j|y|dkDr t|D]}|j|y|j|y)Nr)r r*rr")rpointsr)segments rr#zCu2QuPen.curveToGs] K 6 D   ( U6v> .###W- . DMM6 "rFNT)__name__ __module__ __qualname____doc__rr*r# __classcell__)rs@rr r s"(  + - #rr ceZdZdZdej fdej fdej fdej fdZ d dZdZ d Z d Z d Z y) Cu2QuPointPenaA 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. rrr)movelineqcurver'Nctj||rt||_n||_||_||_||_yr )rrr penrrr)rother_point_penrrrrs rrzCu2QuPointPen.__init__js> &&t, -o>DH&DH  *rc :t|dk\sJ|dddk7}g}|dd}|dd}|D]E\}}|dk(r|j|D]}|d\} } } } |dd|dd}} || || g}t||j|j}|j Ct t|dz }|j j|ddz|j |<|ddDcgc]}|ddif }}|j| | | | f|jst|dk(r|jd|gn|jd|g|dd} +|j||g|dd}H|r |dd|ddz}|j|ycc}w) Nrrr6r'rFr8) r _split_super_bezier_segmentsrrrrrr!append _drawPoints)rsegmentsclosed new_segments prev_points prev_on_curve segment_typer, sub_pointson_curvesmoothnamekwargsbcp1bcp2cubicquadr)pt new_pointss r _flushContourzCu2QuPointPen._flushContour{s8}!!!!Q6) rl1o #B* $, . L&w&"&"C"CF"K6J5?^2HfdF!+Aq!1:a=3C$D*D$AE-eT\\4CUCUVDzz-D A .(, q!(z*Cu2QuPointPen._split_super_bezier_segmentss/ K!O 6    '('U-3BZ *HfdF 1u !*+6,JKB1aR,JK" 1 :! '_AE&&udB'?@A)A-.&&&$'GH && 2dB'GH##K0 1!!G!!KL L-Ks C&c $|j}|jg}|j}t|D]\}\}}||vr||\}} | t ||sJd|d|dt ||dd} |dk(r| }n"| D]\} } } }|j | d| | fi||d\} } } }| |dk(sJ|j | || | fi|t d|z|D]\} } } }|j | d| | fi||jy)Nzillegal z segment point count: expected z, got r=rr8zunexpected segment type: %r)r: beginPath_Cu2QuPointPen__points_requiredrTr addPointrUendPath)rrAr:last_offcurvespoints_requiredrYrFr,r)op offcurvesrPrIrJrKs rr@zCu2QuPointPen._drawPointssthh 00)28)< S %A% f.' 52#f+q)|./ !s&V 7)#3BK 6&/N4=G0FD&$ RvtFvFG+1":(FD&:'8333 CLL\64J6J$%B\%QRR3 S4)7 ; $Bf CLLT64 :6 : ; rcX|jJ|jj||yr ) currentPathr: addComponent)r baseGlyphNametransformations rrgzCu2QuPointPen.addComponents(''' m^r@rgrrr5r5Ssg  HKK HKK hkk"X[[!   +"'B8!F=rr5cZeZdZdZddZdZdZdZdZdZ dZ d Z d Z d Z d Zd Zy) Cu2QuMultiPenaA 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~|r|Dcgc]}t|d}}||_||_d|_d|_ycc}w)NT)outputImpliedClosingLine)rpensr start_pts current_pts)r other_pensrrr:s rrzCu2QuMultiPen.__init__sO &"#EJ  s:c2|j tdy)NzmoveTo is requiredrtrUrs r_check_contour_is_openz$Cu2QuMultiPen._check_contour_is_opens    # !56 6 $rc2|j tdy)Nz closePath or endPath is requiredrwrxs r_check_contour_is_closedz&Cu2QuMultiPen._check_contour_is_closeds    ' !CD D (rc|j?t|j|jD]\}}|j|d|_yyr )rsziprrmoveTo)rrPr:s r _add_moveTozCu2QuMultiPen._add_moveTosG >> %t~~tyy9 C B !DN &rc`|j|x|_|_|jyr )r{rsrtr)rptss rr~zCu2QuMultiPen.moveTos) %%',//) rc|j|jt||jD]\}}|j|||_yr )ryrr}rrlineTort)rrrPr:s rrzCu2QuMultiPen.lineTosM ##% 3 * GB CJJO rcN|jt|ddk(r$|j|Dcgc]}|df c}y|jg}t ||j D])\}}|j ||j|df+||_ycc}w)Nrrr=) ryr rrr}rrr"r?rt)r pointsListr,rtr:s rr"zCu2QuMultiPen.qCurveTos ##% z!}  " KKJ?&&)? @   z4995 .KFC CLL& !   r } - .'@s B"cg}t|j|D]\}}|j||zt||jgt |z}g}|D]}|j|dd|j |y)Nr)r}rtr?rrr r")rrcurvesrr, quadratics quadratics r_curves_to_quadraticz"Cu2QuMultiPen._curves_to_quadratic&s"%d&6&6 "C / J MM*v- . /($,,#f+1MN  # -I   im , - j!rcF|j|j|yr )ryr)rrs rr#zCu2QuMultiPen.curveTo0s ##% !!*-rc|j|j!|jD]}|jdx|_|_yr )ryrsrr closePathrtrr:s rrzCu2QuMultiPen.closePath4sC ##% >> !yy   ,004>rc|j|j!|jD]}|jdx|_|_yr )ryrsrrr`rtrs rr`zCu2QuMultiPen.endPath;sC ##% >> !yy   ,004>rc|jt||jD]\}}|j||yr )r{r}rrrg)r glyphNametransformationstransr:s rrgzCu2QuMultiPen.addComponentBs< %%'otyy9 /JE3   Y . /rN)F)r/r0r1r2rryr{rr~rr"rr#rr`rgrmrrrorosD(  7E"   '".11/rro)rjfontTools.cu2qurrfontTools.pens.basePenrfontTools.pens.filterPenr fontTools.pens.reverseContourPenrfontTools.pens.pointPenrr r r5rormrrrsEC>.>9:8#y8#vJ=)J=Ze/e/r