MCPcopy Index your code
hub / github.com/python-openxml/python-docx / _span_dimensions

Method _span_dimensions

src/docx/oxml/table.py:661–689  ·  view source on GitHub ↗

Return 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.

(self, other_tc: CT_Tc)

Source from the content-addressed store, hash-verified

659 self.remove(p)
660
661 def _span_dimensions(self, other_tc: CT_Tc) -> tuple[int, int, int, int]:
662 """Return a (top, left, height, width) 4-tuple specifying the extents of the
663 merged cell formed by using this tc and `other_tc` as opposite corner
664 extents."""
665
666 def raise_on_inverted_L(a: CT_Tc, b: CT_Tc):
667 if a.top == b.top and a.bottom != b.bottom:
668 raise InvalidSpanError("requested span not rectangular")
669 if a.left == b.left and a.right != b.right:
670 raise InvalidSpanError("requested span not rectangular")
671
672 def raise_on_tee_shaped(a: CT_Tc, b: CT_Tc):
673 top_most, other = (a, b) if a.top < b.top else (b, a)
674 if top_most.top < other.top and top_most.bottom > other.bottom:
675 raise InvalidSpanError("requested span not rectangular")
676
677 left_most, other = (a, b) if a.left < b.left else (b, a)
678 if left_most.left < other.left and left_most.right > other.right:
679 raise InvalidSpanError("requested span not rectangular")
680
681 raise_on_inverted_L(self, other_tc)
682 raise_on_tee_shaped(self, other_tc)
683
684 top = min(self.top, other_tc.top)
685 left = min(self.left, other_tc.left)
686 bottom = max(self.bottom, other_tc.bottom)
687 right = max(self.right, other_tc.right)
688
689 return top, left, bottom - top, right - left
690
691 def _span_to_width(self, grid_width: int, top_tc: CT_Tc, vMerge: str | None):
692 """Incorporate `w:tc` elements to the right until this cell spans `grid_width`.

Callers 3

mergeMethod · 0.95

Calls

no outgoing calls