Skip to content

Commit

Permalink
fix subpixel problem
Browse files Browse the repository at this point in the history
  • Loading branch information
asiloisad committed Jan 6, 2025
1 parent a99dd97 commit c5e8a90
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions packages/image-view/lib/image-editor-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,9 @@ class ImageEditorView {
}

const factor = this.steps[percentageStep]
const newWidth = Math.round(this.originalWidth * factor)
const newHeight = Math.round(this.originalHeight * factor)
const percent = Math.max(1, Math.round((newWidth / this.originalWidth) * 100))
const newWidth = (this.originalWidth * factor)
const newHeight = (this.originalHeight * factor)
const percent = Math.max(1, ((newWidth / this.originalWidth) * 100))

// Switch to pixelated rendering when image is bigger than 200%
if (newWidth > (this.originalWidth * 2)) {
Expand Down
2 changes: 1 addition & 1 deletion packages/wrap-guide/lib/wrap-guide-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ module.exports = class WrapGuideElement {
columnWidth -= this.editorElement.getScrollLeft();
const guide = document.createElement('div');
guide.classList.add('wrap-guide');
guide.style.left = `${Math.round(columnWidth)}px`;
guide.style.left = `${(columnWidth)}px`;
return this.element.appendChild(guide);
}
};
18 changes: 9 additions & 9 deletions src/text-editor-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -1578,8 +1578,8 @@ module.exports = class TextEditorComponent {
}
}

decoration.pixelTop = Math.round(wrapperTop);
decoration.pixelLeft = Math.round(wrapperLeft);
decoration.pixelTop = (wrapperTop);
decoration.pixelLeft = (wrapperLeft);
}

updateOverlaysToRender() {
Expand Down Expand Up @@ -2684,7 +2684,7 @@ module.exports = class TextEditorComponent {

positions.set(
nextColumnToMeasure,
Math.round(clientPixelPosition - lineNodeClientLeft)
(clientPixelPosition - lineNodeClientLeft)
);
continue columnLoop; // eslint-disable-line no-labels
} else {
Expand All @@ -2708,7 +2708,7 @@ module.exports = class TextEditorComponent {

positions.set(
nextColumnToMeasure,
Math.round(lastTextNodeRight - lineNodeClientLeft)
(lastTextNodeRight - lineNodeClientLeft)
);
}
}
Expand Down Expand Up @@ -3100,7 +3100,7 @@ module.exports = class TextEditorComponent {
}

getContentWidth() {
return Math.ceil(this.getLongestLineWidth() + this.getBaseCharacterWidth());
return (this.getLongestLineWidth() + this.getBaseCharacterWidth());
}

getScrollContainerClientWidthInBaseCharacters() {
Expand Down Expand Up @@ -3241,7 +3241,7 @@ module.exports = class TextEditorComponent {
}

getMaxScrollTop() {
return Math.round(
return (
Math.max(
0,
this.getScrollHeight() - this.getScrollContainerClientHeight()
Expand Down Expand Up @@ -3280,7 +3280,7 @@ module.exports = class TextEditorComponent {
}

getMaxScrollLeft() {
return Math.round(
return (
Math.max(0, this.getScrollWidth() - this.getScrollContainerClientWidth())
);
}
Expand Down Expand Up @@ -5227,15 +5227,15 @@ class NodePool {
function roundToPhysicalPixelBoundary(virtualPixelPosition) {
const virtualPixelsPerPhysicalPixel = 1 / window.devicePixelRatio;
return (
Math.round(virtualPixelPosition / virtualPixelsPerPhysicalPixel) *
(virtualPixelPosition / virtualPixelsPerPhysicalPixel) *
virtualPixelsPerPhysicalPixel
);
}

function ceilToPhysicalPixelBoundary(virtualPixelPosition) {
const virtualPixelsPerPhysicalPixel = 1 / window.devicePixelRatio;
return (
Math.ceil(virtualPixelPosition / virtualPixelsPerPhysicalPixel) *
(virtualPixelPosition / virtualPixelsPerPhysicalPixel) *
virtualPixelsPerPhysicalPixel
);
}

0 comments on commit c5e8a90

Please sign in to comment.