Default Font?

Posted by Amun on Wed 10 Jul 2024 07:32 PM — 10 posts, 16,677 views.

#0
Hi. I'm working on a project to capture instances of damage to gear and printing a list of damaged pieces, as well as how many times they've been damaged, at the top of my window.

I've got it all working, though there's one problem. When using "GetInfo(20)" it is selecting the chosen font (which, in this case, is "FixedSys") for the world, but it ignores the "Override with default" option, which is selected in my worlds.

I'd like to know how I detect whether the font is overridden with the default, and how do I determine what the default is?
Australia Forum Administrator #1
To find the default global font you can do this:


DefaultOutputFont = GetGlobalOption ("DefaultOutputFont")


However due to a bug in the code which I just noticed (it's been there for years!) in the current version of MUSHclient you need an extra space, like this:


DefaultOutputFont = GetGlobalOption ("DefaultOutputFont ")


I suggest trying both, and use the one which does not return nil, since the new version may take a while to be adopted.

Then to find if they have enabled it or not:


use_default_output_font = GetOption ("use_default_output_font")


That should return a 0 or 1 where 1 means enabled.

Template:function=GetGlobalOption
GetGlobalOption

The documentation for the GetGlobalOption script function is available online. It is also in the MUSHclient help file.



Template:function=GetOption
GetOption

The documentation for the GetOption script function is available online. It is also in the MUSHclient help file.

Amended on Wed 10 Jul 2024 09:11 PM by Nick Gammon
#2
Thanks a bunch, Nick!

One last question, would there be an easy way to get the font height of the default font, such as GetInfo(212) does for the selected output font?

*edit*

I've found the answer to that question myself! GetGlobalOption( "DefaultOutputFontHeight" ) seems to do the trick.

One last question, finally! Where would I go to find the Font Size of the default output font?
Amended on Thu 11 Jul 2024 12:13 AM by Amun
Australia Forum Administrator #3
You can see the global option names like this:


t = {}
-- Get global option names
for k, v in pairs (GetGlobalOptionList()) do 
  table.insert (t, v)
end

-- sort alphabetically
table.sort (t)

-- show the names and values of each option
for k, v in ipairs (t) do
  print (v .. " = " .. GetGlobalOption (v))
end


In my case I see (amongst other things) this:


DefaultInputFont = Fixedsys
DefaultInputFontHeight = 9
DefaultInputFontItalic  = 0
DefaultInputFontWeight = 400
DefaultLogFileDirectory = C:\Program Files (x86)\MUSHclient\logs\
DefaultMacrosFile = 
DefaultOutputFont  = Arial
DefaultOutputFontHeight = 6


So to answer your question:


DefaultOutputFontHeight = GetGlobalOption ("DefaultOutputFontHeight")
Australia Forum Administrator #4
Quote:

One last question, finally! Where would I go to find the Font Size of the default output font?


Wait a minute! You knew that! What is the difference between the DefaultOutputFontHeight and the font size? Aren't they the same?

Oh, you mean in pixels? You can find that out using the normal technique inside a miniwindow, the same as any other font.

http://gammon.com.au/mushclient/mw_text.htm#WindowFontInfo

See Hint 1 further down the page.
Amended on Thu 11 Jul 2024 05:12 AM by Nick Gammon
#5
Nick Gammon said:

Wait a minute! You knew that! What is the difference between the DefaultOutputFontHeight and the font size? Aren't they the same?


I *didn't* know that! Thanks for all the help, Nick. I'm a big fan of your program and have been for many years. :)
#6
I'm having some trouble still!

I'm using the following bit of code, which accurately detects whether or not we're using the default output font option:


	selectedFont = GetInfo(20)
	selectedFontHeight = GetInfo(212)
	
	if GetOption( "use_default_output_font" ) > 0 then
		selectedFont = (GetGlobalOption( "DefaultOutputFont" ) or GetGlobalOption( "DefaultOutputFont " ))
		selectedFontHeight = GetGlobalOption( "DefaultOutputFontHeight" )
	end


However, GetGlobalOption( "DefaultOutputFontHeight" ) is returning "9", which is the font size, but it creates overlaps when I draw my text in rows using this value.

WindowFontInfo("Tepes_Repair", "Tepes_Repair_Texts_1", 1) returns 15 for me, after I've initialized the text, which is the value I think I want, as it prints cleanly for me with no overlap if I use that value (it's the value I get from GetInfo(212), which prints cleanly, and I believe is utilizing font size 9, but I am not 100% sure!).
Australia Forum Administrator #7
The so-called font size is in points (so 9 is a 9-point font) but the height is in pixels. Thus you have to use the suggested code (WindowFontInfo) to find the amount of vertical height taken by the font, in pixels.
Australia Forum Administrator #8
The selector DefaultOutputFontHeight is probably poorly named. It should be DefaultOutputFontSize rather than height.

I think I might have got a bit confused myself about the difference when I wrote that stuff.
Australia Forum Administrator #9
Maybe GetInfo (241)?

Quote:

241 - The height, in pixels, of a character in the output window, in the current output font.



Template:function=GetInfo
GetInfo

The documentation for the GetInfo script function is available online. It is also in the MUSHclient help file.