Page 1 of 1

Making a Centering function for True Type Fonts

Posted: Tue Feb 28, 2006 9:55 pm
by DaveUnit
I'm using Freebasic and the Yagl library(not really necessary for you to know bu whatever. =P), and I want to know how to figure out how to center the text no matter the size of text.
With Old QB and using 8x8 fonts only it's easy to make a centering routine, but it gets complicated when using True Type Fonts.
I can't think of any formula for doing this. If you know the correlation between point size and dimensions in pixels I'd appreciate any help you can offer.
Thanks a lot.

Dave

Posted: Wed Mar 01, 2006 8:12 am
by Z!re
Yagl has a nifty function called YagGfxFont_getTextDimensions

You use it as such:
YagGfxFont_getTextDimensions( myFONT, myText$, width, height )

Width and height will now hold the size of that text in pixels, after that it's easy to work out the proper offset to place the text at

Posted: Wed Mar 01, 2006 4:36 pm
by DaveUnit
Thanks a lot Z!re, I'm still trying to memorize YAGL's routines so I don't know a lot of the functions.
I reference the sample programs and online documentation but I guess I missed that routine.
Anyway, thanks again Z!re. You sure know YAGL very well. When I heard that you and Nekrophidius were using YAGL for your games I knew YAGL must be great. :D

Later,

Dave

Posted: Wed Mar 01, 2006 4:58 pm
by DaveUnit
Okay... um... FBIDE is giving me some crap so I took a look at yaglwrapper.bi for reference and I see no yaglgfxfont_gettextdimensions...
I'm gonna check to see if there's a newer version of YAGL out.

Posted: Wed Mar 01, 2006 6:04 pm
by Z!re
The latest is 0.0.7 and it has gettextdimensions

And ya, Yagl is a really cool library =)

Posted: Thu Mar 02, 2006 3:49 am
by Macric

Posted: Thu Mar 02, 2006 7:49 am
by Z!re

Posted: Fri Mar 03, 2006 5:32 am
by Macric
i am imperfect but this is good
http://forum.qbasicnews.com/viewforum.php?f=22

Posted: Fri Mar 03, 2006 7:21 am
by Z!re
Macric wrote:i am imperfect but this is good
http://forum.qbasicnews.com/viewforum.php?f=22
I still dont see the relevance to this topic.

Posted: Fri Mar 03, 2006 7:50 am
by DaveUnit
I don't see the relevance either...
Anyway, I got the newest version of Yagl, it has getTextDimensions so I should be good now.

Thanks again, Z!re.

Dave

Posted: Fri Mar 03, 2006 11:51 am
by Z!re
DaveUnit wrote:I don't see the relevance either...
Anyway, I got the newest version of Yagl, it has getTextDimensions so I should be good now.

Thanks again, Z!re.

Dave
No problem =)

Posted: Tue Mar 14, 2006 7:35 pm
by DaveUnit
I feel a little like Dr. Frankenstein bringing this once dead topic back to life but I'm having one wee problem with yaggfxfont_gettextdimensions.

In addition to centering text, I made an option where the text can have a background color rather than being transparent. The background color takes up the correct height, but the width is off. There's got to be something I'm overlooking.

vvvv the important code is in bold vvvv

Code: Select all

    with text_textobjects(text_number)
        .object_name=object_name$
        .text=text$
        .x=x
        .y=y
        .text_color=text_color
        .transparency=transparency
        .font=font
        .active=-1
        [b].shade_color=shade_color
        yaggfxfont_gettextdimensions(.font,.text,width,height)
        .length=width
        .height=height[/b]
    end with
Any help is appreciated.

Dave

Posted: Tue Mar 14, 2006 7:53 pm
by Z!re
I cant see anything wrong..

Posted: Tue Mar 14, 2006 9:25 pm
by DaveUnit
Me either, lemme look somewhere else..

Code: Select all

yaglgfxdevice_solidbox(.x,.y,.x+.length,.y+.height,.shade_color,.transparency)
That's the only place anything involving text dimensions comes up, do you see anything wrong there?

Posted: Wed Mar 15, 2006 10:01 am
by Z!re
Nope... just by chance, try changing the width variable where you get the font dimensions.
I had some problems with variables named: W and H, where my program would crash..
Seems to be a random FB problem.. not sure though..

Changing the variable names to ww and hh, respectively, fixed the problem.

Posted: Wed Mar 15, 2006 2:52 pm
by DaveUnit
Could it be because Width is an FB command? I thought about that but since yaglwrapper.bi had that paramater called width also I thought it must work still.

It must be because of that 'cuz changing width to anything else works perfectly.

Thanks for helping with another one of my stupid mistakes Z!re.

Dave

Posted: Wed Mar 15, 2006 3:36 pm
by Z!re
Heh, no problem, and it's not a misstake.. it's FB screwing up..