Getting font size before initializing graphics

BlitzMax Forums/BlitzMax Programming/Getting font size before initializing graphics

jhague(Posted 2006) [#1]
I'm writing an app that mimics a text window: N columns x M rows of characters of a fixed-width font. I want the window size to be a perfect multiple of the font width and height, so I need to get those values before the Graphics call. Unfortunately, you can't use TextWidth and TextHeight until *after* the graphics system is initialized.

The only option I've come up with is to initialize graphics, get the font measurements, close the graphics device, then re-open it again with the proper window size. This is ugly :)


Duckstab[o](Posted 2006) [#2]
when loading a font you deside what size to use im not sure if fonts have a default size.

how are you styling this.

A. You choose your font then builds a window to suit
B. Creating a window using a preselected font


jhague(Posted 2006) [#3]
In LoadImageFont, you specify a font size, but that size doesn't translate to pixels. Additionally, the width and height of a character in a fixed-width font may be different.

The problem is that you can't call TextWidth and TextHeight before Graphics.


Defoc8(Posted 2006) [#4]
well..one slightly ugly solution might be to create the display
for single purpose of grabbing that info..

graphics(640,480,0)
*GetFont Data*
endgraphics()
*Rest of the Proggy*
end

this should result in the window poping up for
a second or two..but i imagine this isnt too annoying,
anyway..you can use this kludge until someone tells
you how to do it cleanly ;)


tonyg(Posted 2006) [#5]
Does this look too bad?
Graphics 1,1
Print TextWidth("Hello World")
Endgraphics
Graphics 640,480
DrawText "Hello World!",0,0
Flip
WaitKey()

First time there's a small flash but running again it's too quick to see.


peltazoid(Posted 2007) [#6]
this should result in the window poping up for
a second or two..but i imagine this isnt too annoying,
anyway..you can use this kludge until someone tells
you how to do it cleanly ;)


Or Have that window as some kind of splash screen?