首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 更多程式語言 >> Delphi

再學GDI+[43]: 系統已安裝字體列舉 - TGPInstalledFontCollection 專業方式

     編輯:Delphi

前言

TGPInstalledFontCollection 是 GDI+ 官方提供的專業字體列舉類別,直接從系統字體資料庫讀取,不包含垂直字體,適合專業排版應用。本文示範完整列舉流程並輸出至 Memo。

列舉核心步驟

  1. fonts := TGPInstalledFontCollection.Create
  2. fontCount := fonts.GetFamilyCount
  3. 配置 TGPFontFamily 陣列
  4. fonts.GetFamilies(count, arr, actualCount) 批量填充
  5. 逐個呼叫 GetFamilyName 取得名稱
  6. 釋放所有 TGPFontFamily 及 fonts

完整實作

procedure TForm1.FormCreate(Sender: TObject);
var
  fontFamilyArr: array of TGPFontFamily;
  fonts: TGPFontCollection;
  fontCount: Integer;
  str: string;
  i: Integer;
begin
  fonts := TGPInstalledFontCollection.Create;
  fontCount := fonts.GetFamilyCount;
  SetLength(fontFamilyArr, fontCount);
  for i := 0 to fontCount - 1 do fontFamilyArr[i] := TGPFontFamily.Create;
  fonts.GetFamilies(fontCount, fontFamilyArr, fontCount);
  Memo1.Clear;
  for i := 0 to fontCount - 1 do begin
    fontFamilyArr[i].GetFamilyName(str);
    Memo1.Lines.Add(str);
  end;
  for i := 0 to fontCount - 1 do fontFamilyArr[i].Free;
  fonts.Free;
end;

執行效果預覽

專業字體列舉

TGPInstalledFontCollection vs Screen.Fonts

特性TGPInstalledFontCollectionScreen.Fonts
來源GDI+ 字體引擎直接讀取VCL 封裝 EnumFontFamiliesEx
垂直字體自動過濾包含 @ 開頭垂直字體
字體家族物件直接產出 TGPFontFamily需手動建立
效能批量 GetFamilies 較快逐個字串處理
適用場景專業排版、字體管理工具一般應用、快速原型

表單定義檔

object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 196
  ClientWidth = 176
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  Position = poDesktopCenter
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object Memo1: TMemo ... {AlClient 顯示字體清單}
end
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved