Force monospace font in a TMemo cross-platform? lazarus / 31-LCL ---------------------------------------------------------------------- edvard · 2015-02-03 02:29 Hey folks, I have a generic About/Help form I'm coding for my latest venture, and for the 'Help' part, I have a read-only TMemo with a wall of text instructions. Problem is, it's formatted with a monospaced font in mind, and I just had a thought... "how do I tell all platforms to use a monospace font, when there are no defaults, and who knows if the right one is even installed?"  Windows 7 and on have Consolas installed by default, but what was it before that?  Courier? MOST Linux distros have a generic "Monospace" font installed, but I can't guarantee that all distro maintainers follow that as a default, and indeed, the user might uninstall it.  I have no idea if my app will even run on Mac OSX, so... Simple answer: Don't depend on monospace formatting and just let WordWrap do it's thing. ... which would work, but now I'm dying to know if somehow a default monospace font can be chosen at run-time for all (or at least the 'big 3') platforms.  Can this be done? ---------------------------------------------------------------------- skalogryz · 2015-02-03 03:12 well, I guess what you want to do is on start-up run through the list of available fonts (i.e. Screen.Fonts or more direct call to EnumFontFamilies/EnumFontFamiliesEx in LCLIntf unit ). You'd look for FF_MODERN in lfPitchAndFamily flag of TLogFont structure to identify monospace font. (LCL APIs follows WinAPI as much as os allows) Once monospace font is found you'd assign it to your memo. But, I'd strongly encourage you to have a "preferred" monospace font name for every system. Especially Linux.  For OSX and Windows it's easier, since mono-space font names tend to me the same and look the same from one version to another (and you can rely on Courier New to be available in both systems). But on Linux you might find a monospace font, but it might look crappy and hardly readable. Even worse the same font might look different from one distro to another. Alternative approach - don't use TMemo, use TSynEdit. it will force monospace even on non-monospace fonts .. not sure if ThemeAPIs have any "default monospace font" properties. ---------------------------------------------------------------------- Bart · 2015-02-03 09:20 Be aware that EnumFontFamiliesEx behaves different across widgetsets: http://bugs.freepascal.org/view.php?id=24231. Bart ---------------------------------------------------------------------- edvard · 2015-02-04 06:16 Wow... OK, thanks for the replies folks, but I think I'm just going to just remove linebreaks in the paragraphs and let WordWrap take it from there. ---------------------------------------------------------------------- Bart · 2015-02-04 11:05 I vaguely remember that wordwrap does not work on GTK (too lazy to test right now). Bart ---------------------------------------------------------------------- edvard · 2015-02-05 00:36 Nope, it works.  There are other quirks with GTK2, enough that I've been developing in Qt for some time now, but then I do some GTK2 testing just to make sure I'm not blissfully ignorant, and... ---------------------------------------------------------------------- valdir.marcos · 2015-02-05 01:15 Quote from: skalogryz on February 03, 2015, 04:12:52 amBut on Linux you might find a monospace font, but it might look crappy and hardly readable. Even worse the same font might look different from one distro to another. You could try (or suggest to your customers) the monospace fonts: Inconsolata, Source Code Pro, Fira Mono, Droid Sans Mono and DejaVu Sans Mono. http://fedoramagazine.org/5-great-monospaced-fonts-for-coding-and-the- terminal-in-fedora/