Class DTrueTypeFont

Inherits from:
Object
Conforms to:
DFont
Declared in:
DTrueTypeFont.h

Class Hierarchy

    Object
      |
      +---DTrueTypeFont

Class Description

The DTrueTypeFont class implements methods for using a TrueType font. Actually every font that can be loaded with the FreeType library, can be used by this class.

Example:
#include <stdio.h>
#include "ofc/DTrueTypeFont.h"

int main(int argc, char *argv[])
{
  DTrueTypeFont *font = [DTrueTypeFont new];
  DFT_Glyph    glyph;

  unsigned     width,height;
  char         name[] = "../test/arial.ttf";

  if ([font open :name])               // Open font file
  {                                    // Print font info
    printf("Family name:%s\n",    [font familyName]);
    printf("Style name:%s\n",     [font styleName]);
    printf("Glyphs in font:%d\n", [font glyphsInFont]);

    [font size :"a" :20 :15];          // Give the glyphs a size

    [font stringSize :"hello" :&width :&height]; // Get string dimensions
    printf("String size of \"hello\":%u - %u\n", width, height);

    if ([font glyph :'a' :&glyph])     // Render a character to a glyph
    {
      unsigned xe = glyph.bitmapWidth -1;
      unsigned ye = glyph.bitmapHeight - 1;
      unsigned x,y;

      unsigned char *bitmap = glyph.bitmap;

      printf("Glyph bitmap:\n");       // Print the bitmap of the glyph
      for (y = 0; y <= ye; y++)
      {
        unsigned char  mask = 0x80;
        unsigned char *line = bitmap;

        for (x = 0; x <= xe; x++)
        {
          printf("%c", ((*line & mask) ? '1' : '0'));

          mask >>= 1;
          if (mask == 0)
          {
            mask = 0x80;
            line++;
          }
        }
        bitmap += glyph.bitmapPitch;
        printf("\n");
      }
    }
    else
      printf("The glyph 'a' is not present in the font.\n");

    [font close];
  }
  else
    printf("Could not open font file \"%s\".\n", name);

  [font free];

  return 0;
}
Last modified:
26-Aug-2008 (DTrueTypeFont.h)

Instance Variables

private void *_font
the loaded font

Method Index


generated 06-Sep-2008 by ObjcDoc 3.0.0