Open Zxilly opened 2 months ago
Thanks your advice!
I will conduct more detailed testing between skia-canvas
and playwright
later. The width of 'a' measured by skia-canvas is 12.050000190734863
when font-family is "Lucida Console, Courier, monospace"
, font-size is 20px. And the playwright is 12.0625
, which is equal to measured in browser.
In my other repository svg-ebook-reader
, it need more accurate measurements. And I don't know how it behave after using skia-canvas. But in this, using skia-canvas
is indeed a better choice.
In reality, such measurements are very inaccurate. Unless it's an equal-width font, almost every character has a slight difference in width, and when multiple letters are joined together, they may also be wider or thinner than their widths directly add up. You can try using opentype.js to calculate this.
What I am concerned about is the cumulative error in char width, but now I have find that the width difference between the measurements above is 0.0125px
. Only when the accumulated chars reach around 100, there will be a 1px error. In most cases, the situation will not be encountered. And 0.1px difference will be ignored by the browser.
The background overlap when selecting text can be solved by changing the background color.
2024-9-18 If playwright replaced with skia-canvas. The renderer result will be the bottom:
when selecting text, white gaps will appear between the texts.
skia-canvas is much more lightweight than a full chromium