热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

GDI+进阶指南:深入解析IGPFont接口

本文深入探讨了GDI+中IGPFont接口的应用与实现,通过具体的代码示例展示了如何在Delphi中使用GDI+进行高质量的文本渲染。文章详细解析了IGPFont接口的各项属性和方法,并提供了实用的编程技巧,帮助开发者更好地理解和掌握GDI+的字体处理功能。

测试效果图:

o_09121505.png

uses GdiPlus;procedure TForm1.FormPaint(Sender: TObject);
varGraphics: IGPGraphics;Brush: IGPSolidBrush;Pt: TGPPointF;Font: IGPFont;
beginGraphics := TGPGraphics.Create(Handle);Pt.Initialize(10, 10);Brush := TGPSolidBrush.Create($FFFF0000);Font := TGPFont.Create(Canvas.Handle);Graphics.DrawString('Self.Canvas.Font', Font, Pt, Brush);Graphics.TranslateTransform(0, Font.GetHeight(Graphics) * 1.5);Font := TGPFont.Create('微软雅黑', 12);Graphics.DrawString('''微软雅黑'', 12', Font, Pt, Brush);Graphics.TranslateTransform(0, Font.GetHeight(Graphics) * 1.5);Font := TGPFont.Create('微软雅黑', 12, [FontStyleBold]);Graphics.DrawString('''微软雅黑'', 12, [FontStyleBold]', Font, Pt, Brush);Graphics.TranslateTransform(0, Font.GetHeight(Graphics) * 1.5);Font := TGPFont.Create('微软雅黑', 12, [FontStyleItalic]);Graphics.DrawString('''微软雅黑'', 12, [FontStyleItalic]', Font, Pt, Brush);Graphics.TranslateTransform(0, Font.GetHeight(Graphics) * 1.5);Font := TGPFont.Create('微软雅黑', 12, [FontStyleUnderline]);Graphics.DrawString('''微软雅黑'', 12, [FontStyleUnderline]', Font, Pt, Brush);Graphics.TranslateTransform(0, Font.GetHeight(Graphics) * 1.5);Font := TGPFont.Create('微软雅黑', 12, [FontStyleStrikeout]);Graphics.DrawString('''微软雅黑'', 12, [FontStyleStrikeout]', Font, Pt, Brush);Graphics.TranslateTransform(0, Font.GetHeight(Graphics) * 1.5);Font := TGPFont.Create('微软雅黑', 12, FontStyleBoldItalic);Graphics.DrawString('''微软雅黑'', 12, FontStyleBoldItalic', Font, Pt, Brush);Graphics.TranslateTransform(0, Font.GetHeight(Graphics) * 1.5);Font := TGPFont.Create('微软雅黑', 12, FontStyleRegular, UnitPoint);Graphics.DrawString('''微软雅黑'', 12, FontStyleRegular, UnitPoint', Font, Pt, Brush);Graphics.TranslateTransform(0, Font.GetHeight(Graphics) * 1.5);Font := TGPFont.Create('微软雅黑', 12, FontStyleRegular, UnitPixel);Graphics.DrawString('''微软雅黑'', 12, FontStyleRegular, UnitPixel', Font, Pt, Brush);
end;

下面是一个关于 IGPFont 成员的测试:



varFontFamily: IGPFontFamily;Font,Font2: IGPFont;FontHight: Single;LogFont: TLogFontW;
beginFontFamily := TGPFontFamily.Create('宋体');Font := TGPFont.Create(FontFamily, 16, FontStyleBoldItalic, UnitPixel);
// Font := TGPFont.Create(FontFamily, 16, [], UnitPixel);{ Font.Size: 字号大小}ShowMessageFmt('FontSize: %f', [Font.Size]); //16.00{ Font.Style: 字体样式 }if FontStyleBold in Font.Style then ShowMessage('Bold');if FontStyleItalic in Font.Style then ShowMessage('Italic');if FontStyleUnderline in Font.Style then ShowMessage('Underline');if FontStyleStrikeout in Font.Style then ShowMessage('Strikeout');if ((FontStyleBoldItalic * Font.Style) = FontStyleBoldItalic) then ShowMessage('Bold、Italic');if Font.Style = [] then ShowMessage('FontStyleRegular');{ Font.MeasureUnit: 尺寸单位 }case Font.MeasureUnit ofUnitWorld: ShowMessage('World');UnitDisplay: ShowMessage('Display');UnitPixel: ShowMessage('Pixel');UnitPoint: ShowMessage('Point');UnitInch: ShowMessage('Inch');UnitDocument: ShowMessage('Document');UnitMillimeter: ShowMessage('Millimeter');end;{ Font.GetHeight: 字体高度 }FontHight := Font.GetHeight(TGPGraphics.Create(Handle));
// FontHight := Font.GetHeight(nil);
// FontHight := Font.GetHeight(0);ShowMessageFmt('FontHight: %f', [FontHight]); //18.25{ Font.IsAvailable: 字体是否可用 }ShowMessage(BoolToStr(Font.IsAvailable, True));{ Font.GetLogFontW: 获取 TLogFont 结构数据 }LogFont := Font.GetLogFontW(TGPGraphics.Create(Handle));ShowMessage(LogFont.lfFaceName);{ Font.Family: 获取 IGPFontFamily }ShowMessage(Font.Family.FamilyName);{ Font.Clone: 克隆 }Font2 := Font.Clone;ShowMessage(Font2.Family.FamilyName);
end;



推荐阅读
author-avatar
无声无无为爱
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有