Skip to content

Commit

Permalink
Remove self-comments made to document my changes
Browse files Browse the repository at this point in the history
  • Loading branch information
agriyakhetarpal committed Dec 16, 2024
1 parent 8991c7b commit 06e217c
Showing 1 changed file with 1 addition and 14 deletions.
15 changes: 1 addition & 14 deletions matplotlib_pyodide/html5_canvas_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,51 +332,40 @@ def _draw_math_text_path(self, gc, x, y, s, prop, angle):
angle : float
The rotation angle in degrees
"""
# Parse the math text to get paths and metrics
width, height, depth, glyphs, rects = self.mathtext_parser.parse(
s, dpi=self.dpi, prop=prop
)

# Save the canvas state
self.ctx.save()

# Move to text position and apply rotation if needed
self.ctx.translate(x, self.height - y)
if angle != 0:
self.ctx.rotate(-math.radians(angle))

# Set up text rendering style
self.ctx.fillStyle = self._matplotlib_color_to_CSS(
gc.get_rgb(), gc.get_alpha(), gc.get_forced_alpha()
)

# Draw each glyph in the mathematical expression
for font, fontsize, _, ox, oy in glyphs:
# Move to glyph position
self.ctx.save()
self.ctx.translate(ox, -oy)

# Get the glyph's path data
font.set_size(fontsize, self.dpi)
verts, codes = font.get_path()

verts = verts * fontsize / font.units_per_EM

# Convert the glyph to a Path object
path = Path(verts, codes)

# Draw the path
transform = Affine2D().scale(1.0, -1.0)
self._path_helper(self.ctx, path, transform)
self.ctx.fill()

self.ctx.restore()

# Draw rectangles (fraction bars, roots, etc.)
for x1, y1, x2, y2 in rects:
self.ctx.fillRect(x1, -y2, x2 - x1, y2 - y1)

# Restore the canvas state
self.ctx.restore()

def _draw_math_text(self, gc, x, y, s, prop, angle):
Expand All @@ -399,13 +388,11 @@ def _draw_math_text(self, gc, x, y, s, prop, angle):
The rotation angle in degrees
"""
try:
# Try rendering directly with paths first
self._draw_math_text_path(gc, x, y, s, prop, angle)
except Exception as e:
# If path rendering fails, fall back to image-based approach
# If path rendering fails, we fall back to image-based approach
print(f"Path rendering failed, falling back to image: {str(e)}")

# Get RGBA array using the existing image-based method
rgba, depth = self._math_to_rgba(s, prop, gc.get_rgb())

angle = math.radians(angle)
Expand Down

0 comments on commit 06e217c

Please sign in to comment.