I am currently working on creating a comprehensive Unicode table that allows for the comparison of glyph spacing among different fonts.
The goal is to have a table where users can select various fonts, each with their own unique metrics. Given this variability in font characteristics, I am exploring whether it is feasible to align the child fonts with the baseline of the parent font after positioning the child glyph objects absolutely.
#table{
display: flex;
justify-content: center;
align-items: center;
font-size: 72pt;
/* reference dimensions */
border: 1px solid blue;
}
#table > div {
display: inline-flex;
justify-content: center;
font-family: sans-serif;
border: 1px solid #F0F;
}
#table > div > span {
position: absolute;
mix-blend-mode: difference;
font-family: monospace;
color: green;
/* alignment reference */
outline: 1px solid #0F0;
}
<div id="table">
<div>x</div>
<div>y</div>
<div>z</div>
<div>!</div>
</div>
My ideal solution would involve using solely CSS, although my research suggests this may not be achievable. Is there any way to access and manipulate font metrics through JavaScript, perhaps by calculating margins based on top or bottom values and passing them as CSS variables?
If an alternative approach is required, I may end up adjusting the relative position of child glyphs towards the start of the flex container by half their width plus half the width of the parent object. This could become cumbersome when dealing with thousands of glyphs and frequent font changes...
UPDATE: To provide context, the fonts "Arial" and "Times New Roman" are utilized as sans-serif
and monospace
respectively. The initial output is tested in Gecko/Firefox and later aligned with Chromium. While minor discrepancies between browsers may not usually pose a problem, these differences can impact specific layout aspects. For example, the default baselines in Word appear as shown below:
https://i.sstatic.net/Y8JwY.png
- In "Times New Roman", the 'z' and '!' characters extend below the baseline, similar to the right side of 'x'.
- The character 'y' actually extends above the baseline slightly.
- All glyphs exhibit greater ascenders and descenders compared to their counterparts in "Arial".