Package com.formdev.flatlaf.util
Class HiDPIUtils
java.lang.Object
com.formdev.flatlaf.util.HiDPIUtils
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic float
When painting text on HiDPI screens and the JRE scales, then the text is painted too far down on some operating systems.private static float
correctionForScaleY
(Graphics2D g, float[] correction) static Graphics2D
Creates a graphics object and applies Y correction to string drawing methods.static void
drawStringUnderlineCharAtWithYCorrection
(JComponent c, Graphics2D g, String text, int underlinedIndex, int x, int y) Applies Y correction and draws the given string at the specified location underlining the specified character.static void
drawStringWithYCorrection
(JComponent c, Graphics2D g, String text, int x, int y) Applies Y correction and draws the given string at the specified location.private static float
private static double
normalize
(double value) static void
paintAtScale1x
(Graphics2D g, int x, int y, int width, int height, HiDPIUtils.Painter painter) Paint at system scale factor 1x to avoid rounding issues at 125%, 150% and 175% scaling.static void
paintAtScale1x
(Graphics2D g, JComponent c, HiDPIUtils.Painter painter) private static Rectangle2D.Double
scale
(double scaleX, double scaleY, double px, double py, int width, int height) Scales a rectangle in the same way as the JRE does in sun.java2d.pipe.PixelToParallelogramConverter.fillRectangle(), which is used by Graphics.fillRect().private static int
scaleFactor2index
(float scaleFactor) private static boolean
private static boolean
-
Field Details
-
useTextYCorrection
-
SCALE_FACTORS
private static final float[] SCALE_FACTORS -
CORRECTION_SEGOE_UI
private static final float[] CORRECTION_SEGOE_UI -
CORRECTION_TAHOMA
private static final float[] CORRECTION_TAHOMA -
CORRECTION_INTER
private static final float[] CORRECTION_INTER -
CORRECTION_OPEN_SANS
private static final float[] CORRECTION_OPEN_SANS -
useDebugScaleFactor
-
-
Constructor Details
-
HiDPIUtils
public HiDPIUtils()
-
-
Method Details
-
paintAtScale1x
-
paintAtScale1x
public static void paintAtScale1x(Graphics2D g, int x, int y, int width, int height, HiDPIUtils.Painter painter) Paint at system scale factor 1x to avoid rounding issues at 125%, 150% and 175% scaling.Scales the given Graphics2D down to 100% and invokes the given painter passing scaled x, y, width and height.
Uses the same scaling calculation as the JRE uses.
-
scale
private static Rectangle2D.Double scale(double scaleX, double scaleY, double px, double py, int width, int height) Scales a rectangle in the same way as the JRE does in sun.java2d.pipe.PixelToParallelogramConverter.fillRectangle(), which is used by Graphics.fillRect(). -
normalize
private static double normalize(double value) -
useTextYCorrection
private static boolean useTextYCorrection() -
computeTextYCorrection
When painting text on HiDPI screens and the JRE scales, then the text is painted too far down on some operating systems. The higher the system scale factor is, the more.This method computes a correction value for the Y position.
-
correctionForScaleY
-
scaleFactor2index
private static int scaleFactor2index(float scaleFactor) -
useDebugScaleFactor
private static boolean useDebugScaleFactor() -
getUserScaleFactor
private static float getUserScaleFactor() -
drawStringWithYCorrection
Applies Y correction and draws the given string at the specified location. The provided component is used to query text properties and anti-aliasing hints.Use this method instead of
Graphics.drawString(String, int, int)
for correct anti-aliasing.Replacement for
SwingUtilities2.drawString()
. -
drawStringUnderlineCharAtWithYCorrection
public static void drawStringUnderlineCharAtWithYCorrection(JComponent c, Graphics2D g, String text, int underlinedIndex, int x, int y) Applies Y correction and draws the given string at the specified location underlining the specified character. The provided component is used to query text properties and anti-aliasing hints.Replacement for
SwingUtilities2.drawStringUnderlineCharAt()
. -
createGraphicsTextYCorrection
Creates a graphics object and applies Y correction to string drawing methods. If no Y correction is necessary, the passed in graphics object is returned.
-