[Class] CustomFont - Load font from file or resource, without needed install to system.
Re: [Class] CustomFont - Load font from file or resource, without needed install to system.
Thanks tmplinshi, looks promising. Unfortunately I only get a rectangle image on the menu, regardless of the icon no.
Re: [Class] CustomFont - Load font from file or resource, without needed install to system.
Works fine here with latest AHK U32/U64. I've packed all necessary files, you can download at: https://drive.google.com/open?id=1a1_RYPLDjE88d90ppc-ealUX3VhGJFxj
Re: [Class] CustomFont - Load font from file or resource, without needed install to system.
Thanks, very kind. I tried on Win10 and it works great.
It still doesn't work on my Win7 machine, I'll check what might be the issue.

It still doesn't work on my Win7 machine, I'll check what might be the issue.
Re: [Class] CustomFont - Load font from file or resource, without needed install to system.
Guess what, It works on Win10, it's because the font "Segoe MDL2 Assets" is a built-in font on Win10

Then I tried another font generated by http://fontello.com/, it didn't work.
Here is another method without using Class_CustomFont.ahk.
Code: Select all
SetWorkingDir %A_ScriptDir%
#Include <Gdip_All>
#Include <Subtitle> ; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=36384
pToken := Gdip_Startup()
hFamily := Gdip_CreateFontFamilyFromFile("fontello.ttf")
pBitmap := Subtitle.RenderToBitmap(Chr(0xe800), {color:"Transparent"}, {s:24, hFamily:hFamily, color:"black"})
hIcon := Gdip_CreateHICONFromBitmap(pBitmap)
Menu, TestMenu, Add, Smile, MenuOnClick
Menu, TestMenu, Icon, Smile, hIcon:%hIcon%,, 24
Menu, TestMenu, Show
Menu, TestMenu, Delete
Gdip_Shutdown(pToken)
ExitApp
Gdip_CreateFontFamilyFromFile(FontFile, FontName := "") {
if !FileExist(FontFile)
throw "Font file not exist: " . FontFile
DllCall("gdiplus\GdipNewPrivateFontCollection", "ptr*", hCollection)
; FileRead, fontData, *c %FontFile%
; DllCall("gdiplus\GdipPrivateAddMemoryFont", "ptr", hCollection, "ptr", &fontData, "uint", VarSetCapacity(fontData))
DllCall("gdiplus\GdipPrivateAddFontFile", "ptr", hCollection, "str", FontFile)
if (FontName = "") {
VarSetCapacity(pFontFamily, 10, 0)
DllCall("gdiplus\GdipGetFontCollectionFamilyList", "ptr", hCollection, "int", 1, "ptr", &pFontFamily, "int*", found)
VarSetCapacity(FontName, 100)
DllCall("gdiplus\GdipGetFamilyName", "ptr", NumGet(pFontFamily, 0, "ptr"), "str", FontName, "ushort", 1033)
}
DllCall("gdiplus\GdipCreateFontFamilyFromName", "str", FontName, "ptr", hcollection, "uint*", hFamily)
return hFamily
}
MenuOnClick(ItemName) {
MsgBox, % ItemName
}
Code: Select all
; Create Font.
if style2.hFamily
hFamily := style2.hFamily
else
hFamily := (___ := Gdip_FontFamilyCreate(f)) ? ___ : Gdip_FontFamilyCreate("Arial") ; Default font is Arial.
- Attachments
-
- Gidplus load ttf font file example.zip
- (37.37 KiB) Downloaded 54 times
Re: [Class] CustomFont - Load font from file or resource, without needed install to system.
It works, thanks!
But not sure Class_CustomFont is a problem. First part of this works in Win7:
But not sure Class_CustomFont is a problem. First part of this works in Win7:
Code: Select all
SetWorkingDir %A_ScriptDir%
#Include <Gdip_All>
#Include <Subtitle> ; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=36384
#Include <Class_CustomFont>
font1 := New CustomFont("SegMDL2.ttf")
gui, font, s12, Segoe MDL2 Assets
gui, add, text,, % chr(0xE713)
gui, show
pToken := Gdip_Startup()
pBitmap := Subtitle.RenderToBitmap(Chr(0xE713), "color:Transparent", "s:24 f:(Segoe MDL2 Assets) color:black")
hIcon := Gdip_CreateHICONFromBitmap(pBitmap)
Menu, TestMenu, Add, Settings, MenuOnClick
Menu, TestMenu, Icon, Settings, hIcon:%hIcon%,, 24
Menu, TestMenu, Show
Menu, TestMenu, Delete
ExitApp
MenuOnClick(ItemName) {
MsgBox, % ItemName
}
-
- Posts: 745
- Joined: 30 Sep 2017, 03:59
- Facebook: marius.sucan
- GitHub: mariussucan
- Location: Romania
- Contact:
Re: [Class] CustomFont - Load font from file or resource, without needed install to system.
I will include this into the GDI+ library edition I created. It works great.
Please let me know if you wish not to have it included in my GDI+ lib.
Best regards, Marius.
Please let me know if you wish not to have it included in my GDI+ lib.
Best regards, Marius.
tmplinshi wrote: ↑23 Oct 2019, 07:28Guess what, It works on Win10, it's because the font "Segoe MDL2 Assets" is a built-in font on Win10 :shock:
Then I tried another font generated by http://fontello.com/, it didn't work.
Here is another method without using Class_CustomFont.ahk.Note that I added 3 lines to Subtitle.ahk:Code: Select all
SetWorkingDir %A_ScriptDir% #Include <Gdip_All> #Include <Subtitle> ; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=36384 pToken := Gdip_Startup() hFamily := Gdip_CreateFontFamilyFromFile("fontello.ttf") pBitmap := Subtitle.RenderToBitmap(Chr(0xe800), {color:"Transparent"}, {s:24, hFamily:hFamily, color:"black"}) hIcon := Gdip_CreateHICONFromBitmap(pBitmap) Menu, TestMenu, Add, Smile, MenuOnClick Menu, TestMenu, Icon, Smile, hIcon:%hIcon%,, 24 Menu, TestMenu, Show Menu, TestMenu, Delete Gdip_Shutdown(pToken) ExitApp Gdip_CreateFontFamilyFromFile(FontFile, FontName := "") { if !FileExist(FontFile) throw "Font file not exist: " . FontFile DllCall("gdiplus\GdipNewPrivateFontCollection", "ptr*", hCollection) ; FileRead, fontData, *c %FontFile% ; DllCall("gdiplus\GdipPrivateAddMemoryFont", "ptr", hCollection, "ptr", &fontData, "uint", VarSetCapacity(fontData)) DllCall("gdiplus\GdipPrivateAddFontFile", "ptr", hCollection, "str", FontFile) if (FontName = "") { VarSetCapacity(pFontFamily, 10, 0) DllCall("gdiplus\GdipGetFontCollectionFamilyList", "ptr", hCollection, "int", 1, "ptr", &pFontFamily, "int*", found) VarSetCapacity(FontName, 100) DllCall("gdiplus\GdipGetFamilyName", "ptr", NumGet(pFontFamily, 0, "ptr"), "str", FontName, "ushort", 1033) } DllCall("gdiplus\GdipCreateFontFamilyFromName", "str", FontName, "ptr", hcollection, "uint*", hFamily) return hFamily } MenuOnClick(ItemName) { MsgBox, % ItemName }
Code: Select all
; Create Font. if style2.hFamily hFamily := style2.hFamily else hFamily := (___ := Gdip_FontFamilyCreate(f)) ? ___ : Gdip_FontFamilyCreate("Arial") ; Default font is Arial.
-------------------------
KeyPress OSD v4: GitHub or forum. (presentation video)
Quick Picto Viewer: GitHub or forum.
AHK GDI+ expanded / compilation library (on GitHub)
My home page.
KeyPress OSD v4: GitHub or forum. (presentation video)
Quick Picto Viewer: GitHub or forum.
AHK GDI+ expanded / compilation library (on GitHub)
My home page.
-
- Posts: 67
- Joined: 08 Jun 2019, 17:36
Re: [Class] CustomFont - Load font from file or resource, without needed install to system.
Anyone know why Class_CustomFont.ahk might fail?
Here is a snip of the code below:
On all systems I have tested on this works completely fine (top picture). A user has sent me a screenshot and the text is all random characters (bottom picture).
https://gyazo.com/15e8ae23e07f5b577e738f8ee0aca59e
Here is a snip of the code below:
Code: Select all
#Include Class_CustomFont.ahk
fileinstall, Images\logos\Lato-Regular.ttf ,% Base_Folder "Images\logos\Lato-Regular.ttf"
font1 := New CustomFont(Base_Folder "Images\logos\Lato-Regular.ttf")
gui, font, s13 cWhite underline, Lato
gui, add, text, backgroundtrans xs+11 w225 center ys+15, Profiles
https://gyazo.com/15e8ae23e07f5b577e738f8ee0aca59e
Return to “Scripts and Functions”
Who is online
Users browsing this forum: Bing [Bot], Steuerfachwissen and 22 guests