
    ,h~'                         d Z ddlmZ  G d de      Z G d de      Z G d de      Z G d	 d
e      Z G d de      Z	d Z
y)z?Objects related to layout of rendered text, such as TextFitter.    )	ImageFontc                       e Zd ZdZd Zed        Zd Zd Zd Z	e
d        Ze
d        Ze
d	        Ze
d
        Ze
d        Zd Zy)
TextFitterzQ
    Value object that knows how to fit text into given rectangular extents.
    c                 @    |\  }}t         j                  | ||||f      S Ntuple__new__)clsline_sourceextents	font_filewidthheights         R/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/pptx/text/layout.pyr
   zTextFitter.__new__   s%    v}}S;vy"IJJ    c                 N    t        |      } | |||      }|j                  |      S )a+  Return whole-number best fit point size less than or equal to `max_size`.

        The return value is the largest whole-number point size less than or equal to
        `max_size` that allows `text` to fit completely within `extents` when rendered
        using font defined in `font_file`.
        )_LineSource_best_fit_font_size)r   textr   max_sizer   r   text_fitters          r   best_fit_font_sizezTextFitter.best_fit_font_size   s-     "$'+w	:..x88r   c                     | j                   }t        j                  t        dt	        |      dz               }|j                  |      S )z
        Return the largest whole-number point size less than or equal to
        *max_size* that this fitter can fit.
           )_fits_inside_predicate_BinarySearchTreefrom_ordered_sequencerangeintfind_max)selfr   	predicatesizess       r   r   zTextFitter._best_fit_font_size   s?    
 //	!77aXQRAR8ST~~i((r   c                 p    t         j                  |      }| j                  |      }|j                  |      S )z
        Return a (line, remainder) pair where *line* is the longest line in
        *line_source* that will fit in this fitter's width and *remainder* is
        a |_LineSource| object containing the text following the break point.
        )r   r   _fits_in_width_predicater!   )r"   r   
point_sizelinesr#   s        r   _break_linezTextFitter._break_line&   s3     "77D11*=	~~i((r   c                       fd}|S )z
        Return a function taking a text string value and returns |True| if
        that text fits in this fitter when rendered at *point_size*. Used as
        predicate for _break_line()
        c                 j    t        | j                  j                        d   }|j                  k  S )zp
            Return |True| if *line* fits in this fitter when rendered at
            *point_size*.
            r   )_rendered_sizer   
_font_file_width)linecxr'   r"   s     r   r#   z6TextFitter._fits_in_width_predicate.<locals>.predicate7   s/    
  		:tGJB$$r    )r"   r'   r#   s   `` r   r&   z#TextFitter._fits_in_width_predicate0   s    	% r   c                       fd}|S )zReturn  function taking an integer point size argument.

        The function returns |True| if the text in this fitter can be wrapped to fit
        entirely within its extents when rendered at that point size.
        c                     j                  j                  |       }t        d| j                        d   }|t	        |      z  j
                  k  S )zReturn |True| when text in `line_source` can be wrapped to fit.

            Fit means text can be broken into lines that fit entirely within `extents`
            when rendered at `point_size` using the font defined in `font_file`.
            Tyr   )_wrap_lines_line_sourcer,   r-   len_height)r'   
text_linescyr"   s      r   r#   z4TextFitter._fits_inside_predicate.<locals>.predicateI   sL     ))$*;*;ZHJj$//B1EBZ(T\\99r   r1   )r"   r#   s   ` r   r   z!TextFitter._fits_inside_predicateA   s    	: r   c                     | d   S )N   r1   r"   s    r   r-   zTextFitter._font_fileU       Awr   c                     | d   S )N   r1   r=   s    r   r8   zTextFitter._heightY   r>   r   c                     | d   S Nr   r1   r=   s    r   r6   zTextFitter._line_source]   r>   r   c                     | d   S Nr   r1   r=   s    r   r.   zTextFitter._widtha   r>   r   c                 |    | j                  ||      \  }}|g}|r!|j                  | j                  ||             |S )z
        Return a sequence of str values representing the text in
        *line_source* wrapped within this fitter when rendered at
        *point_size*.
        )r)   extendr5   )r"   r   r'   r   	remainderr(   s         r   r5   zTextFitter._wrap_linese   sB     **;
CiLL)))Z@Ar   N)__name__
__module____qualname____doc__r
   classmethodr   r   r)   r&   propertyr   r-   r8   r6   r.   r5   r1   r   r   r   r      s    K 	9 	9))"  &        
r   r   c                   b    e Zd ZdZd ZddZed        Zd ZddZ	e
d        Zed	        Zd
 Zy)r   z]
    A node in a binary search tree. Uniform for root, subtree root, and leaf
    nodes.
    c                 .    || _         d | _        d | _        y r   )_value_lesser_greater)r"   values     r   __init__z_BinarySearchTree.__init__x   s    r   Nc                      || j                         r| j                   }| j                  }n| j                  }||S |j                  ||      S )zc
        Return the largest item in or under this node that satisfies
        *predicate*.
        )rS   rR   rQ   r!   )r"   r#   max_	next_nodes       r   r!   z_BinarySearchTree.find_max}   sI    
 TZZ ::DIIK!!)T22r   c                 j    t        |      } | |j                               }|j                  |       |S )zx
        Return the root of a balanced binary search tree populated with the
        values in iterable *iseq*.
        )listpop_insert_from_ordered_sequence)r   iseqseqbsts       r   r   z'_BinarySearchTree.from_ordered_sequence   s/     4j#'')n))#.
r   c                     || j                   k  rdnd}t        | |      }|t        | |t        |             y|j	                  |       y)z
        Insert a new node containing *value* into this tree such that its
        structure as a binary search tree is preserved.
        rQ   rR   N)rS   getattrsetattrr   insert)r"   rS   sidechilds       r   rb   z_BinarySearchTree.insert   sE    
 "DJJ.yJd#=D$ 1% 89LLr   c                    || j                   j                  d}dd|z  z  }| j                  r"|| j                  j                  |dz   |      z  }| j                  r"|| j                  j                  |dz   |      z  }|S )zq
        A string representation of the tree rooted in this node, useful for
        debugging purposes.
        
u   %s└── z    r   )rS   r   rQ   treerR   )r"   levelprefixr   s       r   rg   z_BinarySearchTree.tree   su    
 "4::??36E>2<<DLL%%eai88D==DMM&&uqy&99Dr   c                     | j                   S )z:
        The value object contained in this node.
        )rP   r=   s    r   rS   z_BinarySearchTree.value   s    
 {{r   c                     t        |       dk(  rg dg fS t        t        |       dz        }| |   }| |dz   d }| d| }|||fS )z~
        Return a (medial_value, greater_values, lesser_values) 3-tuple
        obtained by bisecting sequence *seq*.
        r   Nr@   r   )r7   r    )r]   mid_idxmidgreaterlessers        r   _bisectz_BinarySearchTree._bisect   s^     s8q=tR<c#hl#'lgkm$XgGV##r   c                     t        |      dk(  ry| j                  |      \  }}}| j                  |       | j                  |       | j                  |       y)zx
        Insert the new values contained in *seq* into this tree such that
        a balanced tree is produced.
        r   N)r7   rp   rb   r[   )r"   r]   rm   rn   ro   s        r   r[   z/_BinarySearchTree._insert_from_ordered_sequence   sO    
 s8q=#||C0WfC**73**62r   r   )r    )rH   rI   rJ   rK   rT   r!   rL   r   rb   rg   rM   rS   staticmethodrp   r[   r1   r   r   r   r   r   s\    

3 	 	
    $ $
3r   r   c                   4    e Zd ZdZd Zd Zd Zd Zd Zd Z	y)	r   aj  
    Generates all the possible even-word line breaks in a string of text,
    each in the form of a (line, remainder) 2-tuple where *line* contains the
    text before the break and *remainder* the text after as a |_LineSource|
    object. Its boolean value is |True| when it contains text, |False| when
    its text is the empty string or whitespace only.
    c                     || _         y r   _text)r"   r   s     r   rT   z_LineSource.__init__   s	    
r   c                 <    | j                   j                         dk7  S )z
        Gives this object boolean behaviors (in Python 3). bool(line_source)
        is False if it contains the empty string or whitespace only.
        rr   rw   stripr=   s    r   __bool__z_LineSource.__bool__       
 zz!R''r   c                 4    | j                   |j                   k(  S r   rv   r"   others     r   __eq__z_LineSource.__eq__   s    zzU[[((r   c              #      K   | j                   j                         }t        dt        |      dz         D ]C  }dj	                  |d|       }dj	                  ||d       }t        |      }t        ||       E yw)z
        Generate a (text, remainder) pair for each possible even-word line
        break in this line source, where *text* is a str value and remainder
        is a |_LineSource| value.
        r    N)rw   splitr   r7   joinr   _Line)r"   wordsidx	line_textremainder_textrG   s         r   __iter__z_LineSource.__iter__   sw      

  "CJN+ 	.Ct-I XXeCDk2N#N3I	9--		.s   A:A<c                 <    | j                   j                         dk7  S )z
        Gives this object boolean behaviors (in Python 2). bool(line_source)
        is False if it contains the empty string or whitespace only.
        rr   ry   r=   s    r   __nonzero__z_LineSource.__nonzero__   r|   r   c                      d| j                   z  S )Nz<_LineSource('%s')>rv   r=   s    r   __repr__z_LineSource.__repr__   s    $tzz11r   N)
rH   rI   rJ   rK   rT   r{   r   r   r   r   r1   r   r   r   r      s%    ().(2r   r   c                   N    e Zd ZdZd Zd Zd Zd Zd Ze	d        Z
e	d        Zy	)
r   z
    A candidate line broken at an even word boundary from a string of text,
    and a |_LineSource| value containing the text that remains after the line
    is broken at this spot.
    c                 2    t         j                  | ||f      S r   r   )r   r   rG   s      r   r
   z_Line.__new__  s    }}S4"344r   c                 X    t        | j                        t        |j                        kD  S r   r7   r   r~   s     r   __gt__z_Line.__gt__
  s    499~EJJ//r   c                 &    | j                  |       S r   )r   r~   s     r   __lt__z_Line.__lt__  s    ;;u%%%r   c                 ,    t        | j                        S r   r   r=   s    r   __len__z_Line.__len__  s    499~r   c                 <    d| j                   d| j                  dS )N'z' => ')r   rG   r=   s    r   r   z_Line.__repr__  s    !%DNN;;r   c                     | d   S rD   r1   r=   s    r   rG   z_Line.remainder  r>   r   c                     | d   S rB   r1   r=   s    r   r   z
_Line.text  r>   r   N)rH   rI   rJ   rK   r
   r   r   r   r   rM   rG   r   r1   r   r   r   r      sH    50&<    r   r   c                   $    e Zd ZdZi Zed        Zy)_Fontsz2
    A memoizing cache for ImageFont objects.
    c                     ||f| j                   vr%t        j                  ||      | j                   ||f<   | j                   ||f   S r   )fontsr   truetype)r   	font_pathr'   s      r   fontz_Fonts.font&  sL    z"#))31:1C1C:2CIIy*-. yy)Z011r   N)rH   rI   rJ   rK   r   rL   r   r1   r   r   r   r     s      E2 2r   r   c                 
   d}d}t         j                  ||      }	 |j                  |       \  }}t        ||z  |z        }t        ||z  |z        }||fS # t        $ r# |j	                  |       \  }}	}
}|
|z
  ||	z
  }}Y Qw xY w)z
    Return a (width, height) pair representing the size of *text* in English
    Metric Units (EMU) when rendered at *point_size* in the font defined in
    *font_file*.
    i g      R@)r   r   getsizeAttributeErrorgetbboxr    )r   r'   r   emu_per_inchpx_per_inchr   px_width	px_heightlefttoprightbottom	emu_width
emu_heights                 r   r,   r,   /  s     LK;;y*-D9"ll40)
 H{*\9:IY,|;<Jj    9#'<<#5 c5&#dlFSL)9s   A )BBN)rK   PILr   r	   r   objectr   r   r   r   r,   r1   r   r   <module>r      sV    F g gT]3 ]3@+2& +2\E >2V 2 !r   