Is Helvetica available on every MATLAB platform?
7 views (last 30 days)
Show older comments
I am programmatically building graphical interfaces and was wondering how universal Helvetica is on various platforms. A quick test:
Q=listfonts();k=contains(Q,'Helvetica');Q{k}
verifies if one or more Helvetica font are available. I can confirm than this font is available in R2025a (presumably previous releases as well) on the Mac and Windows. It also appears to be present on MATLAB Online. What I am less clear about is the many different flavors of Linux.
The underlying problem is that horizontal space requirements vary wildly between different font types. I have enabled a system where interfaces can be tailored around the end user's font size preference, but allowing the font itself to change is much tricker. For example, suppose you want to have an edit box wide enough to fit 20 characters. This is straightforward for a fixed with font, such as Monaco or Consolas. The default choice seems to be Helvetica, where the "W" and "i" characters are vastly different. A graphic sized for one font can appear much wider than necessary in some cases or not wide enough in others. If one were certain that Helvetica is always availble, it would make sense to base the design around that font. If not, one could rely on a fixed with font, although not everyone appreciates their appearance.
2 Comments
Rik
on 10 Sep 2025
Fonts are a pain. In my GUIs I generally allow for very large margins (i.e. 2x-3x of what I think will be needed) or I hardcode a font I pixelized myself (see text2im). It is a bit of a cludge, but I often see huge companies with entire departments focused on UI design mess up, so I don't fret too much.
Also, you should be careful assuming any defaults, since people can change them, which would break your carefully calibrated solution.
Accepted Answer
Star Strider
on 9 Sep 2025
On my Ubuntu 24.04 installation (latest updates), using yur example code, 'Helvetica' is the 12th entry in 'k'.
Proportional fonts are exactly that -- proportional. There are probably ways of calculating the pixel width of each letter in a specific font size, or the pixel width of a character array in a specific proportional font. Searching the File Exchange on 'font width' brings up three contributions, however none of them appear to calculate the pixel widths of either individual letters or a character array. You might consider doing a wider interweb search for that.
4 Comments
Star Strider
on 12 Sep 2025
Noted! Thank you!
I believe everything in MathWorks uses Ubuntu, however I know of no further details. The ver command will list some of those details in its OS section.
More Answers (1)
Walter Roberson
on 10 Sep 2025
The traditional way of handling this was to create a uicontrol and set the text string and font properties of the uicontrol, and then query the Extent property of the uicontrol, which would return the width and height actually needed to represent the text string with those properties. And then to use that information to set the size of the target control.
The main alternative to this is to get the Extent property of a text() object.
There is a File Exchange contribution that automates getting the extent from a text object; see https://www.mathworks.com/matlabcentral/fileexchange/168156-gettextextent
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!