freetype-devel
[Top][All Lists]
Advanced

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

[Devel] kerning question


From: Brian G. Rhodes
Subject: [Devel] kerning question
Date: Wed, 02 Jun 2004 06:55:16 -0500

With quite a few truetype fonts that have kerning, I've found that in
most cases where two glyphs such as AV have kerning (V), VA will not. 
Such that the string AVA will look more like AV A than AVA.  Is this
typical, or am I perhaps doing something incorrectly.  I am using
freetype 2.1.8.

  if (FT_Init_FreeType(&library))
    return -1;

  if (FT_New_Face(library, font_path, 0, &face))
    return -1;

  FT_Select_Charmap(face, FT_ENCODING_UNICODE);

  FT_Set_Char_Size(face, 0, size * 64, 100, 0);
  slot = face->glyph;
  
  len = strlen(text);

  for (i=0; i<len; i++)
    {
      
      {
        char      c = text[i];
        FT_BBox   bbox;
        FT_Glyph  glyph;
        

        FT_Load_Char(face, c, FT_LOAD_RENDER);
        
        new = __image_create(&slot->bitmap, 0, 0);
        
        FT_Get_Glyph(slot, &glyph);
        FT_Glyph_Get_CBox(glyph, ft_glyph_bbox_pixels, &bbox);
        
        new->xmin = bbox.xMin;
        new->ymin = bbox.yMin;
        new->xmax = bbox.xMax;
        new->ymax = bbox.yMax;
        
        //  get kerning
        
        if (last)
          {
            FT_Vector kerning;
            FT_UInt   left_index, right_index;
            
            left_index  = FT_Get_Char_Index(face, last->ch);
            right_index = FT_Get_Char_Index(face, c);
            
            FT_Get_Kerning(face, left_index, right_index, FT_KERNING_DEFAULT,
&kerning);
            new->kern_x = kerning.x >> 6;
            //debug("font.c", "%c, %d\n", c, kerning.x >> 6);
          }

        new->ch    = c;
        new->next  = 0;
        
        //  add to char list
        
        if (!(string))
          string = new;
        
        else
          {
            ptr = string;
            while (ptr->next)
              {
                ptr = ptr->next;
              }
            
            ptr->next = new;
          }
        
        last = new;
      }
    }
  
  display_image(string, fg, bg, tl, bl, al, x, y, screenwidth, channel,
speed, update_now);

  __font_free(string);
  string = 0;
  last   = 0;

  FT_Done_Face(face);
  FT_Done_FreeType(library);




reply via email to

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