12 proc FontDialog {font_name {options ""} {fixedOnly 0}} {
13 global fd_family fd_style fd_size fd_close
14 global fd_strikeout fd_underline
16 set fd_family {}
set fd_style {}
set fd_size {}
19 set unsorted_fam [font families]
20 set families [lsort $unsorted_fam]
25 if {[font metrics [list $f] -fixed] == 1} {
lappend families $f}
30 if {[
llength $options] == 4} {
32 set family [
lindex $options 0]
33 set size [
lindex $options 1]
34 set weight [
lindex $options 2]
35 set slant [
lindex $options 3]
38 set family [font actual $font_name -family]
39 set size [font actual $font_name -size]
40 set weight [font actual $font_name -weight]
41 set slant [font actual $font_name -slant]
45 set fd_style "Regular"
46 if { $slant == "italic" } {
47 if { $weight == "bold" } {
48 set fd_style "Bold Italic"
53 if { $weight == "bold" } {
65 pack [ttk::frame $tl.f] -expand 1 -fill both
66 wm protocol $tl WM_DELETE_WINDOW "set fd_close 0"
69 ttk::label $dlg.family_lbl -text "Font:" -anchor w
70 ttk::entry $dlg.family_ent -textvariable fd_family -background white
71 bind $dlg.family_ent <Key-Return> "FontDialogRegen $font_name"
72 grid config $dlg.family_lbl -column 0 -row 0 -sticky w
73 grid config $dlg.family_ent -column 0 -row 1 -sticky snew
75 ttk::label $dlg.style_lbl -text "Font Style:" -anchor w
76 ttk::entry $dlg.style_ent -textvariable fd_style -width 11 -background white
77 bind $dlg.style_ent <Key-Return> "FontDialogRegen $font_name"
78 grid config $dlg.style_lbl -column 1 -row 0 -sticky w
79 grid config $dlg.style_ent -column 1 -row 1 -sticky snew
81 ttk::label $dlg.size_lbl -text "Size:" -anchor w
82 ttk::entry $dlg.size_ent -textvariable fd_size -width 4 -background white
83 bind $dlg.size_ent <Key-Return> "FontDialogRegen $font_name"
84 grid config $dlg.size_lbl -column 2 -row 0 -sticky w
85 grid config $dlg.size_ent -column 2 -row 1 -sticky snew
88 set fr $dlg.family_list
90 listbox $fr.list -height 6 -selectmode single -width 30 -background white -yscrollcommand "$fr.scroll set"
91 ttk::scrollbar $fr.scroll -command "$fr.list yview"
94 $fr.list insert end $f
97 bind $fr.list <Double-Button-1> "FontDialogFamily $fr.list $font_name $dlg.family_ent"
99 pack $fr.scroll -side right -fill y
100 pack $fr.list -side left
101 grid config $fr -column 0 -row 2 -rowspan 16
104 set fr $dlg.style_list
106 listbox $fr.list -height 6 -selectmode single -width 11 -background white -yscrollcommand "$fr.scroll set"
107 ttk::scrollbar $fr.scroll -command "$fr.list yview"
109 $fr.list insert end "Regular"
110 $fr.list insert end "Bold"
111 $fr.list insert end "Italic"
112 $fr.list insert end "Bold Italic"
114 bind $fr.list <Double-Button-1> "FontDialogStyle $fr.list $font_name $dlg.style_ent"
116 pack $fr.scroll -side right -fill y
117 pack $fr.list -side left
118 grid config $fr -column 1 -row 2 -rowspan 16
121 set fr $dlg.size_list
123 listbox $fr.list -height 6 -selectmode single -width 4 -background white -yscrollcommand "$fr.scroll set"
124 ttk::scrollbar $fr.scroll -command "$fr.list yview"
126 for {
set i 7} {$i <= 20} {
incr i} {
127 $fr.list insert end $i
130 bind $fr.list <Double-Button-1> "FontDialogSize $fr.list $font_name $dlg.size_ent"
132 pack $fr.scroll -side right -fill y
133 pack $fr.list -side left
134 grid config $fr -column 2 -row 2 -rowspan 16
137 set fr $dlg.ok_cancel
140 ttk::button $fr.ok -text "OK" -command "set fd_close 1"
141 ttk::button $fr.cancel -text "Cancel" -command "set fd_close 0"
142 pack $fr.ok -side top -fill x
143 pack $fr.cancel -side top -fill x -pady 2
144 ttk::button $fr.help -text "Help" -command "helpWindow Options"
145 pack $fr.help -side top -fill x -pady 10
146 grid config $fr -column 4 -row 1 -rowspan 2 -sticky snew -padx 12
150 ttk::frame $fr -borderwidth 3 -relief groove
151 ttk::label $fr.l_sample -text "Sample" -anchor w
153 ttk::label $fr.sample -font $font_name -relief sunken -text "This is some sample text\nAaBbCcDdEeFfGgHhIiJjKkLlMm\n 0123456789. +=-\n\u2654 \u2655 \u2656 \u2657 \u2658"
155 pack $fr.l_sample -side top -fill x -pady 4
156 pack $fr.sample -side top -pady 4 -ipadx 10 -ipady 10
158 grid config $fr -column 0 -columnspan 3 -row 20 -rowspan 2 -sticky snew -pady 10 -padx 2
161 tkwait variable fd_close
167 if { $fd_close == 0 } {
168 font configure $font_name -family $family -size $size -slant $slant -weight $weight
176 proc FontDialogFamily { listname font_name entrywidget } {
179 set item_num [$listname curselection]
180 set item [$listname get $item_num]
183 $entrywidget delete 0 end
184 $entrywidget insert end $item
192 proc FontDialogStyle { listname font_name entrywidget } {
195 set item_num [$listname curselection]
196 set item [$listname get $item_num]
199 $entrywidget delete 0 end
200 $entrywidget insert end $item
208 proc FontDialogSize { listname font_name entrywidget } {
211 set item_num [$listname curselection]
212 set item [$listname get $item_num]
215 $entrywidget delete 0 end
216 $entrywidget insert end $item
223 proc FontWeight {style} {
224 if { $style == "Bold Italic" || $style == "Bold" } {
230 proc FontSlant {style} {
231 if { $style == "Bold Italic" || $style == "Italic" } {
238 proc FontDialogRegen { font_name } {
239 global fd_family fd_style fd_size
242 if { $fd_style == "Bold Italic" || $fd_style == "Bold" } {
247 if { $fd_style == "Bold Italic" || $fd_style == "Italic" } {
252 font configure $font_name -family $fd_family -size $fd_size -slant $slant -weight $weight