#include #include #include #include #include #include #include #include #include #include ; -------------------------------------------------------------------------- ; -------------------------------------------------------------------------- global $g_GUI global $g_FamilyCombo, $g_StyleCombo, $g_SizeCombo, $g_SampleLabel global $g_Style = "Trebuchet MS", $g_Size = 24 $g_GUI = GUICreate("Test", 800, 600) GUISetState(@SW_SHOW, $g_GUI) HotKeySet("^q", Quit) $style = BitOR($CBS_SIMPLE, $WS_VSCROLL) $g_FamilyCombo = GUICtrlCreateCombo("", 10, 10, 250, 300, $style) GUICtrlSetFont($g_FamilyCombo, 10, $FW_DONTCARE, $GUI_FONTNORMAL, "Alef") $g_StyleCombo = GUICtrlCreateCombo("", 270, 10, 250, 200, $style) GUICtrlSetFont($g_StyleCombo, 10, $FW_DONTCARE, $GUI_FONTNORMAL, "Alef") $g_SizeCombo = GUICtrlCreateCombo("", 530, 10, 100, 20) GUICtrlSetFont($g_SizeCombo, 10, $FW_DONTCARE, $GUI_FONTNORMAL, "Alef") GUICtrlSetData _ ( _ $g_SizeCombo, _ "8|9|10|11|12|13|14|16|18|20|22|24|26|28|30|32|36|42", _ $g_Size _ ) $label1 = GUICtrlCreateLabel("", 10, 320, 780, 100) $label2 = GUICtrlCreateLabel("", 10, 450, 780, 100) $font_tree = EnumFontTree() PopulateComboBoxes($font_tree, $g_FamilyCombo, $g_StyleCombo, $g_Style) UpdateFontSamples($label1, $label2) while True $msg = GUIGetMsg() switch $msg case $g_FamilyCombo, $g_StyleCombo, $g_SizeCombo if ($msg = $g_FamilyCombo) then PopulateStylesComboBox($font_tree, $g_FamilyCombo, $g_StyleCombo, "") endif UpdateFontSamples($label1, $label2) case $GUI_EVENT_CLOSE Exit endswitch wend ; ------------------------------------------ func UpdateFontSamples($label1, $label2) $g_Style = GUICtrlRead($g_StyleCombo) $g_Size = GUICtrlRead($g_SizeCombo) GUICtrlSetFont($label1, $g_Size, $FW_DONTCARE, $GUI_FONTNORMAL, $g_Style) GUICtrlSetData($label1, $g_Style) $a = _WinAPI_EnumFontFamilies(0, $g_Style, $ANSI_CHARSET) $family = $a[1][0] _GDIPlus_Startup() $hGraphic = _GDIPlus_GraphicsCreateFromHWND($g_GUI) $hFamily = _GDIPlus_FontFamilyCreate($family) $hFont = _GDIPlus_FontCreate($hFamily, $g_Size) $height = _GDIPlus_FontGetHeight($hFont, $hGraphic) _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() $font_obj = _WinAPI_CreateFont( _ $height, 0, 0, 0, _ $FW_DONTCARE, False, False, False, _ $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, _ $PROOF_QUALITY, $DEFAULT_PITCH, _ $g_Style _ ) GUICtrlSetData($label2, $g_Style) _WinAPI_SetFont(GUICtrlGetHandle($label2), $font_obj, True) _WinAPI_DeleteObject($font_obj) endfunc ; ------------------------------------------ func PopulateComboBoxes($ft, $f, $st, $sel) for $i from 0 to ubound($ft) - 1 $family = $ft[$i][0] _GUICtrlComboBox_AddString($f, $family) if (($sel <> "") and (StringLeft($sel, StringLen($family)) = $family)) then _GUICtrlComboBox_SetCurSel($f, $i) PopulateStylesComboBox($ft, $f, $st, $sel) endif next endfunc ; ------------------------------------------ func PopulateStylesComboBox($ft, $f, $st, $sel) _GUICtrlComboBox_ResetContent($st) $styles = EnumFontStyles($ft, GUICtrlRead($f)) for $i from 0 to ubound($styles) - 1 $style = $styles[$i] _GUICtrlComboBox_AddString($st, $style) if (($sel <> "") and ($style = $sel)) then _GUICtrlComboBox_SetCurSel($st, $i) else _GUICtrlComboBox_SetCurSel($st, 0) endif next endfunc ; -------------------------------------------------------------------------- ; -------------------------------------------------------------------------- ; ------------------------------------------ func EnumFontTree() local $font_list = _WinAPI_EnumFontFamilies(0, "", $ANSI_CHARSET, -1, "@*", True) _ArraySort($font_list, 0, 1, 0, 0) local $font_tree[0][2] $i = 1 while ($i <= $font_list[0][0]) $stem = $font_list[$i][0] _ArrayAdd($font_tree, $stem) local $sub[0] do $i += 1 if ($i > $font_list[0][0]) then ExitLoop $st = $font_list[$i][0] if (StringLeft($st, StringLen($stem)) <> $stem) then ExitLoop _ArrayAdd($sub, $st) until False $font_tree[ubound($font_tree)-1][1] = $sub wend return $font_tree endfunc ; ------------------------------------------ func EnumFontStyles($font_tree, $family) local $styles[0] $idx = _ArrayBinarySearch($font_tree, $family) if ($idx >= 0) then ; Get base family styles $a = _WinAPI_EnumFontFamilies(0, $family, $ANSI_CHARSET, -1) for $i = 1 to $a[0][0] _ArrayAdd($styles, $a[$i][2]) next ; Get subfamily styles $sub = $font_tree[$idx][1] for $i in $sub _ArrayAdd($styles, $i) next endif _ArraySort($styles) return _ArrayUnique($styles, Default, Default, Default, $ARRAYUNIQUE_NOCOUNT) endfunc ; ------------------------------------------ func Quit() Exit endfunc