microsoft/hve-core
Publicmirrored fromhttps://github.com/microsoft/hve-coreAvailable
.github/skills/experimental/powerpoint/scripts/pptx_shapes.py
62lines · modecode
| 1 | """Shape constants, maps, and rotation utilities for PowerPoint skill scripts. |
| 2 | |
| 3 | Provides the expanded SHAPE_MAP (30+ entries), an inverse AUTO_SHAPE_NAME_MAP |
| 4 | for extraction, and rotation helper functions. |
| 5 | """ |
| 6 | |
| 7 | from pptx.enum.shapes import MSO_SHAPE |
| 8 | |
| 9 | SHAPE_MAP = { |
| 10 | # Original 9 |
| 11 | "rectangle": MSO_SHAPE.RECTANGLE, |
| 12 | "rounded_rectangle": MSO_SHAPE.ROUNDED_RECTANGLE, |
| 13 | "right_arrow": MSO_SHAPE.RIGHT_ARROW, |
| 14 | "chevron": MSO_SHAPE.CHEVRON, |
| 15 | "oval": MSO_SHAPE.OVAL, |
| 16 | "diamond": MSO_SHAPE.DIAMOND, |
| 17 | "pentagon": MSO_SHAPE.PENTAGON, |
| 18 | "hexagon": MSO_SHAPE.HEXAGON, |
| 19 | "right_triangle": MSO_SHAPE.RIGHT_TRIANGLE, |
| 20 | # Arrows |
| 21 | "left_arrow": MSO_SHAPE.LEFT_ARROW, |
| 22 | "up_arrow": MSO_SHAPE.UP_ARROW, |
| 23 | "down_arrow": MSO_SHAPE.DOWN_ARROW, |
| 24 | "left_right_arrow": MSO_SHAPE.LEFT_RIGHT_ARROW, |
| 25 | "notched_right_arrow": MSO_SHAPE.NOTCHED_RIGHT_ARROW, |
| 26 | # Flowchart |
| 27 | "flowchart_process": MSO_SHAPE.FLOWCHART_PROCESS, |
| 28 | "flowchart_decision": MSO_SHAPE.FLOWCHART_DECISION, |
| 29 | "flowchart_terminator": MSO_SHAPE.FLOWCHART_TERMINATOR, |
| 30 | "flowchart_data": MSO_SHAPE.FLOWCHART_DATA, |
| 31 | # Common shapes |
| 32 | "cross": MSO_SHAPE.CROSS, |
| 33 | "donut": MSO_SHAPE.DONUT, |
| 34 | "star_5_point": MSO_SHAPE.STAR_5_POINT, |
| 35 | "cloud": MSO_SHAPE.CLOUD, |
| 36 | "trapezoid": MSO_SHAPE.TRAPEZOID, |
| 37 | "parallelogram": MSO_SHAPE.PARALLELOGRAM, |
| 38 | "left_brace": MSO_SHAPE.LEFT_BRACE, |
| 39 | "right_brace": MSO_SHAPE.RIGHT_BRACE, |
| 40 | "callout_rectangle": MSO_SHAPE.RECTANGULAR_CALLOUT, |
| 41 | "callout_rounded_rectangle": MSO_SHAPE.ROUNDED_RECTANGULAR_CALLOUT, |
| 42 | # Alias |
| 43 | "circle": MSO_SHAPE.OVAL, |
| 44 | } |
| 45 | |
| 46 | # Inverse map: MSO_AUTO_SHAPE_TYPE enum value -> YAML shape name |
| 47 | # Excludes "circle" alias so "oval" is the canonical name for MSO_SHAPE.OVAL |
| 48 | AUTO_SHAPE_NAME_MAP = {v: k for k, v in SHAPE_MAP.items() if k != "circle"} |
| 49 | |
| 50 | |
| 51 | def apply_rotation(shape, rotation: float | None): |
| 52 | """Apply rotation in degrees to a shape when specified.""" |
| 53 | if rotation is not None and rotation != 0: |
| 54 | shape.rotation = rotation |
| 55 | |
| 56 | |
| 57 | def extract_rotation(shape) -> float | None: |
| 58 | """Extract rotation in degrees, returning None when zero.""" |
| 59 | rot = shape.rotation |
| 60 | if rot and rot != 0.0: |
| 61 | return rot |
| 62 | return None |
| 63 | |