测试效果图:
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;