Skip to content

Commit 965c1a3

Browse files
authored
fix: Clamp transforms to sensible levels of precision (#10268)
1 parent 197b697 commit 965c1a3

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

packages/blockly/core/utils/dom.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ export function getFastTextWidthWithSizeString(
308308
if (text && canvasContext) {
309309
// Set the desired font size and family.
310310
canvasContext.font = fontWeight + ' ' + fontSize + ' ' + fontFamily;
311-
width = canvasContext.measureText(text).width;
311+
width = Math.ceil(canvasContext.measureText(text).width);
312312
} else {
313313
width = 0;
314314
}

packages/blockly/core/workspace_svg.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1931,8 +1931,8 @@ export class WorkspaceSvg
19311931
// The scrollX and scrollY still need to have absoluteLeft and absoluteTop
19321932
// subtracted from them, but we'll leave that for setScale so that they're
19331933
// correctly updated for the new flyout size if we have a simple toolbox.
1934-
this.scrollX = matrix.e;
1935-
this.scrollY = matrix.f;
1934+
this.scrollX = Math.round(matrix.e);
1935+
this.scrollY = Math.round(matrix.f);
19361936
this.setScale(newScale);
19371937
}
19381938

@@ -2118,6 +2118,7 @@ export class WorkspaceSvg
21182118
* @param newScale Zoom factor. Units: (pixels / workspaceUnit).
21192119
*/
21202120
setScale(newScale: number) {
2121+
newScale = Math.round(newScale * 1000) / 1000;
21212122
if (
21222123
this.options.zoomOptions.maxScale &&
21232124
newScale > this.options.zoomOptions.maxScale
@@ -2255,8 +2256,8 @@ export class WorkspaceSvg
22552256
metrics.scrollHeight - metrics.viewHeight,
22562257
);
22572258
const maxYScroll = metrics.scrollTop + maxYDisplacement;
2258-
x = Math.max(x, -maxXScroll);
2259-
y = Math.max(y, -maxYScroll);
2259+
x = Math.round(Math.max(x, -maxXScroll));
2260+
y = Math.round(Math.max(y, -maxYScroll));
22602261
this.scrollX = x;
22612262
this.scrollY = y;
22622263

0 commit comments

Comments
 (0)