Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Font filenames and fontnames

steve_konarski
Beginner
1,684 Views
I am trying to obtain the font filename from within a Fortran visual program source code. I have found a roundabout way from the following site

http://www.codeproject.com/KB/GDI/fontfile.aspx

where a simple program is available to be downloaded and seems to work well , the source code is also given but does not seem to be complete.

Is it possible to use RegOpenKeyEx and RegQueryValueex functions to obtain thefont file name from the registry values on

HKEY_LOCAL_MACHINE/ Software / Microsoft / Windows NT / Fonts

--------------------------------------------------------------------------------------------

I have read betwen the lines and assume you need the two functions

RET= RegOpenKeyEx( HKEY_LOCAL_MACHINE, FontName, 0, KEY_ALL_ACCESS,phkey)

RET = RegQueryValueex(HKEY_LOCAL_MACHINE, Fontname, NULL , &type, Fontfilename ,datasize)

regards Steve Konarski

0 Kudos
11 Replies
steve_konarski
Beginner
1,684 Views

I supply the Fontname i.e. "Arial Italic" and require the font file name i.e ARIALI.ttf

0 Kudos
Les_Neilson
Valued Contributor II
1,684 Views

Well it's a bit more work than that.
In RegOpenKey you need tospecifythe registry key you want to open,
sowhere you have "fontname" you need
"SOFTWAREMicrosoftWindows NTCurrentVersionFonts"
(or whatever it is on your system, and it should be NULL terminated.)
This will return a handle in phkey.

Then you use the "handle" in thecall toRegQueryValueEx(phkey, ....
passing the name of the font you want (again null terminated)
and it will return the name of the file.

See the MSDN documentation

Les

0 Kudos
Steven_L_Intel1
Employee
1,684 Views
I looked at the various font functions and could not see a supported interface for this, so what you're proposing may break in the future.

The QuickWinPoker sample provided with IVF contains registry calls so you can see how it is done. Some of the arguments may require that you pass LOC(arg) and any strings you get back will be NUL-terminated.
0 Kudos
steve_konarski
Beginner
1,684 Views

thanks Les I got further

i have the code

USE DFWIN
USE DFLIB

IMPLICIT NONE

character*90 data1,strFont,typeface

integer ret,ret1,type1,phkey

strFont = "SoftwareMicrosoftWindows NTCurrentVersionFonts"
strfont(55:55)=char(0)


ret= RegOpenKeyex(HKEY_LOCAL_MACHINE, strfont, 0, KEY_ALL_ACCESS, LOC(phkey))

typeface="Arial"
typeface(6:6)=char(0)
ret1= RegQueryVAlueEx(phkey, typeface, NULL, LOC(type1), LOC(data1), LOC(datasize))

print * data1

stop

end

_________________________________

ret has a value of 0 from RegOpenKeyex so presume ok, ret1 has value of 2, phkep and type1 have values of 3916

I am expecting ARIAL.TTY in data1

0 Kudos
anthonyrichards
New Contributor III
1,684 Views

Please find the attached program, which, when set up as a console application, produces the output shown below and
in the JPG file. Hope this helps. Note that I am using Windows XP and the registry key used below shows font names as containing the '(TrueType)' string, so the first example fails to find a key value 'Arial Italic' because that string is not present in the font name.

Hello World
Registry subkey for fonts =SoftwareMicrosoftWindows NTCurrentVersionFonts
Font name =Arial Italic , File name =
Font name =Arial Italic (TrueType) , File name =ARIALI.TTF
Font name =Arial Black Italic (TrueType) , File name =ARBLI___.TTF
Font name =Arial Bold Italic (TrueType) , File name =ARIALBI.TTF
Font name =Arial Narrow Italic (TrueType) , File name =ARIALNI.TTF
Press any key to continue
0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,684 Views
But take a look at your data yourself using regedit -- alas, the value name you're after is "Arial (TrueType)" rather than plain "Arial".

There's no reliable way to do that, I'm afraid. You can assume that the string contains "(TrueType)" and append it yourself -- not too attractive. You could call RegEnumValue to get all the values from HKLM...CurrentVersionFonts, and then parse the strings and compare them with the typeface name you're after.

P.S. It's much more reliable to append char(0) like:
strFont = "SoftwareMicrosoftWindows NTCurrentVersionFonts"//char(0)
You don't need the double backlashes unless you use ""C strings, i.e. you will need them only if you write like:
"SoftwareMicrosoftWindows NTCurrentVersionFonts"C
0 Kudos
Steven_L_Intel1
Employee
1,684 Views
You CAN get the full name from the font enumeration functions.(EnumFontFamiliesEx).- the name will be in the ENUMLOGFONTEX structure.
0 Kudos
steve_konarski
Beginner
1,684 Views

Thanks Anthony - I have now incorporated the relavent parts of your code into my program and it works well - I missed the (True Type) from the font name , and Ihad double slashes inthe reg key location, and your help got me to where i wanted

Just one more hurdle to get over - and that is

SUBKEY="SoftwareMicrosoftWindows NTCurrentVersionFonts"//CHAR(0)

which I dont think will work on Vista or some widows versions

IS there a function available to fortran which would give the correct windows version - I think the SUBKEY for each would still have to be hard coded into the fortran source code for each version but that is a minor inconvenience

thanks again Steve Konarski

0 Kudos
steve_konarski
Beginner
1,684 Views
Thanks jugoslav thats a great help its confusing at times to get the structure correct
0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,684 Views
See GetVersion(Ex) API -- it returns the Windows version information.
0 Kudos
Steven_L_Intel1
Employee
1,684 Views
There's also the Platform sample in ifort 10.1.
0 Kudos
Reply