diff options
author | S. Solomon Darnell | 2025-03-28 21:52:21 -0500 |
---|---|---|
committer | S. Solomon Darnell | 2025-03-28 21:52:21 -0500 |
commit | 4a52a71956a8d46fcb7294ac71734504bb09bcc2 (patch) | |
tree | ee3dc5af3b6313e921cd920906356f5d4febc4ed /.venv/lib/python3.12/site-packages/docx/shape.py | |
parent | cc961e04ba734dd72309fb548a2f97d67d578813 (diff) | |
download | gn-ai-master.tar.gz |
Diffstat (limited to '.venv/lib/python3.12/site-packages/docx/shape.py')
-rw-r--r-- | .venv/lib/python3.12/site-packages/docx/shape.py | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/.venv/lib/python3.12/site-packages/docx/shape.py b/.venv/lib/python3.12/site-packages/docx/shape.py new file mode 100644 index 00000000..cd35deb3 --- /dev/null +++ b/.venv/lib/python3.12/site-packages/docx/shape.py @@ -0,0 +1,103 @@ +"""Objects related to shapes. + +A shape is a visual object that appears on the drawing layer of a document. +""" + +from __future__ import annotations + +from typing import TYPE_CHECKING + +from docx.enum.shape import WD_INLINE_SHAPE +from docx.oxml.ns import nsmap +from docx.shared import Parented + +if TYPE_CHECKING: + from docx.oxml.document import CT_Body + from docx.oxml.shape import CT_Inline + from docx.parts.story import StoryPart + from docx.shared import Length + + +class InlineShapes(Parented): + """Sequence of |InlineShape| instances, supporting len(), iteration, and indexed access.""" + + def __init__(self, body_elm: CT_Body, parent: StoryPart): + super(InlineShapes, self).__init__(parent) + self._body = body_elm + + def __getitem__(self, idx: int): + """Provide indexed access, e.g. 'inline_shapes[idx]'.""" + try: + inline = self._inline_lst[idx] + except IndexError: + msg = "inline shape index [%d] out of range" % idx + raise IndexError(msg) + + return InlineShape(inline) + + def __iter__(self): + return (InlineShape(inline) for inline in self._inline_lst) + + def __len__(self): + return len(self._inline_lst) + + @property + def _inline_lst(self): + body = self._body + xpath = "//w:p/w:r/w:drawing/wp:inline" + return body.xpath(xpath) + + +class InlineShape: + """Proxy for an ``<wp:inline>`` element, representing the container for an inline + graphical object.""" + + def __init__(self, inline: CT_Inline): + super(InlineShape, self).__init__() + self._inline = inline + + @property + def height(self) -> Length: + """Read/write. + + The display height of this inline shape as an |Emu| instance. + """ + return self._inline.extent.cy + + @height.setter + def height(self, cy: Length): + self._inline.extent.cy = cy + self._inline.graphic.graphicData.pic.spPr.cy = cy + + @property + def type(self): + """The type of this inline shape as a member of + ``docx.enum.shape.WD_INLINE_SHAPE``, e.g. ``LINKED_PICTURE``. + + Read-only. + """ + graphicData = self._inline.graphic.graphicData + uri = graphicData.uri + if uri == nsmap["pic"]: + blip = graphicData.pic.blipFill.blip + if blip.link is not None: + return WD_INLINE_SHAPE.LINKED_PICTURE + return WD_INLINE_SHAPE.PICTURE + if uri == nsmap["c"]: + return WD_INLINE_SHAPE.CHART + if uri == nsmap["dgm"]: + return WD_INLINE_SHAPE.SMART_ART + return WD_INLINE_SHAPE.NOT_IMPLEMENTED + + @property + def width(self): + """Read/write. + + The display width of this inline shape as an |Emu| instance. + """ + return self._inline.extent.cx + + @width.setter + def width(self, cx: Length): + self._inline.extent.cx = cx + self._inline.graphic.graphicData.pic.spPr.cx = cx |