HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib/python3.10/site-packages/fontTools/__pycache__/afmLib.cpython-310.pyc
o

 wea3�@sdZddlZe�d�Ze�d�Ze�d�Ze�d�Ze�d�Zgd�ZGd	d
�d
e	�Z
Gdd�de�Zd
d�Z
ddd�Zedkr�ddlZe��Zer�ee�ZdZe�e�r[eee�dZe�e�rheee�eej�eej�ee���ee�e�ed�dSdSdS)a
Module for reading and writing AFM (Adobe Font Metrics) files.

Note that this has been designed to read in AFM files generated by Fontographer
and has not been tested on many other files. In particular, it does not
implement the whole Adobe AFM specification [#f1]_ but, it should read most
"common" AFM files.

Here is an example of using `afmLib` to read, modify and write an AFM file:

	>>> from fontTools.afmLib import AFM
	>>> f = AFM("Tests/afmLib/data/TestAFM.afm")
	>>>
	>>> # Accessing a pair gets you the kern value
	>>> f[("V","A")]
	-60
	>>>
	>>> # Accessing a glyph name gets you metrics
	>>> f["A"]
	(65, 668, (8, -25, 660, 666))
	>>> # (charnum, width, bounding box)
	>>>
	>>> # Accessing an attribute gets you metadata
	>>> f.FontName
	'TestFont-Regular'
	>>> f.FamilyName
	'TestFont'
	>>> f.Weight
	'Regular'
	>>> f.XHeight
	500
	>>> f.Ascender
	750
	>>>
	>>> # Attributes and items can also be set
	>>> f[("A","V")] = -150 # Tighten kerning
	>>> f.FontName = "TestFont Squished"
	>>>
	>>> # And the font written out again (remove the # in front)
	>>> #f.write("testfont-squished.afm")

.. rubric:: Footnotes

.. [#f1] `Adobe Technote 5004 <https://www.adobe.com/content/dam/acom/en/devnet/font/pdfs/5004.AFM_Spec.pdf>`_,
   Adobe Font Metrics File Format Specification.

�Nz^([A-Za-z]+).*zl(-?\d+)\s*;\s*WX\s+(-?\d+)\s*;\s*N\s+([.A-Za-z0-9_]+)\s*;\s*B\s+(-?\d+)\s+(-?\d+)\s+(-?\d+)\s+(-?\d+)\s*;\s*z0([.A-Za-z0-9_]+)\s+([.A-Za-z0-9_]+)\s+(-?\d+)\s*z([.A-Za-z0-9_]+)\s+(\d+)\s*;\s*z1PCC\s+([.A-Za-z0-9_]+)\s+(-?\d+)\s+(-?\d+)\s*;\s*)�FontName�FullName�
FamilyName�Weight�ItalicAngle�IsFixedPitch�FontBBox�UnderlinePosition�UnderlineThickness�Version�Notice�EncodingScheme�	CapHeight�XHeight�Ascender�	Descenderc@seZdZdS)�errorN)�__name__�
__module__�__qualname__�rr�I/home/arjun/projects/env/lib/python3.10/site-packages/fontTools/afmLib.pyrusrc@s�eZdZdZgd�Zd.dd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
d/dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�ZdS)0�AFMN)
�StartFontMetrics�EndFontMetrics�StartCharMetrics�EndCharMetrics�
StartKernData�StartKernPairs�EndKernPairs�EndKernData�StartComposites�
EndCompositescCs>i|_i|_i|_i|_g|_i|_|dur|�|�dSdS)z�AFM file reader.

        Instantiating an object with a path name will cause the file to be opened,
        read, and parsed. Alternatively the path can be left unspecified, and a
        file can be parsed later with the :meth:`read` method.N)�_attrs�_chars�_kerning�_index�	_comments�_composites�read)�self�pathrrr�__init__�s�zAFM.__init__cCs�t|�}|D]W}|��s
qt�|�}|durtdt|���|jdd}|d|�}||d���}||jvr9q|dkrC|�|�q|dkrM|�	|�q|dkrW|�
|�q|�||�qdS)zOpens, reads and parses a file.N�syntax error in AFM file: ��C�KPX�CC)�	readlines�strip�identifierRE�matchr�repr�regs�	_keywords�	parsechar�
parsekernpair�parsecomposite�	parseattr)r*r+�lines�line�m�pos�word�restrrrr)�s(

�zAFM.readc
Cs�t�|�}|durtdt|���g}|jdd�D]
\}}|�|||��q|d}|d=dd�|D�\}}}	}
}}|||	|
||ff|j|<dS)Nr-r.�css�|]}t|�VqdS�N��int��.0�thingrrr�	<genexpr>�s�z AFM.parsechar.<locals>.<genexpr>)�charREr5rr6r7�appendr$)
r*rBr?�things�fr�to�charname�charnum�width�l�b�r�trrrr9�s
z
AFM.parsecharc	Cstt�|�}|durtdt|���g}|jdd�D]
\}}|�|||��q|\}}}t|�}||j||f<dS)Nr-r.)�kernREr5rr6r7rLrFr%)	r*rBr?rMrNrO�leftchar�	rightchar�valuerrrr:�s

zAFM.parsekernpairc	Cs�|dkrdd�|��D�\}}}}||||f|j|<dS|dkr(|j�|�dSzt|�}Wnttfy?||j|<YdSw||j|<dS)NrcSsg|]}t|��qSrrErGrrr�
<listcomp>�sz!AFM.parseattr.<locals>.<listcomp>�Comment)�splitr#r'rLrF�
ValueError�
OverflowError)r*rArBrSrTrUrVrZrrrr<�s�z
AFM.parseattrc	Cs�t�|�}|durtdt|���|�d�}t|�d��}||jddd�}g}	t�|�}|dur<tdt|���|�d�}t|�d��}t|�d��}|�|||f�||jddd�}|senq+t	|�|ksnJ�||j
|<dS)Nr-r.rCrT�)�compositeREr5rr6�grouprFr7�componentRErL�lenr()	r*rBr?rP�ncomponents�
components�basechar�xoffset�yoffsetrrrr;�s*



�zAFM.parsecomposite�
cCsDddl}dd|�d|�|����g}|jD]	}|�d|�q|j}tD]}||vrB||}|dkr7d|}|�|d	t|��q%t|�	��}	|	D]\}}|tvrTqK|�|d	t|��qK|�d
t
t|j���dd�|j�	�D�}	d
d�}
|	j
|
d�|	D]\}\}}
\}}}}|�d||
|||||f�q�|�d�|�d�|�dt
t|j���t|j�	��}	|	D]\\}}}|�d|||f�q�|�d�|�d�|j�rt|j�	��}|�dt|j��|D]"\}}d|t|�f}|D]\}}}|d|||f}q�|�|�q�|�d�|�d�t|||�dS)z)Writes out an AFM font to the given path.rNzStartFontMetrics 2.0z"Comment Generated by afmLib; at %sz%m/%d/%Y %H:%M:%SzComment rz%s %s %s %s� zStartCharMetrics cSs$g|]\}\}}}||||ff�qSrr)rHrPrQrR�boxrrrr[
s��zAFM.write.<locals>.<listcomp>cSs |ddkrd|dd�}|S)znCustom key function to make sure unencoded chars (-1)
            end up at the end of the list after sorting.r���)i��r.Nr)�arrr�myKeyszAFM.write.<locals>.myKey)�keyz%C %d ; WX %d ; N %s ; B %d %d %d %d ;rrzStartKernPairs zKPX %s %s %drr zStartComposites %sz
CC %s %s ;z PCC %s %s %s ;r"r)�time�strftime�	localtimer'rLr#�preferredAttributeOrder�str�sorted�itemsr6rdr$�sortr%r(�
writelines)r*r+�seprqr=�comment�attrs�attrrZrwrorQrPrRrSrTrUrVrXrY�
compositesrfr>rgrhrirrr�write�sh��
����





z	AFM.writecC�
||jvS)zgReturns `True` if the given glyph pair (specified as a tuple) exists
        in the kerning dictionary.)r%)r*�pairrrr�has_kernpair9s
zAFM.has_kernpaircC�t|j���S)z;Returns a list of all kern pairs in the kerning dictionary.)�listr%�keys�r*rrr�	kernpairs>�z
AFM.kernpairscCr�)z5Returns `True` if the given glyph exists in the font.)r$)r*�charrrr�has_charBs
zAFM.has_charcCr�)z.Returns a list of all glyph names in the font.)r�r$r�r�rrr�charsFr�z	AFM.charscCs|jS)z#Returns all comments from the file.)r'r�rrr�commentsJszAFM.commentscCs|j�|�dS)zAdds a new comment to the file.N)r'rL)r*r{rrr�
addCommentNszAFM.addCommentcCs||j|<dS)aSpecifies that the glyph `glyphName` is made up of the given components.
        The components list should be of the following form::

                [
                        (glyphname, xOffset, yOffset),
                        ...
                ]

        N)r()r*�	glyphNamerfrrr�addCompositeRs
zAFM.addCompositecCs||jvr
|j|St|��rD)r#�AttributeError�r*r}rrr�__getattr__^s

zAFM.__getattr__cCs,|dd�dkr||j|<dS||j|<dS�Nr.�_)�__dict__r#)r*r}rZrrr�__setattr__dszAFM.__setattr__cCs\|dd�dkrz|j|=WdStyt|��wz|j|=WdSty-t|��wr�)r��KeyErrorr�r#r�rrr�__delattr__ks��zAFM.__delattr__cCst|t�r
|j|S|j|SrD��
isinstance�tupler%r$�r*rprrr�__getitem__xs


zAFM.__getitem__cCs&t|t�r||j|<dS||j|<dSrDr�)r*rprZrrr�__setitem__�s
zAFM.__setitem__cCs"t|t�r|j|=dS|j|=dSrDr�r�rrr�__delitem__�s
zAFM.__delitem__cCs t|d�r
d|jSdt|�S)Nrz<AFM object for %s>z<AFM object at %x>)�hasattrr�idr�rrr�__repr__�s

zAFM.__repr__rD�rj)rrrr#r8r,r)r9r:r<r;rr�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrys0


N
rcCsDt|ddd��}|��}Wd�|��S1swY|��S)NrU�ascii)�encoding)�openr)�
splitlines)r+�f�datarrrr2�s

��r2rjcCsJt|dd|d��}|�d�|�d�Wd�dS1swYdS)N�wr�)r��newline�
)r�r�join)r+r=rzr�rrrry�s"�ry�__main__�A)r��Vz.muckr�)�__doc__�re�compiler4rKrWrarcrt�	Exceptionr�objectrr2ryr�EasyDialogs�AskFileForOpenr+�afmr�r��printr�r�rrr�rrrrr�<module>sP0
����
 




�