测量样文在指定字体下的下伸度,计算从字母基线起算的下划线偏移。
等待样文用到的网页字体后再测量。结果按设备像素向上取整,适用于 text-underline-position: auto。 留白以样文为准,实际链接里的回退字形、混排样式和绘制对齐仍会影响可见间距。
text-underline-position: auto
Canvas 使用的 CSS font 简写,例如 normal 400 16px Yozai, serif。
normal 400 16px Yozai, serif
与实际正文使用相近字形的样文。
字形下方预留的 CSS 像素数,默认为 1。
偏移的 CSS 像素数。样文为空、字体加载失败或无法测量时返回 undefined。
undefined
gap 不是有限的非负数时抛出 RangeError。
0.2.0
// @example-skip 字体测量依赖浏览器的 Canvas 和 FontFaceSet。const offset = await measureUnderlineOffset('16px Yozai, serif', '中文链接 TypeScript gjpqy'); Copy
// @example-skip 字体测量依赖浏览器的 Canvas 和 FontFaceSet。const offset = await measureUnderlineOffset('16px Yozai, serif', '中文链接 TypeScript gjpqy');
测量样文在指定字体下的下伸度,计算从字母基线起算的下划线偏移。
等待样文用到的网页字体后再测量。结果按设备像素向上取整,适用于
text-underline-position: auto。 留白以样文为准,实际链接里的回退字形、混排样式和绘制对齐仍会影响可见间距。