Skip to content

Commit

Permalink
Merge pull request #1077 from Unlasting1/fix/platform-fontSize-reg
Browse files Browse the repository at this point in the history
fix(platform): fix `measureText` can't recognize decimal font size
  • Loading branch information
plainheart authored May 14, 2024
2 parents 379f91f + 76daa1c commit 4783a86
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/core/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const platformApi: Platform = {
text = text || '';
font = font || DEFAULT_FONT;
// Use font size if there is no other method can be used.
const res = /(\d+)px/.exec(font);
const res = /((?:\d+)?\.?\d*)px/.exec(font);
const fontSize = res && +res[1] || DEFAULT_FONT_SIZE;
let width = 0;
if (font.indexOf('mono') >= 0) { // is monospace
Expand Down Expand Up @@ -108,4 +108,4 @@ export function setPlatformAPI(newPlatformApis: Partial<Platform>) {
(platformApi as any)[key] = (newPlatformApis as any)[key];
}
}
}
}

0 comments on commit 4783a86

Please sign in to comment.