@@ -162,9 +162,19 @@ FT2Image::draw_rect_filled(unsigned long x0, unsigned long y0, unsigned long x1,
162162
163163inline double conv (long v)
164164{
165- return double (v) / 64.0 ;
165+ return v / 64 .;
166166}
167167
168+ static FT_UInt ft_get_char_index_or_warn (FT_Face face, FT_ULong charcode)
169+ {
170+ FT_UInt glyph_index = FT_Get_Char_Index (face, charcode);
171+ if (!glyph_index) {
172+ PyErr_WarnFormat (NULL , 1 , " Glyph %lu missing from current font." , charcode);
173+ }
174+ return glyph_index;
175+ }
176+
177+
168178int FT2Font::get_path_count ()
169179{
170180 // get the glyph as a path, a list of (COMMAND, *args) as described in matplotlib.path
@@ -610,7 +620,7 @@ void FT2Font::set_text(
610620 FT_BBox glyph_bbox;
611621 FT_Pos last_advance;
612622
613- glyph_index = FT_Get_Char_Index (face, codepoints[n]);
623+ glyph_index = ft_get_char_index_or_warn (face, codepoints[n]);
614624
615625 // retrieve kerning distance and move pen position
616626 if (use_kerning && previous && glyph_index) {
@@ -663,7 +673,8 @@ void FT2Font::set_text(
663673
664674void FT2Font::load_char (long charcode, FT_Int32 flags)
665675{
666- int error = FT_Load_Char (face, (unsigned long )charcode, flags);
676+ FT_UInt glyph_index = ft_get_char_index_or_warn (face, (FT_ULong)charcode);
677+ int error = FT_Load_Glyph (face, glyph_index, flags);
667678
668679 if (error) {
669680 throw std::runtime_error (" Could not load charcode" );
0 commit comments