# cfont.tcl --
#
# This demonstration script shows how to use compound founts.
#

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

set w .cfont
catch {destroy $w}
toplevel $w
wm title $w "Compound Font Demonstration"
wm iconname $w "cfont"
positionWindow $w

label $w.msg -font $font -wraplength 4i -justify left -text [langSel \
"Choose the family, styles and size of both ASCII and KANJI fonts.  Then press the \"Show Sample\" button to see a sample label of the compound font." \
"ASCII フォントと漢字フォントそれぞれのファミリ、スタイル、大きさを選んで「見本を表示」ボタンを押してください。指定したコンパウンドフォントの見本ラベルが表示されます。"]
pack $w.msg -side top

frame $w.buttons
pack $w.buttons -side bottom -fill x -pady 2m
button $w.buttons.dismiss -text [langSel Dismiss 了解] -command "destroy $w"
button $w.buttons.code -text [langSel "See Code" "コード参照"] -command "showCode $w"
button $w.buttons.sample -text [langSel "Show Sample" "見本を表示"] \
	-command "見本表示 $w $w.dialog"
pack $w.buttons.dismiss $w.buttons.code $w.buttons.sample -side left -expand 1

# set default settings
if {$tcl_platform(platform) == "windows"} {
    set ファミリ(ascii) {Courier}
    set ファミリ(漢字) {ＭＳ Ｐゴシック}
    # In Windows, charset are ignored
    set 文字セット(ascii) {deault}
    set 文字セット(漢字) {shiftjis}
} else {
    set ファミリ(ascii) fixed
    set ファミリ(漢字) fixed
    set 文字セット(ascii) iso8859
    set 文字セット(漢字) jisx0208.1983
}
foreach type {ascii 漢字} {
    set 大きさ($type) 14
    set 太さ($type) normal
    set 傾き($type) roman
}

foreach type {ascii 漢字} {
    frame $w.$type
    pack $w.$type -side top -expand yes -padx 10 -pady 10 -fill both

    label $w.$type.label -font {Helvetica14} \
	    -text "[kstring toupper $type]:" -width 8
    pack $w.$type.label -side left

    frame $w.$type.family
    label $w.$type.family.label -text [langSel "Family:" "ファミリ:"]
    pack $w.$type.family.label -side top -anchor w
    scrollbar $w.$type.family.scroll -command "$w.$type.family.list yview"
    listbox $w.$type.family.list -yscroll "$w.$type.family.scroll set" \
	    -height 8 -setgrid 1 -exportselection false
    pack $w.$type.family.list $w.$type.family.scroll -side left -fill y \
	    -expand yes
    eval $w.$type.family.list insert 0 [font families]
    set index [lsearch -exact [font families] $ファミリ($type)]
    $w.$type.family.list activate $index
    $w.$type.family.list see $index
    $w.$type.family.list selection set $index

    frame $w.$type.style
    foreach {label var values} [list \
	    [langSel "Weight" "太さ"] 太さ {normal bold} \
	    [langSel "Slant" "傾き"] 傾き {roman italic}] {
	label $w.$type.style.$var -text "$label:"
	pack $w.$type.style.$var -side top -anchor w
	foreach value $values {
	    radiobutton $w.$type.style.$var$value -text $value \
		    -variable ${var}($type) -value $value
	    pack $w.$type.style.$var$value -side top -anchor w
	}
    }

    frame $w.$type.size
    label $w.$type.size.label -text [langSel "Size:" "大きさ:"]
    pack $w.$type.size.label -side top -anchor w
    scale $w.$type.size.scale -orient vertical -from 8 -to 32 \
	    -variable 大きさ($type)
    pack $w.$type.size.scale -side left -fill y

    pack $w.$type.family $w.$type.style $w.$type.size -side left \
	    -fill y -padx 15
}

proc 見本表示 {w dialog} {
    global ファミリ 大きさ 太さ 傾き 文字セット

    if {![winfo exists $dialog]} {
	set sample "The quick brown fox jumps over the lazy dog.\n素早い茶色のキツネがうすのろイヌの上を飛び越えた。\nThis is just a サンプル Text."
	toplevel $dialog
	wm title $dialog "Compound Sample"
	label $dialog.sample -relief sunken -text $sample
	pack $dialog.sample -side top -padx 5 -pady 5
	button $dialog.ok -text OK -command "destroy $dialog" -default active
	bind $dialog <Return> "tkButtonInvoke $dialog.ok"
	pack $dialog.ok -side bottom -pady 2
    }

    # set back to default font
    $dialog.sample configure -font [lindex [$dialog.sample config -font] 3]

    catch {font delete コンパウンドフォント}
    catch {font delete asciiフォント}
    catch {font delete 漢字フォント}

    # create descendant fonts
    foreach type {ascii 漢字} {
	set ファミリ($type) [$w.$type.family.list get [$w.$type.family.list curselection]]
	font create ${type}フォント \
		-family $ファミリ($type) -size $大きさ($type) \
		-weight $太さ($type) -slant $傾き($type) \
		-charset $文字セット($type)
    }
    # create compound font
    font create コンパウンドフォント -compound {asciiフォント 漢字フォント}

    $dialog.sample configure -font コンパウンドフォント
}
