freetype-commit
[Top][All Lists]
Advanced

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

[freetype2] anuj-distance-field 320b66f 07/95: [sdf] Added essential enu


From: Anuj Verma
Subject: [freetype2] anuj-distance-field 320b66f 07/95: [sdf] Added essential enums and structs required.
Date: Sun, 2 Aug 2020 01:10:25 -0400 (EDT)

branch: anuj-distance-field
commit 320b66f19131c334336336bf264dc32644bec829
Author: Anuj Verma <anujv@iitbhilai.ac.in>
Commit: Anuj Verma <anujv@iitbhilai.ac.in>

    [sdf] Added essential enums and structs required.
---
 [GSoC]ChangeLog                     |  13 +++
 include/freetype/internal/fttrace.h |   2 +-
 src/sdf/ftsdf.c                     | 157 +++++++++++++++++++++++++++++++++++-
 src/sdf/ftsdfrend.c                 |  36 +++++----
 4 files changed, 187 insertions(+), 21 deletions(-)

diff --git a/[GSoC]ChangeLog b/[GSoC]ChangeLog
index 8e10431..df74a85 100644
--- a/[GSoC]ChangeLog
+++ b/[GSoC]ChangeLog
@@ -1,3 +1,16 @@
+2020-06-25  Anuj Verma  <anujv@iitbhilai.ac.in>
+
+       [sdf] Added essential enums and structs required.
+
+       * src/freetype/internal/fttrace.h: Remove tabs.
+
+       * src/sdf/ftsdfrend.c (ft_sdf_render): Calculate padding
+         using the `spread'.
+
+       * src/sdf/ftsdf.c (SDF_Edge_Type, SDF_Edge, SDF_Contour,
+         SDF_Shape): Added structures and their initializer
+         functions.
+
 2020-06-23  Anuj Verma  <anujv@iitbhilai.ac.in>
 
        [sdf] Added functionality to set and get module properties.
diff --git a/include/freetype/internal/fttrace.h 
b/include/freetype/internal/fttrace.h
index 6caadd3..d0fb482 100644
--- a/include/freetype/internal/fttrace.h
+++ b/include/freetype/internal/fttrace.h
@@ -40,7 +40,7 @@ FT_TRACE_DEF( psprops )   /* PS driver properties    
(ftpsprop.c) */
 FT_TRACE_DEF( raccess )   /* resource fork accessor  (ftrfork.c)  */
 FT_TRACE_DEF( raster )    /* monochrome rasterizer   (ftraster.c) */
 FT_TRACE_DEF( smooth )    /* anti-aliasing raster    (ftgrays.c)  */
-FT_TRACE_DEF( sdf )              /* signed distance raster  (ftsdf.c)    */
+FT_TRACE_DEF( sdf )       /* signed distance raster  (ftsdf.c)   */
 FT_TRACE_DEF( synth )     /* bold/slant synthesizer  (ftsynth.c)  */
 
   /* Cache sub-system */
diff --git a/src/sdf/ftsdf.c b/src/sdf/ftsdf.c
index af18e6b..8f4d550 100644
--- a/src/sdf/ftsdf.c
+++ b/src/sdf/ftsdf.c
@@ -7,6 +7,15 @@
 
   /**************************************************************************
    *
+   * typedefs
+   *
+   */
+
+  typedef  FT_Vector FT_26D6_Vec;   /* with 26.6 fixed point components  */
+  typedef  FT_Vector FT_16D16_Vec;  /* with 16.16 fixed point components */
+
+  /**************************************************************************
+   *
    * structures and enums
    *
    */
@@ -14,8 +23,152 @@
   typedef struct  SDF_TRaster_
   {
     FT_Memory  memory; /* used internally to allocate memory */
+
   } SDF_TRaster;
 
+  /* enumeration of all the types of curve present in vector fonts */
+  typedef enum  SDF_Edge_Type_
+  {
+    SDF_EDGE_UNDEFINED  = 0,  /* undefined, used to initialize */
+    SDF_EDGE_LINE       = 1,  /* straight line segment         */
+    SDF_EDGE_CONIC      = 2,  /* second order bezier curve     */
+    SDF_EDGE_CUBIC      = 3   /* third order bezier curve      */
+
+  } SDF_Edge_Type;
+
+  /* represent a single edge in a contour */
+  typedef struct  SDF_Edge_
+  {
+    FT_26D6_Vec    start_pos;   /* start position of the edge             */
+    FT_26D6_Vec    end_pos;     /* end position of the edge               */
+    FT_26D6_Vec    control_a;   /* first control point of a bezier curve  */
+    FT_26D6_Vec    control_b;   /* second control point of a bezier curve */
+
+    SDF_Edge_Type  edge_type;   /* edge identifier                        */
+
+  } SDF_Edge;
+
+  /* A contour represent a set of edges which make a closed */
+  /* loop.                                                  */
+  typedef struct  SDF_Contour_
+  {
+    FT_26D6_Vec  last_pos;  /* end position of the last edge    */
+    FT_List      edges      /* list of all edges in the contour */
+
+  } SDF_Contour;
+
+  /* Represent a set a contours which makes up a complete */
+  /* glyph outline.                                       */
+  typedef struct  SDF_Shape_
+  {
+    FT_Memory  memory;    /* used internally to allocate memory  */
+    FT_List    contours;  /* list of all contours in the outline */
+
+  } SDF_Shape;
+
+  /**************************************************************************
+   *
+   * constants, initializer and destructor
+   *
+   */
+
+  static
+  const FT_Vector    zero_vector  = { 0, 0 };
+
+  static
+  const SDF_Edge     null_edge    = { { 0, 0 }, { 0, 0 },
+                                      { 0, 0 }, { 0, 0 },
+                                      SDF_EDGE_UNDEFINED };
+
+  static
+  const SDF_Contour  null_contour = { { 0, 0 }, NULL };
+
+  static
+  const SDF_Shape    null_shape   = { NULL, NULL };
+
+  static FT_Error
+  sdf_edge_new( FT_Memory   memory,
+                SDF_Edge**  edge )
+  {
+    FT_Error   error = FT_Err_Ok;
+    SDF_Edge*  ptr   = NULL;
+
+
+    if ( !memory || !edge )
+    {
+      error = FT_THROW( Invalid_Argument );
+      goto Exit;
+    }
+
+    FT_QNEW( ptr );
+    if ( error != FT_Err_Ok )
+      *edge = NULL;
+    else
+    {
+      *ptr = null_edge;
+      *edge = ptr;
+    }
+
+  Exit:
+    return error;
+  }
+
+  static FT_Error
+  sdf_contour_new( FT_Memory      memory,
+                   SDF_Contour**  contour )
+  {
+    FT_Error      error = FT_Err_Ok;
+    SDF_Contour*  ptr   = NULL;
+
+
+    if ( !memory || !contour )
+    {
+      error = FT_THROW( Invalid_Argument );
+      goto Exit;
+    }
+
+    FT_QNEW( ptr );
+    if ( error != FT_Err_Ok )
+      *contour = NULL;
+    else
+    {
+      *ptr = null_contour;
+      FT_QNEW( ptr->edges );
+      *contour = ptr;
+    }
+
+  Exit:
+    return error;
+  }
+
+  static void
+  sdf_shape_new( FT_Memory    memory,
+                 SDF_Shape**  shape )
+  {
+    FT_Error      error = FT_Err_Ok;
+    SDF_Shape*    ptr   = NULL;
+
+
+    if ( !memory || !shape )
+    {
+      error = FT_THROW( Invalid_Argument );
+      goto Exit;
+    }
+
+    FT_QNEW( ptr );
+    if ( error != FT_Err_Ok )
+      *shape = NULL;
+    else
+    {
+      *ptr = null_shape;
+      FT_QNEW( ptr->contours );
+      *shape = ptr;
+    }
+
+  Exit:
+    return error;
+  }
+
   /**************************************************************************
    *
    * interface functions
@@ -56,14 +209,12 @@
                        unsigned long  mode,
                        void*          args )
   {
-    /* Currently there is no use for this function but later */
-    /* it will be used to modify the `spread' parameter.     */
     FT_UNUSED( raster );
     FT_UNUSED( mode );
     FT_UNUSED( args );
 
 
-    return FT_THROW( Unimplemented_Feature );
+    return FT_Err_Ok;
   }
 
   static FT_Error
diff --git a/src/sdf/ftsdfrend.c b/src/sdf/ftsdfrend.c
index 14fb489..b1bda92 100644
--- a/src/sdf/ftsdfrend.c
+++ b/src/sdf/ftsdfrend.c
@@ -48,18 +48,19 @@
 
     if ( ft_strcmp( property_name, "spread" ) == 0 )
     {
-      FT_UInt  val = *(const FT_UInt*)value;
+      FT_Int  val = *(const FT_Int*)value;
 
 
-      if ( val > MAX_SPREAD )
+      if ( val > MAX_SPREAD || val <= 0 )
       {
         FT_TRACE0(( "[sdf module] sdf_property_set: "
                     "the `spread' property can have a "
-                    "maximum value of %d\n", MAX_SPREAD ));
+                    "value within range [1, %d] "
+                    "(value provided %d)\n", MAX_SPREAD, val ));
         error = FT_THROW( Invalid_Argument );
         goto Exit;
       }
-      render->spread = val;
+      render->spread = (FT_UInt)val;
       FT_TRACE7(( "[sdf module] sdf_property_set: "
                   "updated property `spread' to %d\n", val ));
     }
@@ -68,7 +69,6 @@
       FT_TRACE0(( "[sdf module] sdf_property_set: "
                   "missing property `%s'\n", property_name ));
       error = FT_THROW( Missing_Property );
-      goto Exit;
     }
 
   Exit:
@@ -86,7 +86,7 @@
 
     if ( ft_strcmp( property_name, "spread" ) == 0 )
     {
-      FT_UInt*  val = (FT_UInt*)value;
+      FT_Int*  val = (FT_Int*)value;
 
 
       *val = render->spread;
@@ -96,7 +96,6 @@
       FT_TRACE0(( "[sdf module] sdf_property_get: "
                   "missing property `%s'\n", property_name ));
       error = FT_THROW( Missing_Property );
-      goto Exit;
     }
 
   Exit:
@@ -164,9 +163,8 @@
     FT_Pos       x_shift = 0;
     FT_Pos       y_shift = 0;
 
-    /* use hardcoded padding for now */
-    FT_UInt      x_pad   = 10;
-    FT_UInt      y_pad   = 10;
+    FT_UInt      x_pad   = 0;
+    FT_UInt      y_pad   = 0;
 
     FT_Raster_Params  params;
     SDF_Renderer      sdf_module = SDF_RENDERER( module );
@@ -210,9 +208,13 @@
     if ( !bitmap->rows || !bitmap->pitch )
       goto Exit;
 
-    /* apply the padding */
-    bitmap->rows  += y_pad;
-    bitmap->width += x_pad;
+    /* the padding will simply be equal to the `spread' */
+    x_pad = sdf_module->spread;
+    y_pad = sdf_module->spread;
+
+    /* apply the padding, will be in all the directions */
+    bitmap->rows  += y_pad * 2;
+    bitmap->width += x_pad * 2;
 
     /* ignore the pitch, pixel mode and set custom */
     bitmap->pixel_mode = FT_PIXEL_MODE_GRAY16;
@@ -333,10 +335,10 @@
 
     FT_GLYPH_FORMAT_OUTLINE,
 
-    (FT_Renderer_RenderFunc)   ft_sdf_render,     /* render_glyph    */
-    (FT_Renderer_TransformFunc)ft_sdf_transform,  /* transform_glyph */
-    (FT_Renderer_GetCBoxFunc)  ft_sdf_get_cbox,   /* get_glyph_cbox  */
-    (FT_Renderer_SetModeFunc)  ft_sdf_set_mode,   /* set_mode        */
+    (FT_Renderer_RenderFunc)    ft_sdf_render,     /* render_glyph    */
+    (FT_Renderer_TransformFunc) ft_sdf_transform,  /* transform_glyph */
+    (FT_Renderer_GetCBoxFunc)   ft_sdf_get_cbox,   /* get_glyph_cbox  */
+    (FT_Renderer_SetModeFunc)   ft_sdf_set_mode,   /* set_mode        */
 
     (FT_Raster_Funcs*)&ft_sdf_raster              /* raster_class    */
   )



reply via email to

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