Results 1 to 9 of 9

Thread: How to use a custom TTF-Font?

  1. #1

    Exclamation How to use a custom TTF-Font?

    Hey i just played around with the gui and i wondered if it is possible to load a custom created TTF-Font. And if so, how to load it from an virtual file system?


    Thanks in advance!

    Imp

  2. #2
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    It is possible, but at the moment, not with the VFS - (It currently is not implemented).

    There are a couple of things that use CL_File instead of the VFS. I'll have a look...

  3. #3

    Default

    Thanks! I'm looking forward to it

  4. #4
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Implemented in SVN

    CL_Font_Freetype is now CL_TextureGroup based (So should be the same speed as CL_Font_Texture).

    The constructors are:
    Code:
    	CL_Font_Freetype( CL_GraphicContext &gc, const CL_StringRef &typeface_name, int height);
    	CL_Font_Freetype( CL_GraphicContext &gc, const CL_StringRef &typeface_name, int height, CL_IODevice &file);
    	CL_Font_Freetype( CL_GraphicContext &gc, const CL_StringRef &typeface_name, int height, const CL_VirtualDirectory &directory);
    
    	CL_Font_Freetype( CL_GraphicContext &gc, const CL_FontDescription &desc);
    	CL_Font_Freetype( CL_GraphicContext &gc, const CL_FontDescription &desc, CL_IODevice &file);
    	CL_Font_Freetype( CL_GraphicContext &gc, const CL_FontDescription &desc, const CL_VirtualDirectory &directory);
    If you want to use the font in the GUI, you will have to call CL_GUIManager::set_named_font() and set the font-family in the theme. For example:

    In the Code -
    Code:
    	CL_GUIManager gui;
    	...
    	CL_Font_Freetype font_freetype(gc, "my_font.ttf", 16, directory);
     
    	CL_FontDescription clanlib_font_desc;
    	clanlib_font_desc.set_typeface_name("ClanLib Font");
    	clanlib_font_desc.set_height(16);
    	clanlib_font_desc.set_weight(400);
    	gui.set_named_font(font_freetype, clanlib_font_desc);
    In the CSS -
    Code:
    	button
    	{
    		font-family: ClanLib Font;
    		font-size: 16;
    	}

  5. #5

    Default

    Awesome, works like a charm! Thanks rombust!

  6. #6

    Default

    Ok, this is not working for me.

    In main I have:
    Code:
    CL_GUIManager gui_manager;
    
    CL_GUIWindowManagerSystem wm;
    gui_manager.set_window_manager(wm);
    
    CL_GUIThemeDefault theme;
    CL_ResourceManager resources("Resources/GUIThemeAero/resources.xml");
    theme.set_resources(resources);
    gui_manager.set_theme(theme); 
    gui_manager.set_css_document("Resources/GUIThemeAero/theme.css");
    
    MainWindow main_window(&gui_manager, desc);
    gui_manager.exec();
    in the MainWindow ctor I have:
    Code:
    CL_Font_Freetype font_freetype(get_gc(), "Resources/visitor1.ttf", 16);
    CL_FontDescription clanlib_font_desc;
    clanlib_font_desc.set_typeface_name("visitor");
    clanlib_font_desc.set_height(16);
    clanlib_font_desc.set_weight(400);
    manager->register_font(font_freetype, clanlib_font_desc);
    // setting the css document again just in case
    manager->set_css_document("Resources/GUIThemeAero/theme.css");
    in checkbox.css I have:
    Code:
    checkbox
    {
        font-family: visitor;
    }
    But my checkbox is still using the default system font.
    Any ideas?

    If you want to test, you can get the full project by doing "svn checkout -r29 http://music-life.googlecode.com/svn/trunk/"

  7. #7
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Bergen, Norway
    Posts
    588

    Default

    Dunno why that isnt working, but I see that I do the following in the DiceWars example:

    CL_Font_System::register_font("Resources\\bitstrea m_vera_sans\\VeraBd.ttf", "VeraBd");

    and then I initialize the gui.

    in my css:

    font-family: VeraBd;

  8. #8
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Sphairs right, and it is the better method.

    But your method "should" work. (Assuming the css is matching the EXACT font description -including the font size)
    See Tests/GUI/GUIFont

    But try dicewar's method. It's simpler. The other method is for advanced stuff like using CL_Font_Sprites

  9. #9

    Default

    (Assuming the css is matching the EXACT font description -including the font size)
    Yay. That worked, thx. had to set the font size in css.
    For the record, this seems like an unnecessary requirement. I want to register just the fontname in code, and then, when I use a particular fontsize from CSS, THEN ClanLib can generate the necessary textures on the fly.
    If you ever get some time, you could look into doing that.

    Btw... it bugs me that it was so hard to debug. I guess I'd like ClanLib to print a warning when parsing the CSS and failing to apply some rule.

Similar Threads

  1. New example in ClanLib 2.0: Custom GUI Component
    By sphair in forum Official ClanLib SDK Forums
    Replies: 4
    Last Post: 05-19-2009, 02:08 PM
  2. Custom primitive, textures wont show.
    By sandelz in forum Official ClanLib SDK Forums
    Replies: 3
    Last Post: 05-07-2009, 12:25 PM
  3. error in custom pallette window...
    By harrio in forum Novashell Game Creation System
    Replies: 1
    Last Post: 04-06-2008, 01:16 AM
  4. custom resource
    By oilen in forum Official ClanLib SDK Forums
    Replies: 0
    Last Post: 12-07-2007, 12:12 PM
  5. Custom resource combined with sprite
    By tompawarrior in forum Official ClanLib SDK Forums
    Replies: 0
    Last Post: 07-17-2007, 05:30 PM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •