%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/reportlab/lib/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/reportlab/lib/__pycache__/fontfinder.cpython-312.pyc

�

��d94����dZdZddlZddlZddlZddlmZddlmZddl	m
Zddlm
Z
mZd�Zgd	�Zd
ZdZdZd
ZdZdZdZdZdZGd�d�ZddlmZmZmZmZGd�d�Zd�Z e!dk(re �yy)z3.4.22a�This provides some general-purpose tools for finding fonts.

The FontFinder object can search for font files.  It aims to build
a catalogue of fonts which our framework can work with.  It may be useful
if you are building GUIs or design-time interfaces and want to present users
with a choice of fonts.

There are 3 steps to using it
1. create FontFinder and set options and directories
2. search
3. query

>>> import fontfinder
>>> ff = fontfinder.FontFinder()
>>> ff.addDirectories([dir1, dir2, dir3])
>>> ff.search()
>>> ff.getFamilyNames()   #or whichever queries you want...

Because the disk search takes some time to find and parse hundreds of fonts,
it can use a cache to store a file with all fonts found. The cache file name

For each font found, it creates a structure with
- the short font name
- the long font name
- the principal file (.pfb for type 1 fonts), and the metrics file if appropriate
- the time modified (unix time stamp)
- a type code ('ttf')
- the family name
- bold and italic attributes

One common use is to display families in a dialog for end users;
then select regular, bold and italic variants of the font.  To get
the initial list, use getFamilyNames; these will be in alpha order.

>>> ff.getFamilyNames()
['Bitstream Vera Sans', 'Century Schoolbook L', 'Dingbats', 'LettErrorRobot',
'MS Gothic', 'MS Mincho', 'Nimbus Mono L', 'Nimbus Roman No9 L',
'Nimbus Sans L', 'Vera', 'Standard Symbols L',
'URW Bookman L', 'URW Chancery L', 'URW Gothic L', 'URW Palladio L']

One can then obtain a specific font as follows

>>> f = ff.getFont('Bitstream Vera Sans', bold=False, italic=True)
>>> f.fullName
'Bitstream Vera Sans'
>>> f.fileName
'C:\code\reportlab\fonts\Vera.ttf'
>>>

It can also produce an XML report of fonts found by family, for the benefit
of non-Python applications.

Future plans might include using this to auto-register fonts; and making it
update itself smartly on repeated instantiation.
�N)�md5)�	quoteattr)�process_time)�asBytes�asNativec�B�	t|�S#t|d��cYSxYw)Nzlatin-1��enc)�	_asNative)�ss �:/usr/lib/python3/dist-packages/reportlab/lib/fontfinder.pyrrCs%��*���|���*���y�)�)�s�

�)z.ttfz.ttcz.otfz.pfbz.pfa����� �@iiic�"�eZdZdZd�Zd�Zd�Zy)�FontDescriptorz�This is a short descriptive record about a font.

    typeCode should be a file extension e.g. ['ttf','ttc','otf','pfb','pfa']
    c��d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_	d|_
d|_y)NFr)�name�fullName�
familyName�	styleName�isBold�isItalic�isFixedPitch�
isSymbolic�typeCode�fileName�metricsFileName�timeModified��selfs r
�__init__zFontDescriptor.__init__[sY����	���
������������
�!��������
���
�#������c� �d|jzS)NzFontDescriptor(%s))rr#s r
�__repr__zFontDescriptor.__repr__ks��#�d�i�i�/�/r&c
���g}|jj�D]5\}}|dvs�|s�|j|�dtt	|������7ddj|�zdzS)z Return an XML tag representation)r"�=z<font � z/>)�__dict__�items�appendr�str�join)r$�attrs�k�vs    r
�getTagzFontDescriptor.getTagnsi�����M�M�'�'�)�	C�D�A�q��(�(���L�L�A�y��Q��/@�!A�B�	C��#�(�(�5�/�)�D�0�0r&N)�__name__�
__module__�__qualname__�__doc__r%r(r4�r&r
rrVs���� 0�1r&r)�rl_isdir�	rl_isfile�
rl_listdir�rl_getmtimec�h�eZdZgdddddfd�Zdd�Zdd�Zd�Zd	�Zd
�Zd�Z	dd�Z
d
�Zd�Zd�Z
d�Zy)�
FontFinderTFNrc��||_||_|�tj�}|xsd|_t�|_||_|j|�g|_	g|_
g|_i|_i|_
i|_||_y)N�utf8)�useCache�validate�sys�getfilesystemencoding�_fsEncoding�set�_dirs�_recur�addDirectories�_fonts�
_skippedFiles�	_badFiles�_fontsByName�_fontsByFamily�_fontsByFamilyBoldItalic�verbose)r$�dirsrBrC�recur�
fsEncodingrQs       r
r%zFontFinder.__init__ys��� ��
� ��
����2�2�4�J�%�/�����U��
�������D�!������������� ���(*��%���r&c�4�t|�r�|jj|�|�|rmn|jr_t	j
|�D]F\}}}|D];}|jjtjj||���=�Hyyyy�N)r:rH�addrI�os�walk�pathr0)r$�dirNamerS�r�D�F�ds       r
�addDirectoryzFontFinder.addDirectory�s����G���J�J�N�N�7�#��)�u�t�{�{��W�W�W�-�:�E�A�a���:���
�
���r�w�w�|�|�A�a�'8�9�:�:�0;�u�r&c�8�|D]}|j||���y)N)rS)r`)r$�dirNamesrSr[s    r
rJzFontFinder.addDirectories�s$���	3�G����g�E��2�	3r&c�n��|js_|j}|D]N}|j}|��||jvr|j|j|��?|g|j|<�P|j�t�fd�|jj
�D��}|j�|S)z2Returns a list of the distinct font families foundc3�8�K�|]}t|������y�w�r	N�r��.0�_rTs  �r
�	<genexpr>z,FontFinder.getFamilyNames.<locals>.<genexpr>�s�����S�1�W�Q�:�.�.�S���)rOrKrr.rF�list�keys�sort)r$�fonts�font�fam�namesrTs     @r
�getFamilyNameszFontFinder.getFamilyNames�s�����"�"��K�K�E��
6���o�o���;���$�-�-�-��'�'��,�3�3�D�9�04�v�D�'�'��,�

6��%�%�
��S��8K�8K�8P�8P�8R�S�S��
�
�
���r&c�:�|jj|g�S)z5Return list of all font objects with this family name)rO�get)r$rs  r
�getFontsInFamilyzFontFinder.getFontsInFamily�s���"�"�&�&�z�"�5�5r&c	�
�g}|jd�|jd�|jD](}|jdtt|��z��*|j	�D]t}|s�|jdtt|��z�|j|�D]$}|jd|j
�z��&|jd��v|jd�dj|�S)	z.Reports on all families found as XML.
        z7<?xml version="1.0" encoding="UTF-8" standalone="yes"?>z<font_families>z    <directory name=%s/>z    <family name=%s>z        z
    </family>z</font_families>�
)r.rHrrrsrvr4r0)r$�linesr[rrps     r
�getFamilyXmlReportzFontFinder.getFamilyXmlReport�s�����
���N�O�
���&�'��z�z�	T�G��L�L�3�i���@Q�6R�R�S�	T��-�-�/�	.�J�����3�i���@T�6U�U�V� �1�1�*�=�=�D��L�L��d�k�k�m�!;�<�=����_�-�	.�	���'�(��y�y���r&c��g}|jD]C}d}|j�D]\}}t||d�|k7s�d}�|s�3|j|��E|S)z%This is a general lightweight search.TNF)rKr-�getattrr.)r$�kwds�selectedrp�OKr2r3s       r
�getFontsWithAttributesz!FontFinder.getFontsWithAttributes�sf�����K�K�	&�D��B��
�
��
���1��4��D�)�Q�.��B�
������%�
	&��r&c��|jD]5}|j|k(s�|j|k(s�#|j|k(s�3|cSt	d|�d|�d|����)z$Try to find a font matching the speczCannot find font z with bold=z	, italic=)rKrrr�KeyError)r$r�bold�italicrps     r
�getFontzFontFinder.getFont�sV���K�K�	$�D����*�,��;�;�$�&��}�}��.�#��		$��
�TX�Z`�a�b�br&c����|j�tdj�fd�t|j�D���j�}ddlm}|d|z�}|S)zUBase this on the directories...same set of directories
        should give same cacher&c3�8�K�|]}t|������y�wrerfrgs  �r
rjz/FontFinder._getCacheFileName.<locals>.<genexpr>�s�����R�!�G�A�*�5�5�R�rkr)�get_rl_tempfilezfonts_%s.dat)rFrr0�sortedrH�	hexdigest�reportlab.lib.utilsr�)r$�hashr��fnrTs    @r
�_getCacheFileNamezFontFinder._getCacheFileName�sR����%�%�
��3�8�8�R�v�d�j�j�?Q�R�R�S�]�]�_��7�
�^�d�2�
3���	r&c�h�t|d�}tj||�|j�y)N�wb)�open�pickle�dump�close)r$r �fs   r
�savezFontFinder.save�s%����4� �����D�!��	���	r&c��t|d�}tj|�}|j�|jj|j�y)N�rb)r�r��loadr�r,�update)r$r r��finder2s    r
r�zFontFinder.load�s<����4� ���+�+�a�.��	���	��
�
���W�-�-�.r&c	��	�|jr
t�}|jstd��|jr`|j�}t
|�rE	|j|�|jdk\r#tdt|j�|fz�y|jD�]c}	t|�}|D�]N}tjj|�\}}|j�t vs�=t#�}tjj%tjj'||��x|_}	t+|�|_|j�}|ddk(r|dd}||_|dvr|j.j1|��nS|dvr�dd	lm}	m}
	|	||j:�
�}|j>|_|j@|_ |jB|_!|jD|_"tFtF|jHzk(|_%tLtL|jHzk(|_'�n�|dk(�r�t
tjj'||dz��rFtjj%tjj'||dz��|_(n�t
tjj'||d
z��rFtjj%tjj'||d
z��|_(n|j.j1|����ddl)m*}||jP�\}
}|
d|_|
jWd|j>�|_ |
jWdd�|_"tY|
jWdd��dkD|_'d|
jWdd�j�v|_%|jj1|���Q��f|jr|j[�|jrYt�}tdt|j�t|j.�t|j<�|z
fz�yy#Y���xYw#Y���xYw#|j.j1|�Y��xYw#|
$r|j<j1|�Y��.wxYw)NzbFont search path is empty!  Please specify search directories using addDirectory or addDirectories�z%loaded cached file with %d fonts (%s)r�.r)�otf�pfa)�ttf�ttc)�
TTFontFile�TTFError)rC�pfbz.afmz.AFM)�parseAFMFile�FontName�FullName�
FamilyName�ItalicAnglegr��Weight�z7found %d fonts; skipped %d; bad %d.  Took %0.2f seconds).rQ�clockrH�
ValueErrorrBr�r;r��print�lenrKr<rXrZ�splitext�lower�
EXTENSIONSr�normpathr0r r=r"rLr.r�reportlab.pdfbase.ttfontsr�r�rCrMrrrr�FF_FORCEBOLD�flagsr�	FF_ITALICrr!�reportlab.pdfbase.pdfmetricsr�ru�floatr�)r$�started�cfnr[�	fileNamesr �root�extr�r�r�rpr��info�glyphs�finisheds                r
�searchzFontFinder.search�s����<�<��g�G��z�z��B�C�
C��=�=��(�(�*�C���~���I�I�c�N��|�|�Q���E��T�[�[�IY�[^�H_�_�`���z�z�?	*�G�
�&�w�/�	�&�:
*���G�G�,�,�X�6�	��c��9�9�;�*�,�&�(�A�,.�G�G�,<�,<�R�W�W�\�\�'�S[�=\�,]�]�A�J��!�)4�X�)>���
�)�)�+�C��1�v��}�!�!�"�g��!$�A�J�
�n�,��*�*�1�1�(�;��
�-�R�%�#-�h��
�
�#N�D�"&�����%)�]�]��
�&*�n�n���'+�����$0�L�4�:�:�4M�$M���&/�9�t�z�z�3I�&I��
����%�R�W�W�\�\�'�4�&�=�%I�J�02���0@�0@������g�W[�^d�Wd�Ae�0f�A�-�&�r�w�w�|�|�G�T�F�]�'K�L�02���0@�0@������g�W[�^d�Wd�Ae�0f�A�-� �.�.�5�5�h�?�$�M�)5�a�6G�6G�)H���v�!%�j�!1���%)�X�X�j�!�&�&�%A��
�'+�x�x��d�'C���&+�D�H�H�]�A�,F�&G�#�&M��
�$*�d�h�h�x��.C�.I�.I�.K�$K����K�K�&�&�q�)�u:
*�?	*�@�=�=��I�I�c�N��<�<��w�H��K��D�K�K� �#�d�&8�&8�"9�3�t�~�~�;N��7�"�O��
���M���

���!��*�*�1�1�(�;� ��$ (�%� �N�N�1�1�(�;�$�%�s7�AR�+R�R �&S�R�R� S� S'�&S'rV)FF)r5r6r7r%r`rJrsrvrzr�r�r�r�r�r�r9r&r
r?r?xsO�����U�W[�ef��(:�3�� 6� �"
�	c���
/�Yr&r?c�~�ddlm}t|j��}d|_d|_ddl}|j
d�tjjtjj|j�d�}|j
|�|j�td�t|j��td�|j�D]}td	|z��t�t j"j$}|d
�|j'd�D]}|d|j(z��t�|d
�|j+dd��D]}||j,dz��t�td�t|j/��y)Nr)�	rl_config)rQTzC:\windows\fontsrozcache file name...zfamilies...z	%szfonts called Vera:zBitstream Vera Sansz %szBold fonts
	F)rrr+z
family report)�	reportlabr�r?rQrBrCr`rXrZr0�dirname�__file__r�r�r�rsrD�stdout�writervrr�rrz)r��ffr��	rlFontDirr�outwrps       r
�testr�Fs]��#�	�I�-�-�	.�B��B�K��B�K���O�O�(�)������R�W�W�_�_�Y�-?�-?�@�'�J�I��O�O�I���I�I�K�	�
��	�"�
�
�
 �!�	�-���'�'�)�#�
�
�f�z�!�"�#�
�G��:�:���D��	���#�#�$9�:� ���U�T�Y�Y�
�� �	�G��	���)�)���)�F� ���T�]�]�3�
�� �	�G�	�/��	�"�
�
�
!�"r&�__main__)"�__version__r8rDrXr��hashlibr�xml.sax.saxutilsr�timerr�r�rrrr��FF_FIXED�FF_SERIF�FF_SYMBOLIC�	FF_SCRIPT�FF_NONSYMBOLICr��	FF_ALLCAP�FF_SMALLCAPr�rr:r;r<r=r?r�r5r9r&r
�<module>r�s���
��6	��n���&�&�>�*�2�
��������	����	��	�����1�1�BM�L�L�L�\#�B�Z���F�r&

Zerion Mini Shell 1.0