Is there a way to disable font anti aliasing when using TextRect (aka ExtTextOut in GDI32) in Delphi?

前端 未结 1 1637
名媛妹妹
名媛妹妹 2020-12-17 06:12

I\'m using a custom gauge, based on the example that came with Delphi (5 Enterprise). For those that don\'t know, it\'s like a smooth progress bar, but displays the percenta

相关标签:
1条回答
  • 2020-12-17 07:01

    Specifying NONANTIALIASED_QUALITY in the LOGFONT structure should turn antialiasing off:

    procedure SetFontQuality(Font: TFont; Quality: Byte);
    var
      LogFont: TLogFont;
    begin
      if GetObject(Font.Handle, SizeOf(TLogFont), @LogFont) = 0 then
        RaiseLastOSError;
      LogFont.lfQuality := Quality;
      Font.Handle := CreateFontIndirect(LogFont);
    end;
    
    procedure TForm1.PaintBox1Paint(Sender: TObject);
    const
      FontQualities: array[Boolean] of Byte = (DEFAULT_QUALITY, NONANTIALIASED_QUALITY);
    var
      Canvas: TCanvas;
    begin
      Canvas := (Sender as TPaintBox).Canvas;
      SetFontQuality(Canvas.Font, FontQualities[CheckBox1.Checked]);
      Canvas.TextOut(12, 12, 'Hello, world!');
    end;
    
    0 讨论(0)
提交回复
热议问题