| |
| |
| |
| |
| |
| |
| |
|
|
| import ParseError from "./ParseError"; |
| import type {FontName} from "./types/fonts"; |
|
|
| type WideChar = { |
| readonly mathClass: string; |
| readonly textClass: string; |
| readonly font: Extract<FontName, |
| | "Main-Bold" |
| | "Math-Italic" |
| | "Main-BoldItalic" |
| | "Script-Regular" |
| | "Fraktur-Regular" |
| | "AMS-Regular" |
| | "SansSerif-Regular" |
| | "SansSerif-Bold" |
| | "SansSerif-Italic" |
| | "Typewriter-Regular" |
| > | ""; |
| }; |
|
|
| const boldUpright: WideChar = { |
| mathClass: "mathbf", |
| textClass: "textbf", |
| font: "Main-Bold", |
| }; |
| const italic: WideChar = { |
| mathClass: "mathnormal", |
| textClass: "textit", |
| font: "Math-Italic", |
| }; |
| const boldItalic: WideChar = { |
| mathClass: "boldsymbol", |
| textClass: "boldsymbol", |
| font: "Main-BoldItalic", |
| }; |
| const script: WideChar = { |
| mathClass: "mathscr", |
| textClass: "textscr", |
| font: "Script-Regular", |
| }; |
| const noFont: WideChar = {mathClass: "", textClass: "", font: ""}; |
| const fraktur: WideChar = { |
| mathClass: "mathfrak", |
| textClass: "textfrak", |
| font: "Fraktur-Regular", |
| }; |
| const doubleStruck: WideChar = { |
| mathClass: "mathbb", |
| textClass: "textbb", |
| font: "AMS-Regular", |
| }; |
| const boldFraktur: WideChar = { |
| mathClass: "mathboldfrak", |
| textClass: "textboldfrak", |
| font: "Fraktur-Regular", |
| }; |
| const sansSerif: WideChar = { |
| mathClass: "mathsf", |
| textClass: "textsf", |
| font: "SansSerif-Regular", |
| }; |
| const boldSansSerif: WideChar = { |
| mathClass: "mathboldsf", |
| textClass: "textboldsf", |
| font: "SansSerif-Bold", |
| }; |
| const italicSansSerif: WideChar = { |
| mathClass: "mathitsf", |
| textClass: "textitsf", |
| font: "SansSerif-Italic", |
| }; |
| const monospace: WideChar = { |
| mathClass: "mathtt", |
| textClass: "texttt", |
| font: "Typewriter-Regular", |
| }; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| const wideLatinLetterData = [ |
| boldUpright, boldUpright, |
| italic, italic, |
| boldItalic, boldItalic, |
| |
| |
| script, noFont, |
| noFont, noFont, |
| fraktur, fraktur, |
| doubleStruck, doubleStruck, |
| |
| boldFraktur, boldFraktur, |
| sansSerif, sansSerif, |
| boldSansSerif, boldSansSerif, |
| italicSansSerif, italicSansSerif, |
| noFont, noFont, |
| monospace, monospace, |
| ] as const; |
|
|
| const wideNumeralData = [ |
| boldUpright, |
| noFont, |
| sansSerif, |
| boldSansSerif, |
| monospace, |
| ] as const; |
|
|
| export const wideCharacterFont = ( |
| wideChar: string, |
| ): WideChar => { |
|
|
| |
| const H = wideChar.charCodeAt(0); |
| const L = wideChar.charCodeAt(1); |
| const codePoint = ((H - 0xD800) * 0x400) + (L - 0xDC00) + 0x10000; |
|
|
| if (0x1D400 <= codePoint && codePoint < 0x1D6A4) { |
| |
| |
| const i = Math.floor((codePoint - 0x1D400) / 26); |
| return wideLatinLetterData[i]; |
|
|
| } else if (0x1D7CE <= codePoint && codePoint <= 0x1D7FF) { |
| |
| const i = Math.floor((codePoint - 0x1D7CE) / 10); |
| return wideNumeralData[i]; |
|
|
| } else if (codePoint === 0x1D6A5 || codePoint === 0x1D6A6) { |
| |
| return wideLatinLetterData[0]; |
|
|
| } else if (0x1D6A6 < codePoint && codePoint < 0x1D7CE) { |
| |
| return noFont; |
|
|
| } else { |
| |
| throw new ParseError("Unsupported character: " + wideChar); |
| } |
| }; |
|
|