Skip to content

Commit

Permalink
fix: use larger font-size to calc real font size
Browse files Browse the repository at this point in the history
  • Loading branch information
weizhenye committed Jun 16, 2024
1 parent 0ecdd45 commit 4dfbe4e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
opacity: var(--ass-border-opacity);
}
.ASS-fix-font-size {
font-size: 2048px;
line-height: normal;
position: absolute;
visibility: hidden;
}
Expand Down
13 changes: 7 additions & 6 deletions src/renderer/font-size.js
Original file line number Diff line number Diff line change
@@ -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];
}

0 comments on commit 4dfbe4e

Please sign in to comment.