Skip to content

Commit

Permalink
Partial fix for Matplotlib 3.9's test suite.
Browse files Browse the repository at this point in the history
  • Loading branch information
anntzer committed May 2, 2024
1 parent 4a940ee commit 1899f17
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
10 changes: 6 additions & 4 deletions ext/_mplcairo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1588,10 +1588,12 @@ void GraphicsContextRenderer::draw_text(
next_glyphs_pos = glyphs_pos + cluster.num_glyphs;
for (auto j = glyphs_pos; j < next_glyphs_pos; ++j) {
if (!gac.glyphs[j].index) {
auto missing =
py::cast(s.substr(bytes_pos, cluster.num_bytes))
.attr("encode")("ascii", "namereplace");
warn_on_missing_glyph(missing.cast<std::string>());
auto missing = py::cast(s.substr(bytes_pos, cluster.num_bytes));
warn_on_missing_glyph( // Format forced by test_mathtext_ticks.
"{} ({})"_format(
py::module::import("builtins").attr("ord")(missing),
missing.attr("encode")("ascii", "namereplace").attr("decode")())
.cast<std::string>());
}
}
bytes_pos = next_bytes_pos;
Expand Down
4 changes: 2 additions & 2 deletions ext/_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -903,8 +903,8 @@ void warn_on_missing_glyph(std::string s)
{
PY_CHECK(
PyErr_WarnEx,
nullptr,
"Requested glyph ({}) missing from current font."_format(s)
PyExc_UserWarning,
"Glyph {} missing from current font."_format(s)
.cast<std::string>().c_str(),
1);
}
Expand Down
9 changes: 7 additions & 2 deletions src/mplcairo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ def _print_vector(self, renderer_factory,
def _print_ps_impl(self, is_eps, path_or_stream, *,
metadata=None, orientation="portrait", papertype=None,
**kwargs):
# FIXME: papertype seems currently broken.
if papertype is None:
papertype = mpl.rcParams["ps.papersize"]
if orientation == "portrait":
Expand Down Expand Up @@ -342,11 +343,15 @@ def _print_ps_impl(self, is_eps, path_or_stream, *,
with TemporaryDirectory() as tmp_dirname:
tmp_name = Path(tmp_dirname, "tmp")
print_method(tmp_name, metadata=metadata, **kwargs)
# Assume we can get away without passing the bbox.
# Assume we can get away with just passing bbox width/height.
wh = (self.figure.bbox.width, self.figure.bbox.height)
if orientation == "landscape":
wh = wh[::-1]
{"ghostscript": backend_ps.gs_distill,
"xpdf": backend_ps.xpdf_distill}[
mpl.rcParams["ps.usedistiller"]](
str(tmp_name), is_eps, ptype=papertype)
str(tmp_name), is_eps, ptype=papertype,
bbox=(None, None, *wh))
# If path_or_stream is *already* a text-mode stream then
# tmp_name needs to be opened in text-mode too.
with cbook.open_file_cm(path_or_stream, "wb") as stream, \
Expand Down

0 comments on commit 1899f17

Please sign in to comment.