freetype-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[freetype2-demos] master e51a6b3 1/2: * src/ftlint.c (main): Report bitm


From: Werner Lemberg
Subject: [freetype2-demos] master e51a6b3 1/2: * src/ftlint.c (main): Report bitmap size, improve output formatting.
Date: Mon, 14 Jun 2021 23:35:57 -0400 (EDT)

branch: master
commit e51a6b390dae21f0b9116508cc4d9a27d718d4af
Author: Alexei Podtelezhnikov <apodtele@gmail.com>
Commit: Alexei Podtelezhnikov <apodtele@gmail.com>

    * src/ftlint.c (main): Report bitmap size, improve output formatting.
    (Checksum): Updated.
---
 ChangeLog    |  7 ++++-
 src/ftlint.c | 88 +++++++++++++++++++++++++++++-------------------------------
 2 files changed, 49 insertions(+), 46 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index dff7aeb..d4c04a7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,11 @@
 2021-06-14  Alexei Podtelezhnikov  <apodtele@gmail.com>
 
-       * bin/ftlint.c (main): Implement limited indexing.
+       * src/ftlint.c (main): Report bitmap size, improve output formatting.
+       (Checksum): Updated.
+
+2021-06-14  Alexei Podtelezhnikov  <apodtele@gmail.com>
+
+       * src/ftlint.c (main): Implement limited indexing.
        (Usage): Document it.
 
 2021-06-13  Sarthak Bhardwaj  <1sarthakbhardwaj@gmail.com>
diff --git a/src/ftlint.c b/src/ftlint.c
index 1a6311c..01a4e4f 100644
--- a/src/ftlint.c
+++ b/src/ftlint.c
@@ -68,41 +68,23 @@
     exit(1);
   }
 
+
+  /* Calculate MD5 checksum; bitmap should have positive pitch */
   static void
-  Checksum( FT_GlyphSlot glyph )
+  Checksum( FT_Bitmap* bitmap )
   {
-      FT_Bitmap  bitmap;
-      FT_Error err;
-      FT_Bitmap_Init( &bitmap );
-
-
-      printf( "#%u ", glyph->glyph_index );
-
-      err = FT_Bitmap_Convert( library, &glyph->bitmap, &bitmap, 1 );
-      if ( !err )
-      {
-        MD5_CTX        ctx;
-        unsigned char  md5[16];
-        int            i;
-        int            rows  = (int)bitmap.rows;
-        int            pitch = bitmap.pitch;
-
-        MD5_Init( &ctx );
-        if ( bitmap.buffer )
-          MD5_Update( &ctx, bitmap.buffer,
-                      (unsigned long)rows * (unsigned long)pitch );
-        MD5_Final( md5, &ctx );
-
-        for ( i = 0; i < 16; i++ )
-        {
-          printf( "%02X", md5[i] );
-        }
-        printf( "\n" );
-      }
-      else
-        printf("Error generating checksums\n");
-
-      FT_Bitmap_Done( library, &bitmap );
+    MD5_CTX        ctx;
+    unsigned char  md5[16];
+    int            i;
+
+    MD5_Init( &ctx );
+    if ( bitmap->buffer )
+      MD5_Update( &ctx, bitmap->buffer,
+                  (unsigned long)bitmap->rows * (unsigned long)bitmap->pitch );
+    MD5_Final( md5, &ctx );
+
+    for ( i = 0; i < 16; i++ )
+       printf( "%02X", md5[i] );
   }
 
 
@@ -270,21 +252,37 @@
         Panic( "Could not set character size" );
 
       Fail = 0;
+      for ( id = first_index; id <= last_index; id++ )
       {
-        for ( id = first_index; id <= last_index; id++ )
-        {
-          error = FT_Load_Glyph( face, id, load_flags );
-          if ( error )
-          {
-            if ( Fail < 10 )
-              printf( "glyph %4u: 0x%04x\n" , id, error );
-            Fail++;
-            continue;
-          }
+        FT_Bitmap  bitmap;
+
+
+        printf( "%5u: ", id );
 
-          FT_Render_Glyph( face->glyph, render_mode );
-          Checksum( face->glyph );
+        error = FT_Load_Glyph( face, id, load_flags );
+        if ( error )
+        {
+          printf( "error = 0x%04x\n" , error );
+          Fail++;
+          continue;
         }
+
+        FT_Render_Glyph( face->glyph, render_mode );
+
+        FT_Bitmap_Init( &bitmap );
+
+        /* convert to an 8-bit bitmap with a positive pitch */
+        error = FT_Bitmap_Convert( library, &face->glyph->bitmap, &bitmap, 1 );
+        if ( error )
+          printf( "error = 0x%04x", error );
+        else
+          printf( "%3ux%-4u ", bitmap.width, bitmap.rows );
+
+        Checksum( &bitmap );
+
+        FT_Bitmap_Done( library, &bitmap );
+
+        printf( "\n" );
       }
 
       if ( Fail == 0 )



reply via email to

[Prev in Thread] Current Thread [Next in Thread]