
    <`E'                        d dl m Z  d dlmZmZmZmZ d dlmZmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZmZ d dlmZmZ d d	lmZ d d
lmZ d dlmZ d dlmZ ddgZ G d d          Z G d dee          Z G d dee
e          ZdS )    )array)AnyDictOptionalTuple)MAX_F2DOT14floatToFixedToFloat)LogMixin)AbstractPointPenotRound)
LoggingPenPenError)TransformPenTransformPointPen)	ttProgram)Glyph)GlyphComponent)GlyphCoordinates
TTGlyphPenTTGlyphPointPenc                       e Zd Z	 ddeeeef                  deddfdZdede	e
e
e
e
e
e
f         fd	Zd
 ZddZ	 ddede	e
e
e
e
e
e
f         dee         deddf
dZd ZddedefdZdS )_TTGlyphBasePenTglyphSethandleOverflowingTransformsreturnNc                 J    || _         || _        |                                  dS )a  
        Construct a new pen.

        Args:
            glyphSet (Dict[str, Any]): A glyphset object, used to resolve components.
            handleOverflowingTransforms (bool): See below.

        If ``handleOverflowingTransforms`` is True, the components' transform values
        are checked that they don't overflow the limits of a F2Dot14 number:
        -2.0 <= v < +2.0. If any transform value exceeds these, the composite
        glyph is decomposed.

        An exception to this rule is done for values that are very close to +2.0
        (both for consistency with the -2.0 case, and for the relative frequency
        these occur in real fonts). When almost +2.0 values occur (and all other
        values are within the range -2.0 <= x <= +2.0), they are clamped to the
        maximum positive value that can still be encoded as an F2Dot14: i.e.
        1.99993896484375.

        If False, no check is done and all components are translated unmodified
        into the glyf table, followed by an inevitable ``struct.error`` once an
        attempt is made to compile them.

        If both contours and components are present in a glyph, the components
        are decomposed.
        N)r   r   init)selfr   r   s      9lib/python3.11/site-packages/fontTools/pens/ttGlyphPen.py__init__z_TTGlyphBasePen.__init__   s$    > !+F(		    	glyphNametransformationc                     |                      | |          } t          | j        |         | j                  |           d S N)transformPengetattrr   
drawMethod)r   r#   r$   tpens       r    
_decomposez_TTGlyphBasePen._decompose6   sB    
   ~66:i($/::4@@@@@r"   c                     t           )z6
        Check if the current path is closed.
        NotImplementedErrorr   s    r    	_isClosedz_TTGlyphBasePen._isClosed>   s
     "!r"   c                 >    g | _         g | _        g | _        g | _        d S r&   )pointsendPtstypes
componentsr/   s    r    r   z_TTGlyphBasePen.initD   s"    
r"   baseGlyphName
identifierkwargsc                 >    | j                             ||f           dS )z"
        Add a sub glyph.
        N)r5   append)r   r6   r$   r7   r8   s        r    addComponentz_TTGlyphBasePen.addComponentJ   s%     	~>?????r"   c                    | j         rt          d | j        D                       }g }| j        D ] \  }}|| j        vr| j                            d| d           .| j        s	| j         r|r|                     ||           Ut                      }||_	        d |dd          D             \  |_
        |_        t          d |d d         D                       }|dk    rR| j         r2t          d |D                       rt          d	 |D                       }|d d
         |d
d          f|_        ||_        |                    |           "|S )Nc              3   N   K   | ] \  }}|d d         D ]}|dk    p|dk     V  !d S )N       ).0r#   r$   ss       r    	<genexpr>z3_TTGlyphBasePen._buildComponents.<locals>.<genexpr>Z   sf        /Y'+   AR      r"   z skipped non-existing component ''c              3   4   K   | ]}t          |          V  d S r&   r   rB   vs     r    rD   z3_TTGlyphBasePen._buildComponents.<locals>.<genexpr>k   s(      'O'Oq

'O'O'O'O'O'Or"   r>   c              3   6   K   | ]}t          |d           V  dS )   N)r	   rG   s     r    rD   z3_TTGlyphBasePen._buildComponents.<locals>.<genexpr>n   s>       # #/0#Ar**# # # # # #r"   )   r   r   rK   c              3   @   K   | ]}t           |cxk     od k    nc V  dS r?   Nr   rB   rC   s     r    rD   z3_TTGlyphBasePen._buildComponents.<locals>.<genexpr>r   sO       < <-.K!((((q((((< < < < < <r"   c              3   R   K   | ]"}t           |cxk     rd k    r
n nt           n|V  #dS rM   rN   rO   s     r    rD   z3_TTGlyphBasePen._buildComponents.<locals>.<genexpr>v   s[       + + (3Q';';';';!';';';';';+ + + + + +r"   r?   )r   anyr5   r   logwarningr2   r+   r   r#   xytuple	transformflagsr:   )r   componentFlagsoverflowingr5   r#   r$   	components          r    _buildComponentsz _TTGlyphBasePen._buildComponentsV   s   + 	   37?    K
 
)- 	) 	)%I~--  !PI!P!P!PQQQ{ t? K 	>:::&((I"+I'O'ON122<N'O'O'O$IK # # #4B2A24F# # #  N --3  < <2@< < < 9 9  &+ + +!/+ + + & &N (6bqb'9>!"";M&N	#,IOi((((r"   r>   rY   c                 "   |                                  st          d          |                     |          }t                      }t	          | j                  |_        |j                                         | j        |_	        t          d| j                  |_        |                                  |r||_        d|_        nKt!          |j	                  |_        t#          j                    |_        |j                            d           |S )zW
        Returns a :py:class:`~._g_l_y_f.Glyph` object representing the glyph.
        zDidn't close last contour.Br"   )r0   r   r\   r   r   r2   coordinatestoIntr3   endPtsOfContoursr   r4   rX   r   r5   numberOfContourslenr   ProgramprogramfromBytecode)r   rY   r5   glyphs       r    rh   z_TTGlyphBasePen.glyph   s     ~~ 	97888**>::
,T[99!!!!%C,,		 	,  *E%'E""%()?%@%@E"%-//EMM&&s+++r"   )Tr   Nr&   )r>   )__name__
__module____qualname__r   r   strr   boolr!   r   floatr+   r0   r   r;   r\   intr   rh   rA   r"   r    r   r      sb        -1! !4S>*! &*! 
	! ! ! !FAA eUE5%FGA A A A" " "    %)	
@ 
@
@ eUE5%FG
@ SM	
@
 
@ 

@ 
@ 
@ 
@' ' 'R C %      r"   r   c                       e Zd ZdZdZeZdeeef         de	ddfdZ
ddZdefd	Zdeeef         ddfd
Zdeeef         ddfdZddZddZddZddZdS )r   a  
    Pen used for drawing to a TrueType glyph.

    This pen can be used to construct or modify glyphs in a TrueType format
    font. After using the pen to draw, use the ``.glyph()`` method to retrieve
    a :py:class:`~._g_l_y_f.Glyph` object representing the glyph.
    drawptonCurver   Nc                 n    | j                             |           | j                            |           d S r&   )r2   r:   r4   )r   rs   rt   s      r    	_addPointzTTGlyphPen._addPoint   s4    2
'"""""r"   c                 j    | j                                          | j                                         d S r&   )r2   popr4   r/   s    r    	_popPointzTTGlyphPen._popPoint   s,    
r"   c                 l    | j          p,| j        o%| j        d         t          | j                   dz
  k    S )Nr_   rK   )r2   r3   rd   r/   s    r    r0   zTTGlyphPen._isClosed   s7    K 
KCDKOs4;/?/?!/CC	
r"   c                 2    |                      |d           d S )NrK   )rv   r   rs   s     r    lineTozTTGlyphPen.lineTo   s    r1r"   c                 x    |                                  st          d          |                     |d           d S )Nz+"move"-type point must begin a new contour.rK   )r0   r   rv   r|   s     r    moveTozTTGlyphPen.moveTo   s>    ~~ 	JHIIIr1r"   c                     t           r&   r-   )r   r2   s     r    curveTozTTGlyphPen.curveTo   s    !!r"   c                     t          |          dk    sJ |d d         D ]}|                     |d           |d         |                     |d         d           d S d S )NrK   r_   r   )rd   rv   )r   r2   rs   s      r    qCurveTozTTGlyphPen.qCurveTo   sy    6{{a"+ 	" 	"BNN2q!!!! ":!NN6":q))))) "!r"   c                 r   t          | j                  dz
  }|dk    s| j        r*|| j        d         dz   k    r|                                  d S d}| j        r| j        d         dz   }| j        |         | j        |         k    r|                                  |dz  }| j                            |           d S )NrK   r   r_   )rd   r2   r3   ry   r:   )r   endPtstartPts      r    	closePathzTTGlyphPen.closePath   s    DK  1$ A::$+:%4;r?Q3F*F*FNNF ; 	*k"o)G;w4;u#555NNQJE5!!!!!r"   c                 .    |                                   d S r&   )r   r/   s    r    endPathzTTGlyphPen.endPath   s    r"   ri   )rj   rk   rl   __doc__r)   r   r'   r   ro   rp   rv   ry   rn   r0   r}   r   r   r   r   r   rA   r"   r    r   r      s1         JL#E%,/ ## #$ # # # #   
4 
 
 
 

ue|,     ue|,     
" " " "* * * *" " " "$     r"   c                        e Zd ZdZdZeZd fdZdefdZ	dde
e         deddfd	Zdd
Z	 	 	 	 ddeeef         de
e         dede
e         de
e         deddfdZ xZS )r   a  
    Point pen used for drawing to a TrueType glyph.

    This pen can be used to construct or modify glyphs in a TrueType format
    font. After using the pen to draw, use the ``.glyph()`` method to retrieve
    a :py:class:`~._g_l_y_f.Glyph` object representing the glyph.
    
drawPointsr   Nc                 V    t                                                       d | _        d S r&   )superr   _currentContourStartIndex)r   	__class__s    r    r   zTTGlyphPointPen.init   s"    )-&&&r"   c                     | j         d u S r&   )r   r/   s    r    r0   zTTGlyphPointPen._isClosed   s    -55r"   r7   r8   c                 ~    |                                  st          d          t          | j                  | _        dS )z'
        Start a new sub path.
        zDidn't close previous contour.N)r0   r   rd   r2   r   )r   r7   r8   s      r    	beginPathzTTGlyphPointPen.beginPath   s=     ~~ 	=;<<<),T[)9)9&&&r"   c                    |                                  rt          d          | j        t          | j                  k    rt          d          | j                            t          | j                  dz
             d| _        dS )z+
        End the current sub path.
        zContour is already closed.zTried to end an empty contour.rK   N)r0   r   r   rd   r2   r3   r:   r/   s    r    r   zTTGlyphPointPen.endPath   s    
 >> 	97888)S-=-===;<<<3t{++a/000)-&&&r"   Frs   segmentTypesmoothnamec                    |                                  rt          d          || j                            d           n&|dv r| j                            d           nt          | j                            |           dS )z6
        Add a point to the current sub path.
        z&Can't add a point to a closed contour.Nr   )qcurvelinerK   )r0   r   r4   r:   r.   r2   )r   rs   r   r   r   r7   r8   s          r    addPointzTTGlyphPointPen.addPoint  s     >> 	ECDDDJa    ...Ja     &%2r"   ri   r&   )NFNN)rj   rk   rl   r   r)   r   r'   r   rn   r0   r   rm   r   r   r   r   ro   r   __classcell__)r   s   @r    r   r      s4         J$L. . . . . .64 6 6 6 6: :HSM :C :D : : : :
. 
. 
. 
. &*"$( %, c] 	
 sm SM  
       r"   N)r   typingr   r   r   r   fontTools.misc.fixedToolsr   r	   fontTools.misc.loggingToolsr
   fontTools.pens.pointPenr   fontTools.misc.roundToolsr   fontTools.pens.basePenr   r   fontTools.pens.transformPenr   r   fontTools.ttLib.tablesr   fontTools.ttLib.tables._g_l_y_fr   r   r   __all__r   r   r   rA   r"   r    <module>r      s         - - - - - - - - - - - - F F F F F F F F 0 0 0 0 0 0 4 4 4 4 4 4 - - - - - - 7 7 7 7 7 7 7 7 G G G G G G G G , , , , , , 1 1 1 1 1 1 : : : : : : < < < < < < *
+F F F F F F F FRA A A A A* A A AH= = = = =ox1A = = = = =r"   