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 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 ImageData`
`autoScaleImageData(Device device, ImageData imageData, float scaleFactor)`
`static ImageData`
`autoScaleImageData(Device device, ImageData imageData, int imageDataZoomFactor)`
Auto-scale ImageData to device zoom that are at given zoom factor.
`static int`
`getDeviceZoom()`
`static int`
`getNativeDeviceZoom()`
`static float`
`getScalingFactor(int zoom)`
Returns scaling factor from the given device zoom
`static float`
`getScalingFactor(int targetZoom, int currentZoom)`
`static int`
`getZoomForAutoscaleProperty(int nativeDeviceZoom)`
`static boolean`
`isSmoothScalingEnabled()`
`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 float`
`pixelToPoint(float size, int zoom)`
`static int`
`pixelToPoint(int size, int zoom)`
`static void`
`runWithAutoScaleValue(String autoScaleValue, Runnable runnable)`
`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 void`
`setDeviceZoom(int nativeDeviceZoom)`
`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.
`static void`
`validateLinearScaling(ImageDataProvider provider)`

### 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

### pixelToPoint

public static int pixelToPoint(int size, int zoom)

### pixelToPoint

public static float pixelToPoint(float size, 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)

### autoScaleImageData

public static ImageData autoScaleImageData(Device device, ImageData imageData, float scaleFactor)

### isSmoothScalingEnabled

public static boolean isSmoothScalingEnabled()

### autoScaleImageData

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

### getScalingFactor

public static float getScalingFactor(int zoom)
Returns scaling factor from the given device zoom

Returns:
  float scaling factor

### getScalingFactor

public static float getScalingFactor(int targetZoom, int currentZoom)

### 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

### validateLinearScaling

public static void validateLinearScaling(ImageDataProvider provider)

### 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)

### getZoomForAutoscaleProperty

public static int getZoomForAutoscaleProperty(int nativeDeviceZoom)

### runWithAutoScaleValue

public static void runWithAutoScaleValue(String autoScaleValue, Runnable runnable)