x-Height Ratio From Font File
Extract head.unitsPerEm and OS/2.sxHeight from caller hex standalone SFNT font bytes; absent/zero/old OS/2 x-height is explicitly unavailable, not guessed from cap height or a full font validity certification.
Description
A font’s x-height ratio relates a native metric to units per em.
A font’s x-height ratio relates a native metric to units per em. Missing native metrics should be represented separately from measured outline height.1, 2
Paste even-length hexadecimal standalone TrueType/OpenType SFNT bytes. Parse a bounded table directory, validate nonoverlap/in-bounds tables, head magic and unitsPerEm 16–16384; read OS/2 v2+ sxHeight at offset 86. Return units, x-height, ratio and availability.
When to use x-Height Ratio From Font File
Use x-Height Ratio From Font File when you need to evaluate the supplied records under the calculation and evidence rules below. Missing OS/2, versions below 2 or zero x-height return unavailable with zero placeholders. WOFF/collections, truncated/overlapping tables and negative x-height fail. No checksum or complete font validity is verified.
Prepare measured font or typeset-layout values and the explicit design policy requested. For text or font bytes, use the supported syntax explained below.
How to use x-Height Ratio From Font File and understand its results
- Prepare measured font or typeset-layout values and the explicit design policy requested. For text or font bytes, use the supported syntax explained below.
- Enter fontFileHex using the field table and calculation rules, then run the tool.
- Read unitsPerEm, nativeXHeightUnits, xHeightRatio, nativeXHeightAvailable. The explanation below defines the units, signs, ordering and any flags or placeholder values.
- If the tool reports an input issue, correct the values and run it again. Apply the stated assumptions when interpreting a successfully returned result.
| Input field | Meaning | Value type; see rules below | Requirement |
|---|---|---|---|
| fontFileHex | Font file hex | string | Required |
Paste even-length hexadecimal standalone TrueType/OpenType SFNT bytes. Parse a bounded table directory, validate nonoverlap/in-bounds tables, head magic and unitsPerEm 16–16384; read OS/2 v2+ sxHeight at offset 86. Return units, x-height, ratio and availability.
ratio=sxHeight/unitsPerEm when available, otherwise zero Units, indexing, boundary conditions and exceptional cases are defined in the calculation rules above.
| Output field | Meaning | Value type |
|---|---|---|
| unitsPerEm | Units per em | number |
| nativeXHeightUnits | Native x height units | number |
| xHeightRatio | X height ratio | number |
| nativeXHeightAvailable | Native x height available | boolean |
{
"input": {
"fontFileHex": "00010000000200200001000068656164000000000000002c000000364f532f320000000000000064000000600000000000000000000000005f0f3cf5000003e8000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001f40000000000000000"
},
"output": {
"unitsPerEm": 1000,
"nativeXHeightUnits": 500,
"xHeightRatio": 0.5,
"nativeXHeightAvailable": true
}
} Limitations and assumptions
Missing OS/2, versions below 2 or zero x-height return unavailable with zero placeholders. WOFF/collections, truncated/overlapping tables and negative x-height fail. No checksum or complete font validity is verified.
Numeric inputs, where present, must be finite. Follow the calculation-specific rules for overflow, underflow and exceptional cases. Extremely large text inputs are rejected. Missing required fields, extra fields, wrong value types and violations of the calculation rules are input errors. A successfully returned false flag is an evaluated outcome; its meaning is explained above.
Alternative or Complementary methods
Use Inline Code Monospace x-Height Match: Matching inline code to body x-height requires independent metrics from both fonts. Equal x-height does not imply equal weight or baselines. For a complementary task, use Fallback Metrics Ascent/Descent Override: Font metrics overrides and size-adjust scaling interact. The requested percentages must account for scaling to reach the target layout metrics.
Further background: OpenType OS/2: sxHeight.
References
-
x-Height Ratio From Font File — tool.io
-
OpenType OS/2: sxHeight — Microsoft
Similar or alternative tools
- Inline Code Monospace x-Height Match
Matching inline code to body x-height requires independent metrics from both fonts. Equal x-height does not imply equal weight or baselines.
- Fallback Metrics Ascent/Descent Override
Font metrics overrides and size-adjust scaling interact. The requested percentages must account for scaling to reach the target layout metrics.