Class DPIUtil
- Since:
- 3.105
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static enumstatic final recordRepresents an element, such as some image data, at a specific zoom level.private static interface -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final DPIUtil.AutoScaleMethodprivate static DPIUtil.AutoScaleMethodprivate static AutoScaleCalculation.AutoScaleprivate static intprivate static final intprivate static intprivate static final StringSystem property that controls the autoScale functionality.private static final StringSystem 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 "smooth" on GTK when deviceZoom is an integer multiple of 100% and on Windows if monitor-specific scaling is enabled, and "nearest" otherwise..(package private) static final StringSystem property to enable to scale the application on runtime when a DPI change is detected. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ImageDataautoScaleImageData(Device device, ImageData imageData, float scaleFactor) static ImageDataautoScaleImageData(Device device, ImageData imageData, int imageDataZoomFactor) Auto-scale ImageData to device zoom that are at given zoom factor.static ImageDataautoScaleImageData(Device device, ImageData imageData, int targetWidth, int targetHeight) static intReturns the zoom of the UI and its controls according to SWT autoscaling settings.static Stringprivate static <T> DPIUtil.ElementAtZoom<T> getElementAtZoom(Function<Integer, T> elementForZoomProvider, int zoom) static intReturns the native zoom of the UI and its controls according to the adapted OS elements.static floatgetScalingFactor(int zoom) Returns scaling factor from the given device zoomstatic floatgetScalingFactor(int targetZoom, int currentZoom) static intgetZoomForAutoscaleProperty(int nativeDeviceZoom) static booleanstatic booleanprivate static booleanstatic booleanReturnstrueonly if the current setup is compatible with monitor-specific scaling.static booleanstatic intmapDPIToZoom(int dpi) Compute the zoom value based on the DPI value.static intmapZoomToDPI(int zoom) Compute the DPI value value based on the zoom.static doublepixelToPoint(double size, int zoom) static floatpixelToPoint(float size, int zoom) static intpixelToPoint(int size, int zoom) static intpointToPixel(int size, int zoom) static voidrunWithAutoScaleValue(String autoScaleValue, Runnable runnable) private static ImageDatascaleImage(Device device, ImageData imageData, DPIUtil.ImageDrawFunction drawFunction, int scaledWidth, int scaledHeight) static ImageDatascaleImageData(Device device, ImageData imageData, int targetZoom, int currentZoom) Auto-scale image with ImageDatastatic ImageDatascaleImageData(Device device, DPIUtil.ElementAtZoom<ImageData> elementAtZoom, int targetZoom) static voidsetDeviceZoom(int nativeDeviceZoom) static voidsetMonitorSpecificScaling(boolean activate) private static booleanprivate static voidstatic 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 voidvalidateLinearScaling(ImageDataProvider provider)
-
Field Details
-
DPI_ZOOM_100
private static final int DPI_ZOOM_100- See Also:
-
deviceZoom
private static int deviceZoom -
nativeDeviceZoom
private static int nativeDeviceZoom -
AUTO_SCALE_METHOD_SETTING
-
autoScaleMethod
-
autoScaleValue
-
SWT_AUTOSCALE_UPDATE_ON_RUNTIME
System property to enable to scale the application on runtime when a DPI change is detected.- "force": the application is scaled on DPI changes even if an unsupported
value for swt.autoScale are defined. See allowed values in
AutoScaleCalculation. - "true": the application is scaled on DPI changes
- "false": the application will remain in its initial scaling
- See Also:
- "force": the application is scaled on DPI changes even if an unsupported
value for swt.autoScale are defined. See allowed values in
-
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%).
- 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.
- See Also:
-
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
- See Also:
-
-
Constructor Details
-
DPIUtil
public DPIUtil()
-
-
Method Details
-
updateAutoScaleValue
private static void updateAutoScaleValue() -
isCustomAutoScale
public static boolean isCustomAutoScale() -
getEffectiveAutoScaleValue
-
isSetupCompatibleToMonitorSpecificScaling
public static boolean isSetupCompatibleToMonitorSpecificScaling()Returnstrueonly if the current setup is compatible with monitor-specific scaling. Returnsfalseif:- Not running on Windows
- The current auto-scale mode is incompatible
Background information: Monitor-specific scaling on Windows only supports auto-scale modes in which all elements (font, images, control bounds etc.) are scaled equally or almost equally. The previously default mode "integer", which rounded the scale factor for everything but fonts to multiples of 100, is complex and difficult to realize with monitor-specific rescaling of UI elements. Since a uniform scale factor for everything should perspectively be used anyway, there will be no support for complex auto-scale modes for monitor-specific scaling.
-
isMonitorSpecificScalingEnforced
private static boolean isMonitorSpecificScalingEnforced() -
setMonitorSpecificScaling
public static void setMonitorSpecificScaling(boolean activate) -
isMonitorSpecificScalingActive
public static boolean isMonitorSpecificScalingActive() -
pixelToPoint
public static int pixelToPoint(int size, int zoom) -
pixelToPoint
public static float pixelToPoint(float size, int zoom) -
pixelToPoint
public static double pixelToPoint(double size, int zoom) -
scaleImageData
-
scaleImageData
public static ImageData scaleImageData(Device device, DPIUtil.ElementAtZoom<ImageData> elementAtZoom, int targetZoom) -
autoScaleImageData
-
scaleImage
private static ImageData scaleImage(Device device, ImageData imageData, DPIUtil.ImageDrawFunction drawFunction, int scaledWidth, int scaledHeight) -
autoScaleImageData
-
isSmoothScalingEnabled
public static boolean isSmoothScalingEnabled() -
autoScaleImageData
-
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
-
pointToPixel
public static int pointToPixel(int size, int zoom) -
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. -
getElementAtZoom
private static <T> DPIUtil.ElementAtZoom<T> getElementAtZoom(Function<Integer, T> elementForZoomProvider, int zoom) -
getNativeDeviceZoom
public static int getNativeDeviceZoom()Returns the native zoom of the UI and its controls according to the adapted OS elements. Particularly on Windows, this is the zoom used for fonts by the OS, no matter what autoscaling of SWT might be applied on top.Warning: When using monitor-specific scaling on Windows, this value may not be reasonable as there is no single zoom for the application but one per shell and its monitor. In that case, this method will return the native zoom for the shell whose zoom has last been changed (via moving the shell to another monitor or changing the zoom of a monitor).
-
getDeviceZoom
public static int getDeviceZoom()Returns the zoom of the UI and its controls according to SWT autoscaling settings. It is an adapted value ofgetNativeDeviceZoom()based on the setting of theswt.autoScaleproperty.Warning: When using monitor-specific scaling on Windows, this value may not be reasonable as there is no single zoom for the application but one per shell and its monitor. In that case, this method will return the autoscaling zoom for the shell whose zoom has last been changed (via moving the shell to another monitor or changing the zoom of a monitor).
-
setDeviceZoom
public static void setDeviceZoom(int nativeDeviceZoom) -
shouldUseSmoothScaling
private static boolean shouldUseSmoothScaling() -
getZoomForAutoscaleProperty
public static int getZoomForAutoscaleProperty(int nativeDeviceZoom) -
runWithAutoScaleValue
-