)Ej4 ddlZn#eef$r ddlmZYnwxYwejZddlmZddlm Z ddl Z ddl m Z m Z mZdgZejejejejejejejejejejejejd Zejejejejej d Zejejejejejejejejejejejejej d ZejejejejejejejdZee eefefZdZdZdZejejej d5de e ededede e edffdZ e dgdZ!ejd6idejdejd ejd!ejd"ejd#ejd$ejd%ejd&ejd'ejd(ejd)ejdejd*ejd+ejd,ejd-ejd.ejd/ejd0ejd1ejd5d2Z"d3Z#e$d4kr e#dSdS)7N)cython)splitCubicAtTC) namedtuple)ListTupleUnionquadratic_to_curves) tolerancep0p1p2p3)midderiv3c*t||krt||krdS|d||zzz|zdz}t||krdS||z|z |z dz}t|||zdz||z ||ot|||z||zdz||S)aCheck if a cubic Bezier lies within a given distance of the origin. "Origin" means *the* origin (0,0), not the start of the curve. Note that no checks are made on the start and end positions of the curve; this function only checks the inside of the curve. Args: p0 (complex): Start point of curve. p1 (complex): First handle of curve. p2 (complex): Second handle of curve. p3 (complex): End point of curve. tolerance (double): Distance from origin. Returns: bool: True if the cubic Bezier ``p`` entirely lies within a distance ``tolerance`` of the origin, False otherwise. Tg?F?)abscubic_farthest_fit_inside)r r r rr rrs GC:\PYTHON\MyICR_Suite\python\Lib\site-packages\fontTools/qu2cu/qu2cu.pyrr(s: 2ww)B9 4 4t R"W  "e +C 3xx)u2glR5 (F $ R"WOS6\3    W #CvR3I V VWr r r p1_2_3c0|dz}||dz|z|dz|z|fS)zAGiven a quadratic bezier curve, return its degree-elevated cubic.gUUUUUU?gUUUUUU?rs relevate_quadraticrRs55\F u  u   r) startnk prod_ratio sum_ratioratiotr r r rcld}ddg}td|D]}|||z}|||zdz }|d|dksJt|d|dz t|d|dz z }||z}|z |fd|ddD}||d} ||d} |||zdz d} |||zdz d} | | | z |r|dndz z} | | | z |r d|dz ndz z} | | | | f} | |fS) zGive a cubic-Bezier spline, reconstruct one cubic-Bezier that has the same endpoints and tangents and approxmates the spline.g?rrcg|]}|z Srr).0r#r!s r z merge_curves..s ) ) )A!i- ) ) )rN)rangerappend)curvesrrr tsrckc_beforer"r r r rcurver!s @r merge_curvesr2es(JI B 1a[[   EAI %!)a-(!u ####BqEBqEM""S!x{)B%C%CCe Z  ) * ) ) )CRC ) ) )B q B q B  A q !B  A q !B rBwB-2a55A. .B rBw24A2JJ15 5B R E "9r)count num_offcurvesioff1off2onct|}d}t|dz }td|D]A}||}||dz}|||z dzz}||dz|z||dz }B|S)Nrr&r%r)listlenr+insert)pqr3r4r5r6r7r8s radd_implicit_on_curvesr?s QA EFFQJM 1m $ $tQx TD[C' ' Q###   Hrc,td|d|)Nz1Quadratic splines must connect end-to-start; got z then  ValueError)pointprevious_points r_raise_incompatible_pointrEs( ]N]]TY]]  rcJt|dkrtddS)Nrz0Quadratic splines must contain at least 3 points)r;rB)splines r_validate_spline_lengthrHs' 6{{QKLLLrc0|dkrtddS)Nrz!max_err must be greater than zerorA)max_errs r_validate_positive_tolerancerKs!!||<===|r)cost is_complexrFquadsrJ all_cubicreturn.c|sgSt||D]}t|t|ddtu}|s d|D}|ddg}dg}d}|D]}|d|dkrt |d|dt t |dz D]1} |dz }||||2t|dd} | | | |dz }||t||||} |s d| D} | S)aConverts a connecting list of quadratic splines to a list of quadratic and cubic curves. A quadratic spline is specified as a list of points. Either each point is a 2-tuple of X,Y coordinates, or each point is a complex number with real/imaginary components representing X,Y coordinates. The first and last points are on-curve points and the rest are off-curve points, with an implied on-curve point in the middle between every two consequtive off-curve points. Returns: The output is a list of tuples of points. Points are represented in the same format as the input, either as 2-tuples or complex numbers. If ``quads`` is empty, returns an empty list. Each tuple is either of length three, for a quadratic curve, or four, for a cubic curve. Each curve's last point is the same as the next curve's first point. Args: quads: quadratic splines max_err: absolute error tolerance; defaults to 0.5 all_cubic: if True, only cubic curves are generated; defaults to False Raises: ValueError: if an input spline has fewer than 3 points, or if adjacent splines do not connect end-to-start. rc&g|]}d|DS)c4g|]\}}t||Sr)complex)r(xys rr)z2quadratic_to_curves...s$000FQ'!Q--000rr)r(r=s rr)z'quadratic_to_curves..s'@@@Q00a000@@@rr%r*r&Nc@g|]}td|DS)c32K|]}|j|jfVdSN)realimag)r(cs r z1quadratic_to_curves...s+88Q(888888r)tuple)r(r1s rr)z'quadratic_to_curves..s/MMMU%88%88888MMMr) rKrHtyperTrEr+r;r,r?popextendspline_to_curves) rNrJrOrGrMr>costsrLr=r5qqr-s rr r sP   )))((''''eAhqk""g-J A@@%@@@ q! A CE D    R5AaD== %adAbE 2 2 2s1vvz""  A AID LL    LL     #A & &qrr *      T a ; ;F NMMfMMM MrSolution) num_pointserror start_indexis_cubicr5jrr i_sol_count j_sol_countthis_sol_countr errrg i_sol_error j_sol_errorrir3r r r rvuc tdks Jdfdtdtdz dD}t}tdt|D]}||dz d}||d}||d} t||z t| |z z|t| |z zkr||t ddddg} t t|dzdzddd} d} tdt|dzD]}| } t| |D]}| |j| |j}}|sH|d|zdz |d|zz dz}||z}|}t ||||z d}|| kr|} |dkrg t||||z \}}n#t$rYwxYwtg||R}g}d}t|D][\}}|||z}t|d|dz }t||}||krn| |\||krt|D]V\}}|||z}tdt||D\}}} }t!||| ||s|dz}nW||kr|dz}t||}t ||||z d }|| kr|} |dkrn| | ||vr|} g}g} t| dz }|rK| |j| |j}"}!| || |"||!z}|Kg}#d}t't)t|| D]p\}}"|"r.|# t||||z dn9t||D](}|# |dz|dzdz)|}q|#S) aF q: quadratic spline with alternating on-curve / off-curve points. costs: cumulative list of encoding cost of q in terms of number of points that need to be encoded. Implied on-curve points do not contribute to the cost. If all points need to be encoded, then costs will be range(1, len(q)+1). rz+quadratic spline requires at least 3 pointsc8g|]}t||dzS)r)r)r(r5r>s rr)z$spline_to_curves..2s8-.1QQY<(rrr&r%Fc3&K|] \}}||z V dSrYr)r(rqrrs rr]z#spline_to_curves..ps*&L&LAq1u&L&L&L&L&L&LrT)r;r+setraddrerfrgr2ZeroDivisionErrorr enumeratemaxr,r^ziprrhrireversedr:)$r>rcr rOelevated_quadraticsforcedr5r r r sols impossiblerbest_solrjrlrp this_countrkroi_solr1r.reconstructed_iter reconstructedrgrreconstorigrnrsplitscubicr3rir-s$` rrbrbs2B q66Q;;;E;;;273q66A:q2I2I UUF 1c-.. / / Q ' *  #A &  #A & rBw<<#b2g,, &Sb\\)A A A JJqMMM Q1e $ $ %D#122Q6:Aq%HHJ E 1c-..2 3 3BBua< < A'+Aw'947=K "1q519-a!e rs&&MMMM $&&&%%%%%%%%& ?555555""""""  ! ! m ~ ~ ~ ~ 6>&.999WW:9W@ ~ ~ ~ >      * j j}m - m ~ ~ ~ ~   $$  $N ** j   ~       eE5L!7*+ MMM >>>  z BB U B BB %s  BBB BJ :j"T"T"T U U jj jj jj **     ::mm   --  jjZZ ** ~~!"~~#$~~%&~~'( nn)* nn+.vvv/.vr---$ zDFFFFFs