
    ii                     F    S SK r S SKrS SKJr  \" 5       rS rS rS rS rg)    N)
get_loggerc                     U S   nUS   nU S   S   S   nUS   nUS   nUS   n[        US   US   -
  5      nXb-
  nX:  a  [        $ [        $ )a`  Select the function to merge paragraph.

Determine the paragraph merging method based on the positional
relationship between the text bbox and the first line of text in the text bbox.

Args:
    in_region: Elements with text type in the layout result.

Returns:
    Merge the functions of paragraph, convert_text_space_head or convert_text_space_tail.
bboxr   restext_region      )absconvert_text_space_headconvert_text_space_tail)		in_region	text_bboxtext_x1frist_line_boxpoint_1point_2frist_line_x1frist_line_heightx1_distances	            s/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddleocr/ppstructure/recovery/recovery_to_markdown.pycheck_merge_methodr      s     &!IlGu%a(7NQGQGAJMGAJ34)K * 	  %    c                 l   SnSnSn[        U S   5       H  u  pEUS   S   nUS   S   nUS   US   -
  nUS:X  a  XS	   -  nUS   nM4  US   n	U(       a*  [        X)-
  5      U:  a  US
-  nXS	   -  nSnO9XS	   -  nSnO/[        X)-
  5      U:  n
U
(       a
  XS	   -  nSnOUS
-  nXS	   -  nSnU	nM     U$ )zThe function to merge paragraph.

The sign of dividing paragraph is that there are two spaces at the beginning.

Args:
    in_region: Elements with text type in the layout result.

Returns:
    The text content of the current text box.
 NTr   r   r   r   r	   text

F)	enumerater
   )r   r   pre_x
frist_lineir   point1point2hx1same_paraghs              r   r   r   2   s    DEJIe,-]#A&]#A&1Iq	!6KD1IEAY5:"F#!
F#"
ej/A-KF#"
F#!
9 .: Kr   c                     SnSnU S   nUS   US   -
  n[        U S   5       HU  u  pVUS   S   nUS   S   nUS   US   -
  n	US   US   -
  n
XJ-
  nX:  nU(       a  US	-  nXS
   -  nOXS
   -  nU(       + nMW     U$ )zThe function to merge paragraph.

The symbol for dividing paragraph is a space at the end.

Args:
    in_region: Elements with text type in the layout result.

Returns:
    The text content of the current text box.
r   Tr   r   r   r   r   r	   r   r   )r   )r   r   r   r   widthr    r   r!   r"   	row_width
row_heightfull_row_thresholdis_fulls                r   r   r   `   s     DJ&!IaL9Q<'EIe,-]#A&]#A&1Iq	)	AY*
"/1FNDKDKD [
 . Kr   c                 j   S n/ n[        U 5       GH  u  pVUS   (       d  US   R                  5       S:w  a  M)  US   nUS   R                  5       S:X  a2  SR                  US   U5      nUR                  SUS	-   U-    S
35        Mw  US   R                  5       S:X  aN  UR                  SUS   S   S    3SR	                  US   SS  V	s/ s H  n	SU	S   -   PM     sn	5      -   5        M  US   R                  5       S:X  a  UR                  US   S   5        GM  US   R                  5       S:X  d  US   R                  5       S:X  a  GM>  US   R                  5       S:X  a'  SUS   ;   a  UR                  SUS   S    S35        GM|  US   R                  5       S:X  a+  [        U5      n
UR                  U" U
" U5      5      5        GM  SnUS    H  nXS   S-   -  nM     UR                  U5        GM     [        R                  R	                  USR                  U5      5      nSR	                  U5      n[        R                  " SSU5      n[        USSS9 nUR                  U5        SSS5        [        R                  S R                  U5      5        gs  sn	f ! , (       d  f       N8= f)!zSave the recognition result as a markdown file.

Args:
    res: Recognition result
    save_folder: Folder to save the markdown file
    img_name: PDF file or image file name

Returns:
    None
c                 J    / SQnU H  nU R                  USU-   5      n M     U $ )N)*`~$\)replace)contentspecial_charschars      r   replace_special_char3convert_info_markdown.<locals>.replace_special_char   s*    ,!DoodD4K8G "r   r   typefigureimg_idxz	{}_{}.jpgr   z <div align="center">
	<img src="/z	">
</div>titlez# r   r   r   r	   N tablehtmlheaderfooterequationlatexz$$z	{}_ocr.mdr   z\n{3,}wzutf-8)encodingzmarkdown save to {})r   lowerformatappendjoinr   ospathresubopenwriteloggerinfo)r   save_folderimg_namer7   markdown_stringr    regionr;   img_file_name
one_region
merge_funcstringlinemd_pathfs                  r   convert_info_markdownr^      s    Os^	e}!5!5!78!C#&>!X-'..vf~wGM""6x|M7Q6RR\_ F^!!#w.""ve}Q'/03''@Fuab@QR@Q*S:f--@QR F^!!#w.""6%=#89F^!!#x/6&>3G3G3IX3UF^!!#z1g6N""r&-*@)A#FGF^!!#v-+F3J""#7
68J#KLFuv,,, &""6*? $B ggll;(:(:8(DEGkk/2OffY@O	gsW	-	  
.
KK%,,W561 S, 
.	-s   J J$$
J2)	rK   rM   ppocr.utils.loggingr   rQ   r   r   r   r^    r   r   <module>ra      s-    
 	 *	6+\B:7r   