Currently, accessing this information from Web-APIs remains a challenge.
The Houdini group is in the midst of ongoing discussions regarding the potential inclusion of a font-metrics API. This API aims to provide detailed font usage data, but it has not yet progressed beyond the proposal stage. The path towards its implementation is expected to be complex and arduous.
Determining the specific fonts being used presents complexities due to the possibility of multiple fonts being employed at various levels within text content. In order to properly expose this information, proposed solutions suggest utilizing handles that contain comprehensive font details, including raw font data for web fonts. dbaron & eae are leading efforts in defining an appropriate API for this purpose.
An example scenario involves using one font for the glyph ̂
(U+0302), while another font may be utilized for the glyph a
(U+0061), resulting in a combined glyph like â
requiring two distinct fonts.
Current conversations indicate the potential introduction of a Font interface, accessible through the document.measureElement
and document.measureText
methods. This interface would offer properties such as a DOMString name
and a numeric value indicating glyphsRendered
. However, these ideas are still in the discussion phase and have yet to advance to draft proposals, signifying further deliberation and refinement are necessary before any concrete steps can be taken towards implementation.
In the absence of definitive Web-API support, alternative methods exist, albeit with limitations. As numerous other Q/A threads explain, strategies involving inspecting rendering sizes or observed pixel output may provide insights into the fonts used, though these tactics are considered unreliable and may not function universally across all scenarios.
For instance, if a custom font on a user's system displays select characters from a standard font, discerning between font fallbacks and intended selections becomes problematic using existing techniques.
Ultimately, full control over font usage and fidelity can best be achieved by employing web-font solutions.