How to set a medium weight font using TFontDialog?

Some fonts have only medium and heavy weight. Given the code below, should I avoid TFontDialog together? When you select a style from a dialog box, it returns the weight of 500 sets of BOLD styles. If I keep this style and open TFontDialog, it will now be set to BOLD.

  FW_THIN = 100;
  {$EXTERNALSYM FW_EXTRALIGHT}
  FW_EXTRALIGHT = 200;
  {$EXTERNALSYM FW_LIGHT}
  FW_LIGHT = 300;
  {$EXTERNALSYM FW_NORMAL}
  FW_NORMAL = 400;
  {$EXTERNALSYM FW_MEDIUM}
  FW_MEDIUM = 500;
  {$EXTERNALSYM FW_SEMIBOLD}
  FW_SEMIBOLD = 600;
  {$EXTERNALSYM FW_BOLD}
  FW_BOLD = 700;
  {$EXTERNALSYM FW_EXTRABOLD}
  FW_EXTRABOLD = 800;
  {$EXTERNALSYM FW_HEAVY}
  FW_HEAVY = 900;

  {$EXTERNALSYM FW_REGULAR}
  FW_REGULAR = FW_NORMAL;

    procedure TFontDialog.UpdateFromLogFont(const LogFont: TLogFont);
     var
      Style: TFontStyles;
    begin
      with LogFont do
      begin
        Font.Name := LogFont.lfFaceName;
        Font.Height := LogFont.lfHeight;
        if FFontCharsetModified then
          Font.Charset := TFontCharset(LogFont.lfCharSet);
        Style := [];
        with LogFont do
        begin
          if lfWeight > FW_REGULAR then Include(Style, fsBold);
          if lfItalic <> 0 then Include(Style, fsItalic);
          if lfUnderline <> 0 then Include(Style, fsUnderline);
          if lfStrikeOut <> 0 then Include(Style, fsStrikeOut);
        end;
        Font.Style := Style;
      end;
    end;
+4
source share
2 answers

Unfortunately, TFontDialogavailable from VCL, does not know about this, as well as TFontin Delphi. VCL only recognizes in bold or not bold without intermediate font weights. You will have to go around them completely and implement your own dialogs and font objects to achieve this functionality.

0

TLogFont, OnClose:

var
 LogFont: TLogFont;
begin
 if Sender is TFontDialog then
  with Sender as TFontDialog do
   SendGetStructMessage(Handle, WM_CHOOSEFONT_GETLOGFONT, 0, LogFont);
end;

: Windows, Messages CommDlg. , TLogFont de TCanvas.

0

All Articles