text
stringlengths 1
93.6k
|
|---|
elif ha == "right":
|
ax -= w
|
if va == "top":
|
ay -= h
|
elif va == "center":
|
ay -= h / 2
|
if mtext.get_rotation_mode() != "anchor":
|
# if not anchor mode, rotation is undone last
|
v_offset = np.dot(dir_vert, [(x - ax), (y - ay)])
|
ax = ax + v_offset * dir_vert[0]
|
ay = ay + v_offset * dir_vert[1]
|
x, y = ax, ay
|
x += self.widget.x
|
y += self.widget.y
|
if ismath:
|
self.draw_mathtext(gc, x, y, s, prop, angle)
|
else:
|
font = resource_find(prop.get_name() + ".ttf")
|
color = gc.get_rgb()
|
if font is None:
|
plot_text = CoreLabel(font_size=prop.get_size_in_points(), color=color)
|
else:
|
plot_text = CoreLabel(font_size=prop.get_size_in_points(),
|
font_name=prop.get_name(), color=color)
|
plot_text.text = six.text_type("{}".format(s))
|
if prop.get_style() == 'italic':
|
plot_text.italic = True
|
if self.weight_as_number(prop.get_weight()) > 500:
|
plot_text.bold = True
|
plot_text.refresh()
|
with self.widget.canvas:
|
if isinstance(angle, float):
|
PushMatrix()
|
Rotate(angle=angle, origin=(int(x), int(y)))
|
Rectangle(pos=(int(x), int(y)), texture=plot_text.texture,
|
size=plot_text.texture.size)
|
PopMatrix()
|
else:
|
Rectangle(pos=(int(x), int(y)), texture=plot_text.texture,
|
size=plot_text.texture.size)
|
def draw_mathtext(self, gc, x, y, s, prop, angle):
|
'''Draw the math text using matplotlib.mathtext. The position
|
x,y is given in Kivy coordinates.
|
'''
|
ftimage, depth = self.mathtext_parser.parse(s, self.dpi, prop)
|
w = ftimage.get_width()
|
h = ftimage.get_height()
|
texture = Texture.create(size=(w, h))
|
if _mpl_ge_1_5:
|
texture.blit_buffer(ftimage.as_rgba_str()[0][0], colorfmt='rgba',
|
bufferfmt='ubyte')
|
else:
|
texture.blit_buffer(ftimage.as_rgba_str(), colorfmt='rgba',
|
bufferfmt='ubyte')
|
texture.flip_vertical()
|
with self.widget.canvas:
|
Rectangle(texture=texture, pos=(x, y), size=(w, h))
|
def draw_path(self, gc, path, transform, rgbFace=None):
|
'''Produce the rendering of the graphics elements using
|
:class:`kivy.graphics.Line` and :class:`kivy.graphics.Mesh` kivy
|
graphics instructions. The paths are converted into polygons and
|
assigned either to a clip rectangle or to the same canvas for
|
rendering. Paths are received in matplotlib coordinates. The
|
aesthetics is defined by the `GraphicsContextKivy` gc.
|
'''
|
if _mpl_ge_2_0:
|
polygons = path.to_polygons(transform, self.widget.width,
|
self.widget.height, closed_only=False)
|
else:
|
polygons = path.to_polygons(transform, self.widget.width,
|
self.widget.height)
|
list_canvas_instruction = self.get_path_instructions(gc, polygons,
|
closed=True, rgbFace=rgbFace)
|
for widget, instructions in list_canvas_instruction:
|
widget.canvas.add(instructions)
|
def draw_markers(self, gc, marker_path, marker_trans, path,
|
trans, rgbFace=None):
|
'''Markers graphics instructions are stored on a dictionary and
|
hashed through graphics context and rgbFace values. If a marker_path
|
with the corresponding graphics context exist then the instructions
|
are pulled from the markers dictionary.
|
'''
|
if not len(path.vertices):
|
return
|
# get a string representation of the path
|
path_data = self._convert_path(
|
marker_path,
|
marker_trans + Affine2D().scale(1.0, -1.0),
|
simplify=False)
|
# get a string representation of the graphics context and rgbFace.
|
style = str(gc._get_style_dict(rgbFace))
|
dictkey = (path_data, str(style))
|
# check whether this marker has been created before.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.