⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aflatin.c

📁 奇趣公司比较新的qt/emd版本
💻 C
📖 第 1 页 / 共 5 页
字号:
      }      /* insert maximum segment */      if ( max_point )      {        /* clear all segment fields */        error = af_axis_hints_new_segment( axis, memory, &segment );        if ( error )          goto Exit;        segment[0]     = seg0;        segment->dir   = segment_dir;        segment->first = max_point;        segment->last  = max_point;        segment->pos   = max_pos;        segment = NULL;      }    }#endif /* AF_HINT_METRICS */  Exit:    return error;  }  FT_LOCAL_DEF( void )  af_latin_hints_link_segments( AF_GlyphHints  hints,                                AF_Dimension   dim )  {    AF_AxisHints  axis          = &hints->axis[dim];    AF_Segment    segments      = axis->segments;    AF_Segment    segment_limit = segments + axis->num_segments;    FT_Pos        len_threshold, len_score;    AF_Segment    seg1, seg2;    len_threshold = AF_LATIN_CONSTANT( hints->metrics, 8 );    if ( len_threshold == 0 )      len_threshold = 1;    len_score = AF_LATIN_CONSTANT( hints->metrics, 6000 );    /* now compare each segment to the others */    for ( seg1 = segments; seg1 < segment_limit; seg1++ )    {      /* the fake segments are introduced to hint the metrics -- */      /* we must never link them to anything                     */      if ( seg1->first == seg1->last )        continue;      for ( seg2 = seg1 + 1; seg2 < segment_limit; seg2++ )        if ( seg1->dir + seg2->dir == 0 )        {          FT_Pos  pos1 = seg1->pos;          FT_Pos  pos2 = seg2->pos;          FT_Pos  dist = pos2 - pos1;          if ( dist < 0 )            dist = -dist;          {            FT_Pos  min = seg1->min_coord;            FT_Pos  max = seg1->max_coord;            FT_Pos  len, score;            if ( min < seg2->min_coord )              min = seg2->min_coord;            if ( max > seg2->max_coord )              max = seg2->max_coord;            len = max - min;            if ( len >= len_threshold )            {              score = dist + len_score / len;              if ( score < seg1->score )              {                seg1->score = score;                seg1->link  = seg2;              }              if ( score < seg2->score )              {                seg2->score = score;                seg2->link  = seg1;              }            }          }        }    }    /* now, compute the `serif' segments */    for ( seg1 = segments; seg1 < segment_limit; seg1++ )    {      seg2 = seg1->link;      if ( seg2 )      {        if ( seg2->link != seg1 )        {          seg1->link  = 0;          seg1->serif = seg2->link;        }      }    }  }  FT_LOCAL_DEF( FT_Error )  af_latin_hints_compute_edges( AF_GlyphHints  hints,                                AF_Dimension   dim )  {    AF_AxisHints  axis   = &hints->axis[dim];    FT_Error      error  = AF_Err_Ok;    FT_Memory     memory = hints->memory;    AF_LatinAxis  laxis  = &((AF_LatinMetrics)hints->metrics)->axis[dim];    AF_Segment    segments      = axis->segments;    AF_Segment    segment_limit = segments + axis->num_segments;    AF_Segment    seg;    AF_Direction  up_dir;    FT_Fixed      scale;    FT_Pos        edge_distance_threshold;    FT_Pos        segment_length_threshold;    axis->num_edges = 0;    scale = ( dim == AF_DIMENSION_HORZ ) ? hints->x_scale                                         : hints->y_scale;    up_dir = ( dim == AF_DIMENSION_HORZ ) ? AF_DIR_UP                                          : AF_DIR_RIGHT;    /*     *  We ignore all segments that are less than 1 pixels in length,     *  to avoid many problems with serif fonts.  We compute the     *  corresponding threshold in font units.     */    if ( dim == AF_DIMENSION_HORZ )        segment_length_threshold = FT_DivFix( 64, hints->y_scale );    else        segment_length_threshold = 0;    /*********************************************************************/    /*                                                                   */    /* We will begin by generating a sorted table of edges for the       */    /* current direction.  To do so, we simply scan each segment and try */    /* to find an edge in our table that corresponds to its position.    */    /*                                                                   */    /* If no edge is found, we create and insert a new edge in the       */    /* sorted table.  Otherwise, we simply add the segment to the edge's */    /* list which will be processed in the second step to compute the    */    /* edge's properties.                                                */    /*                                                                   */    /* Note that the edges table is sorted along the segment/edge        */    /* position.                                                         */    /*                                                                   */    /*********************************************************************/    edge_distance_threshold = FT_MulFix( laxis->edge_distance_threshold,                                         scale );    if ( edge_distance_threshold > 64 / 4 )      edge_distance_threshold = 64 / 4;    edge_distance_threshold = FT_DivFix( edge_distance_threshold,                                         scale );    for ( seg = segments; seg < segment_limit; seg++ )    {      AF_Edge  found = 0;      FT_Int   ee;      if ( seg->height < segment_length_threshold )        continue;      /* A special case for serif edges: If they are smaller than */      /* 1.5 pixels we ignore them.                               */      if ( seg->serif                                     &&           2 * seg->height < 3 * segment_length_threshold )        continue;      /* look for an edge corresponding to the segment */      for ( ee = 0; ee < axis->num_edges; ee++ )      {        AF_Edge  edge = axis->edges + ee;        FT_Pos   dist;        dist = seg->pos - edge->fpos;        if ( dist < 0 )          dist = -dist;        if ( dist < edge_distance_threshold )        {          found = edge;          break;        }      }      if ( !found )      {        AF_Edge   edge;        /* insert a new edge in the list and */        /* sort according to the position    */        error = af_axis_hints_new_edge( axis, seg->pos, memory, &edge );        if ( error )          goto Exit;        /* add the segment to the new edge's list */        FT_ZERO( edge );        edge->first    = seg;        edge->last     = seg;        edge->fpos     = seg->pos;        edge->opos     = edge->pos = FT_MulFix( seg->pos, scale );        seg->edge_next = seg;      }      else      {        /* if an edge was found, simply add the segment to the edge's */        /* list                                                       */        seg->edge_next         = found->first;        found->last->edge_next = seg;        found->last            = seg;      }    }    /*********************************************************************/    /*                                                                   */    /* Good, we will now compute each edge's properties according to     */    /* segments found on its position.  Basically, these are:            */    /*                                                                   */    /*  - edge's main direction                                          */    /*  - stem edge, serif edge or both (which defaults to stem then)    */    /*  - rounded edge, straight or both (which defaults to straight)    */    /*  - link for edge                                                  */    /*                                                                   */    /*********************************************************************/    /* first of all, set the `edge' field in each segment -- this is */    /* required in order to compute edge links                       */    /*     * Note that removing this loop and setting the `edge' field of each     * segment directly in the code above slows down execution speed for     * some reasons on platforms like the Sun.     */    {      AF_Edge  edges      = axis->edges;      AF_Edge  edge_limit = edges + axis->num_edges;      AF_Edge  edge;      for ( edge = edges; edge < edge_limit; edge++ )      {        seg = edge->first;        if ( seg )          do          {            seg->edge = edge;            seg       = seg->edge_next;          } while ( seg != edge->first );      }      /* now, compute each edge properties */      for ( edge = edges; edge < edge_limit; edge++ )      {        FT_Int  is_round    = 0;  /* does it contain round segments?    */        FT_Int  is_straight = 0;  /* does it contain straight segments? */        FT_Pos  ups         = 0;  /* number of upwards segments         */        FT_Pos  downs       = 0;  /* number of downwards segments       */        seg = edge->first;        do        {          FT_Bool  is_serif;          /* check for roundness of segment */          if ( seg->flags & AF_EDGE_ROUND )            is_round++;          else            is_straight++;          /* check for segment direction */          if ( seg->dir == up_dir )            ups   += seg->max_coord-seg->min_coord;          else            downs += seg->max_coord-seg->min_coord;          /* check for links -- if seg->serif is set, then seg->link must */          /* be ignored                                                   */          is_serif = (FT_Bool)( seg->serif               &&                                seg->serif->edge         &&                                seg->serif->edge != edge );          if ( ( seg->link && seg->link->edge != NULL ) || is_serif )          {            AF_Edge     edge2;            AF_Segment  seg2;            edge2 = edge->link;            seg2  = seg->link;            if ( is_serif )            {              seg2  = seg->serif;              edge2 = edge->serif;            }            if ( edge2 )            {              FT_Pos  edge_delta;              FT_Pos  seg_delta;              edge_delta = edge->fpos - edge2->fpos;              if ( edge_delta < 0 )                edge_delta = -edge_delta;              seg_delta = seg->pos - seg2->pos;              if ( seg_delta < 0 )                seg_delta = -seg_delta;              if ( seg_delta < edge_delta )                edge2 = seg2->edge;            }            else              edge2 = seg2->edge;            if ( is_serif )            {              edge->serif   = edge2;              edge2->flags |= AF_EDGE_SERIF;            }            else              edge->link  = edge2;          }          seg = seg->edge_next;        } while ( seg != edge->first );        /* set the round/straight flags */        edge->flags = AF_EDGE_NORMAL;        if ( is_round > 0 && is_round >= is_straight )          edge->flags |= AF_EDGE_ROUND;        /* set the edge's main direction */        edge->dir = AF_DIR_NONE;        if ( ups > downs )          edge->dir = (FT_Char)up_dir;        else if ( ups < downs )          edge->dir = (FT_Char)-up_dir;        else if ( ups == downs )          edge->dir = 0;  /* both up and down! */        /* gets rid of serifs if link is set                */        /* XXX: This gets rid of many unpleasant artefacts! */        /*      Example: the `c' in cour.pfa at size 13     */        if ( edge->serif && edge->link )          edge->serif = 0;      }    }  Exit:    return error;  }  FT_LOCAL_DEF( FT_Error )  af_latin_hints_detect_features( AF_GlyphHints  hints,                                  AF_Dimension   dim )  {    FT_Error  error;    error = af_latin_hints_compute_segments( hints, dim );    if ( !error )    {      af_latin_hints_link_segments( hints, dim );      error = af_latin_hints_compute_edges( hints, dim );    }    return error;  }  FT_LOCAL_DEF( void )  af_latin_hints_compute_blue_edges( AF_GlyphHints    hints,                                     AF_LatinMetrics  metrics )  {    AF_AxisHints  axis       = &hints->axis[ AF_DIMENSION_VERT ];    AF_Edge       edge       = axis->edges;    AF_Edge       edge_limit = edge + axis->num_edges;    AF_LatinAxis  latin      = &metrics->axis[ AF_DIMENSION_VERT ];    FT_Fixed      scale      = latin->scale;    /* compute which blue zones are active, i.e. have their scaled */    /* size < 3/4 pixels                                           */    /* for each horizontal edge search the blue zone which is closest */    for ( ; edge < edge_limit; edge++ )    {      FT_Int    bb;      AF_Width  best_blue = NULL;      FT_Pos    best_dist;  /* initial threshold */      /* compute the initial threshold as a fraction of the EM size */      best_dist = FT_MulFix( metrics->units_per_em / 40, scale );      if ( best_dist > 64 / 2 )        best_dist = 64 / 2;      for ( bb = 0; bb < AF_LATIN_BLUE_MAX; bb++ )      {        AF_LatinBlue  blue = latin->blues + bb;        FT_Bool       is_top_blue, is_major_dir;        /* skip inactive blue zones (i.e., those that are too small) */        if ( !( blue->flags & AF_LATIN_BLUE_ACTIVE ) )          continue;        /* if it is a top zone, check for right edges -- if it is a bottom */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -