Team Ai
Datasetpublic

Brunobkr/llama.cpp_AlgMor24_github

ΩFFFΣLLIa • llama.cpp • AlgMor24 ██████╗ ███████╗███████╗███████╗██╗ ██╗ ██╗ █████╗ ██╔═══██╗██╔════╝██╔════╝██╔════╝██║ ██║ ██║██╔══██╗ ██║ ██║█████╗ █████╗ █████╗ ██║ ██║ ██║███████║ ██║ ██║██╔══╝ ██╔══╝ ██╔══╝ ██║ ██║ ██║██╔══██║ ╚██████╔╝██║ ██║ ███████╗███████╗███████╗██║██║ ██║ ╚═════╝ ╚═╝ ╚═╝ ╚══════╝╚══════╝╚══════╝╚═╝╚═╝ ╚═╝ High-Performance LLM / VLM Inference & Autonomous Agentic Ecosystem… See the full description on the dataset page: https://huggingface.co/datasets/Brunobkr/llama.cpp_AlgMor24_github.

sourceHugging Faceupdated 2mo agoView on Hugging Face
0likes3.1kdownloads
fontMetrics.ts268 linesDownload Raw Back to src
1import {supportedCodepoint} from "./unicodeScripts";2 3import type {Mode} from "./types";4import type {CharacterMetrics, CharacterMetricsTuple, FontMetrics} from "./types/fonts";5// This map contains a mapping from font name and character code to character6// metrics, including height, depth, italic correction, and skew (kern from the7// character to the corresponding \skewchar)8// This map is generated via `make metrics`. It should not be changed manually.9import metricMap from "./fontMetricsData";10 11/**12 * This file contains metrics regarding fonts and individual symbols. The sigma13 * and xi variables, as well as the metricMap map contain data extracted from14 * TeX, TeX font metrics, and the TTF files. These data are then exposed via the15 * `metrics` variable and the getCharacterMetrics function.16 */17 18// In TeX, there are actually three sets of dimensions, one for each of19// textstyle (size index 5 and higher: >=9pt), scriptstyle (size index 3 and 4:20// 7-8pt), and scriptscriptstyle (size index 1 and 2: 5-6pt).  These are21// provided in the arrays below, in that order.22//23// The font metrics are stored in fonts cmsy10, cmsy7, and cmsy5 respectively.24// This was determined by running the following script:25//26//     latex -interaction=nonstopmode \27//     '\documentclass{article}\usepackage{amsmath}\begin{document}' \28//     '$a$ \expandafter\show\the\textfont2' \29//     '\expandafter\show\the\scriptfont2' \30//     '\expandafter\show\the\scriptscriptfont2' \31//     '\stop'32//33// The metrics themselves were retrieved using the following commands:34//35//     tftopl cmsy1036//     tftopl cmsy737//     tftopl cmsy538//39// The output of each of these commands is quite lengthy.  The only part we40// care about is the FONTDIMEN section. Each value is measured in EMs.41const sigmasAndXis: Record<string, [number, number, number]> = {42    slant: [0.250, 0.250, 0.250],       // sigma143    space: [0.000, 0.000, 0.000],       // sigma244    stretch: [0.000, 0.000, 0.000],     // sigma345    shrink: [0.000, 0.000, 0.000],      // sigma446    xHeight: [0.431, 0.431, 0.431],     // sigma547    quad: [1.000, 1.171, 1.472],        // sigma648    extraSpace: [0.000, 0.000, 0.000],  // sigma749    num1: [0.677, 0.732, 0.925],        // sigma850    num2: [0.394, 0.384, 0.387],        // sigma951    num3: [0.444, 0.471, 0.504],        // sigma1052    denom1: [0.686, 0.752, 1.025],      // sigma1153    denom2: [0.345, 0.344, 0.532],      // sigma1254    sup1: [0.413, 0.503, 0.504],        // sigma1355    sup2: [0.363, 0.431, 0.404],        // sigma1456    sup3: [0.289, 0.286, 0.294],        // sigma1557    sub1: [0.150, 0.143, 0.200],        // sigma1658    sub2: [0.247, 0.286, 0.400],        // sigma1759    supDrop: [0.386, 0.353, 0.494],     // sigma1860    subDrop: [0.050, 0.071, 0.100],     // sigma1961    delim1: [2.390, 1.700, 1.980],      // sigma2062    delim2: [1.010, 1.157, 1.420],      // sigma2163    axisHeight: [0.250, 0.250, 0.250],  // sigma2264 65    // These font metrics are extracted from TeX by using tftopl on cmex10.tfm;66    // they correspond to the font parameters of the extension fonts (family 3).67    // See the TeXbook, page 441. In AMSTeX, the extension fonts scale; to68    // match cmex7, we'd use cmex7.tfm values for script and scriptscript69    // values.70    defaultRuleThickness: [0.04, 0.049, 0.049], // xi8; cmex7: 0.04971    bigOpSpacing1: [0.111, 0.111, 0.111],       // xi972    bigOpSpacing2: [0.166, 0.166, 0.166],       // xi1073    bigOpSpacing3: [0.2, 0.2, 0.2],             // xi1174    bigOpSpacing4: [0.6, 0.611, 0.611],         // xi12; cmex7: 0.61175    bigOpSpacing5: [0.1, 0.143, 0.143],         // xi13; cmex7: 0.14376 77    // The \sqrt rule width is taken from the height of the surd character.78    // Since we use the same font at all sizes, this thickness doesn't scale.79    sqrtRuleThickness: [0.04, 0.04, 0.04],80 81    // This value determines how large a pt is, for metrics which are defined82    // in terms of pts.83    // This value is also used in katex.scss; if you change it make sure the84    // values match.85    ptPerEm: [10.0, 10.0, 10.0],86 87    // The space between adjacent `|` columns in an array definition. From88    // `\showthe\doublerulesep` in LaTeX. Equals 2.0 / ptPerEm.89    doubleRuleSep: [0.2, 0.2, 0.2],90 91    // The width of separator lines in {array} environments. From92    // `\showthe\arrayrulewidth` in LaTeX. Equals 0.4 / ptPerEm.93    arrayRuleWidth: [0.04, 0.04, 0.04],94 95    // Two values from LaTeX source2e:96    fboxsep: [0.3, 0.3, 0.3], //        3 pt / ptPerEm97    fboxrule: [0.04, 0.04, 0.04], // 0.4 pt / ptPerEm98};99 100// These are very rough approximations.  We default to Times New Roman which101// should have Latin-1 and Cyrillic characters, but may not depending on the102// operating system.  The metrics do not account for extra height from the103// accents.  In the case of Cyrillic characters which have both ascenders and104// descenders we prefer approximations with ascenders, primarily to prevent105// the fraction bar or root line from intersecting the glyph.106// TODO(kevinb) allow union of multiple glyph metrics for better accuracy.107const extraCharacterMap: Record<string, string> = {108    // Latin-1109    'Å': 'A',110    'Ð': 'D',111    'Þ': 'o',112    'å': 'a',113    'ð': 'd',114    'þ': 'o',115 116    // Cyrillic117    'А': 'A',118    'Б': 'B',119    'В': 'B',120    'Г': 'F',121    'Д': 'A',122    'Е': 'E',123    'Ж': 'K',124    'З': '3',125    'И': 'N',126    'Й': 'N',127    'К': 'K',128    'Л': 'N',129    'М': 'M',130    'Н': 'H',131    'О': 'O',132    'П': 'N',133    'Р': 'P',134    'С': 'C',135    'Т': 'T',136    'У': 'y',137    'Ф': 'O',138    'Х': 'X',139    'Ц': 'U',140    'Ч': 'h',141    'Ш': 'W',142    'Щ': 'W',143    'Ъ': 'B',144    'Ы': 'X',145    'Ь': 'B',146    'Э': '3',147    'Ю': 'X',148    'Я': 'R',149    'а': 'a',150    'б': 'b',151    'в': 'a',152    'г': 'r',153    'д': 'y',154    'е': 'e',155    'ж': 'm',156    'з': 'e',157    'и': 'n',158    'й': 'n',159    'к': 'n',160    'л': 'n',161    'м': 'm',162    'н': 'n',163    'о': 'o',164    'п': 'n',165    'р': 'p',166    'с': 'c',167    'т': 'o',168    'у': 'y',169    'ф': 'b',170    'х': 'x',171    'ц': 'n',172    'ч': 'n',173    'ш': 'w',174    'щ': 'w',175    'ъ': 'a',176    'ы': 'm',177    'ь': 'a',178    'э': 'e',179    'ю': 'm',180    'я': 'r',181};182 183/**184 * This function adds new font metrics to default metricMap185 * It can also override existing metrics186 */187export function setFontMetrics(188    fontName: string,189    metrics: {[key: string]: CharacterMetricsTuple}190) {191    metricMap[fontName] = metrics;192}193 194/**195 * This function is a convenience function for looking up information in the196 * metricMap table. It takes a character as a string, and a font.197 *198 * Note: the `width` property may be undefined if fontMetricsData.js wasn't199 * built using `Make extended_metrics`.200 */201export function getCharacterMetrics(202    character: string,203    font: string,204    mode: Mode,205): CharacterMetrics | null | undefined {206    if (!metricMap[font]) {207        throw new Error(`Font metrics not found for font: ${font}.`);208    }209    let ch = character.charCodeAt(0);210    let metrics = metricMap[font][ch];211    if (!metrics && character[0] in extraCharacterMap) {212        ch = extraCharacterMap[character[0]].charCodeAt(0);213        metrics = metricMap[font][ch];214    }215 216    if (!metrics && mode === 'text') {217        // We don't typically have font metrics for Asian scripts.218        // But since we support them in text mode, we need to return219        // some sort of metrics.220        // So if the character is in a script we support but we221        // don't have metrics for it, just use the metrics for222        // the Latin capital letter M. This is close enough because223        // we (currently) only care about the height of the glyph224        // not its width.225        if (supportedCodepoint(ch)) {226            metrics = metricMap[font][77]; // 77 is the charcode for 'M'227        }228    }229 230    if (metrics) {231        return {232            depth: metrics[0],233            height: metrics[1],234            italic: metrics[2],235            skew: metrics[3],236            width: metrics[4],237        };238    }239}240 241type FontSizeIndex = 0 | 1 | 2;242const fontMetricsBySizeIndex: Partial<Record<FontSizeIndex, FontMetrics>> = {};243 244/**245 * Get the font metrics for a given size.246 */247export function getGlobalMetrics(size: number): FontMetrics {248    let sizeIndex: FontSizeIndex;249    if (size >= 5) {250        sizeIndex = 0;251    } else if (size >= 3) {252        sizeIndex = 1;253    } else {254        sizeIndex = 2;255    }256    if (!fontMetricsBySizeIndex[sizeIndex]) {257        const metrics: FontMetrics = fontMetricsBySizeIndex[sizeIndex] = {258            cssEmPerMu: sigmasAndXis.quad[sizeIndex] / 18,259        };260        for (const key in sigmasAndXis) {261            if (sigmasAndXis.hasOwnProperty(key)) {262                metrics[key] = sigmasAndXis[key][sizeIndex];263            }264        }265    }266    return fontMetricsBySizeIndex[sizeIndex]!;267}268 
Brunobkr/llama.cpp_AlgMor24_github · Team Ai