Package org.eclipse.swt.internal

# Class DPIUtil

java.lang.Object
org.eclipse.swt.internal.DPIUtil

public class DPIUtil extends Object
This class hold common constants and utility functions w.r.t. to SWT high DPI functionality.

The `autoScaleUp(..)` methods convert from API coordinates (in SWT points) to internal high DPI coordinates (in pixels) that interface with native widgets.

The `autoScaleDown(..)` convert from high DPI pixels to API coordinates (in SWT points).

Since:
  3.105

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`static final class`
`DPIUtil.AutoScaleImageDataProvider`
AutoScale ImageDataProvider.
`static final record`
`DPIUtil.ElementAtZoom<T>`
Represents an element, such as some image data, at a specific zoom level.

## Constructor Summary

Constructors
Constructor
Description
`DPIUtil()`

## Method Summary

Modifier and Type
Method
Description
`static float`
`autoScaleDown(float size)`
Auto-scale down float dimensions.
`static float[]`
`autoScaleDown(float[] size)`
Auto-scale down float array dimensions.
`static int`
`autoScaleDown(int size)`
Auto-scale down int dimensions.
`static int[]`
`autoScaleDown(int[] pointArray)`
`static ImageData`
`autoScaleDown(Device device, ImageData imageData)`
Auto-scale down ImageData
`static float`
`autoScaleDown(Drawable drawable, float size)`
Auto-scale down float dimensions if enabled for Drawable class.
`static float[]`
`autoScaleDown(Drawable drawable, float[] size)`
Auto-scale down float array dimensions if enabled for Drawable class.
`static int`
`autoScaleDown(Drawable drawable, int size)`
Auto-scale down int dimensions if enabled for Drawable class.
`static int[]`
`autoScaleDown(Drawable drawable, int[] pointArray)`
`static Point`
`autoScaleDown(Drawable drawable, Point point)`
Returns a new scaled down Point if enabled for Drawable class.
`static Rectangle`
`autoScaleDown(Drawable drawable, Rectangle rect)`
Returns a new scaled down Rectangle if enabled for Drawable class.
`static Point`
`autoScaleDown(Point point)`
Returns a new scaled down Point.
`static Rectangle`
`autoScaleDown(Rectangle rect)`
Returns a new scaled down Rectangle.
`static ImageData`
`autoScaleImageData(Device device, ImageData imageData, int imageDataZoomFactor)`
Auto-scale ImageData to device zoom that are at given zoom factor.
`static float`
`autoScaleUp(float size)`
`static int`
`autoScaleUp(int size)`
Auto-scale up int dimensions.
`static int[]`
`autoScaleUp(int[] pointArray)`
`static ImageData`
`autoScaleUp(Device device, ImageData imageData)`
Auto-scale up ImageData to device zoom that is at 100%.
`static ImageData`
`autoScaleUp(Device device, DPIUtil.ElementAtZoom<ImageData> elementAtZoom)`
`static float`
`autoScaleUp(Drawable drawable, float size)`
`static int`
`autoScaleUp(Drawable drawable, int size)`
Auto-scale up int dimensions if enabled for Drawable class.
`static int[]`
`autoScaleUp(Drawable drawable, int[] pointArray)`
`static Point`
`autoScaleUp(Drawable drawable, Point point)`
Returns a new scaled up Point if enabled for Drawable class.
`static Rectangle`
`autoScaleUp(Drawable drawable, Rectangle rect)`
Returns a new scaled up Rectangle if enabled for Drawable class.
`static Point`
`autoScaleUp(Point point)`
Returns a new scaled up Point.
`static Rectangle`
`autoScaleUp(Rectangle rect)`
Returns a new scaled up Rectangle.
`static int`
`getDeviceZoom()`
`static int`
`getNativeDeviceZoom()`
`static int`
`getZoomForAutoscaleProperty(int nativeDeviceZoom)`
`static boolean`
`isAutoScaleOnRuntimeActive()`
`static int`
`mapDPIToZoom(int dpi)`
Compute the zoom value based on the DPI value.
`static int`
`mapZoomToDPI(int zoom)`
Compute the DPI value value based on the zoom.
`static Rectangle`
`scaleBounds(Rectangle rect, int targetZoom, int currentZoom)`
Returns a new rectangle as per the scaleFactor.
`static float[]`
`scaleDown(float[] size, int zoom)`
`static float`
`scaleDown(float size, int zoom)`
`static int`
`scaleDown(int size, int zoom)`
`static float[]`
`scaleDown(Drawable drawable, float[] size, int zoom)`
`static float`
`scaleDown(Drawable drawable, float size, int zoom)`
`static int`
`scaleDown(Drawable drawable, int size, int zoom)`
`static Point`
`scaleDown(Drawable drawable, Point point, int zoom)`
`static Rectangle`
`scaleDown(Drawable drawable, Rectangle rect, int zoom)`
`static Point`
`scaleDown(Point point, int zoom)`
`static Rectangle`
`scaleDown(Rectangle rect, int zoom)`
`static ImageData`
`scaleImageData(Device device, ImageData imageData, int targetZoom, int currentZoom)`
Auto-scale image with ImageData
`static ImageData`
`scaleImageData(Device device, DPIUtil.ElementAtZoom<ImageData> elementAtZoom, int targetZoom)`
`static float`
`scaleUp(float size, int zoom)`
`static int[]`
`scaleUp(int[] pointArray, int zoom)`
`static int`
`scaleUp(int size, int zoom)`
Auto-scale up int dimensions to match the given zoom level
`static float`
`scaleUp(Drawable drawable, float size, int zoom)`
`static int[]`
`scaleUp(Drawable drawable, int[] pointArray, int zoom)`
`static int`
`scaleUp(Drawable drawable, int size, int zoom)`
`static Point`
`scaleUp(Drawable drawable, Point point, int zoom)`
`static Rectangle`
`scaleUp(Drawable drawable, Rectangle rect, int zoom)`
`static Point`
`scaleUp(Point point, int zoom)`
`static Rectangle`
`scaleUp(Rectangle rect, int zoom)`
`static void`
`setDeviceZoom(int nativeDeviceZoom)`
`static void`
`setUseCairoAutoScale(boolean cairoAutoScale)`
`static boolean`
`useCairoAutoScale()`
`static DPIUtil.ElementAtZoom<ImageData>`
`validateAndGetImageDataAtZoom(ImageDataProvider provider, int zoom)`
Gets ImageData that are appropriate for the specified zoom level together with the zoom level at which the image data are.
`static DPIUtil.ElementAtZoom<String>`
`validateAndGetImagePathAtZoom(ImageFileNameProvider provider, int zoom)`
Gets the image file path that are appropriate for the specified zoom level together with the zoom level at which the image data are.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### DPIUtil

public DPIUtil()

## Method Details

### autoScaleDown

public static ImageData autoScaleDown(Device device, ImageData imageData)
Auto-scale down ImageData

### autoScaleDown

public static int[] autoScaleDown(int[] pointArray)

### autoScaleDown

public static int[] autoScaleDown(Drawable drawable, int[] pointArray)

### autoScaleDown

public static float[] autoScaleDown(float[] size)
Auto-scale down float array dimensions.

### scaleDown

public static float[] scaleDown(float[] size, int zoom)

### autoScaleDown

public static float[] autoScaleDown(Drawable drawable, float[] size)
Auto-scale down float array dimensions if enabled for Drawable class.

### scaleDown

public static float[] scaleDown(Drawable drawable, float[] size, int zoom)

### autoScaleDown

public static int autoScaleDown(int size)
Auto-scale down int dimensions.

### scaleDown

public static int scaleDown(int size, int zoom)

### autoScaleDown

public static int autoScaleDown(Drawable drawable, int size)
Auto-scale down int dimensions if enabled for Drawable class.

### scaleDown

public static int scaleDown(Drawable drawable, int size, int zoom)

### autoScaleDown

public static float autoScaleDown(float size)
Auto-scale down float dimensions.

### scaleDown

public static float scaleDown(float size, int zoom)

### autoScaleDown

public static float autoScaleDown(Drawable drawable, float size)
Auto-scale down float dimensions if enabled for Drawable class.

### scaleDown

public static float scaleDown(Drawable drawable, float size, int zoom)

### autoScaleDown

public static Point autoScaleDown(Point point)
Returns a new scaled down Point.

### scaleDown

public static Point scaleDown(Point point, int zoom)

### autoScaleDown

public static Point autoScaleDown(Drawable drawable, Point point)
Returns a new scaled down Point if enabled for Drawable class.

### scaleDown

public static Point scaleDown(Drawable drawable, Point point, int zoom)

### autoScaleDown

public static Rectangle autoScaleDown(Rectangle rect)
Returns a new scaled down Rectangle.

### scaleDown

public static Rectangle scaleDown(Rectangle rect, int zoom)

### autoScaleDown

public static Rectangle autoScaleDown(Drawable drawable, Rectangle rect)
Returns a new scaled down Rectangle if enabled for Drawable class.

### scaleDown

public static Rectangle scaleDown(Drawable drawable, Rectangle rect, int zoom)

### scaleImageData

public static ImageData scaleImageData(Device device, ImageData imageData, int targetZoom, int currentZoom)
Auto-scale image with ImageData

### scaleImageData

public static ImageData scaleImageData(Device device, DPIUtil.ElementAtZoom<ImageData> elementAtZoom, int targetZoom)

### scaleBounds

public static Rectangle scaleBounds(Rectangle rect, int targetZoom, int currentZoom)
Returns a new rectangle as per the scaleFactor.

### autoScaleImageData

public static ImageData autoScaleImageData(Device device, ImageData imageData, int imageDataZoomFactor)
Auto-scale ImageData to device zoom that are at given zoom factor.

### autoScaleUp

public static ImageData autoScaleUp(Device device, ImageData imageData)
Auto-scale up ImageData to device zoom that is at 100%.

### autoScaleUp

public static ImageData autoScaleUp(Device device, DPIUtil.ElementAtZoom<ImageData> elementAtZoom)

### autoScaleUp

public static int[] autoScaleUp(int[] pointArray)

### scaleUp

public static int[] scaleUp(int[] pointArray, int zoom)

### autoScaleUp

public static int[] autoScaleUp(Drawable drawable, int[] pointArray)

### scaleUp

public static int[] scaleUp(Drawable drawable, int[] pointArray, int zoom)

### autoScaleUp

public static int autoScaleUp(int size)
Auto-scale up int dimensions.

### scaleUp

public static int scaleUp(int size, int zoom)
Auto-scale up int dimensions to match the given zoom level

### autoScaleUp

public static int autoScaleUp(Drawable drawable, int size)
Auto-scale up int dimensions if enabled for Drawable class.

### scaleUp

public static int scaleUp(Drawable drawable, int size, int zoom)

### autoScaleUp

public static float autoScaleUp(float size)

### scaleUp

public static float scaleUp(float size, int zoom)

### autoScaleUp

public static float autoScaleUp(Drawable drawable, float size)

### scaleUp

public static float scaleUp(Drawable drawable, float size, int zoom)

### autoScaleUp

public static Point autoScaleUp(Point point)
Returns a new scaled up Point.

### scaleUp

public static Point scaleUp(Point point, int zoom)

### autoScaleUp

public static Point autoScaleUp(Drawable drawable, Point point)
Returns a new scaled up Point if enabled for Drawable class.

### scaleUp

public static Point scaleUp(Drawable drawable, Point point, int zoom)

### autoScaleUp

public static Rectangle autoScaleUp(Rectangle rect)
Returns a new scaled up Rectangle.

### scaleUp

public static Rectangle scaleUp(Rectangle rect, int zoom)

### autoScaleUp

public static Rectangle autoScaleUp(Drawable drawable, Rectangle rect)
Returns a new scaled up Rectangle if enabled for Drawable class.

### scaleUp

public static Rectangle scaleUp(Drawable drawable, Rectangle rect, int zoom)

### mapDPIToZoom

public static int mapDPIToZoom(int dpi)
Compute the zoom value based on the DPI value.

Returns:
  zoom

### mapZoomToDPI

public static int mapZoomToDPI(int zoom)
Compute the DPI value value based on the zoom.

Returns:
  DPI

### validateAndGetImageDataAtZoom

public static DPIUtil.ElementAtZoom<ImageData> validateAndGetImageDataAtZoom(ImageDataProvider provider, int zoom)
Gets ImageData that are appropriate for the specified zoom level together with the zoom level at which the image data are. If there is an image at the specified zoom level, it is returned. Otherwise the next larger image at 150% and 200% is returned, if existing. If none of these is found, the 100% image is returned as a fallback. If provider or fallback image is not available, an error is thrown.

### validateAndGetImagePathAtZoom

public static DPIUtil.ElementAtZoom<String> validateAndGetImagePathAtZoom(ImageFileNameProvider provider, int zoom)
Gets the image file path that are appropriate for the specified zoom level together with the zoom level at which the image data are. If there is an image at the specified zoom level, it is returned. Otherwise the next larger image at 150% and 200% is returned, if existing. If none of these is found, the 100% image is returned as a fallback. If provider or fallback image is not available, an error is thrown.

### getNativeDeviceZoom

public static int getNativeDeviceZoom()

### getDeviceZoom

public static int getDeviceZoom()

### setDeviceZoom

public static void setDeviceZoom(int nativeDeviceZoom)

### setUseCairoAutoScale

public static void setUseCairoAutoScale(boolean cairoAutoScale)

### useCairoAutoScale

public static boolean useCairoAutoScale()

### getZoomForAutoscaleProperty

public static int getZoomForAutoscaleProperty(int nativeDeviceZoom)

### isAutoScaleOnRuntimeActive

public static boolean isAutoScaleOnRuntimeActive()