freetype-devel
[Top][All Lists]
Advanced

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

[Devel] Re: FT_Outline-Contours


From: |Ron|
Subject: [Devel] Re: FT_Outline-Contours
Date: Fri, 6 Jun 2003 18:23:44 +0200 (CEST)

> I am having problem with FT_Outline struct of freetype.
> I am not able to visualize this. Can someone explain what is written for 
> the explaination.

A contour is a set of points that make up one part of a glyph. Most glyphs
consist of several countours. E.g. the quote char " (ASCII 34) has two
contours (two boxes) and the uppercase B (ASCII 66) has three contours
(one counter-clockwise outside and two clockwise holes inside).

Looking at the contents of FT_Outline for different glyphs certainly helps.
A simple program to dump the structure is attached.

Compile with: cc -o ftoutline ftoutline.c `freetype-config --cflags --libs`
Run with: ./ftoutline <fontfile> <charnum>

The quote char looks like:

$ ./ftoutline /usr/lib/X11/fonts/truetype/verdana.ttf 34
8 points, 2 contours

 0:   772  1556 *
 1:   729   977 *
 2:   597   977 *
 3:   554  1556 *

 4:   386  1556 *
 5:   343   977 *
 6:   211   977 *
 7:   168  1556 *

Try this with different fonts (outline fonts only of course) and different
characters and see what you get.

Note: '*', '+' and '#' mark on-curve points, off-curve 2nd order control
points and off-curve 3rd order control points. Since TrueType fonts use
only 2nd order and Type1 PostScript fonts use only 3rd order control points
you will only get one kind at a time.

|Ron|


#include <stdio.h>
#include <stdlib.h>
#include <freetype/freetype.h>

static void
dump_outline(FT_Outline *out)
{
  int i,j;

  printf("%d points, %d contours\n\n",out->n_points,out->n_contours);

  for (i=j=0;i<out->n_points;i++) {
    FT_Vector *v=&out->points[i];
    int t=out->tags[i];

    printf("%2d: %5ld %5ld %c\n",i,v->x,v->y,"+*##"[t&3]);
    if (i==out->contours[j]) { j++; putchar('\n'); }
  }
}

int
main(int argc,char** argv)
{
  FT_Error err;
  FT_Library ftlib;
  FT_Face face;
  char *file;
  unsigned long chr;
  FT_UInt idx;

  if (argc<3) {
    fprintf(stderr,"Usage: %s fontfile charnum\n",argv[0]);
    return 1;
  }

  file=argv[1];
  chr=strtoul(argv[2],NULL,0);

  if ((err=FT_Init_FreeType(&ftlib))) {
    fprintf(stderr,"Cannot initialize freetype library: 0x%04x\n",err);
    return 1;
  }

  if ((err=FT_New_Face(ftlib,file,0,&face))) {
    fprintf(stderr,"Cannot load font '%s': 0x%04x\n",file,err);
    FT_Done_FreeType(ftlib);
    return 1;
  }

  if (!(idx=FT_Get_Char_Index(face,chr)) ||
      (err=FT_Load_Glyph(face,idx,FT_LOAD_NO_SCALE|FT_LOAD_NO_BITMAP))) {
    fprintf(stderr,"Cannot load char %ld (0x%04lx): 0x%04x\n",chr,chr,err);
    FT_Done_Face(face);
    FT_Done_FreeType(ftlib);
    return 1;
  }

  if (face->glyph->format==FT_GLYPH_FORMAT_OUTLINE) {
    dump_outline(&face->glyph->outline);
  } else {
    fprintf(stderr,"Glyph is not in outline format. Cannot dump.\n");
  }

  FT_Done_Face(face);
  FT_Done_FreeType(ftlib);

  return 0;
}




reply via email to

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