【发布时间】:2021-05-20 21:55:17
【问题描述】:
我正在尝试使用自定义字体呈现一些像这样的上标数字:¹ ² ³ ⁴ ⁵ ⁶ ⁷ ⁸ ⁹ ⁰,但只有前 3 个数字使用当前的 font-family 显示。其他的以默认页面字体显示。
这是一个工作示例:
@font-face {
font-family: "verveine";
src: url("//db.onlinewebfonts.com/t/b3fb273a4c9c465126f860b59809fd4a.eot");
src: url("//db.onlinewebfonts.com/t/b3fb273a4c9c465126f860b59809fd4a.eot?#iefix")
format("embedded-opentype"),
url("//db.onlinewebfonts.com/t/b3fb273a4c9c465126f860b59809fd4a.woff2")
format("woff2"),
url("//db.onlinewebfonts.com/t/b3fb273a4c9c465126f860b59809fd4a.woff")
format("woff"),
url("//db.onlinewebfonts.com/t/b3fb273a4c9c465126f860b59809fd4a.ttf")
format("truetype"),
url("//db.onlinewebfonts.com/t/b3fb273a4c9c465126f860b59809fd4a.svg#VerveineW01-Regular")
format("svg");
}
body {
font-family: verveine;
}
Test 1 2 3 4 5 6 7 8 9 0<br/>
Test ¹ ² ³ ⁴ ⁵ ⁶ ⁷ ⁸ ⁹ ⁰
但是当我访问 Adobe 网站上的 Verveine font page 并输入这些上标数字时,它们会正确显示:
我该如何解决这个问题?
编辑:
现在我将采用这种相当笨拙的解决方案来解析文本并将每个上标数字包装在 sup 标记中
function fixSuperNumbers(input: string): ReactNode[] {
const supers: Record<string, string> = {
"¹": "1",
"²": "2",
"³": "3",
"⁴": "4",
"⁵": "5",
"⁶": "6",
"⁷": "7",
"⁸": "8",
"⁹": "9",
"⁰": "0",
};
let results: ReactNode[] = [""];
for (let c of input.split("")) {
if (supers.hasOwnProperty(c)) {
results.push(<sup>{supers[c]}</sup>, "");
} else {
results[results.length - 1] += c;
}
}
return results.map((result, i) => <Fragment key={i}>{result}</Fragment>);
}
【问题讨论】:
-
当我用
<sup>1 2 3 4 5 6 7 8 9 0</sup>尝试它时seems to work。 -
Not reproducible 在 Edge 90.0.818.62(基于 Chrome)上
-
@SagarV 您的屏幕截图显示了该错误。上标数字 4-0 与常规数字 4-0 不匹配。
-
@j08691 这确实有效,但我很想找到一个不涉及转换文本的答案。
-
@SimpleJ 对不起,我错过了。这是字形支持问题。请参阅下面的答案。