Top Description Inners Fields Constructors Methods
org.eclipse.swt.internal

public Class DPIUtil

extends Object
Class Inheritance
Imports
java.util.function.*, org.eclipse.swt.*, org.eclipse.swt.graphics.*

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 and Inner Type Summary

Modifier and TypeClass and Description
public static class
DPIUtil.AutoScaleImageDataProvider

AutoScale ImageDataProvider.

private static enum
public static record
DPIUtil.ElementAtZoom<
type of the element to be presented, e.g., ImageData
T
>

Represents an element, such as some image data, at a specific zoom level.

Field Summary

Modifier and TypeField and Description
private static DPIUtil.AutoScaleMethod
private static DPIUtil.AutoScaleMethod
private static String
private static int
private static final int
private static int
private static final String
SWT_AUTOSCALE

System property that controls the autoScale functionality.

private static final String
SWT_AUTOSCALE_METHOD

System property that controls the method for scaling images:

  • "nearest": nearest-neighbor interpolation, may look jagged
  • "smooth": smooth edges, may look blurry
private static boolean

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static Rectangle
autoScaleBounds(Rectangle rect, int targetZoom, int currentZoom)

Returns a new rectangle as per the scaleFactor.

public static ImageData
autoScaleDown(Device device, final ImageData imageData)

Auto-scale down ImageData

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

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

public static float[]
autoScaleDown(float[] size)

Auto-scale down float array dimensions.

public static float[]
autoScaleDown(Drawable drawable, float[] size)

Auto-scale down float array dimensions if enabled for Drawable class.

public static int
autoScaleDown(int size)

Auto-scale down int dimensions.

public static int
autoScaleDown(Drawable drawable, int size)

Auto-scale down int dimensions if enabled for Drawable class.

public static float
autoScaleDown(float size)

Auto-scale down float dimensions.

public static float
autoScaleDown(Drawable drawable, float size)

Auto-scale down float dimensions if enabled for Drawable class.

public static Point
autoScaleDown(Point point)

Returns a new scaled down Point.

public static Point
autoScaleDown(Drawable drawable, Point point)

Returns a new scaled down Point if enabled for Drawable class.

public static Rectangle
autoScaleDown(Rectangle rect)

Returns a new scaled down Rectangle.

public static Rectangle
autoScaleDown(Drawable drawable, Rectangle rect)

Returns a new scaled down Rectangle if enabled for Drawable class.

public static ImageData
autoScaleImageData(Device device, final ImageData imageData, int targetZoom, int currentZoom)

Auto-scale image with ImageData

private static ImageData
autoScaleImageData(Device device, final ImageData imageData, float scaleFactor)

public static ImageData
autoScaleImageData(Device device, final ImageData imageData, int imageDataZoomFactor)

Auto-scale ImageData to device zoom that are at given zoom factor.

public static ImageData
autoScaleUp(Device device, final ImageData imageData)

Auto-scale up ImageData to device zoom that is at 100%.

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

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

public static int
autoScaleUp(int size)

Auto-scale up int dimensions.

public static int
autoScaleUp(Drawable drawable, int size)

Auto-scale up int dimensions if enabled for Drawable class.

public static float
autoScaleUp(float size)

public static float
autoScaleUp(Drawable drawable, float size)

public static Point
autoScaleUp(Point point)

Returns a new scaled up Point.

public static Point
autoScaleUp(Drawable drawable, Point point)

Returns a new scaled up Point if enabled for Drawable class.

public static Rectangle
autoScaleUp(Rectangle rect)

Returns a new scaled up Rectangle.

public static Rectangle
autoScaleUp(Drawable drawable, Rectangle rect)

Returns a new scaled up Rectangle if enabled for Drawable class.

public static int
autoScaleUpUsingNativeDPI(int size)

Auto-scale up int dimensions using Native DPI

public static int
private static <T> DPIUtil.ElementAtZoom<T>
getElementAtZoom(Function<Integer, T> elementForZoomProvider, int zoom)

private static float

Returns:

float scaling factor
getScalingFactor
()

Returns Scaling factor from the display

public static int
getZoomForAutoscaleProperty(int nativeDeviceZoom)

public static int

Returns:

zoom
mapDPIToZoom
(int dpi)

Compute the zoom value based on the DPI value.

public static void
setDeviceZoom(int nativeDeviceZoom)

public static void
setUseCairoAutoScale(boolean cairoAutoScale)

public static boolean
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.

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.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

autoScaleMethodback to summary
private static DPIUtil.AutoScaleMethod autoScaleMethod
autoScaleMethodSettingback to summary
private static DPIUtil.AutoScaleMethod autoScaleMethodSetting
autoScaleValueback to summary
private static String autoScaleValue
deviceZoomback to summary
private static int deviceZoom
DPI_ZOOM_100back to summary
private static final int DPI_ZOOM_100
nativeDeviceZoomback to summary
private static int nativeDeviceZoom
SWT_AUTOSCALEback to summary
private static final String SWT_AUTOSCALE

System property that controls the autoScale functionality.

  • false: deviceZoom is set to 100%
  • integer: deviceZoom depends on the current display resolution, but only uses integer multiples of 100%. The detected native zoom is generally rounded down (e.g. at 150%, will use 100%), unless close to the next integer multiple (currently at 175%, will use 200%).
  • integer200: like integer, but the maximal zoom level is 200%.
  • half: deviceZoom depends on the current display resolution, but only uses integer multiples of 50%. The detected native zoom is rounded to the closest permissible value, with tie-breaker towards even.
  • quarter: deviceZoom depends on the current display resolution, but only uses integer multiples of 25%. The detected native zoom is rounded to the closest permissible value.
  • exact: deviceZoom uses the native zoom (with 1% as minimal step).
  • <value>: deviceZoom uses the given integer value in percent as zoom level.
The current default is "integer200".
SWT_AUTOSCALE_METHODback to summary
private static final String SWT_AUTOSCALE_METHOD

System property that controls the method for scaling images:

  • "nearest": nearest-neighbor interpolation, may look jagged
  • "smooth": smooth edges, may look blurry
The current default is to use "nearest", except on GTK when the deviceZoom is not an integer multiple of 100%. The smooth strategy currently doesn't work on Win32 and Cocoa, see bug 493455.
useCairoAutoScaleback to summary
private static boolean useCairoAutoScale

Constructor Detail

DPIUtilback to summary
public DPIUtil()

Method Detail

autoScaleBoundsback to summary
public static Rectangle autoScaleBounds(Rectangle rect, int targetZoom, int currentZoom)

Returns a new rectangle as per the scaleFactor.

autoScaleDownback to summary
public static ImageData autoScaleDown(Device device, final ImageData imageData)

Auto-scale down ImageData

autoScaleDownback to summary
public static int[] autoScaleDown(int[] pointArray)
autoScaleDownback to summary
public static int[] autoScaleDown(Drawable drawable, int[] pointArray)
autoScaleDownback to summary
public static float[] autoScaleDown(float[] size)

Auto-scale down float array dimensions.

autoScaleDownback to summary
public static float[] autoScaleDown(Drawable drawable, float[] size)

Auto-scale down float array dimensions if enabled for Drawable class.

autoScaleDownback to summary
public static int autoScaleDown(int size)

Auto-scale down int dimensions.

autoScaleDownback to summary
public static int autoScaleDown(Drawable drawable, int size)

Auto-scale down int dimensions if enabled for Drawable class.

autoScaleDownback to summary
public static float autoScaleDown(float size)

Auto-scale down float dimensions.

autoScaleDownback to summary
public static float autoScaleDown(Drawable drawable, float size)

Auto-scale down float dimensions if enabled for Drawable class.

autoScaleDownback to summary
public static Point autoScaleDown(Point point)

Returns a new scaled down Point.

autoScaleDownback to summary
public static Point autoScaleDown(Drawable drawable, Point point)

Returns a new scaled down Point if enabled for Drawable class.

autoScaleDownback to summary
public static Rectangle autoScaleDown(Rectangle rect)

Returns a new scaled down Rectangle.

autoScaleDownback to summary
public static Rectangle autoScaleDown(Drawable drawable, Rectangle rect)

Returns a new scaled down Rectangle if enabled for Drawable class.

autoScaleImageDataback to summary
public static ImageData autoScaleImageData(Device device, final ImageData imageData, int targetZoom, int currentZoom)

Auto-scale image with ImageData

autoScaleImageDataback to summary
private static ImageData autoScaleImageData(Device device, final ImageData imageData, float scaleFactor)
autoScaleImageDataback to summary
public static ImageData autoScaleImageData(Device device, final ImageData imageData, int imageDataZoomFactor)

Auto-scale ImageData to device zoom that are at given zoom factor.

autoScaleUpback to summary
public static ImageData autoScaleUp(Device device, final ImageData imageData)

Auto-scale up ImageData to device zoom that is at 100%.

autoScaleUpback to summary
public static int[] autoScaleUp(int[] pointArray)
autoScaleUpback to summary
public static int[] autoScaleUp(Drawable drawable, int[] pointArray)
autoScaleUpback to summary
public static int autoScaleUp(int size)

Auto-scale up int dimensions.

autoScaleUpback to summary
public static int autoScaleUp(Drawable drawable, int size)

Auto-scale up int dimensions if enabled for Drawable class.

autoScaleUpback to summary
public static float autoScaleUp(float size)
autoScaleUpback to summary
public static float autoScaleUp(Drawable drawable, float size)
autoScaleUpback to summary
public static Point autoScaleUp(Point point)

Returns a new scaled up Point.

autoScaleUpback to summary
public static Point autoScaleUp(Drawable drawable, Point point)

Returns a new scaled up Point if enabled for Drawable class.

autoScaleUpback to summary
public static Rectangle autoScaleUp(Rectangle rect)

Returns a new scaled up Rectangle.

autoScaleUpback to summary
public static Rectangle autoScaleUp(Drawable drawable, Rectangle rect)

Returns a new scaled up Rectangle if enabled for Drawable class.

autoScaleUpUsingNativeDPIback to summary
public static int autoScaleUpUsingNativeDPI(int size)

Auto-scale up int dimensions using Native DPI

getDeviceZoomback to summary
public static int getDeviceZoom()
getElementAtZoomback to summary
private static <T> DPIUtil.ElementAtZoom<T> getElementAtZoom(Function<Integer, T> elementForZoomProvider, int zoom)
getScalingFactorback to summary
private static float getScalingFactor()

Returns Scaling factor from the display

Returns:float

float scaling factor

getZoomForAutoscalePropertyback to summary
public static int getZoomForAutoscaleProperty(int nativeDeviceZoom)
mapDPIToZoomback to summary
public static int mapDPIToZoom(int dpi)

Compute the zoom value based on the DPI value.

Returns:int

zoom

setDeviceZoomback to summary
public static void setDeviceZoom(int nativeDeviceZoom)
setUseCairoAutoScaleback to summary
public static void setUseCairoAutoScale(boolean cairoAutoScale)
useCairoAutoScaleback to summary
public static boolean useCairoAutoScale()
validateAndGetImageDataAtZoomback to summary
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.

validateAndGetImagePathAtZoomback to summary
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.

org.eclipse.swt.internal back to summary

public final Class DPIUtil.AutoScaleImageDataProvider

extends Object
implements ImageDataProvider
Class Inheritance
All Implemented Interfaces
org.eclipse.swt.graphics.ImageDataProvider

AutoScale ImageDataProvider.

Field Summary

Modifier and TypeField and Description
pack-priv int
pack-priv Device
pack-priv ImageData

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public ImageData
getImageData(int
The zoom level in % of the standard resolution (which is 1 physical monitor pixel == 1 SWT logical point). Typically 100, 150, or 200.
zoom
)

Implements org.eclipse.swt.graphics.ImageDataProvider.getImageData.

Returns the image data for the given zoom level.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

currentZoomback to summary
pack-priv int currentZoom
deviceback to summary
pack-priv Device device
imageDataback to summary
pack-priv ImageData imageData

Constructor Detail

AutoScaleImageDataProviderback to summary
public AutoScaleImageDataProvider(Device device, ImageData data, int zoom)

Method Detail

getImageDataback to summary
public ImageData getImageData(int zoom)

Implements org.eclipse.swt.graphics.ImageDataProvider.getImageData.

Doc from org.eclipse.swt.graphics.ImageDataProvider.getImageData.

Returns the image data for the given zoom level.

If no image is available for a particular zoom level, this method should return null. For zoom == 100, returning null is not allowed, and SWT will throw an exception.

Parameters
zoom:int

The zoom level in % of the standard resolution (which is 1 physical monitor pixel == 1 SWT logical point). Typically 100, 150, or 200.

Returns:ImageData

the image data, or null if zoom != 100 and no image is available for the given zoom level.

Annotations
@Override
org.eclipse.swt.internal back to summary

private final Enum DPIUtil.AutoScaleMethod

extends Enum<DPIUtil.AutoScaleMethod>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final DPIUtil.AutoScaleMethod
public static final DPIUtil.AutoScaleMethod
public static final DPIUtil.AutoScaleMethod

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static DPIUtil.AutoScaleMethod
public static DPIUtil.AutoScaleMethod[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

AUTOback to summary
public static final DPIUtil.AutoScaleMethod AUTO
NEARESTback to summary
public static final DPIUtil.AutoScaleMethod NEAREST
SMOOTHback to summary
public static final DPIUtil.AutoScaleMethod SMOOTH

Constructor Detail

AutoScaleMethodback to summary
private AutoScaleMethod()

Method Detail

valueOfback to summary
public static DPIUtil.AutoScaleMethod valueOf(String name)
valuesback to summary
public static DPIUtil.AutoScaleMethod[] values()
org.eclipse.swt.internal back to summary

public final Record DPIUtil.ElementAtZoom<T>

extends Record
Class Inheritance
Record Components
element:T 
zoom:int 
Type Parameters
<T>
type of the element to be presented, e.g., ImageData

Represents an element, such as some image data, at a specific zoom level.

Field Summary

Modifier and TypeField and Description
private final T
element

Record Component accessed by element().

private final int
zoom

Record Component accessed by zoom().

Constructor Summary

AccessConstructor and Description
public
ElementAtZoom(T element, int zoom)

Method Summary

Modifier and TypeMethod and Description
public T
element()

Record Component getter of element.

public final boolean
equals(Object
the reference object with which to compare.
o
)

Implements abstract java.lang.Record.equals.

Indicates whether some other object is "equal to" this one.
public final int
hashCode()

Implements abstract java.lang.Record.hashCode.

Returns a hash code value for the record.
public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.
public int
zoom()

Record Component getter of zoom.

Field Detail

elementback to summary
private final T element

Record Component accessed by element().

zoomback to summary
private final int zoom

Record Component accessed by zoom().

Constructor Detail

ElementAtZoomback to summary
public ElementAtZoom(T element, int zoom)

Method Detail

elementback to summary
public T element()

Record Component getter of element.

equalsback to summary
public final boolean equals(Object o)

Implements abstract java.lang.Record.equals.

Doc from java.lang.Record.equals.

Indicates whether some other object is "equal to" this one. In addition to the general contract of Object.equals, record classes must further obey the invariant that when a record instance is "copied" by passing the result of the record component accessor methods to the canonical constructor, as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this record is equal to the argument; false otherwise.

hashCodeback to summary
public final int hashCode()

Implements abstract java.lang.Record.hashCode.

Doc from java.lang.Record.hashCode.

Returns a hash code value for the record. Obeys the general contract of Object.hashCode. For records, hashing behavior is constrained by the refined contract of Record.equals, so that any two records created from the same components must have the same hash code.

Returns:int

a hash code value for this record.

toStringback to summary
public final String toString()

Implements abstract java.lang.Record.toString.

Doc from java.lang.Record.toString.

Returns a string representation of the record. In accordance with the general contract of Object#toString(), the toString method returns a string that "textually represents" this record. The result should be a concise but informative representation that is easy for a person to read.

In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves.

Returns:String

a string representation of the object.

zoomback to summary
public int zoom()

Record Component getter of zoom.