[prev in list] [next in list] [prev in thread] [next in thread] 

List:       freetype-devel
Subject:    Re: [ft-devel] Any tool that visually present segments of autofit
From:       Just Fill Bugs <mozbugbox () yahoo ! com ! au>
Date:       2011-04-29 5:56:08
Message-ID: ipdjsq$u6h$1 () dough ! gmane ! org
[Download RAW message or body]

On 04/24/2011 02:05 PM, Werner LEMBERG wrote:
> I very much dislike the use of afhints.h and aftypes.h within the user
> space.  Could you instead add debug hooks to afhints.c which can be
> used for communication?  The simplest form could be something like
> these two functions:
>
>    FT_Error
>    af_glyph_hints_get_num_segments(AF_GlyphHints hints,
>                                    int dimension,
>                                    FT_Int* num_segments);
>
>    FT_Error
>    af_glyph_hints_get_segment_offset(AF_GlyphHints hints,
>                                      int dimension,
>                                      FT_Int idx,
>                                      FT_Pos* offset);
>

Okey, I add the accessor functions to afhint.c.

I also made the segment drawing independent of the force autofit mode. I 
found that the segment lines are useful reference with or without 
autofit turned on.

One observation I had is that in order to have the outlines merge with 
the segments into one, I have to

1. turn on force autofit (f)
2. turn of Horizontal and Vertical Hinting (H and V)
3. turn on hinting (h)

Otherwise, there are always some offset between the outlines and the 
segments.




["freetype-autofit-seg-helper.patch" (text/x-patch)]

diff --git a/src/autofit/afhints.c b/src/autofit/afhints.c
index 70c1054..22092b0 100644
--- a/src/autofit/afhints.c
+++ b/src/autofit/afhints.c
@@ -276,6 +276,55 @@
   }
 #endif
 
+  /* Fetch number of segments */
+#ifdef __cplusplus
+  extern "C" {
+#endif
+  FT_Error
+  af_glyph_hints_get_num_segments( AF_GlyphHints hints,
+                                   int dimension,
+                                   FT_Int* num_segments )
+  {
+    FT_Error      error    = AF_Err_Ok;
+    AF_AxisHints  axis     = &hints->axis[dimension];
+
+    *num_segments = axis->num_segments;
+
+    return error;
+  }
+#ifdef __cplusplus
+  }
+#endif
+
+  /* fetch offset of segments. User supply the offset array. */
+#ifdef __cplusplus
+  extern "C" {
+#endif
+  FT_Error
+  af_glyph_hints_get_segment_offset( AF_GlyphHints hints,
+                                     int dimension,
+                                     FT_Int idx,
+                                     FT_Pos* offset )
+  {
+    FT_Error      error    = AF_Err_Ok;
+    AF_AxisHints  axis     = &hints->axis[dimension];
+    AF_Segment    segments = axis->segments;
+    AF_Segment    limit    = segments + idx;
+    AF_Segment    seg;
+
+
+    for ( seg = segments; seg < limit; seg++ )
+    {
+      *offset = dimension == AF_DIMENSION_HORZ ? (int)seg->first->ox
+                                               : (int)seg->first->oy;
+      offset++;
+    }
+
+    return error;
+  }
+#ifdef __cplusplus
+  }
+#endif
 
   /* Dump the array of linked edges. */
 
@@ -348,6 +397,27 @@
     FT_UNUSED( hints );
   }
 
+  FT_Error
+  af_glyph_hints_get_num_segments( AF_GlyphHints hints,
+                                   int dimension,
+                                   FT_Int* num_segments )
+  {
+    FT_UNUSED( hints );
+    FT_UNUSED( dimension );
+    FT_UNUSED( num_segments );
+  }
+
+  FT_Error
+  af_glyph_hints_get_segment_offset( AF_GlyphHints hints,
+                                     int dimension,
+                                     FT_Int idx,
+                                     FT_Pos* offset )
+  {
+    FT_UNUSED( hints );
+    FT_UNUSED( dimension );
+    FT_UNUSED( idx );
+    FT_UNUSED( offset );
+  }
 
   void
   af_glyph_hints_dump_edges( AF_GlyphHints  hints )

["ftgrid-segment.patch" (text/x-patch)]

diff --git a/src/ftgrid.c b/src/ftgrid.c
index 711da2b..ed3a77a 100644
--- a/src/ftgrid.c
+++ b/src/ftgrid.c
@@ -57,6 +57,13 @@
   extern void af_glyph_hints_dump_segments( AF_GlyphHints  hints );
   extern void af_glyph_hints_dump_points( AF_GlyphHints  hints );
   extern void af_glyph_hints_dump_edges( AF_GlyphHints  hints );
+  extern FT_Error af_glyph_hints_get_num_segments( AF_GlyphHints hints,
+                                                   int dimension,
+                                                   FT_Int* num_segments );
+  extern FT_Error af_glyph_hints_get_segment_offset( AF_GlyphHints hints,
+                                                     int dimension,
+                                                     FT_Int idx,
+                                                     FT_Pos* offset );
 #ifdef __cplusplus
   }
 #endif
@@ -87,12 +94,14 @@ typedef struct  status_
   grColor      on_color;
   grColor      conic_color;
   grColor      cubic_color;
+  grColor      segment_color;
 
   int          do_horz_hints;
   int          do_vert_hints;
   int          do_blue_hints;
   int          do_outline;
   int          do_dots;
+  int          do_segment;
 
   double       gamma;
   const char*  header;
@@ -116,6 +125,7 @@ grid_status_init( GridStatus       st,
   st->on_color      = grFindColor( display->bitmap,  64,  64, 255, 255 );
   st->conic_color   = grFindColor( display->bitmap,   0, 128,   0, 255 );
   st->cubic_color   = grFindColor( display->bitmap, 255,  64, 255, 255 );
+  st->segment_color = grFindColor( display->bitmap,  64, 255, 128,  64 );
   st->disp_width    = display->bitmap->width;
   st->disp_height   = display->bitmap->rows;
   st->disp_bitmap   = display->bitmap;
@@ -125,6 +135,7 @@ grid_status_init( GridStatus       st,
   st->do_blue_hints = 1;
   st->do_dots       = 1;
   st->do_outline    = 1;
+  st->do_segment    = 0;
 
   st->Num    = 0;
   st->gamma  = 1.0;
@@ -218,6 +229,48 @@ grid_status_draw_grid( GridStatus  st )
   grFillHLine( st->disp_bitmap, 0, y_org, st->disp_width,  st->axis_color );
 }
 
+static void
+grid_hint_draw_segment( GridStatus       st,
+                        AF_GlyphHints  hints )
+{
+  FT_Int  dimension;
+  FT_Int  num_seg;
+  FT_Pos  *offset;
+  int     x_org   = (int)st->x_origin;
+  int     y_org   = (int)st->y_origin;
+
+
+  for ( dimension = 1; dimension >= 0; dimension-- )
+  {
+    int count;
+    FT_Pos *cur_offset;
+
+
+    af_glyph_hints_get_num_segments( hints, dimension, &num_seg );
+    offset = (FT_Pos*) malloc( num_seg * sizeof( FT_Pos ));
+    af_glyph_hints_get_segment_offset( hints, dimension, num_seg, offset );
+
+    cur_offset = offset;
+    for ( count = 0; count < num_seg; count++, cur_offset++ )
+    {
+      int pos;
+
+      if ( dimension == 0 ) /* AF_DIMENSION_HORZ is 0 */
+      {
+        pos = x_org + (int)(*cur_offset) * st->scale;
+        grFillVLine( st->disp_bitmap, pos, 0,
+            st->disp_height, st->segment_color );
+      }
+      else
+      {
+        pos = y_org - (int)(*cur_offset) * st->scale;
+        grFillHLine( st->disp_bitmap, 0, pos,
+            st->disp_width, st->segment_color );
+      }
+    }
+    free(offset);
+  }
+}
 
 static void
 ft_bitmap_draw( FT_Bitmap*       bitmap,
@@ -396,6 +449,21 @@ grid_status_draw_outline( GridStatus       st,
 
   FTDemo_Get_Size( handle, &size );
 
+  /* Draw segment before draw glyph. */
+  if ( status.do_segment )
+  {
+    /* Force hinting first in order to collect segment info. */
+    _af_debug_disable_horz_hints = 0;
+    _af_debug_disable_vert_hints = 0;
+
+    if ( ! FT_Load_Glyph( size->face, st->Num,
+          ( FT_LOAD_DEFAULT | FT_LOAD_NO_BITMAP |
+            FT_LOAD_FORCE_AUTOHINT | FT_LOAD_TARGET_NORMAL ) ) )
+    {
+      grid_hint_draw_segment ( &status, _af_debug_hints );
+    }
+  }
+
   _af_debug_disable_horz_hints = !st->do_horz_hints;
   _af_debug_disable_vert_hints = !st->do_vert_hints;
 
@@ -501,6 +569,7 @@ grid_status_draw_outline( GridStatus       st,
     grLn();
     grWriteln( "  a          : toggle anti-aliasing" );
     grWriteln( "  f          : toggle forced autofit mode" );
+    grWriteln( "  h          : toggle ignore hinting mode" );
     grWriteln( "  left/right : decrement/increment glyph index" );
     grWriteln( "  up/down    : change character size" );
     grLn();
@@ -522,6 +591,7 @@ grid_status_draw_outline( GridStatus       st,
     grWriteln( "  H          : toggle horizontal hinting" );
     grWriteln( "  V          : toggle vertical hinting" );
     grWriteln( "  B          : toggle blue zone hinting" );
+    grWriteln( "  s          : toggle draw hinting segments" );
 #endif
     grWriteln( "  d          : toggle dots display" );
     grWriteln( "  o          : toggle outline display" );
@@ -780,6 +850,12 @@ grid_status_draw_outline( GridStatus       st,
       else
         status.header = "need autofit mode to toggle blue zone hinting";
       break;
+
+    case grKEY('s'):
+      status.do_segment = !status.do_segment;
+      status.header = status.do_segment ? "segment drawing enabled"
+                                        : "segment drawing disabled";
+      break;
 #endif /* FT_DEBUG_AUTOFIT */
 
 


_______________________________________________
Freetype-devel mailing list
Freetype-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/freetype-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic