在Delphi中使用TextRect(也称为GDI32中的ExtTextOut)时,是否有一种禁用字体反锯齿的方法? [英] Is there a way to disable font anti aliasing when using TextRect (aka ExtTextOut in GDI32) in Delphi?

查看:1065
本文介绍了在Delphi中使用TextRect(也称为GDI32中的ExtTextOut)时,是否有一种禁用字体反锯齿的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据Delphi(5企业版)附带的示例,我使用了一个自定义的测量。对于那些不知道的人来说,这就像一个顺利的进度条,但是显示组件中心(垂直和水平)的百分比或值。



确保文本是可读的,当量表填满时,当它为空时,文本将使用反转颜色显示。



当使用字体反锯齿时,这些反转颜色导致字体的边缘出现在真正疯狂的颜色中,破坏了组件的外观。



有没有办法禁用字体平滑/反锯齿只是这一个组件或禁用它,绘制文本,然后重新启用它?



我目前的解决方法是使用不平滑的字体,如MS Sans Serif,但我想使用与其余UI相同的字体来保持一致。

解决方案

指定 NONANTIALIASED_QUALITY LOGFONT 结构中应该会使抗锯齿:

  procedure SetFontQuality(Font:TFont;质量:字节); 
var
LogFont:TLogFont;如果GetObject(Font.Handle,SizeOf(TLogFont),@LogFont)= 0,则
begin
然后
RaiseLastOSError;
LogFont.lfQuality:=质量;
Font.Handle:= CreateFontIndirect(LogFont);
结束

procedure TForm1.PaintBox1Paint(Sender:TObject);
const
FontQualities:Byte =(DEFAULT_QUALITY,NONANTIALIASED_QUALITY)的array [Boolean];
var
画布:TCanvas;
begin
Canvas:=(发件人为TPaintBox).Canvas;
SetFontQuality(Canvas.Font,FontQualities [CheckBox1.Checked]);
Canvas.TextOut(12,12,'Hello,world!');
结束


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 percentage or value in the centre (vertically and horizontally) of the component.

To make sure the text is readable both when the gauge is filled and when it's empty, the text is displayed using inverted colours.

When font anti-aliasing is used, these inverted colours cause the edge of the font to appear in really crazy colours, ruining the look of the component.

Is there any way to disable font smoothing / anti aliasing for just this one component, or disable it, draw the text, then re-enable it?

My current workaround is to use a font that doesn't get smoothed, like "MS Sans Serif", but I'd like to use the same font as the rest of the UI for consistency.

解决方案

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;

这篇关于在Delphi中使用TextRect(也称为GDI32中的ExtTextOut)时,是否有一种禁用字体反锯齿的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆