Results 1 to 14 of 14

Thread: loading sprite fonts from css

  1. #1
    Lesser Knight
    Join Date
    Sep 2006
    Location
    Barcelona, Catalonia
    Posts
    30

    Default loading sprite fonts from css

    Hi, I'm working with a sprite font of my own, trying to use it from a css using the font-family tag. Taking a look at the example of the overview I thought that it can be made, as well as getting it later in this way:
    Code:
    CL_Font_Sprite * font  = new CL_Font_Sprite(gc, "Foo", resourceManager);
    CL_FontDescription desc;
    desc.set_typeface_name("foo");
    guiManager.register_font(*font, desc);
    ...
    CL_Font foo2(gc,desc);
    foo2.draw_text(gc,100,100,"Hello World");
    Unfortunately it is not working, and I can only get my custom font if I call "get_registered_font" from the GUI Manager, as the CL_Font_System provider and the list of registered fonts inside GUI Manager are two different lists, and my font "foo" can't be used from any 'css'. Am I doing something wrong?

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

    Default

    Use:

    CL_Font_Sprite * font = new CL_Font_Sprite(gc, "Foo", resourceManager);
    CL_FontDescription desc;
    desc.set_typeface_name("foo");
    desc.set_height(32);
    desc.set_weight(400);

    guiManager.register_font(*font, desc);

    The GUI manager needs to know the font height and weight.
    Ideally, the GUI manager should say "desc has this unset, so I'll assume it's the font I want" ... but at the moment it does not.

    Note: You can use
    CL_Font_Sprite font(gc, "Foo", resourceManager);
    As CL_Font_Sprite implementation uses a shared pointer. (Personal preference)

  3. #3
    Lesser Knight
    Join Date
    Sep 2006
    Location
    Barcelona, Catalonia
    Posts
    30

    Default

    It still doesn't work...it throws this exception when I try to create a font with the name of my registered font:
    Code:
    "Exception caught: Resource not found: foo"
    The "get_register_method" of the gui manager returns the correct font.

    By the way, I've added control about max_length in the LineEdit component (there existed a set_max_length method before, but it was not used). Where do I send the patch?

    Thanks for the help.

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

    Default

    Send the patch to this forum (Under additional options / Attach Files / Manage Attachments button)

    I'll have a quick look at the problem...

  5. #5
    Lesser Knight
    Join Date
    Sep 2006
    Location
    Barcelona, Catalonia
    Posts
    30

    Default

    Here goes the patch, thanks!
    Attached Files Attached Files

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

    Default

    I have made some changes in SVN, which may fix your problem, if not look at:

    Tests/GUI/GUIFont in SVN

    See attached.

    Notice, that CL_LineEdit calculates the content_rect box incorrectly. It's correct for the selected text, but not the unselected text.

    [Applied your patch - many thanks]
    Attached Images Attached Images  
    Last edited by rombust; 07-29-2009 at 12:02 PM. Reason: Fixed the Test crash on exit (a problem with CL_PrimitivesArray)

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

    Default

    Fixed the problem in CL_LineEdit, see attached:
    Attached Images Attached Images  

  8. #8
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    554

    Default

    I think the height also needs the internal leading taken into account for it to look good.

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

    Default

    The CL_Font_Sprite used has a leading height of zero - It can have one by changing resources.xml and specifying one though

    Normal System fonts look perfect.

  10. #10
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    554

    Default

    Ah, good.

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

    Default

    Unfortunately, linux fonts still need more work! It looks like the freetype fonts are not detecting the leading edge

  12. #12
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    554

    Default

    It would seem the patch broke both the vertical alignment and the selection:


  13. #13
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    554

    Default

    Oh and in case you wonder about the foul language. That's just me being inspired by Linus Torvalds!

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

    Default

    Whoops!

    I guess we need a proper test created.

    In the meantime, the following patch fixes it for CTalk

    Next week, i'll have another look
    Attached Files Attached Files
    Last edited by rombust; 07-31-2009 at 10:50 AM. Reason: added patch

Similar Threads

  1. Linux fonts [0.9]
    By kbluck in forum Official ClanLib SDK Forums
    Replies: 10
    Last Post: 09-25-2008, 11:48 AM
  2. ClanLib 0.9 OpenGL Fonts
    By rombust in forum Official ClanLib SDK Forums
    Replies: 3
    Last Post: 09-05-2008, 11:45 AM
  3. my fonts are really grainy
    By babyvegas in forum Official ClanLib SDK Forums
    Replies: 4
    Last Post: 07-11-2008, 04:07 PM
  4. ClanLib gui and fonts
    By LonelyStar in forum Official ClanLib SDK Forums
    Replies: 1
    Last Post: 04-28-2008, 07:52 AM
  5. Fonts & Graphics
    By AllenJB in forum Game development
    Replies: 1
    Last Post: 09-16-2006, 12:00 AM

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
  •