Page 2 of 2

Re: [Library] Fnt v2.0 - Do Stuff With Fonts

Posted: 28 Jan 2017, 06:15
by rommmcek
I made a small contribution regarding ToolTip. I've packed all the stuff in the function ToolTipFnt() and appended it to Fnt.ahk for easier use. I noticed an additional positive effect on my system (Windows 10 at 120 DPI):
Using this function, ToolTip when touching the bottom of the screen, won't flip any more to the top, instead it behaves exactly like native Windows ToolTip.

Code: Select all

ToolTipFnt(fs:="s14", ff:="") {
    ;-- Initialize 
    hTT :=0
    ;-- Get the current process ID
    Process Exist
    ScriptPID :=ErrorLevel
    ;-- Find the tooltip
    WinGet IDList,List,ahk_pid %ScriptPID%
    Loop %IDList%
        {
        WinGetClass Class,% "ahk_ID " . IDList%A_Index%
        if (Class="tooltips_class32")
            {
            hTT:=IDList%A_Index%
            Break
            }
        }
    ;-- Create font
    ;~ hFont :=Fnt_CreateFont("Arial Unicode MS","s14") ; - orignal syntax
    hFont :=Fnt_CreateFont(ff, fs)
    ;-- Set the font on the tooltip control and redraw
    Fnt_SetFont(hTT,hFont)
        ;-- RControlSend, AListCtl321, {Tab}, ahk_class CabinetWClassedraw set to FALSE (the default)
    Fnt_UpdateTooltip(hTT)
        ;-- This forces the tooltip to redraw without deactivating it first
}
P.s.: As a measure against broken ToolTip display, which occurs occasionally, it seems to work Sleep, -1 before Return hFont in Fnt_CreateFont() function of the Fnt.ahk library.

Two updated (7) examples, one original from jballi using ToolTipFnt():

Re: [Library] Fnt v2.0 - Do Stuff With Fonts

Posted: 28 Jan 2017, 23:50
by jballi
rommmcek,

Thank you for your contribution. I tested it and both of the examples work great! I have a few notes. I hope you don't mind.

1) The function creates a logical font but there is no mechanism for deleting the font. Fixing this is only needed for completeness. The amount of memory saved is trivial.

This is an easy fix. Simply have the function return the handle to the font that was created (Ex: Return hFont) and then delete the font after the tooltip is destroyed. For example:

Code: Select all

Tooltip Brown Chicken`, Brown Cow
hTTFont:=ToolTipFnt()
MsgBox The tooltip will continue to show while this window is open.
Tooltip                   ;-- Destroy the tooltip
Fnt_DeleteFont(hTTFont)   ;-- Delete the tooltip font
2) Calling the function multiple times for the same AutoHotkey tooltip is not a good idea because a new font is created for every call and the previous font (if any) is not destroyed. This will create the equivalent of a memory leak that will use a tiny bit of additional memory every time the function is called. Probably not enough to worry about for the average script but the extra memory usage can add up for a long-running script.

One possible fix is to delete the previous font before creating a new one (see #1) but the better and more efficient solution is to only call the function once for every tooltip. Let me explain...

When a tooltip is created for the first time, AutoHotkey will create a new tooltip control. That control is destroyed when the Tooltip command is called without any parameters. For example:

Code: Select all

Tooltip Brown Chicken   ;-- New tooltip control is created
Sleep 2000
Tooltip                 ;-- Tooltip control is destroyed
However, if a tooltip exists and the Tooltip command is called again, a new tooltip control is not created. Instead, the tooltip control is updated with the new text from the Tooltip command. Since a new tooltip control is not created, the font changes made by the function remain in effect. For example:

Code: Select all

Tooltip Brown Chicken   ;-- New tooltip control is created
hTTFont:=ToolTipFnt()   ;-- New tooltip font is set
Sleep 2000
Tooltip Brown Cow       ;-- The same tooltip control is used
;-- No need to set/update the font here
Sleep 2000
Tooltip                 ;-- Tooltip control is destroyed
Fnt_DeleteFont(hTTFont)
3) In your example, you imply that the function somehow fixes a tooltip positioning bug when the pointer and the tooltip is moved to the bottom right section of the screen. The positioning code for the AutoHotkey tooltip has been in AutoHotkey since as long as I can remember and changing the font or font size doesn't (or shouldn't) change how it works. OTOH, I'm not experiencing the "skip to the top" problem you mentioned and I don't have Windows 10 to try to duplicate the problem.

Once again, thank you for your contribution.

Re: [Library] Fnt v2.0 - Do Stuff With Fonts

Posted: 03 Feb 2017, 19:19
by rommmcek
This is what we get when a layman firefights his problems!
Despite frequent admonishments in the library, I just didn't pay attention!

Manny thanks for your survey & fix!

P.s.: I just updated examples.
P.p.s.: The anti skip example doesn't prove anything (I tested it extensively), but skipping to the top remains an issue on Win 10, even at 96 DPI and "my" function for sure mitigate this problem, but I couldn't isolate the trigger.

Re: [Library] Fnt v2.0 - Do Stuff With Fonts

Posted: 29 Sep 2017, 19:44
by jballi
Tab Stop Size

Preface
This discussion is about the tab stop size in some of the Microsoft common controls and dialogs, not the tab stop size in applications like Microsoft Word.

Introduction
The amount of space that a tab character is expanded to is known as the "tab stop size". For some reason, Microsoft created two different methods for measuring the size of a tab stop. Both methods are based on the width of an "average character" but the methods for calculating the width of an "average character" are different.

Method 1
In the first method, the width of an "average character" is defined by the tmAveCharWidth member of the font's metrics. Typically this is the width of the letter x but it can be anything. This value can be collected by calling Fnt_GetFontAvgCharWidth. The tab stop size is the width of 8 "average characters". Ex: Fnt_GetFontAvgCharWidth(hFont)*8.

The Text and Tooltip controls use this measurement method. There may be others.

Credit: Thanks to jeeswg for figuring out that the tab stop size for these controls are based on the font's average character width as defined by the font's text metrics.

Method 2
In the second method, the width of an "average character" is the average width of a character in the following string: "AaBbCc...XxYyZz". The width for this "average character" measurement can be collected by calling Fnt_GetDialogBaseUnits.

The name for this measurement is not consistent in the Microsoft documentation. In many cases, this measurement is written as "average character" or the "width of an average character". When this measurement relates to a Microsoft custom dialog, is sometimes labeled as Dialog Base Units. Although Dialog Base Units is an unfortunate name for this measurement, it is more useful than "average character" which has two different meanings. In addition, the tab stop size for some of these controls are set in Dialog Template Units which are based on Dialog Base Units. For these controls, the default tab stop size is the font's Dialog Base Units times 8. Ex: Fnt_GetDialogBaseUnits(hFont)*8.

The Edit, ListBox, and RichEdit controls use this measurement method as well as the MsgBox dialog. There may be others.

Re: [Library] Fnt v3.0 - Do Stuff With Fonts

Posted: 02 Jan 2018, 00:41
by jballi
v3.0
Major new release. See the Release Notes section of the first post for the details.

If using a earlier version of the libary, please read the Release Notes section of the first post and the library documentation, especially the Issues and Considerations section, before using the new version.

Re: [Library] Fnt v3.0 - Do Stuff With Fonts

Posted: 16 Jan 2018, 16:48
by robodesign
It's a lovely project and very nicely coded and organized. Thank you very much.

Re: [Library] Fnt v3.0 - Do Stuff With Fonts

Posted: 27 Jun 2019, 09:13
by rommmcek
Just made custom color options for ToolTipFnt().
Fresh code, very little tested though!

Re: [Library] Fnt v3.0 - Do Stuff With Fonts

Posted: 02 Jul 2019, 16:10
by burque505
@jballi, thanks for this library, I downloaded it months ago but haven't opened it till now.
@rommmcek, very, very nice. That's going to be useful.
Regards,
burque505

Re: [Library] Fnt v3.0 - Do Stuff With Fonts

Posted: 31 Oct 2019, 18:43
by m3user
Wonderful library, thanks!
I just wonder if there is a way to hide only the color selection in Choose Font standard dialog? I know I can hide all effects but then underline and strikeout options are hidden too.

Re: [Library] Fnt v3.0 - Do Stuff With Fonts

Posted: 01 Nov 2019, 05:19
by jballi
Thank you for your interest.
m3user wrote:
31 Oct 2019, 18:43
I just wonder if there is a way to hide only the color selection in Choose Font standard dialog? I know I can hide all effects but then underline and strikeout options are hidden too.
No, not with the standard ChooseFont dialog. If the CF_EFFECTS flag is included, all of the elements in the Effects group (Strikeout, Underline, and Color) are shown. There is no way to hide or delete the Color element without writing some code that hides or deletes the Color controls after the dialog is showing. Not recommended.

The Fnt_ChooseFontDlg add-on function was written to specifically deal with this type of problem. It allows the developer the option to choose which elements of a custom "Choose Font" dialog are shown. You can easily create a dialog that only excludes the Color control. In addition, the custom "Choose Font" dialog pops up significantly faster than the standard ChooseFont dialog. See the example scripts for an example.

Re: [Library] Fnt v3.0 - Do Stuff With Fonts

Posted: 01 Nov 2019, 08:53
by jeeswg
Hello jballi. Do you have any idea why the font dialog can be slow to open, e.g. on Notepad (Windows 7), at around 10 seconds. It's often slow the first time, but then fine after that. Btw Notepad only lists 158 fonts for me. Thanks.

Re: [Library] Fnt v3.0 - Do Stuff With Fonts

Posted: 01 Nov 2019, 18:07
by m3user
Thanks jballi, very useful function. I see the "Character set" can be selected in the Example - Get list of fonts. Is this the same as "Script" selection in the standard dialog? Do you know what is the practical purpose of this two selections?

Re: [Library] Fnt v3.0 - Do Stuff With Fonts

Posted: 02 Nov 2019, 06:37
by jballi
jeeswg wrote:
01 Nov 2019, 08:53
Do you have any idea why the font dialog can be slow to open, e.g. on Notepad (Windows 7), at around 10 seconds. It's often slow the first time, but then fine after that.
Notepad uses the standard ChooseFont dialog and yes, it does take an unusually long time to start it for the first time. I don't know why.
jeeswg wrote:
01 Nov 2019, 08:53
Btw Notepad only lists 158 fonts for me.
Some programs, especially native Windows programs, try hard to combine like font families into a single group. For example, the Font window in the Control Panel and the ChooseFont dialog combine like font families into a single group. This is done specifically for these programs and is not available elsewhere. These custom groupings work OK for some typefaces like Arial but doesn’t work as well for typefaces like Segoe which are represented by a large number of font families. Some combinations of the font typeface and font attributes cannot be selected when the fonts are grouped this way.

The Fnt library does not group the font families together so the user will see few more fonts.

Re: [Library] Fnt v3.0 - Do Stuff With Fonts

Posted: 02 Nov 2019, 07:31
by jballi
m3user wrote:
01 Nov 2019, 18:07
I see the "Character set" can be selected in the Example - Get list of fonts. Is this the same as "Script" selection in the standard dialog? Do you know what is the practical purpose of this two selections?
Yes and no.

Disclaimer: I am not an expert on this topic. Some of the following is based on speculation. If I get anything wrong, please feel free to correct me.

Fonts for computers have evolved dramatically since they were originally introduced. A "character set" is just the list of characters that are used for a particular purpose. The original purpose was to identify different languages but with the introduction of Unicode and fonts that now support many languages, the purpose and need to identify a particular character set has changed.

The ChooseFont dialog uses the Script combo box to show a list of characters sets supported by the font typeface that is currently selected. Selecting a particular character set (Ex: Greek) doesn't really do anything that I'm aware of. The user must still enter the correct characters needed for the particular language.

More:
https://docs.microsoft.com/en-us/windows/win32/gdi/character-sets-used-by-fonts

The Fnt library uses "Character Set" as a means to filter the list of fonts that support that character set. It can be helpful if there are only a limited number of fonts that support a particular language.

Language is the primary use but "Symbol" is also a character set. It can be used to only show fonts that only contain symbols.

Re: [Library] Fnt v3.0 - Do Stuff With Fonts

Posted: 03 Nov 2019, 17:09
by m3user
Thanks jballi, very much appreciated.

Re: [Library] Fnt v3.0 - Do Stuff With Fonts

Posted: 07 Sep 2021, 15:59
by joefiesta
Fnt\_Functions\Fnt.ahk makes a reference to "(see _FontMetrics.png) "

I can not find this image.

Re: [Library] Fnt v3.0 - Do Stuff With Fonts

Posted: 08 Sep 2021, 02:50
by jballi
joefiesta wrote:
07 Sep 2021, 15:59
Fnt\_Functions\Fnt.ahk makes a reference to "(see _FontMetrics.png) "

I can not find this image.
Thank you for your interest. The image is embedded in documentation file (Fnt_Library.html) in the Terminology section. The actual link to the pic is
https://i.imgur.com/i5OIqSf.png

Re: [Library] Fnt v3.0 - Do Stuff With Fonts

Posted: 08 Sep 2021, 08:41
by joedf
Wow, first time I see a graphic like that. Stumble upon now, but quite enlightening. :+1:

Re: [Library] Fnt v3.0 - Do Stuff With Fonts

Posted: 28 Jun 2023, 03:53
by jballi
v4.0
Major new release. See the Release Notes section of the first post for the details.

If using a earlier version of the library, please read the Release Notes section of the first post and the library documentation, especially the Issues and Considerations section, before using the new version.

This version of the project only runs on AutoHotkey v1.1+. AutoHotkey v2.0+ is not supported. With the exception of bug fixes, this will be the last release that uses AutoHotkey v1.1+. Future versions of this project (if any) will require AutoHotkey v2.0.

Re: [Library] Fnt v4.0 - Do Stuff With Fonts

Posted: 08 Nov 2023, 15:01
by jballi
Added a new function to the library that is now being used by other libraries. Instead of generating a new release with only one change, I'm posting the new function here jic anyone needs it. This function will be included in the next release (if any).

Code: Select all

;------------------------------
;
; Function: Fnt_GetFontAscent
;
; Description:
;
;   Return the ascent (units above the base line) of the characters of the font.
;
; Parameters:
;
;   hFont - The handle to a logical font.  Set to null or 0 to use the default
;       GUI font.
;
; Calls To Other Functions:
;
; * <Fnt_GetFontMetrics>
;
;-------------------------------------------------------------------------------
Fnt_GetFontAscent(hFont:="")
    {
    Return NumGet(Fnt_GetFontMetrics(hFont),4,"Int")
    }