Skip to content
⌘ NSIS Forum Archive

font name from its file name

50 posts

Yathosho#

font name from its file name

is there a possibility to query a font file for the fonts name?

example: comic.ttf is called 'comic sans ms' and registered as such.

i know one can specify that when one uses font installation functions for nsis, but it would be useful (for my script) to get around that.
Afrow UK#
Try opening a font into Notepad and see the layout of the file.
You can then probably read from this file and get hold of the chunk you need.

-Stu
Joost Verburg#
Do you want to get the name of a registered or unregistered font?

Do you want to get the file from a name or the name from a file?
Yathosho#
i want to read the font name (to register it under that name) from the ttf file. so, unregistered font and name from file.
Joost Verburg#
You can write a plug-in using this code:

Joost Verburg#
There is no such plug-in available in the archive, but you can easily write one using the code above.
Vytautas#
Only problem is that my C/C++ skills are almost non existent and I do not have access to MS VC copmiler. I think that it would be quite difficult to convert that code into delphi.

Vytautas
Vytautas#
I tried to create this plugin with C++ Builder 6 but I get "Undefined Symbol: 'CFile'" and "Undefined Symbol: 'CString'" errors did I miss a really obvious include or do I need VC for this to work?

Vytautas
rsegal#
CFile and CString are MFC classes. Are you building the project with MFC included? I think visual c++ includes this automatically when you use any MFC data type. Sounds like you need to do something different for C++ builder.
Vytautas#
OK, in that case are there any equivalents that dont use MFC or is there a way do accomplish this task with just the ANSI C/C++. Cos after a quick look on the net I discovered that getting MFC to work with Borlan C++ Builder is next to impossible, good old Microsoft.

Vytautas
kichik#


GetFontProperties is what you're looking for.
Vytautas#
Thanks kichik I will try to make the plugin tomorrow.

I just noticed one thing. The name of the font from the file is used for the display name in the registry, thats the reason I need this plugin, however the name in the registry has (TrueType) appended to the end of the name if its a TTF file however if tis a FON file it has either (All res) or (VGA res).

Is this always the case with TTF files and is there a way to find out which type is the FON font?

Vytautas
kichik#
Well, TTF stands for TrueType Font, so unless the file name is wrong, it should be TrueType. There is another page in CodeProject, in the same category that shows how to get the font type from the file. Maybe that would help.
Vytautas#
Yes joost but I need to get the name of the font so that I can add it to the registry when installing the font. Kichik I will check out that page.

Vytautas
Vytautas#edited
Attached is a plugin to get the name of a TTF Font from the file. Considering that this plugin only works with TTF files the previous post about registry name change can be disregarded.

Vytautas

PS. Attached file contains the source code with the project files for DEV-C++

PPS. I will create an archive page about this plugin later tonight including usage examples.

PPPS. You should call this plugin using this command:
FontName::Name 'Location of TTF font file'
Vytautas#
kickik, or someone else, could you please upload this plugin to the archive. For a more detailed example of the plugins usage check out my font registration page in the archive as it utilizes this plugin.

Vytautas
Yathosho#
thats a very nice plugin, but i want suggest adding the fontstyle to the output.

try the plugin on all ttf files of the arial family. the plugin will always display

Arial (TrueType)

not

Arial Bold (TrueType)
Arial Italics (TrueType)
etc.

without fontstyle, fonts of the same family aren't distinguishable.
Vytautas#
OK found where the problem was, the original code replaces the name with the family name of the font if the font name was '' and for some reason the code is not reading the name. Will post when a fix is found.

Vytautas
Vytautas#
Fixed, also removed unused info from the plugin, made it slightly smaller. 🙂 Could someone please update the archive file with this.

Vytautas
Vytautas#
Optimized the plugin size a little more.

Vytautas 😁
Vytautas#
I have struck a problem with my plugin. It seems to generate a BSOD in Win98SE. Could anyone help me test this, e.g. try with different versions of windows to see which platforms have this problem.

Also what is the best way to debug a NSIS Plugin. I used Dev-C++ to create it, source code is included in the plugin.

Any help is greatly appreaciated.

Vytautas 😢
kichik#
According to Dev-C++'s changelog, they have added an option to debug DLLs in version 4.9.8.2 so it should be there somewhere if you're using this version. I suggest you first get more information about the crash, the exact text to start with.
Vytautas#
The error I get is this:
A fatal exception OE has occured at 0028:C02A3531 in VXD VWIN32(05) + 00002059. The current application will be terminated.
This error only seems to occur in Win9x.

kickik when I asked how to debug a plugin I meant how do I tell NSIS to run the debug dll instead of the normal.

Vytautas
kichik#
You simply put it in the Plugins directory and use it like every other plug-in. For NSIS it's just another DLL.

.
Vytautas#
I'm not so good with C++ so I don't know if I'm on the right path here or not, but I thought that if you wanted to let's say step through the execution of a dll you had to link it the the application that used that dll.

Vytautas