Making a Centering function for True Type Fonts
Making a Centering function for True Type Fonts
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
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
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
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
I have left this dump.
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.
Later,
Dave
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.
Later,
Dave
i am imperfect but this is good
http://forum.qbasicnews.com/viewforum.php?f=22
http://forum.qbasicnews.com/viewforum.php?f=22
I still dont see the relevance to this topic.Macric wrote:i am imperfect but this is good
http://forum.qbasicnews.com/viewforum.php?f=22
I have left this dump.
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
Any help is appreciated.
Dave
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
Dave
Me either, lemme look somewhere else..
That's the only place anything involving text dimensions comes up, do you see anything wrong there?
Code: Select all
yaglgfxdevice_solidbox(.x,.y,.x+.length,.y+.height,.shade_color,.transparency)
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.
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.
I have left this dump.
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
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