diff --git a/src/global.css b/src/global.css index 08ebf63..9a53101 100644 --- a/src/global.css +++ b/src/global.css @@ -34,6 +34,8 @@ opacity: var(--ass-border-opacity); } .ASS-fix-font-size { + font-size: 2048px; + line-height: normal; position: absolute; visibility: hidden; } diff --git a/src/renderer/font-size.js b/src/renderer/font-size.js index d6b4478..4346e9c 100644 --- a/src/renderer/font-size.js +++ b/src/renderer/font-size.js @@ -1,14 +1,15 @@ +// https://github.com/weizhenye/ASS/wiki/Font-Size-in-ASS + export const $fixFontSize = document.createElement('div'); $fixFontSize.className = 'ASS-fix-font-size'; -$fixFontSize.textContent = 'M'; +$fixFontSize.textContent = '0'; const cache = Object.create(null); export function getRealFontSize(fn, fs) { - const key = `${fn}-${fs}`; - if (!cache[key]) { - $fixFontSize.style.cssText = `line-height:normal;font-size:${fs}px;font-family:"${fn}",Arial;`; - cache[key] = fs * fs / $fixFontSize.clientHeight; + if (!cache[fn]) { + $fixFontSize.style.fontFamily = `font-family:"${fn}",Arial;`; + cache[fn] = fs * 2048 / $fixFontSize.clientHeight; } - return cache[key]; + return cache[fn]; }