freetype-commit
[Top][All Lists]
Advanced

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

[freetype2-demos] master dc1ded1 2/2: [ftgrid] Direct outline drawing.


From: Alexei Podtelezhnikov
Subject: [freetype2-demos] master dc1ded1 2/2: [ftgrid] Direct outline drawing.
Date: Wed, 19 Jun 2019 23:34:39 -0400 (EDT)

branch: master
commit dc1ded1be7be37ccc7872ba83ed0f5fb0005d49d
Author: Alexei Podtelezhnikov <address@hidden>
Commit: Alexei Podtelezhnikov <address@hidden>

    [ftgrid] Direct outline drawing.
    
    Now we can test `FT_RASTER_FLAG_DIRECT' and it is also faster because
    the glyph outline image is extremely sparse.
    
    * src/ftcommon.[hc] (FTDemo_Sketch_Glyph_Color): Implement rendering
    in direct mode.
    * src/ftgrid.c (grid_status_draw_outline): Use it.
---
 ChangeLog      | 11 +++++++++++
 src/ftcommon.c | 39 +++++++++++++++++++++++++++++++++++++++
 src/ftcommon.h | 10 ++++++++++
 src/ftgrid.c   |  5 +++--
 4 files changed, 63 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index b0e7256..e9f0b09 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2019-06-19  Alexei Podtelezhnikov  <address@hidden>
 
+       [ftgrid] Direct outline drawing.
+
+       Now we can test `FT_RASTER_FLAG_DIRECT' and it is also faster because
+       the glyph outline image is extremely sparse.
+
+       * src/ftcommon.[hc] (FTDemo_Sketch_Glyph_Color): Implement rendering
+       in direct mode.
+       * src/ftgrid.c (grid_status_draw_outline): Use it.
+
+2019-06-19  Alexei Podtelezhnikov  <address@hidden>
+
        [graph] Implement and register gray_span function.
 
        * graph/gblspans.h, graph/gblany.h (_gblender_spans_*): New functions.
diff --git a/src/ftcommon.c b/src/ftcommon.c
index 19de19f..85762e6 100644
--- a/src/ftcommon.c
+++ b/src/ftcommon.c
@@ -1725,6 +1725,45 @@
   }
 
 
+  FT_Error
+  FTDemo_Sketch_Glyph_Color( FTDemo_Handle*     handle,
+                             FTDemo_Display*    display,
+                             FT_Glyph           glyph,
+                             FT_Pos             x,
+                             FT_Pos             y,
+                             grColor            color )
+  {
+    grSurface*        surface = (grSurface*)display->surface;
+    FT_Raster_Params  params;
+    FT_Outline*       outline;
+
+
+    if ( glyph->format != FT_GLYPH_FORMAT_OUTLINE )
+      return FT_Err_Ok;
+
+    outline = &((FT_OutlineGlyph)glyph)->outline;
+
+    FT_Outline_Translate( outline, x, display->bitmap->rows * 64 - y );
+
+    params.source        = outline;
+    params.flags         = FT_RASTER_FLAG_AA     |
+                           FT_RASTER_FLAG_DIRECT |
+                           FT_RASTER_FLAG_CLIP;
+    params.gray_spans    = (FT_SpanFunc)surface->gray_spans;
+    params.user          = surface;
+    params.clip_box.xMin = 0;
+    params.clip_box.yMin = 0;
+    params.clip_box.xMax = display->bitmap->width;
+    params.clip_box.yMax = display->bitmap->rows;
+
+    surface->gcolor = ((GBlenderPixel)color.chroma[0] << 16) |
+                      ((GBlenderPixel)color.chroma[1] << 8 ) |
+                      ((GBlenderPixel)color.chroma[2]      ) ;
+
+    return FT_Outline_Render( handle->library, outline, &params );
+  }
+
+
   unsigned long
   FTDemo_Make_Encoding_Tag( const char*  s )
   {
diff --git a/src/ftcommon.h b/src/ftcommon.h
index f9bdf5e..c12ea3e 100644
--- a/src/ftcommon.h
+++ b/src/ftcommon.h
@@ -374,6 +374,16 @@
                       int                     center_y );
 
 
+  /* draw an outline glyph directly onto display surface */
+  FT_Error
+  FTDemo_Sketch_Glyph_Color( FTDemo_Handle*     handle,
+                             FTDemo_Display*    display,
+                             FT_Glyph           glyph,
+                             FT_Pos             x,
+                             FT_Pos             y,
+                             grColor            color );
+
+
   /* make a FT_Encoding tag from a string */
   unsigned long
   FTDemo_Make_Encoding_Tag( const char*  s );
diff --git a/src/ftgrid.c b/src/ftgrid.c
index 8dab729..a6b1c4b 100644
--- a/src/ftgrid.c
+++ b/src/ftgrid.c
@@ -681,8 +681,9 @@
         FT_Get_Glyph( slot, &glyph );
         FT_Glyph_Stroke( &glyph, st->stroker, 1 );
 
-        error = FTDemo_Draw_Glyph_Color( handle, display, glyph, &ox, &oy,
-                                         st->outline_color );
+        error = FTDemo_Sketch_Glyph_Color( handle, display, glyph,
+                                           ox * 64, oy * 64,
+                                           st->outline_color );
         if ( !error )
           FT_Done_Glyph( glyph );
       }



reply via email to

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