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

Method drawCube

Lib/pagebot/elements/variablefonts/cube.py:91–155  ·  view source on GitHub ↗

Draw the content of the element, responding to size, styles, font and content. Create 2 columns for the self.fontSizes ranges that show the text with and without [opsz] if the axis exists. TODO: If the axis does not exist or not selected, do something else with the r

(self, view, origin, **kwargs)

Source from the content-addressed store, hash-verified

89 view.drawElementInfo(self, origin) # Depends on flag 'view.showElementInfo'
90
91 def drawCube(self, view, origin, **kwargs):
92 """Draw the content of the element, responding to size, styles, font and content.
93 Create 2 columns for the self.fontSizes ranges that show the text with and without [opsz]
94 if the axis exists.
95
96 TODO:
97 If the axis does not exist or not selected, do something else with the right column
98 Add optional relation between VF-axes and cube ribs
99 Automatic calculation of incrementing opsz range
100 Add axis labels and/or values
101 Draw the cube as lines and panes.
102 Auto center vertical and horizontal
103 Auto fontSize calculation
104 Export as animation of rotating cube.
105 """
106
107 c = self.context
108
109 r = 20
110 ox, oy, _ = origin
111 mx = self.w/2
112 my = self.pb
113 dx = self.dx or self.pw/(2*self.steps-2)
114 dy = self.dy or dx/2 + 6
115
116 fontSize = self.css('fontSize', 24)
117 opszRange = (8, 12, 20, 30, 45, 64, 96, 144)
118 #opszRange = (8, 10, 12, 14, 16, 18, 22, 24, 28, 32, 36, 42, 48, 56, 64)
119
120 for xzStep in range(self.steps):
121 for yStep in range(self.steps):
122 # Draw right side of the cube.
123 opsz = opszRange[yStep]
124 x = ox + mx + xzStep * dx
125 y = oy + my + xzStep * dy + 2 * yStep * dy
126 # Calculate the location
127 location = self.getLocation(wght=-xzStep/2+1, wdth=1, opsz=opsz)
128 instance = getInstance(self.f, location)
129 style = dict(font=instance.path, fontSize=fontSize, xTextAlign=CENTER)
130 bs = c.newString(self.label, style=style)
131 tw, th = bs.textSize
132 c.text(bs, (x-tw/2, y))
133
134 if xzStep > 0:
135 # Draw left side of the cube. Avoid double drawing on front axis
136 x = ox + mx - xzStep * dx
137 location = self.getLocation(wght=1, wdth=-xzStep/2+1, opsz=opsz)
138 instance = getInstance(self.f, location)
139 style = dict(font=instance.path, fontSize=fontSize, xTextAlign=CENTER)
140 bs = c.newString(self.label, style=style)
141 tw, th = bs.textSize
142 c.text(bs, (x-tw/2, y))
143
144 # Draw top part of the cube
145 for xStep in range(1, self.steps):
146 for zStep in range(1, self.steps):
147 x = ox + mx + xStep * dx - zStep * dx
148 y = oy + my + (2 * self.steps - 2) * dy + xStep * dy + zStep * dy

Callers 1

buildMethod · 0.95

Calls 5

getInstanceFunction · 0.90
newStringMethod · 0.80
cssMethod · 0.45
getLocationMethod · 0.45
textMethod · 0.45

Tested by

no test coverage detected