MCPcopy Create free account
hub / github.com/PageBot/PageBot / oval

Method oval

Lib/pagebot/contexts/flatcontext/flatcontext.py:1057–1106  ·  view source on GitHub ↗

Draws an oval in a rectangle, where (x, y) is the bottom left origin and (w, h) is the size. This default DrawBot behavior, different from default Flat, where the (x, y) is the middle of the oval. Compensate for the difference. NOTE: We are not using Flat.ellipse, tr

(self, x, y, w, h)

Source from the content-addressed store, hash-verified

1055 self.page.place(r)
1056
1057 def oval(self, x, y, w, h):
1058 """Draws an oval in a rectangle, where (x, y) is the bottom left origin
1059 and (w, h) is the size. This default DrawBot behavior, different from
1060 default Flat, where the (x, y) is the middle of the oval. Compensate
1061 for the difference.
1062
1063 NOTE: We are not using Flat.ellipse, transform won't work. Instead, we
1064 make a new Bézier path and transform the points."""
1065 shape = self._getShape()
1066
1067 if shape is not None:
1068 path = self.newPath()
1069
1070 # Control point offsets.
1071 kappa = .5522848
1072 offsetX = upt(w / 2) * kappa
1073 offsetY = upt(h / 2) * kappa
1074
1075 x = upt(x)
1076 y = upt(y)
1077
1078 # Middle and other extreme points.
1079 x0 = upt(x + (w / 2))
1080 y0 = upt(y + (h / 2))
1081 x1 = upt(x + w)
1082 y1 = upt(y + h)
1083
1084 px0, py0 = self.getTransformed(x, y0)
1085 path.moveTo((px0, py0))
1086
1087 cp1 = self.getTransformed(x, y0 - offsetY)
1088 cp2 = self.getTransformed(x0 - offsetX, y)
1089 p = self.getTransformed(x0, y)
1090 path.curveTo(cp1, cp2, p)
1091
1092 cp1 = self.getTransformed(x0 + offsetX, y)
1093 cp2 = self.getTransformed(x1, y0 - offsetY)
1094 p = self.getTransformed(x1, y0)
1095 path.curveTo(cp1, cp2, p)
1096
1097 cp1 = self.getTransformed(x1, y0 + offsetY)
1098 cp2 = self.getTransformed(x0 + offsetX, y1)
1099 p = self.getTransformed(x0, y1)
1100 path.curveTo(cp1, cp2, p)
1101
1102 cp1 = self.getTransformed(x0 - offsetX, y1)
1103 cp2 = self.getTransformed(x, y0 + offsetY)
1104 p = self.getTransformed(x, y0)
1105 path.curveTo(cp1, cp2, p)
1106 self.drawShapePath()
1107
1108 def circle(self, x, y, r):
1109 """Draws a circle in a square with radius r and (x, y) as center.

Callers

nothing calls this directly

Calls 7

_getShapeMethod · 0.95
newPathMethod · 0.95
getTransformedMethod · 0.95
drawShapePathMethod · 0.95
uptFunction · 0.90
moveToMethod · 0.45
curveToMethod · 0.45

Tested by

no test coverage detected