FontWidth() not found

Archives Forums/BlitzPlus Bug Reports/FontWidth() not found

Jester(Posted 2007) [#1]
This is in the full version of Blitz Plus.

The FontWidth() function does not exist. Here is the sample code:

Global blockheight = FontHeight()
Global blockwidth = Len(blockstring) * fontwidth() 
Global paddleheight = FontHeight()
Global paddlewidth = Len(paddlestring) * fontwidth()


When this is ran I get a box telling me function FontWidth() can not be found.


H&K(Posted 2007) [#2]
That is not example code.
Read:
Fontwidth returns the width, in pixels, of the currently selected font (using SetFont). This command returns the width of the WIDEST character of the font
So unless you post some code that has Setfont in it, it is not example code of Fontwidth existing or not. Also with any graphics command, (yes this is a graphics command), its better to have called/created the Graphic (ie 800,600)

Maybe it doesnt exist, maybe it does. But people will just assume you have forgotten to set a Font.

Does this work
; FontWidth()/FontHeight example

; enable graphics mode
Graphics 800,600,16

; Set global on font variable
Global fntArial

;Load fonts to a file handle variables
fntArial=LoadFont("Arial",13,False,False,False)

; set the font and print sizes
SetFont fntArial
Text 400,0,"The font width of the widest character is:"+ FontWidth(),True,False
Text 400,30,"The height of the font is:"+ FontHeight(),True,False

; Standard 'wait for ESC' from user
While Not KeyHit(1)
Wend

; Clear all the fonts from memory!
FreeFont fntArial



Yan(Posted 2007) [#3]
Are you using an old version of BPlus? I vaguely remember something about fontwidth() not being in the early versions.

@H&K - [cough]flip[/cough] ;o)


H&K(Posted 2007) [#4]
@yan
[cough]not double buffered[/cough]

Edit: Didnt think you would be watchin' ;)


Yan(Posted 2007) [#5]
(And not double buffered)
Hehe...Nice edit...And...Doh!, must remember to turn off debug mode (flip still needed for windowed mode).


skidracer(Posted 2007) [#6]
Jester, I think the FontWidth command was superceeded by StringWidth.


Jester(Posted 2007) [#7]
H&K,
That example gives the same results as my code. I cut out just that part of my code. All the other ingredients were there. Sorry about that I'll include it next time I have trouble. Thanks


skidracer,
Thats what I needed. Thanks!


skidracer(Posted 2007) [#8]
No problem, check the Migrating to BlitzPlus appendix in the user guide for a few other differences between BlitzBASIC/Blitz3D and BlitzPlus.


Yan(Posted 2007) [#9]
Skidracer, FontWidth() works with the demo version of B+ (v1.43), was it taken out again in a later version (if there is one)?


H&K(Posted 2007) [#10]
@Yan,

Fontwidth was useless though wasnt it? Cos unless you had a monospaced font you couldnt actualy do anything useful with it. StringWidth does seem a better idea, (cos you only ever want fontwidth to calculate string width anyway)

I agree thou, that the Demos should be as close to the products as possible