L i^dZddlmZddlZddlmZmZmZmZm Z ddl m Z ddl m Z ddlmZmZddlmZmZmZgd Ze eefZeeZee eeeeefZeeZee eefZGd d e ZGd d ZGddeZ Gdde Z!GddeZ"GddeZ#GddeZ$Gdde eZ%y)a ========= PointPens ========= Where **SegmentPens** have an intuitive approach to drawing (if you're familiar with postscript anyway), the **PointPen** is geared towards accessing all the data in the contours of the glyph. A PointPen has a very simple interface, it just steps through all the points in a call from glyph.drawPoints(). This allows the caller to provide more data for each point. For instance, whether or not a point is smooth, and its name. ) annotationsN)AnyDictListOptionalTuple)StrEnum)LogMixin)DecomposedTransformIdentity) AbstractPenMissingComponentErrorPenError)AbstractPointPenBasePointToSegmentPenPointToSegmentPenSegmentToPointPenGuessSmoothPointPenReverseContourPointPenReverseFlippedceZdZdZdZdZdZy)raHow to handle flipped components during decomposition. NO: Don't reverse flipped components KEEP_START: Reverse flipped components, keeping original starting point ON_CURVE_FIRST: Reverse flipped components, ensuring first point is on-curve no keep_starton_curve_firstN)__name__ __module__ __qualname____doc__NO KEEP_STARTON_CURVE_FIRST]/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/fontTools/pens/pointPen.pyrr,s BJ%Nr#rceZdZdZdd dZd dZ d d dZ d d dZ d ddZy)rzBaseclass for all PointPens.Nc t)zStart a new sub path.NotImplementedErrorself identifierkwargss r$ beginPathzAbstractPointPen.beginPath<!!r#ct)zEnd the current sub path.r'r*s r$endPathzAbstractPointPen.endPath@r.r#c t)z$Add a point to the current sub path.r'r*pt segmentTypesmoothnamer+r,s r$addPointzAbstractPointPen.addPointDs "!r#c t)zAdd a sub glyph.r')r* baseGlyphNametransformationr+r,s r$ addComponentzAbstractPointPen.addComponentPs "!r#c t)zAdd a VarComponent sub glyph. The 'transformation' argument must be a DecomposedTransform from the fontTools.misc.transform module, and the 'location' argument must be a dictionary mapping axis tags to their locations. )AttributeErrorr* glyphNamer;locationr+r,s r$addVarComponentz AbstractPointPen.addVarComponentZs r#N)r+ Optional[str]r,rreturnNonerErFNFNN)r4zTuple[float, float]r5rDr6boolr7rDr+rDr,rrErF) r:strr;z/Tuple[float, float, float, float, float, float]r+rDr,rrErF) r@rJr;r rAzDict[str, float]r+rDr,rrErF) rrrrr-r1r8r<rBr"r#r$rr9s&""&*"$( "  "# " "  " " " "  " %) ""H"" "  "  "%) ,#  "    r#rc:eZdZdZddZd dZd dZddZ d dZy) ra/ Base class for retrieving the outline in a segment-oriented way. The PointPen protocol is simple yet also a little tricky, so when you need an outline presented as segments but you have as points, do use this base implementation as it properly takes care of all the edge cases. cd|_yrC) currentPathr0s r$__init__zBasePointToSegmentPen.__init__ts r#Nc @|j tdg|_y)NzPath already begun.)rMrr)s r$r-zBasePointToSegmentPen.beginPathws"    '01 1r#ct)aOverride this method. It will be called for each non-empty sub path with a list of segments: the 'segments' argument. The segments list contains tuples of length 2: (segmentType, points) segmentType is one of "move", "line", "curve" or "qcurve". "move" may only occur as the first segment, and it signifies an OPEN path. A CLOSED path does NOT start with a "move", in fact it will not contain a "move" at ALL. The 'points' field in the 2-tuple is a list of point info tuples. The list has 1 or more items, a point tuple has four items: (point, smooth, name, kwargs) 'point' is an (x, y) coordinate pair. For a closed path, the initial moveTo point is defined as the last point of the last segment. The 'points' list of "move" and "line" segments always contains exactly one point tuple. r')r*segmentss r$ _flushContourz#BasePointToSegmentPen._flushContour|s 4"!r#c|j td|j}d|_|syt|dk(r'|d\}}}}}d||||fgfg}|j|yg}|dddk(r5|d\}}}}}|j d||||fgf|j dnNd}t t|D]} || d}|| }n||j dn||dzd|d|dzz}g} |D]5\}}}}}| j ||||f|!|j || fg} 7|j|y)NzPath not begun.rmove)NqcurveNNN)rMrlenrRappendpoprange) r*pointsr4r5r6r7r,rQ firstOnCurveicurrentSegments r$r1zBasePointToSegmentPen.endPaths    #,- -!!  v;! 4:1I 1B VT6&,FD&/I.J%K$LH   x (  !9Q<6 !5;1I 1B VT6 OOVr64&@%AB C JJqM  L3v;' $Qil *#$L   # @A q 0 23f=O|a?O6PP+-5; 1B VT6  ! !2vtV"< =" OO[.9 :N   8$r#c r|j td|jj|||||fyNPath not begun)rMrrXr3s r$r8zBasePointToSegmentPen.addPoints;    #+, , [&$ GHr#rGrC)rQ SegmentListrErFrH) rrrrrNr-rRr1r8r"r#r$rrks)  "8.%bIMIr#rc(eZdZdZdddZdZddZy) rz Adapter class that converts the PointPen protocol to the (Segment)Pen protocol. NOTE: The segment pen does not support and will drop point names, identifiers and kwargs. cJtj|||_||_yrC)rrNpenoutputImpliedClosingLine)r* segmentPenrfs r$rNzPointToSegmentPen.__init__s&&t,(@%r#c "|s td|j}|dddk(r=d}|dd}t|dk7rtdt||d\}}}}|d=nd}|d\}}|d\}}}}|n|j||j}t|} |} t | D]} || \}}|D cgc] \} }}}|  }} }|d k(rPt|dk7rtd t||d} | dz| k7s |s|r| | k(sb|j | | } v|d k(r|j||d} |d k(r|j||d} td ||r|jy|jycc}} w)NzMust have at least one segment.rrUFrTz"Illegal move segment point count: Tlinez"Illegal line segment point count: curverVzIllegal segmentType: ) rrerWmoveTorfrZlineTocurveToqCurveTo closePathr1) r*rQreclosedr[movePt_r5rf nSegmentslastPtr]r4s r$rRzPointToSegmentPen._flushContours<= =hh A;q>V #Fa[^F6{a!CCK=QRR$QiOFAq! F"*2, K$RjOFAq! >  JJv #'#@#@ M y! FA"*1+ K,23[RAqb3F3f$v;!#"%GF }#UVVAYEY&/!V|JJrNF' V$( f%!6{mDEE? F@  MMO KKMC4s>F Nc @~~|jj||yrC)rer<r*r@ transformr+r,s r$r<zPointToSegmentPen.addComponents   i3r#)F)rfrIrErFrC)rrrrrNrRr<r"r#r$rrsA ?B4r#rcLeZdZdZd d dZd dZdZdZdZdZ dZ d Z d Z y )rz] Adapter class that converts the (Segment)Pen protocol to the PointPen protocol. cT|rt||_d|_y||_d|_yrC)rrecontour)r*pointPen guessSmooths r$rNzSegmentToPointPen.__init__+s, *84DHCG  DHBF r#c|j}|j|jD]\}}|j|||j y)N)r5)rer-r{r8r1)r*rer4r5s r$rRzSegmentToPointPen._flushContour2sDhh #|| 6OB LLL 5 6 r#cLg|_|jj|dfy)NrU)r{rXr*r4s r$rlzSegmentToPointPen.moveTo9s  RL)r#cl|j td|jj|dfy)N'Contour missing required initial moveTorj)r{rrXrs r$rmzSegmentToPointPen.lineTo=s. << DE E RL)r#c|s td|j td|ddD]}|jj|df!|jj|ddfy)NMust pass in at least one pointrrirk TypeErrorr{rrXr*ptsr4s r$rnzSegmentToPointPen.curveToBsm=> > << DE Ecr( ,B LL  T + , SWg./r#c|s td|dg|_n|j td|ddD]}|jj|df!|d!|jj|ddfyy)NrrirrVrrs r$rozSegmentToPointPen.qCurveToKs=> > r7?DL||#HIIcr( ,B LL  T + , r7  LL  R( 3 4 r#c~|j tdt|jdkDrO|jdd|jddk(r*|jd|jd<|jd=n(|jd\}}|dk(r|df|jd<|jd|_y)NrrTrrirUrj)r{rrWrR)r*r4tps r$rpzSegmentToPointPen.closePathXs << DE E t|| q T\\!_Q%74<<;KA;N%N"ll2.DLLO R \\!_FBV|"$f* Q  r#c`|j td|jd|_y)Nr)r{rrRr0s r$r1zSegmentToPointPen.endPathgs+ << DE E  r#cj|j td|jj||y)N1Components must be added before or after contours)r{rrer<)r*r@rxs r$r<zSegmentToPointPen.addComponentms, << #NO O i3r#N)TrG) rrrrrNrRrlrmrnrorpr1r<r"r#r$rr%s5 G** 0 5  4r#rcHeZdZdZd dZdZd dZdZ d dZd dZ d d Z y) rz Filtering PointPen that tries to determine whether an on-curve point should be "smooth", ie. that it's a "tangent" point or a "curve" point. c.||_||_d|_yrC)_outPen_error_points)r*outPenerrors r$rNzGuessSmoothPointPen.__init__ys   r#c|j td|j}t|}|sy|dddk(rtd|dz }n|dkDrtd|dz }ng}|D]}||\}}}}} ||dz } |dz} || d || d,||d}|| d} || d} || k7sJ|| k7sP|d| dz |d| dz }}| d|dz | d|dz }}t j ||}t j ||}t ||z |jks||d|| f||<|D](\}}}}} |jj||||fi| *y)NrarrTrUriT) rrrWrZmathatan2absrrr8)r*r[nPointsindicesr]r4r5rsr7r,prevnextprevPtnextPtdx1dy1dx2dy2a1a2r6s r$rRz!GuessSmoothPointPen._flushContour~s << +, ,f+  !9Q<6 !Aw{+G q[B! ,GG DA/5ay ,B Qf"q5Dq5Dd|A*vd|A/J1BD\!_FD\!_FV|f a56!9,befQi.?S!!9r!u,fQi"Q%.?SZZS)ZZS)rBw<$++- "KtV CF1I% D(6< K 1B VT6 !DLL ! !"k64 J6 J Kr#Nc |j tdg|_|||d<|jjdi|y)NPath already begunr+r")rrrr-r)s r$r-zGuessSmoothPointPen.beginPathsF << #/0 0  !#-F<  ((r#cf|j|jjd|_yrC)rRrr1rr0s r$r1zGuessSmoothPointPen.endPaths%   r#c |j td|||d<|jj||d||fy)Nrar+F)rrrXr3s r$r8zGuessSmoothPointPen.addPointsG << +, ,  !#-F<  ReT6BCr#c ||j td|||d<|jj||fi|yNrr+)rrrr<)r*r@r;r+r,s r$r<z GuessSmoothPointPen.addComponentsC << #NO O  !#-F< ! !!)^FvFr#c ~|j td|||d<|jj|||fi|y)Nz4VarComponents must be added before or after contoursr+)rrrrBr?s r$rBz#GuessSmoothPointPen.addVarComponentsG << #QR R  !#-F< $ $$YSFSr#)g?rCrH) rrrrrNrRr-r1r8r<rBr"r#r$rrss<  &KP) IMDG?CTr#rc<eZdZdZdZdZd dZdZ d dZd dZ y) ra This is a PointPen that passes outline data to another PointPen, but reversing the winding direction of all contours. Components are simply passed through unchanged. Closed contours are reversed in such a way that the first point remains the first point. c ||_d|_yrC)recurrentContour)r*outputPointPens r$rNzReverseContourPointPen.__init__s!"r#ct|j}|j}|s-|j|j|j y|dddk7}|sd}nT|j |j dd}tt|D]}||d |}n|d}n||d}|j|s"|dd|j d|dd|j|j|D](\}}} } } ||} |}nd} |j|f| | | d| *|j y)N)r+rrTrU)r5r6r7) rerr-currentContourIdentifierr1rXrYrZrWreverser8) r*rer{rqlastSegmentTyper\r]r4nextSegmentTyper6r7r,r5s r$rRz$ReverseContourPointPen._flushContoursehh%% MMT%B%BM C KKM A&($O NN7;;q> *L3w<( 1:a=,#$L ##'"),"7":!*Q-' A!*Q-' !>!> ?9@  5Bv*- "1" CLL  +F IO    r#Nc \|j tdg|_||_g|_y)Nr)rrronCurver)s r$r-z ReverseContourPointPen.beginPaths1    */0 0 (2% r#c`|j td|jd|_yr`)rrrRr0s r$r1zReverseContourPointPen.endPaths.    &+, , "r#c |j td|||d<|jj|||||fy)Nrar+)rrrXr3s r$r8zReverseContourPointPen.addPointsK    &+, ,  !#-F<  ""B VT6#JKr#c r|j td|jj||fd|i|yr)rrrer<rws r$r<z#ReverseContourPointPen.addComponent$s:    *NO OiTzTVTr#rCrH) rrrrrNrRr-r1r8r<r"r#r$rrs/# 0d#IMLUr#rc>eZdZdZdZeZddd dfdZd dZxZS) DecomposingPointPena:Implements a 'addComponent' method that decomposes components (i.e. draws them onto self as simple contours). It can also be used as a mixin class (e.g. see DecomposingRecordingPointPen). You must override beginPath, addPoint, endPath. You may additionally override addVarComponent and addComponent. By default a warning message is logged when a base glyph is missing; set the class variable ``skipMissingComponents`` to False if you want all instances of a sub-class to raise a :class:`MissingComponentError` exception by default. TNF)skipMissingComponentsreverseFlippedct||i|||_||jjn||_|durt j |_y|durt j|_yt ||_y)a=Takes a 'glyphSet' argument (dict), in which the glyphs that are referenced as components are looked up by their name. If the optional 'reverseFlipped' argument is True or a ReverseFlipped enum value, components whose transformation matrix has a negative determinant will be decomposed with a reversed path direction to compensate for the flip. The reverseFlipped parameter can be: - False or ReverseFlipped.NO: Don't reverse flipped components - True or ReverseFlipped.KEEP_START: Reverse, keeping original starting point - ReverseFlipped.ON_CURVE_FIRST: Reverse, ensuring first point is on-curve The optional 'skipMissingComponents' argument can be set to True/False to override the homonymous class attribute for a given pen instance. NFT) superrNglyphSet __class__rrrrr )r*rrrargsr,rs r$rNzDecomposingPointPen.__init__<s{. $)&)  %, NN 0 0& " U ""0"3"3D  t #"0";";D "0"@D r#c ddlm} |j|}|}|tk7r |||}|jt j k7rN|dd\}} } } || z| | zz dkr6t|}|jt jk(rddl m } | |}|j|y#t$r8|js t||jj!d|zYywxYw)zTransform the points of the base glyph and draw it onto self. The `identifier` parameter and any extra kwargs are ignored. r)TransformPointPenN)OnCurveFirstPointPenz,glyph '%s' is missing from glyphSet; skipped)fontTools.pens.transformPenrrr rrrrr!fontTools.pens.filterPenr drawPointsKeyErrorrrlogwarning) r*r:r;r+r,rglyphreabcdrs r$r<z DecomposingPointPen.addComponentbs B "MM-0EC)'^<""n&7&77,BQ/ 1aq51q5=1$05C**n.K.KKQ337   S !1 --+M:: HH  >N  sB((>C)(C))rzbool | ReverseFlippedrC) rrrrrrrNr< __classcell__)rs@r$rr*s5 !1 #05 $A . $AL!"r#r)&r __future__rrtypingrrrrrfontTools.misc.enumToolsr fontTools.misc.loggingToolsr fontTools.misc.transformr r fontTools.pens.basePenr rr__all__floatPointrJ PointNamerISegmentPointList SegmentTyperbrrrrrrrrr"r#r$rs # 33,0BOO  eUl SM huotYCDEsm 5&6678  &W &//dbI,bIJR4-R4jK4 K4\WT*WTtZU-ZUzY"($4Y"r#