測試效果圖:
uses GdiPlus;
procedure TForm1.FormPaint(Sender: TObject);
var
Graphics: IGPGraphics;
Brush: IGPSolidBrush;
Pt: TGPPointF;
Font: IGPFont;
begin
Graphics := 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 成員的測試:
var
FontFamily: IGPFontFamily;
Font,Font2: IGPFont;
FontHight: Single;
LogFont: TLogFontW;
begin
FontFamily := 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 of
UnitWorld: 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;