
    hB                        S r SSKJrJr  SSKJr  SSKJrJr  / SQr	 " S S\
5      r " S S	\5      r " S
 S5      r " S S\5      r " S S\\5      r " S S\5      r " S S\5      r " S S\5      rS rS r " S S\5      r\S:X  a|  \" S5      r\R3                  S5        \R5                  S5        \R7                  SSS S5        \R9                  5         \" S5      r\R;                  SSS!S"S5        \R9                  5         gg)#a  fontTools.pens.basePen.py -- Tools and base classes to build pen objects.

The Pen Protocol

A Pen is a kind of object that standardizes the way how to "draw" outlines:
it is a middle man between an outline and a drawing. In other words:
it is an abstraction for drawing outlines, making sure that outline objects
don't need to know the details about how and where they're being drawn, and
that drawings don't need to know the details of how outlines are stored.

The most basic pattern is this::

        outline.draw(pen)  # 'outline' draws itself onto 'pen'

Pens can be used to render outlines to the screen, but also to construct
new outlines. Eg. an outline object can be both a drawable object (it has a
draw() method) as well as a pen itself: you *build* an outline using pen
methods.

The AbstractPen class defines the Pen protocol. It implements almost
nothing (only no-op closePath() and endPath() methods), but is useful
for documentation purposes. Subclassing it basically tells the reader:
"this class implements the Pen protocol.". An examples of an AbstractPen
subclass is :py:class:`fontTools.pens.transformPen.TransformPen`.

The BasePen class is a base implementation useful for pens that actually
draw (for example a pen renders outlines using a native graphics engine).
BasePen contains a lot of base functionality, making it very easy to build
a pen that fully conforms to the pen protocol. Note that if you subclass
BasePen, you *don't* override moveTo(), lineTo(), etc., but _moveTo(),
_lineTo(), etc. See the BasePen doc string for details. Examples of
BasePen subclasses are fontTools.pens.boundsPen.BoundsPen and
fontTools.pens.cocoaPen.CocoaPen.

Coordinates are usually expressed as (x, y) tuples, but generally any
sequence of length 2 will do.
    )TupleDict)LogMixin)DecomposedTransformIdentity)AbstractPenNullPenBasePenPenErrordecomposeSuperBezierSegmentdecomposeQuadraticSegmentc                       \ rS rSrSrSrg)r   6   z#Represents an error during penning. N__name__
__module____qualname____firstlineno____doc____static_attributes__r       H/var/www/html/env/lib/python3.13/site-packages/fontTools/pens/basePen.pyr   r   6   s    -r   r   c                       \ rS rSrSrg)OpenContourError:   r   N)r   r   r   r   r   r   r   r   r   r   :   s    r   r   c            
           \ rS rSrS\\\4   SS4S jrS\\\4   SS4S jrS\\\4   SS4S jrS\\\4   SS4S	 jr	SS
 jr
SS jrS\S\\\\\\\4   SS4S jrS\S\S\\\4   SS4S jrSrg)r   >   ptreturnNc                     [         e)zBegin a new sub path, set the current point to 'pt'. You must
end each sub path with a call to pen.closePath() or pen.endPath().
NotImplementedErrorselfr   s     r   moveToAbstractPen.moveTo?   s
     "!r   c                     [         e)z4Draw a straight line from the current point to 'pt'.r"   r$   s     r   lineToAbstractPen.lineToE   s    !!r   pointsc                     [         e)a'  Draw a cubic bezier with an arbitrary number of control points.

The last point specified is on-curve, all others are off-curve
(control) points. If the number of control points is > 2, the
segment is split into multiple bezier segments. This works
like this:

Let n be the number of control points (which is the number of
arguments to this call minus 1). If n==2, a plain vanilla cubic
bezier is drawn. If n==1, we fall back to a quadratic segment and
if n==0 we draw a straight line. It gets interesting when n>2:
n-1 PostScript-style cubic segments will be drawn as if it were
one curve. See decomposeSuperBezierSegment().

The conversion algorithm used for n>2 is inspired by NURB
splines, and is conceptually equivalent to the TrueType "implied
points" principle. See also decomposeQuadraticSegment().
r"   r%   r+   s     r   curveToAbstractPen.curveToI   s
    & "!r   c                     [         e)a  Draw a whole string of quadratic curve segments.

The last point specified is on-curve, all others are off-curve
points.

This method implements TrueType-style curves, breaking up curves
using 'implied points': between each two consequtive off-curve points,
there is one implied point exactly in the middle between them. See
also decomposeQuadraticSegment().

The last argument (normally the on-curve point) may be None.
This is to support contours that have NO on-curve points (a rarely
seen feature of TrueType outlines).
r"   r-   s     r   qCurveToAbstractPen.qCurveTo^   s
     "!r   c                     g)zgClose the current sub path. You must call either pen.closePath()
or pen.endPath() after each sub path.
Nr   r%   s    r   	closePathAbstractPen.closePatho        	r   c                     g)zyEnd the current sub path, but don't close it. You must call
either pen.closePath() or pen.endPath() after each sub path.
Nr   r4   s    r   endPathAbstractPen.endPathu   r7   r   	glyphNametransformationc                     [         e)zAdd a sub glyph. The 'transformation' argument must be a 6-tuple
containing an affine transformation, or a Transform object from the
fontTools.misc.transform module. More precisely: it should be a
sequence containing 6 numbers.
r"   r%   r;   r<   s      r   addComponentAbstractPen.addComponent{   s
     "!r   locationc                     [         e)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.
AttributeErrorr%   r;   r<   rA   s       r   addVarComponentAbstractPen.addVarComponent   s
     r   r   )r    N)r   r   r   r   r   floatr&   r)   r.   r1   r5   r9   strr?   r   r   rF   r   r   r   r   r   r   >   s    "ue|, " ""ue|, " ""uUE\2 "t "*"eUl 3 " ""
"
" eUE5%FG
" 
	
" , sEz"	
 
r   r   c                   H    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rSrg)r	      zA pen that does nothing.c                     g Nr   r$   s     r   r&   NullPen.moveTo       r   c                     g rM   r   r$   s     r   r)   NullPen.lineTo   rO   r   c                     g rM   r   r-   s     r   r.   NullPen.curveTo   rO   r   c                     g rM   r   r-   s     r   r1   NullPen.qCurveTo   rO   r   c                     g rM   r   r4   s    r   r5   NullPen.closePath   rO   r   c                     g rM   r   r4   s    r   r9   NullPen.endPath   rO   r   c                     g rM   r   r>   s      r   r?   NullPen.addComponent   rO   r   c                     g rM   r   rE   s       r   rF   NullPen.addVarComponent   rO   r   r   N)r   r   r   r   r   r&   r)   r.   r1   r5   r9   r?   rF   r   r   r   r   r	   r	      s-    "r   r	   c                       \ rS rSrSrSrg)
LoggingPen   zHA pen with a ``log`` property (see fontTools.misc.loggingTools.LogMixin)r   Nr   r   r   r   r_   r_      s    Rr   r_   c                       \ rS rSrSrSrg)MissingComponentError   zGIndicates a component pointing to a non-existent glyph in the glyphset.r   Nr   r   r   r   rb   rb      s    Qr   rb   c                   J   ^  \ rS rSrSrSr\rSSS.U 4S jjrS rS	 r	S
r
U =r$ )DecomposingPen   a  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 ContourRecordingPen).

You must override moveTo, lineTo, curveTo and qCurveTo. You may
additionally override closePath, endPath 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)skipMissingComponentsreverseFlippedc                   > [         [        U ]
  " U0 UD6  Xl        Uc  U R                  R
                  OUU l        X0l        g)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, components whose transformation
matrix has a negative determinant will be decomposed with a reversed path direction
to compensate for the flip.

The optional 'skipMissingComponents' argument can be set to True/False to
override the homonymous class attribute for a given pen instance.
N)superre   __init__glyphSet	__class__rg   rh   )r%   rl   rg   rh   argskwargsrm   s         r   rk   DecomposingPen.__init__   sH    $ 	nd,d=f=  %, NN00& 	"
 -r   c                 z   SSK Jn   U R                  U   nU nU[        :w  a  U" XR5      nU R                  (       a%  USS u  pgpXi-  Xx-  -
  n
U
S:  a  SSKJn  U" U5      nUR                  U5        g! [         a=    U R                  (       d  [        U5      eU R                  R                  SU-  5         gf = f)z=Transform the points of the base glyph and draw it onto self.r   )TransformPenN   )ReverseContourPenz,glyph '%s' is missing from glyphSet; skipped)fontTools.pens.transformPenrr   rl   r   rh    fontTools.pens.reverseContourPenrt   drawKeyErrorrg   rb   logwarning)r%   r;   r<   rr   glyphpenabcddetrt   s               r   r?   DecomposingPen.addComponent   s    <	MM),E C)"37"" ,BQ/
aeaem7R+C0CJJsO#  	Y--+I66HHKiWX	Ys   A3 3AB:9B:c                     [         erM   rC   rE   s       r   rF   DecomposingPen.addVarComponent  s    r   )rl   rh   rg   )r   r   r   r   r   rg   rb   rk   r?   rF   r   __classcell__rm   s   @r   re   re      s7     !1 #- -62 r   re   c                   ~   ^  \ rS rSrSrSU 4S jjrS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rSrU =r$ )r
   i  zBase class for drawing pens. You must override _moveTo, _lineTo and
_curveToOne. You may additionally override _closePath, _endPath,
addComponent, addVarComponent, and/or _qCurveToOne. You should not
override any other methods.
c                 :   > [         [        U ]  U5        S U l        g rM   )rj   r
   rk   _BasePen__currentPoint)r%   rl   rm   s     r   rk   BasePen.__init__  s    gt%h/"r   c                     [         erM   r"   r$   s     r   _moveToBasePen._moveTo      !!r   c                     [         erM   r"   r$   s     r   _lineToBasePen._lineTo  r   r   c                     [         erM   r"   )r%   pt1pt2pt3s       r   _curveToOneBasePen._curveToOne  r   r   c                     g rM   r   r4   s    r   
_closePathBasePen._closePath  rO   r   c                     g rM   r   r4   s    r   _endPathBasePen._endPath"  rO   r   c                     U R                   u  p4Uu  pVUu  pxUSXS-
  -  -   n	USXd-
  -  -   n
USXW-
  -  -   nUSXh-
  -  -   nU R                  X4X4U5        g)zThis method implements the basic quadratic curve type. The
default implementation delegates the work to the cubic curve
function. Optionally override with a native implementation.
gUUUUUU?N)r   r   )r%   r   r   pt0xpt0ypt1xpt1ypt2xpt2ymid1xmid1ymid2xmid2ys                r   _qCurveToOneBasePen._qCurveToOne%  s}    
 ((


*dk::*dk::*dk::*dk::%%=r   c                     U R                   $ )zbReturn the current point. This is not part of the public
interface, yet is useful for subclasses.
)r   r4   s    r   _getCurrentPointBasePen._getCurrentPoint5  s     """r   c                 2    U R                  5         S U l        g rM   )r   r   r4   s    r   r5   BasePen.closePath;  s    "r   c                 2    U R                  5         S U l        g rM   )r   r   r4   s    r   r9   BasePen.endPath?  s    "r   c                 2    U R                  U5        Xl        g rM   )r   r   r$   s     r   r&   BasePen.moveToC      R r   c                 2    U R                  U5        Xl        g rM   )r   r   r$   s     r   r)   BasePen.lineToG  r   r   c                 T   [        U5      S-
  nUS:  d   eUS:X  a  U R                  " U6   US   U l        g US:  a1  U R                  n[        U5       H  u  pEnU" XEU5        X`l        M     g US:X  a  U R                  " U6   g US:X  a  U R                  US   5        g [        S5      e)N   r      zcan't get there from here)lenr   r   r   r1   r)   AssertionError)r%   r+   nr   r   r   r   s          r   r.   BasePen.curveToK  s    K!OAvv6
 f%"(*DU **K!<V!D#Cc*&)# "E !VMM6"!VKKq	" !<==r   c                 F   [        U5      S-
  nUS:  d   eUS   c<  US   u  p4US   u  pVSX5-   -  SXF-   -  4nXpl        U R                  U5        US S U4-   nUS:  a/  U R                  n[	        U5       H  u  pU" X5        Xl        M     g U R                  US   5        g )Nr   r   r         ?)r   r   r   r   r   r)   )r%   r+   r   xynxnyimpliedStartPointr   r   r   s              r   r1   BasePen.qCurveToh  s    K!OAvv": ":DAAYFB!$ @"3LL*+CR[$5#77Fq5
  ,,L5f=S&&)# > KKq	"r   )__currentPointrM   )r   r   r   r   r   rk   r   r   r   r   r   r   r   r5   r9   r&   r)   r.   r1   r   r   r   s   @r   r
   r
     sS    #"""
> ###!!>:# #r   r
   c                    [        U 5      S-
  nUS:  d   e/ nU S   SSpTn[        SUS-   5       H  n[        USX-
  S-   5      n[        SU5       Hv  nX-  n	XS-
     n
XS-
     nUS   XS   US   -
  -  -   US   XS   US   -
  -  -   4nUc  UnMB  SUS   US   -   -  SUS   US   -   -  4nUR                  X4U45        USSpTnMx     M     UR                  X0S   U S   45        U$ )	a  Split the SuperBezier described by 'points' into a list of regular
bezier segments. The 'points' argument must be a sequence with length
3 or greater, containing (x, y) coordinates. The last point is the
destination on-curve point, the rest of the points are off-curve points.
The start point should not be supplied.

This function returns a list of (pt1, pt2, pt3) tuples, which each
specify a regular curveto-style bezier segment.
r   r   Nr      r   r   r   )r   rangeminappend)r+   r   bezierSegmentsr   r   r   i
nDivisionsjfactortemp1temp2temps                r   r   r     sA    	FaAq5L5N1ItTcC1a!e_Aquqy)
q*%A^Fq5MEq5MEa61Xa%899a61Xa%899D {c!ftAw./Aa8H1IJ%%so6 $dD## & " 3r
F2J78r   c                     [        U 5      S-
  nUS:  d   e/ n[        US-
  5       H5  nX   u  pEXS-      u  pgSXF-   -  SXW-   -  4nUR                  X   U45        M7     UR                  U S   U S   45        U$ )a  Split the quadratic curve segment described by 'points' into a list
of "atomic" quadratic segments. The 'points' argument must be a sequence
with length 2 or greater, containing (x, y) coordinates. The last point
is the destination on-curve point, the rest of the points are off-curve
points. The start point should not be supplied.

This function returns a list of (pt1, pt2) tuples, which each specify a
plain quadratic bezier segment.
r   r   r   r   r   )r   r   r   )	r+   r   quadSegmentsr   r   r   r   r   	impliedPts	            r   r   r     s     	FaAq5L5L1q5\yAAF^SAF^4	VY	23	 
 VBZ01r   c                   0    \ rS rSrSrS rS rS rS rSr	g)	_TestPeni  z,Test class that prints PostScript to stdout.c                 6    [        US   < SUS   < S35        g )Nr    r   z movetoprintr$   s     r   r   _TestPen._moveTo      1r!u-.r   c                 6    [        US   < SUS   < S35        g )Nr   r   r   z linetor   r$   s     r   r   _TestPen._lineTo  r   r   c                 n    [        US   < SUS   < SUS   < SUS   < SUS   < SUS   < S35        g )Nr   r   r   z curvetor   )r%   bcp1bcp2r   s       r   r   _TestPen._curveToOne  s5    AwQa$q'2a5"Q%A	
r   c                     [        S5        g )N	closepathr   r4   s    r   r   _TestPen._closePath  s
    kr   r   N)
r   r   r   r   r   r   r   r   r   r   r   r   r   r   r     s    6//
r   r   __main__N)r   r   )r   d   )2   K   )<   r   )r      )r   r   )r   r   )r   typingr   r   fontTools.misc.loggingToolsr   fontTools.misc.transformr   r   __all__	Exceptionr   r   r   r	   r_   rx   rb   re   r
   r   r   r   r   r|   r&   r)   r.   r5   r1   r   r   r   <module>r      s  $L  0 B.y .	x 	U Upk 8	; 	RH RHZ HV{#n {#| F,w & z
4.CJJvJJxKK(Hf5MMO
4.CLL:x>MMO r   