
    Og}                       d dl mZ d dlmZmZmZmZmZmZm	Z	m
Z
 d dlmZ d dlmZ d dlmZmZ d dlmZ d dlmZmZ e	rd dlmZ d d	lmZ d
ZdZdZdZdZdZ dZ!dZ"dZ#dZ$ejJ                  Z&dZ'dZ(dZ)dZ*dZ+dZ,dZ- e
dd      Z. G d d      Z/ G d d      Z0 G d d       Z1 G d! d"      Z2 G d# d$      Z3 G d% d&      Z4 G d' d      Z5e5Z6 G d( d)e5      Z7 G d* d+e5      Z8	 d-	 	 	 	 	 	 	 d.d,Z9y)/    )annotations)AnyCallableIterableIteratorOptionalSequenceTYPE_CHECKINGTypeVar)deepcopy)const)MTextEntityAlignmentMAP_MTEXT_ALIGN_TO_FLAGS)MTextSurrogate)UVecVec2)BlockLayout)GenericLayoutTypeTABLEBACKGROUNDTABLECONTENT	TABLEGRIDSTANDARD      ?g      @gffffff?g      ?Ng?   BYLAYERT2   TCell)boundc                  \   e Zd ZdZeedf	 	 	 	 	 ddZddZddZ	 	 d	 	 	 	 	 	 	 	 	 ddZ		 	 	 d	 	 	 	 	 	 	 	 	 ddZ
edd	       Zedd
       ZddZddZddZ	 	 	 d 	 	 	 	 	 	 	 	 	 d!dZd"dZeej*                  dddej,                  f	 	 	 	 	 	 	 	 	 d#d       Zd"dZ	 	 	 	 d$dZd%d&dZy)'TablePaintera  The TablePainter class renders tables build from DXF primitives.

    The TablePainter instance contains all the data cells.

    Args:
        insert: insert location as or :class:`~ezdxf.math.UVec`
        nrows: row count
        ncols: column count
        cell_width: default cell width in drawing units
        cell_height: default cell height in drawing units
        default_grid: draw a grid of solid lines if ``True``, otherwise
            draw only explicit defined borders, the default grid has a
            priority of 50.

    Tc                Z   t        |      | _        || _        || _        |g|z  | _        |g|z  | _        t        | _        t        | _	        t        | _        dt               i| _        |s%| j                  d      }|j                  dddd       i | _        g | _        t%        |       | _        y )NdefaultF)r   insertnrowsncolsrow_heights
col_widthsDEFAULT_TABLE_BG_LAYERbg_layer_nameDEFAULT_TABLE_FG_LAYERfg_layer_nameDEFAULT_TABLE_GRID_LAYERgrid_layer_name	CellStylestylesget_cell_styleset_border_status_cellsframesr   
empty_cell)selfr$   r%   r&   
cell_widthcell_heightdefault_griddefault_styles           ^/var/www/html/public_html/myphp/venv/lib/python3.12/site-packages/ezdxf/addons/tablepainter.py__init__zTablePainter.__init__D   s     6l

)4(=(2|e';"8"8$<-6	,D //	:M++E5%G35#%t*    c                4    t        |      | j                  |<   y)zSet column width in drawing units of the given column index.

        Args:
            index: zero based column index
            value: new column width in drawing units

        N)floatr(   r6   indexvalues      r;   set_col_widthzTablePainter.set_col_width^   s     "'ur=   c                4    t        |      | j                  |<   y)zSet row height in drawing units of the given row index.

        Args:
            index: zero based row index
            value: new row height in drawing units
        N)r?   r'   r@   s      r;   set_row_heightzTablePainter.set_row_heighth   s     #(,r=   c                F    t        | |||      }| j                  |||      S )zFactory method to create a new text cell at location (row, col),
        with `text` as content, the `text` can be a line breaks ``'\n'``.
        The final cell can spread over several cells defined by the argument
        `span`.

        )stylespan)TextCellset_cell)r6   rowcoltextrH   rG   cells          r;   	text_cellzTablePainter.text_cellq   s'     d%d;}}S#t,,r=   Nc                P    |i }t        | ||||      }| j                  |||      S )aA  Factory method to Create a new block cell at position (row, col).

        Content is a block reference inserted by an INSERT entity,
        attributes will be added if the block definition contains ATTDEF.
        Assignments are defined by attribs-key to attdef-tag association.

        Example: attribs = {'num': 1} if an ATTDEF with tag=='num' in
        the block definition exists, an attrib with text=str(1) will be
        created and added to the insert entity.

        The cell spans over 'span' cells and has the cell style with the
        name 'style'.
        )rG   attribsrH   )	BlockCellrJ   )r6   rK   rL   blockdefrH   rQ   rG   rN   s           r;   
block_cellzTablePainter.block_cell   s8    , ?G(%t
 }}S#t,,r=   c                ,    t        | j                        S )zReturns the total table width.)sumr(   r6   s    r;   table_widthzTablePainter.table_width   s     4??##r=   c                ,    t        | j                        S )zReturns the total table height.)rV   r'   rW   s    r;   table_heightzTablePainter.table_height   s     4##$$r=   c                R    | j                  ||      \  }}|| j                  ||f<   |S )z%Insert a cell at position (row, col).)validate_indexr3   r6   rK   rL   rN   s       r;   rJ   zTablePainter.set_cell   s/    &&sC0S $CHr=   c                    | j                  ||      \  }}	 | j                  ||f   S # t        $ r | j                  cY S w xY w)z Get cell at location (row, col).)r\   r3   KeyErrorr5   r6   rK   rL   s      r;   get_cellzTablePainter.get_cell   sI    &&sC0S	#;;sCx(( 	#??"	#s   ( A A c                    t        |      }t        |      }|dk  s#|| j                  k\  s|dk  s|| j                  k\  rt        d      ||fS )Nr   zcell index out of range)intr%   r&   
IndexErrorr`   s      r;   r\   zTablePainter.validate_index   sL    #h#h7cTZZ'37cTZZ6G677Cxr=   c                b    t        | ||f||f|      }| j                  j                  |       |S )zCreates a frame around the give cell area, starting at (row, col) and
        covering `width` columns and `height` rows. The `style` argument is the
        name of a :class:`CellStyle`.
        )posrH   rG   )Framer4   append)r6   rK   rL   widthheightrG   frames          r;   rk   zTablePainter.frame   s3     dc
&%N5!r=   c                    t        |t              r|dk7  sJ d       t        | j                  d            }|j	                  |       || j
                  |<   |S )zFactory method to create a new :class:`CellStyle` object, overwrites
        an already existing cell style.

        Args:
            name: style name as string
            kwargs: see attributes of class :class:`CellStyle`

         z!name has to be a non-empty stringr#   )
isinstancestrr   r1   updater0   )r6   namekwargsrG   s       r;   new_cell_stylezTablePainter.new_cell_style   sX     tS!dbj	/.	/0#D$7$7	$BCV!Dr=   d   r   c                `    t               }| |_        ||_        ||_        ||_        ||_        |S )ao  Factory method to create a new border style.

        Args:
            status: ``True`` for visible, ``False`` for invisible
            color: :ref:`ACI`
            linetype: linetype name, default is "BYLAYER"
            lineweight: lineweight as int, default is by layer
            priority: drawing priority, higher priorities cover lower priorities

        )BorderStylecolorlinetype
lineweightstatuspriority)rw   rz   r{   rx   ry   border_styles         r;   new_border_stylezTablePainter.new_border_style   s9    $ #}" (",$ (r=   c                     | j                   |   S )zGet cell style by name.)r0   )r6   rq   s     r;   r1   zTablePainter.get_cell_style   s    {{4  r=   c                      fd|D        S )zIterate over all visible cellsc              3  N   K   | ]  \  }}||j                  ||      f  y wN)ra   .0rK   rL   r6   s      r;   	<genexpr>z2TablePainter.iter_visible_cells.<locals>.<genexpr>  s,      
4<CS#t}}S#./
s   "% )r6   visibility_maps   ` r;   iter_visible_cellszTablePainter.iter_visible_cells   s    
@N
 	
r=   c                "   | j                   }|t        |      | _         t        |       }t        |       }| j	                  |      D ].  \  }}}|j                  ||||       |j                  ||||       0 |j                  ||       || _         y)zRender table to layout.N)r$   r   VisibilityMapGridr   render_cell_backgroundrender_cell_contentrender_lines)	r6   layoutr$   insert_backupr   gridrK   rL   rN   s	            r;   renderzTablePainter.render  s    v,DK&t,Dz"55nE 	=NCd''S$?$$VS#t<	= 	&.1#r=   )r$   r   r%   rc   r&   rc   )rA   rc   rB   r?   )   r   r#   )
rK   rc   rL   rc   rM   ro   rH   tuple[int, int]returnrI   )r   Nr#   )
rK   rc   rL   rc   rS   r   rH   r   r   rR   )r   r?   )rK   rc   rL   rc   rN   r   r   r   )rK   rc   rL   rc   r   r   )rK   rc   rL   rc   r   r   )r   r   r#   )
rK   rc   rL   rc   ri   rc   rj   rc   r   rg   )rq   ro   r   r/   )
rw   rc   r{   rc   rx   ro   ry   rc   r   rv   )r   r   r   zIterator[tuple[int, int, Cell]]r   )r   r   r$   zOptional[UVec])__name__
__module____qualname____doc__DEFAULT_CELL_WIDTHDEFAULT_CELL_HEIGHTr<   rC   rE   rO   rT   propertyrX   rZ   rJ   ra   r\   rk   rs   staticmethodr   r   LINEWEIGHT_BYLAYERr}   r1   r   r   r   r=   r;   r!   r!   3   s   * &'%% % 	%4./ !'-- - 	-
 - 
-, !'-- - 	-
 - 
-: $ $ % %#   	
  
 " ]]!22  	
  
 2!
+
	(
$r=   r!   c                  N    e Zd ZdZddZd ZddZddZddZddZ	ddZ
dd	Zy
)r   z)Stores the visibility of the table cells.c                P    || _         t               | _        | j                          y)z$Create the visibility map for table.N)tableset_hidden_cells_create_visibility_mapr6   r   s     r;   r<   zVisibilityMap.__init__  s    #(
365##%r=   c                    t        |       D ]>  \  }}| j                  j                  ||      }| j                  |||j                         @ y)z&Set visibility for all existing cells.N)iterr   ra   _set_span_visibilityrH   r]   s       r;   r   z$VisibilityMap._create_visibility_map  sE    T
 	;HC::&&sC0D%%c3		:	;r=   c                    |dk7  r=|\  }}t        |      D ]*  }t        |      D ]  }| j                  ||z   ||z           , | j                  ||       y)zSet the visibility of the given cell.

        The cell itself is visible, all other cells in the span-range
        (tuple: width, height) are invisible, they are covered by the
        main cell (row, col).
        r   N)rangehideshow)r6   rK   rL   rH   r%   r&   rowxcolxs           r;   r   z"VisibilityMap._set_span_visibility"  s`     6>LE5e 6!%L 6DIIcDj#*566
 			#sr=   c                ^    	 | j                   j                  ||f       y# t        $ r Y yw xY w)zShow cell (row, col).N)r   remover_   r`   s      r;   r   zVisibilityMap.show3  s1    	%%sCj1 		s     	,,c                >    | j                   j                  ||f       y)zHide cell (row, col).N)r   addr`   s      r;   r   zVisibilityMap.hide:  s    Sz*r=   c              #     K   t        | j                  j                        D ],  }t        | j                  j                        D ]  }||f 
 . yw)z8Iterate over all cell indices, yields (row, col) tuples.N)r   r   r%   r&   r`   s      r;   iter_all_cellszVisibilityMap.iter_all_cells>  sK     ))* 	CTZZ--. 3h	s   AAc                "    ||f| j                   vS )z0True if cell (row, col)  is visible, else False.)r   r`   s      r;   is_visible_cellzVisibilityMap.is_visible_cellD  s    Sz!3!333r=   c                6      fd j                         D        S )zIterate over all visible cells.c              3  P   K   | ]  \  }}j                  ||      r||f  y wr   )r   r   s      r;   r   z)VisibilityMap.__iter__.<locals>.<genexpr>J  s1      
c##C- #J
s   #&)r   rW   s   `r;   __iter__zVisibilityMap.__iter__H  s    
"113
 	
r=   Nr   r!   )rK   rc   rL   rc   rH   r   )rK   rc   rL   rc   )rK   rc   rL   rc   r   None)r   zIterator[tuple[int, int]])rK   rc   rL   rc   r   bool)r   r   r   r   r<   r   r   r   r   r   r   r   r   r=   r;   r   r     s-    3&;"+4
r=   r   c                  b    e Zd ZdZdddZddZddZddZddZ	 d	 ddZ	e
dd	       Zdd
Zy)r/   zCell style object.

    .. important::

        Always instantiate new styles by the factory method:
        :meth:`TablePainter.new_cell_style`

    Nc                   d| _         t        | _        t        | _        t
        | _        t        | _        t        | _
        d| _        d| _        t        j                  | _        t         | _        t$        | _        t(        | _        t-               | _        t-               | _        t-               | _        t-               | _        |r| j7                  |       y y )Nr           F)
text_styleDEFAULT_CELL_CHAR_HEIGHTchar_heightDEFAULT_CELL_LINE_SPACINGline_spacingDEFAULT_CELL_X_SCALEscale_xDEFAULT_CELL_Y_SCALEscale_yDEFAULT_CELL_TEXTCOLOR
text_colorrotationstackedr   
TOP_CENTERalignDEFAULT_CELL_X_MARGINmargin_xDEFAULT_CELL_Y_MARGINmargin_yDEFAULT_CELL_BG_COLORbg_colorrv   lefttoprightbottomrp   )r6   datas     r;   r<   zCellStyle.__init__[  s    $35++0)44
---M	= ]
!mKK r=   c                     | j                   |   S r   )__dict__)r6   ks     r;   __getitem__zCellStyle.__getitem__  s    }}Qr=   c                t    || j                   v r| j                   j                  ||       y t        d|       )Nzinvalid attribute name: )r   __setitem__r_   )r6   r   vs      r;   r   zCellStyle.__setitem__  s5    MM%%a+5aS9::r=   c                    |j                         D ]  \  }}| j                  ||        t        | j                  t              sJ d       y )NzBenum ezdxf.enums.MTextEntityAlignment for text alignments required)itemsr   rn   r   r   )r6   r   r   r   s       r;   rp   zCellStyle.update  sQ    JJL 	#DAqQ"	#JJ,
 	PO	P 
r=   c                    || j                   _        || j                  _        || j                  _        || j                  _        y)z'Set status of all cell borders at once.N)r   rz   r   r   r   )r6   r   r   r   r   s        r;   r2   zCellStyle.set_border_status  s1    		!

#r=   c                @    d|fd|fd|fd|ffD ]  \  }}|s	|| |<    y)z.Set border styles of all cell borders at once.r   r   r   r   Nr   )r6   rG   r   r   r   r   borderrz   s           r;   set_border_stylezCellStyle.set_border_style  sE    
 TNeCLv	
 	%NFF $V	%r=   c                     t               S r   )rv   r   r=   r;   get_default_border_stylez"CellStyle.get_default_border_style  s
    }r=   c                (    t         | j                     S r   )r   r   rW   s    r;   get_text_align_flagszCellStyle.get_text_align_flags  s    '

33r=   r   )r   zOptional[dict[str, Any]])r   ro   r   r   )r   ro   r   r   )r   zdict[str, Any])TTTT)rG   rv   )r   rv   r   r   )r   r   r   r   r<   r   r   rp   r2   r   r   r   r   r   r=   r;   r/   r/   Q  sO    "H ;P$ KO% %  4r=   r/   c                  F    e Zd ZdZeeeej                  e	f	 	 	 	 	 	 	 ddZ
y)rv   zBorder style class.

    .. important::

        Always instantiate new border styles by the factory method:
        :meth:`TablePainter.new_border_style`

    c                J    || _         || _        || _        || _        || _        y r   )rz   rw   rx   ry   r{   )r6   rz   rw   rx   ry   r{   s         r;   r<   zBorderStyle.__init__  s'     
 $ r=   N)rz   r   rw   rc   rx   ro   r{   rc   )r   r   r   r   DEFAULT_BORDER_STATUSDEFAULT_BORDER_COLORDEFAULT_BORDER_LINETYPEr   r   DEFAULT_BORDER_PRIORITYr<   r   r=   r;   rv   rv     sI     -)/++/!! ! 	! !r=   rv   c                  (   e Zd ZdZddZddZddZddZddZ	 	 	 	 	 	 	 	 ddZ	ddZ
dd	Z	 	 	 	 	 	 	 	 dd
ZddZddZ	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 	 d dZ	 	 	 	 	 	 	 	 d dZd!dZd"dZ	 	 	 	 	 	 	 	 	 	 d#dZ	 	 	 	 	 	 	 	 	 	 d$dZd%dZd&dZy)'r   z8Grid contains the graphical representation of the table.c                    || _         | j                         | _        | j                         | _        g | _        g | _        t        dddd      | _        y )NFi  r   r   )rz   r{   rx   rw   )	r   _calc_col_poscol_pos_calc_row_posrow_pos
_x_borders
_y_bordersrv   	no_borderr   s     r;   r<   zGrid.__init__  sP    #(
$($6$6$8$($6$6$8 .0
 .0$3!
r=   c                    | j                   j                  dz   | j                   j                  dz   z  }|g|z  | _        |g|z  | _        y)z@Init the _hborders with  <hborder> and _vborders with <vborder>.r   N)r   r%   r&   r   r   )r6   x_bordery_borderborder_counts       r;   _init_borderszGrid._init_borders  sH     "ZZ--1djj6F6F6JK#*|3#*|3r=   c                @    || j                   j                  dz   z  |z   S )zCCalculate linear index for border arrays _x_borders and _y_borders.r   )r   r&   r`   s      r;   _border_indexzGrid._border_index  s!    djj&&*+c11r=   c                >    | j                  | j                  |||      S )zYSet <border_style> for the horizontal border element above
        <row>, <col>.
        )_set_border_styler   r6   rK   rL   r|   s       r;   set_x_borderzGrid.set_x_border       %%doosCNNr=   c                >    | j                  | j                  |||      S )zYSet <border_style> for the vertical border element left of
        <row>, <col>.
        )r  r   r  s       r;   set_y_borderzGrid.set_y_border  r  r=   c                p    | j                  ||      }||   }|j                  |j                  k\  r|||<   yy)z1Set <border_style> for <row>, <col> in <borders>.N)r  r{   )r6   bordersrK   rL   r|   border_indexactual_borderstyles          r;   r  zGrid._set_border_style  sF     ))#s3$\2  $6$?$??$0GL! @r=   c                <    | j                  | j                  ||      S )zGet the horizontal border element above <row>, <col>.
        Last grid line (below <nrows>) is the element above of <nrows+1>.
        )_get_borderr   r`   s      r;   get_x_borderzGrid.get_x_border       c::r=   c                <    | j                  | j                  ||      S )zGet the vertical border element left of <row>, <col>.
        Last grid line (right of <ncols>) is the element left of <ncols+1>.
        )r  r   r`   s      r;   get_y_borderzGrid.get_y_border  r  r=   c                ,    || j                  ||         S )z2Get border element at <row>, <col> from <borders>.)r  )r6   r
  rK   rL   s       r;   r  zGrid._get_border  s     t))#s344r=   c                    g }| j                   j                  j                  }t        || j                   j                  |j
                         |S )zBCalculate the x-axis coords of the grid lines between the columns.)r   r$   x
sum_fieldsr(   rh   )r6   r   start_xs      r;   r   zGrid._calc_col_pos  s;    !**,,7DJJ117>>Br=   c                    g }| j                   j                  j                  }t        || j                   j                  |j
                  d       |S )z?Calculate the y-axis coords of the grid lines between the rows.g      )r   r$   yr  r'   rh   )r6   r   start_ys      r;   r   zGrid._calc_row_pos$  s=    !**,,7DJJ22GNNDIr=   c                    | j                   |   }| j                   ||d   z      }| j                  |   }| j                  ||d   z      }||||fS )zGet the coordinates of the cell <row>,<col> as absolute drawing units.

        :return: a tuple (left, right, top, bottom)
        r   r   )r   r   )r6   rK   rL   rH   r   r   r   r   s           r;   cell_coordszGrid.cell_coords+  s[     ll3cDGm,||C S47]+UC''r=   c                    |j                   }|j                  y| j                  |||j                        \  }}}}	|j	                  ||f||	f||f||	ff|j                  | j
                  j                  d       y)z:Render the cell background for (row, col) as SOLID entity.N)rw   layer)points
dxfattribs)rG   r   r  rH   	add_solidr   r*   )
r6   r   rK   rL   rN   rG   r   r   r   r   s
             r;   r   zGrid.render_cell_background8  s     

>>!#'#3#3Cdii#H eS&3K$%vO11 	 	
r=   c                    | j                  |||j                        }|j                  ||| j                  j                         y)z;Render the cell content for <row>,<col> into layout object.N)r  rH   r   r   r,   )r6   r   rK   rL   rN   coordss         r;   r   zGrid.render_cell_contentI  s6    
 !!#sDII6FFDJJ$<$<=r=   c                d   | j                   j                  d      }|j                  }|j                  }| j	                  ||       | j                  | j                   j                         | j                  | j                   j                  |             | j                  || j                          y)z)Render all grid lines into layout object.r#   N)
r   r1   r   r   r   _set_framesr4   _set_bordersr   _render_borders)r6   r   vmr:   r   r   s         r;   r   zGrid.render_linesQ  s     

11)< $$ %%8X.**+$**77;<VTZZ0r=   c                    |D ]h  \  }}}||j                   d   z   }||j                   d   z   }| j                  |||||j                         | j                  ||||| j                         j y)z!Set borders of the visible cells.r   r   N)rH   _set_rect_bordersrG   _set_inner_bordersr   )r6   visible_cellsrK   rL   rN   
bottom_row	right_cols          r;   r&  zGrid._set_borders\  sr    + 	NCdtyy|+Jdiil*I""3
CDJJO##Zi		r=   c                   ||z
  dkD  r8t        ||      D ])  }t        |dz   |      D ]  }| j                  |||        + ||z
  dkD  r9t        ||      D ])  }t        |dz   |      D ]  }| j                  |||        + yy)zdSet `border_style` to the inner borders of the rectangle (top_row,
        bottom_row, ...)
        r   N)r   r  r  )r6   top_rowr-  left_colr.  r|   rL   rK   s           r;   r+  zGrid._set_inner_bordersf  s     !#Xy1 > 1j9 >C%%c3=>> x!#Wj1 > Ay9 >C%%c3=>> $r=   c                0   t        ||      D ]<  }| j                  |||j                         | j                  |||j                         > t        ||      D ]<  }| j	                  |||j
                         | j	                  |||j                         > y)a  Set border `style` to the rectangle (top_row, bottom_row, ...)

        The values describing the grid lines between the cells, see doc-strings
        for methods set_x_border() and set_y_border() and see comments for
        self._x_borders and self._y_borders.
        N)r   r  r   r   r  r   r   )r6   r0  r-  r1  r.  rG   rL   rK   s           r;   r*  zGrid._set_rect_bordersz  s     9- 	=CgsEII6j#u||<	= *- 	;Cc8UZZ8c9ekk:	;r=   c                    |D ]c  }|j                   d   }|j                   d   }||j                  d   z   }||j                  d   z   }| j                  |||||j                         e y)z#Set borders for all defined frames.r   r   N)rf   rH   r*  rG   )r6   r4   rk   r0  r1  r-  r.  s          r;   r%  zGrid._set_frames  sl     	EiilGyy|H 5::a=0J 5::a=0I""Xy%++	r=   c                l     dfd fd} fd}j                    |         |        y)z:Render the grid lines as LINE entities into layout object.c           	         |j                   r8j                  | ||j                  |j                  |j                  d       yy)z*Render the LINE entity into layout object.)r  rw   rx   ry   )startendr   N)rz   add_linerw   rx   ry   )r6  r7  rG   r  r   s      r;   render_linez)Grid._render_borders.<locals>.render_line  sE    ||!&!&$)NN&+&6&6	    	 r=   c            	     4   t        j                  dz         D ]|  } j                  |    }t        j                        D ]S  }j                  |   }j                  |dz      }j                  | |      } t        ||      t        ||      |       U ~ y)zDraw the horizontal grid lines.r   N)r   r%   r   r&   r   r  r   )	rK   r  rL   r   r   rG   r9  r6   r   s	         r;   render_x_bordersz.Grid._render_borders.<locals>.render_x_borders  s    U[[1_- FLL% - FC<<,D LLq1E --c37ET1tE1~uE	FFr=   c            	     4   t        j                  dz         D ]|  } j                  |    }t        j                        D ]S  }j                  |   }j                  |dz      }j                  ||       } t        ||      t        ||      |       U ~ y)zDraw the vertical grid lines.r   N)r   r&   r   r%   r   r  r   )	rL   r  rK   r   r   rG   r9  r6   r   s	         r;   render_y_bordersz.Grid._render_borders.<locals>.render_y_borders  s    U[[1_- FLL% - FC,,s+C!\\#'2F --c37EQd1fouE	FFr=   N)r6  r   r7  r   rG   rv   )r.   )r6   r   r   r;  r=  r  r9  s   ```  @@r;   r'  zGrid._render_borders  s-    		F	F %%r=   Nr   )r   rv   r   rv   )rK   rc   rL   rc   r   rc   )rK   rc   rL   rc   r|   rv   )r
  list[BorderStyle]rK   rc   rL   rc   r|   rv   )rK   rc   rL   rc   r   rv   )r
  r>  rK   rc   rL   rc   r   rv   )r   list[float])rK   rc   rL   rc   rH   r   r   z!tuple[float, float, float, float])r   r   rK   rc   rL   rc   rN   r   )r   r   r(  r   )r,  zIterable[tuple[int, int, Cell]])
r0  rc   r-  rc   r1  rc   r.  rc   r|   rv   )
r0  rc   r-  rc   r1  rc   r.  rc   rG   r/   )r4   zIterable[Frame])r   r   r   r!   )r   r   r   r   r<   r   r  r  r  r  r  r  r  r   r   r  r   r   r   r&  r+  r*  r%  r'  r   r=   r;   r   r     sq   B
.	42OO1"1 1 	1
 "1;;5(5/259<5	5(( ((7(	*(
'
.1
8;
CG
">'>.1>8;>CG>	1>> > 	>
 > ">(;; ; 	;
 ; ;*	'r=   r   c                  <    e Zd ZdZ	 	 	 d	 	 	 	 	 ddZedd       Zy)rg   a0  Represent a rectangle cell area enclosed by borderlines.

    Args:
         table: the assigned data table
         pos: tuple (row, col), border goes left and top of pos
         span: count of cells that Frame covers, border goes right and below of this cells
         style: style name as string
    c                <    || _         || _        || _        || _        y r   )r   rf   rH   	stylename)r6   r   rf   rH   rG   s        r;   r<   zFrame.__init__  s      
	r=   c                L    | j                   j                  | j                        S r   r   r1   rB  rW   s    r;   rG   zFrame.style  s    zz((88r=   N))r   r   r   r#   )r   r!   rf   r   rH   r   r   r/   )r   r   r   r   r<   r   rG   r   r=   r;   rg   rg     sG      & &

 
 	
 9 9r=   rg   c                      e Zd ZdZ	 	 d		 	 	 d
dZedd       Zej                  dd       Zedd       Z	 	 	 	 	 	 ddZ	ddZ
y)r   a  Base class for table cells.

    Args:
        table: assigned data table
        style: style name as string
        span: tuple(spanrows, spancols), count of cells that cell covers

    A cell doesn't know its own position in the data table, because a cell can
    be used multiple times in the same or in different tables, therefore the
    cell itself can not determine if the cell-range reaches beyond the table
    borders.
    c                .    || _         || _        || _        y r   )r   rB  rH   )r6   r   rG   rH   s       r;   r<   zCell.__init__  s     
	r=   c                    | j                   S )zGet/set table span parameters.)_spanrW   s    r;   rH   z	Cell.span  s     zzr=   c                J    t        d|d         t        d|d         f| _        y)z4Ensures that span values are >= 1 in each direction.r   r   N)maxrI  )r6   rB   s     r;   rH   z	Cell.span  s&     !U1X&AuQx(89
r=   c                L    | j                   j                  | j                        S )z*Returns the associated :class:`CellStyle`.rD  rW   s    r;   rG   z
Cell.style  s     zz((88r=   c                     y)z1Renders the cell content into the given `layout`.Nr   )r6   r   r#  r  s       r;   r   zCell.render  s     	r=   c                    | j                   j                  }| j                   j                  }|d   |z   |d   |z
  |d   |z
  |d   |z   fS )zCReduces the cell-coords about the margin_x and the margin_y values.r   r         )rG   r   r   )r6   r#  r   r   s       r;   get_workspace_coordszCell.get_workspace_coords  sZ    ::&&::&&1I 1I 1I 1I 	
 	
r=   Nr#   r   )r   r!   rH   r   r   )rB   r   rE  r   r   r#  Sequence[float]r  ro   )r#  rT  r   rT  )r   r   r   r   r<   r   rH   setterrG   r   rQ  r   r=   r;   r   r     s       &			 		   
[[: : 9 9'1@IL	
r=   c                  H     e Zd ZdZ	 	 d	 	 	 	 	 d fdZ	 	 	 	 	 	 ddZ xZS )rI   a  Implements a cell type containing a multi-line text. Uses the
    :class:`~ezdxf.addons.MTextSurrogate` add-on to render the multi-line
    text, therefore the content of these cells is compatible to DXF R12.

    Args:
        table: assigned data table
        text: multi line text, lines separated by the new line character ``"\n"``
        style: cell style name as string
        span: tuple(rows, cols) area of cells to cover

    c                >    t         t        |   |||       || _        y r   )superrI   r<   rM   )r6   r   rM   rG   rH   	__class__s        r;   r<   zTextCell.__init__)  s     	h&ueT:	r=   c                   t        | j                        sy| j                  |      \  }}}}| j                  }|j	                         \  }	}
| j                  j
                  }| j                  }|j                  r4d}dj                  d | j                  j                  dd      D              }|t        ||z         dz  |f|	   }|t        ||z         dz  |f|
dz
     }t        |||f| j                  j                  | j                  j                  | j                  j                  || j                  j                  |j                  | j                  j                   |
      }|j#                  |       y)	zText cell.

        Args:
            layout: target layout
            coords: tuple of border-coordinates: left, right, top, bottom
            layer: target layer name as string

        Nr   
c              3      K   | ]  }|  y wr   r   )r   chars     r;   r   z"TextCell.render.<locals>.<genexpr>H  s     LtdLs           @r   )r   rG   r   r   width_factorr   rw   r  )lenrM   rQ  rG   r   r   r   joinreplacer?   r   r   r   r   r   r   r   r   )r6   r   r#  r  r   r   r   r   rG   h_alignv_alignrotatedrM   xposyposmtexts                   r;   r   zTextCell.render3  sB    499~#'#<#<V#D eS&

 557**%%yy==G99Ltyy/@/@s/KLMDeD5L)C/7@fsl+c137!D4L00**''

..++++**''
 	Vr=   rR  )r   r!   rM   ro   rH   r   rS  r   r   r   r   r<   r   __classcell__rY  s   @r;   rI   rI     sN    
   & 
 $'$1@$IL$r=   rI   c                  J     e Zd ZdZ	 	 	 d	 	 	 	 	 d fdZ	 	 	 	 	 	 ddZ xZS )rR   a<  Implements a cell type containing a block reference.

    Args:
        table: table object
        blockdef: :class:`ezdxf.layouts.BlockLayout` instance
        attribs: BLOCK attributes as (tag, value) dictionary
        style: cell style name as string
        span: tuple(rows, cols) area of cells to cover

    c                h    |i }t         t        |   |||       |j                  | _        || _        y r   )rX  rR   r<   rq   
block_namerQ   )r6   r   rS   rG   rQ   rH   rY  s         r;   r<   zBlockCell.__init__f  s4     ?Gi'ud;"--r=   c           
     l   | j                  |      \  }}}}| j                  }|j                         \  }	}
|t        ||z         dz  |f|	   }|t        ||z         dz  |f|
dz
     }|j	                  | j
                  ||f| j                  |j                  |j                  |j                  |d       y)zCreate the cell content as INSERT-entity with trailing ATTRIB-Entities.

        Args:
            layout: target layout
            coords: tuple of border-coordinates : left, right, top, bottom
            layer: target layer name as string

        r_  r   )xscaleyscaler   r  )rq   r$   valuesr   N)
rQ  rG   r   r?   add_auto_blockrefro  rQ   r   r   r   )r6   r   r#  r  r   r   r   r   rG   rd  re  rg  rh  s                r;   r   zBlockCell.rendert  s     $(#<#<V#D eS&

 557eD5L)C/7@fsl+c137!D  $<<<----!NN		 	! 
	
r=   )r#   Nr   )r   r!   rS   r   rH   r   rS  rj  rl  s   @r;   rR   rR   Z  sQ    	  &  
'
1@
IL
r=   rR   c                F    | } ||       |D ]  }|||z  z  } ||        y)zAdds step-by-step the fields-values, starting with <start_value>,
    and appends the resulting values to another object with the
    append-method.
    Nr   )start_valuefieldsrh   signpositionelements         r;   r  r    s6     H
8 GdN"xr=   )r   )rv  r?   rw  r?  rh   zCallable[[float], None]rx  r?   ):
__future__r   typingr   r   r   r   r   r	   r
   r   copyr   ezdxf.lldxfr   ezdxf.enumsr   r   ezdxf.addonsr   
ezdxf.mathr   r   ezdxf.layoutsr   ezdxf.eztypesr   r)   r+   r-   DEFAULT_TEXT_STYLEr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r!   r   r/   rv   r   rg   r   
CustomCellrI   rR   r  r   r=   r;   <module>r     sU   #	 	 	   ( !)/* ' &             #    Cv]$ ]$@;
 ;
|W4 W4t! !<x xv9 967
 7
t 
;t ;|4
 4
v 	 $ 	r=   