%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__/textsplit.cpython-312.pyc

�

��d�%��>�dZdZddlmZddlmZddlmZddlm	Z	gd�Z
dje
�Zd	d
gZ
dje
�Zd�Zd�Zdd
�Zd�Zd�ZddlZej*dej,�Zdd�Zedk(rddlZddlmZej:e�yy)aXHelpers for text wrapping, hyphenation, Asian text splitting and kinsoku shori.

How to split a 'big word' depends on the language and the writing system.  This module
works on a Unicode string.  It ought to grow by allowing ore algoriths to be plugged
in based on possible knowledge of the language and desirable 'niceness' of the algorithm.

z3.3.0�)�category��stringWidth)�_FUZZ)�	isUnicode)u&!',.:;?!")]、。」』】〕]】)uK々―ぁぃぅぇぉっゃゅょゎァィゥェォッャュョヮーヵヶu/゛゜・ヽヾゝゞ―‐°′″℃¢%‰�u&‘“([{(〔[{〈《「『【u$£@#¥$£@〒§c��t|�dk\S)zIs this an Asian character?�0)�ord)�chs �9/usr/lib/python3/dist-packages/reportlab/lib/textsplit.py�
is_multi_byter's����G�v���c�B�|D�cgc]}t|||���c}Scc}w)u�Returns a list of glyph widths.

    >>> getCharWidths('Hello', 'Courier', 10)
    [6.0, 6.0, 6.0, 6.0, 6.0]
    >>> from reportlab.pdfbase.cidfonts import UnicodeCIDFont
    >>> from reportlab.pdfbase.pdfmetrics import registerFont
    >>> registerFont(UnicodeCIDFont('HeiseiMin-W3'))
    >>> getCharWidths(u'東京', 'HeiseiMin-W3', 10)   #most kanji are 100 ems
    [10.0, 10.0]
    r)�word�fontName�fontSize�uChars    r
�
getCharWidthsr+s#��AE�E�u�K��x��2�E�E��Es�c���t|�s|j|�}n|}t|||�}t|||�}t|�s0g}|D]'\}	}
|j	|	|
j|�g��)|}|S)aAttempts to break a word which lacks spaces into two parts, the first of which
    fits in the remaining space.  It is allowed to add hyphens or whatever it wishes.

    This is intended as a wrapper for some language- and user-choice-specific splitting
    algorithms.  It should only be called after line breaking on spaces, which covers western
    languages and is highly optimised already.  It works on the 'last unsplit word'.

    Presumably with further study one could write a Unicode splitting algorithm for text
    fragments whick was much faster.

    Courier characters should be 6 points wide.
    >>> wordSplit('HelloWorld', 30, 'Courier', 10)
    [[0.0, 'Hello'], [0.0, 'World']]
    >>> wordSplit('HelloWorld', 31, 'Courier', 10)
    [[1.0, 'Hello'], [1.0, 'World']]
    )r�decoder�	dumbSplit�append�encode)r�	maxWidthsrr�encoding�uword�
charWidths�lines�lines2�
extraSpace�texts           r
�	wordSplitr#:s~��"�T�?����H�%�����u�h��9�J��e�Z��3�E��T�?���"'�	?��Z���M�M�:�t�{�{�8�'<�=�>�	?����Lrc���d}t|ttf�s|g}t|�sJ�g}dx}x}}|d}t	|�}	||	kr�||}
||}||
z
}|dz
}||t
zkDr�|dkDr�||z
}t
|�dkrm||zdz	}
t|dz
|
d�D]R}||}t|�dk(st
|�dk\s�%|dz}||ks�0|dz}|t|||�z
}||}
||}|}n|tvr||dzkDr
|dz}||
z
}|j||||j�g�	|t	|�}|}d}||	kr��|dkDr|j||z
||dg�|S#t$r|d}Y�:wxYw)a�This function attempts to fit as many characters as possible into the available
    space, cutting "like a knife" between characters.  This would do for Chinese.
    It returns a list of (text, extraSpace) items where text is a Unicode string,
    and extraSpace is the points of unused space available on the line.  This is a
    structure which is fairly easy to display, and supports 'backtracking' approaches
    after the fact.

    Test cases assume each character is ten points wide...

    >>> dumbSplit(u'Hello', [10]*5, 60)
    [[10, u'Hello']]
    >>> dumbSplit(u'Hello', [10]*5, 50)
    [[0, u'Hello']]
    >>> dumbSplit(u'Hello', [10]*5, 40)
    [[0, u'Hell'], [30, u'o']]
    uQ
    #>>> dumbSplit(u'Hello', [10]*5, 4)   # less than one character
    #(u'', u'Hello')
    # this says 'Nihongo wa muzukashii desu ne!' (Japanese is difficult isn't it?) in 12 characters
    >>> jtext = u'日本語は難しいですね!'
    >>> dumbSplit(jtext, [10]*11, 30)   #
    (u'日本語', u'は難しいですね!')
    r�r
����ZsN)�
isinstance�list�tupler�lenrr�ranger�sum�ALL_CANNOT_STARTr�strip�
IndexError)r�widthsr�_morer�i�	widthUsed�lineStartPos�maxWidth�nW�w�cr!�
limitCheck�j�cj�ks                 r
rr\s���"
�E��i��e��-�I�;�y��T�?��?��E�#$�$�A�$�	�L���|�H�	�T��B�
�B�$��1�I����G���Q��	�	�Q����x�%�'�'�I�a�K�!�I�-�J��1�v�f�}�+�1�n�q�0�
��q��s�:�b�1�
"�A��a��B���|�T�)�S��W�f�_��a�C���Q�3� !�!��A�&�#�f�Q�q�k�*:�:�J� &�q�	�A� $�Q��A� !�A�!�
"�*�(�(�Q�|�A�~�-=��Q����a��
�
�L�L�*�d�<��&:�&@�&@�&B�C�D�
)�$�S��Z�0���L��I�o�B�$�t�1�}�
���h��*�D���,?�@�A��L���
)�$�R�=��
)�s�*E"�"E3�2E3c��g}t|�t|�k(sJ�d}g}d}	||}||}||z|kr|j|�||z
}n|tdvr	�6)aSplit according to Japanese rules according to CJKV (Lunde).

    Essentially look for "nice splits" so that we don't end a line
    with an open bracket, or start one with a full stop, or stuff like
    that.  There is no attempt to try to split compound words into
    constituent kanji.  It currently uses wrap-down: packs as much
    on a line as possible, then backtracks if needed

    This returns a number of words each of which should just about fit
    on a line.  If you give it a whole paragraph at once, it will
    do all the splits.

    It's possible we might slightly step over the width limit
    if we do hanging punctuation marks in future (e.g. dangle a Japanese
    full stop in the right margin rather than using a whole character
    box.

    gr)r+r�CANNOT_END_LINE)	rr1�
availWidthr�curWidth�curLiner3rr8s	         r
�kinsokuShoriSplitrC�s{��(
�E��t�9��F��#�#�#��H��G�	�A�
�
�!�W���1�I���a�<�*�$��N�N�2����M�H��_�Q�'�'��rNu([⺀-￿])c
��t|fd�tjdt||��j	d��jdd�j
|�S)Nc	��|�gd�t|�|jd�z
dz
t|jdd�d�z|k\xs|dddk(xrd�|��S)N)� �
rrGr%rr&��)r+�rfind�split)�liner�widths   r
�<lambda>zcjkwrap.<locals>.<lambda>�so�����T��4�:�:�d�+;�!;�A�!=��T�Z�Z��Q�/��2�4�"5�8=�">�!.��2�3�i�4�'�-�A�/��4�rz\1\0 rFrHr)�reduce�rx�sub�strrK�replacer)r"rMrs   r
�cjkwraprT�sO���E�����x��T�(�!3�4�:�:�3�?�

��g�d�B����x� 0�1r�__main__)�	textsplit)�utf8)�__doc__�__version__�unicodedatar�reportlab.pdfbase.pdfmetricsr�reportlab.rl_configr�reportlab.lib.utilsr�CANNOT_START_LINE�joinr.r?�ALL_CANNOT_ENDrrr#rrC�re�compile�UNICODErPrT�__name__�doctest�
reportlab.librV�testmod�rr
�<module>ris���
�
�� �4�%�)����8�8�-�.��R�4�	�����/�*���
F� �D\�|"�P
�
�2�:�:�!�2�:�:�.��1��Z���'��G�O�O�I��r

Zerion Mini Shell 1.0