程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> GdiPlus[22]: IGPFont

GdiPlus[22]: IGPFont

編輯:Delphi

 測試效果圖:

GdiPlus[22]: IGPFont

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; 



  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved