From be1d7dd70c14f60ceb56147b5036059b4b29fcec Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Mon, 28 Jan 2013 12:41:23 -0500 Subject: [PATCH 1/2] Fix #1710. When a font doesn't have glyph names, we should synthesize them. --- src/ft2font.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/ft2font.cpp b/src/ft2font.cpp index 19e18e67914a..e4a8d2399886 100644 --- a/src/ft2font.cpp +++ b/src/ft2font.cpp @@ -1616,15 +1616,17 @@ FT2Font::get_glyph_name(const Py::Tuple & args) _VERBOSE("FT2Font::get_glyph_name"); args.verify_length(1); - if (!FT_HAS_GLYPH_NAMES(face)) - { - throw Py::RuntimeError("Face has no glyph names"); - } - char buffer[128]; - if (FT_Get_Glyph_Name(face, (FT_UInt) (unsigned long)Py::Int(args[0]), buffer, 128)) + FT_UInt glyph_number = Py::Int(args[0]); + + if (!FT_HAS_GLYPH_NAMES(face)) { - throw Py::RuntimeError("Could not get glyph names."); + snprintf(buffer, 128, "uni%04x", glyph_number); + } else { + if (FT_Get_Glyph_Name(face, glyph_number, buffer, 128)) + { + throw Py::RuntimeError("Could not get glyph names."); + } } return Py::String(buffer); } From d5710a48f80df0ba0e96c6575635a04cb8480062 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Mon, 28 Jan 2013 13:03:37 -0500 Subject: [PATCH 2/2] Fix for Python 3 --- src/ft2font.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ft2font.cpp b/src/ft2font.cpp index e4a8d2399886..659736405f78 100644 --- a/src/ft2font.cpp +++ b/src/ft2font.cpp @@ -1617,7 +1617,7 @@ FT2Font::get_glyph_name(const Py::Tuple & args) args.verify_length(1); char buffer[128]; - FT_UInt glyph_number = Py::Int(args[0]); + FT_UInt glyph_number = (FT_UInt)(unsigned long long)Py::Int(args[0]); if (!FT_HAS_GLYPH_NAMES(face)) {