%PDF- %PDF-
Mini Shell

Mini Shell

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

�

��dPI���dZdZddlZddlZddlZddlmZddlmZddl	m
Z
mZmZm
Z
mZddlmZddlmZdd	lmZdd
lmZddlmZmZdZd
�Zd�ZGd�dej8�ZGd�dej<�ZGd�dej@�Z!Gd�de!�Z"d�Z#d�Z$e%dk(rddl&Z&ddlm'Z'e&jPe'�yy)z3.3.0z�CID (Asian multi-byte) font support.

This defines classes to represent CID fonts.  They know how to calculate
their own width and how to write themselves into PDF files.�N)�md5)�
pdfmetrics)�allowedTypeFaces�allowedEncodings�CIDFontInfo�defaultUnicodeEncodings�widthsByUnichar)�Canvas)�pdfdoc��	escapePDF)�CMapSearchPath)�isSeq�isBytesTc��tD];}|tjz|z}tjj	|�s�9|cStd|z��)z&Returns full filename, or raises errorz'CMAP file for encodings "%s" not found!)r�os�sep�path�isfile�IOError)�name�dirname�cmapfiles   �</usr/lib/python3/dist-packages/reportlab/pdfbase/cidfonts.py�findCMapFilersL��!����R�V�V�#�d�*��
�7�7�>�>�(�#��O�	�
�;�d�B�
C�C�c�&�t|t�r=i}|j�D]\}}t|�||<�t	j
|�St
|�r8g}|D]}|jt|���t	j|�S|S)zCConverts deeply nested structure to PDFdoc dictionary/array objects)	�
isinstance�dict�items�structToPDFr�
PDFDictionaryr�append�PDFArray)�	structure�newDict�k�v�newList�elems      rr!r!'s����)�D�!����O�O�%�	(�D�A�q�$�Q��G�A�J�	(��#�#�G�,�,�	�y�	����	.�D��N�N�;�t�,�-�	.����w�'�'��rc�<�eZdZdZd
d�Zd�Zd�Zd�Zd�Zd�Z	d�Z
y	)�CIDEncodingz�Multi-byte encoding.  These are loaded from CMAP files.

    A CMAP file is like a mini-codec.  It defines the correspondence
    between code points in the (multi-byte) input data and Character
    IDs. c���||_d|_g|_g|_i|_d|_ts�|r�ddlm}|d�}tjj|tjz|zdz�r0|j|�|tjz|zdz|_y|j|�d|z|_|j|�y|j|�yy)Nr)�get_rl_tempdir�	FastCMAPS�.fastmapzCMAP: )r�_mapFileHash�_codeSpaceRanges�
_notDefRanges�_cmap�source�DISABLE_CMAP�reportlab.lib.utilsr.rrrr�fastLoad�
parseCMAPFile�fastSave)�selfr�useCacher.�
fontmapdirs     r�__init__zCIDEncoding.__init__Bs�����	� ��� "��������
������>�+�K�8�
��7�7�>�>�*�r�v�v�"5��"<�z�"I�J��M�M�*�-�",�r�v�v�"5��"<�z�"I�D�K��&�&�t�,�"*�T�/�D�K��M�M�*�-��"�"�4�(�rc�X�t�}|j|�|j�S�N)r�update�digest)r;�text�hashers   r�_hashzCIDEncoding._hashWs!������
�
�d���}�}��rc��t|�}t|d�j�}|j|�|_|jd�}|dkDr+|d|}|j
�}|d}|j|�|j
�}|gk7�rn|ddk(rb|dd}|ddk7�rP|d|d|d	d}}	}t|ddd
�}
t|	ddd
�}|jj|
|f�|ddk7r�Sn�|ddk(rl|dd}|ddk7r�|dd
\}}	}t|ddd
�}
t|	ddd
�}t|�}
|jj|
||
f�|d
d}|ddk7r�^n�|ddk(r{|dd}|ddk7rs|dd
\}}	}t|ddd
�}
t|	ddd
�}t|�}
d}|
|z|kr#|
|z|j|
|z<|dz}|
|z|kr�#|d
d}|ddk7r�mn|dd}|gk7r��myy)zvThis is a tricky one as CMAP files are Postscript
        ones.  Some refer to others with a 'usecmap'
        command�r�usecmap���r�begincodespacerange�N�endcodespacerange���beginnotdefrange�endnotdefrange��
begincidrange�endcidrange)
r�open�readrEr1�find�splitr9�intr2r#r3r4)r;rr�rawdata�usecmap_pos�chunk�words�
otherCMAPName�strStart�strEnd�start�end�strValue�value�offsets               rr9zCIDEncoding.parseCMAPFile\s���
 ��%���x��%�*�*�,�� �J�J�w�/����l�l�9�-���"���A�k�*�E��K�K�M�E�!�"�I�M����}�-�
�
�
����r�k��Q�x�0�0��a�b�	���A�h�"5�5�.3�A�h��a��%���)�e�f�H����2���3�E��f�Q�r�l�B�/�C��)�)�0�0�%���?�	�A�h�"5�5�
�q��/�/��a�b�	���A�h�"2�2�16�q���.�H�f�h����2���3�E��f�Q�r�l�B�/�C���M�E��&�&�-�-�u�c�5�.A�C�!�!�"�I�E�
�A�h�"2�2��q��_�,��a�b�	���A�h�-�/�16�q���.�H�f�h����2���3�E��f�Q�r�l�B�/�C���M�E��F��&�.�C�/�5:�V�^��
�
�5�6�>�2�!'�!��� �&�.�C�/�"�!�"�I�E��A�h�-�/��a�b�	��E�r�krc��g}|j}d}|D]u}|dk7rt|�dzt|�z}nt|�}|}d}|jD].\}}	||cxkr|	ks�n�	||}
|j|
�d}n|rd}�t|}�w|S#t$r,d}
|jD]\}}}
||cxkr|ks�n�|
}
nY�UwxYw)z$Convert a string into a list of CIDs��rrK)r4�ordr2�KeyErrorr3r#)r;rC�output�cmap�lastChar�char�num�found�low�high�cid�low2�high2�notdefs              r�	translatezCIDEncoding.translate�s�����z�z�����	 �D��2�~��(�m�c�)�C��I�5���$�i���H��E�!�2�2�
�	��T���#�t�#�&�"�3�i���M�M�#�&��E��!
�"�����;	 �<�
��!$�&� ��37�3E�3E�&�/�D�%��#�c�1�E�1�&,�� %�&��&�s�'B
�
)C�7C�Cc��ttjj||jdz�d�}tj|j|�tj|j|�tj|j|�tj|j|�|j�y)Nr0�wb)rTrr�joinr�marshal�dumpr1r2r3r4�close)r;�	directory�fs   rr:zCIDEncoding.fastSave�s}��������i����Z�)?�@�$�G�����T�&�&��*����T�*�*�A�.����T�'�'��+����T�Z�Z��#�	���	rc��tj�}ttjj||jdz�d�}tj|�|_	tj|�|_
tj|�|_tj|�|_|j�tj�}y)Nr0�rb)�time�clockrTrrryrrz�loadr1r2r3r4r|)r;r}�startedr~�finisheds     rr8zCIDEncoding.fastLoad�s����*�*�,��������i����Z�)?�@�$�G��#�L�L��O��� '���Q����$�\�\�!�_����\�\�!�_��
�	���	��:�:�<�rc�`�|j|j|j|jd�S)z@Simple persistence helper.  Return a dict with all that matters.)�mapFileHash�codeSpaceRanges�notDefRangesrk)r1r2r3r4)r;s r�getDatazCIDEncoding.getData�s0�� �,�,�#�4�4� �.�.��J�J�	�	rN)rK)�__name__�
__module__�__qualname__�__doc__r>rEr9rvr:r8r��rrr,r,6s,��
�)�*�
="�B#�J� �rr,c�(�eZdZdZd�Zd�Zd�Zd�Zy)�CIDTypeFacez�Multi-byte type face.

    Conceptually similar to a single byte typeface,
    but the glyphs are identified by a numeric Character
    ID (CID) and not a glyph name. c�f�tjj||�|j|�y)zmInitialised from one of the canned dictionaries in allowedEncodings

        Or rather, it will be shortly...N)r�TypeFacer>�_extractDictInfo)r;rs  rr>zCIDTypeFace.__init__�s(��	���$�$�T�4�0����d�#rc��	t|}|dd}|dd|_|dd|_|d|_|j|d	�|_y#t$r"td|zdztt�z��wxYw)
Nz/Unable to find information on CID typeface '%s'z#Only the following font names work:�DescendantFontsr�FontDescriptor�Ascent�Descent�DW�W)	rri�reprr�ascent�descent�
_defaultWidth�
_expandWidths�_explicitWidths)r;r�fontDict�descFonts    rr�zCIDTypeFace._extractDictInfo�s���	\�"�4�(�H��-�.�q�1���/�0��:���� 0�1�)�<���%�d�^���#�1�1�(�3�-�@�����	\��L�t�S�A�B�DH�IY�DZ�[�\�
\�	\�s�	A�+A<c��|dd}i}|rr|d|dd}}t|d�r/|d|dd}}tt|��D]
}|||||z<�n(|d|d|dd}}}t||dz�D]}	|||	<�	|r�r|S)a�Expands Adobe nested list structure to get a dictionary of widths.

        Here is an example of such a structure.::
        
            (
            # starting at character ID 1, next n  characters have the widths given.
            1,  (277,305,500,668,668,906,727,305,445,445,508,668,305,379,305,539),
            # all Characters from ID 17 to 26 are 668 em units wide
            17, 26, 668,
            27, (305, 305, 668, 668, 668, 566, 871, 727, 637, 652, 699, 574, 555,
                 676, 687, 242, 492, 664, 582, 789, 707, 734, 582, 734, 605, 605,
                 641, 668, 727, 945, 609, 609, 574, 445, 668, 445, 668, 668, 590,
                 555, 609, 547, 602, 574, 391, 609, 582, 234, 277, 539, 234, 895,
                 582, 605, 602, 602, 387, 508, 441, 582, 562, 781, 531, 570, 555,
                 449, 246, 449, 668),
            # these must be half width katakana and the like.
            231, 632, 500
            )
        
        NrrKrM)r�range�len)
r;�compactWidthArray�data�widthsr`r rdra�width�idxs
          rr�zCIDTypeFace._expandWidths�s���*!��#������q�'�4���8�4�E��T�!�W�~�"�1�g�t�A�B�x�t��#�C��J�/�;�F�-2�6�]�F�5�6�>�*�;�$(��7�D��G�T�!�"�X�D�U�� ���A��.�(�C�"'�F�3�K�(���
rc�N�|jj||j�Sr@)r��getr�)r;�characterIds  r�getCharWidthzCIDTypeFace.getCharWidths!���#�#�'�'��T�5G�5G�H�HrN)r�r�r�r�r>r�r�r�r�rrr�r��s��'�
$�
A� !�FIrr�c�.�eZdZdZdZd�Zd�Zdd�Zd�Zy)	�CIDFontz%Represents a built-in multi-byte fontrKc�d�|tvsJd|�dt����||_t|�|_|tvsJd|�dt����||_t
|�|_|jdz|j
z|_|j|_	|j
ddk(|_
g|_y)Nz
TypeFace 'z+' not supported! Use any of these instead: z
Encoding 'z,' not supported!  Use any of these instead: �-rI�V)r�faceNamer��facer�encodingNamer,�encoding�fontNamer�
isVertical�substitutionFonts)r;r�r�s   rr>zCIDFont.__init__$s����'�'��hl�n~�)��'���
���%��	��+�+�	I�mu�xH�.I�	I�+�$���#�H�-��
��
�
��+�d�.?�.?�?��
��M�M��	� �,�,�R�0�C�7���"$��rc��t|�}|Sr@r)r;rC�encodeds   r�formatForPdfzCIDFont.formatForPdf9s���D�/���rNc���|jj|�}|jrt|�|zSd}|D] }||jj|�z}�"d|z|zS)zJThis presumes non-Unicode input.  UnicodeCIDFont wraps it for that contextr���MbP?)r�rvr�r�r�r�)r;rC�sizer��cidlist�wrrs       r�stringWidthzCIDFont.stringWidth>sj���-�-�)�)�$�/���?�?��w�<�$�&�&��A��
4����	�	�.�.�s�3�3��
4��1�9�t�#�#rc�h�dtt|j�dz�z}t|jj
}d|z|d<d|jz|d<t|�}|j||�}|jdj}|||<d|z|j|j
<y)z�The explicit code in addMinchoObjects and addGothicObjects
        will be replaced by something that pulls the data from
        _cidfontdata.py in the next few days.�FrK�/�Name�Encoding�
BasicFontsN)r�r��fontMappingrr�rr�r!�	Reference�
idToObjectr)r;�doc�internalName�bigDict�cidObjrGr�s       r�
addObjectszCIDFont.addObjectsLs����T�#�c�o�o�"6�q�"8�9�9���d�i�i�n�n�-����,����!�D�$5�$5�5��
���W�%��
�M�M�&�,�/���>�>�,�/�4�4��!"����%(�<�%7�����	�	�"rr@)	r�r�r�r��
_multiByter>r�r�r�r�rrr�r� s��+��J�$�*�
$�8rr�c�&�eZdZdZdd�Zd�Zdd�Zy)�UnicodeCIDFontu�Wraps up CIDFont to hide explicit encoding choice;
    encodes text for output as UTF16.

    lang should be one of 'jpn',chs','cht','kor' for now.
    if vertical is set, it will select a different widths array
    and possibly glyphs for some punctuation marks.

    halfWidth is only for Japanese.


    >>> dodgy = UnicodeCIDFont('nonexistent')
    Traceback (most recent call last):
    ...
    KeyError: "don't know anything about CID font nonexistent"
    >>> heisei = UnicodeCIDFont('HeiseiMin-W3')
    >>> heisei.name
    'HeiseiMin-W3'
    >>> heisei.language
    'jpn'
    >>> heisei.encoding.name
    'UniJIS-UCS2-H'
    >>> #This is how PDF data gets encoded.
    >>> print(heisei.formatForPdf('hello'))
    \000h\000e\000l\000l\000o
    >>> tokyo = u'東䫬'
    >>> print(heisei.formatForPdf(tokyo))
    gqJ\354
    >>> print(heisei.stringWidth(tokyo,10))
    20.0
    >>> print(heisei.stringWidth('hello world',10))
    45.83
    c�*�	t|\}}||_|dd}|r|dz}|r|dz}n|dz}tj	|||�|x|_|_||_||_t|j
|_
y#t$rtd|z��wxYw)Nz%don't know anything about CID font %srIzHW-r��H)rri�languager�r>rr��vertical�isHalfWidthr	�
unicodeWidths)r;r�r�r��lang�defaultEncoding�encs       rr>zUnicodeCIDFont.__init__�s���	K�$;�D�$A�!�D�/�
��
��c�r�"�����+�C����)�C���)�C�	����t�S�)�%)�(��	�D�M�"��
�&���,�T�Y�Y�7����1�	K��B�T�I�J�J�	K�s�A:�:Bc�v�ddlm}t|�r|jd�}||�d}t	|�}|S)Nr)�utf_16_be_encode�utf8)�codecsr�r�decoder
)r;rCr��utfTextr�s     rr�zUnicodeCIDFont.formatForPdf�s8��+��4�=��;�;�v�&�D�"�4�(��+���G�$���rNc
��t|�r|jd�}|j}|dzt|D�cgc]}|j	|d���c}�zScc}w)z8Just ensure we do width test on characters, not bytes...r�r�i�)rr�r��sumr�)r;rCr�r�r��uchs      rr�zUnicodeCIDFont.stringWidth�sO���4�=��;�;�v�&�D��#�#���e�|�c�D�"I�S�6�:�:�c�4�#8�"I�J�J�J��"Is�A
)FFr@)r�r�r�r�r>r�r�r�rrr�r�`s���B8�>	� Krr�c��ddl}|j|�}|D]\}|jj||jz|zdz�r�2	t|�}|j|�t
d|z��^y#t
dz�Y�rxYw)Nrr0zcannot parse %s, skippingzsaved %s.fastmap)r�listdirrrrr,�printr:)�cmapdirr�files�filer�s     r�precalculater��s���
��B�J�J�w��E��	)��
�7�7�>�>�'�B�F�F�*�T�1�J�>�?��	��d�#�C�	���W��
� �4�'�(�	)��
	��-��3�4��s�A9�9Bc�
�td�}|jdd�|jddd�tjtdd��tjtd	d��|jd
d�d}|jdd
|�|j
�td�d}t|�}t|d|j|��tdd�}td|j|d�z�y)Nztest_japanese.pdf�	Helvetica��di�zJapanese Font SupportzHeiseiMin-W3z90ms-RKSJ-HzHeiseiKakuGo-W5zHeiseiMin-W3-90ms-RKSJ-HrNu'‚±‚ê‚Í•½¬–¾’©‚Å‚·Bi�zsaved test_japanese.pdfz->z
width = %0.2f�
)r
�setFont�
drawStringr�registerFontr��saver�r,rvr�)�c�message1�encNamer�r~s     r�testr��s����"�#�A��I�I�k�2���L�L��S�1�2����G�N�=�A�B����G�$5�m�D�E��I�I�(�"�-�_�H��L�L��c�8�$��F�F�H�	�
#�$��G�
�g�
�C�	�(�D�#�-�-��1�2���}�-�A�	�/�A�M�M�(�B�7�
7�8r�__main__)�cidfonts))�__version__r�rrzr��hashlibr�reportlab.pdfbaser�reportlab.pdfbase._cidfontdatarrrrr	�reportlab.pdfgen.canvasr
r�reportlab.lib.rl_accelr
�reportlab.rl_configrr7rrr6rr!r�r,r�r��Fontr�r�r�r�r��doctestr��testmodr�rr�<module>rs���

��	?��

����(�.�.�*�$�,�.�.���D�
�f�*�%�%�f�P@I�*�%�%�@I�D=8�j�o�o�=8�@WK�W�WK�v
)�!9�d�Z���*��G�O�O�H��r

Zerion Mini Shell 1.0