]> git.tdb.fi Git - ttf2png.git/commitdiff
Improve glyph details output with -vv
authorMikko Rasa <tdb@tdb.fi>
Sat, 14 Apr 2018 13:29:08 +0000 (16:29 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 14 Apr 2018 13:29:08 +0000 (16:29 +0300)
The code point is now printed in the standard Unicode syntax.  A UTF-8
encoded character is also printed when applicable.

ttf2png.c

index 7cd94551202ff74897f2687a0d8dc597adc1b5ae..58b901666a282e4e1aee2805f1d53741a5a10568 100644 (file)
--- 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)
+                                       utf8[j] = 0x80 | ((i>>((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)
                {