|
32 | 32 | "html5_canvas_backend is only supported in the browser in the main thread"
|
33 | 33 | ) from err
|
34 | 34 | from pyodide.ffi import create_proxy
|
| 35 | +from pyodide.ffi.wrappers import set_timeout |
35 | 36 |
|
36 | 37 | _capstyle_d = {"projecting": "square", "butt": "butt", "round": "round"}
|
37 | 38 |
|
@@ -311,14 +312,28 @@ def _draw_math_text_path(self, gc, x, y, s, prop, angle):
|
311 | 312 | angle : float
|
312 | 313 | The rotation angle in degrees
|
313 | 314 | """
|
| 315 | + import sys |
| 316 | + |
| 317 | + print(f"Drawing math text: '{s}' at ({x}, {y})", file=sys.stderr) # noqa: B907 |
| 318 | + |
314 | 319 | # Parse the math text to get paths and metrics
|
315 | 320 | width, height, depth, glyphs, rects = self.mathtext_parser.parse(
|
316 | 321 | s, dpi=self.dpi, prop=prop
|
317 | 322 | )
|
318 | 323 |
|
| 324 | + print( |
| 325 | + f"Parsed text dimensions: {width}x{height} (depth: {depth})", |
| 326 | + file=sys.stderr, |
| 327 | + ) |
| 328 | + print(f"Number of glyphs: {len(glyphs)}", file=sys.stderr) |
| 329 | + print(f"Number of rectangles: {len(rects)}", file=sys.stderr) |
| 330 | + |
319 | 331 | # Save the canvas state
|
320 | 332 | self.ctx.save()
|
321 | 333 |
|
| 334 | + baseline_y = self.height - y + depth |
| 335 | + self.ctx.translate(x, baseline_y) |
| 336 | + |
322 | 337 | # Move to text position and apply rotation if needed
|
323 | 338 | self.ctx.translate(x, self.height - y)
|
324 | 339 | if angle != 0:
|
@@ -377,6 +392,24 @@ def _draw_math_text(self, gc, x, y, s, prop, angle):
|
377 | 392 | angle : float
|
378 | 393 | The rotation angle in degrees
|
379 | 394 | """
|
| 395 | + |
| 396 | + def check_fonts_loaded(): |
| 397 | + for url in self.fonts_loading: |
| 398 | + if url in self.fonts_loading: |
| 399 | + return False |
| 400 | + return True |
| 401 | + |
| 402 | + if not check_fonts_loaded(): |
| 403 | + # if fonts aren't loaded, we shall schedule a redraw |
| 404 | + def redraw_when_ready(): |
| 405 | + if check_fonts_loaded(): |
| 406 | + self.fig.draw() |
| 407 | + else: |
| 408 | + set_timeout(redraw_when_ready, 50) |
| 409 | + |
| 410 | + set_timeout(redraw_when_ready, 50) |
| 411 | + return |
| 412 | + |
380 | 413 | try:
|
381 | 414 | # Try rendering directly with paths first
|
382 | 415 | self._draw_math_text_path(gc, x, y, s, prop, angle)
|
|
0 commit comments