
    j1l                    :   d Z ddlmZ ddlmZmZmZ ddlmZ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mZmZmZ dd	lmZmZmZmZmZmZmZ dd
lm Z m!Z! erddl"m#Z# ddl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e          Z) G d de          Z* G d de          Z+ G d de          Z, G d de          Z- G d d e          Z. G d! d"e          Z/ G d# d$e          Z0 G d% d&e          Z1d'S )(z"Custom element classes for tables.    )annotations)TYPE_CHECKINGCallableList)WD_CELL_VERTICAL_ALIGNMENTWD_ROW_HEIGHT_RULE)InvalidSpanError)nsdeclsqn)	parse_xml)ST_MergeST_TblLayoutTypeST_TblWidthST_TwipsMeasureXsdInt)BaseOxmlElementOneAndOnlyOne	OneOrMoreOptionalAttributeRequiredAttribute
ZeroOrMore	ZeroOrOne)EmuTwips)CT_P)Lengthc                  B    e Zd ZdZ ede          Z ede          ZdS )	CT_HeightzFUsed for ``<w:trHeight>`` to specify a row height and row height rule.w:valzw:hRuleN)	__name__
__module____qualname____doc__r   r   valr   hRule     Y/lsinfo/ai/hellotax_ai/base_platform/venv/lib/python3.11/site-packages/docx/oxml/table.pyr   r   "   s9        PP

G_
5
5Ci);<<EEEr'   r   c                      e Zd ZdZ ed          Z ed          Z ed          Zd Z	e
d             Ze
d             Zej        d             Ze
d	             Zej        d
             Zd Zd Zd ZdS )CT_Rowz``<w:tr>`` element.z	w:tblPrExzw:trPrzw:tcc                    d}| j         D ].}||k    r|c S ||j        z  }||k    rt          d|z            /t          d          )zThe ``<w:tc>`` element appearing at grid column `idx`.

        Raises |ValueError| if no ``w:tc`` element begins at that grid column.
        r   zno cell on grid column %dzindex out of bounds)tc_lst	grid_span
ValueError)selfidxgrid_coltcs       r(   tc_at_grid_colzCT_Row.tc_at_grid_col0   sk    
 + 	D 	DB3			$H#~~ !<s!BCCC .///r'   c                Z    |                                  j                            |           S )zSThe index of this ``<w:tr>`` element within its parent ``<w:tbl>``
        element.)	getparenttr_lstindexr/   s    r(   tr_idxzCT_Row.tr_idx>   s%     ~~&,,T222r'   c                &    | j         }|dS |j        S )zJReturn the value of `w:trPr/w:trHeight@w:hRule`, or |None| if not present.N)trPrtrHeight_hRuler/   r;   s     r(   r<   zCT_Row.trHeight_hRuleD   s     y<4""r'   c                <    |                                  }||_        d S N)get_or_add_trPrr<   r/   valuer;   s      r(   r<   zCT_Row.trHeight_hRuleL   s!    ##%%#r'   c                &    | j         }|dS |j        S )zHReturn the value of `w:trPr/w:trHeight@w:val`, or |None| if not present.N)r;   trHeight_valr=   s     r(   rD   zCT_Row.trHeight_valQ   s     y<4  r'   c                <    |                                  }||_        d S r?   )r@   rD   rA   s      r(   rD   zCT_Row.trHeight_valY   s!    ##%%!r'   c                2    |                      d|           d S Nr   insert)r/   tblPrExs     r(   _insert_tblPrExzCT_Row._insert_tblPrEx^   s    Awr'   c                r    | j         }||                    |           d S |                     d|           d S rG   )rJ   addnextrI   )r/   r;   rJ   s      r(   _insert_trPrzCT_Row._insert_trPra   sA    ,OOD!!!!!KK4     r'   c                4    t                                           S r?   )CT_Tcnewr8   s    r(   _new_tczCT_Row._new_tch   s    yy{{r'   N)r    r!   r"   r#   r   rJ   r;   r   r2   r3   propertyr9   r<   setterrD   rK   rN   rR   r&   r'   r(   r*   r*   )   s       i$$G9XD	F		B0 0 0 3 3 X3
 # # X# $ $ $ ! ! X! " " "     ! ! !    r'   r*   c                  N   e Zd ZdZ ed          Z ed          Z ed          Ze	d             Z
e
j        d             Z
e	d             Zd Zedd            Ze	d             Zej        d             Zedd            Zed             Zed             Zed             ZdS )CT_Tblz``<w:tbl>`` element.zw:tblPrz	w:tblGridzw:trc                0    | j         j        }|dS |j        S )zValue of `w:tblPr/w:bidiVisual/@w:val` or |None| if not present.

        Controls whether table cells are displayed right-to-left or left-to-right.
        N)tblPr
bidiVisualr$   )r/   rY   s     r(   bidiVisual_valzCT_Tbl.bidiVisual_vals   s!     Z*
4~r'   c                v    | j         }||                                 d S ||                                _        d S r?   )rX   _remove_bidiVisualget_or_add_bidiVisualr$   )r/   rB   rX   s      r(   rZ   zCT_Tbl.bidiVisual_val~   s@    
=$$&&&&&05E''))---r'   c                4    t          | j        j                  S )z)The number of grid columns in this table.)lentblGridgridCol_lstr8   s    r(   	col_countzCT_Tbl.col_count   s     4<+,,,r'   c              #  :   K   | j         D ]}|j        D ]}|V  dS )zGenerate each of the `w:tc` elements in this table, left to right and top to
        bottom.

        Each cell in the first row is generated, followed by each cell in the second
        row, etc.
        N)r6   r,   )r/   trr2   s      r(   iter_tcszCT_Tbl.iter_tcs   sD       + 	 	Bi  	 	r'   rowsintcolswidthr   returnc                J    t          |                     |||                    S )zReturn a new `w:tbl` element having `rows` rows and `cols` columns.

        `width` is distributed evenly between the columns.
        )r   _tbl_xml)clsrf   rh   ri   s       r(   new_tblzCT_Tbl.new_tbl   s"     dD%88999r'   c                0    | j         j        }|dS |j        S )zYValue of `w:tblPr/w:tblStyle/@w:val` (a table style id) or |None| if not
        present.N)rX   tblStyler$   r/   rp   s     r(   tblStyle_valzCT_Tbl.tblStyle_val   s!     :&4|r'   c                v    | j         }|                                 |dS ||                                _        dS )zSet the value of `w:tblPr/w:tblStyle/@w:val` (a table style id) to `styleId`.

        If `styleId` is None, remove the `w:tblStyle` element.
        N)rX   _remove_tblStyle_add_tblStyler$   )r/   styleIdrX   s      r(   rr   zCT_Tbl.tblStyle_val   sA     
   ?F$+!!!r'   strc           	         |dk    rt          ||z            nt          d          }dt          d          d|                     ||          |                     |||          dS )Nr   z<w:tbl wz>
  <w:tblPr>
    <w:tblW w:type="auto" w:w="0"/>
    <w:tblLook w:firstColumn="1" w:firstRow="1"
               w:lastColumn="0" w:lastRow="0" w:noHBand="0"
               w:noVBand="1" w:val="04A0"/>
  </w:tblPr>
z	</w:tbl>
)r   r
   _tblGrid_xml_trs_xml)rm   rf   rh   ri   	col_widths        r(   rl   zCT_Tbl._tbl_xml   sp    )-C%%%s1vv		 CLLLLT9---LLtY////
 	
r'   c                R    d}t          |          D ]}|d|j        z  z  }|dz  }|S )Nz  <w:tblGrid>
z    <w:gridCol w:w="%d"/>
z  </w:tblGrid>
rangetwipsrm   rb   r|   xmlis        r(   rz   zCT_Tbl._tblGrid_xml   sD    y!! 	C 	CA09?BBCC!!
r'   c                f    d}t          |          D ]}|d|                     ||          z  z  }|S )N z  <w:tr>
%s  </w:tr>
)r   _tcs_xml)rm   	row_countrb   r|   r   r   s         r(   r{   zCT_Tbl._trs_xml   sN    y!! 	 	A3s||98 8  CC 
r'   c                H    d}t          |          D ]}|d|j        z  z  }|S )Nr   zj    <w:tc>
      <w:tcPr>
        <w:tcW w:type="dxa" w:w="%d"/>
      </w:tcPr>
      <w:p/>
    </w:tc>
r~   r   s        r(   r   zCT_Tbl._tcs_xml   sB    y!! 	  	 A     CC 
r'   N)rf   rg   rh   rg   ri   r   rj   rV   )rf   rg   rh   rg   ri   r   rj   rw   )r    r!   r"   r#   r   rX   r`   r   rd   rS   rZ   rT   rb   re   classmethodrn   rr   rl   rz   r{   r   r&   r'   r(   rV   rV   l   st       M)$$EmK((G	F		B  X 6 6 6 - - X-	 	 	 : : : [:   X 	, 	, 	, 
 
 
 [
&   [   [   [  r'   rV   c                  ,    e Zd ZdZ edd          ZdS )
CT_TblGridzw``<w:tblGrid>`` element, child of ``<w:tbl>``, holds ``<w:gridCol>`` elements
    that define column count, width, etc.z	w:gridCol)zw:tblGridChange
successorsN)r    r!   r"   r#   r   gridColr&   r'   r(   r   r      s/        - - j1EFFFGGGr'   r   c                  @    e Zd ZdZ ede          Zed             ZdS )CT_TblGridColzJ``<w:gridCol>`` element, child of ``<w:tblGrid>``, defines a table column.w:wc                Z    |                                  j                            |           S )z\The index of this ``<w:gridCol>`` element within its parent ``<w:tblGrid>``
        element.)r5   ra   r7   r8   s    r(   gridCol_idxzCT_TblGridCol.gridCol_idx   s%     ~~+11$777r'   N)	r    r!   r"   r#   r   r   ry   rS   r   r&   r'   r(   r   r      sE        TT%11A8 8 X8 8 8r'   r   c                  *    e Zd ZdZ ede          ZdS )CT_TblLayoutTypez|``<w:tblLayout>`` element, specifying whether column widths are fixed or can be
    automatically adjusted based on content.w:typeN)r    r!   r"   r#   r   r   typer&   r'   r(   r   r      s-        0 0 X'788DDDr'   r   c                  f   e Zd ZdZdZ ededd                   Z ededd                   Z ed	ed
d                   Z ededd                   Z	[e
d             Zej        d             Ze
dd            Zej        dd            Ze
d             Zej        d             ZdS )CT_TblPrz}``<w:tblPr>`` element, child of ``<w:tbl>``, holds child elements that define
    table properties such as style and borders.)
w:tblStylezw:tblpPrzw:tblOverlapw:bidiVisualzw:tblStyleRowBandSizezw:tblStyleColBandSizezw:tblWw:jcw:tblCellSpacingzw:tblIndzw:tblBordersw:shdw:tblLayoutzw:tblCellMarz	w:tblLookzw:tblCaptionzw:tblDescriptionzw:tblPrChanger      Nr   r      r      r      c                &    | j         }|dS |j        S )zMember of :ref:`WdRowAlignment` enumeration or |None|, based on the contents
        of the `w:val` attribute of `./w:jc`.

        |None| if no `w:jc` element is present.
        N)jcr$   )r/   r   s     r(   	alignmentzCT_TblPr.alignment  s     W:4vr'   c                l    |                                   |d S |                                 }||_        d S r?   )
_remove_jcget_or_add_jcr$   )r/   rB   r   s      r(   r   zCT_TblPr.alignment+  s8    =F!!r'   rj   boolc                .    | j         }|dn
|j        dk    S )zg|False| when there is a `w:tblLayout` child with `@w:type="fixed"`.

        Otherwise |True|.
        NTfixed)	tblLayoutr   )r/   r   s     r(   autofitzCT_TblPr.autofit3  s!     N	 (ttin.GGr'   rB   c                D    |                                  }|rdnd|_        d S )Nr   r   )get_or_add_tblLayoutr   )r/   rB   r   s      r(   r   zCT_TblPr.autofit<  s'    --//	&+8	r'   c                &    | j         }|dS |j        S )ziReturn the value of the ``val`` attribute of the ``<w:tblStyle>`` child or
        |None| if not present.N)rp   r$   rq   s     r(   stylezCT_TblPr.styleA  s     =4|r'   c                b    |                                   |d S |                     |           d S )N)r$   )rt   ru   r/   rB   s     r(   r   zCT_TblPr.styleJ  s;    =Fu%%%%%r'   )rj   r   )rB   r   )r    r!   r"   r#   _tag_seqr   rp   rY   r   r   rS   r   rT   r   r   r&   r'   r(   r   r     sP       3 3H( y(122,???H>hqrrlCCCJ	6hqrrl	3	3	3B	-HRSSMBBBI	 	 X	    H H H XH ^9 9 9 ^9   X \& & \& & &r'   r   c                  x    e Zd ZdZ ede          Z ede          Ze	d             Z
e
j        d             Z
dS )CT_TblWidthzeUsed for ``<w:tblW>`` and ``<w:tcW>`` elements and many others, to specify a
    table-related width.r   r   c                D    | j         dk    rdS t          | j                  S )zbReturn the EMU length value represented by the combined ``w:w`` and
        ``w:type`` attributes.dxaN)r   r   ry   r8   s    r(   ri   zCT_TblWidth.width\  s$     94TV}}r'   c                F    d| _         t          |          j        | _        d S )Nr   )r   r   r   ry   r   s     r(   ri   zCT_TblWidth.widthd  s    	U!r'   N)r    r!   r"   r#   r   r   ry   r   r   rS   ri   rT   r&   r'   r(   r   r   R  sz          	%((AX{33D  X \" " \" " "r'   r   c                     e Zd ZU dZded<   ded<   ded<   ded	<    ed
          Z ed          Z ed          Z	e
d             Zd Ze
d             Zej        d             Ze
d3d            Zd Ze
d             Zd Zed             Ze
d             Ze
d             Ze
d             Zej        d             Ze
d             Zej        d             Zd Ze
d             Zd4d!Zd" Ze
d#             Zd$ Zd% Ze
d&             Z d' Z!d( Z"d) Z#d* Z$d+ Z%e
d,             Z&e
d-             Z'e
d.             Z(e
d/             Z)e
d0             Z*e
d1             Z+e
d2             Z,d S )5rP   z`w:tc` table cell element.zCallable[[], CT_P]add_pz
List[CT_P]p_lstzList[CT_Tbl]tbl_lstzCallable[[CT_Tbl], CT_Tbl]_insert_tblzw:tcPrw:pw:tblc                n    | j         %| j        }||j         t          j        k    r|j        S | j        dz   S )zThe row index that marks the bottom extent of the vertical span of this cell.

        This is one greater than the index of the bottom-most row of the span, similar
        to how a slice of the cell's rows would be specified.
        Nr   )vMerge	_tc_belowr   CONTINUEbottom_tr_idx)r/   tc_belows     r(   r   zCT_Tc.bottomw  s=     ;"~H#8;L(L(L&|ar'   c                T    g }| j         }||                    |           || dd<   dS )aM  Remove all content child elements, preserving the ``<w:tcPr>`` element if
        present.

        Note that this leaves the ``<w:tc>`` element in an invalid state because it
        doesn't contain at least one block-level element. It's up to the caller to add a
        ``<w:p>``child element as the last content element.
        N)tcPrappend)r/   new_childrenr   s      r(   clear_contentzCT_Tc.clear_content  s;     y%%%QQQr'   c                &    | j         }|dS |j        S )zzThe integer number of columns this cell spans.

        Determined by ./w:tcPr/w:gridSpan/@val, it defaults to 1.
        Nr   )r   r-   r/   r   s     r(   r-   zCT_Tc.grid_span  s     y<1~r'   c                <    |                                  }||_        d S r?   )get_or_add_tcPrr-   r/   rB   r   s      r(   r-   zCT_Tc.grid_span  s    ##%%r'   rj   List[CT_P | CT_Tbl]c                ,    |                      d          S )zGenerate all `w:p` and `w:tbl` elements in this document-body.

        Elements appear in document order. Elements shaded by nesting in a `w:ins` or
        other "wrapper" element will not be included.
        z./w:p | ./w:tblxpathr8   s    r(   inner_content_elementszCT_Tc.inner_content_elements  s     zz+,,,r'   c              #     K   t          d          t          d          t          d          f}| D ]}|j        |v r|V  dS )zpGenerate a reference to each of the block-level content elements in this
        cell, in the order they appear.r   r   zw:sdtN)r   tag)r/   block_item_tagschilds      r(   iter_block_itemszCT_Tc.iter_block_items  sV       e99bkk2g;;? 	 	EyO++	 	r'   c                    | j         S )z?The grid column index at which this ``<w:tc>`` element appears.)	_grid_colr8   s    r(   leftz
CT_Tc.left  s     ~r'   c                    |                      |          \  }}}}| j        j        |                             |          }|                    ||           |S )zReturn the top-left ``<w:tc>`` element of a new span formed by merging the
        rectangular region defined by using this tc element and `other_tc` as diagonal
        corners.)_span_dimensions_tblr6   r3   _grow_to)r/   other_tctopr   heightri   top_tcs          r(   mergezCT_Tc.merge  sV     $(#8#8#B#B T65!#&55d;;v&&&r'   c                @    t          dt          d          z            S )zhReturn a new ``<w:tc>`` element, containing an empty paragraph as the
        required EG_BlockLevelElt.z<w:tc %s>
  <w:p/>
</w:tc>ry   )r   r
   )rm   s    r(   rQ   z	CT_Tc.new  s     =LMMMr'   c                     | j         | j        z   S )a  The grid column index that marks the right-side extent of the horizontal span
        of this cell.

        This is one greater than the index of the right-most column of the span, similar
        to how a slice of the cell's columns would be specified.
        )r   r-   r8   s    r(   rightzCT_Tc.right  s     ~..r'   c                `    | j         | j         t          j        k    r| j        S | j        j        S )z9The top-most row index in the vertical span of this cell.)r   r   RESTARTr   	_tc_abover   r8   s    r(   r   z	CT_Tc.top  s.     ;$+1A"A"A<~!!r'   c                &    | j         }|dS |j        S )zlThe value of the ./w:tcPr/w:vMerge/@val attribute, or |None| if the w:vMerge
        element is not present.N)r   
vMerge_valr   s     r(   r   zCT_Tc.vMerge  s     y<4r'   c                <    |                                  }||_        d S r?   )r   r   r   s      r(   r   zCT_Tc.vMerge  s    ##%%r'   c                &    | j         }|dS |j        S )zqReturn the EMU length value represented in the ``./w:tcPr/w:tcW`` child
        element or |None| if not present.N)r   ri   r   s     r(   ri   zCT_Tc.width  s     y<4zr'   c                <    |                                  }||_        d S r?   )r   ri   r   s      r(   ri   zCT_Tc.width  s    ##%%


r'   c                T    | j         r|j         r| xj         |j         z  c_         dS dS dS )zAdd the width of `other_tc` to this cell.

        Does nothing if either this tc or `other_tc` does not have a specified width.
        N)ri   )r/   r   s     r(   _add_width_ofzCT_Tc._add_width_of  sA    
 : 	)(. 	)JJ(.(JJJJ	) 	) 	) 	)r'   c                    | j         }|j                            |           }|j        d|         }t          d |D                       S )z*The grid column at which this cell begins.Nc              3  $   K   | ]}|j         V  d S r?   )r-   ).0r2   s     r(   	<genexpr>z"CT_Tc._grid_col.<locals>.<genexpr>  s$      88B2<888888r'   )_trr,   r7   sum)r/   rd   r0   preceding_tcss       r(   r   zCT_Tc._grid_col  sJ     Xiood##	$3$88-888888r'   Nc                      fd}| n|}                      || ||                     dk    r! j                            |dz
  |           dS dS )zGrow this cell to `width` grid columns and `height` rows by expanding
        horizontal spans and creating continuation cells to form vertical spans.c                L    | urt           j        S dk    rd S t           j        S Nr   )r   r   r   )r   r   r/   s    r(   r   z"CT_Tc._grow_to.<locals>.vMerge_val  s.    T!!(({{t##r'   Nr   )_span_to_widthr   r   )r/   ri   r   r   r   s   ` `  r(   r   zCT_Tc._grow_to  s    	$ 	$ 	$ 	$ 	$ 	$  VE6::f+=+=>>>A::N##E6A:v>>>>> :r'   c                2    |                      d|           |S )z``tcPr`` has a bunch of successors, but it comes first if it appears, so just
        overriding and using insert(0, ...) rather than spelling out successors.r   rH   r   s     r(   _insert_tcPrzCT_Tc._insert_tcPr  s     	Atr'   c                    t          |                                           }t          |          dk    rdS |d         }t          |j                  dk    rdS dS )zATrue if this cell contains only a single empty ``<w:p>`` element.r   Fr   T)listr   r_   r_lst)r/   block_itemsps      r(   	_is_emptyzCT_Tc._is_empty  s[     4002233{a5Nqw<<14ur'   c                    || u rdS | j         rdS |                                 |                                 D ]}|                    |           |                     |                                            dS )zoAppend the content of this cell to `other_tc`, leaving this cell with a
        single empty ``<w:p>`` element.N)r  _remove_trailing_empty_pr   r   _new_p)r/   r   block_elements      r(   _move_content_tozCT_Tc._move_content_to%  s     tF> 	F))+++!2244 	+ 	+MOOM****DKKMM"""""r'   c                4    t                                           S r?   )rV   rQ   r8   s    r(   _new_tblzCT_Tc._new_tbl3  s    zz||r'   c                D    |                      d          }|r|d         ndS )zThe `w:tc` element immediately following this one in this row, or |None| if
        this is the last `w:tc` element in the row.z./following-sibling::w:tcr   Nr   )r/   following_tcss     r(   _next_tczCT_Tc._next_tc6  s+     

#>??#0:}Qd:r'   c                T    |                                                      |            dS )z-Remove this `w:tc` element from the XML tree.N)r5   remover8   s    r(   _removezCT_Tc._remove=  s&    %%%%%r'   c                    t          |                                           }|d         }|j        t          d          k    rdS |}t	          |j                  dk    rdS |                     |           dS )z[Remove the last content element from this cell if it is an empty ``<w:p>``
        element.r   Nr   )r  r   r   r   r_   r  r  )r/   r  last_content_elmr  s       r(   r
  zCT_Tc._remove_trailing_empty_pA  sp     4002233&r?2e99,,Fqw<<!FAr'   c                &   d }d } || |            || |           t          | j        |j                  }t          | j        |j                  }t          | j        |j                  }t          | j        |j                  }||||z
  ||z
  fS )zReturn a (top, left, height, width) 4-tuple specifying the extents of the
        merged cell formed by using this tc and `other_tc` as opposite corner
        extents.c                    | j         |j         k    r| j        |j        k    rt          d          | j        |j        k    r| j        |j        k    rt          d          d S d S Nzrequested span not rectangularr   r   r	   r   r   )abs     r(   raise_on_inverted_Lz3CT_Tc._span_dimensions.<locals>.raise_on_inverted_LR  sf    u~~!(ah"6"6&'GHHHvAGqw$6$6&'GHHH  $6$6r'   c                2   | j         |j         k     r| |fn|| f\  }}|j         |j         k     r|j        |j        k    rt          d          | j        |j        k     r| |fn|| f\  }}|j        |j        k     r|j        |j        k    rt          d          d S d S r  r  )r  r  top_mostother	left_mosts        r(   raise_on_tee_shapedz3CT_Tc._span_dimensions.<locals>.raise_on_tee_shapedX  s    ()q!ffAq6OHe|ei''HOel,J,J&'GHHH)*!&1vvq!fIu~
**y/L/L&'GHHH +*/L/Lr'   )minr   r   maxr   r   )r/   r   r  r$  r   r   r   r   s           r(   r   zCT_Tc._span_dimensionsM  s    
	I 	I 	I	I 	I 	I 	D(+++D(+++$(HL))49hm,,T[(/22DJ//D&3,44r'   c                    |                      |           | j        |k     r!|                     ||           | j        |k     !|| _        dS )aZ  Incorporate and then remove `w:tc` elements to the right of this one until
        this cell spans `grid_width`.

        Raises |ValueError| if `grid_width` cannot be exactly achieved, such as when a
        merged cell would drive the span width greater than `grid_width` or if not
        enough grid columns are available to make this cell that wide. All content from
        incorporated cells is appended to `top_tc`. The val attribute of the vMerge
        element on the single remaining cell is set to `vMerge`. If `vMerge` is |None|,
        the vMerge element is removed if present.
        N)r  r-   _swallow_next_tcr   )r/   
grid_widthr   r   s       r(   r   zCT_Tc._span_to_widthk  sU     	f%%%nz))!!*f555 nz))r'   c                      fd} j         } ||           |                    |                                |            xj        |j        z  c_        |                                 dS )a  Extend the horizontal span of this `w:tc` element to incorporate the
        following `w:tc` element in the row and then delete that following `w:tc`
        element.

        Any content in the following `w:tc` element is appended to the content of
        `top_tc`. The width of the following `w:tc` element is added to this one, if
        present. Raises |InvalidSpanError| if the width of the resulting cell is greater
        than `grid_width` or if there is no next `<w:tc>` element in the row.
        c                n    | t          d          j        | j        z   k    rt          d          d S )Nznot enough grid columnszspan is not rectangular)r	   r-   )next_tcr)  r/   s    r(   raise_on_invalid_swallowz8CT_Tc._swallow_next_tc.<locals>.raise_on_invalid_swallow  sC    &'@AAA~ 11J>>&'@AAA ?>r'   N)r  r  r   r-   r  )r/   r)  r   r-  r,  s   ``   r(   r(  zCT_Tc._swallow_next_tc{  s    	B 	B 	B 	B 	B 	B -  )))  (((7###'++r'   c                8    |                      d          d         S )z+The tbl element this tc element appears in.z./ancestor::w:tbl[position()=1]r   r   r8   s    r(   r   z
CT_Tc._tbl  s     zz;<<Q??r'   c                @    | j                             | j                  S )zAThe `w:tc` element immediately above this one in its grid column.)	_tr_abover3   r   r8   s    r(   r   zCT_Tc._tc_above  s     ~,,T^<<<r'   c                L    | j         }|dS |                    | j                  S )z=The tc element immediately below this one in its grid column.N)	_tr_belowr3   r   )r/   tr_belows     r(   r   zCT_Tc._tc_below  s,     >4&&t~666r'   c                8    |                      d          d         S )z*The tr element this tc element appears in.z./ancestor::w:tr[position()=1]r   r   r8   s    r(   r   z	CT_Tc._tr  s     zz:;;A>>r'   c                    | j         j        }|                    | j                  }|dk    rt	          d          ||dz
           S )zThe tr element prior in sequence to the tr this cell appears in.

        Raises |ValueError| if called on a cell in the top-most row.
        r   zno tr above topmost trr   )r   r6   r7   r   r.   r/   r6   r9   s      r(   r0  zCT_Tc._tr_above  sH     !dh''Q;;5666fqj!!r'   c                    | j         j        }|                    | j                  }	 ||dz            S # t          $ r Y dS w xY w)zzThe tr element next in sequence after the tr this cell appears in, or |None|
        if this cell appears in the last row.r   N)r   r6   r7   r   
IndexErrorr6  s      r(   r2  zCT_Tc._tr_below  sW     !dh''	&1*%% 	 	 	44	s   
3 
A Ac                J    | j         j                            | j                  S )z;The row index of the tr element this tc element appears in.)r   r6   r7   r   r8   s    r(   r   zCT_Tc._tr_idx  s     y%%dh///r'   )rj   r   r?   )-r    r!   r"   r#   __annotations__r   r   r   r  tblrS   r   r   r-   rT   r   r   r   r   r   rQ   r   r   r   ri   r   r   r   r  r  r  r  r  r  r
  r   r   r(  r   r   r   r   r0  r2  r   r&   r'   r(   rP   rP   j  s        $$++++9XD	%A
)G

C
  
  X
      X    - - - X-     X   N N [N
 / / X/ " " X"   X ]    ]    X \  \) ) ) 9 9 X9? ? ? ?      X# # #   ; ; X;& & &
 
 
5 5 5<     0 @ @ X@ = = X= 7 7 X7 ? ? X? 	" 	" X	"   X 0 0 X0 0 0r'   rP   c                     e Zd ZdZdZ ededd                   Z ededd                   Z ed	ed
d                   Z ededd                   Z	[e
d             Zej        d             Ze
d             Zej        d             Ze
d             Zej        d             Ze
d             Zej        d             ZdS )CT_TcPrz5``<w:tcPr>`` element, defining table cell properties.)
w:cnfStylew:tcW
w:gridSpanzw:hMergew:vMergezw:tcBordersr   zw:noWrapzw:tcMarzw:textDirectionzw:tcFitTextw:vAlignz
w:hideMarkz	w:headersz	w:cellInsz	w:cellDelzw:cellMergezw:tcPrChanger?     Nr   r@     rA     rB     c                &    | j         }|dS |j        S )zsThe integer number of columns this cell spans.

        Determined by ./w:gridSpan/@val, it defaults to 1.
        Nr   )gridSpanr$   )r/   rH  s     r(   r-   zCT_TcPr.grid_span  s     =1|r'   c                p    |                                   |dk    r||                                 _        d S d S r   )_remove_gridSpanget_or_add_gridSpanr$   r   s     r(   r-   zCT_TcPr.grid_span  s>    199-2D$$&&*** 9r'   c                &    | j         }|dS |j        S )zValue of `w:val` attribute on  `w:vAlign` child.

        Value is |None| if `w:vAlign` child is not present. The `w:val` attribute on
        `w:vAlign` is required.
        N)vAlignr$   )r/   rM  s     r(   
vAlign_valzCT_TcPr.vAlign_val  s     >4zr'   c                h    ||                                   d S ||                                 _        d S r?   )_remove_vAlignget_or_add_vAlignr$   r   s     r(   rN  zCT_TcPr.vAlign_val  s8    =!!!F',  $$$r'   c                &    | j         }|dS |j        S )zeThe value of the ./w:vMerge/@val attribute, or |None| if the w:vMerge element
        is not present.N)r   r$   )r/   r   s     r(   r   zCT_TcPr.vMerge_val  s     >4zr'   c                h    |                                   |||                                 _        d S d S r?   )_remove_vMerge_add_vMerger$   r   s     r(   r   zCT_TcPr.vMerge_val  s<    %*D""" r'   c                &    | j         }|dS |j        S )zReturn the EMU length value represented in the ``<w:tcW>`` child element or
        |None| if not present or its type is not 'dxa'.N)tcWri   )r/   rW  s     r(   ri   zCT_TcPr.width  s     h;4yr'   c                <    |                                  }||_        d S r?   )get_or_add_tcWri   )r/   rB   rW  s      r(   ri   zCT_TcPr.width   s    !!##			r'   )r    r!   r"   r#   r   r   rW  rH  r   rM  rS   r-   rT   rN  r   ri   r&   r'   r(   r=  r=    sz       ??H( )G
5
5
5Cy(122,???HYzhqrrl;;;FYzhrssm<<<F  X 3 3 3
 	 	 X	 - - -   X + + +
   X \  \  r'   r=  c                      e Zd ZdZdZ ededd                   Z[ed             Zej	        d             Zed	             Z
e
j	        d
             Z
dS )CT_TrPrz4``<w:trPr>`` element, defining table row properties.)r>  zw:divIdzw:gridBeforezw:gridAfterz	w:wBeforezw:wAfterzw:cantSplit
w:trHeightzw:tblHeaderr   r   zw:hiddenzw:inszw:delzw:trPrChanger\  r   Nr   c                &    | j         }|dS |j        S )zCReturn the value of `w:trHeight@w:hRule`, or |None| if not present.N)trHeightr%   r/   r^  s     r(   r<   zCT_TrPr.trHeight_hRule=  s     =4~r'   c                R    |	| j         d S |                                 }||_        d S r?   )r^  get_or_add_trHeightr%   r/   rB   r^  s      r(   r<   zCT_TrPr.trHeight_hRuleE  s/    =T]2F++--r'   c                &    | j         }|dS |j        S )zAReturn the value of `w:trHeight@w:val`, or |None| if not present.N)r^  r$   r_  s     r(   rD   zCT_TrPr.trHeight_valL  s     =4|r'   c                R    |	| j         d S |                                 }||_        d S r?   )r^  ra  r$   rb  s      r(   rD   zCT_TrPr.trHeight_valT  s/    =T]2F++--r'   )r    r!   r"   r#   r   r   r^  rS   r<   rT   rD   r&   r'   r(   r[  r[  &  s        >>H" y(122,???H  X      X     r'   r[  c                  *    e Zd ZdZ ede          ZdS )CT_VerticalJcz:`w:vAlign` element, specifying vertical alignment of cell.r   N)r    r!   r"   r#   r   r   r$   r&   r'   r(   rf  rf  \  s'        DD

G%?
@
@CCCr'   rf  c                  8    e Zd ZdZ edeej                  ZdS )	CT_VMergezG``<w:vMerge>`` element, specifying vertical merging behavior of a cell.r   )defaultN)r    r!   r"   r#   r   r   r   r$   r&   r'   r(   rh  rh  b  s.        QQ

GXx7H
I
I
ICCCr'   rh  N)2r#   
__future__r   typingr   r   r   docx.enum.tabler   r   docx.exceptionsr	   docx.oxml.nsr
   r   docx.oxml.parserr   docx.oxml.simpletypesr   r   r   r   r   docx.oxml.xmlchemyr   r   r   r   r   r   r   docx.sharedr   r   docx.oxml.text.paragraphr   r   r   r*   rV   r   r   r   r   r   rP   r=  r[  rf  rh  r&   r'   r(   <module>rt     s   ( ( " " " " " " 0 0 0 0 0 0 0 0 0 0 J J J J J J J J , , , , , , $ $ $ $ $ $ $ $ & & & & & &                               # " " " " " " " #------""""""= = = = = = = =@ @ @ @ @_ @ @ @Fx x x x x_ x x xvG G G G G G G G	8 	8 	8 	8 	8O 	8 	8 	89 9 9 9 9 9 9 9N& N& N& N& N& N& N& N&b" " " " "/ " " "0Z0 Z0 Z0 Z0 Z0O Z0 Z0 Z0z
\ \ \ \ \o \ \ \~3 3 3 3 3o 3 3 3lA A A A AO A A AJ J J J J J J J J Jr'   