
    ]Mh^.                     6   d dl m Z  d dlmZ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mZ d dlmZ d dlmZ d dlmZ d dlmZ d dl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CallableDictOptionalTuple)MAX_F2DOT14floatToFixedToFloat)LogMixin)AbstractPointPenotRound)
LoggingPenPenError)TransformPenTransformPointPen)	ttProgram)flagOnCurve	flagCubic)Glyph)GlyphComponent)GlyphCoordinates)dropImpliedOnCurvePointsN
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eddededee
gef         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      Y/var/www/html/test/jupyter/venv/lib/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._decompose9   sB    
   ~66:i($/::4@@@@@r&   c                     t           )z6
        Check if the current path is closed.
        )NotImplementedErrorr#   s    r$   	_isClosedz_TTGlyphBasePen._isClosedA   s
     "!r&   c                 >    g | _         g | _        g | _        g | _        d S r*   )pointsendPtstypes
componentsr2   s    r$   r"   z_TTGlyphBasePen.initG   s"    
r&   baseGlyphName
identifierkwargsc                 >    | j                             ||f           dS )z"
        Add a sub glyph.
        N)r8   append)r#   r9   r(   r:   r;   s        r$   addComponentz_TTGlyphBasePen.addComponentM   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>]   sf        /Y'+   AR      r&   z skipped non-existing component ''c              3   4   K   | ]}t          |          V  d S r*   r   rE   vs     r$   rG   z3_TTGlyphBasePen._buildComponents.<locals>.<genexpr>n   s(      'O'Oq

'O'O'O'O'O'Or&   rA   c              3   6   K   | ]}t          |d           V  dS )   N)r
   rJ   s     r$   rG   z3_TTGlyphBasePen._buildComponents.<locals>.<genexpr>q   s>       # #/0#Ar**# # # # # #r&   )   r   r   rN   c              3   @   K   | ]}t           |cxk     od k    nc V  dS rB   Nr	   rE   rF   s     r$   rG   z3_TTGlyphBasePen._buildComponents.<locals>.<genexpr>u   sO       < <-.K!((((q((((< < < < < <r&   c              3   R   K   | ]"}t           |cxk     rd k    r
n nt           n|V  #dS rP   rQ   rR   s     r$   rG   z3_TTGlyphBasePen._buildComponents.<locals>.<genexpr>y   s[       + + (3Q';';';';!';';';';';+ + + + + +r&   rB   )r   anyr8   r   logwarningr5   r/   r   r'   xytuple	transformflagsr=   )r#   componentFlagsoverflowingr8   r'   r(   	components          r$   _buildComponentsz _TTGlyphBasePen._buildComponentsY   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&   rA   Froundr\   dropImpliedOnCurvesra   c                H   |                                  st          d          |                     |          }t                      }t	          | j                  |_        | j        |_        t          d| j
                  |_        |                                  |r||_        d|_        nwt          |j                  |_        t!          j                    |_        |j                            d           |rt)          |           |j                            |           |S )a  
        Returns a :py:class:`~._g_l_y_f.Glyph` object representing the glyph.

        Args:
            componentFlags: Flags to use for component glyphs. (default: 0x04)

            dropImpliedOnCurves: Whether to remove implied-oncurve points. (default: False)
        zDidn't close last contour.Br&   r`   )r3   r   r_   r   r   r5   coordinatesr6   endPtsOfContoursr   r7   r[   r"   r8   numberOfContourslenr   ProgramprogramfromBytecoder   toInt)r#   r\   rb   ra   r8   glyphs         r$   rn   z_TTGlyphBasePen.glyph   s    ~~ 	97888**>::
,T[99!%C,,		 	1  *E%'E""%()?%@%@E"%-//EMM&&s+++" 0(///##%#000r&   )Tr    Nr*   )rA   F)__name__
__module____qualname__r   r   strr   boolr%   r   floatr/   r3   r"   r>   r_   r   intr   r   rn   rD   r&   r$   r   r      s        -1! !4S>*! &*! 
	! ! ! !FAA eUE5%FGA A A A" " "    %)	
@ 
@
@ eUE5%FG
@ SM	
@
 
@ 

@ 
@ 
@ 
@' ' 'V #$)&
 )0& & && "&
 %& 
& & & & & &r&   r   c            	            e Zd ZdZdZeZ	 	 	 ddeee	e
f                  deded	df fd
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 xZ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.
    drawNTFr   r   outputImpliedClosingLiner    c                 Z    t                                          ||           || _        d S r*   )superr%   ry   )r#   r   r   ry   	__class__s       r$   r%   zTTGlyphPen.__init__   s.     	#>???(@%%%r&   pttpc                 n    | j                             |           | j                            |           d S r*   )r5   r=   r7   )r#   r}   r~   s      r$   	_addPointzTTGlyphPen._addPoint   s4    2
"r&   c                 j    | j                                          | j                                         d S r*   )r5   popr7   r2   s    r$   	_popPointzTTGlyphPen._popPoint   s,    
r&   c                 l    | j          p,| j        o%| j        d         t          | j                   dz
  k    S )Nre   rN   )r5   r6   ri   r2   s    r$   r3   zTTGlyphPen._isClosed   s7    K 
KCDKOs4;/?/?!/CC	
r&   c                 <    |                      |t                     d S r*   )r   r   r#   r}   s     r$   lineTozTTGlyphPen.lineTo   s    r;'''''r&   c                     |                                  st          d          |                     |t                     d S )Nz+"move"-type point must begin a new contour.)r3   r   r   r   r   s     r$   moveTozTTGlyphPen.moveTo   s>    ~~ 	JHIIIr;'''''r&   c                     t          |          dz  dk    sJ |d d         D ]}|                     |t                     |d         |                     |d         d           d S d S )NrB   rN   re   )ri   r   r   r#   r5   r}   s      r$   curveTozTTGlyphPen.curveTo   s}    6{{Q!####"+ 	* 	*BNN2y)))) ":!NN6":q))))) "!r&   c                     t          |          dk    sJ |d d         D ]}|                     |d           |d         |                     |d         d           d S d S )NrN   re   r   )ri   r   r   s      r$   qCurveTozTTGlyphPen.qCurveTo   sy    6{{a"+ 	" 	"BNN2q!!!! ":!NN6":q))))) "!r&   c                    t          | j                  dz
  }|dk    s| j        r*|| j        d         dz   k    r|                                  d S | j        sNd}| j        r| j        d         dz   }| j        |         | j        |         k    r|                                  |dz  }| j                            |           d S )NrN   r   re   )ri   r5   r6   r   ry   r=   )r#   endPtstartPts      r$   	closePathzTTGlyphPen.closePath   s    DK  1$ A::$+:%4;r?Q3F*F*FNNF, 	G{ .+b/A-{7#t{5'999   
5!!!!!r&   c                 .    |                                   d S r*   )r   r2   s    r$   endPathzTTGlyphPen.endPath   s    r&   )NTFro   )rp   rq   rr   __doc__r-   r   r+   r   r   rs   r   rt   r%   r   ru   rv   r   r   r3   r   r   r   r   r   r   __classcell__r|   s   @r$   r   r      s         JL .2,0).	A A4S>*A &*A #'	A
 
A A A A A AE%,/ S T       
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*   )r{   r"   _currentContourStartIndex)r#   r|   s    r$   r"   zTTGlyphPointPen.init  s"    )-&&&r&   c                     | j         d u S r*   )r   r2   s    r$   r3   zTTGlyphPointPen._isClosed  s    -55r&   r:   r;   c                 ~    |                                  st          d          t          | j                  | _        dS )z'
        Start a new sub path.
        zDidn't close previous contour.N)r3   r   ri   r5   r   )r#   r:   r;   s      r$   	beginPathzTTGlyphPointPen.beginPath  s=     ~~ 	=;<<<),T[)9)9&&&r&   c                 8   |                                  rt          d          | j        t          | j                  k    r	d| _        dS | j        r| j        d         dz   nd}| j                            t          | j                  dz
             d| _        | j        }t          |t          |                    D ]\}||         dk    rN|dz
  }||k     rt          |          dz
  }||         dk    rt          ||<   |dz  }||         dk    t          ||<   ]dS )z+
        End the current sub path.
        zContour is already closed.Nre   rN   r   curve)r3   r   r   ri   r5   r6   r=   r7   ranger   r   )r#   contourStartr[   ijs        r$   r   zTTGlyphPointPen.endPath  s1   
 >> 	97888)S-=-===-1D*F.2k@t{2**q3t{++a/000)-& 
|SZZ00 	' 	'AQx7""E|##E

QAAh!mm(E!HFA Ah!mm 'a	' 	'r&   Fr}   segmentTypesmoothnamec                    |                                  rt          d          || j                            d           nz|dv r | j                            t                     nV|dk    r | j                            t                     n0|dk    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   )linemoveqcurver   )r3   r   r7   r=   r   AssertionErrorr5   )r#   r}   r   r   r   r:   r;   s          r$   addPointzTTGlyphPointPen.addPoint6  s     >> 	ECDDDJa    ,,,Jk****H$$Jk****G##Jg&&&& ---2r&   ro   r*   )NFNN)rp   rq   rr   r   r-   r   r+   r"   rt   r3   r   rs   r   r   r   r   ru   r   r   r   s   @r$   r   r      s4         J$L. . . . . .64 6 6 6 6: :HSM :C :D : : : :' ' ' '> &*"$( %, c] 	
 sm SM  
       r&   )$r   typingr   r   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   r   r   r   math__all__r   r   r   rD   r&   r$   <module>r      s         7 7 7 7 7 7 7 7 7 7 7 7 7 7 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 , , , , , , B B B B B B B B 1 1 1 1 1 1 : : : : : : < < < < < < D D D D D D  *
+S S S S S S S SlQ Q Q Q Q* Q Q QhP P P P Pox1A P P P P Pr&   