def __init__(self, filename, anchor_x=0, anchor_y=0, bezier_points=BEZIER_POINTS, circle_points=CIRCLE_POINTS, rawdata=None): """Creates an SVG object from a .svg or .svgz file. `filename`: str The name of the file to be loaded. `anchor_x`: float The horizontal anchor position for scaling and rotations. Defaults to 0. The symbolic values 'left', 'center' and 'right' are also accepted. `anchor_y`: float The vertical anchor position for scaling and rotations. Defaults to 0. The symbolic values 'bottom', 'center' and 'top' are also accepted. `bezier_points`: int The number of line segments into which to subdivide Bezier splines. Defaults to 10. `circle_points`: int The number of line segments into which to subdivide circular and elliptic arcs. Defaults to 10. `rawdata`: string Raw data string (you need to set a fake filename for cache anyway) Defaults to None. """ self._tess = gluNewTess() gluTessNormal(self._tess, 0, 0, 1) gluTessProperty(self._tess, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_NONZERO) self.filename = filename self.rawdata = rawdata self.bezier_points = bezier_points self.circle_points = circle_points self.bezier_coefficients = [] self.gradients = GradientContainer() self.generate_disp_list() self.anchor_x = anchor_x self.anchor_y = anchor_y
def _get_filled_path(self): if self._filled_path: return self._filled_path self._tess = gluNewTess() gluTessNormal(self._tess, 0, 0, 1) gluTessProperty(self._tess, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_NONZERO) tess_list = [] def tess_vertex(vertex): self._tess_shape += list(vertex[0:2]) def tess_begin(which): self._tess_style = which self._tess_shape = [] def tess_end(): tess_list.append((self._tess_style, self._tess_shape)) def tess_error(code): err = gluErrorString(code) pymt_logger.warning('BezierPath: GLU Tesselation Error: %s' % str(err)) gluTessCallback(self._tess, GLU_TESS_VERTEX, tess_vertex) gluTessCallback(self._tess, GLU_TESS_BEGIN, tess_begin) gluTessCallback(self._tess, GLU_TESS_END, tess_end) gluTessCallback(self._tess, GLU_TESS_ERROR, tess_error) gluTessBeginPolygon(self._tess, None) gluTessBeginContour(self._tess) for x, y in zip(self._path[::2], self._path[1::2]): v_data = (x, y, 0) gluTessVertex(self._tess, v_data, v_data) gluTessEndContour(self._tess) gluTessEndPolygon(self._tess) self._filled_path = tess_list return tess_list
def __init__(self): self.tess = gluNewTess() self.primitives = [] # [[gl_type, vertices, idx]...] self.vertices = [] # Vertices for the current shape self.type = None # Type for the current shape gl_mode_map = { GL_TRIANGLE_FAN: 'triangle_fan', GL_TRIANGLE_STRIP: 'triangle_strip', GL_TRIANGLES: 'triangles', GL_LINE_LOOP: 'line_loop' } def end_shape_handler(): curr_obj = [ gl_mode_map[self.type], self.vertices, np.arange(len(self.vertices), dtype=np.uint32) ] self.primitives.append(curr_obj) def begin_shape_handler(x): self.type = x self.vertices = [] def vertex_handler(v): self.vertices.append(v) def combine_handler(new_vert, _, __): return new_vert # Register Callbacks gluTessCallback(self.tess, GLU_TESS_VERTEX, vertex_handler) gluTessCallback(self.tess, GLU_TESS_END, end_shape_handler) gluTessCallback(self.tess, GLU_TESS_ERROR, lambda x: print("Error", gluErrorString(x))) gluTessCallback(self.tess, GLU_TESS_BEGIN, begin_shape_handler) gluTessCallback(self.tess, GLU_TESS_COMBINE, combine_handler)