
    kh                     T   d Z ddlmZ ddlZddlmZ ddlmZ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      Z G d d      Zd Zd Zd,dedefdZdefdZd-defdZdefdZdefdZd.ded ed!ed"ed#ef
d$Zd%efd&Zd'ed(ed)efd*Zd/d)efd+Zy)0zCommon methods.    )EnumN)Iterable)getColorListgetColorInfoListc                   (    e Zd ZdZdZdZdZdZdZdZ	y)		BlockTypezBlock types.r               N)
__name__
__module____qualname____doc__	UNDEFINEDTEXTIMAGELATTICE_TABLESTREAM_TABLEFLOAT_IMAGE     Q/var/www/teggl/fontify/venv/lib/python3.12/site-packages/pdf2docx/common/share.pyr   r   	   s#    IDEMLKr   r   c                   (    e Zd ZdZdZdZdZdZdZdZ	y)	RectTypezShape type in context.r
   r   r             N)
r   r   r   r   	HIGHLIGHT	UNDERLINESTRIKE	HYPERLINKBORDERSHADINGr   r   r   r   r      s#     IIFIFGr   r   c                        e Zd ZdZdZdZdZdZy)TextDirectiona)  Text direction.
    * LEFT_RIGHT: from left to right within a line, and lines go from top to bottom
    * BOTTOM_TOP: from bottom to top within a line, and lines go from left to right
    * MIX       : a mixture if LEFT_RIGHT and BOTTOM_TOP
    * IGNORE    : neither LEFT_RIGHT nor BOTTOM_TOP
    r	   r   r
   r   N)r   r   r   r   IGNORE
LEFT_RIGHT
BOTTOM_TOPMIXr   r   r   r'   r'      s     FJJCr   r'   c                   (    e Zd ZdZdZdZdZdZdZdZ	y)	TextAlignmentzText alignment.

    .. note::
        The difference between ``NONE`` and ``UNKNOWN``: 

        * NONE: none of left/right/center align -> need TAB stop
        * UNKNOWN: can't decide, e.g. single line only
    r	   r   r
   r   r   r   N)
r   r   r   r   NONEUNKNOWNLEFTCENTERRIGHTJUSTIFYr   r   r   r-   r-   *   s'     DGDFEGr   r-   c                   P    e Zd ZdZed        Zed        Zed        Zed        Zy)ITextz2Text related interface considering text direction.c                 "    t         j                  S )z0Text direction is from left to right by default.)r'   r)   selfs    r   text_directionzIText.text_direction=   s     '''r   c                 z    | j                   t        j                  k(  xs | j                   t        j                  k(  S )z3Check whether text direction is from left to right.)r9   r'   r)   r+   r7   s    r   is_horizontal_textzIText.is_horizontal_textB   s6     ""m&>&>> 9##}'8'88	9r   c                 <    | j                   t        j                  k(  S )z3Check whether text direction is from bottom to top.)r9   r'   r*   r7   s    r   is_vertical_textzIText.is_vertical_textH   s     ""m&>&>>>r   c                 <    | j                   t        j                  k(  S )zYCheck whether text direction is either from left to 
        right or from bottom to top.)r9   r'   r+   r7   s    r   is_mix_textzIText.is_mix_textM   s     ""m&7&777r   N)	r   r   r   r   propertyr9   r;   r=   r?   r   r   r   r5   r5   ;   sS    <( ( 9 9
 ? ? 8 8r   r5   c                       e Zd ZdZd Zd Zy)lazypropertyz-Calculate only once and cache property value.c                     || _         y N)func)r8   rE   s     r   __init__zlazyproperty.__init__V   s	    	r   c                 r    || S | j                  |      }t        || j                   j                  |       |S rD   )rE   setattrr   )r8   instanceclsvalues       r   __get__zlazyproperty.__get__Y   s6    KIIh'EHdii00%8Lr   N)r   r   r   r   rF   rL   r   r   r   rB   rB   T   s    7r   rB   c                 :    	 t        |        y# t        $ r Y yw xY w)z$Whether can be converted to a float.TF)float
ValueError)
str_numbers    r   	is_numberrQ   e   s(    j   s    	c              #      K   | D ]7  }t        |t              r!t        ||      st        ||      E d{    4| 9 y7 w)z%Yield items from any nested iterable.N)
isinstancer   flatten)itemsklassitems      r   rT   rT   o   s@      dH%ju.EtU+++J	+s   1AA Anumberndigitsc                 .    d|z  }t        || z        |z  S )zPRound number to lower bound with specified digits, e.g. lower_round(1.26, 1)=1.2g      $@)int)rX   rY   ns      r   lower_roundr]   x   s    gAqx=1r   sc                 n    t        d | D              }dD ]  }	 |j                  |      } |S  S #  Y xY w)zTry to decode a unicode string.c              3   2   K   | ]  }t        |        y wrD   )ord).0cs     r   	<genexpr>zdecode.<locals>.<genexpr>   s      c!f s   )zutf-8gbkgb2312z
iso-8859-1)bytesdecode)r^   bencodingress       r   rh   rh   ~   sO     a  A< 	((8$C J J	s   04namec                 &   | rB| j                         t               v r(t               j                  | j                               }n*t        j                  dt        t                     dz
        }t               |   }|d   dz  |d   dz  |d   dz  fS )zaGet a named RGB color (or random color) from fitz predefined colors, e.g. 'red' -> (1.0,0.0,0.0).r   r
   g     o@r   r   )upperr   indexrandomrandintlenr   )rl   posrc   s      r   rgb_component_from_namert      s|     

.n""4::<0nnQLN 3A 563AaD5L!A$,!u55r   srgbc           	          t        |       dd j                  d      }dD cg c]  }t        |||dz    d       c}S c c}w )zsrgb value to R,G,B components, e.g. 16711680 -> (255, 0, 0).

    Equal to PyMuPDF built-in method::

        [int(255*x) for x in fitz.sRGB_to_pdf(x)]
    r   N   )r   r   r   r   )hexzfillr[   )ru   r^   is      r   rgb_componentr{      sC     	D	!"AA'01!C!AaC"111s   >rgbc                 |    d}t        |       D ]"  \  }}|t        |dz        ddd|z  z
  z  z  z  }$ t        |      S )z:RGB components to decimal value, e.g. (1,0,0) -> 16711680.r      r   r   r   )	enumerater[   )r|   rk   rz   xs       r   rgb_to_valuer      sK    
C3 .1s1g;"q1u+--.s8Or   rc   myk
cmyk_scalec                     d| t        |      z  z
  d|t        |      z  z
  z  }d|t        |      z  z
  d|t        |      z  z
  z  }d|t        |      z  z
  d|t        |      z  z
  z  }t        |||g      }|S )zCMYK components to GRB value.      ?)rN   r   )	rc   r   r   r   r   rgri   rk   s	            r   cmyk_to_rgbr      s    	q5$$	$q53D/D)DEA	q5$$	$q53D/D)DEA	q5$$	$q53D/D)DEA
1ay
!CJr   
componentsc                    t        |       }|dk(  r't        t        |       \  }}}}t        ||||d      }|S |dk(  r$t        t        |       \  }}}	t	        |||	g      }|S |dk(  rt        | d         }t	        |||g      }|S d}|S )z-Gray/RGB/CMYK mode components to color value.r   r   )r   r   r
   r   )rr   maprN   r   r   )
r   numrc   r   r   r   colorr   r   ri   s
             r   	rgb_valuer      s    
j/C
Av
+
1aAq!Q37 L 
aeZ(1aaAY' L 
a*Q- a!W% L Lr   widthheighttitlec                 l    | j                  ||      }t        d      }|j                  d||d       |S )zInsert a new page with given title.

    Args:
        doc (fitz.Document): pdf document object.
        width (float): Page width.
        height (float): Page height.
        title (str): Page title shown in page.
    )r   r   gray)   r      )r   fontsize)new_pagert   insert_text)docr   r   r   pager   s         r   r   r      s>     <<eF<3D #6*DWe4"=Kr   c                       fd}|S )a  Plot the returned objects of inner function.

    Args:
        title (str): Page title.
        show (bool, optional): Don't plot if show==False. Default to True.

    .. note::
        Prerequisite of the inner function: 
            - the first argument is a :py:class:`~pdf2docx.page.BasePage` instance.
            - the last argument is configuration parameters in ``dict`` type.
    c                       fd}|S )Nc                  &    | i |}| d   }|j                  dd      }|j                  dd       }|j                  dd       }	rJ|rH|rF|Dt        ||j                  |j                  
      }|j	                  |       |j                  |       |S )Nr   debugF	debug_docdebug_filename)getr   r   r   plotsave)argskwargsobjectsr   r   r   filename
debug_pagerE   showr   s           r   innerz*debug_plot.<locals>.wrapper.<locals>.inner   s    D+F+G 7DJJw.E**[$/Czz"2D9HEco%c4::t{{EJ
Z("Nr   r   )rE   r   r   r   s   ` r   wrapperzdebug_plot.<locals>.wrapper   s    	$ r   r   )r   r   r   s   `` r   
debug_plotr      s    ( Nr   )r   ) )d   )T)r   enumr   rp   collections.abcr   
fitz.utilsr   r   r   r   r'   r-   r5   rB   rQ   rT   rN   r[   r]   strrh   rt   r{   listr   r   r   r   r   r   r   r   <module>r      s       $ 5 t 
D 
D "8 82 "u c 	S 		6 	6	2s 	2T % 5 E U u  0 e 3 & S  r   