MCPcopy Create free account
hub / github.com/TruthHun/BookStack / getCharacterMetrics

Function getCharacterMetrics

static/katex/katex.mjs:3743–3779  ·  view source on GitHub ↗

* This function is a convenience function for looking up information in the * metricMap table. It takes a character as a string, and a font. * * Note: the `width` property may be undefined if fontMetricsData.js wasn't * built using `Make extended_metrics`.

(character, font, mode)

Source from the content-addressed store, hash-verified

3741 */
3742
3743function getCharacterMetrics(character, font, mode) {
3744 if (!metricMap[font]) {
3745 throw new Error(`Font metrics not found for font: ${font}.`);
3746 }
3747
3748 let ch = character.charCodeAt(0);
3749
3750 if (character[0] in extraCharacterMap) {
3751 ch = extraCharacterMap[character[0]].charCodeAt(0);
3752 }
3753
3754 let metrics = metricMap[font][ch];
3755
3756 if (!metrics && mode === 'text') {
3757 // We don't typically have font metrics for Asian scripts.
3758 // But since we support them in text mode, we need to return
3759 // some sort of metrics.
3760 // So if the character is in a script we support but we
3761 // don't have metrics for it, just use the metrics for
3762 // the Latin capital letter M. This is close enough because
3763 // we (currently) only care about the height of the glpyh
3764 // not its width.
3765 if (supportedCodepoint(ch)) {
3766 metrics = metricMap[font][77]; // 77 is the charcode for 'M'
3767 }
3768 }
3769
3770 if (metrics) {
3771 return {
3772 depth: metrics[0],
3773 height: metrics[1],
3774 italic: metrics[2],
3775 skew: metrics[3],
3776 width: metrics[4]
3777 };
3778 }
3779}
3780const fontMetricsBySizeIndex = {};
3781/**
3782 * Get the font metrics for a given size.

Callers 3

lookupSymbolFunction · 0.70
getVariantFunction · 0.70
getMetricsFunction · 0.70

Calls 1

supportedCodepointFunction · 0.70

Tested by

no test coverage detected