专注于互联网--专注于架构

最新标签
网站地图
文章索引
Rss订阅

首页 »PHP教程 » GdiPlus[22]: IGPFont »正文

GdiPlus[22]: IGPFont

来源: 发布时间:星期四, 2009年12月17日 浏览:0次 评论:0


  测试效果图:



uses GdiPlus; 
 
procedure TForm1.FormPa(Sender: TObject); 
var 
 Graphics: IGPGraphics; 
 Brush: IGPSolidBrush; 
 Pt: TGPPoF; 
 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, UnitPo); 
 Graphics.DrawString('''微软雅黑'', 12, FontStyleRegular, UnitPo', 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: 字体样式 } 
  FontStyleBold in Font.Style then ShowMessage('Bold'); 
  FontStyleItalic in Font.Style then ShowMessage('Italic'); 
  FontStyleUnderline in Font.Style then ShowMessage('Underline'); 
  FontStyleStrikeout in Font.Style then ShowMessage('Strikeout'); 
  ((FontStyleBoldItalic * Font.Style) = FontStyleBoldItalic) then ShowMessage('Bold、Italic'); 
  Font.Style =  then ShowMessage('FontStyleRegular'); 
 
 { Font.MeasureUnit: 尺寸单位 } 
  Font.MeasureUnit of 
  UnitWorld:   ShowMessage('World'); 
  UnitDisplay:  ShowMessage('Display'); 
  UnitPixel:   ShowMessage('Pixel'); 
  UnitPo:   ShowMessage('Po'); 
  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; 


标签:
0

相关文章

读者评论

发表评论

  • 昵称:
  • 内容: