Skip to content

Commit

Permalink
font accuracy.......
Browse files Browse the repository at this point in the history
  • Loading branch information
onlypuppy7 committed Dec 11, 2024
1 parent 8fb0d6c commit 79068a7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Binary file added src/Nunito-Bold.ttf
Binary file not shown.
6 changes: 4 additions & 2 deletions src/shell/stringWidth.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
//legacyshell: string width
import { isClient } from '#constants';
import { createCanvas } from 'canvas';
import { createCanvas, registerFont } from 'canvas';
//

//(server-only-start)
registerFont('./src/Nunito-Bold.ttf', { family: 'Nunito' });

const nameTestCanvas = createCanvas(200, 50);
//(server-only-end)

export function getStringWidth(str) {
const context = nameTestCanvas.getContext('2d');

context.font = '1em Nunito, sans-serif'; // same font definition on both environments
context.font = 'bold 1em Nunito, sans-serif'; // same font definition on both environments

return context.measureText(str).width / (isClient ? 1 : 2); //dont ask abt the division
};
Expand Down

0 comments on commit 79068a7

Please sign in to comment.