Skip to content
Open
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
8 changes: 7 additions & 1 deletion lib/matplotlib/tests/test_ft2font.py
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,12 @@ def test_ft2font_loading():
file = fm.findfont('DejaVu Sans')
font = ft2font.FT2Font(file)
font.set_size(12, 72)
with pytest.warns(UserWarning,
match=r'Glyph 6504 \(\\N{TAI LE LETTER OO}\) missing from '
r'font\(s\) DejaVu Sans\.'):
with pytest.raises(RuntimeError, match='failed to find glyph to load'):
# Character doesn't exist in DejaVu Sans, and no fallback defined.
font.load_char(0x1968)
for glyph in [font.load_char(ord('M')),
font.load_glyph(font.get_char_index(ord('M')))]:
assert glyph is not None
Expand All @@ -946,7 +952,7 @@ def test_ft2font_loading():
assert glyph.vertBearingY == 64
assert glyph.vertAdvance == 832
assert glyph.bbox == (54, 0, 574, 576)
assert font.get_num_glyphs() == 2 # Both count as loaded.
assert font.get_num_glyphs() == 2 # Both valid glyphs count as loaded.
# But neither has been placed anywhere.
assert font.get_width_height() == (0, 0)
assert font.get_descent() == 0
Expand Down
8 changes: 6 additions & 2 deletions src/ft2font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,9 +535,13 @@ void FT2Font::load_char(long charcode, FT_Int32 flags, FT2Font *&ft_object, bool
ft_glyph_warn(charcode, glyph_seen_fonts);
if (charcode_error) {
THROW_FT_ERROR("charcode loading", charcode_error);
}
else if (glyph_error) {
} else if (glyph_error) {
THROW_FT_ERROR("charcode loading", glyph_error);
} else {
throw std::runtime_error{
"charcode loading (ft2font.cpp line " + std::to_string(__LINE__) +
") failed to find glyph to load"
};
}
} else if (ft_object_with_glyph->warn_if_used) {
ft_glyph_warn(charcode, glyph_seen_fonts);
Expand Down
4 changes: 4 additions & 0 deletions src/ft2font_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ const char *PyGlyph__doc__ = R"""(
static PyGlyph *
PyGlyph_from_FT2Font(const FT2Font *font)
{
if (font == nullptr || font->get_num_glyphs() == 0) {
throw std::runtime_error("No glyphs have been loaded.");
}

const FT_Face &face = font->get_face();
const FT_Glyph &glyph = font->get_last_glyph();

Expand Down
Loading