kcvinu Posted February 28, 2016 Posted February 28, 2016 (edited) Hi all, I would like to know how to check if a specific font is installed in user's system. If it is not installed, my program needs to install the font. (Don't worry about the copy right of the font. it's free) I have got some points from google which directs me into _WinAPI_AddFontResourceEx function. But help file says that this function is only for current session. And i also got the _WinAPI_EnumFontFamilies function too. But before trying any of these, i would like to hear from the masters. Edited February 28, 2016 by kcvinu Spoiler My Contributions Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language. UDF Link Viewer --- A tool to visit the links of some most important UDFs Includer_2 ----- A tool to type the #include statement automatically Digits To Date ----- date from 3 integer values PrintList ----- prints arrays into console for testing. Alert ------ An alternative for MsgBox MousePosition ------- A simple tooltip display of mouse position GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function Access_UDF -------- An UDF for working with access database files. (.*accdb only)
kcvinu Posted February 28, 2016 Author Posted February 28, 2016 Well, i digged this with a deep search Not bad i think. Spoiler My Contributions Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language. UDF Link Viewer --- A tool to visit the links of some most important UDFs Includer_2 ----- A tool to type the #include statement automatically Digits To Date ----- date from 3 integer values PrintList ----- prints arrays into console for testing. Alert ------ An alternative for MsgBox MousePosition ------- A simple tooltip display of mouse position GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function Access_UDF -------- An UDF for working with access database files. (.*accdb only)
mikell Posted February 28, 2016 Posted February 28, 2016 _WinAPI_EnumFontFamilies is perfect to check if a font exists... why didn't you try it ? _WinAPI_AddFontResourceEx installs the font only for the current session, but anyway the font gets installed when the script is launched kcvinu 1
kcvinu Posted February 28, 2016 Author Posted February 28, 2016 Thanks @mikell . I just hesitated because the time it consumes for getting all fonts list. And what do you mean by "script is launched ?. Help file says that it won't work after a restart. Spoiler My Contributions Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language. UDF Link Viewer --- A tool to visit the links of some most important UDFs Includer_2 ----- A tool to type the #include statement automatically Digits To Date ----- date from 3 integer values PrintList ----- prints arrays into console for testing. Alert ------ An alternative for MsgBox MousePosition ------- A simple tooltip display of mouse position GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function Access_UDF -------- An UDF for working with access database files. (.*accdb only)
InunoTaishou Posted February 28, 2016 Posted February 28, 2016 _WinAPI_AddFontResourceEx Quote Remarks This function installs the font only for the current session. When the system restarts, the font will not be present. To have the font installed even after restarting the system, the font must be listed in the registry. It'll just be removed after a restart, I'm sure there's a way to install it and update the registry ;). Unless you don't wanna add it to the registry, in which case I doubt the time it takes to install the font is noticeable. Also #include <WinAPIGdi.au3> #include <Array.au3> Local $timer = TimerInit() Local $font_families = _WinAPI_EnumFontFamilies() Local $time = TimerDiff($timer) / 1000 _ArrayDisplay($font_families, $time) 1672 fonts installed, .2 second to finish the execution of the function. kcvinu 1
kcvinu Posted February 28, 2016 Author Posted February 28, 2016 Since my program is portable, i don't want to play with users registry. Spoiler My Contributions Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language. UDF Link Viewer --- A tool to visit the links of some most important UDFs Includer_2 ----- A tool to type the #include statement automatically Digits To Date ----- date from 3 integer values PrintList ----- prints arrays into console for testing. Alert ------ An alternative for MsgBox MousePosition ------- A simple tooltip display of mouse position GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function Access_UDF -------- An UDF for working with access database files. (.*accdb only)
mikell Posted February 28, 2016 Posted February 28, 2016 kcvinu, I meant : I assume that you use FileInstall and that the script at each launch will check then install the font if necessary kcvinu 1
AutoBert Posted February 28, 2016 Posted February 28, 2016 1 minute ago, kcvinu said: Since my program is portable, i don't want to play with users registry. So on evry starting your programm: test if font exists (_WinAPI_EnumFontFamilies) if not install it for this session (_WinAPI_AddFontResourceEx)
kcvinu Posted February 28, 2016 Author Posted February 28, 2016 No @AutoBert , i am planning to write the data to an ini file Spoiler My Contributions Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language. UDF Link Viewer --- A tool to visit the links of some most important UDFs Includer_2 ----- A tool to type the #include statement automatically Digits To Date ----- date from 3 integer values PrintList ----- prints arrays into console for testing. Alert ------ An alternative for MsgBox MousePosition ------- A simple tooltip display of mouse position GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function Access_UDF -------- An UDF for working with access database files. (.*accdb only)
kcvinu Posted February 28, 2016 Author Posted February 28, 2016 @InunoTaishou Thank you man. That's not a big delay for my program. Now i am testing Fileinstall Spoiler My Contributions Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language. UDF Link Viewer --- A tool to visit the links of some most important UDFs Includer_2 ----- A tool to type the #include statement automatically Digits To Date ----- date from 3 integer values PrintList ----- prints arrays into console for testing. Alert ------ An alternative for MsgBox MousePosition ------- A simple tooltip display of mouse position GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function Access_UDF -------- An UDF for working with access database files. (.*accdb only)
mLipok Posted February 28, 2016 Posted February 28, 2016 Just check for c:\Windows\Fonts\ kcvinu 1 Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24
jguinch Posted February 28, 2016 Posted February 28, 2016 Or in the registry : HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts kcvinu 1 Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
kcvinu Posted February 29, 2016 Author Posted February 29, 2016 @mLipok & @jguinch I am happy with _WinAPI_EnumFontFamilies function for finding if the font is installed or not. Now i need to install the font if it is not in the system. Is there any method other than FileInstall ? Spoiler My Contributions Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language. UDF Link Viewer --- A tool to visit the links of some most important UDFs Includer_2 ----- A tool to type the #include statement automatically Digits To Date ----- date from 3 integer values PrintList ----- prints arrays into console for testing. Alert ------ An alternative for MsgBox MousePosition ------- A simple tooltip display of mouse position GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function Access_UDF -------- An UDF for working with access database files. (.*accdb only)
InunoTaishou Posted February 29, 2016 Posted February 29, 2016 (edited) This will install it and save it to the registry so it won't be removed on startup. Honestly though I've used _WinAPI_AddFontResourceEX in a program I made that I used frequently (close and restart) and there was never any problem or delay to install the three custom fonts I used. Don't know if you're worried about the overhead or the processing speed but when you're just working with small files (my .ttf files were 12kb, 22kb, and 324kb) and checking checking (not accessing) a lot of files, almost all, modern, machines can do the processing without any any noticeable delay. #include <WinAPIGdi.au3> #include <Array.au3> Local $timer_init = TimerInit() Local $font_families = _WinAPI_EnumFontFamilies() Local $time_enum_font_families = TimerDiff($timer_init) / 1000 & "s" $timer_init = TimerInit() Local $font_installed = _ArraySearch($font_families, "Futura", 0, 0, 0, 1) Local $time_array_search = TimerDiff($timer_init) / 1000 & "s" Local $time_font_install = 0 If ($font_installed = -1) Then $timer_init = TimerInit() _WinAPI_AddFontResourceEx("Futura Extra Bold.ttf", $FR_PRIVATE) $time_font_install = TimerDiff($timer_init) / 1000 & "s" EndIf MsgBox("", "Time", "Time to enum font families: " & $time_enum_font_families & @CRLF & _ "Time to search through (" & $font_families[0][0] & ") font families: " & $time_array_search & @CRLF & _ "Time to add font resource: " & $time_font_install) Time to enum font families: 0.210863995560568s Time to search through (1672) font families: 0.0302487330923837s Time to add font resource: 0.00023872755105527s It would probably be more efficient to just always install your font on startup, save yourself roughly 1/4 - 1/5 of a second. Edited February 29, 2016 by InunoTaishou kcvinu 1
kcvinu Posted February 29, 2016 Author Posted February 29, 2016 @InunoTaishou Your last point is most important. I just want install the font at once. And thank you for that link. It is helpful. Spoiler My Contributions Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language. UDF Link Viewer --- A tool to visit the links of some most important UDFs Includer_2 ----- A tool to type the #include statement automatically Digits To Date ----- date from 3 integer values PrintList ----- prints arrays into console for testing. Alert ------ An alternative for MsgBox MousePosition ------- A simple tooltip display of mouse position GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function Access_UDF -------- An UDF for working with access database files. (.*accdb only)
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now