Get name of a font from the file without installing it

Well, I keep getting “There was a problem reading the length of the name”.

I will have to dig into that when I have a clear mind.

Hmm I tested it with https://github.com/google/fonts/raw/master/ofl/alexbrush/AlexBrush-Regular.ttf and it worked fine.

You might have it pointing to a font that it cant read :frowning:

I better make sure it can read any font that is recognized by Windows.

[quote=311113:@Cho Sing Kum]I have reference to this old solid workhorse code. I tested it after making sure that TTFontFile is assigned a valid filename in Command1_Click event.

I converted it to Xojo but no luck. It seems the function has become inoperative in Windows 10. No error, but the function returns systematically zero.

[quote=311161:@]Hmm I tested it with https://github.com/google/fonts/raw/master/ofl/alexbrush/AlexBrush-Regular.ttf and it worked fine.

You might have it pointing to a font that it cant read :([/quote]

Well, something else is happening. Pointing to that font triggers the same error :frowning:

Hmm, thats odd, it works a treat here, did you use the same code just cut and paste from my post?

Did you call it with an absolute path, ie.

system.DebugLog GetFontName("C:\\Test\\AlexBrush-Regular.ttf")

What version/edition of windows are you running, w10/64 ? w10/32 ?

Can you try it in a brand new blank project so you know the project settings are all default?

If you double click that font in windows, does it show ok ? ie. is the download not corrupt

Does the exe have read permission to the location of the font?

[quote=311176:@]Hmm, thats odd, it works a treat here, did you use the same code just cut and paste from my post?

Did you call it with an absolute path, ie.

system.DebugLog GetFontName("C:\\Test\\AlexBrush-Regular.ttf")

What version/edition of windows are you running, w10/64 ? w10/32 ?

Can you try it in a brand new blank project so you know the project settings are all default?

If you double click that font in windows, does it show ok ? ie. is the download not corrupt

Does the exe have read permission to the location of the font?[/quote]

I did copy from the forum.

I am under Windows 10, and the font is not in a restricted folder.

Could you consider posting your project ?

Ummm I tried making a copy of the font into the same folder and loading that, now I’m having the same problem as you, give me a couple of mins to figure this out.

Sorry Michel, but I think this one had beaten me. I’m just getting strange problems, if I change filename or folder the routine just stops working. I guess thats why its an undocumented call. I have double and triple checked my calls and I cant see where it might be causing a problem. All I am changing is the length of a WString being passed to the function, heck if I keep the length the same and just change a character from r to s it stops working boggle

I have also tested it in another language and I see the same problems, so I dont think its a Xojo issue.

loading C:\Users\Julian\Dropbox\Development\[redacted]\AlexBrush-Regular.ttf
Alex Brush
loading C:\Users\Julian\Dropbox\Development\[redacted]\AlexBrush-Regulas.ttf
ERROR

loading C:\Users\Julian\Dropbox\Development\[redacted]\AlexBrush-Regular-Copy1.ttf
ERROR
loading C:\Users\Julian\Dropbox\Development\[redacted]\AlexBrush-Regular.ttf
Alex Brush
loading C:\Users\Julian\Dropbox\Development\[redacted]\Ace.ttf
Alex Brush

loading C:\Users\Julian\Dropbox\Development\Xojo\AlexBrush-Regular-Copy1.ttf
ERROR
loading C:\Users\Julian\Dropbox\Development\Xojo\AlexBrush-Regular.ttf
ERROR
loading C:\Users\Julian\Dropbox\Development\Xojo\Ace.ttf
ERROR

loading C:\Users\Julian\Dropbox\Development\Ace.ttf
ERROR

I hope that someone else with a bit more windows api knowledge might be able to shed some light on it.

It’s alright Julian. It is an undocumented call anyway. That probably explains a lot. Thank you for your efforts.

I will get back to my efforts to parse the font.

CreateScalableFontResourceA is available in Windows 10. I just ran the old code there and it works. I also used DLL Export Viewer to check exported functions.

Add:
Maybe this is the problem - It only works with True Type fonts.