Recent

Author Topic: TFontDialog how to filter out at-sign (@) fonts  (Read 1291 times)

quantumfoam

  • New Member
  • *
  • Posts: 23
TFontDialog how to filter out at-sign (@) fonts
« on: November 11, 2020, 08:06:25 pm »
TFontDialog has mulltiple Options derived from TFontDialogOptions, which allow to customize its look and content.
I want to it to show only monospace fonts, so my options look like this:

Code: Pascal  [Select][+][-]
  1. fontDialog.Options := [fdAnsiOnly, fdTrueTypeOnly, fdFixedPitchOnly, fdForceFontExists, fdScalableOnly,
  2. fdNoSimulations, fdWysiwyg fdNoVectorFonts, fdNoOEMFonts];

However, the dialog window still shows vertically-oriented fonts starting with @, which are actually not monospace horizonally.
On Windows it is e.g.  @FangSong, @KaiTi, @NSimSun etc.

How to filter them out? Thanks.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: TFontDialog how to filter out at-sign (@) fonts
« Reply #1 on: November 11, 2020, 09:18:10 pm »
If the system font dialog fails to filter as you expect (and the LCL TFontDialog is a wrapper round the system dialog), I think you have to roll your own dialog.

Enumerate all the fonts on your system, filter the 'monospaced' ones, and then actually test their monospaced-ness by measuring, say, that
Code: Pascal  [Select][+][-]
  1. 'wwwwwww'
in the font has the same width as
Code: Pascal  [Select][+][-]
  1. 'iiiiiii'
in the same font, and skipping fonts that fail the test.

Bart

  • Hero Member
  • *****
  • Posts: 5677
    • Bart en Mariska's Webstek
Re: TFontDialog how to filter out at-sign (@) fonts
« Reply #2 on: November 11, 2020, 10:24:45 pm »
You can use EnumFontFamiliesEx() to filter out monospaced fonts.

Bart

quantumfoam

  • New Member
  • *
  • Posts: 23
Re: TFontDialog how to filter out at-sign (@) fonts
« Reply #3 on: November 11, 2020, 10:47:57 pm »
Thanks for tips. I wanted to avoid making my own dialog. I found different solution, although I'm not going to use it, if they don't actually implement it into LCL in future versions.
According to this https://docs.microsoft.com/en-us/windows/win32/dlgbox/font-dialog-box , the dialog window supports filtering
vertical fonts (I'm not sure if all Windows versions), yet it's not implemented in LCL.

I tried to add
Code: Pascal  [Select][+][-]
  1. fdNoVertFonts // into TFontDialogOption in lcl\dialogs.pp
  and
Code: Pascal  [Select][+][-]
  1. if fdNoVertFonts in Options then Result := Result or CF_NOVERTFONTS; // into GetFlagsFromOptions function in lcl\interfaces\win32\win32wsdialogs.pp


It seems to work. How do I propose to include it in new version?

Bart

  • Hero Member
  • *****
  • Posts: 5677
    • Bart en Mariska's Webstek
Re: TFontDialog how to filter out at-sign (@) fonts
« Reply #4 on: November 11, 2020, 11:15:49 pm »
It seems to work. How do I propose to include it in new version?

The problem is to have this work in all supported widgetsets if at all possible.
LCL tries to be as compatible as possible acrosss widgetsets.
Also Delphi compatibility comes inot play here.

Bart

 

TinyPortal © 2005-2018