Skip to content

[Refactor DPIUtil] rename scaleUp/Down #2314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public static Frame new_Frame (final Composite parent) {

parent.getDisplay().asyncExec(() -> {
if (parent.isDisposed()) return;
final Rectangle clientArea = Win32DPIUtils.scaleUp(parent.getClientArea(), DPIUtil.getZoomForAutoscaleProperty(parent.nativeZoom)); // To Pixels
final Rectangle clientArea = Win32DPIUtils.pointToPixel(parent.getClientArea(), DPIUtil.getZoomForAutoscaleProperty(parent.nativeZoom)); // To Pixels
EventQueue.invokeLater(() -> {
frame.setSize (clientArea.width, clientArea.height);
frame.validate ();
Expand Down Expand Up @@ -293,7 +293,7 @@ public void componentResized (ComponentEvent e) {
display.syncExec (() -> {
if (shell.isDisposed()) return;
Dimension dim = parent.getSize ();
shell.setSize(Win32DPIUtils.scaleDown(new Point(dim.width, dim.height), DPIUtil.getDeviceZoom())); // To Points
shell.setSize(Win32DPIUtils.pixelToPoint(new Point(dim.width, dim.height), DPIUtil.getDeviceZoom())); // To Points
});
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1254,14 +1254,14 @@ int handleContextMenuRequested(long pView, long pArgs) {
// to PIXEL coordinates with the real native zoom value
// independent from the swt.autoScale property:
Point pt = new Point( //
Win32DPIUtils.scaleUp(win32Point.x, DPIUtil.getNativeDeviceZoom()), //
Win32DPIUtils.scaleUp(win32Point.y, DPIUtil.getNativeDeviceZoom()));
Win32DPIUtils.pointToPixel(win32Point.x, DPIUtil.getNativeDeviceZoom()), //
Win32DPIUtils.pointToPixel(win32Point.y, DPIUtil.getNativeDeviceZoom()));
// - then, scale back down from PIXEL to DISPLAY coordinates, taking
// swt.autoScale property into account
// which is also later considered in Menu#setLocation()
pt = new Point( //
DPIUtil.scaleDown(pt.x, DPIUtil.getZoomForAutoscaleProperty(browser.getShell().nativeZoom)), //
DPIUtil.scaleDown(pt.y, DPIUtil.getZoomForAutoscaleProperty(browser.getShell().nativeZoom)));
DPIUtil.pixelToPoint(pt.x, DPIUtil.getZoomForAutoscaleProperty(browser.getShell().nativeZoom)), //
DPIUtil.pixelToPoint(pt.y, DPIUtil.getZoomForAutoscaleProperty(browser.getShell().nativeZoom)));
// - finally, translate the POINT from widget-relative
// to DISPLAY-relative coordinates
pt = browser.toDisplay(pt.x, pt.y);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1880,7 +1880,7 @@ void handleDOMEvent (OleEvent e) {
int screenY = pVarResult.getInt();
pVarResult.dispose();

Point position = Win32DPIUtils.scaleDown(new Point(screenX, screenY), DPIUtil.getDeviceZoom()); // To Points
Point position = Win32DPIUtils.pixelToPoint(new Point(screenX, screenY), DPIUtil.getDeviceZoom()); // To Points
position = browser.getDisplay().map(null, browser, position);
newEvent.x = position.x; newEvent.y = position.y;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ int ShowContextMenu(int dwID, long ppt, long pcmdtReserved, long pdispReserved)
Event event = new Event();
POINT pt = new POINT();
OS.MoveMemory(pt, ppt, POINT.sizeof);
pt.x = DPIUtil.scaleDown(pt.x, DPIUtil.getDeviceZoom()); // To Points
pt.y = DPIUtil.scaleDown(pt.y, DPIUtil.getDeviceZoom()); // To Points
pt.x = DPIUtil.pixelToPoint(pt.x, DPIUtil.getDeviceZoom()); // To Points
pt.y = DPIUtil.pixelToPoint(pt.y, DPIUtil.getDeviceZoom()); // To Points
event.x = pt.x;
event.y = pt.y;
browser.notifyListeners(SWT.MenuDetect, event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ private void drag(Event dragEvent) {
int offsetX = event.offsetX;
hwndDrag = topControl.handle;
if ((topControl.getStyle() & SWT.RIGHT_TO_LEFT) != 0) {
offsetX = Win32DPIUtils.scaleUp(image.getBounds(), zoom).width - offsetX;
offsetX = Win32DPIUtils.pointToPixel(image.getBounds(), zoom).width - offsetX;
RECT rect = new RECT ();
OS.GetClientRect (topControl.handle, rect);
hwndDrag = OS.CreateWindowEx (
Expand Down Expand Up @@ -538,8 +538,8 @@ private void drag(Event dragEvent) {
int flags = OS.RDW_UPDATENOW | OS.RDW_ALLCHILDREN;
OS.RedrawWindow (topControl.handle, null, 0, flags);
POINT pt = new POINT ();
pt.x = Win32DPIUtils.scaleUp(dragEvent.x, zoom);// To Pixels
pt.y = Win32DPIUtils.scaleUp(dragEvent.y, zoom);// To Pixels
pt.x = Win32DPIUtils.pointToPixel(dragEvent.x, zoom);// To Pixels
pt.y = Win32DPIUtils.pointToPixel(dragEvent.y, zoom);// To Pixels
OS.MapWindowPoints (control.handle, 0, pt, 1);
RECT rect = new RECT ();
OS.GetWindowRect (hwndDrag, rect);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ private Point convertPixelToPoint(int xInPixels, int yInPixels) {
if (this.control == null) {
// If there is no control for context, the behavior remains as before
int zoom = DPIUtil.getZoomForAutoscaleProperty(this.nativeZoom);
return Win32DPIUtils.scaleDown(new Point(xInPixels, yInPixels), zoom);
return Win32DPIUtils.pixelToPoint(new Point(xInPixels, yInPixels), zoom);
}
int zoom = DPIUtil.getZoomForAutoscaleProperty(this.control.nativeZoom);
// There is no API to convert absolute values in pixels to display relative
Expand All @@ -419,7 +419,7 @@ private Point convertPixelToPoint(int xInPixels, int yInPixels) {
POINT pt = new POINT ();
pt.x = xInPixels; pt.y = yInPixels;
OS.ScreenToClient (this.control.handle, pt);
Point p = Win32DPIUtils.scaleDown(new Point (pt.x, pt.y), zoom);
Point p = Win32DPIUtils.pixelToPoint(new Point (pt.x, pt.y), zoom);
return this.control.toDisplay(p);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void dragOver(DropTargetEvent event) {
int effect = checkEffect(event.feedback);
long handle = table.handle;
Point coordinates = new Point(event.x, event.y);
coordinates = Win32DPIUtils.scaleUp(table.toControl(coordinates), DPIUtil.getZoomForAutoscaleProperty(table.nativeZoom)); // To Pixels
coordinates = Win32DPIUtils.pointToPixel(table.toControl(coordinates), DPIUtil.getZoomForAutoscaleProperty(table.nativeZoom)); // To Pixels
LVHITTESTINFO pinfo = new LVHITTESTINFO();
pinfo.x = coordinates.x;
pinfo.y = coordinates.y;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public void dragOver(DropTargetEvent event) {
int effect = checkEffect(event.feedback);
long handle = tree.handle;
Point coordinates = new Point(event.x, event.y);
coordinates = Win32DPIUtils.scaleUp(tree.toControl(coordinates), DPIUtil.getZoomForAutoscaleProperty(tree.nativeZoom)); // To Pixels
coordinates = Win32DPIUtils.pointToPixel(tree.toControl(coordinates), DPIUtil.getZoomForAutoscaleProperty(tree.nativeZoom)); // To Pixels
TVHITTESTINFO lpht = new TVHITTESTINFO ();
lpht.x = coordinates.x;
lpht.y = coordinates.y;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ protected int GetWindow(long phwnd) {
return COM.S_OK;
}
RECT getRect() {
Rectangle area = Win32DPIUtils.scaleUp(getClientArea(), DPIUtil.getZoomForAutoscaleProperty(nativeZoom)); // To Pixels
Rectangle area = Win32DPIUtils.pointToPixel(getClientArea(), DPIUtil.getZoomForAutoscaleProperty(nativeZoom)); // To Pixels
RECT rect = new RECT();
rect.left = area.x;
rect.top = area.y;
Expand Down Expand Up @@ -987,14 +987,14 @@ private int OnInPlaceDeactivate() {
return COM.S_OK;
}
private int OnPosRectChange(long lprcPosRect) {
Point size = Win32DPIUtils.scaleUp(getSize(), DPIUtil.getZoomForAutoscaleProperty(nativeZoom)); // To Pixels
Point size = Win32DPIUtils.pointToPixel(getSize(), DPIUtil.getZoomForAutoscaleProperty(nativeZoom)); // To Pixels
setExtent(size.x, size.y);
return COM.S_OK;
}
private void onPaint(Event e) {
if (state == STATE_RUNNING || state == STATE_INPLACEACTIVE) {
SIZE size = getExtent();
Rectangle area = Win32DPIUtils.scaleUp(getClientArea(), DPIUtil.getZoomForAutoscaleProperty(nativeZoom)); // To Pixels
Rectangle area = Win32DPIUtils.pointToPixel(getClientArea(), DPIUtil.getZoomForAutoscaleProperty(nativeZoom)); // To Pixels
RECT rect = new RECT();
if (getProgramID().startsWith("Excel.Sheet")) { //$NON-NLS-1$
rect.left = area.x; rect.right = area.x + (area.height * size.cx / size.cy);
Expand Down Expand Up @@ -1370,11 +1370,11 @@ void setBorderSpace(RECT newBorderwidth) {
}
void setBounds() {
int zoom = DPIUtil.getZoomForAutoscaleProperty(nativeZoom);
Rectangle area = Win32DPIUtils.scaleUp(frame.getClientArea(), zoom); // To Pixels
setBounds(DPIUtil.scaleDown(borderWidths.left, zoom),
DPIUtil.scaleDown(borderWidths.top, zoom),
DPIUtil.scaleDown(area.width - borderWidths.left - borderWidths.right, zoom),
DPIUtil.scaleDown(area.height - borderWidths.top - borderWidths.bottom, zoom));
Rectangle area = Win32DPIUtils.pointToPixel(frame.getClientArea(), zoom); // To Pixels
setBounds(DPIUtil.pixelToPoint(borderWidths.left, zoom),
DPIUtil.pixelToPoint(borderWidths.top, zoom),
DPIUtil.pixelToPoint(area.width - borderWidths.left - borderWidths.right, zoom),
DPIUtil.pixelToPoint(area.height - borderWidths.top - borderWidths.bottom, zoom));
setObjectRects();
}
private void setExtent(int width, int height){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1822,27 +1822,27 @@ public String toString () {
* @noreference This method is not intended to be referenced by clients.
*/
public static void drawScaled(GC gc, Image original, int width, int height, float scaleFactor) {
gc.drawImage (original, 0, 0, CocoaDPIUtil.autoScaleDown (width), CocoaDPIUtil.autoScaleDown (height),
gc.drawImage (original, 0, 0, CocoaDPIUtil.pixelToPoint (width), CocoaDPIUtil.pixelToPoint (height),
/* E.g. destWidth here is effectively DPIUtil.autoScaleDown (scaledWidth), but avoiding rounding errors.
* Nevertheless, we still have some rounding errors due to the point-based API GC#drawImage(..).
*/
0, 0, Math.round (CocoaDPIUtil.autoScaleDown (width * scaleFactor)), Math.round (CocoaDPIUtil.autoScaleDown (height * scaleFactor)));
0, 0, Math.round (CocoaDPIUtil.pixelToPoint (width * scaleFactor)), Math.round (CocoaDPIUtil.pixelToPoint (height * scaleFactor)));
}

private final class CocoaDPIUtil {

/**
* Auto-scale down int dimensions.
*/
public static int autoScaleDown(int size) {
return DPIUtil.scaleDown(size, DPIUtil.getDeviceZoom());
public static int pixelToPoint(int size) {
return DPIUtil.pixelToPoint(size, DPIUtil.getDeviceZoom());
}

/**
* Auto-scale down float dimensions.
*/
public static float autoScaleDown(float size) {
return DPIUtil.scaleDown(size, DPIUtil.getDeviceZoom());
public static float pixelToPoint(float size) {
return DPIUtil.pixelToPoint(size, DPIUtil.getDeviceZoom());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2620,25 +2620,25 @@ static void fillGradientRectangle(GC gc, Device device,
fromRGB, toRGB, redBits, greenBits, blueBits);
Image image = new Image(device, band);
if ((band.width == 1) || (band.height == 1)) {
gc.drawImage(image, 0, 0, DPIUtil.scaleDown(band.width, zoom), DPIUtil.scaleDown(band.height, zoom),
DPIUtil.scaleDown(x, zoom), DPIUtil.scaleDown(y, zoom), DPIUtil.scaleDown(width, zoom),
DPIUtil.scaleDown(height, zoom));
gc.drawImage(image, 0, 0, DPIUtil.pixelToPoint(band.width, zoom), DPIUtil.pixelToPoint(band.height, zoom),
DPIUtil.pixelToPoint(x, zoom), DPIUtil.pixelToPoint(y, zoom), DPIUtil.pixelToPoint(width, zoom),
DPIUtil.pixelToPoint(height, zoom));
} else {
if (vertical) {
for (int dx = 0; dx < width; dx += band.width) {
int blitWidth = width - dx;
if (blitWidth > band.width) blitWidth = band.width;
gc.drawImage(image, 0, 0, DPIUtil.scaleDown(blitWidth, zoom), DPIUtil.scaleDown(band.height, zoom),
DPIUtil.scaleDown(dx + x, zoom), DPIUtil.scaleDown(y, zoom), DPIUtil.scaleDown(blitWidth, zoom),
DPIUtil.scaleDown(band.height, zoom));
gc.drawImage(image, 0, 0, DPIUtil.pixelToPoint(blitWidth, zoom), DPIUtil.pixelToPoint(band.height, zoom),
DPIUtil.pixelToPoint(dx + x, zoom), DPIUtil.pixelToPoint(y, zoom), DPIUtil.pixelToPoint(blitWidth, zoom),
DPIUtil.pixelToPoint(band.height, zoom));
}
} else {
for (int dy = 0; dy < height; dy += band.height) {
int blitHeight = height - dy;
if (blitHeight > band.height) blitHeight = band.height;
gc.drawImage(image, 0, 0, DPIUtil.scaleDown(band.width, zoom), DPIUtil.scaleDown(blitHeight, zoom),
DPIUtil.scaleDown(x, zoom), DPIUtil.scaleDown(dy + y, zoom), DPIUtil.scaleDown(band.width, zoom),
DPIUtil.scaleDown(blitHeight, zoom));
gc.drawImage(image, 0, 0, DPIUtil.pixelToPoint(band.width, zoom), DPIUtil.pixelToPoint(blitHeight, zoom),
DPIUtil.pixelToPoint(x, zoom), DPIUtil.pixelToPoint(dy + y, zoom), DPIUtil.pixelToPoint(band.width, zoom),
DPIUtil.pixelToPoint(blitHeight, zoom));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ public static Optional<AutoScaleMethod> forString(String s) {
}


public static int scaleDown(int size, int zoom) {
public static int pixelToPoint(int size, int zoom) {
if (zoom == 100 || size == SWT.DEFAULT) return size;
float scaleFactor = getScalingFactor (zoom);
return Math.round (size / scaleFactor);
}


public static float scaleDown(float size, int zoom) {
public static float pixelToPoint(float size, int zoom) {
if (zoom == 100 || size == SWT.DEFAULT) return size;
float scaleFactor = getScalingFactor (zoom);
return (size / scaleFactor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ public Image(Device device, Rectangle bounds) {
* @see #dispose()
*/
public Image(Device device, ImageData data) {
this(device, GtkDPIUtil.autoScaleUp(device, data), DPIUtil.getDeviceZoom());
this(device, GtkDPIUtil.pointToPixel(device, data), DPIUtil.getDeviceZoom());
}

private Image(Device device, ImageData data, int zoom) {
Expand Down Expand Up @@ -488,8 +488,8 @@ public Image(Device device, ImageData source, ImageData mask) {
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
}
currentDeviceZoom = DPIUtil.getDeviceZoom();
source = GtkDPIUtil.autoScaleUp (device, source);
mask = GtkDPIUtil.autoScaleUp (device, mask);
source = GtkDPIUtil.pointToPixel (device, source);
mask = GtkDPIUtil.pointToPixel (device, mask);
mask = ImageData.convertMask (mask);
ImageData image = new ImageData(source.width, source.height, source.depth, source.palette, source.scanlinePad, source.data);
image.maskPad = mask.scanlinePad;
Expand Down Expand Up @@ -1597,7 +1597,7 @@ private final class GtkDPIUtil {
/**
* Auto-scale up ImageData to device zoom that is at 100%.
*/
public static ImageData autoScaleUp (Device device, final ImageData imageData) {
public static ImageData pointToPixel (Device device, final ImageData imageData) {
int imageDataZoomFactor = 100;
if (DPIUtil.getDeviceZoom() == imageDataZoomFactor || imageData == null || (device != null && !device.isAutoScalable())) return imageData;
float scaleFactor = (float) DPIUtil.getDeviceZoom() / imageDataZoomFactor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ long EnumFontFamProc (long lpelfe, long lpntme, long FontType, long lParam) {
*/
public Rectangle getBounds() {
checkDevice ();
return Win32DPIUtils.scaleDown(getBoundsInPixels(), getDeviceZoom());
return Win32DPIUtils.pixelToPoint(getBoundsInPixels(), getDeviceZoom());
}

private Rectangle getBoundsInPixels () {
Expand Down Expand Up @@ -527,7 +527,7 @@ public Point getDPI () {
int dpiX = OS.GetDeviceCaps (hDC, OS.LOGPIXELSX);
int dpiY = OS.GetDeviceCaps (hDC, OS.LOGPIXELSY);
internal_dispose_GC (hDC, null);
return Win32DPIUtils.scaleDown(new Point (dpiX, dpiY), DPIUtil.getZoomForAutoscaleProperty(getDeviceZoom()));
return Win32DPIUtils.pixelToPoint(new Point (dpiX, dpiY), DPIUtil.getZoomForAutoscaleProperty(getDeviceZoom()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public boolean equals (Object object) {
* @return the ascent of the font
*/
public int getAscent() {
return DPIUtil.scaleDown(handle.tmAscent - handle.tmInternalLeading, getZoom());
return DPIUtil.pixelToPoint(handle.tmAscent - handle.tmInternalLeading, getZoom());
}

/**
Expand All @@ -120,7 +120,7 @@ public double getAverageCharacterWidth() {
*/
@Deprecated
public int getAverageCharWidth() {
return DPIUtil.scaleDown(handle.tmAveCharWidth, getZoom());
return DPIUtil.pixelToPoint(handle.tmAveCharWidth, getZoom());
}

/**
Expand All @@ -132,7 +132,7 @@ public int getAverageCharWidth() {
* @return the descent of the font
*/
public int getDescent() {
return DPIUtil.scaleDown(handle.tmDescent, getZoom());
return DPIUtil.pixelToPoint(handle.tmDescent, getZoom());
}

/**
Expand All @@ -147,7 +147,7 @@ public int getDescent() {
* @see #getLeading
*/
public int getHeight() {
return DPIUtil.scaleDown(handle.tmHeight, getZoom());
return DPIUtil.pixelToPoint(handle.tmHeight, getZoom());
}

/**
Expand Down
Loading
Loading