-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharch.py
More file actions
51 lines (40 loc) · 2.01 KB
/
arch.py
File metadata and controls
51 lines (40 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from dataclasses import dataclass
from typing import Optional
from lxml import etree
from pptx_shapes import units
from pptx_shapes.entities.bbox import BBox
from pptx_shapes.entities.namespace_helper import NamespaceHelper
from pptx_shapes.shapes.shape import Shape
from pptx_shapes.style.fill_style import FillStyle
from pptx_shapes.style.stroke_style import StrokeStyle
@dataclass
class Arch(Shape):
x: float
y: float
width: float
height: float
thickness: float
start_angle: float = 0
end_angle: float = 180
angle: float = 0
fill: Optional[FillStyle] = None
stroke: Optional[StrokeStyle] = None
def to_xml(self, shape_id: int, ns_helper: NamespaceHelper) -> etree.Element:
node = ns_helper.element("p:sp")
nvsppr = ns_helper.element("p:nvSpPr", parent=node)
ns_helper.element("p:cNvPr", {"id": str(shape_id), "name": f"Arch {shape_id}"}, parent=nvsppr)
ns_helper.element("p:cNvSpPr", parent=nvsppr)
ns_helper.element("p:nvPr", parent=nvsppr)
sppr = ns_helper.element("p:spPr", parent=node)
sppr.append(self.make_xfrm(ns_helper, {"rot": units.angle_to_unit(self.angle)}, x=self.x, y=self.y, width=self.width, height=self.height))
av_lst = ns_helper.element("a:avLst", parent=ns_helper.element("a:prstGeom", {"prst": "blockArc"}, parent=sppr))
ns_helper.element("a:gd", {"fmla": f"val {units.angle_to_unit(self.start_angle)}", "name": "adj1"}, parent=av_lst)
ns_helper.element("a:gd", {"fmla": f"val {units.angle_to_unit(self.end_angle)}", "name": "adj2"}, parent=av_lst)
ns_helper.element("a:gd", {"fmla": f"val {round(self.thickness / min(self.width, self.height) * 100000)}", "name": "adj3"}, parent=av_lst)
if self.fill:
sppr.append(self.fill.to_xml(ns_helper))
if self.stroke:
sppr.append(self.stroke.to_xml(ns_helper))
return node
def bbox(self) -> BBox:
return BBox.from_rect(x=self.x, y=self.y, width=self.width, height=self.height, angle=self.angle)