Commit 80565d1
Fix race condition with fillText/strokeText.
This commit fixes the race condition where if you executed fillText or
strokeText more than once you would be using the previously scaled font
size property.
Let's consider this example:
ctx.font = '12pt Tahoma';
ctx.fillText('Hello', 0, 0); // ctx.font changes to ratio * font_size
ctx.fillText('Hello', 0, 0); // ctx.font changes to ratio^2 * font_size
The first fillText would be rendered with ratio * font_size, but since
the font size property stays multiplied, on the next execution it will
be multiplied again, causing a further multiplied version to appear.
The solution employed —since canvas works this way and you can't
explicitly set a font with a fillText call— is to multiply the font size,
execute the fillText function and then divide by the ratio. This way,
the font size stays intact.1 parent 5c30ed6 commit 80565d1
1 file changed
+16
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
81 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
82 | 89 | | |
83 | 90 | | |
84 | 91 | | |
| |||
97 | 104 | | |
98 | 105 | | |
99 | 106 | | |
100 | | - | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
101 | 115 | | |
102 | 116 | | |
103 | 117 | | |
0 commit comments