Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ jobs:
uses: pypa/cibuildwheel@294735312765b09d24a2fbec22660ce817587d55 # v4.1.0
env:
CIBW_PLATFORM: "pyodide"
CIBW_TEST_COMMAND: "true"

- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
Expand Down
13 changes: 13 additions & 0 deletions lib/matplotlib/backends/backend_agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,16 @@ def _draw_text_glyphs_and_boxes(self, gc, x, y, angle, glyphs, boxes):
sin = math.sin(math.radians(angle))
load_flags = get_hinting_flag()
for font, size, glyph_index, slant, extend, dx, dy in glyphs: # dy is upwards.
print(f'Rendering {font.fname}@{size}/{self.dpi}:',
glyph_index, slant, extend, dx, dy)
font.set_size(size, self.dpi)
print(
f'set_transform {sin=} {cos=}',
(0x10000 * np.array([[cos, -sin], [sin, cos]])
@ [[extend, extend * slant], [0, 1]]).round().astype(int),
[round(0x40 * (x + dx * cos - dy * sin)),
# FreeType's y is upwards.
round(0x40 * (self.height - y + dx * sin + dy * cos))])
font._set_transform(
(0x10000 * np.array([[cos, -sin], [sin, cos]])
@ [[extend, extend * slant], [0, 1]]).round().astype(int),
Expand All @@ -193,6 +202,9 @@ def _draw_text_glyphs_and_boxes(self, gc, x, y, angle, glyphs, boxes):
if not gc.get_antialiased():
buffer *= 0xff
# draw_text_image's y is downwards & the bitmap bottom side.
print(f'draw_text_image at {bitmap.left=} {self.height=} {bitmap.top=} '
f'{buffer.shape[0]=} {int(self.height)=} '
f'{int(self.height) - bitmap.top + buffer.shape[0]=}')
self._renderer.draw_text_image(
buffer,
bitmap.left, int(self.height) - bitmap.top + buffer.shape[0],
Expand All @@ -205,6 +217,7 @@ def _draw_text_glyphs_and_boxes(self, gc, x, y, angle, glyphs, boxes):
gc1.set_linewidth(0)
gc1.set_snap(gc.get_snap())
for dx, dy, w, h in boxes: # dy is upwards.
print(f'Draw rect {dx=} {dy=} {w=} {h=}')
if gc1.get_snap() in [None, True]:
# Prevent thin bars from disappearing by growing symmetrically.
if w < 1:
Expand Down
12 changes: 8 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -461,16 +461,20 @@ test-command = [
"""\
pytest -p no:cacheprovider --pyargs \
matplotlib mpl_toolkits.axes_grid1 mpl_toolkits.axisartist mpl_toolkits.mplot3d \
-k 'not test_complex_shaping'""",
-k 'test_mathtext or last_resort' || true""",
"cp -a result_images {project}",
]
test-environment = { FT2_DEBUG="any:7 -v" }
[tool.cibuildwheel.pyodide.config-settings]
setup-args = ["-Dbuildtype=debug"]
[tool.cibuildwheel.pyodide.environment]
# Exception handling is needed for pybind11:
# https://github.com/pybind/pybind11/pull/5298
# And the pyemscripten_2025_0 platform and above uses -fwasm-exceptions for this.
# https://pyodide.org/en/stable/development/abi/313.html
CFLAGS = "-fwasm-exceptions"
CXXFLAGS = "-fwasm-exceptions"
LDFLAGS = "-fwasm-exceptions"
CFLAGS = "-fwasm-exceptions -g"
CXXFLAGS = "-fwasm-exceptions -g"
LDFLAGS = "-fwasm-exceptions -g"

[tool.cibuildwheel.windows]
before-build = [
Expand Down
4 changes: 3 additions & 1 deletion subprojects/freetype2.wrap
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ source_hash = 36bc4f1cc413335368ee656c42afca65c5a3987e8768cc28cf11ba775e785a5f

# First patch allows using our bundled HarfBuzz.
# Second patch fixes symbol problems on wasm.
diff_files = freetype-2.14.1-static-harfbuzz.patch, freetype-2.14.1-wasm-visibility.patch
# Third and fourth fix debug logging https://gitlab.freedesktop.org/freetype/freetype/-/merge_requests/438
# Fifth enables debug logging.
diff_files = freetype-2.14.1-static-harfbuzz.patch, freetype-2.14.1-wasm-visibility.patch, 0003-Add-missing-dlg-logging-library-to-meson-build.patch, 0004-Fix-debug-logging-when-NDEBUG-is-set.patch, 0005-Enable-debug-logging.patch

[provide]
freetype2 = freetype_dep
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
From a4279b16570434a2d46f073d221a1d3a5034f9e7 Mon Sep 17 00:00:00 2001
From: Elliott Sales de Andrade <quantum.analyst@gmail.com>
Date: Fri, 31 Jul 2026 23:09:34 -0400
Subject: [PATCH 3/5] Add missing dlg logging library to meson build

Without this source file, the final library fails to link if you set
`FT_DEBUG_LOGGING` for the build.

Signed-off-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
---
meson.build | 1 +
1 file changed, 1 insertion(+)

diff --git a/meson.build b/meson.build
index 046163ecd..c731ed938 100644
--- a/meson.build
+++ b/meson.build
@@ -236,6 +236,7 @@ endif
# might make these platform-specific files much smaller, and could be moved
# into `ftsystem.c` as well.

+ft2_sources += 'src/dlg/dlgwrap.c'
if host_machine.system() == 'windows'
winmod = import('windows')
ft2_sources += [
--
2.55.0

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
From 36633fe4a2bc417ce575f6aa74e9f3a6da20b7e7 Mon Sep 17 00:00:00 2001
From: Elliott Sales de Andrade <quantum.analyst@gmail.com>
Date: Fri, 31 Jul 2026 23:12:47 -0400
Subject: [PATCH 4/5] Fix debug logging when `NDEBUG` is set

In Meson, the default for `b_ndebug` is `is-release`, which will enable
it when in release mode. Additionally, in `dlg`, the default log level
is `warn` if `NDEBUG` is set or `trace` otherwise. Because `FT_LOG` uses
the `trace` level always, all debug logging will be disabled if
`b_ndebug` is set (or in release mode).

Using `NDEBUG` is not documented anywhere to toggle debug logging, so
define `DLG_LOG_LEVEL` so that `trace` level is always output by `dlg`.
FreeType's other (runtime or otherwise) configuration remains as it is
to toggle logging per-component.

Signed-off-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
---
include/freetype/internal/ftdebug.h | 1 +
1 file changed, 1 insertion(+)

diff --git a/include/freetype/internal/ftdebug.h b/include/freetype/internal/ftdebug.h
index 62b9ec2f7..f2339aff4 100644
--- a/include/freetype/internal/ftdebug.h
+++ b/include/freetype/internal/ftdebug.h
@@ -33,6 +33,7 @@

#ifdef FT_DEBUG_LOGGING
#define DLG_STATIC
+#define DLG_LOG_LEVEL dlg_level_trace
#include <dlg/output.h>
#include <dlg/dlg.h>

--
2.55.0

26 changes: 26 additions & 0 deletions subprojects/packagefiles/0005-Enable-debug-logging.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
From dc723711549e7710e074b210f48391c6b07c013e Mon Sep 17 00:00:00 2001
From: Elliott Sales de Andrade <quantum.analyst@gmail.com>
Date: Sat, 1 Aug 2026 01:46:51 -0400
Subject: [PATCH 5/5] Enable debug logging

Signed-off-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
---
include/freetype/config/ftoption.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/freetype/config/ftoption.h b/include/freetype/config/ftoption.h
index b857e0ebb..bef9e6853 100644
--- a/include/freetype/config/ftoption.h
+++ b/include/freetype/config/ftoption.h
@@ -473,7 +473,7 @@ FT_BEGIN_HEADER
*
* This option needs a C99 compiler.
*/
-/* #define FT_DEBUG_LOGGING */
+#define FT_DEBUG_LOGGING


/**************************************************************************
--
2.55.0

Loading