freetype-commit
[Top][All Lists]
Advanced

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

[freetype2-demos] master 2e8477b 4/4: [ftgrid, ftview, ftstring] Add ico


From: Alexei Podtelezhnikov
Subject: [freetype2-demos] master 2e8477b 4/4: [ftgrid, ftview, ftstring] Add icons.
Date: Thu, 15 Oct 2020 23:36:34 -0400 (EDT)

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

    [ftgrid,ftview,ftstring] Add icons.
    
    * src/ftcommon.[ch] (FTDemo_Icon, icon_span): Draw and set icons.
    * src/ftgrid.c, src/ftview.c, src/ftstring.c (main): Add icons.
---
 ChangeLog      |  7 ++++++
 src/ftcommon.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/ftcommon.h |  6 +++++
 src/ftgrid.c   |  1 +
 src/ftstring.c |  1 +
 src/ftview.c   |  1 +
 6 files changed, 86 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index ee49e63..2ddc8b6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2020-10-15  Alexei Podtelezhnikov  <apodtele@gmail.com>
 
+       [ftgrid,ftview,ftstring] Add icons.
+
+       * src/ftcommon.[ch] (FTDemo_Icon, icon_span): Draw and set icons.
+       * src/ftgrid.c, src/ftview.c, src/ftstring.c (main): Add icons.
+
+2020-10-15  Alexei Podtelezhnikov  <apodtele@gmail.com>
+
        [graph/win32] Icon support.
 
        * graph/win32/grwin32.c (gr_win32_surface_set_icon): Implement it.
diff --git a/src/ftcommon.c b/src/ftcommon.c
index 275d6fe..44e4214 100644
--- a/src/ftcommon.c
+++ b/src/ftcommon.c
@@ -571,6 +571,76 @@
   }
 
 
+  static void
+  icon_span( int              y,
+             int              count,
+             const FT_Span*   spans,
+             grBitmap*        icon )
+  {
+    FT_UInt32*      dst_line;
+    FT_UInt32*      dst;
+    FT_UInt32       color = 0xFF7F00;
+    unsigned short  w;
+
+
+    if ( icon->pitch > 0 )
+      y -= icon->rows - 1;
+
+    dst_line = (FT_UInt32*)( icon->buffer - y * icon->pitch );
+
+    for ( ; count--; spans++ )
+      for ( dst = dst_line + spans->x, w = spans->len; w--; dst++ )
+        *dst = ( spans->coverage << 24 ) | color;
+  }
+
+
+  void
+  FTDemo_Icon( FTDemo_Handle*   handle,
+               FTDemo_Display*  display )
+  {
+    FT_Vector   p[] = { { 4, 4}, { 4, 6}, { 8, 8}, { 8,56}, { 4,58},
+                        { 4,60}, {60,60}, {60,48}, {58,48}, {56,56},
+                        {44,56}, {44, 8}, {48, 6}, {48, 4}, {32, 4},
+                        {32, 6}, {36, 8}, {36,56}, {16,56}, {16,36},
+                        {24,36}, {26,40}, {28,40}, {28,28}, {26,28},
+                        {24,32}, {16,32}, {16, 8}, {20, 6}, {20, 4} };
+    char        t[] = { 1,1,1,1,1, 1,1,1,1,1, 1,1,1,1,1,
+                        1,1,1,1,1, 1,1,1,1,1, 1,1,1,1,1 };
+    short       c[] = {29};
+    FT_Outline  FT  = { sizeof( c ) / sizeof( c[0] ),
+                        sizeof( p ) / sizeof( p[0] ),
+                        p, t, c, FT_OUTLINE_NONE };
+    grBitmap    icon = { 0 };
+    grBitmap*   picon = NULL;
+    int         size, i;
+
+    FT_Raster_Params  params = { NULL, NULL,
+                                 FT_RASTER_FLAG_AA | FT_RASTER_FLAG_DIRECT,
+                                 (FT_SpanFunc)icon_span, NULL, NULL, NULL,
+                                 &icon, { 0, 0, 0, 0 } };
+
+
+    while ( ( size = grSetIcon( display->surface, picon ) ) )
+    {
+      grNewBitmap( gr_pixel_mode_rgb32, 256, size, size, &icon );
+      memset( icon.buffer, 0, (size_t)icon.rows * (size_t)icon.pitch );
+
+      for ( i = 0; i < FT.n_points; i++ )
+        FT.points[i].x *= size, FT.points[i].y *= size;
+
+      FT_Outline_Render( handle->library, &FT, &params );
+
+      for ( i = 0; i < FT.n_points; i++ )
+        FT.points[i].x /= size, FT.points[i].y /= size;
+
+      picon = &icon;
+    }
+
+    if ( picon )
+      grDoneBitmap( picon );
+  }
+
+
   FT_Error
   FTDemo_Install_Font( FTDemo_Handle*  handle,
                        const char*     filepath,
diff --git a/src/ftcommon.h b/src/ftcommon.h
index 3645a95..4565dc2 100644
--- a/src/ftcommon.h
+++ b/src/ftcommon.h
@@ -246,6 +246,12 @@
                   FT_String*      str );
 
 
+  /* add FT window icon */
+  void
+  FTDemo_Icon( FTDemo_Handle*   handle,
+               FTDemo_Display*  display );
+
+
   /* install a font */
   FT_Error
   FTDemo_Install_Font( FTDemo_Handle*  handle,
diff --git a/src/ftgrid.c b/src/ftgrid.c
index 360d455..96df1b1 100644
--- a/src/ftgrid.c
+++ b/src/ftgrid.c
@@ -1976,6 +1976,7 @@
 
     grSetTitle( display->surface,
                 "FreeType Glyph Grid Viewer - press ? for help" );
+    FTDemo_Icon( handle, display );
 
     grid_status_display( &status, display );
     grid_status_colors(  &status, display );
diff --git a/src/ftstring.c b/src/ftstring.c
index 97fb79a..cc58d00 100644
--- a/src/ftstring.c
+++ b/src/ftstring.c
@@ -972,6 +972,7 @@
 
     grSetTitle( display->surface,
                 "FreeType String Viewer - press ? for help" );
+    FTDemo_Icon( handle, display );
 
     status.header = NULL;
 
diff --git a/src/ftview.c b/src/ftview.c
index e420365..10319fe 100644
--- a/src/ftview.c
+++ b/src/ftview.c
@@ -2025,6 +2025,7 @@
 
     grSetTitle( display->surface,
                 "FreeType Glyph Viewer - press ? for help" );
+    FTDemo_Icon( handle, display );
 
     status.num_fails = 0;
 



reply via email to

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