Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita5d314f

Browse files
committed
print fontname in missing glyph warning
1 parent21ce592 commita5d314f

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

‎lib/matplotlib/_text_helpers.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
"LayoutItem", ["ft_object","char","glyph_idx","x","prev_kern"])
1313

1414

15-
defwarn_on_missing_glyph(codepoint):
15+
defwarn_on_missing_glyph(codepoint,font_name):
1616
_api.warn_external(
17-
"Glyph {} ({}) missing from current font.".format(
17+
"Glyph {} ({}) missing from current font {}.".format(
1818
codepoint,
19-
chr(codepoint).encode("ascii","namereplace").decode("ascii")))
19+
chr(codepoint).encode("ascii","namereplace").decode("ascii"),
20+
font_name))
2021
block= ("Hebrew"if0x0590<=codepoint<=0x05ffelse
2122
"Arabic"if0x0600<=codepoint<=0x06ffelse
2223
"Devanagari"if0x0900<=codepoint<=0x097felse

‎lib/matplotlib/tests/test_text.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -817,12 +817,14 @@ def test_pdf_kerning():
817817

818818
deftest_unsupported_script(recwarn):
819819
fig=plt.figure()
820-
fig.text(.5,.5,"\N{BENGALI DIGIT ZERO}")
820+
t=fig.text(.5,.5,"\N{BENGALI DIGIT ZERO}")
821+
print(t.get_fontname())
821822
fig.canvas.draw()
822823
assertall(isinstance(warn.message,UserWarning)forwarninrecwarn)
823824
assert (
824825
[warn.message.argsforwarninrecwarn]==
825-
[(r"Glyph 2534 (\N{BENGALI DIGIT ZERO}) missing from current font.",),
826+
[(r"Glyph 2534 (\N{BENGALI DIGIT ZERO}) missing from current font "
827+
+f"{t.get_fontname()}.",),
826828
(r"Matplotlib currently does not support Bengali natively.",)])
827829

828830

‎src/ft2font.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include"ft2font.h"
1212
#include"mplutils.h"
1313
#include"numpy_cpp.h"
14+
#include"py_converters.h"
1415
#include"py_exceptions.h"
1516

1617
#ifndef M_PI
@@ -184,11 +185,13 @@ FT2Image::draw_rect_filled(unsigned long x0, unsigned long y0, unsigned long x1,
184185
m_dirty =true;
185186
}
186187

187-
staticvoidft_glyph_warn(FT_ULong charcode)
188+
staticvoidft_glyph_warn(FT_ULong charcode, FT_String * family_name)
188189
{
190+
constchar* name = (family_name !=NULL)?family_name:"UNAVAILABLE";
189191
PyObject *text_helpers =NULL, *tmp =NULL;
192+
190193
if (!(text_helpers =PyImport_ImportModule("matplotlib._text_helpers")) ||
191-
!(tmp =PyObject_CallMethod(text_helpers,"warn_on_missing_glyph","k", charcode))){
194+
!(tmp =PyObject_CallMethod(text_helpers,"warn_on_missing_glyph","(k, s)", charcode, name))){
192195
gotoexit;
193196
}
194197
exit:
@@ -207,7 +210,7 @@ ft_get_char_index_or_warn(FT_Face face, FT_ULong charcode, bool warn = true)
207210
return glyph_index;
208211
}
209212
if (warn) {
210-
ft_glyph_warn(charcode);
213+
ft_glyph_warn(charcode, face->family_name);
211214
}
212215
return0;
213216
}
@@ -515,7 +518,7 @@ void FT2Font::set_text(
515518
char_to_font, glyph_to_font, codepoints[n], flags,
516519
charcode_error, glyph_error,false);
517520
if (!was_found) {
518-
ft_glyph_warn((FT_ULong)codepoints[n]);
521+
ft_glyph_warn((FT_ULong)codepoints[n], (ft_object_with_glyph->face)->family_name);
519522

520523
// render missing glyph tofu
521524
// come back to top-most font
@@ -582,7 +585,7 @@ void FT2Font::load_char(long charcode, FT_Int32 flags, FT2Font *&ft_object, bool
582585
bool was_found =load_char_with_fallback(ft_object_with_glyph, final_glyph_index, glyphs, char_to_font,
583586
glyph_to_font, charcode, flags, charcode_error, glyph_error,true);
584587
if (!was_found) {
585-
ft_glyph_warn(charcode);
588+
ft_glyph_warn(charcode, (ft_object_with_glyph->face)->family_name);
586589
if (charcode_error) {
587590
throw_ft_error("Could not load charcode", charcode_error);
588591
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp