
    ~Zi'                        S r SSKJr  SSKJr  SSKJr  \(       a  SSKJr   " S S\	5      r
 " S S	\5      r " S
 S\5      r " S S\	5      r " S S\5      rS rg)z?Objects related to layout of rendered text, such as TextFitter.    )annotations)TYPE_CHECKING)	ImageFont)Lengthc                      \ rS rSrSrS r\          SS j5       rS rS r	S r
\S 5       r\S	 5       r\S
 5       r\S 5       r\S 5       rS rSrg)
TextFitter   zGValue object that knows how to fit text into given rectangular extents.c                :    Uu  pE[         R                  XXEU45      $ Ntuple__new__)clsline_sourceextents	font_filewidthheights         j/var/www/eduai.edurigo.com/question_generate/ques_gen_env/lib/python3.13/site-packages/pptx/text/layout.pyr   TextFitter.__new__   s    }}Sy"IJJ    c                L    [        U5      nU " XRU5      nUR                  U5      $ )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_sizeTextFitter.best_fit_font_size   s+     "$'+	:..x88r   c                    U R                   n[        R                  [        S[	        U5      S-   5      5      nUR                  U5      $ )zg
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   TextFitter._best_fit_font_size"   s?    
 //	!77aXQRAR8ST~~i((r   c                p    [         R                  U5      nU R                  U5      nUR                  U5      $ )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_lineTextFitter._break_line+   s3     "77D11*=	~~i((r   c                   ^ ^ UU 4S jnU$ )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   > [        U R                  TTR                  5      S   nUTR                  :*  $ )zL
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)   6TextFitter._fits_in_width_predicate.<locals>.predicate<   s/    
  		:tGJB$$r    )r(   r.   r)   s   `` r   r-   #TextFitter._fits_in_width_predicate5   s    	% r   c                   ^  U 4S jnU$ )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                   > TR                  TR                  U 5      n[        SU TR                  5      S   nU[	        U5      -  TR
                  :*  $ )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_sourcer4   r5   len_height)r.   
text_linescyr(   s      r   r)   4TextFitter._fits_inside_predicate.<locals>.predicateN   sL     ))$*;*;ZHJj$//B1EBZ(T\\99r   r:   )r(   r)   s   ` r   r"   !TextFitter._fits_inside_predicateF   s    	: r   c                    U S   $ )N   r:   r(   s    r   r5   TextFitter._font_fileZ       Awr   c                    U S   $ )N   r:   rI   s    r   rB   TextFitter._height^   rK   r   c                    U S   $ Nr   r:   rI   s    r   r@   TextFitter._line_sourceb   rK   r   c                    U S   $ Nr!   r:   rI   s    r   r6   TextFitter._widthf   rK   r   c                    U R                  X5      u  p4U/nU(       a   UR                  U R                  XB5      5        U$ )z
Return a sequence of str values representing the text in
*line_source* wrapped within this fitter when rendered at
*point_size*.
)r0   extendr?   )r(   r   r.   r   	remainderr/   s         r   r?   TextFitter._wrap_linesj   s<     **;CLL)))@Ar   r:   N)
r   strr   ztuple[Length, Length]r   r&   r   rY   returnr&   )__name__
__module____qualname____firstlineno____doc__r   classmethodr   r   r0   r-   propertyr"   r5   rB   r@   r6   r?   __static_attributes__r:   r   r   r   r      s    QK 99!69BE9RU9	9 9))"  &        
r   r   c                  n    \ rS rSrSrS rSS jr\S 5       rS r	SS jr
\S	 5       r\S
 5       rS rSrg)r#   w   zQ
A node in a binary search tree. Uniform for root, subtree root, and leaf
nodes.
c                ,    Xl         S U l        S U l        g r   )_value_lesser_greater)r(   values     r   __init___BinarySearchTree.__init__}   s    r   Nc                    U" U R                   5      (       a  U R                   nU R                  nOU R                  nUc  U$ UR                  X5      $ )zK
Return the largest item in or under this node that satisfies
*predicate*.
)ri   rh   rg   r'   )r(   r)   max_	next_nodes       r   r'   _BinarySearchTree.find_max   sJ    
 TZZ  ::DIIK!!)22r   c                j    [        U5      nU " UR                  5       5      nUR                  U5        U$ )z`
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$   '_BinarySearchTree.from_ordered_sequence   s/     4j#'')n))#.
r   c                    XR                   :  a  SOSn[        X5      nUc  [        X[        U5      5        gUR	                  U5        g)zs
Insert a new node containing *value* into this tree such that its
structure as a binary search tree is preserved.
rg   rh   N)ri   getattrsetattrr#   insert)r(   ri   sidechilds       r   r{   _BinarySearchTree.insert   s?    
 "JJ.yJ#=D 1% 89LLr   c                   U< U R                   R                  < S3nSSU-  -  nU R                  (       a!  X0R                  R                  US-   U5      -  nU R                  (       a!  X0R                  R                  US-   U5      -  nU$ )zY
A string representation of the tree rooted in this node, useful for
debugging purposes.

u   %s└── z    r!   )ri   r   rg   treerh   )r(   levelprefixr   s       r   r   _BinarySearchTree.tree   sq    
 "4::??36E>2<<LL%%eai88D==MM&&uqy&99Dr   c                    U R                   $ )z*
The value object contained in this node.
)rf   rI   s    r   ri   _BinarySearchTree.value   s    
 {{r   c                    [        U 5      S:X  a  / S/ 4$ [        [        U 5      S-  5      nX   nXS-   S nU SU nX#U4$ )zf
Return a (medial_value, greater_values, lesser_values) 3-tuple
obtained by bisecting sequence *seq*.
r   NrM   r!   )rA   r&   )ru   mid_idxmidgreaterlessers        r   _bisect_BinarySearchTree._bisect   sX     s8q=tR<c#hl#lkm$XgV##r   c                    [        U5      S:X  a  gU R                  U5      u  p#nU R                  U5        U R                  U5        U R                  U5        g)z`
Insert the new values contained in *seq* into this tree such that
a balanced tree is produced.
r   N)rA   r   r{   rs   )r(   ru   r   r   r   s        r   rs   /_BinarySearchTree._insert_from_ordered_sequence   sM    
 s8q=#||C0fC**73**62r   )rh   rg   rf   r   )r    )r[   r\   r]   r^   r_   rj   r'   r`   r$   r{   r   ra   ri   staticmethodr   rs   rb   r:   r   r   r#   r#   w   s\    

3 	 	
    $ $
3r   r#   c                  <    \ rS rSrSrS rS rS rS rS r	S r
S	rg
)r      aR  
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                    Xl         g r   _text)r(   r   s     r   rj   _LineSource.__init__   s    
r   c                <    U R                   R                  5       S:g  $ )z
Gives this object boolean behaviors (in Python 3). bool(line_source)
is False if it contains the empty string or whitespace only.
r   r   striprI   s    r   __bool___LineSource.__bool__       
 zz!R''r   c                4    U R                   UR                   :H  $ r   r   r(   others     r   __eq___LineSource.__eq__   s    zzU[[((r   c              #     #    U R                   R                  5       n[        S[        U5      S-   5       HB  nSR	                  USU 5      nSR	                  XS 5      n[        U5      n[        X55      v   MD     g7f)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)r   splitr%   rA   joinr   _Line)r(   wordsidx	line_textremainder_textrW   s         r   __iter___LineSource.__iter__   sm      

  "CJN+Ct-I XXeDk2N#N3I	--	 ,s   A:A<c                <    U R                   R                  5       S:g  $ )z
Gives this object boolean behaviors (in Python 2). bool(line_source)
is False if it contains the empty string or whitespace only.
r   r   rI   s    r   __nonzero___LineSource.__nonzero__   r   r   c                     SU R                   -  $ )Nz<_LineSource('%s')>r   rI   s    r   __repr___LineSource.__repr__  s    $tzz11r   r   N)r[   r\   r]   r^   r_   rj   r   r   r   r   r   rb   r:   r   r   r   r      s%    ().(2r   r   c                  V    \ rS rSrSrS rS rS rS rS r	\
S 5       r\
S	 5       rS
rg)r   i  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                0    [         R                  XU45      $ r   r   )r   r   rW   s      r   r   _Line.__new__  s    }}S"344r   c                X    [        U R                  5      [        UR                  5      :  $ r   rA   r   r   s     r   __gt___Line.__gt__  s    499~EJJ//r   c                .    U R                  U5      (       + $ r   )r   r   s     r   __lt___Line.__lt__  s    ;;u%%%r   c                ,    [        U R                  5      $ r   r   rI   s    r   __len___Line.__len__  s    499~r   c                @    SU R                   < SU R                  < S3$ )N'z' => ')r   rW   rI   s    r   r   _Line.__repr__  s    !%DNN;;r   c                    U S   $ rS   r:   rI   s    r   rW   _Line.remainder  rK   r   c                    U S   $ rP   r:   rI   s    r   r   
_Line.text  rK   r   r:   N)r[   r\   r]   r^   r_   r   r   r   r   r   ra   rW   r   rb   r:   r   r   r   r     sH    50&<    r   r   c                  ,    \ rS rSrSr0 r\S 5       rSrg)_Fontsi$  z*
A memoizing cache for ImageFont objects.
c                    X4U R                   ;  a$  [        R                  " X5      U R                   X4'   U R                   X4   $ r   )fontsr   truetype)r   	font_pathr.   s      r   font_Fonts.font+  s?    "#))31:1C1CI1ZCIIy-.yy)011r   r:   N)	r[   r\   r]   r^   r_   r   r`   r   rb   r:   r   r   r   r   $  s      E2 2r   r   c                    SnSn[         R                  X!5      n UR                  U 5      u  pg[        Xd-  U-  5      n[        Xt-  U-  5      nX4$ ! [         a    UR	                  U 5      u  ppX-
  X-
  pv NJf = f)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   r4   r4   2  s     LK;;y-D9"ll40
 H*\9:IY,|;<J    9#'<<#5 5#lFL)9s   A %A98A9N)r_   
__future__r   typingr   PILr   	pptx.utilr   r   r   objectr#   r   r   r   r4   r:   r   r   <module>r      s_    E "    g gT]3 ]3@+2& +2\E >2V 2!r   