ClanLib SDK

Fonts

A Font is a collection of images that can be used to represent text on a screen.

There are various font classes that you can use.

  • Default Font
  • The Default Font (provided by CL_Font ) uses CL_Font_System

  • Freetype Font
  • The Freetype Font (provided by CL_Font_FreeType ) uses a truetype font, stored in a texture group ( CL_TextureGroup ).

  • System Font
  • The system font (provided by CL_Font_System ) uses the operating system font, stored in a texture group ( CL_TextureGroup ).

  • Vector Font
  • The vector font (provided by CL_Font_Vector ) uses a truetype font, stored as triangle primitives (drawn using CL_PrimitivesArray )

  • Sprite Font
  • The sprite font (provided by CL_Font_Sprite ) uses a font stored as a CL_Sprite.

    Constructing fonts

  • Freetype Font
  •   CL_FontDescription desc;
      font_desc.set_typeface_name("myfont.ttf");
      CL_Font_Freetype freetype_font(gc, font_desc);
      freetype_font.draw_text(gc, 100, 100, "Hello World");
    
  • System Font
  •   CL_FontDescription desc;
      font_desc.set_typeface_name("tahoma");
      CL_Font_System system_font(gc, font_desc);
      system_font.draw_text(gc, 100, 100, "Hello World");
    
  • Vector Font
  •   CL_FontDescription desc;
      font_desc.set_typeface_name("myfont.ttf");
      CL_Font_Vector vector_font(font_desc);
      vector_font.draw_text(gc, 100, 100, "Hello World");
    
  • Sprite Font
  •   CL_Font_Sprite sprite_font(gc, "ClanFont", &app_resources);
      sprite_font.draw_text(gc, 100, 100, "Hello World");
      (See Examples/Font/resources.xml)
    

    ClanGUI and Fonts

    If you want ClanGUI to use a custom font, instead of a native font, you will first need to register the font as follows

    	CL_Font_Sprite sprite_font(gc, "ClanFont", &app_resources);
    	CL_FontDescription font_desc;
    	font_desc.set_typeface_name("GUI Font Name");
    	font_desc.set_height(32);
    	font_desc.set_weight(400);
    	gui->register_font(sprite_font, font_desc);