)Ej4ddlZddlmZmZddlmZddlmZddlm Z ddl m Z ddl m Z Gdd eZ Gd d e ZGd d ZdS)N)curve_to_quadraticcurves_to_quadratic)decomposeSuperBezierSegment) FilterPenReverseContourPen)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. FNTc|rt|}t|||_||_||_dSN)rsuper__init__max_errstats all_quadratic)self other_penrreverse_directionrr __class__s IC:\PYTHON\MyICR_Suite\python\Lib\site-packages\fontTools/pens/cu2quPen.pyrzCu2QuPen.__init__)sN  5))44I ###  *c|j|||f}t||j|j}|jEt t |dz }|j|ddz|j|<|jr|j|dddSt |dkr|j|dddSt |dksJtj |dddS)Nr) current_ptrrrrstrlengetqCurveTorcurveTo)rpt1pt2pt3curveresultnrs r_convert_curvezCu2QuPen._convert_curve8s#sC0#E4<9KLL : !CKK!O$$A JNN1a0014DJqM   - DM6!"": & & & &6{{a vabbz****6{{a'''',,,,rct|}|dkr |j|dS|dkrt|D] }|j| dS|j|dS)Nr)r!r+rr#)rpointsr*segments rr$zCu2QuPen.curveToGs KK 66 D  ( ( ( ( UU6v>> . .##W--- . . DM6 " " " "rFNT)__name__ __module__ __qualname____doc__rr+r$ __classcell__)rs@rr r sz(  + + + + + + - - - - - # # # # # # #rr c~eZdZdZdejfdejfdejfdejfdZ dd Zd Z d Z d Z d Z dS) 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(FNTctj||rt||_n||_||_||_||_dSr)r rr penrrr)rother_point_penrrrrs rrzCu2QuPointPen.__init__jsQ &t,,,  '-o>>DHH&DH  *rct|dksJ|dddk}g}|dd}|dd}|D]h\}}|dkr6||D]}|d\} } } } |dd|dd}} || || g}t||j|j}|jEt t|dz }|j|ddz|j|<d|ddD}|| | | | f|jst|dkr|d|gn|d|g|dd}C|||g|dd}j|r|dd|ddz}| |dS) Nrrr7r(rcg|]}|ddif S)FN).0pts r z/Cu2QuPointPen._flushContour..s!!M!M!MB2udB"7!M!M!Mrr9) r!_split_super_bezier_segmentsrrrrr r"append _drawPoints)rsegmentsclosed new_segments prev_points prev_on_curve segment_typer- sub_pointson_curvesmoothnamekwargsbcp1bcp2cubicquadr* new_pointss r _flushContourzCu2QuPointPen._flushContour{s 8}}!!!!!Q6) rl1o #B* $, . . L&w&&"&"C"CF"K"K66J5?^2HfdF!+Aq!1:a=3C$D*D$AE-eT\4CUVVDz-D A ..(, q!(<(cg|] \}}}}| Sr@r@)rArB_s rrCz>Cu2QuPointPen._split_super_bezier_segments..s ,J,J,JKB1aR,J,J,JrFTz$expected 2 control points, found: %d)r!rE enumeraterAssertionError) rr- sub_segmentsr*rNrOrPrQnum_sub_segmentsirM new_segmentpoints rrDz*Cu2QuPointPen._split_super_bezier_segmentss^ KK!O 66    ' ' ' ' UU-3BZ *HfdF 1u !*+,J,J6,J,J,JKK"" 1 1 :! '_AAE&&udB'?@@@@)A-..&&&$'GHHHH && 2dB'GHHH##K0000 1!!G!!KLL Lrc >|j}|g}|j}t|D]\}\}}||vr||\}} | t ||s Jd|d|dt ||dd} |dkr| }n| D]\} } } }|j| d| | fi||d\} } } }| |dksJ|j| || | fi|t d|z|D]\} } } }|j| d| | fi||dS)Nzillegal z segment point count: expected z, got r>rr9zunexpected segment type: %r)r; beginPath_Cu2QuPointPen__points_requiredr[r!addPointr\endPath)rrGr;last_offcurvespoints_requiredr_rLr-r*op offcurvesrBrOrPrQs rrFzCu2QuPointPen._drawPointssh 0)28)<)< S S %A% f..' 52r#f++q))7|77 !77),V77)#3B3K 66&/NN4=GG0FD&$ RvtFFvFFFF+1":(FD&:'83333 CL\64JJ6JJJJ$%B\%QRRR(6 ; ; $Bf CLT64 : :6 : : : : rcN|jJ|j||dSr) currentPathr; addComponent)r baseGlyphNametransformations rrmzCu2QuPointPen.addComponents/''' m^<<<<.s5"#EEEr)pensr start_pts current_pts)r other_pensrrs rrzCu2QuMultiPen.__init__sM  %J  rc2|jtddS)NzmoveTo is requiredrzr\rs r_check_contour_is_openz$Cu2QuMultiPen._check_contour_is_opens"   # !566 6 $ #rc2|jtddS)Nz closePath or endPath is requiredr}r~s r_check_contour_is_closedz&Cu2QuMultiPen._check_contour_is_closeds"   ' !CDD D ( 'rcz|j3t|j|jD]\}}|j|d|_dSdSr)ryziprxmoveTo)rrBr;s r _add_moveTozCu2QuMultiPen._add_moveTosM > %t~ty99  C B!DNNN & %rcr||x|_|_|dSr)rryrzr)rptss rrzCu2QuMultiPen.moveTos; %%''',//) rc||t||jD]\}}|j|||_dSr)rrrrxlineTorz)rrrBr;s rrzCu2QuMultiPen.lineTosb ##%%% 3 **  GB CJOOOrc^|t|ddkr!|d|DdS|g}t ||jD]+\}}|j|||df,||_dS)Nrrc g|] }|df S)rr@)rAr-s rrCz*Cu2QuMultiPen.qCurveTo..s???&&)???rr>) rr!rrrrxr#rErz)r pointsListrzr-r;s rr#zCu2QuMultiPen.qCurveTos ##%%% z!}   " " KK??J??? @ @ @ F  z4955 . .KFC CL& ! !   r } - - - -&rc.g}t|j|D]\}}|||zt||jgt |z}g}|D]}||dd ||dS)Nr)rrzrErrr!r#)rrcurvesrr- quadratics quadratics r_curves_to_quadraticz"Cu2QuMultiPen._curves_to_quadratic&s"%d&6 "C"C / / J MM*v- . . . .($,#f++1MNN  # - -I   im , , , , j!!!!!rcX|||dSr)rr)rrs rr$zCu2QuMultiPen.curveTo0s. ##%%% !!*-----rc||j|jD]}|dx|_|_dSr)rryrx closePathrzrr;s rrzCu2QuMultiPen.closePath4sO ##%%% > !y   ,004>>>rc||j|jD]}|dx|_|_dSr)rryrxrfrzrs rrfzCu2QuMultiPen.endPath;sO ##%%% > !y   ,004>>>rc|t||jD]\}}|||dSr)rrrxrm)r glyphNametransformationstransr;s rrmzCu2QuMultiPen.addComponentBsV %%'''oty99 / /JE3   Y . . . . / /rN)F)r0r1r2r3rrrrrrr#rr$rrfrmr@rrrtrts(     777EEE"""   ' ' '"""...111111/////rrt)rpfontTools.cu2qurrfontTools.pens.basePenrfontTools.pens.filterPenr fontTools.pens.reverseContourPenrfontTools.pens.pointPenr r r r6rtr@rrrsCCCCCCCC>>>>>>......>>>>>>999999::::::8#8#8#8#8#y8#8#8#vJ=J=J=J=J=)J=J=J=Ze/e/e/e/e/e/e/e/e/e/r