字體度量單位為「設計單位」(Design Units),需配合 Font.GetSize (指定單位) 換算成像素。TGPInstalledFontCollection 可列舉系統所有已安裝字體家族名稱。
var
fontFamily: TGPFontFamily;
font: TGPFont;
begin
fontFamily := TGPFontFamily.Create('宋體');
font := TGPFont.Create(fontFamily, 9, FontStyleRegular, UnitPixel);
ShowMessage(FloatToStr(font.GetSize)); // 字號大小 (像素)
ShowMessage(IntToStr(fontFamily.GetEmHeight(FontStyleRegular))); // Em 高度 (設計單位)
ShowMessage(IntToStr(fontFamily.GetLineSpacing(FontStyleRegular))); // 行距
ShowMessage(IntToStr(fontFamily.GetCellAscent(FontStyleRegular))); // 上升距
ShowMessage(IntToStr(fontFamily.GetCellDescent(FontStyleRegular))); // 下降距
font.Free; fontFamily.Free;
end;
像素大小 = FontSize * (EmHeight / LineSpacing) (近似)
var
fonts: TGPFontCollection;
fArr: array of TGPFontFamily;
count, ti: Integer;
s: string;
i: Integer;
begin
fonts := TGPInstalledFontCollection.Create;
count := fonts.GetFamilyCount;
SetLength(fArr, count);
for i := 0 to count - 1 do fArr[i] := TGPFontFamily.Create;
fonts.GetFamilies(count, fArr, ti);
Memo1.Clear;
for i := 0 to count - 1 do begin
fArr[i].GetFamilyName(s);
Memo1.Lines.Add(s);
fArr[i].Free;
end;
fonts.Free;
end;
| Delphi | 微軟 | 說明 |
|---|---|---|
| FontStyleRegular | Regular | 正常 |
| FontStyleBold | Bold | 粗體 |
| FontStyleItalic | Italic | 斜體 |
| FontStyleUnderline | Underline | 底線 |
| FontStyleStrikeout | Strikeout | 刪除線 |
| Delphi | 微軟 | 單位 |
|---|---|---|
| UnitPixel | Pixel | 裝置像素 |
| UnitPoint | Point | 印表機點 (1/72 吋) |
| UnitInch | Inch | 英吋 |
| UnitMillimeter | Millimeter | 公釐 |
| UnitDocument | Document | 文件單位 (1/300 吋) |
| UnitDisplay | Display | 顯示裝置單位 |
| UnitWorld | World | 世界座標單位 |
字體度量是排版引擎、報表產生器、PDF 輸出的基石。