Old 3rd June 2010, 08:24   #1
jiake
Senior Member
 
jiake's Avatar
 
Join Date: Oct 2007
Location: Shanghai, China
Posts: 207
Can I get font name Using API ?

Last time I post a thread about the FontName plugin. I said that the plugin can only get the English name of the font. I used to contact the author, but the plugin is built in 2007, I thought it is not easy to contact to him. Later I search in internet, someone said that a win32 API could get the infomation of a font file.

This is an article about the funtion:
http://www.undocprint.org/winspool/getfontresourceinfo

I tried to use it, but I didn't get the result as my programming is poor. Would you help me to write an example script to show the usage?
jiake is offline   Reply With Quote
Old 3rd June 2010, 10:53   #2
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
Nice find. I'm not sure if it gets exactly what you need but here you go anyway (see attached script). Tested on Windows 7 (Verdana.ttf -> Verdana).

Stu
Attached Files
File Type: nsi Test.nsi (642 Bytes, 461 views)
Afrow UK is offline   Reply With Quote
Old 3rd June 2010, 14:33   #3
jiake
Senior Member
 
jiake's Avatar
 
Join Date: Oct 2007
Location: Shanghai, China
Posts: 207
Quote:
Originally Posted by Afrow UK View Post
Nice find. I'm not sure if it gets exactly what you need but here you go anyway (see attached script). Tested on Windows 7 (Verdana.ttf -> Verdana).

Stu
Thanks a lot!
I test your script like this:
PHP Code:
  Push simsun.ttc
  Call GetFontName
  Pop $R0
  DetailPrint $R0
  Push simhei
.ttf
  Call GetFontName
  Pop $R0
  DetailPrint $R0 
It exactly prints the Chinese font name:


When I have a lot of TTF fonts to install, I must write to registry for every font file before, for the FontName plugin only got the English names. But now, I can easily inst any TTF fonts in custom folder by using a macro. This function is not only useful to me, but also to more users from different contries. Thank you again!
Attached Thumbnails
Click image for larger version

Name:	未命名.PNG
Views:	1925
Size:	12.2 KB
ID:	47066  

Last edited by jiake; 3rd June 2010 at 15:15.
jiake is offline   Reply With Quote
Old 3rd June 2010, 18:30   #4
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
That's great. I will put it on the Wiki when it's back up (down at the moment).

Stu
Afrow UK is offline   Reply With Quote
Old 3rd June 2010, 18:35   #5
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
I just updated the function with a missing Push/Pop for $R2.

Stu
Afrow UK is offline   Reply With Quote
Old 4th June 2010, 11:46   #6
jiake
Senior Member
 
jiake's Avatar
 
Join Date: Oct 2007
Location: Shanghai, China
Posts: 207
Thanks, I have downloaded the new one.
Ok, more users may view it also on Wiki now.
jiake is offline   Reply With Quote
Old 4th June 2010, 12:02   #7
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
Posted: http://nsis.sourceforge.net/Get_localised_font_name

Stu
Afrow UK is offline   Reply With Quote
Old 19th June 2010, 04:18   #8
jiake
Senior Member
 
jiake's Avatar
 
Join Date: Oct 2007
Location: Shanghai, China
Posts: 207
Recently, I found that I get only "error" when using this code. I found that, I tried to "push" a installed font file name, it returned the correct name, but when I "push" a file name that is not yet installed, it always returned "error". At the beginning I donot know why, later I imagine that the font resource must be added to system first, actually that's it.

So, to install a font, you must insert this line before get its name and write to registry:
System::Call "gdi32::AddFontResource(t 'FontFileName')"

PHP Code:
ReadRegStr $0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" "CurrentVersion"
IfErrors Win9x WinNT

Win9x
:
StrCpy $FONTREGKEY "Software\Microsoft\Windows\CurrentVersion\Fonts"
Goto RegFont

WinNT
:
StrCpy $FONTREGKEY "Software\Microsoft\Windows NT\CurrentVersion\Fonts"
Goto RegFont

RegFont
:
ClearErrors

!macro InstFont FONTFILE
        System
::Call "gdi32::AddFontResource(t '${FONTFILE}')"
        
Push '${FONTFILE}'
        
Call GetFontName
        Pop $R0
        
${If} $R0 != 'error'
            
WriteRegStr HKLM '$FONTREGKEY' '$R0 (TrueType)' '${FONTFILE}'
        
${Else}
            
System::Call "gdi32::RemoveFontResource(t '${FONTFILE}')"
        
${EndIf}
!
macroend

FindFirst 
$$'$INSTDIR\TrueType\*.ttf'
loop:
        
StrCmp $"" done
        
!insertmacro InstFont '$INSTDIR\TrueType\$1'
        
FindNext $$1
        
Goto loop
done
:

SendMessage ${HWND_BROADCAST} ${WM_FONTCHANGE0 0 
jiake is offline   Reply With Quote
Old 9th July 2015, 13:20   #9
stass
Senior Member
 
Join Date: Nov 2012
Posts: 166
If you change the name of the font file, the code is not working ...
( For example, if I change the file name to the arial.ttf - arial1.ttf - I get an error. )

We need to get a real Font name, regardless of the name of the font file...
How to do it?

ps
Please tell me - a syntax for the plugin FontName plug-in ? The documentation does not even have examples of ...
Quote:
!insertmacro FontName "MyFontFile.ttf"
How to get out of here the name of the font ?
http://nsis.sourceforge.net/FontName_plug-in
stass is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump