Xj*(dZddlmZddlmZmZmZmZddlm Z ddl m Z ddl m Z ddlmZddlmZdd lmZdd lmZdd lmZdd lmZdd lmZerddlmZddl mZddl m!Z!m"Z"ddlm#Z#GddeZ$GddZ%y)z=Run-related proxy objects for python-docx, Run in particular.) annotations)IO TYPE_CHECKINGIteratorcast)Drawing) WD_STYLE_TYPE)WD_BREAK) CT_Drawing)CT_LastRenderedPageBreak) InlineShape) StoryChild)CharacterStyle)Font)RenderedPageBreakN) WD_UNDERLINE)CT_RCT_Text)LengthceZdZdZdfd Zej fddZ d ddZddZ ddZ e ddZ e jddZ d Ze dd Ze dd Ze dd Zejdd Zd dZd!dZe d"dZejd#dZe d$dZejddZe d%dZejd&dZxZS)'RunaIProxy object wrapping `` element. Several of the properties on Run take a tri-state value, |True|, |False|, or |None|. |True| and |False| correspond to on and off respectively. |None| indicates the property is not specified directly on the run and its effective value is taken from the style hierarchy. cNt|||x|_x|_|_yN)super__init___r_elementelement)selfrparent __class__s a/mnt/ssd/data/Dropbox/adrian/vault-secondbrain/venv/lib/python3.12/site-packages/docx/text/run.pyrz Run.__init__"s%  1222$-$,c .tjdtjdtjdtjdtj dtj di|\}}|jj}|||_ |||_ yy)a Add a break element of `break_type` to this run. `break_type` can take the values `WD_BREAK.LINE`, `WD_BREAK.PAGE`, and `WD_BREAK.COLUMN` where `WD_BREAK` is imported from `docx.enum.text`. `break_type` defaults to `WD_BREAK.LINE`. NN)pageN)columnN) textWrappingleft)r)right)r)allN) r LINEPAGECOLUMNLINE_CLEAR_LEFTLINE_CLEAR_RIGHTLINE_CLEAR_ALLradd_brtypeclear)r break_typetype_r5brs r# add_breakz Run.add_break&s MM< MM> OO-  $ $&>  % %'@  # #%<    uWW^^   BG  BH r$c|jj|||}|jj|t |S)aReturn |InlineShape| containing image identified by `image_path_or_stream`. The picture is added to the end of this run. `image_path_or_stream` can be a path (a string) or a file-like object containing a binary image. If neither width nor height is specified, the picture appears at its native size. If only one is specified, it is used to compute a scaling factor that is then applied to the unspecified dimension, preserving the aspect ratio of the image. The native size of the picture is calculated using the dots- per-inch (dpi) value specified in the image file, defaulting to 72 dpi if no value is specified, as is often the case. )partnew_pic_inliner add_drawingr )rimage_path_or_streamwidthheightinlines r# add_picturezRun.add_picture;s:())*>vN F#6""r$c8|jjy)zcAdd a ```` element at the end of the run, which Word interprets as a tab character.N)radd_tabrs r#rDz Run.add_tabSs r$cN|jj|}t|S)zReturns a newly appended |_Text| object (corresponding to a new ```` child element) to the run, containing `text`. Compare with the possibly more friendly approach of assigning text to the :attr:`Run.text` property. )radd_t_Text)rtextts r#add_textz Run.add_textXs GGMM$ Qxr$c.|jjS)aRead/write tri-state value. When |True|, causes the text of the run to appear in bold face. When |False|, the text unconditionally appears non-bold. When |None| the bold setting for this run is inherited from the style hierarchy. fontboldrEs r#rOzRun.boldbsyy~~r$c&||j_yrrMrvalues r#rOzRun.boldls  r$c:|jj|S)zoReturn reference to this run after removing all its content. All run formatting is preserved. )r clear_contentrEs r#r5z Run.clearps  r$c@t|jjS)a`True` when one or more rendered page-breaks occur in this run. Note that "hard" page-breaks inserted by the author are not included. A hard page-break gives rise to a rendered page-break in the right position so if those were included that page-break would be "double-counted". It would be very rare for multiple rendered page-breaks to occur in a single run, but it is possible. )boolrlastRenderedPageBreaksrEs r#contains_page_breakzRun.contains_page_breakxsDGG2233r$c,t|jS)z{The |Font| object providing access to the character formatting properties for this run, such as font name and size.)rrrEs r#rNzRun.fontsDMM""r$c.|jjS)a Read/write tri-state value. When |True|, causes the text of the run to appear in italics. When |False|, the text unconditionally appears non-italic. When |None| the italic setting for this run is inherited from the style hierarchy. rNitalicrEs r#r\z Run.italicsyyr$c&||j_yrr[rQs r#r\z Run.italics  r$c#K|jjD]U}t|tr|t|trt ||7t|t sHt||Wyw)a'Generate the content-items in this run in the order they appear. NOTE: only content-types currently supported by `python-docx` are generated. In this version, that is text and rendered page-breaks. Drawing is included but currently only provides access to its XML element (CT_Drawing) on its `._drawing` attribute. `Drawing` attributes and methods may be expanded in future releases. There are a number of element-types that can appear inside a run, but most of those (w:br, w:cr, w:noBreakHyphen, w:t, w:tab) have a clear plain-text equivalent. Any contiguous range of such elements is generated as a single `str`. Rendered page-break and drawing elements are generated individually. Any other elements are ignored. N)rinner_content_items isinstancestrr rr r)ritems r#iter_inner_contentzRun.iter_inner_contents_GG// *D$$ D":;'d33D*-dD))  *s AA2!A2cp|jj||jj|y)zMark the range of runs from this run to `last_run` (inclusive) as belonging to a comment. `comment_id` identfies the comment that references this range. N)r insert_comment_range_start_above,insert_comment_range_end_and_reference_below)rlast_run comment_ids r#mark_comment_rangezRun.mark_comment_ranges* 00<  @@Lr$c|jj}tt|jj |t jS)aaRead/write. A |CharacterStyle| object representing the character style applied to this run. The default character style for the document (often `Default Character Font`) is returned if the run has no directly-applied character style. Setting this property to |None| removes any directly-applied character style. )rstylerrr; get_styler CHARACTER)rstyle_ids r#rkz Run.styles577==NDII$7$7-BYBY$Z[[r$cz|jj|tj}||j_yr)r; get_style_idr rmrrk)r style_or_namerns r#rkz Run.styles)99))-9P9PQ  r$c.|jjS)a"String formed by concatenating the text equivalent of each run. Each `` element adds the text characters it contains. A `` element adds a `\t` character. A `` or `` element each add a `\n` character. Note that a `` element can indicate a page break or column break as well as a line break. Only line-break `` elements translate to a `\n` character. Others are ignored. All other content child elements, such as ``, are ignored. Assigning text to this property has the reverse effect, translating each `\t` character to a `` element and each `\n` or `\r` character to a `` element. Any existing run content is replaced. Run formatting is preserved. rrIrEs r#rIzRun.texts ww||r$c&||j_yrrs)rrIs r#rIzRun.texts  r$c.|jjS)aThe underline style for this |Run|. Value is one of |None|, |True|, |False|, or a member of :ref:`WdUnderline`. A value of |None| indicates the run has no directly-applied underline value and so will inherit the underline value of its containing paragraph. Assigning |None| to this property removes any directly-applied underline value. A value of |False| indicates a directly-applied setting of no underline, overriding any inherited value. A value of |True| indicates single underline. The values from :ref:`WdUnderline` are used to specify other outline styles such as double, wavy, and dotted. rN underlinerEs r#rwz Run.underlines$yy"""r$c&||j_yrrvrQs r#rwz Run.underlines# r$)r rr!zt.ProvidesStoryPart)r6r r&)r>zstr | IO[bytes]r?int | Length | Noner@ryreturnr )rzNone)rIra)rz bool | None)rRr|)rzrV)rzr)rzz+Iterator[str | Drawing | RenderedPageBreak])rgrrhintrzr{)rzr)rqzstr | CharacterStyle | None)rzra)rzbool | WD_UNDERLINE | None)rRr~)__name__ __module__ __qualname____doc__rr r-r9rBrDrKpropertyrOsetterr5rXrNr\rcrirkrIrw __classcell__r"s@r#rrsp308}}0&*&* #-###$ #  #0  [[ 4 4##    ]]!!*. M \ \ \\!!" [[##&$$r$rc$eZdZdZdfd ZxZS)rHz&Proxy object wrapping `` element.c8tt| ||_yr)rrHr_t)rt_elmr"s r#rz_Text.__init__s eT#%r$)rr)rrrrrrrs@r#rHrHs0r$rH)&r __future__rtypingrrrr docx.drawingrdocx.enum.styler docx.enum.textr docx.oxml.drawingr docx.oxml.text.pagebreakr docx.shaper docx.sharedrdocx.styles.stylerdocx.text.fontrdocx.text.pagebreakr docx.typestypesrJrdocx.oxml.text.runrrrrrHr$r#rsWC"44 )#(="",1+0"`$*`$Fr$