Skip to content

Commit 1899f17

Browse files
committed
Partial fix for Matplotlib 3.9's test suite.
1 parent 4a940ee commit 1899f17

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

Diff for: ext/_mplcairo.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -1588,10 +1588,12 @@ void GraphicsContextRenderer::draw_text(
15881588
next_glyphs_pos = glyphs_pos + cluster.num_glyphs;
15891589
for (auto j = glyphs_pos; j < next_glyphs_pos; ++j) {
15901590
if (!gac.glyphs[j].index) {
1591-
auto missing =
1592-
py::cast(s.substr(bytes_pos, cluster.num_bytes))
1593-
.attr("encode")("ascii", "namereplace");
1594-
warn_on_missing_glyph(missing.cast<std::string>());
1591+
auto missing = py::cast(s.substr(bytes_pos, cluster.num_bytes));
1592+
warn_on_missing_glyph( // Format forced by test_mathtext_ticks.
1593+
"{} ({})"_format(
1594+
py::module::import("builtins").attr("ord")(missing),
1595+
missing.attr("encode")("ascii", "namereplace").attr("decode")())
1596+
.cast<std::string>());
15951597
}
15961598
}
15971599
bytes_pos = next_bytes_pos;

Diff for: ext/_util.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -903,8 +903,8 @@ void warn_on_missing_glyph(std::string s)
903903
{
904904
PY_CHECK(
905905
PyErr_WarnEx,
906-
nullptr,
907-
"Requested glyph ({}) missing from current font."_format(s)
906+
PyExc_UserWarning,
907+
"Glyph {} missing from current font."_format(s)
908908
.cast<std::string>().c_str(),
909909
1);
910910
}

Diff for: src/mplcairo/base.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ def _print_vector(self, renderer_factory,
315315
def _print_ps_impl(self, is_eps, path_or_stream, *,
316316
metadata=None, orientation="portrait", papertype=None,
317317
**kwargs):
318+
# FIXME: papertype seems currently broken.
318319
if papertype is None:
319320
papertype = mpl.rcParams["ps.papersize"]
320321
if orientation == "portrait":
@@ -342,11 +343,15 @@ def _print_ps_impl(self, is_eps, path_or_stream, *,
342343
with TemporaryDirectory() as tmp_dirname:
343344
tmp_name = Path(tmp_dirname, "tmp")
344345
print_method(tmp_name, metadata=metadata, **kwargs)
345-
# Assume we can get away without passing the bbox.
346+
# Assume we can get away with just passing bbox width/height.
347+
wh = (self.figure.bbox.width, self.figure.bbox.height)
348+
if orientation == "landscape":
349+
wh = wh[::-1]
346350
{"ghostscript": backend_ps.gs_distill,
347351
"xpdf": backend_ps.xpdf_distill}[
348352
mpl.rcParams["ps.usedistiller"]](
349-
str(tmp_name), is_eps, ptype=papertype)
353+
str(tmp_name), is_eps, ptype=papertype,
354+
bbox=(None, None, *wh))
350355
# If path_or_stream is *already* a text-mode stream then
351356
# tmp_name needs to be opened in text-mode too.
352357
with cbook.open_file_cm(path_or_stream, "wb") as stream, \

0 commit comments

Comments
 (0)