Skip to content

Instantly share code, notes, and snippets.

@fand
Last active July 15, 2025 00:52
Show Gist options
  • Save fand/395387dddeb78e198c8f2c9cb14a7e59 to your computer and use it in GitHub Desktop.
Save fand/395387dddeb78e198c8f2c9cb14a7e59 to your computer and use it in GitHub Desktop.
Deno Script to check font metrics

font_metrics.ts

Check font metrics (unitsPerEm, ascent, descent and lineGap) of the font files in the specified directory. Only works for .ttf and .otf (.ttc not supported).

Required

  • Deno
  • ttx (fonttool)
  • dasel
  • jq

Example

deno --allow-read --allow-env --allow-run font_metrics.ts /System/Library/Fonts

This outputs a Markdown table like this:

Name UnitsPerEm Ascender Descender LineGap
.Zither India Narrow 1000 1083 -451 0
Symbol 2048 1436 -612 0
Geneva 2048 2048 -512 171
.LastResort 2048 1950 -494 0
.SF NS Mono 2048 1980 -432 0
.SF Georgian 2048 1950 -494 0
.SF Hebrew 2048 1950 -494 0
Zapf Dingbats 2048 1667 -362 0
.SF Armenian 2048 1950 -494 0
Apple Braille 2048 1600 -512 171
.Zither India 1000 1083 -451 0
.SF Compact 2048 1950 -494 0
Apple Braille 2048 1600 -512 171
Apple Braille 2048 1600 -512 171
.New York 2048 1950 -494 0
.SF NS Mono 2048 1980 -432 0
.SF NS 2048 1980 -432 0
.SF Camera 2048 1950 -494 0
.SF Armenian Rounded 2048 1950 -494 0
Monaco 2048 2048 -512 171
Apple Symbols 2048 1365 -512 171
.New York 2048 1950 -494 0
.SF Compact 2048 1950 -494 0
.SF Arabic 2048 2050 -494 140
.SF NS Rounded 2048 1980 -432 0
Apple Braille 2048 1600 -512 171
.Keyboard 2048 1980 -432 0
.SF Georgian Rounded 2048 1950 -494 0
.SF Compact Rounded 2048 1950 -494 0
Apple Braille 2048 1600 -512 171
.SF NS 2048 1980 -432 0
.SF Arabic Rounded 2048 2050 -494 140
.SF Hebrew Rounded 2048 1950 -494 0

Example 2

deno --allow-read --allow-env --allow-run font_metrics.ts /System/Library/Fonts/Supplemental
Name UnitsPerEm Ascender Descender LineGap
Noto Sans Lepcha 1000 1069 -450 0
Webdings 2048 1638 -410 0
Noto Sans Mandaic 1000 724 -423 0
Zapfino 400 750 -601 0
Noto Sans CaucAlban 1000 976 -274 0
Trebuchet MS 2048 1923 -455 0
Noto Sans OldHung 1000 859 -177 0
Georgia 2048 1878 -449 0
Noto Sans Saurashtra 1000 1069 -293 0
Noto Sans Multani 1000 1069 -293 0
Noto Sans Hatran 1000 1069 -293 0
Verdana 2048 2059 -430 0
Bodoni 72 Smallcaps 1000 936 -262 0
Noto Sans InsPahlavi 1000 1069 -352 0
Noto Sans Hanunoo 1000 1069 -293 0
Times New Roman 2048 1825 -443 87
Silom 1000 959 -316 0
Noto Sans Bhaiksuki 1000 960 -460 0
Noto Sans Cham 1000 1117 -351 0
Noto Sans Manichaean 1000 790 -340 0
Noto Sans NKo 1000 1069 -293 0
Verdana 2048 2059 -430 0
Noto Sans Kayah Li 1000 1069 -293 0
Noto Sans Osage 1000 1069 -293 0
Noto Sans Adlam 1000 1069 -293 0
Noto Sans Pahawh Hmong 1000 1069 -293 0
Times New Roman 2048 1825 -443 87
Noto Sans Mro 1000 1069 -293 0
Noto Sans CanAborig 1000 1069 -293 0
Noto Sans Avestan 1000 1069 -293 0
Bradley Hand 1000 850 -399 0
Noto Sans Miao 1000 1142 -350 0
Arial Narrow 2048 1916 -434 0
Noto Sans Bassa Vah 1000 1069 -293 0
STIXGeneral 1000 1055 -455 0
Noto Sans Syriac 1000 926 -486 0
Noto Sans Mende Kikakui 1000 1030 -237 0
AppleGothic 1000 891 -325 0
STIX Two Text 1000 762 -238 250
Noto Sans Lydian 1000 1069 -293 0
DIN Condensed 1000 712 -288 200
Noto Sans Chakma 1000 1140 -320 0
Noto Sans Nabataean 1000 1069 -293 0
Noto Serif Hmong Nyiakeng 1000 1068 -292 0
Farisi 2048 2263 -2000 0
Arial 2048 1854 -434 67
Trebuchet MS 2048 1923 -455 0
Mishafi 2048 1607 -1356 0
Noto Sans Duployan 1000 1069 -293 0
Academy Engraved LET 2048 1400 -1024 0
Noto Sans SoraSomp 1000 1069 -293 0
Trattatello 1000 1150 -662 0
Noto Sans Rejang 1000 1069 -293 0
Noto Sans Ugaritic 1000 743 -381 0
Noto Sans Lycian 1000 1069 -293 0
Big Caslon 1000 934 -257 18
Noto Sans WarangCiti 1000 1042 -100 0
Courier New 2048 1705 -615 0
Noto Sans HanifiRohg 1000 1069 -293 0
Noto Sans Tirhuta 1000 1026 -519 0
STIXIntegralsUpSm 1000 1055 -455 0
STIXGeneral 1000 1055 -455 0
STIXIntegralsUpD 1000 2182 -451 0
Lao Sangam MN 2048 2052 -646 0
Noto Sans Tai Le 1000 1069 -293 0
Noto Sans Thaana 1000 1069 -424 0
Luminari 1000 983 -356 0
STIXVariants 1000 1055 -455 0
STIXSizeOneSym 1000 1588 -363 0
Times New Roman 2048 1825 -443 87
Brush Script MT 2048 1820 -692 0
Noto Sans Javanese 1000 1120 -916 0
Georgia 2048 1878 -449 0
Courier New 2048 1705 -615 0
Arial Unicode MS 2048 2189 -555 0
Chalkduster 905 887 -256 12
STIXIntegralsUpSm 1000 1055 -455 0
STIXIntegralsUpD 1000 2182 -451 0
Noto Sans Sundanese 1000 1069 -368 0
Apple Chancery 2048 2289 -952 0
AppleMyungjo 1025 891 -326 0
STIXSizeOneSym 1000 1588 -363 0
Noto Sans Ol Chiki 1000 1069 -293 0
Noto Sans Gunjala Gondi 1000 1014 -252 0
Noto Sans Carian 1000 1069 -293 0
Arial Narrow 2048 1916 -434 0
Noto Sans Modi 1000 891 -463 0
Noto Sans Meroitic 1000 928 -415 0
STIXNonUnicode 1000 1450 -552 0
Noto Sans Palmyrene 1000 1069 -293 0
Noto Sans PhagsPa 1000 1069 -293 0
Arial Narrow 2048 1916 -434 0
Noto Sans Siddham 1000 1000 -1030 0
Noto Sans Yi 1000 1069 -293 0
Noto Sans PsaPahlavi 1000 737 -554 0
Noto Sans Limbu 1000 1069 -293 0
Noto Sans Cypriot 1000 1069 -293 0
Noto Sans Bamum 1000 1069 -293 0
Noto Sans Lisu 1000 1069 -293 0
Courier New 2048 1705 -615 0
Wingdings 3 2048 1900 -432 0
Noto Sans Mahajani 1000 757 -243 0
Wingdings 2 2048 1727 -432 0
Noto Sans Glagolitic 1000 1069 -293 0
Hoefler Text Ornaments 2000 1613 -416 0
Noto Serif Ahom 1000 980 -675 0
Bodoni Ornaments 1000 810 -191 0
Noto Sans Vai 1000 1069 -293 0
Noto Sans Tagbanwa 1000 1069 -293 0
STIX Two Text 1000 762 -238 250
Skia 2048 1591 -457 0
Noto Sans Phoenician 1000 1069 -293 0
Trebuchet MS 2048 1923 -455 0
STIX Two Math 1000 762 -238 250
Impact 2048 2066 -432 0
Kokonor 2600 2714 -1596 42
Noto Sans Kaithi 1000 1077 -425 0
STIXIntegralsUp 1000 1055 -455 0
Noto Serif Balinese 1000 1069 -726 0
Noto Sans Takri 1000 955 -307 0
Noto Sans Masaram Gondi 1000 1000 -200 0
STIXSizeThreeSym 1000 2604 -510 0
Noto Sans EgyptHiero 1000 1324 -326 0
Noto Sans Samaritan 1000 1069 -293 0
Noto Sans Elbasan 1000 847 -270 0
Party LET 2048 1365 -1024 0
Noto Sans Kharoshthi 1000 1069 -301 0
Tahoma 2048 2049 -423 0
Arial 2048 1854 -434 67
Diwan Thuluth 2048 2071 -1439 0
Noto Sans Tagalog 1000 1069 -293 0
Ayuthaya 2100 2241 -674 0
STIXIntegralsUp 1000 1055 -455 0
Khmer Sangam MN 2048 2294 -1393 380
STIXSizeThreeSym 1000 2604 -510 0
Noto Sans Sharada 1000 925 -455 0
Noto Sans Khojki 1000 1409 -447 0
Noto Sans NewTaiLue 1000 1069 -293 0
Noto Sans InsParthi 1000 1069 -301 0
STIXNonUnicode 1000 1450 -552 0
Trebuchet MS 2048 1923 -455 0
Noto Sans Buhid 1000 1069 -293 0
Arial Black 2048 2254 -634 0
Courier New 2048 1705 -615 0
Comic Sans MS 2048 2257 -597 0
Noto Sans Khudawadi 1000 944 -373 0
Noto Serif Yezidi 1000 1068 -292 0
Noto Sans Buginese 1000 1069 -293 0
Noto Sans Linear B 1000 1069 -293 0
DIN Alternate 2048 1921 -463 0
Wingdings 2048 1841 -432 0
Noto Sans Newa 1000 1036 -396 0
Sathu 1274 1151 -404 0
Noto Sans Syloti Nagri 1000 1069 -293 0
Arial 2048 1854 -434 67
STIXSizeTwoSym 1000 2095 -404 0
Noto Sans OldPersian 1000 1069 -293 0
Tahoma 2048 2049 -423 0
Plantagenet Cherokee 1000 697 -285 74
Georgia 2048 1878 -449 0
Noto Sans Linear A 1000 1069 -293 0
STIXIntegralsSm 1000 1055 -455 0
STIXNonUnicode 1000 1450 -552 0
STIXSizeFourSym 1000 2604 -510 0
Verdana 2048 2059 -430 0
Microsoft Sans Serif 2048 1888 -430 0
Noto Sans Cuneiform 1000 1596 -690 0
Georgia 2048 1878 -449 0
Noto Sans Batak 1000 1069 -293 0
Arial Rounded MT Bold 2048 1938 -432 0
Times New Roman 2048 1825 -443 87
STIXSizeTwoSym 1000 2095 -404 0
Noto Sans Wancho 1000 1096 -161 0
STIXGeneral 1000 1042 -455 0
Krungthep 2560 2587 -672 0
Noto Sans OldSouArab 1000 1069 -293 0
STIXSizeFourSym 1000 2604 -510 0
STIXIntegralsSm 1000 1055 -455 0
Noto Sans PauCinHau 1000 1069 -293 0
Noto Sans Marchen 1000 1107 -534 0
Noto Sans Old Italic 1000 1069 -293 0
Noto Sans Gothic 1000 1069 -293 0
Gurmukhi MT 2048 1770 -900 0
STIXNonUnicode 1000 1450 -552 0
Andale Mono 2048 1858 -446 0
Mishafi Gold 2048 1607 -1356 0
Herculanum 1000 795 -205 0
Noto Sans Tai Viet 1000 1069 -293 0
Noto Sans ImpAramaic 1000 1069 -293 0
STIXIntegralsD 1000 2182 -451 0
Noto Sans Brahmi 1000 1069 -306 0
STIXVariants 1000 1055 -455 0
Comic Sans MS 2048 2257 -597 0
Noto Sans Coptic 1000 1069 -293 0
STIXSizeFiveSym 1000 960 -454 0
Arial 2048 1854 -434 67
Noto Sans Tifinagh 1000 1069 -293 0
Noto Sans Old Turkic 1000 1069 -293 0
STIXGeneral 1000 1055 -455 0
Noto Sans Mongolian 1000 1457 -293 0
Verdana 2048 2059 -430 0
Noto Sans Old Permic 1000 1069 -293 0
STIXIntegralsD 1000 2182 -451 0
Noto Sans Tai Tham 2048 2189 -1000 0
Noto Sans MeeteiMayek 1000 1069 -321 0
Noto Sans OldNorArab 1000 1069 -293 0
Noto Sans Osmanya 1000 1069 -293 0
Arial Narrow 2048 1916 -434 0
// This script extracts font metadata from TTF/OTF files in a specified directory
// Example: deno run --allow-read --allow-run --allow-env font_metrics.ts FONTS_DIR
import fs from "node:fs";
import path from "node:path";
import { execSync } from "node:child_process";
const fontDir = process.argv[2];
if (fontDir.trim() === "") {
console.error("Dir not provided");
process.exit(-1);
}
const files = fs.readdirSync(fontDir);
const fontFiles = files.filter((f) => /\.(ttf|otf)$/i.test(f));
if (fontFiles.length === 0) {
console.log("No font files found.");
process.exit(0);
}
function run(cmd: string): string {
const out = execSync(cmd, {
shell: true,
encoding: "utf8",
stdio: ["ignor", "pipe", "ignore"],
});
return out.trim();
}
console.log("| Name | UnitsPerEm | Ascender | Descender | LineGap |");
console.log("|:-|:-|:-|:-|:-|");
for (const file of fontFiles) {
const fullPath = path.join(fontDir, file);
const results = [
run(
`ttx -q -t name -o - "${fullPath}" | dasel -r xml -w json | jq -r '.ttFont.name.namerecord | map(select(."-nameID" == "1"))[0]."#text"'`,
),
run(
`ttx -t head -q -o - "${fullPath}" | dasel -r xml '.ttFont.head.unitsPerEm.-value'`,
),
run(
`ttx -t hhea -q -o - "${fullPath}" | dasel -r xml '.ttFont.hhea.ascent.-value'`,
),
run(
`ttx -t hhea -q -o - "${fullPath}" | dasel -r xml '.ttFont.hhea.descent.-value'`,
),
run(
`ttx -t hhea -q -o - "${fullPath}" | dasel -r xml '.ttFont.hhea.lineGap.-value'`,
),
];
console.log(`| ${results.join(" | ")} |`);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment