
    h}                       S SK Jr  S SKJrJrJrJrJrJrJ	r	J
r
  S SKJr  S SKJr  S SKJrJr  S SKJr  S SKJrJr  \	(       a  S SKJr  S S	KJr  S
rSrSrSrSrSr Sr!Sr"Sr#Sr$\RJ                  r&Sr'Sr(Sr)Sr*Sr+Sr,Sr-\
" SSS9r. " S S5      r/ " S S5      r0 " S S 5      r1 " S! S"5      r2 " S# S$5      r3 " S% S&5      r4 " S' S5      r5\5r6 " S( S)\55      r7 " S* S+\55      r8 S-       S.S, jjr9g)/    )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                     \ rS rSrSr\\S4     SS jjrSS jrSS jr	  S         SS jjr
   S         SS	 jjr\SS
 j5       r\SS j5       rSS jrS S jrS!S jr   S"         S#S jjrS$S jr\\R,                  SSS\R.                  4         S%S jj5       rS$S jr    S&S jrS'S(S jjrSrg))TablePainter3   a  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                `   [        U5      U l        X l        X0l        U/U-  U l        U/U-  U l        [        U l        [        U l	        [        U l        S[        5       0U l        U(       d%  U R                  S5      nUR                  SSSS5        0 U l        / U l        [%        U 5      U l        g )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           K/var/www/html/env/lib/python3.13/site-packages/ezdxf/addons/tablepainter.py__init__TablePainter.__init__D   s     6l

)4(=(2|e';"8"8$<-6	,D //	:M++E5%G35#%t*    c                4    [        U5      U R                  U'   g)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)   r7   indexvalues      r<   set_col_widthTablePainter.set_col_width^   s     "'ur?   c                4    [        U5      U R                  U'   g)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)rA   r(   rB   s      r<   set_row_heightTablePainter.set_row_heighth   s     #(,r?   c                :    [        XXTS9nU R                  XU5      $ )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)r7   rowcoltextrL   rK   cells          r<   	text_cellTablePainter.text_cellq   s!     %;}}St,,r?   Nc                F    Uc  0 n[        XXeUS9nU R                  XU5      $ )a  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'.
)rK   attribsrL   )	BlockCellrN   )r7   rO   rP   blockdefrL   rV   rK   rR   s           r<   
block_cellTablePainter.block_cell   s2    , ?G%t
 }}St,,r?   c                ,    [        U R                  5      $ )zReturns the total table width.)sumr)   r7   s    r<   table_widthTablePainter.table_width   s     4??##r?   c                ,    [        U R                  5      $ )zReturns the total table height.)r\   r(   r]   s    r<   table_heightTablePainter.table_height   s     4##$$r?   c                J    U R                  X5      u  pX0R                  X4'   U$ )z%Insert a cell at position (row, col).)validate_indexr4   r7   rO   rP   rR   s       r<   rN   TablePainter.set_cell   s'    &&s0 $CHr?   c                    U R                  X5      u  p U R                  X4   $ ! [         a    U R                  s $ f = f)z Get cell at location (row, col).)rd   r4   KeyErrorr6   r7   rO   rP   s      r<   get_cellTablePainter.get_cell   sC    &&s0	#;;sx(( 	#??"	#s   % >>c                    [        U5      n[        U5      nUS:  d$  XR                  :  d  US:  d  X R                  :  a  [        S5      eX4$ )Nr   zcell index out of range)intr&   r'   
IndexErrorri   s      r<   rd   TablePainter.validate_index   sF    #h#h7cZZ'37cZZ6G677xr?   c                X    [        XU4XC4US9nU R                  R                  U5        U$ )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`.
)posrL   rK   )Framer5   append)r7   rO   rP   widthheightrK   frames          r<   rv   TablePainter.frame   s/     dc
&N5!r?   c                    [        U[        5      (       a  US:w  d   S5       e[        U R                  S5      5      nUR	                  U5        X0R
                  U'   U$ )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   r2   updater1   )r7   namekwargsrK   s       r<   new_cell_styleTablePainter.new_cell_style   sY     tS!!dbj	/.	/0#D$7$7	$BCV!Dr?   d   r   c                V    [        5       nXl        X5l        XEl        Xl        X%l        U$ )a7  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)r   r   r   r   r   border_styles         r<   new_border_styleTablePainter.new_border_style   s/    $ #}" (",$ (r?   c                     U R                   U   $ )zGet cell style by name.)r1   )r7   r}   s     r<   r2   TablePainter.get_cell_style   s    {{4  r?   c                   ^  U 4S jU 5       $ )zIterate over all visible cellsc              3  N   >#    U  H  u  pXTR                  X5      4v   M     g 7fN)rj   .0rO   rP   r7   s      r<   	<genexpr>2TablePainter.iter_visible_cells.<locals>.<genexpr>  s$      
@NHCSt}}S./s   "% )r7   visibility_maps   ` r<   iter_visible_cellsTablePainter.iter_visible_cells   s    
@N
 	
r?   c                   U R                   nUb  [        U5      U l         [        U 5      n[        U 5      nU R	                  U5       H*  u  pgnUR                  XXx5        UR                  XXx5        M,     UR                  X5        X0l         g)zRender table to layout.N)r%   r   VisibilityMapGridr   render_cell_backgroundrender_cell_contentrender_lines)	r7   layoutr%   insert_backupr   gridrO   rP   rR   s	            r<   renderTablePainter.render  s~    v,DK&t,Dz"55nENCd''S?$$V#< F 	&1#r?   )r4   r+   r)   r6   r-   r5   r/   r%   r'   r&   r(   r1   )r%   r   r&   rm   r'   rm   )rC   rm   rD   rA   )   r   r$   )
rO   rm   rP   rm   rQ   r{   rL   tuple[int, int]returnrM   )r   Nr$   )
rO   rm   rP   rm   rX   r   rL   r   r   rW   )r   rA   )rO   rm   rP   rm   rR   r   r   r   )rO   rm   rP   rm   r   r   )rO   rm   rP   rm   r   r   )r   r   r$   )
rO   rm   rP   rm   rt   rm   ru   rm   r   rr   )r}   r{   r   r0   )
r   rm   r   rm   r   r{   r   rm   r   r   )r   r   r   zIterator[tuple[int, int, Cell]]r   )r   r   r%   zOptional[UVec])__name__
__module____qualname____firstlineno____doc__DEFAULT_CELL_WIDTHDEFAULT_CELL_HEIGHTr=   rE   rH   rS   rY   propertyr^   ra   rN   rj   rd   rv   r   staticmethodr   r   LINEWEIGHT_BYLAYERr   r2   r   r   __static_attributes__r   r?   r<   r!   r!   3   s   * &'%% % 	%4./ !'-- - 	-
 - 
-, !'-- - 	-
 - 
-: $ $ % %#   	
  
 " ]]!22  	
  
 2!
+
	(
$ $r?   r!   c                  d    \ rS rSrSrSS jrS rSS jrSS jrSS jr	SS jr
SS	 jrSS
 jrSrg)r   i  z)Stores the visibility of the table cells.c                N    Xl         [        5       U l        U R                  5         g)z$Create the visibility map for table.N)tableset_hidden_cells_create_visibility_mapr7   r   s     r<   r=   VisibilityMap.__init__  s    #(
365##%r?   c                    [        U 5       H<  u  pU R                  R                  X5      nU R                  XUR                  5        M>     g)z&Set visibility for all existing cells.N)iterr   rj   _set_span_visibilityrL   re   s       r<   r   $VisibilityMap._create_visibility_map  s:    T
HC::&&s0D%%c		: #r?   c                    US:w  a>  Uu  pE[        U5       H+  n[        U5       H  nU R                  X-   X'-   5        M     M-     U R                  X5        g)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)r7   rO   rP   rL   r&   r'   rowxcolxs           r<   r   "VisibilityMap._set_span_visibility"  sN     6>LEe!%LDIIcj#*5 ) %
 			#r?   c                ^     U R                   R                  X45        g! [         a     gf = f)zShow cell (row, col).N)r   removerh   ri   s      r<   r   VisibilityMap.show3  s/    	%%sj1 		s    
,,c                <    U R                   R                  X45        g)zHide cell (row, col).N)r   addri   s      r<   r   VisibilityMap.hide:  s    z*r?   c              #     #    [        U R                  R                  5       H.  n[        U R                  R                  5       H  nX4v   M
     M0     g7f)z8Iterate over all cell indices, yields (row, col) tuples.N)r   r   r&   r'   ri   s      r<   iter_all_cellsVisibilityMap.iter_all_cells>  s>     ))*CTZZ--.h / +s   AAc                "    X4U R                   ;  $ )z0True if cell (row, col)  is visible, else False.)r   ri   s      r<   is_visible_cellVisibilityMap.is_visible_cellD  s    z!3!333r?   c                8   ^  U 4S jT R                  5        5       $ )zIterate over all visible cells.c              3  ^   >#    U  H"  u  pTR                  X5      (       d  M  X4v   M$     g 7fr   )r   r   s      r<   r   )VisibilityMap.__iter__.<locals>.<genexpr>J  s,      
3
##C- SJ3s   -
-)r   r]   s   `r<   __iter__VisibilityMap.__iter__H  s    
"113
 	
r?   )r   r   Nr   r!   )rO   rm   rP   rm   rL   r   )rO   rm   rP   rm   )rO   rm   rP   rm   r   None)r   zIterator[tuple[int, int]])rO   rm   rP   rm   r   bool)r   r   r   r   r   r=   r   r   r   r   r   r   r   r   r   r?   r<   r   r     s-    3&;"+4
r?   r   c                  ~    \ rS rSrSrSSS jjrSS jrSS jrSS jrSS jr	 S SS	 jjr
\SS
 j5       rSS jrSrg)r0   iQ  zCell style object.

.. important::

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

Nc                   SU l         [        U l        [        U l        [
        U l        [        U l        [        U l
        SU l        SU l        [        R                  U l        [         U l        [$        U l        [(        U l        [-        5       U l        [-        5       U l        [-        5       U l        [-        5       U l        U(       a  U R7                  U5        g g )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_colorr   lefttoprightbottomr|   )r7   datas     r<   r=   CellStyle.__init__[  s    $35++0)44
---M	= ]
!mKK r?   c                     U R                   U   $ r   )__dict__)r7   ks     r<   __getitem__CellStyle.__getitem__  s    }}Qr?   c                t    XR                   ;   a  U R                   R                  X5        g [        SU 35      e)Nzinvalid attribute name: )r   __setitem__rh   )r7   r   vs      r<   r   CellStyle.__setitem__  s1    MM%%a+5aS9::r?   c                    UR                  5        H  u  p#U R                  X#5        M     [        U R                  [        5      (       d   S5       eg )NzBenum ezdxf.enums.MTextEntityAlignment for text alignments required)itemsr   rz   r   r   )r7   r   r   r   s       r<   r|   CellStyle.update  sM    JJLDAQ" !JJ,
 
 	PO	P 
r?   c                    XR                   l        X R                  l        X0R                  l        X@R                  l        g)z'Set status of all cell borders at once.N)r   r   r   r   r   )r7   r   r   r   r   s        r<   r3   CellStyle.set_border_status  s)    		!

#r?   c                L    SU4SU4SU4SU44 H  u  pgU(       d  M  XU'   M     g)z.Set border styles of all cell borders at once.r   r   r   r   Nr   )r7   rK   r   r   r   r   borderr   s           r<   set_border_styleCellStyle.set_border_style  s>    
 TNeCLv	
NF v$V
r?   c                     [        5       $ r   )r   r   r?   r<   get_default_border_style"CellStyle.get_default_border_style  s
    }r?   c                (    [         U R                     $ r   )r   r   r]   s    r<   get_text_align_flagsCellStyle.get_text_align_flags  s    '

33r?   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   zOptional[dict[str, Any]])r   r{   r   r   )r   r{   r   r   )r   zdict[str, Any])TTTT)rK   r   )r   r   r   r   )r   r   r   r   r   r=   r   r   r|   r3   r  r   r  r  r   r   r?   r<   r0   r0   Q  sO    "H ;P$ KO% %  4r?   r0   c                  R    \ rS rSrSr\\\\R                  \
4       SS jjrSrg)r   i  zBorder style class.

.. important::

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

c                @    Xl         X l        X0l        X@l        XPl        g r   )r   r   r   r   r   )r7   r   r   r   r   r   s         r<   r=   BorderStyle.__init__  s     
 $ r?   )r   r   r   r   r   N)r   r   r   rm   r   r{   r   rm   )r   r   r   r   r   DEFAULT_BORDER_STATUSDEFAULT_BORDER_COLORDEFAULT_BORDER_LINETYPEr   r   DEFAULT_BORDER_PRIORITYr=   r   r   r?   r<   r   r     sN     -)/++/!! ! 	! ! !r?   r   c                  X   \ rS rSrSrSS jrSS jrSS jrSS jrSS jr	        SS jr
SS	 jrSS
 jr        SS jrS S jrS S jr        S!S jr        S"S jr        S"S jrS#S jrS$S jr          S%S jr          S&S jrS'S jrS(S jrSrg))r   i  z8Grid contains the graphical representation of the table.c                    Xl         U R                  5       U l        U R                  5       U l        / U l        / U l        [        SSSSS9U l        g )NFi  r   r   )r   r   r   r   )	r   _calc_col_poscol_pos_calc_row_posrow_pos
_x_borders
_y_bordersr   	no_borderr   s     r<   r=   Grid.__init__  sN    #(
$($6$6$8$($6$6$8 .0
 .0$3!
r?   c                    U R                   R                  S-   U R                   R                  S-   -  nU/U-  U l        U/U-  U l        g)z@Init the _hborders with  <hborder> and _vborders with <vborder>.r   N)r   r&   r'   r  r  )r7   x_bordery_borderborder_counts       r<   _init_bordersGrid._init_borders  sH     "ZZ--1djj6F6F6JK#*|3#*|3r?   c                >    XR                   R                  S-   -  U-   $ )zCCalculate linear index for border arrays _x_borders and _y_borders.r   )r   r'   ri   s      r<   _border_indexGrid._border_index  s    jj&&*+c11r?   c                <    U R                  U R                  XU5      $ )zISet <border_style> for the horizontal border element above
<row>, <col>.
)_set_border_styler  r7   rO   rP   r   s       r<   set_x_borderGrid.set_x_border       %%doosNNr?   c                <    U R                  U R                  XU5      $ )zISet <border_style> for the vertical border element left of
<row>, <col>.
)r,  r  r-  s       r<   set_y_borderGrid.set_y_border  r0  r?   c                l    U R                  X#5      nX   nUR                  UR                  :  a  XAU'   gg)z1Set <border_style> for <row>, <col> in <borders>.N)r)  r   )r7   bordersrO   rP   r   border_indexactual_borderstyles          r<   r,  Grid._set_border_style  s@     ))#3$2  $6$?$??$0L! @r?   c                :    U R                  U R                  X5      $ )zxGet the horizontal border element above <row>, <col>.
Last grid line (below <nrows>) is the element above of <nrows+1>.
)_get_borderr  ri   s      r<   get_x_borderGrid.get_x_border       ::r?   c                :    U R                  U R                  X5      $ )zzGet the vertical border element left of <row>, <col>.
Last grid line (right of <ncols>) is the element left of <ncols+1>.
)r:  r  ri   s      r<   get_y_borderGrid.get_y_border  r=  r?   c                (    XR                  X#5         $ )z2Get border element at <row>, <col> from <borders>.)r)  )r7   r5  rO   rP   s       r<   r:  Grid._get_border  s     ))#344r?   c                    / nU R                   R                  R                  n[        X R                   R                  UR
                  5        U$ )zBCalculate the x-axis coords of the grid lines between the columns.)r   r%   x
sum_fieldsr)   rs   )r7   r  start_xs      r<   r  Grid._calc_col_pos  s9    !**,,7JJ117>>Br?   c                    / nU R                   R                  R                  n[        X R                   R                  UR
                  S5        U$ )z?Calculate the y-axis coords of the grid lines between the rows.g      )r   r%   yrE  r(   rs   )r7   r  start_ys      r<   r  Grid._calc_row_pos$  s;    !**,,7JJ22GNNDIr?   c                    U R                   U   nU R                   XS   -      nU R                  U   nU R                  X#S   -      nXgXE4$ )ztGet the coordinates of the cell <row>,<col> as absolute drawing units.

:return: a tuple (left, right, top, bottom)
r   r   )r  r  )r7   rO   rP   rL   r   r   r   r   s           r<   cell_coordsGrid.cell_coords+  sS     ll3cGm,||C S7]+C''r?   c                    UR                   nUR                  c  gU R                  X#UR                  5      u  pgpUR	                  Xh4Xi4Xx4Xy44UR                  U R
                  R                  S.S9  g)z:Render the cell background for (row, col) as SOLID entity.N)r   layer)points
dxfattribs)rK   r   rM  rL   	add_solidr   r+   )
r7   r   rO   rP   rR   rK   r   r   r   r   s
             r<   r   Grid.render_cell_background8  su     

>>!#'#3#3Cdii#H SK$%O11 	 	
r?   c                    U R                  X#UR                  5      nUR                  XU R                  R                  5        g)z;Render the cell content for <row>,<col> into layout object.N)rM  rL   r   r   r-   )r7   r   rO   rP   rR   coordss         r<   r   Grid.render_cell_contentI  s2    
 !!#DII6FDJJ$<$<=r?   c                `   U R                   R                  S5      nUR                  nUR                  nU R	                  XE5        U R                  U R                   R                  5        U R                  U R                   R                  U5      5        U R                  XR                   5        g)z)Render all grid lines into layout object.r$   N)
r   r2   r   r   r&  _set_framesr5   _set_bordersr   _render_borders)r7   r   vmr;   r#  r$  s         r<   r   Grid.render_linesQ  s     

11)< $$ %%8.**+$**77;<VZZ0r?   c                    U Hb  u  p#nX$R                   S   -   nX4R                   S   -   nU R                  X%X6UR                  5        U R                  X%X6U R                  5        Md     g)z!Set borders of the visible cells.r   r   N)rL   _set_rect_bordersrK   _set_inner_bordersr   )r7   visible_cellsrO   rP   rR   
bottom_row	right_cols          r<   rZ  Grid._set_borders\  s_    +NCdyy|+Jiil*I""3CDJJO##	 ,r?   c                   X!-
  S:  a:  [        X45       H+  n[        US-   U5       H  nU R                  XvU5        M     M-     XC-
  S:  a;  [        X5       H+  n[        US-   U5       H  nU R                  XvU5        M     M-     gg)zTSet `border_style` to the inner borders of the rectangle (top_row,
bottom_row, ...)
r   N)r   r.  r2  )r7   top_rowrb  left_colrc  r   rP   rO   s           r<   r`  Grid._set_inner_bordersf  s     !#X1 1j9C%%c= : 2 !#W1 Ay9C%%c= : 2 $r?   c                ,   [        X45       H;  nU R                  XUR                  5        U R                  X&UR                  5        M=     [        X5       H;  nU R	                  XsUR
                  5        U R	                  XtUR                  5        M=     g)zSet 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   r2  r   r   )r7   rf  rb  rg  rc  rK   rP   rO   s           r<   r_  Grid._set_rect_bordersz  st     -CgEII6ju||< . -CcUZZ8cekk: .r?   c                    U H`  nUR                   S   nUR                   S   nX2R                  S   -   nXBR                  S   -   nU R                  X5XFUR                  5        Mb     g)z#Set borders for all defined frames.r   r   N)rq   rL   r_  rK   )r7   r5   rv   rf  rg  rb  rc  s          r<   rY  Grid._set_frames  s_    EiilGyy|H ::a=0J ::a=0I""X%++ r?   c                t   ^ ^^^^ SUU4S jjmUU U4S jnUU U4S jnTR                   mU" 5         U" 5         g)z:Render the grid lines as LINE entities into layout object.c           	        > UR                   (       a5  TR                  U UTUR                  UR                  UR                  S.S9  gg)z*Render the LINE entity into layout object.)rP  r   r   r   )startendrR  N)r   add_liner   r   r   )ro  rp  rK   rP  r   s      r<   render_line)Grid._render_borders.<locals>.render_line  sE    ||!&!&$)NN&+&6&6	    	 r?   c            	     6  > [        TR                  S-   5       H|  n TR                  U    n[        TR                  5       HQ  nTR                  U   nTR                  US-      nTR                  X5      nT" [        X15      [        XA5      U5        MS     M~     g)zDraw the horizontal grid lines.r   N)r   r&   r  r'   r  r;  r   )	rO   rI  rP   r   r   rK   rr  r7   r   s	         r<   render_x_borders.Grid._render_borders.<locals>.render_x_borders  s    U[[1_-LL% -C<<,D LLq1E --c7ETtE~uE	 . .r?   c            	     6  > [        TR                  S-   5       H|  n TR                  U    n[        TR                  5       HQ  nTR                  U   nTR                  US-      nTR                  X 5      nT" [        X5      [        X5      U5        MS     M~     g)zDraw the vertical grid lines.r   N)r   r'   r  r&   r  r?  r   )	rP   rD  rO   r   r   rK   rr  r7   r   s	         r<   render_y_borders.Grid._render_borders.<locals>.render_y_borders  s    U[[1_-LL% -C,,s+C!\\#'2F --c7EQd1ouE	 . .r?   N)ro  r   rp  r   rK   r   )r/   )r7   r   r   ru  rx  rP  rr  s   ```  @@r<   r[  Grid._render_borders  s2    	 		F	F %%r?   )r  r  r  r   r  r   Nr   )r#  r   r$  r   )rO   rm   rP   rm   r   rm   )rO   rm   rP   rm   r   r   )r5  list[BorderStyle]rO   rm   rP   rm   r   r   )rO   rm   rP   rm   r   r   )r5  r{  rO   rm   rP   rm   r   r   )r   list[float])rO   rm   rP   rm   rL   r   r   z!tuple[float, float, float, float])r   r   rO   rm   rP   rm   rR   r   )r   r   r\  r   )ra  zIterable[tuple[int, int, Cell]])
rf  rm   rb  rm   rg  rm   rc  rm   r   r   )
rf  rm   rb  rm   rg  rm   rc  rm   rK   r0   )r5   zIterable[Frame])r   r   r   r!   )r   r   r   r   r   r=   r&  r)  r.  r2  r,  r;  r?  r:  r  r  rM  r   r   r   rZ  r`  r_  rY  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                  J    \ rS rSrSr   S     SS jjr\S	S j5       rSrg)
rr   i  a  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                4    Xl         X l        X0l        X@l        g r   )r   rq   rL   	stylename)r7   r   rq   rL   rK   s        r<   r=   Frame.__init__  s     
	r?   c                L    U R                   R                  U R                  5      $ r   r   r2   r  r]   s    r<   rK   Frame.style  s    zz((88r?   )rq   rL   r  r   N))r   r   r   r$   )r   r!   rq   r   rL   r   r   r0   )	r   r   r   r   r   r=   r   rK   r   r   r?   r<   rr   rr     sG      & &

 
 	
 9 9r?   rr   c                      \ rS rSrSr  S   SS jjr\SS j5       r\R                  SS j5       r\SS j5       r	      SS jr
SS jrS	rg
)r   i  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                (    Xl         X l        X0l        g r   )r   r  rL   )r7   r   rK   rL   s       r<   r=   Cell.__init__  s     
	r?   c                    U R                   $ )zGet/set table span parameters.)_spanr]   s    r<   rL   	Cell.span  s     zzr?   c                J    [        SUS   5      [        SUS   5      4U l        g)z4Ensures that span values are >= 1 in each direction.r   r   N)maxr  )r7   rD   s     r<   rL   r    s&     !U1X&AuQx(89
r?   c                L    U R                   R                  U R                  5      $ )z*Returns the associated :class:`CellStyle`.r  r]   s    r<   rK   
Cell.style  s     zz((88r?   c                    g)z1Renders the cell content into the given `layout`.Nr   )r7   r   rV  rP  s       r<   r   Cell.render  s     	r?   c                    U R                   R                  nU R                   R                  nUS   U-   US   U-
  US   U-
  US   U-   4$ )zCReduces the cell-coords about the margin_x and the margin_y values.r   r         )rK   r   r   )r7   rV  r   r   s       r<   get_workspace_coordsCell.get_workspace_coords  sZ    ::&&::&&1I 1I 1I 1I 	
 	
r?   )r  rL   r  r   Nr$   r   )r   r!   rL   r   r  )rD   r   r  r   r   rV  Sequence[float]rP  r{   )rV  r  r   r  )r   r   r   r   r   r=   r   rL   setterrK   r   r  r   r   r?   r<   r   r     s       &			 		   
[[: : 9 9'1@IL	
r?   c                  X   ^  \ rS rSrSr  S     SU 4S jjjr      SS jrSrU =r$ )	rM   i  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                :   > [         [        U ]  XU5        X l        g r   )superrM   r=   rQ   )r7   r   rQ   rK   rL   	__class__s        r<   r=   TextCell.__init__)  s     	h&uT:	r?   c                   [        U R                  5      (       d  gU R                  U5      u  pEpgU R                  nUR	                  5       u  pU R                  R
                  nU R                  nUR                  (       a4  SnSR                  S U R                  R                  SS5       5       5      nU[        XE-   5      S-  U4U	   nU[        Xv-   5      S-  U4U
S-
     n[        UX4U R                  R                  U R                  R                  U R                  R                  UU R                  R                  UR                  U R                  R                   US9
nUR#                  U5        g)	zText cell.

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

Nr   
c              3  $   #    U  H  ov   M     g 7fr   r   )r   chars     r<   r   "TextCell.render.<locals>.<genexpr>H  s     L/Ktd/Ks           @r   )r   rK   r   r   width_factorr   r   rP  )lenrQ   r  rK   r  r   r   joinreplacerA   r   r   r   r   r   r   r   r   )r7   r   rV  rP  r   r   r   r   rK   h_alignv_alignrotatedrQ   xposyposmtexts                   r<   r   TextCell.render3  s8    499~~#'#<#<V#D S

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

..++++**''
 	Vr?   )rQ   r  )r   r!   rQ   r{   rL   r   r  	r   r   r   r   r   r=   r   r   __classcell__r  s   @r<   rM   rM     sX    
   & 
  $'$1@$IL$ $r?   rM   c                  Z   ^  \ rS rSrSr   S     SU 4S jjjr      SS jrSrU =r$ )	rW   iZ  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                f   > Uc  0 n[         [        U ]  XU5        UR                  U l        X@l        g r   )r  rW   r=   r}   
block_namerV   )r7   r   rX   rK   rV   rL   r  s         r<   r=   BlockCell.__init__f  s0     ?Gi'd;"--r?   c           
     Z   U R                  U5      u  pEpgU R                  nUR                  5       u  pU[        XE-   5      S-  U4U	   nU[        Xv-   5      S-  U4U
S-
     nUR	                  U R
                  X4U R                  UR                  UR                  UR                  US.S9  g)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   rP  )r}   r%   valuesrR  N)
r  rK   r  rA   add_auto_blockrefr  rV   r   r   r   )r7   r   rV  rP  r   r   r   r   rK   r  r  r  r  s                r<   r   BlockCell.rendert  s     $(#<#<V#D S

 557eDL)C/7@fl+c137!D  <<<----!NN		 	! 
	
r?   )rV   r  )r$   Nr   )r   r!   rX   r   rL   r   r  r  r  s   @r<   rW   rW   Z  s[    	  &   
'
1@
IL
 
r?   rW   c                H    U nU" U5        U H  nXEU-  -  nU" U5        M     g)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fieldsrs   signpositionelements         r<   rE  rE    s/     H
8dN"x r?   )r   )r  rA   r  r|  rs   zCallable[[float], None]r  rA   ):
__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   r0   r   r   rr   r   
CustomCellrM   rW   rE  r   r?   r<   <module>r     sU   #	 	 	   ( !)/* ' &             #    Cv]$ ]$@;
 ;
|W4 W4t! !<x xv9 967
 7
t 
;t ;|4
 4
v 	 $ 	r?   