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

Function getCharacterMetrics

static/katex/katex.js:3740–3776  ·  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

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

Callers 3

buildCommon_lookupSymbolFunction · 0.70
buildMathML_getVariantFunction · 0.70
delimiter_getMetricsFunction · 0.70

Calls 1

supportedCodepointFunction · 0.70

Tested by

no test coverage detected