TrueType Font Widths

Blitz3D Forums/Blitz3D Programming/TrueType Font Widths

EPS(Posted 2007) [#1]
Hi, is there any way to get the following BMax example to work in B3D?

http://www.blitzbasic.com/Community/posts.php?topic=47573

my code is not working:

Graphics 640,480,0,2

bank = CreateBank( 256 * 3 * 4 )

hwnd = api_GetActiveWindow()
hdc = api_GetDC( hwnd )

font = LoadFont("Tahoma.ttf",20)
SetFont font

api_GetCharABCWidths( hdc, 0, 255, bank )

For i=0 To 255*3
Text x,y, PeekInt( bank, i)

x = x + 20: If x > 620 Then x = 0: y = y + 20
Next

WaitKey()
End



....my english is very bad, sorry for that....hope anybody can help - thanks.


b32(Posted 2007) [#2]
I think it could have to do with the .decls
I believe that for passing banks, a "%" is required.
But why not use StringWidth() ?


EPS(Posted 2007) [#3]
Because i need all the character spacings, A, B and C not only the width "created" by Blitz.


jfk EO-11110(Posted 2007) [#4]
Not sure if you understood b32's hint.

Something like

for i=0 to 255
print stringwidth(chr$(i))
next

Should return the width of each character.


EPS(Posted 2007) [#5]
Yes i know that stringwidth() gives me the width of a string but i need also...

...i repeat the MSDN:

"the negative A or C widths for a character, that character includes underhangs or overhangs."

take a look here:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/fontext_8icz.asp


Subirenihil(Posted 2007) [#6]
Blitz does not use underhangs or overhangs - it simply doesn't draw them. Can be frustrating at times. You'll mostly only notice the clipping when using italics or really fancy fonts. You will need to bypass Blitz "Text"/"Print" commands to have a use for underhangs or overhangs.

I assume you are getting a "User lib function not found" error on this line:
api_GetCharABCWidths( hdc, 0, 255, bank )


EPS(Posted 2007) [#7]
No, i get NO ERROR. But i get no results in the bank.

It is not so importend for what kind of thing i need this information but i need it ;)

The point is that it will not work and i don't no why.


Subirenihil(Posted 2007) [#8]
Ok. Got it to run now. But like you said, no data. Interesting...


Subirenihil(Posted 2007) [#9]
Um... Tahoma doesn't have overhangs/underhangs but that shouldn't make the function return 0's. Hmmm...

[Update] It's not even writing to the bank. Strange...

[Update] I guess (I'm not quite sure how to test) that Blitz doesn't use the fonts the same way that Windows does, so when you call that command (a Windows function) it doesn't think you have a font and therefore returns nothing.

[Update] Confirmed. GetCharABCWidths returns a failure. You'll need to use Windows functions to load a font if you want to use GetCharABCWidths. :(