Skip to content

Refactor: Move GTK-specific DPI logic to GtkDPIUtil #2280

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 4, 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 @@ -284,7 +284,7 @@ public static ImageData scaleImageData (Device device, final ElementAtZoom<Image
return scaleImageData(device, elementAtZoom.element(), targetZoom, elementAtZoom.zoom());
}

private static ImageData autoScaleImageData (Device device, final ImageData imageData, float scaleFactor) {
public static ImageData autoScaleImageData (Device device, final ImageData imageData, float scaleFactor) {
// Guards are already implemented in callers: if (deviceZoom == 100 || imageData == null || scaleFactor == 1.0f) return imageData;
int width = imageData.width;
int height = imageData.height;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ void checkGC (int mask) {
Cairo.cairo_set_line_join(cairo, join_style);
}
if ((state & LINE_WIDTH) != 0) {
Cairo.cairo_set_line_width(cairo, data.lineWidth == 0 ? DPIUtil.autoScaleUp(drawable, 1) : data.lineWidth);
Cairo.cairo_set_line_width(cairo, data.lineWidth == 0 ? 1 : data.lineWidth);
switch (data.lineStyle) {
case SWT.LINE_DOT:
case SWT.LINE_DASH:
Expand Down Expand Up @@ -467,7 +467,7 @@ public void copyArea(Image image, int x, int y) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
if (image.type != SWT.BITMAP || image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
Point loc = DPIUtil.autoScaleUp(drawable, new Point(x, y));
Point loc = new Point(x, y);
copyAreaInPixels(image, loc.x, loc.y);
}
void copyAreaInPixels(Image image, int x, int y) {
Expand Down Expand Up @@ -507,8 +507,8 @@ void copyAreaInPixels(Image image, int x, int y) {
*/
public void copyArea(int srcX, int srcY, int width, int height, int destX, int destY) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
Rectangle src = DPIUtil.autoScaleUp(drawable, new Rectangle(srcX, srcY, width, height));
Point dest = DPIUtil.autoScaleUp(drawable, new Point(destX, destY));
Rectangle src = new Rectangle(srcX, srcY, width, height);
Point dest = new Point(destX, destY);
copyAreaInPixels(src.x, src.y, src.width, src.height, dest.x, dest.y);
}

Expand All @@ -535,8 +535,8 @@ void copyAreaInPixels(int srcX, int srcY, int width, int height, int destX, int
*/
public void copyArea(int srcX, int srcY, int width, int height, int destX, int destY, boolean paint) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
Rectangle srcLoc = DPIUtil.autoScaleUp(drawable, new Rectangle(srcX, srcY, width, height));
Point destLoc = DPIUtil.autoScaleUp(drawable, new Point(destX, destY));
Rectangle srcLoc = new Rectangle(srcX, srcY, width, height);
Point destLoc = new Point(destX, destY);
copyAreaInPixels(srcLoc.x, srcLoc.y, srcLoc.width, srcLoc.height, destLoc.x, destLoc.y, paint);
}
void copyAreaInPixels(int srcX, int srcY, int width, int height, int destX, int destY, boolean paint) {
Expand Down Expand Up @@ -726,7 +726,7 @@ void destroy() {
*/
public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
Rectangle loc = DPIUtil.autoScaleUp(drawable, new Rectangle(x, y, width, height));
Rectangle loc = new Rectangle(x, y, width, height);
drawArcInPixels(loc.x, loc.y, loc.width, loc.height, startAngle, arcAngle);
}
void drawArcInPixels(int x, int y, int width, int height, int startAngle, int arcAngle) {
Expand Down Expand Up @@ -781,7 +781,7 @@ void drawArcInPixels(int x, int y, int width, int height, int startAngle, int ar
*/
public void drawFocus(int x, int y, int width, int height) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
Rectangle loc = DPIUtil.autoScaleUp(drawable, new Rectangle(x, y, width, height));
Rectangle loc = new Rectangle(x, y, width, height);
drawFocusInPixels(loc.x, loc.y, loc.width, loc.height);
}
void drawFocusInPixels(int x, int y, int width, int height) {
Expand Down Expand Up @@ -814,7 +814,7 @@ public void drawImage(Image image, int x, int y) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
if (image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
Point loc = DPIUtil.autoScaleUp(drawable, new Point(x, y));
Point loc = new Point(x, y);
drawImageInPixels(image, loc.x, loc.y);
}
void drawImageInPixels(Image image, int x, int y) {
Expand Down Expand Up @@ -861,7 +861,7 @@ public void drawImage(Image image, int srcX, int srcY, int srcWidth, int srcHeig
}
if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
if (image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
Rectangle destRect = DPIUtil.autoScaleUp(drawable, new Rectangle(destX, destY, destWidth, destHeight));
Rectangle destRect = new Rectangle(destX, destY, destWidth, destHeight);
drawImage(image, srcX, srcY, srcWidth, srcHeight, destRect.x, destRect.y, destRect.width, destRect.height, false);
}
void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple) {
Expand Down Expand Up @@ -939,8 +939,8 @@ void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight,
*/
public void drawLine(int x1, int y1, int x2, int y2) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
Point loc1 = DPIUtil.autoScaleUp(drawable, new Point(x1, y1));
Point loc2 = DPIUtil.autoScaleUp(drawable, new Point(x2, y2));
Point loc1 = new Point(x1, y1);
Point loc2 = new Point(x2, y2);
drawLineInPixels(loc1.x, loc1.y, loc2.x, loc2.y);
}
void drawLineInPixels(int x1, int y1, int x2, int y2) {
Expand Down Expand Up @@ -978,7 +978,7 @@ void drawLineInPixels(int x1, int y1, int x2, int y2) {
*/
public void drawOval(int x, int y, int width, int height) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
Rectangle rect = DPIUtil.autoScaleUp(drawable, new Rectangle(x, y, width, height));
Rectangle rect = new Rectangle(x, y, width, height);
drawOvalInPixels(rect.x, rect.y, rect.width, rect.height);
}
void drawOvalInPixels(int x, int y, int width, int height) {
Expand Down Expand Up @@ -1065,7 +1065,7 @@ public void drawPath(Path path) {
*/
public void drawPoint (int x, int y) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
Point loc = DPIUtil.autoScaleUp(drawable, new Point(x, y));
Point loc = new Point(x, y);
drawPointInPixels(loc.x, loc.y);
}
void drawPointInPixels (int x, int y) {
Expand Down Expand Up @@ -1095,7 +1095,7 @@ void drawPointInPixels (int x, int y) {
public void drawPolygon(int[] pointArray) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
int [] scaledPointArray = DPIUtil.autoScaleUp(drawable, pointArray);
int [] scaledPointArray = pointArray;
drawPolygonInPixels(scaledPointArray);
}
void drawPolygonInPixels(int[] pointArray) {
Expand Down Expand Up @@ -1125,7 +1125,7 @@ void drawPolygonInPixels(int[] pointArray) {
public void drawPolyline(int[] pointArray) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
int [] scaledPointArray = DPIUtil.autoScaleUp(drawable, pointArray);
int [] scaledPointArray = pointArray;
drawPolylineInPixels(scaledPointArray);
}
void drawPolylineInPixels(int[] pointArray) {
Expand Down Expand Up @@ -1199,7 +1199,7 @@ void drawRectangleInPixels(int x, int y, int width, int height) {
*/
public void drawRectangle(Rectangle rect) {
if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
drawRectangleInPixels(DPIUtil.autoScaleUp(drawable, rect));
drawRectangleInPixels(rect);
}
void drawRectangleInPixels(Rectangle rect) {
drawRectangleInPixels (rect.x, rect.y, rect.width, rect.height);
Expand Down Expand Up @@ -1227,8 +1227,8 @@ void drawRectangleInPixels(Rectangle rect) {
*/
public void drawRoundRectangle(int x, int y, int width, int height, int arcWidth, int arcHeight) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
Rectangle rect = DPIUtil.autoScaleUp(drawable, new Rectangle(x, y, width, height));
Point arcSize = DPIUtil.autoScaleUp(drawable, new Point(arcWidth, arcHeight));
Rectangle rect = new Rectangle(x, y, width, height);
Point arcSize = new Point(arcWidth, arcHeight);
drawRoundRectangleInPixels(rect.x, rect.y, rect.width, rect.height, arcSize.x, arcSize.y);
}
void drawRoundRectangleInPixels(int x, int y, int width, int height, int arcWidth, int arcHeight) {
Expand Down Expand Up @@ -1333,7 +1333,7 @@ void drawStringInPixels (String string, int x, int y) {
public void drawString(String string, int x, int y, boolean isTransparent) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
Point loc = DPIUtil.autoScaleUp(drawable, new Point(x, y));
Point loc = new Point(x, y);
drawStringInPixels(string, loc.x, loc.y, isTransparent);
}

Expand Down Expand Up @@ -1395,7 +1395,7 @@ void drawTextInPixels(String string, int x, int y) {
* </ul>
*/
public void drawText(String string, int x, int y, boolean isTransparent) {
Point loc = DPIUtil.autoScaleUp(drawable, new Point (x, y));
Point loc = new Point (x, y);
drawTextInPixels(string, loc.x, loc.y, isTransparent);
}
void drawTextInPixels(String string, int x, int y, boolean isTransparent) {
Expand Down Expand Up @@ -1444,7 +1444,7 @@ void drawTextInPixels(String string, int x, int y, boolean isTransparent) {
* </ul>
*/
public void drawText (String string, int x, int y, int flags) {
Point loc = DPIUtil.autoScaleUp(drawable, new Point (x, y));
Point loc = new Point (x, y);
drawTextInPixels(string, loc.x, loc.y, flags);
}
void drawTextInPixels (String string, int x, int y, int flags) {
Expand Down Expand Up @@ -1530,7 +1530,7 @@ public boolean equals(Object object) {
*/
public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
Rectangle rect = DPIUtil.autoScaleUp(drawable, new Rectangle(x, y, width, height));
Rectangle rect = new Rectangle(x, y, width, height);
fillArcInPixels(rect.x, rect.y, rect.width, rect.height, startAngle, arcAngle);
}
void fillArcInPixels(int x, int y, int width, int height, int startAngle, int arcAngle) {
Expand Down Expand Up @@ -1589,7 +1589,7 @@ void fillArcInPixels(int x, int y, int width, int height, int startAngle, int ar
*/
public void fillGradientRectangle(int x, int y, int width, int height, boolean vertical) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
Rectangle rect = DPIUtil.autoScaleUp(drawable, new Rectangle(x, y, width, height));
Rectangle rect = new Rectangle(x, y, width, height);
fillGradientRectangleInPixels(rect.x, rect.y, rect.width, rect.height, vertical);
}

Expand Down Expand Up @@ -1673,7 +1673,7 @@ void fillGradientRectangleInPixels(int x, int y, int width, int height, boolean
*/
public void fillOval(int x, int y, int width, int height) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
Rectangle rect = DPIUtil.autoScaleUp(drawable, new Rectangle(x, y, width, height));
Rectangle rect = new Rectangle(x, y, width, height);
fillOvalInPixels(rect.x, rect.y, rect.width, rect.height);
}
void fillOvalInPixels(int x, int y, int width, int height) {
Expand Down Expand Up @@ -1758,7 +1758,7 @@ public void fillPath (Path path) {
public void fillPolygon(int[] pointArray) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
int [] scaledPointArray = DPIUtil.autoScaleUp(drawable, pointArray);
int [] scaledPointArray = pointArray;
fillPolygonInPixels(scaledPointArray);
}
void fillPolygonInPixels(int[] pointArray) {
Expand Down Expand Up @@ -1824,7 +1824,7 @@ void fillRectangleInPixels(int x, int y, int width, int height) {
public void fillRectangle(Rectangle rect) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
fillRectangleInPixels(DPIUtil.autoScaleUp(drawable, rect));
fillRectangleInPixels(rect);
}
void fillRectangleInPixels(Rectangle rect) {
fillRectangleInPixels(rect.x, rect.y, rect.width, rect.height);
Expand All @@ -1849,8 +1849,8 @@ void fillRectangleInPixels(Rectangle rect) {
*/
public void fillRoundRectangle(int x, int y, int width, int height, int arcWidth, int arcHeight) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
Rectangle rect = DPIUtil.autoScaleUp(drawable, new Rectangle(x, y, width, height));
Point arcSize = DPIUtil.autoScaleUp(drawable, new Point(arcWidth, arcHeight));
Rectangle rect = new Rectangle(x, y, width, height);
Point arcSize = new Point(arcWidth, arcHeight);
fillRoundRectangleInPixels(rect.x, rect.y, rect.width, rect.height, arcSize.x, arcSize.y);
}
void fillRoundRectangleInPixels(int x, int y, int width, int height, int arcWidth, int arcHeight) {
Expand Down Expand Up @@ -2074,7 +2074,7 @@ public int getCharWidth(char ch) {
*/
public Rectangle getClipping() {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
return DPIUtil.autoScaleDown(drawable, getClippingInPixels());
return getClippingInPixels();
}
Rectangle getClippingInPixels() {
/* Calculate visible bounds in device space */
Expand Down Expand Up @@ -2251,11 +2251,11 @@ public FontMetrics getFontMetrics() {
FontMetrics fm = new FontMetrics();
int ascent = OS.pango_font_metrics_get_ascent(metrics);
int descent = OS.pango_font_metrics_get_descent(metrics);
int ascentInPoints = DPIUtil.autoScaleDown(drawable, OS.PANGO_PIXELS(ascent));
int ascentInPoints = OS.PANGO_PIXELS(ascent);
fm.ascentInPoints = ascentInPoints;
int heightInPoints = DPIUtil.autoScaleDown(drawable, OS.PANGO_PIXELS(ascent + descent));
int heightInPoints = OS.PANGO_PIXELS(ascent + descent);
fm.descentInPoints = heightInPoints - ascentInPoints;
fm.averageCharWidthInPoints = DPIUtil.autoScaleDown(drawable, OS.PANGO_PIXELS(OS.pango_font_metrics_get_approximate_char_width(metrics)));
fm.averageCharWidthInPoints = OS.PANGO_PIXELS(OS.pango_font_metrics_get_approximate_char_width(metrics));
OS.pango_font_metrics_unref(metrics);
return fm;
}
Expand Down Expand Up @@ -2352,7 +2352,7 @@ public int getInterpolation() {
public LineAttributes getLineAttributes() {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
LineAttributes attributes = getLineAttributesInPixels();
attributes.width = DPIUtil.autoScaleDown(drawable, attributes.width);
attributes.width = attributes.width;
return attributes;
}
LineAttributes getLineAttributesInPixels() {
Expand Down Expand Up @@ -2453,7 +2453,7 @@ public int getLineStyle() {
*/
public int getLineWidth() {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
return (int)DPIUtil.autoScaleDown(drawable, data.lineWidth);
return getLineWidthInPixels();
}
int getLineWidthInPixels() {
return (int)data.lineWidth;
Expand Down Expand Up @@ -3112,7 +3112,7 @@ void setClipping(long clipRgn) {
*/
public void setClipping(int x, int y, int width, int height) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
setClippingInPixels(DPIUtil.autoScaleUp(drawable, x), DPIUtil.autoScaleUp(drawable, y), DPIUtil.autoScaleUp(drawable, width), DPIUtil.autoScaleUp(drawable, height));
setClippingInPixels(x, y, width, height);
}
void setClippingInPixels(int x, int y, int width, int height) {
if (width < 0) {
Expand Down Expand Up @@ -3190,7 +3190,7 @@ public void setClipping(Path path) {
*/
public void setClipping(Rectangle rect) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
setClippingInPixels(DPIUtil.autoScaleUp(drawable, rect));
setClippingInPixels(rect);
}
void setClippingInPixels(Rectangle rect) {
if (rect == null) {
Expand Down Expand Up @@ -3415,7 +3415,7 @@ public void setInterpolation(int interpolation) {
public void setLineAttributes(LineAttributes attributes) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (attributes == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
attributes.width = DPIUtil.autoScaleUp(drawable, attributes.width);
attributes.width = attributes.width;
setLineAttributesInPixels(attributes);
}
void setLineAttributesInPixels(LineAttributes attributes) {
Expand Down Expand Up @@ -3669,7 +3669,7 @@ public void setLineStyle(int lineStyle) {
*/
public void setLineWidth(int lineWidth) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
setLineWidthInPixels(DPIUtil.autoScaleUp(drawable, lineWidth));
setLineWidthInPixels(lineWidth);
}
void setLineWidthInPixels(int lineWidth) {
if (data.lineWidth == lineWidth) return;
Expand Down Expand Up @@ -3853,7 +3853,7 @@ public void setXORMode(boolean xor) {
* </ul>
*/
public Point stringExtent(String string) {
return DPIUtil.autoScaleDown(drawable, stringExtentInPixels(string));
return stringExtentInPixels(string);
}
Point stringExtentInPixels(String string) {
return textExtentInPixels(string, 0);
Expand All @@ -3879,7 +3879,7 @@ Point stringExtentInPixels(String string) {
* </ul>
*/
public Point textExtent(String string) {
return DPIUtil.autoScaleDown(drawable, textExtentInPixels(string));
return textExtentInPixels(string);
}

Point textExtentInPixels(String string) {
Expand Down Expand Up @@ -3920,7 +3920,7 @@ Point textExtentInPixels(String string) {
public Point textExtent(String string, int flags) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
return DPIUtil.autoScaleDown(drawable, textExtentInPixels(string, flags));
return textExtentInPixels(string, flags);
}
Point textExtentInPixels(String string, int flags) {
setString(string, flags);
Expand Down
Loading
Loading