
    ]MhDD                        d Z ddlmZmZ ddl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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mZmZ  G d de          Z G d de          Z G d de          Z  G d de          Z! G d de          Z" G d de"          Z# G d de"          Z$d Z% G d de"          Z&ddd Z' G d! d"e          Z( G d# d$          Z)d%S )&zGlyphSets returned by a TTFont.    )ABCabstractmethod)Mapping)contextmanager)copydeepcopy)SimpleNamespace)Vector)otRoundfixedToFloat)deprecateFunction)	TransformDecomposedTransform)TransformPenTransformPointPen)DecomposingRecordingPenlerpRecordingsreplayRecordingc                       e Zd ZdZdddZedefd            Zed             Zd Z	d	 Z
d
 Z ede          d             ZdS )_TTGlyphSetzlGeneric dict-like GlyphSet class that pulls metrics from hmtx and
    glyph shape from TrueType or CFF.
    TrecalcBoundsc                6   || _         || _        d| j        v rd | j        d         j        D             ni | _        ||ni | _        i | _        ||ni | _        d| _        g | _        g | _	        || _
        |d         j        | _        t          |                    d          dd           | _        d | _        |r_ddlm} t          |                    d          d	d           | _        | j        + || j        j        |d         j        |          | _        d S d S d S )
Nfvarc                     i | ]
}|j         d S )r   axisTag).0axiss     Z/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/fontTools/ttLib/ttGlyphSet.py
<dictcomp>z(_TTGlyphSet.__init__.<locals>.<dictcomp>   s    @@@T\1@@@    r   hmtxvmtxmetricsVarStoreInstancerHVARtable)r   fontaxesdefaultLocationNormalizedlocationrawLocationoriginalLocationdepthlocationStackrawLocationStackglyphsMappingr%   hMetricsgetattrgetvMetrics	hvarTablefontTools.varLib.varStorer'   VarStorehvarInstancer)selfr*   r-   r3   r   r'   s         r    __init__z_TTGlyphSet.__init__   sK   (	 "" A@6):)?@@@@ 	&
 %-$8b,4,@b
 "*V, 0 0)TBB 	CCCCCC$TXXf%5%5wEEDN~)%6%6N+T&\->& &"""	 	 *)r"   resetc              #     K   | j                             | j                   | j                            | j                   |r=| j                                        | _        | j                                        | _        n%| j                                        | _        i | _        | j                            |           | j                            |           	 d V  | j         	                                | _        | j        	                                | _        d S # | j         	                                | _        | j        	                                | _        w xY wN)
r1   appendr-   r2   r.   r/   r   r,   updatepop)r<   r-   r>   s      r    pushLocationz_TTGlyphSet.pushLocation5   s8     !!$-000$$T%5666 	" 16688DM#=BBDDD M..00DM!DX&&&)))	;JJJ .2244DM#488::D !.2244DM#488::D::::s   D >Ec              #      K   	 | j         }| xj         dz  c_         |V  | xj         dz  c_         d S # | xj         dz  c_         w xY w)N   )r0   )r<   r0   s     r    	pushDepthz_TTGlyphSet.pushDepthH   sT      	JEJJ!OJJKKKJJ!OJJJJDJJ!OJJJJJJs	   1 Ac                     || j         v S r@   r3   r<   	glyphNames     r    __contains__z_TTGlyphSet.__contains__Q   s    D...r"   c                 N    t          | j                                                  S r@   )iterr3   keysr<   s    r    __iter__z_TTGlyphSet.__iter__T   s    D&++--...r"   c                 *    t          | j                  S r@   )lenr3   rP   s    r    __len__z_TTGlyphSet.__len__W   s    4%&&&r"   z#use 'glyphName in glyphSet' instead)categoryc                     || j         v S r@   rI   rJ   s     r    has_keyz_TTGlyphSet.has_keyZ   s     D...r"   N)__name__
__module____qualname____doc__r=   r   boolrD   rG   rL   rQ   rT   r   DeprecationWarningrW    r"   r    r   r      s          GK     8 ;D ; ; ; ^;$   ^/ / // / /' ' ' -8J  / / / / /r"   r   c                   &     e Zd Zd fd	Zd Z xZS )_TTGlyphSetGlyfTc                     |d         | _         t                                          ||| j         |           |                    d          | _        d S )Nglyfr   gvar)	glyfTablesuperr=   r6   	gvarTable)r<   r*   r-   r   	__class__s       r    r=   z_TTGlyphSetGlyf.__init__b   sH    fxlSSS&))r"   c                 0    t          | || j                  S )Nr   )_TTGlyphGlyfr   rJ   s     r    __getitem__z_TTGlyphSetGlyf.__getitem__g   s    D)$:KLLLLr"   )TrX   rY   rZ   r=   rj   __classcell__rg   s   @r    r`   r`   a   sS        * * * * * *
M M M M M M Mr"   r`   c                   F     e Zd Z fdZd Zd Zedefd            Z xZ	S )_TTGlyphSetCFFc                 
   d|v rdnd}t          ||         j                                                  d         j        | _        t                                          ||| j                   |                     |           d S )NCFF2zCFF r   )listcffvaluesCharStringscharStringsre   r=   setLocation)r<   r*   r-   tableTagrg   s       r    r=   z_TTGlyphSetCFF.__init__l   sx    #t^^66X 2 9 9 ; ;<<Q?Kx)9:::"""""r"   c                 "    t          | |          S r@   )_TTGlyphCFFrJ   s     r    rj   z_TTGlyphSetCFF.__getitem__r   s    4+++r"   c                     d | _         |rPddlm} t          | j        dd           }|0 ||j        | j        d         j        |          }|j        | _         d S d S d | _         d S )Nr   r&   varStorer   )	blenderr9   r'   r5   rv   
otVarStorer*   r+   interpolateFromDeltas)r<   r-   r'   r|   	instancers        r    rw   z_TTGlyphSetCFF.setLocationu   s     	  DCCCCCt/TBBH#--'6):)? 	  )>	 $#  DLLLr"   r>   c              #     K   |                      |           t                              | ||          5 }	 |V  |                      | j                   n# |                      | j                   w xY w	 d d d            d S # 1 swxY w Y   d S r@   )rw   r   rD   r-   )r<   r-   r>   values       r    rD   z_TTGlyphSetCFF.pushLocation   s      """%%dHe<< 	00  ////  /////		0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0s'   BABA11BB	B)
rX   rY   rZ   r=   rj   rw   r   r\   rD   rl   rm   s   @r    ro   ro   k   s}        # # # # #, , ,       0D 0 0 0 ^0 0 0 0 0r"   ro   c                   $     e Zd Z fdZd Z xZS )_TTGlyphSetVARCc                     || _         t                                          |||           |d         j        | _        d S )NVARC)glyphSetre   r=   r)   	varcTable)r<   r*   r-   r   rg   s       r    r=   z_TTGlyphSetVARC.__init__   s8     x222f+r"   c                 f    | j         }||j        j        vr| j        |         S t	          | |          S r@   )r   Coverageglyphsr   _TTGlyphVARC)r<   rK   varcs      r    rj   z_TTGlyphSetVARC.__getitem__   s6    ~DM000=++D),,,r"   rk   rm   s   @r    r   r      sG        , , , , ,
- - - - - - -r"   r   c                   :    e Zd ZdZdddZed             Zd ZdS )_TTGlyphaS  Glyph object that supports the Pen protocol, meaning that it has
    .draw() and .drawPoints() methods that take a pen object as their only
    argument. Additionally there are 'width' and 'lsb' attributes, read from
    the 'hmtx' table.

    If the font contains a 'vmtx' table, there will also be 'height' and 'tsb'
    attributes.
    Tr   c                   || _         || _        || _        |j        |         \  | _        | _        |j        |j        |         \  | _        | _        nd\  | _        | _        |j	        ra|j
        \|j
        j        |j                            |          n|j
        j        j        |         }| xj        |j        |         z  c_        d S d S d S )NNN)r   namer   r4   widthlsbr7   heighttsbr-   r8   AdvWidthMapr*   
getGlyphIDmappingr;   )r<   r   rK   r   varidxs        r    r=   z_TTGlyph.__init__   s     	('0;
DH($,$5i$@!DK$.!DK 	9!3!? %19 ((333'3;IF 
 JJ(088JJJJ	9 	9!?!?r"   c                     t           )dDraw the glyph onto ``pen``. See fontTools.pens.basePen for details
        how that works.
        )NotImplementedErrorr<   pens     r    drawz_TTGlyph.draw   s
    
 "!r"   c                 N    ddl m} |                      ||                     dS )eDraw the glyph onto ``pen``. See fontTools.pens.pointPen for details
        how that works.
        r   )SegmentToPointPenN)fontTools.pens.pointPenr   r   )r<   r   r   s      r    
drawPointsz_TTGlyph.drawPoints   s:     	>=====		##C(()))))r"   N)rX   rY   rZ   r[   r=   r   r   r   r^   r"   r    r   r      sg          =A 9 9 9 9 9$ " " ^"* * * * *r"   r   c                   &    e Zd Zd Zd Zd Zd ZdS )ri   c                     |                                  \  }}| j                                        5 }|rd}|                    || j        j        |           ddd           dS # 1 swxY w Y   dS )r   r   N)_getGlyphAndOffsetr   rG   r   rd   r<   r   glyphoffsetr0   s        r    r   z_TTGlyphGlyf.draw   s     //11v]$$&& 	=% JJsDM3V<<<		= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	=   &A$$A(+A(c                     |                                  \  }}| j                                        5 }|rd}|                    || j        j        |           ddd           dS # 1 swxY w Y   dS )r   r   N)r   r   rG   r   rd   r   s        r    r   z_TTGlyphGlyf.drawPoints   s     //11v]$$&& 	C% S$-"96BBB		C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	Cr   c                     | j         j        r!| j         j        |                                 }n| j         j        | j                 }t          |d          r| j        |j        z
  nd}||fS )NxMinr   )	r   r-   rf   _getGlyphInstancerd   r   hasattrr   r   )r<   r   r   s      r    r   z_TTGlyphGlyf._getGlyphAndOffset   si    =! 	7dm&=&I**,,EEM+DI6E*1%*@*@GEJ&&af}r"   c           	         ddl m} ddlm} ddlm} | j        }|j        }|j        j	        | j
                 }|j        }|j        }|                    | j
        ||          \  }	}
d\  }}|D ]} ||j        |j                  }|s|j        }d |v rq|b|                    | j
        ||          \  }}|d         dk    r|d         n.t#          t%          t'          |d                                       } ||||          }|	 ||          |z  z  }	t)          || j
                           }t+          ||	|| j                  \  }}}}|| _        || _        |j        || _        || _        |S )Nr   )	iup_delta)GlyphCoordinates)supportScalarr   rF   r   )fontTools.varLib.iupr   fontTools.ttLib.tables._g_l_y_fr   fontTools.varLib.modelsr   r   rd   rf   
variationsr   r4   r7   _getCoordinatesAndControlsr-   r+   coordinatesrr   rangerS   r   _setCoordinatesr   r   r   r8   r   r   )r<   r   r   r   r   rd   r   r4   r7   r   _
origCoordsendPtsvarscalardeltacontrolr   r   r   r   r   s                         r    r   z_TTGlyphGlyf._getGlyphInstance   s   222222DDDDDD999999=&	'249=
$$"==Ix
 
Q (
F 	< 	<C"]8#4ch??F OEu}}%*3*N*N	8X+ +'J '.ajAoo

4c'RS*oo@V@V;W;W  "	%V<<++E22V;;KKYty)**"1;	8I#
 #
 #
sFC %DJ DKr"   N)rX   rY   rZ   r   r   r   r   r^   r"   r    ri   ri      sS        
= 
= 
=
C 
C 
C  ( ( ( ( (r"   ri   c                       e Zd Zd ZdS )rz   c                 p    | j         j        | j                                     || j         j                   dS )r   N)r   rv   r   r   r}   r   s     r    r   z_TTGlyphCFF.draw  s1     	!$),11#t}7LMMMMMr"   N)rX   rY   rZ   r   r^   r"   r    rz   rz     s(        N N N N Nr"   rz   c                    | j         dk    rH| j        }||         j        }|                    |d          }| j        }| j        }||cxk    o|k    nc S | j         dk    r#| j        }	|	|| j                 d         z  }	|	dk    S | j         dk    r!| j        D ]}
t          |
|||          s dS dS | j         dk    r!| j        D ]}
t          |
|||          r dS dS | j         dk    rt          | j
        |||           S dS )	NrF   r         FT      )Format	AxisIndexr   r6   FilterRangeMinValueFilterRangeMaxValueDefaultValueVarIdxConditionTable_evaluateConditionconditionTable)	conditionfvarAxesr-   r   	axisIndexr   	axisValueminValuemaxValuer   subconditions              r    r   r     sg   1'	9%-LL!,,	009000000000		Q		&9+,Q//qy		Q		%4 	 	L%lHh	RR uut		Q		%4 	 	L!,(INN ttu		Q		%$h)
 
 
 	
 ur"   c                        e Zd Zd Zd Zd ZdS )r   c                 ^   ddl m}m} | j        }|j        }|j        j                            | j                  }|j	        j
        |         }ddlm}	 ddlm}
 |j        d         j         |	|j        | j        j                  }|j        D ]}|j        |j        z  r4|j        j        |j                 }t3          || j        j        |          sFi }|j        |j        j        |j                 }t;          |j                  }|j        |k    r|tA          ||j                 d          z  }tC          |          tC          |          k    s&J tC          |          tC          |          f            fdtE          ||          D             }|j#        |k    r1||j#                 }tI          |          }|%                    |           |j&        }|j        |j'        z  }| j        j        (                    ||          5  | j        (                    ||          5  | j        |j)        k    }|s:	 |*                    |j)        || j        j+                   n# tX          $ r d	}Y nw xY w|r|-                                }|j)        | j        k    r| j        n|j        }||j)                 }|r&t]          ||          }|/                    |           n%ta          ||          }|1                    |           ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   dS )
r   r   )VarComponentFlagsNO_VARIATION_INDEX)MultiVarStoreInstancerr&   r   N   c                 2    i | ]\  }}|         j         |S r^   r   )r   ivr   s      r    r!   z&_TTGlyphVARC._draw.<locals>.<dictcomp>i  s3       /3q!HQK'  r"   T)2fontTools.ttLib.tables.otTablesr   r   r   r   r   r   indexr   VarCompositeGlyphsVarCompositeGlyphfontTools.varLib.multiVarStorer   r9   r'   r*   r+   MultiVarStorer-   
componentsflagsHAVE_CONDITIONConditionListr   conditionIndexr   axisIndicesIndexAxisIndicesListItemr
   
axisValuesaxisValuesVarIndexfi2flrS   ziptransformVarIndexr   applyTransformDeltas	transformRESET_UNSPECIFIED_AXESrD   rK   addVarComponentr.   AttributeErrortoTransformr   r   r   r   )r<   r   
isPointPenr   r   r   r   idxr   r   r'   r   compr   r-   axisIndicesr   deltasr   r>   shouldDecomposetcompGlyphSetgtPenr   s                            @r    _drawz_TTGlyphVARC._drawA  s$   	
 	
 	
 	
 	
 	
 	
 	

 =!m"((33'9#>IIIIII??????=(-**$-*@
 
	 $ 6	) 6	)Dz-<<  .=d>QR	)x)?   H$0"278MN#DO44
*.@@@%	$2I(JB"O"OOJ;''3z??:::$$
OO=:::   7:;
7S7S   %);;;"4#9:~~))&111IJ!2!IIE'44XuEE ) )]//%@@ ) )&*i4>&AO* 33// $	4=;T     . 3 3 3.2OOO3 ' )%1133  $~:: !MM!)!2 %
 )8% )#4S!#<#<DLL....#/Q#7#7DFF4LLL1) ) ) ) ) ) ) ) ) ) ) ) ) ) )) ) ) ) ) ) ) ) ) ) ) ) ) ) );6	) 6	)s[   L "L	6&IL	I,	)L	+I,	,BL	=L 	LL LL  L$	'L$	c                 2    |                      |d           d S )NFr  r   s     r    r   z_TTGlyphVARC.draw  s    

3r"   c                 2    |                      |d           d S )NTr
  r   s     r    r   z_TTGlyphVARC.drawPoints  s    

3r"   N)rX   rY   rZ   r  r   r   r^   r"   r    r   r   @  sE        L) L) L)\      r"   r   Tr   c                Z   t          |          dk    sJ |d         d         }|d         d         }|d         d         }|d         d         }t          d          D ]}|d= |                                 rxt          |          t          | j                  k    sJ d | j        D             | _        t	          || j                  D ]$\  }	}
t          |
d	          r|	\  |
_        |
_        %nO| j        dk    rt          |          dk    sJ n.t          |          t          | j	                  k    sJ || _	        |r| 
                    |           t          ||z
            }t          ||z
            }t          | j        |z
            }t          || j        z
            }||||fS )
Nr   r   rF   c                 ,    g | ]}t          |          S r^   )r   )r   r   s     r    
<listcomp>z#_setCoordinates.<locals>.<listcomp>  s    DDD4DJJDDDr"   x)rS   r   isCompositer   r   r   r  ynumberOfContoursr   r   r   r   yMax)r   coordrd   r   	leftSideX
rightSideXtopSideYbottomSideYr   pr   horizontalAdvanceWidthverticalAdvanceWidthleftSideBearingtopSideBearings                  r    r   r     s   u::????b	!Ir1JRy|H)A,K1XX  "II 
"5zzS!1222222DD53CDDD5%"233 	# 	#GAttS!! #!"	# 
	1	$	$5zzQ5zzS!2333333! &9%%%$Z)%;<<"8k#9::ej9455OX
233N	 r"   c                   2    e Zd ZdZd	dZd Zd Zd Zd ZdS )
LerpGlyphSeta+  A glyphset that interpolates between two other glyphsets.

    Factor is typically between 0 and 1. 0 means the first glyphset,
    1 means the second glyphset, and 0.5 means the average of the
    two glyphsets. Other values are possible, and can be useful to
    extrapolate. Defaults to 0.5.
          ?c                 0    || _         || _        || _        d S r@   )	glyphset1	glyphset2factor)r<   r&  r'  r(  s       r    r=   zLerpGlyphSet.__init__  s    ""r"   c                 d    || j         v r|| j        v rt          ||           S t          |          r@   )r&  r'  	LerpGlyphKeyErrorr<   	glyphnames     r    rj   zLerpGlyphSet.__getitem__  s9    &&9+F+FY---y!!!r"   c                 &    || j         v o|| j        v S r@   )r&  r'  r,  s     r    rL   zLerpGlyphSet.__contains__  s    DN*JyDN/JJr"   c                     t          | j                  }t          | j                  }t          |                    |                    S r@   )setr&  r'  rN   intersectionr<   set1set2s      r    rQ   zLerpGlyphSet.__iter__  s<    4>""4>""D%%d++,,,r"   c                     t          | j                  }t          | j                  }t          |                    |                    S r@   )r0  r&  r'  rS   r1  r2  s      r    rT   zLerpGlyphSet.__len__  s<    4>""4>""4$$T**+++r"   N)r$  )	rX   rY   rZ   r[   r=   rj   rL   rQ   rT   r^   r"   r    r#  r#    sq            
" " "
K K K- - -
, , , , ,r"   r#  c                       e Zd Zd Zd ZdS )r*  c                 "    || _         || _        d S r@   )glyphsetr-  )r<   r-  r8  s      r    r=   zLerpGlyph.__init__  s     "r"   c                 |   t          | j        j                  }| j        j        | j                                     |           t          | j        j                  }| j        j        | j                                     |           | j        j        }t          t          |j	        |j	        |          |           d S r@   )
r   r8  r&  r-  r   r'  r(  r   r   r   )r<   r   
recording1
recording2r(  s        r    r   zLerpGlyph.draw  s    ,T]-DEE
/44Z@@@,T]-DEE
/44Z@@@%z'79I6RRTWXXXXXr"   N)rX   rY   rZ   r=   r   r^   r"   r    r*  r*    s7        # # #Y Y Y Y Yr"   r*  N)*r[   abcr   r   collections.abcr   
contextlibr   r   r   typesr	   fontTools.misc.vectorr
   fontTools.misc.fixedToolsr   r   r   fontTools.misc.loggingToolsr   fontTools.misc.transformr   r   fontTools.pens.transformPenr   r   fontTools.pens.recordingPenr   r   r   r   r`   ro   r   r   ri   rz   r   r   r   r#  r*  r^   r"   r    <module>rF     s#   % % # # # # # # # # # # # # # # % % % % % %         ! ! ! ! ! ! ( ( ( ( ( ( D D D D D D D D 9 9 9 9 9 9 C C C C C C C C G G G G G G G G         J/ J/ J/ J/ J/' J/ J/ J/ZM M M M Mk M M M!0 !0 !0 !0 !0[ !0 !0 !0H
- 
- 
- 
- 
-k 
- 
- 
-)* )* )* )* )*s )* )* )*XJ J J J J8 J J JZN N N N N( N N N     FS S S S S8 S S Sl >B # # # # #L, , , , ,7 , , ,BY Y Y Y Y Y Y Y Y Yr"   