-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathFontSelect_V1.ahk
116 lines (95 loc) · 4.15 KB
/
FontSelect_V1.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
; Link: https://raw.githubusercontent.com/TheArkive/CallTipsForAll/master/LibV1/_Font_Picker_Dialog_v1.ahk
; Author:
; Date:
; for: AHK_L
/*
*/
; originally posted by maestrith
; https://autohotkey.com/board/topic/94083-ahk-11-font-and-color-dialogs/
; to initialize fontObject object (not required):
; ============================================
; fontObject := Object("name","Tahoma","size",14,"color",0xFF0000,"strike",1,"underline",1,"italic",1,"bold",1)
; ==================================================================
; fntName = name of var to store selected font
; fontObject = name of var to store fontObject
; hwnd = parent gui hwnd for modal, leave blank for not modal
; effects = allow selection of underline / strike out / italic
; ==================================================================
; fontObject output:
;
; fontObject["str"] = string to use with AutoHotkey to set GUI values - see examples
; fontObject["hwnd"] = handle of the font object to use with SendMessage - see examples
; ==================================================================
FontSelect(fontObject:="",hwnd:=0,effects:=1) {
fontObject := (fontObject="") ? Object() : fontObject
VarSetCapacity(logfont,60)
uintVal := DllCall("GetDC","uint",0)
LogPixels := DllCall("GetDeviceCaps","uint",uintVal,"uint",90)
Effects := 0x041 + (Effects ? 0x100 : 0)
fntName := fontObject.HasKey("name") ? fontObject["name"] : ""
fontBold := fontObject.HasKey("bold") ? fontObject["bold"] : 0
fontBold := fontBold ? 700 : 400
fontItalic := fontObject.HasKey("italic") ? fontObject["italic"] : 0
fontUnderline := fontObject.HasKey("underline") ? fontObject["underline"] : 0
fontStrikeout := fontObject.HasKey("strike") ? fontObject["strike"] : 0
fontSize := fontObject.HasKey("size") ? fontObject["size"] : 10
fontSize := fontSize ? Floor(fontSize*LogPixels/72) : 16
c := fontObject.HasKey("color") ? fontObject["color"] : 0
c1 := Format("0x{:02X}",(c&255)<<16) ; convert RGB colors to BGR for input
c2 := Format("0x{:02X}",c&65280)
c3 := Format("0x{:02X}",c>>16)
fontColor := Format("0x{:06X}",c1|c2|c3)
fontval := Object(16,fontBold,20,fontItalic,21,fontUnderline,22,fontStrikeout,0,fontSize)
for a,b in fontval
NumPut(b,logfont,a)
cap:=VarSetCapacity(choosefont,A_PtrSize=8?103:60,0)
NumPut(hwnd,choosefont,A_PtrSize)
offset1 := (A_PtrSize = 8) ? 24 : 12
offset2 := (A_PtrSize = 8) ? 36 : 20
offset3 := (A_PtrSize = 4) ? 6 * A_PtrSize : 5 * A_PtrSize
fontArray := Array([cap,0,"Uint"],[&logfont,offset1,"Uptr"],[effects,offset2,"Uint"],[fontColor,offset3,"Uint"])
for index,value in fontArray
NumPut(value[1],choosefont,value[2],value[3])
if (A_PtrSize=8) {
strput(fntName,&logfont+28)
r := DllCall("comdlg32\ChooseFont","uptr",&CHOOSEFONT,"cdecl")
fntName := strget(&logfont+28)
} else {
strput(fntName,&logfont+28,32,"utf-8")
r := DllCall("comdlg32\ChooseFontA","uptr",&CHOOSEFONT,"cdecl")
fntName := strget(&logfont+28,32,"utf-8")
}
if !r
return false
fontObj := Object("bold",16,"italic",20,"underline",21,"strike",22)
for a,b in fontObj
fontObject[a] := NumGet(logfont,b,"UChar")
fontObject["bold"] := (fontObject["bold"] < 188) ? 0 : 1
c := NumGet(choosefont,A_PtrSize=4?6*A_PtrSize:5*A_PtrSize) ; convert from BGR to RBG for output
c1 := Format("0x{:02X}",(c&255)<<16)
c2 := Format("0x{:02X}",c&65280)
c3 := Format("0x{:02X}",c>>16)
c := Format("0x{:06X}",c1|c2|c3)
fontObject["color"] := c
fontObject["size"] := NumGet(choosefont,A_PtrSize=8?32:16,"UInt")//10
fontHwnd := DllCall("CreateFontIndirect","uptr",&logfont) ; last param "cdecl"
fontObject["name"] := fntName
If (!fontHwnd) {
fontObject := ""
return 0
} Else {
fontObject["hwnd"] := fontHwnd
b := fontObject["bold"] ? "bold" : ""
i := fontObject["italic"] ? "italic" : ""
s := fontObject["strike"] ? "strike" : ""
c := fontObject["color"] ? "c" fontObject["color"] : ""
z := fontObject["size"] ? "s" fontObject["size"] : ""
u := fontObject["underline"] ? "underline" : ""
fullStr := b "|" i "|" s "|" c "|" z "|" u
Loop Parse, fullStr, |
If (A_LoopField)
str .= A_LoopField " "
fontObject["str"] := "norm " Trim(str)
return fontObject
}
}