freetype-commit
[Top][All Lists]
Advanced

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

[freetype2-demos] color 2696ba1: Color glyph framework and rendering (te


From: Alexei Podtelezhnikov
Subject: [freetype2-demos] color 2696ba1: Color glyph framework and rendering (testing).
Date: Tue, 11 Dec 2018 23:28:27 -0500 (EST)

branch: color
commit 2696ba12a74c7dc31756157b4bb39db817ffe29e
Author: Alexei Podtelezhnikov <address@hidden>
Commit: Alexei Podtelezhnikov <address@hidden>

    Color glyph framework and rendering (testing).
    
    * src/ftstring.c (flower_init): Split into contours and assign colors.
    (Render_String): Render flowers using FT_RENDER_MODE_BGRA.
---
 ChangeLog      |  7 +++++++
 src/ftstring.c | 42 ++++++++++++++++++++++++++++++++----------
 2 files changed, 39 insertions(+), 10 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 23cea5d..dd8e7b3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2018-12-11  Alexei Podtelezhnikov  <address@hidden>
+
+       Color glyph framework and rendering (testing).
+
+       * src/ftstring.c (flower_init): Split into contours and assign colors.
+       (Render_String): Render flowers using FT_RENDER_MODE_BGRA.
+
 2018-11-18  Alexei Podtelezhnikov  <address@hidden>
 
        [ftdiff] Tweak adjustment of spacing.
diff --git a/src/ftstring.c b/src/ftstring.c
index c940269..7efc077 100644
--- a/src/ftstring.c
+++ b/src/ftstring.c
@@ -112,7 +112,7 @@
   static void
   flower_init( FT_Glyph*     glyph,
                FT_F26Dot6    radius,
-               unsigned int  i,
+               unsigned int  n,
                int           v,
                int           w,
                int           reflect,
@@ -122,23 +122,38 @@
     FT_Vector*   vec;
     FT_Vector*   limit;
     char*        tag;
-    FT_Fixed     s = FT_Sin( FT_ANGLE_PI4 / i );
+    FT_Fixed     s = FT_Sin( FT_ANGLE_PI4 / n );
     FT_Pos       b, d, p = 0, q = radius;
+    FT_Color*    color;
+    unsigned int i;
 
 
     FT_New_Glyph( handle->library, FT_GLYPH_FORMAT_OUTLINE, glyph );
 
     outline = &((FT_OutlineGlyph)*glyph)->outline;
 
-    FT_Outline_New( handle->library, 6 * i, 1, outline );
-    outline->contours[0] = outline->n_points - 1;
+    FT_Outline_New( handle->library, 6 * n, n, outline );
+
+    color = (FT_Color*)calloc( n, sizeof (FT_Color) );
+    ((FT_OutlineGlyph)*glyph)->color = color;
+
+    /* split and color contours */
+    for ( i = 0; i < n; i++ )
+    {
+       outline->contours[i] = 6 * i + 5;
+
+       color[i].red   = i & 1 ? 0xFF : 0;
+       color[i].green = i & 2 ? 0xFF : 0;
+       color[i].blue  = i & 4 ? 0xFF : 0;
+       color[i].alpha = 0xFF;
+    }
 
     if ( order == FT_CURVE_TAG_CUBIC )
       q += q / 3;
 
-    for ( vec = outline->points, tag = outline->tags;
-          i--;
-          vec += 6,              tag += 6 )
+    for ( i = 0, vec = outline->points, tag = outline->tags;
+          i < n;
+          i++,   vec += 6,              tag += 6 )
     {
        b = p + FT_MulFix( q, s );
        d = q - FT_MulFix( p, s );
@@ -703,14 +718,21 @@
   static FT_Error
   Render_String( void )
   {
-    int x, y = display->bitmap->rows - 4;
+    FT_Glyph  flower;
+    int       x, y = display->bitmap->rows - 4;
 
 
     x = 4;
-    FTDemo_Draw_Glyph( handle, display, daisy, &x, &y );
+    FT_Glyph_Copy( daisy, &flower );
+    FT_Glyph_To_Bitmap( &flower, FT_RENDER_MODE_BGRA, NULL, 0 );
+    FTDemo_Draw_Glyph( handle, display, flower, &x, &y );
+    FT_Done_Glyph( flower );
 
     x = display->bitmap->width - 4;
-    FTDemo_Draw_Glyph( handle, display, aster, &x, &y );
+    FT_Glyph_Copy( aster, &flower );
+    FT_Glyph_To_Bitmap( &flower, FT_RENDER_MODE_BGRA, NULL, 0 );
+    FTDemo_Draw_Glyph( handle, display, flower, &x, &y );
+    FT_Done_Glyph( flower );
 
     FTDemo_String_Draw( handle, display,
                         &status.sc,



reply via email to

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