Kerning data?
BlitzMax Forums/BlitzMax Programming/Kerning data?
| ||
Just wondering, has anyone found an easy way to get the kerning data for a font? I am aware of BMFont, but I'm interested in auto generating a font tile set instead of relying on an external tool. |
| ||
This is a page of freetype examples. There's a whole section about kerning. |
| ||
Somehow I missed that page in my search, so thanks! |
| ||
I'm struggling a bit with this one. I put the following line in the Externs in the freetype.bmx module.Function FT_Get_Kerning( ft_face:Byte Ptr, lg:Int, rg:Int, mode:Int, ft_vector:Byte Ptr Ptr ) And this is my test program. It works perfectly in DEBUG mode and prints out data similar to the output of BMFont, but in RELEASE I get an EXCEPTION_ACCESS_VIOLATION error. What am I missing? |
| ||
Try changing this:Local fnt:TImageFont = LoadImageFont( "c:\Windows\Fonts\Arial.ttf", 24, SMOOTHFONT ) ...to this Global fnt:TImageFont = LoadImageFont( "c:\Windows\Fonts\Arial.ttf", 24, SMOOTHFONT ) -Henri |
| ||
I'd suggest using SuperStrict so know all your types are working properly. |
| ||
@Henri - Thanks, but it made no difference. @Brucey - I dislike SuperStrict, but tried your suggestion. All it did was force me to declare all of my types - use :Int instead of nothing. Otherwise, the result was the same and it still gives me the exception error. EDIT: Henri, I tried Global ftf:TFreeTypeFont instead and that helped. Then I added End after WaitKey() and that worked. Still clueless as to why, though. And why would End make any difference at all? :( |
| ||
My take on it...SuperStrict Framework brl.freetypefont Import brl.standardio Local font:TFreeTypeFont = TFreeTypeFont(LoadFont("arial.ttf", 12)) If font.HasKerning() Then Local vec:FTVector = New FTVector Local count:Int = 0 For Local l:Int = 32 To 126 For Local r:Int = 32 To 126 If font.Kerning(l, r, 0, vec ) And vec.x Then Print l + " , " + r + " : " + vec.x + ", " + vec.y count :+ 1 End If Next Next Print "Total Count = " + count End If with the results : 70 , 44 : -64, 0 70 , 46 : -64, 0 80 , 44 : -64, 0 80 , 46 : -64, 0 84 , 44 : -64, 0 84 , 46 : -64, 0 84 , 58 : -64, 0 84 , 59 : -64, 0 84 , 97 : -64, 0 84 , 99 : -64, 0 84 , 101 : -64, 0 84 , 111 : -64, 0 84 , 115 : -64, 0 86 , 44 : -64, 0 86 , 46 : -64, 0 89 , 44 : -64, 0 89 , 45 : -64, 0 89 , 46 : -64, 0 89 , 101 : -64, 0 89 , 111 : -64, 0 89 , 113 : -64, 0 Total Count = 21 As to your crashing problem, I don't think this is working for you : Varptr delta |
| ||
Well, you must have something I don't. My TFreeTypeFont module doesn't have HasKerning() or Kerning() methods. That would've made things a lot easier! As for Varptr delta, why do you say that? |
| ||
My TFreeTypeFont module doesn't have HasKerning() or Kerning() methods. Well, I only added them to mine just now. As for Varptr delta, why do you say that? because ft_vector is a structure with an x and a y, which you are meant to pass into the the function for it to be populated. |
| ||
Ah, I did it try it that way first. Are you still using MemCopy, because I couldn't get that to work. |
| ||
Are you still using MemCopy No, it's not required here. You just pass an object of the correct type and the function will populate it correctly. (BlitzMax sorts out the internal object offsets etc for you). It's like magic ;-) Anyway, you can find the latest BRL and PUB modules here : https://github.com/maxmods (see History.md file to see what's changed from the official 1.50 version) |
| ||
I realized as I was typing it in. I've been using Max for ten years or so and still don't know all the little things. Might want to look a few other things over now, working or not! :) Thanks for your help! You are the man! |
| ||
I've been using Max for ten years or so and still don't know all the little things. Indeed. I discovered loop labels last week ! |