From 7e78e3535d807df01c113e4a870082d79d9ecf49 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 14 Apr 2018 16:29:08 +0300 Subject: [PATCH] Improve glyph details output with -vv The code point is now printed in the standard Unicode syntax. A UTF-8 encoded character is also printed when applicable. --- ttf2png.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/ttf2png.c b/ttf2png.c index 7cd9455..58b9016 100644 --- a/ttf2png.c +++ b/ttf2png.c @@ -466,7 +466,25 @@ int init_font(Font *font, FT_Face face, unsigned first, unsigned last, bool auto FT_Render_Glyph(face->glyph, FT_RENDER_MODE_NORMAL); if(verbose>=2) - printf(" Char %u: glyph %u, size %dx%d\n", i, n, bmp->width, bmp->rows); + { + printf(" Code point U+%04X", i); + if(i>=0x20 && i<0x7F) + printf(" (%c)", i); + else if(i>=0xA0 && i<=0x10FFFF) + { + char utf8[5]; + unsigned bytes; + + for(bytes=2; i>>(1+bytes*5); ++bytes) ; + for(j=0; j>((bytes-j-1)*6))&0x3F); + utf8[0] |= 0xF0<<(4-bytes); + utf8[j] = 0; + + printf(" (%s)", utf8); + } + printf(": glyph %u, size %dx%d\n", n, bmp->width, bmp->rows); + } if(bmp->pixel_mode!=FT_PIXEL_MODE_GRAY) { -- 2.43.0