o
    jqi)                     @  s   d Z ddlmZ ddlmZ ddlmZmZmZ ddl	m
Z
mZmZmZmZ dd ZG dd	 d	e
ZG d
d de
ZG dd de
ZG dd de
ZdS )z2Custom element classes related to the styles part.    )annotations)WD_STYLE_TYPE)ST_DecimalNumberST_OnOff	ST_String)BaseOxmlElementOptionalAttributeRequiredAttribute
ZeroOrMore	ZeroOrOnec                 C  s*   ddddddddd	d
d
 | | ddS )zlReturn the style id corresponding to `name`, taking into account special-case
    names such as 'Heading 1'.ZCaptionZHeading1ZHeading2ZHeading3ZHeading4ZHeading5ZHeading6ZHeading7ZHeading8ZHeading9)
captionz	heading 1z	heading 2z	heading 3z	heading 4z	heading 5z	heading 6z	heading 7z	heading 8z	heading 9  )getreplace)name r   W/home/app/PaddleOCR-VL/.venv_paddleocr/lib/python3.10/site-packages/docx/oxml/styles.pystyleId_from_name   s   r   c                   @  sp   e Zd ZdZedddZedeZede	Z
ede	Zede	Zed	eZed
e	Zdd Zdd Zdd ZdS )CT_LatentStylesz`w:latentStyles` element, defining behavior defaults for latent styles and
    containing `w:lsdException` child elements that each override those defaults for a
    named latent style.zw:lsdExceptionr   
successorszw:countzw:defLockedStatezw:defQFormatzw:defSemiHiddenzw:defUIPriorityzw:defUnhideWhenUsedc                 C  s   t | |}|du rdS |S )z`Return the boolean value of the attribute having `attr_name`, or |False| if
        not present.NFgetattrself	attr_namevaluer   r   r   	bool_prop/   s   
zCT_LatentStyles.bool_propc                 C  s   |  d| }|sdS |d S )zHReturn the `w:lsdException` child having `name`, or |None| if not found.zw:lsdException[@w:name="%s"]Nr   xpath)r   r   foundr   r   r   get_by_name7   s   zCT_LatentStyles.get_by_namec                 C  s   t | |t| dS z7Set the on/off attribute having `attr_name` to `value`.N)setattrboolr   r   r   r   set_bool_prop>      zCT_LatentStyles.set_bool_propN)__name__
__module____qualname____doc__r
   ZlsdExceptionr   r   countr   ZdefLockedStateZ
defQFormatZdefSemiHiddenZdefUIPriorityZdefUnhideWhenUsedr   r"   r&   r   r   r   r   r   !   s    





r   c                   @  sd   e Zd ZdZedeZedeZ	edeZ
edeZedeZedeZdd	 Zd
d Zdd ZdS )CT_LsdExceptionzb``<w:lsdException>`` element, defining override visibility behaviors for a named
    latent style.w:lockedw:name	w:qFormatw:semiHiddenw:uiPriorityw:unhideWhenUsedc                 C     |   |  dS )z;Remove this `w:lsdException` element from the XML document.N	getparentremover   r   r   r   deleteN      zCT_LsdException.deletec                 C  s
   t | |S )z_Return the boolean value of the attribute having `attr_name`, or |None| if
        not present.r   )r   r   r   r   r   on_off_propR   s   
zCT_LsdException.on_off_propc                 C  s   t | || dS r#   )r$   r   r   r   r   set_on_off_propW   s   zCT_LsdException.set_on_off_propN)r(   r)   r*   r+   r   r   lockedr	   r   r   qFormat
semiHiddenr   
uiPriorityunhideWhenUsedr9   r;   r<   r   r   r   r   r-   C   s    





r-   c                   @  s  e Zd ZU dZdZededd dZededd dZed	ed
d dZededd dZ	ededd dZ
ededd dZededd dZededd dZededd dZededd dZ[edeZded< edeZded< edeZed eZed!d" Zejd#d" Zed$d% Zd&d' Zed(d) Zejd*d) Zed+d, Zejd-d, Zed.d/ Z ed0d1 Z!e!jd2d1 Z!ed3d4 Z"e"jd5d4 Z"ed6d7 Z#e#jd8d7 Z#ed9d: Z$e$jd;d: Z$dS )<CT_Stylez9A ``<w:style>`` element, representing a style definition.)r/   z	w:aliases	w:basedOnw:nextzw:linkzw:autoRedefinezw:hiddenr2   r1   r3   r0   r.   z
w:personalzw:personalComposezw:personalReplyzw:rsidw:pPrw:rPrzw:tblPrzw:trPrzw:tcPrzw:tblStylePrr/      Nr   rC      rD      r2      r1   	   r3   
   r0      r.      rE      rF      zw:typezWD_STYLE_TYPE | Nonetypez	w:styleIdz
str | NonestyleIdz	w:defaultzw:customStylec                 C     | j }|du r	dS |jS )z5Value of `w:basedOn/@w:val` or |None| if not present.N)basedOnval)r   rT   r   r   r   basedOn_val      zCT_Style.basedOn_valc                 C  s"   |d u r
|    d S ||  _d S N)Z_remove_basedOnZget_or_add_basedOnrU   r   r   r   r   r   rV      s   c                 C  s6   | j }|du r	dS |  }||j}|du rdS |S )zkSibling CT_Style element this style is based on or |None| if no base style or
        base style not found.N)rT   r6   	get_by_idrU   )r   rT   styles
base_styler   r   r   r\      s   zCT_Style.base_stylec                 C  r4   )zARemove this `w:style` element from its parent `w:styles` element.Nr5   r8   r   r   r   r9      r:   zCT_Style.deletec                 C     | j }|du r	dS |jS )z5Value of `w:locked/@w:val` or |False| if not present.NF)r=   rU   )r   r=   r   r   r   
locked_val   rW   zCT_Style.locked_valc                 C  *   |    t|du r|  }||_d S d S NT)Z_remove_lockedr%   Z_add_lockedrU   )r   r   r=   r   r   r   r^      
   
c                 C  rS   )z5Value of ``<w:name>`` child or |None| if not present.N)r   rU   )r   r   r   r   r   name_val   rW   zCT_Style.name_valc                 C  &   |    |d ur|  }||_d S d S rX   )Z_remove_nameZ	_add_namerU   )r   r   r   r   r   r   rb      
   
c                 C  s&   | j }|du r	dS |  }||jS )zSibling CT_Style element identified by the value of `w:name/@w:val` or |None|
        if no value is present or no style with that style id is found.N)nextr6   rZ   rU   )r   re   r[   r   r   r   
next_style   s
   zCT_Style.next_stylec                 C  r]   )z6Value of `w:qFormat/@w:val` or |False| if not present.NF)r>   rU   )r   r>   r   r   r   qFormat_val   rW   zCT_Style.qFormat_valc                 C  s    |    t|r|   d S d S rX   )Z_remove_qFormatr%   Z_add_qFormatrY   r   r   r   rg      s   c                 C  r]   )z<Value of ``<w:semiHidden>`` child or |False| if not present.NF)r?   rU   )r   r?   r   r   r   semiHidden_val   rW   zCT_Style.semiHidden_valc                 C  r_   r`   )Z_remove_semiHiddenr%   Z_add_semiHiddenrU   )r   r   r?   r   r   r   rh      ra   c                 C  rS   )z;Value of ``<w:uiPriority>`` child or |None| if not present.N)r@   rU   )r   r@   r   r   r   uiPriority_val   rW   zCT_Style.uiPriority_valc                 C  rc   rX   )Z_remove_uiPriorityZ_add_uiPriorityrU   )r   r   r@   r   r   r   ri      rd   c                 C  r]   )z=Value of `w:unhideWhenUsed/@w:val` or |False| if not present.NF)rA   rU   )r   rA   r   r   r   unhideWhenUsed_val   rW   zCT_Style.unhideWhenUsed_valc                 C  r_   r`   )Z_remove_unhideWhenUsedr%   Z_add_unhideWhenUsedrU   )r   r   rA   r   r   r   rj     ra   )%r(   r)   r*   r+   _tag_seqr   r   rT   re   r@   r?   rA   r>   r=   ZpPrZrPrr   r   rQ   __annotations__r   rR   r   defaultcustomStylepropertyrV   setterr\   r9   r^   rb   rf   rg   rh   ri   rj   r   r   r   r   rB   \   sn   
 









	






rB   c                   @  sb   e Zd ZdZdZededd dZedddZ[d	d
 Z	dd Z
dddZdddZdd ZdS )	CT_StyleszK``<w:styles>`` element, the root element of a styles part, i.e. styles.xml.)zw:docDefaultsw:latentStylesw:stylerr      Nr   rs   r   c                 C  s0   |   }||_|rdnd|_t||_||_|S )zReturn a newly added `w:style` element having `name` and `style_type`.

        `w:style/@customStyle` is set based on the value of `builtin`.
        NT)Z	add_stylerQ   rn   r   rR   rb   )r   r   
style_typebuiltinstyler   r   r   add_style_of_type  s   
zCT_Styles.add_style_of_typec                   s&    fdd|   D }|sdS |d S )zEReturn `w:style[@w:type="*{style_type}*][-1]` or |None| if not found.c                   s    g | ]}|j  kr|jr|qS r   )rQ   rm   ).0sru   r   r   
<listcomp>&  s    z)CT_Styles.default_for.<locals>.<listcomp>N)_iter_styles)r   ru   Zdefault_styles_for_typer   r{   r   default_for$  s   
zCT_Styles.default_forrR   strreturnCT_Style | Nonec                 C  s    d| d}t t| |dS )zR`w:style` child where @styleId = `styleId`.

        |None| if not found.
        zw:style[@w:styleId="z"]Nre   iterr    )r   rR   r    r   r   r   rZ   .  s   zCT_Styles.get_by_idr   c                 C  s   d| }t t| |dS )zd`w:style` child with `w:name` grandchild having value `name`.

        |None| if not found.
        zw:style[w:name/@w:val="%s"]Nr   )r   r   r    r   r   r   r"   6  s   zCT_Styles.get_by_namec                 C  s   dd |  dD S )z@Generate each of the `w:style` child elements in document order.c                 s  s    | ]}|V  qd S rX   r   )ry   rw   r   r   r   	<genexpr>@  s    z)CT_Styles._iter_styles.<locals>.<genexpr>rs   r   r8   r   r   r   r~   >  r'   zCT_Styles._iter_styles)rR   r   r   r   )r   r   r   r   )r(   r)   r*   r+   rk   r   ZlatentStylesr
   rw   rx   r   rZ   r"   r~   r   r   r   r   rq     s    


rq   N)r+   
__future__r   Zdocx.enum.styler   Zdocx.oxml.simpletypesr   r   r   Zdocx.oxml.xmlchemyr   r   r	   r
   r   r   r   r-   rB   rq   r   r   r   r   <module>   s    	" 5