Recent

Author Topic: Crossplatform font  (Read 980 times)

LemonParty

  • Sr. Member
  • ****
  • Posts: 439
Crossplatform font
« on: February 25, 2026, 09:59:29 pm »
Hello.
I have a GUI application that is desirable to be portable and I need monospace font. I target Windows, Linux (and optionally MacOS). In Windows I can use Courier, it's fine. What about other OSs? Should I bring there my font or is there a more elegant decision?
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

dsiders

  • Hero Member
  • *****
  • Posts: 1597
Re: Crossplatform font
« Reply #1 on: February 25, 2026, 10:15:35 pm »
Hello.
I have a GUI application that is desirable to be portable and I need monospace font. I target Windows, Linux (and optionally MacOS). In Windows I can use Courier, it's fine. What about other OSs? Should I bring there my font or is there a more elegant decision?

In LCL applications, there are aliases (my term) that can be assigned to Font.Name properties like "Sans Serif" and "Monospace". These are automatically translated to the real font names supported for a given platform. If you want exactly the same font, then you'll need to provide it. Good news is that basically any TrueType font works. You just need to install it on the target system.

zeljko

  • Hero Member
  • *****
  • Posts: 1906
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Crossplatform font
« Reply #2 on: February 25, 2026, 11:25:52 pm »
Hello.
I have a GUI application that is desirable to be portable and I need monospace font. I target Windows, Linux (and optionally MacOS). In Windows I can use Courier, it's fine. What about other OSs? Should I bring there my font or is there a more elegant decision?

This is what I'm doing (for linux you can add monospace if you want, but DejaVu Sans Mono is installed on all distros by default for years):
  {$IFDEF MSWINDOWS}
  LogMemo0.Font.Name := 'Consolas';
  {$ELSE}
  {$IFDEF DARWIN}
  LogMemo0.Font.Name := 'Menlo';
  {$ELSE}
  LogMemo0.Font.Name := 'DejaVu Sans Mono';
  {$ENDIF}
  {$ENDIF}

Graeme

  • Hero Member
  • *****
  • Posts: 1518
    • Graeme on the web
Re: Crossplatform font
« Reply #3 on: February 26, 2026, 12:47:23 am »
I found the most reliable way with consistent look, is to ship such a font with your application. eg: 'DejaVu Sans Mono'

Saying that, fpGUI currently does what Zeljko showed. Each platform's IFDEF defines a known font.
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

Thaddy

  • Hero Member
  • *****
  • Posts: 19017
  • Glad to be alive.
Re: Crossplatform font
« Reply #4 on: February 26, 2026, 01:52:28 pm »
I usually  choose an Open source font that I like and include it as a font resource in my application.
Recovered from removal of tumor in tongue following tongue reconstruction with a part from my leg.

LemonParty

  • Sr. Member
  • ****
  • Posts: 439
Re: Crossplatform font
« Reply #5 on: February 26, 2026, 04:08:27 pm »
Thank you, zeljko. That is a good solution.
I don't really want to bring an extra font.
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

 

TinyPortal © 2005-2018