-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathCreateFont.ahk
42 lines (36 loc) · 1.4 KB
/
CreateFont.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
;--------------------------------------------------------------------------
; Function: CreateFont
; Creates font in memory which can be used with any API function accepting font handles.
;
; Parameters:
; pFont - AHK font description, "style, face"
;
; Returns:
; Font handle
;
; Example:
;> hFont := CreateFont("s12 italic, Courier New")
;> SendMessage, 0x30, %hFont%, 1,, ahk_id %hGuiControl% ;WM_SETFONT = 0x30
CreateFont(pFont="") {
;parse font
italic := InStr(pFont, "italic") ? 1 : 0
underline := InStr(pFont, "underline") ? 1 : 0
strikeout := InStr(pFont, "strikeout") ? 1 : 0
weight := InStr(pFont, "bold") ? 700 : 400
;height
RegExMatch(pFont, "(?<=[S|s])(\d{1,2})(?=[ ,])", height)
if (height = "")
height := 10
RegRead, LogPixels, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontDPI, LogPixels
height := -DllCall("MulDiv", "int", Height, "int", LogPixels, "int", 72)
;face
RegExMatch(pFont, "(?<=,).+", fontFace)
if (fontFace != "")
fontFace := RegExReplace( fontFace, "(^\s*)|(\s*$)") ;trim
else fontFace := "MS Sans Serif"
;create font
hFont := DllCall("CreateFont", "int", height, "int", 0, "int", 0, "int", 0
,"int", weight, "Uint", italic, "Uint", underline
,"uint", strikeOut, "Uint", nCharSet, "Uint", 0, "Uint", 0, "Uint", 0, "Uint", 0, "str", fontFace)
return hFont
}