From 25fd535a11803c74a4fb63c627bee6f771d83480 Mon Sep 17 00:00:00 2001
From: Glenn Burkhardt <gbburkhardt@gmail.com>
Date: Sun, 4 Jun 2023 15:50:56 -0400
Subject: Use DPI scaling to scale drawn fonts.

---
 .../classes/com/jogamp/opengl/util/awt/TextRenderer.java  | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

(limited to 'src/jogl/classes/com/jogamp/opengl')

diff --git a/src/jogl/classes/com/jogamp/opengl/util/awt/TextRenderer.java b/src/jogl/classes/com/jogamp/opengl/util/awt/TextRenderer.java
index 0fc36a249..06671c0c7 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/awt/TextRenderer.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/awt/TextRenderer.java
@@ -42,6 +42,8 @@ package com.jogamp.opengl.util.awt;
 import com.jogamp.common.nio.Buffers;
 import com.jogamp.common.util.InterruptSource;
 import com.jogamp.common.util.PropertyAccess;
+import com.jogamp.nativewindow.NativeSurface;
+import com.jogamp.nativewindow.ScalableSurface;
 import com.jogamp.opengl.util.*;
 import com.jogamp.opengl.util.packrect.*;
 import com.jogamp.opengl.util.texture.*;
@@ -291,7 +293,18 @@ public class TextRenderer {
     public TextRenderer(final Font font, final boolean antialiased,
                         final boolean useFractionalMetrics, RenderDelegate renderDelegate,
                         final boolean mipmap) {
-        this.font = font;
+       
+    	NativeSurface surface = GLContext.getCurrent().getGLDrawable().getNativeSurface();
+        if (surface instanceof ScalableSurface) {
+        	// DPI scaling for surface
+        	float[] surfaceScale = new float[2];
+        	((ScalableSurface) surface).getCurrentSurfaceScale(surfaceScale);
+        	float newSize = font.getSize() * surfaceScale[0];
+        	this.font = font.deriveFont(newSize);
+        } else {
+        	this.font = font;
+        }
+
         this.antialiased = antialiased;
         this.useFractionalMetrics = useFractionalMetrics;
         this.mipmap = mipmap;
-- 
cgit v1.2.3