Files
intellecton/venv/lib/python3.12/site-packages/fontTools/__pycache__/afmLib.cpython-312.pyc
T

119 lines
16 KiB
Plaintext
Raw Normal View History

Ë
zRjl3ãóv—dZddlZejd«Zejd«Zejd«Zejd«Zejd«Zgd¢ZGd „d
e «Z
Gd „d e «Z d
„Z
dd„Zedk(r³ddlZej"«Zer›e e«ZdZej+e«r eee«dZej1e«r eee«eej2«eej4«eej7««ee«ej9edz«yyy)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ó —eZdZy)ÚerrorN)Ú__name__Ú
__module__Ú __qualname__©óúS/home/antigravity/intellecton/venv/lib/python3.12/site-packages/fontTools/afmLib.pyrrws„Ørrcóš—eZdZdZgd¢Zdd„Zd„Zd„Zd„Zd„Z d„Z
dd „Z d
„Z d „Z
d „Zd
„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zy)ÚAFMN)
ÚStartFontMetricsÚEndFontMetricsÚStartCharMetricsÚEndCharMetricsÚ
StartKernDataÚStartKernPairsÚ EndKernPairsÚ EndKernDataÚStartCompositesÚ
EndCompositescó€—i|_i|_i|_i|_g|_i|_|�|j
|«yy)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Úpaths rÚ__init__z AFM.__init__‹sE€ð ˆŒ ؈Œ ؈Œ
؈Œ ؈ŒØˆÔØ Ð Ø �I‰I�d�Oð rcóÆ—t|«}|D]Ñ}|j«sŒtj|«}|€t dt |«z«‚|j dd}|d|}||dj«}||jvrŒ{|dk(r|j|«Œ’|dk(r|j|«Œ©|dk(r|j|«ŒÀ|j||«ŒÓy)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/r0ÚlinesÚlineÚmÚposÚwordÚrests rr.zAFM.readšsÚ€ä˜$“ˆØò +ˆDØ—:‘:”<ØÜ×"Ñ" 4Ó(ˆA؈yÜÐ8¼4À»:ÑEÓFÐFà—&‘&˜‘)˜A‘,ˆCؘ˜�:ˆDؘ˜�:×#Ñ#Ó%ˆDØ�t—~‘~Ñ%ØØ�sŠ{Ø—‘˜tÕ$ؘ’Ø×"Ñ" 4Õ(ؘ’Ø×#Ñ# DÕ)à—‘˜t TÕ*ñ' +rcó—tj|«}|€tdt|«z«‚g}|jddD]\}}|j |||«Œ|d}|d=d„|D«\}}} }
} } ||| |
| | ff|j |<y)Nr3r4éc3ó2K—|]}t|«–—Œy­w©N)Úint)Ú.0Úthings rú <genexpr>z AFM.parsechar.<locals>.<genexpr>»sèø€Ò%E°U¤c¨%§jÑ%Eùs‚)ÚcharREr;rr<r=Úappendr))
r/rHrEÚthingsÚfrÚtoÚcharnameÚcharnumÚwidthÚlÚbÚrÚts
rr?z
AFM.parsechar²s¢€Ü �L‰L˜Ó ˆØ ˆ9ÜÐ4´t¸D³zÑAÓBÐ B؈ؗf‘f˜Q˜R�jò '‰FˆB�Ø �M‰M˜$˜r "˜+Õ &ð 'à˜!‘9ˆØ �1ˆIÙ%E¸fÔ%EÑ"ˆ�˜˜1˜a Ø '¨°°A°q¸!° Ð <ˆ� ‰ �HÒrcóþ—tj|«}|€tdt|«z«‚g}|jddD]\}}|j |||«Œ|\}}}t
|«}||j||f<y)Nr3r4)ÚkernREr;rr<r=rRrMr*) r/rHrErSrTrUÚleftcharÚ rightcharÚvalues rr@zAFM.parsekernpair¾s†€Ü �L‰L˜Ó ˆØ ˆ9ÜÐ4´t¸D³zÑAÓBÐ B؈ؗf‘f˜Q˜R�jò '‰FˆB�Ø �M‰M˜$˜r "˜+Õ &ð 'à%+Ñ"ˆ�)˜UÜ�E“
ˆØ/4ˆ�
‰
�x Ð+Ò,rcóX—|dk(r@|j«D�cgc]
}t|«‘Œc}\}}}}||||f|j|<y|dk(r|jj |«y t|«}||j|<ycc}w#t
t f$r||j|<YywxYw)Nr ÚComment)ÚsplitrMr(r,rRÚ
ValueErrorÚ
OverflowError) r/rGrHrOrYrZr[r\ras rrBz
AFM.parseattrÉs¤€Ø �:Ò Ø26·*±*³,Ö?¨œ#˜e�*Ò?‰JˆAˆq�!�QØ ! 1 a¨ 
ˆD�K‰K˜Ò Ø
�YÒ
Ø �N‰N× !Ñ ! $Õ 'ð
*ܘD› �ð%*�— ‘ ˜DÒ!ùò@øô¤
Ð.ò
)Ø$(�— ‘ ˜DÓ!ð
)ús˜BÁ( BÂB)Â(B)cód—tj|«}|€tdt|«z«‚|j d«}t |j d««}||j ddd}g} tj|«}|€tdt|«z«‚|j d«}t |j d««}t |j d««}|j|||f«||j ddd}|snŒ t|«|k(sJ‚||j|<y)Nr3r4rJré) Ú compositeREr;rr<ÚgrouprMr=Ú componentRErRÚlenr-) r/rHrErVÚ ncomponentsÚ
componentsÚbasecharÚxoffsetÚyoffsets rrAzAFM.parsecomposite×s€Ü × Ñ ˜dÓ #ˆØ ˆ9ÜÐ4´t¸D³zÑAÓBÐ BØ—7‘7˜1“:ˆÜ˜!Ÿ'™' !›*“oˆ Ø�A—F‘F˜1‘I˜a‘L�NÐ#ˆØˆ
ØÜ×!Ñ! $Ó'ˆA؈yÜÐ8¼4À»:ÑEÓFÐFØ—w‘w˜q“zˆHܘ!Ÿ'™' !›*“oˆGܘ!Ÿ'™' !›*“oˆGØ × Ñ ˜x¨°'Ð:Ô ;ؘŸ™˜q™  !™ ˜Ð'ˆDÙØðô�:‹ +Ò-Ð-Ð-Ø%/ˆ×јÒ"rc ób—ddl}dd|jd|j|j«««zg}|jD]}|j d|z«Œ|j
}t D]6}||vsŒ||}|dk(rd|z}|j |d zt|«z«Œ8t|j««} | D].\}}|t vrŒ|j |d zt|«z«Œ0|j d
tt|j««z«|jj«D�
� � �
cgc]\}
\} } }
| |
| |
ff‘Œ} } } }
}
d „}| j|¬ «| D])\} \}
} \}}}}|j d
| | |
||||fz«Œ+|j d«|j d«|j dtt|j««z«t|jj««} | D]\\}}}|j d|||fz«Œ!|j d«|j d«|jr¢t|jj««}|j dt|j«z«|D]B\}
}d|
›d t|«›d�}|D]\}}}|d|›d |›d |›d�z}Œ|j |«ŒD|j d«|j d«t!|||«ycc}
} } }
w)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 r z %s %s %s %sú zStartCharMetrics có&—|ddk(rd|ddz}|S)znCustom key function to make sure unencoded chars (-1)
end up at the end of the list after sorting.réÿÿÿÿ)iÿÿr4Nr)Úas rÚmyKeyzAFM.write.<locals>.myKeys$€ð�‰t�rŠzØ  ! " Ñ%�؈Hr)Úkeyz%C %d ; WX %d ; N %s ; B %d %d %d %d ;r r!zStartKernPairs z KPX %s %s %dr#r$zStartComposites %szCC z ;z PCC r&r)ÚtimeÚstrftimeÚ localtimer,rRr(ÚpreferredAttributeOrderÚstrÚsortedÚitemsr<rlr)Úsortr*r-Ú
writelines)r/r0ÚsepryrCÚcommentÚattrsÚattrrarrVrWrXÚboxrwrYrZr[r\r_r`Ú
compositesrnrDrorprqs rÚwritez AFM.writeís'€ãð
#Ø 0Ø�}‰}Ð0°$·.±.ÀÇÁÃÓ2MÓNñ
Pð
ˆð—~‘~ò /ˆGØ �L‰L˜ gÑ-Õ .ð /ð
— ‘ ˆÜ+ò 6ˆDØ�uŠ}ؘd™ �ؘ:Ò%Ø)¨EÑ1�EØ— ‘ ˜T C™Z¬#¨e«*Ñ4Õ5ð  6ô�u—{‘{“}Ó%ˆØ ò 2‰KˆD�%ØÔ.Ñ.ØØ �L‰L˜ ™¤c¨%£jÑ0Õ 1ð 2ð � ‰ Ð(¬4´°D·K±KÓ0@Ó+AÑAÔBð48·;±;×3DÑ3DÓ3F÷
ñ
á/�Ñ/˜7 E¨3ð�x ¨Ð,Ò -ð
ˆó
ò