Recreates the freeform geometry on the slide using a FreeformBuilder. Note: If you loaded this shape from an existing slide, you may already have it in place. Typically, build() is used when exporting back to PPTX from your internal representation. If you don't need
(self, slide: PPTXSlide)
| 617 | ) |
| 618 | |
| 619 | def build(self, slide: PPTXSlide): |
| 620 | """ |
| 621 | Recreates the freeform geometry on the slide using a FreeformBuilder. |
| 622 | |
| 623 | Note: If you loaded this shape from an existing slide, you may already |
| 624 | have it in place. Typically, build() is used when exporting back to PPTX |
| 625 | from your internal representation. If you don't need to reconstruct (because |
| 626 | the shape already exists), you can simply no-op here. This is an example of |
| 627 | how you'd do it if you needed to fully recreate geometry. |
| 628 | """ |
| 629 | # Retrieve your geometry data |
| 630 | left = self.data["left"] |
| 631 | top = self.data["top"] |
| 632 | width = self.data["width"] |
| 633 | height = self.data["height"] |
| 634 | points = self.data["points"] |
| 635 | closed = self.data["closed"] |
| 636 | |
| 637 | # Start the builder at the first point (or top-left, etc.). |
| 638 | # This is completely up to you how you define your local coordinate system. |
| 639 | if points: |
| 640 | first_x, first_y = points[0] |
| 641 | else: |
| 642 | # Default to top-left if no data |
| 643 | first_x, first_y = (0, 0) |
| 644 | |
| 645 | builder = slide.shapes.build_freeform(left + first_x, top + first_y) |
| 646 | |
| 647 | # Now add line segments for the rest of the points (if any). |
| 648 | # This is an example usage: |
| 649 | if len(points) > 1: |
| 650 | # Skip the first point since we used it in build_freeform(...) above |
| 651 | builder.add_line_segments(points[1:], close=closed) |
| 652 | |
| 653 | # Convert to a shape |
| 654 | shape = builder.convert_to_shape() |
| 655 | |
| 656 | # Possibly apply local styling, rotation, lines, etc. |
| 657 | shape.name = self.data["name"] |
| 658 | apply_fill(shape, self.style.get("fill")) |
| 659 | if self.style.get("line") is not None: |
| 660 | apply_fill(shape.line, self.style["line"]["fill"]) |
| 661 | dict_to_object(self.style["line"], shape.line, exclude=["fill"]) |
| 662 | |
| 663 | # If you have a bounding box in .style["shape_bounds"], apply it: |
| 664 | if "shape_bounds" in self.style: |
| 665 | dict_to_object(self.style["shape_bounds"], shape) |
| 666 | if "rotation" in self.style: |
| 667 | shape.rotation = self.style["rotation"] |
| 668 | |
| 669 | return shape |
| 670 | |
| 671 | def to_html(self, style_args: StyleArg) -> str: |
| 672 | """ |
nothing calls this directly
no test coverage detected