freetype-devel
[Top][All Lists]
Advanced

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

[Devel] Help with outlines of fonts


From: Brown Wayne C Civ USAFA/DFCS
Subject: [Devel] Help with outlines of fonts
Date: Mon, 24 Mar 2003 15:15:13 -0700

I wrote code to extract font outlines using Free Type 1 last year with successful results. I am currently trying to write similar code using Free Type 2.1.3. However I cannot seem to access correct outline control points. All of the data seems to be correct except the contour points. I have included my code and a dump of output for the ASCII character '2' using the Arial.ttf font file under Microsoft Windows, compiling using Microsoft Visual C.
 
Can anyone point out my error or problem?
 
Sincerely,
Wayne Brown
 
CODE
/*-------------------------------------------------------------------*/
         int               error;
  static FT_Library        library;
  static FT_Long           face_index = 0;
         FT_Face           face;
         FT_Glyph          glyph;
         FT_UInt           glyph_index;
         int               j;
         char              buffer[100];
 
  /* Make sure the Free Type Library has been initialized. */
  if (! freeTypeLibraryHasBeenInitialize)
  {
    error = FT_Init_FreeType( &library );
    if (error != 0) return 1;
    freeTypeLibraryHasBeenInitialize = 1;
  }
 
  /* Create a new font (i.e., face) */
  error = FT_New_Face( library, filename, face_index, &face );
  printf("FT_New_Face error %x\n", error);
 
  if (face->face_flags & FT_FACE_FLAG_SCALABLE)         printf("FT_FACE_FLAG_SCALABLE\n");
  if (face->face_flags & FT_FACE_FLAG_FIXED_SIZES)      printf("FT_FACE_FLAG_FIXED_SIZES\n");
  if (face->face_flags & FT_FACE_FLAG_FIXED_WIDTH)      printf("FT_FACE_FLAG_FIXED_WIDTH\n");
  if (face->face_flags & FT_FACE_FLAG_SFNT)             printf("FT_FACE_FLAG_SFNT\n");
  if (face->face_flags & FT_FACE_FLAG_HORIZONTAL)       printf("FT_FACE_FLAG_HORIZONTAL\n");
  if (face->face_flags & FT_FACE_FLAG_KERNING)          printf("FT_FACE_FLAG_KERNING\n");
  if (face->face_flags & FT_FACE_FLAG_FAST_GLYPHS)      printf("FT_FACE_FLAG_FAST_GLYPHS\n");
  if (face->face_flags & FT_FACE_FLAG_MULTIPLE_MASTERS) printf("FT_FACE_FLAG_MULTIPLE_MASTERS\n");
  if (face->face_flags & FT_FACE_FLAG_GLYPH_NAMES)      printf("FT_FACE_FLAG_GLYPH_NAMES\n");
  if (face->face_flags & FT_FACE_FLAG_EXTERNAL_STREAM)  printf("FT_FACE_FLAG_EXTERNAL_STREAM\n");
 

  printf("face num_glyphs = %d\n", face->num_glyphs);
  printf("face   xmax = %d\n", face->bbox.xMax);
  printf("face   xmin = %d\n", face->bbox.xMin);
  printf("face   ymax = %d\n", face->bbox.yMax);
  printf("face   ymin = %d\n", face->bbox.yMin);
  printf("face  units_per_em = %d\n", face->units_per_EM);
 
  for (j=0; j<face->num_charmaps; j++)
    printf("platform_id = %d  encoding_id = %d\n",
            face->charmaps[j]->platform_id, face->charmaps[j]->encoding_id);
           
  /* For each character in the specified range, generate a 3D polygonal mesh
     for the character glyph. */
  for (j=minChar; j<=maxChar; j++)
  {
    glyph_index = FT_Get_Char_Index( face, j );
    if (glyph_index > 0)
    {
      FT_Get_Glyph_Name( face, glyph_index, buffer, 100);
      printf("glyph name = '%s'\n", buffer);
      error = FT_Load_Glyph( face, glyph_index, FT_LOAD_DEFAULT);  
      if (error == 0)
      {
        error = FT_Get_Glyph( face->glyph, &glyph);
        if (error == 0)
          create3dGlyph( glyph );
      } 
    }
  }
/*-------------------------------------------------------------------*/
int create3dGlyph(FT_Glyph  glyph)
{
  #define MAX_CONTOURS    50
  int                  startIndex;
  int                  endIndex;
  contourStruct        contours[MAX_CONTOURS];
  edgeStruct           edges[MAX_CONTOURS];
  int                  j, k;
  unsigned long        x;
  FT_OutlineGlyph      outlineGlyph;
  FT_Outline           outline;
  FT_GlyphRec          root;
 
  outlineGlyph = (FT_OutlineGlyph) glyph;
  root    = outlineGlyph->root;
  outline = outlineGlyph->outline;
 
  x = (unsigned long) root.format;
  printf("format = %c%c%c%c\n", (x >> 24), (x >> 16 & 0x000000FF),
                                (x >> 8 & 0x000000FF), (x & 0x000000FF) );
  printf("advance = %ld %ld\n", root.advance.x, root.advance.y);
  printf("number of contours = %hd\n", outline.n_contours);
  printf("number of points   = %hd\n", outline.n_points);
  printf("size of n_contours = %d\n", sizeof(outline.n_contours));
  printf("size of points x = %d\n", sizeof(outline.points[0].x));
  printf("size of points y = %d\n", sizeof(outline.points[0].y));
 
  printf("points  tags  contours\n");
  for (j=0; j<outline.n_points; j++)
    printf("%3d  %6ld %6ld   %d\n", j,
        outline.points[j].x,
        outline.points[j].y,
        outline.tags[j]);
  for (j=0; j<outline.n_contours; j++)
    printf("Contour %d ends at %hd\n", j, outline.contours[j]);
  printf("flags = %d\n", outline.flags);
 
 
DUMP OF OUTPUT (for '2' in the arial.ttf file)
 
FT_New_Face error 0
FT_FACE_FLAG_SCALABLE
FT_FACE_FLAG_SFNT
FT_FACE_FLAG_HORIZONTAL
FT_FACE_FLAG_KERNING
FT_FACE_FLAG_GLYPH_NAMES
face num_glyphs = 1320
face   xmax = 4154
face   xmin = -1361
face   ymax = 2060
face   ymin = -665
face  units_per_em = 2048
platform_id = 0  encoding_id = 3
platform_id = 1  encoding_id = 0
platform_id = 3  encoding_id = 1
glyph name = 'two'
format = outl
advance = 65536 0
number of contours = 1
number of points   = 31
size of n_contours = 2
size of points x = 4
size of points y = 4
points  tags  contours
  0      64     64   1
  1      64      0   1
  2       0      0   1
  3       0     24   0
  4       0     46   1
  5       0     64   0
  6       0     64   0
  7       0     64   1
  8       0     64   0
  9       0     64   0
 10       0     64   1
 11       0     64   0
 12       0     64   0
 13       0     64   1
 14       0     64   0
 15       0     64   0
 16       0     64   1
 17       0     64   1
 18       0     64   0
 19       0     64   0
 20       0     64   1
 21       0     64   0
 22      64     64   0
 23      64     64   1
 24      64     64   0
 25      64     64   0
 26       0     64   0
 27       0     64   1
 28       0     64   0
 29       0     64   0
 30       0     64   1
Contour 0 ends at 30
flags = 1

Wayne Brown, Assistant Professor
Department of Computer Science 
United States Air Force Academy
Phone: 719-333-3131
FAX:   719-333-3338       

 

reply via email to

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