This patch adds the -s and -u options to start ftgrid for a given UTF-8 character or unicode code in a font.

diff --git a/src/ftgrid.c b/src/ftgrid.c
index 711da2b..7860c7e 100644
--- a/src/ftgrid.c
+++ b/src/ftgrid.c
@@ -66,6 +66,7 @@ typedef struct  status_
   int          ptsize;
   int          res;
   int          Num;  /* glyph index */
+  FT_UInt32    charcode; /* unicode index */
   int          font_index;
 
   double       scale;
@@ -127,6 +128,7 @@ grid_status_init( GridStatus       st,
   st->do_outline    = 1;
 
   st->Num    = 0;
+  st->charcode = 0;
   st->gamma  = 1.0;
   st->header = "";
 }
@@ -909,6 +911,8 @@ grid_status_draw_outline( GridStatus       st,
     fprintf( stderr,  "\n" );
     fprintf( stderr,  "  -r R      use resolution R dpi (default: 72 dpi)\n" );
     fprintf( stderr,  "  -f index  specify first index to display\n" );
+    fprintf( stderr,  "  -c char   specify first UTF-8 Character to display\n" );
+    fprintf( stderr,  "  -u char   specify first unicode number to display\n" );
     fprintf( stderr,  "\n" );
 
     exit( 1 );
@@ -921,13 +925,14 @@ grid_status_draw_outline( GridStatus       st,
   {
     char*  execname;
     int    option;
+    const char* Text;
 
 
     execname = ft_basename( (*argv)[0] );
 
     while ( 1 )
     {
-      option = getopt( *argc, *argv, "f:r:" );
+      option = getopt( *argc, *argv, "f:r:c:u:" );
 
       if ( option == -1 )
         break;
@@ -944,6 +949,15 @@ grid_status_draw_outline( GridStatus       st,
           usage( execname );
         break;
 
+      case 'c':
+        Text = (const char*)optarg;
+        status.charcode = utf8_next(&Text, Text + strlen(Text));
+        break;
+
+      case 'u':
+        status.charcode = atoi( optarg );
+        break;
+
       default:
         usage( execname );
         break;
@@ -1001,6 +1015,12 @@ grid_status_draw_outline( GridStatus       st,
 
     event_font_change( 0 );
 
+    if ( status.Num == 0 && status.charcode != 0 ) {
+      status.Num = FTDemo_Get_Index( handle, status.charcode );
+      if ( status.Num == 0 )
+        printf( "Could not found the given character in the font.\n" );
+    }
+
     grid_status_rescale_initial( &status, handle );
 
     for ( ;; )
_______________________________________________
Freetype-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/freetype-devel

Reply via email to