diff --git a/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java b/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java
index adff79812..40354f9d2 100644
a
|
b
|
import org.openstreetmap.josm.gui.layer.imagery.ZoomToNativeLevelAction;
|
121 | 121 | import org.openstreetmap.josm.gui.progress.ProgressMonitor; |
122 | 122 | import org.openstreetmap.josm.gui.util.GuiHelper; |
123 | 123 | import org.openstreetmap.josm.tools.GBC; |
| 124 | import org.openstreetmap.josm.tools.HiDPISupport; |
124 | 125 | import org.openstreetmap.josm.tools.HttpClient; |
125 | 126 | import org.openstreetmap.josm.tools.Logging; |
126 | 127 | import org.openstreetmap.josm.tools.MemoryManager; |
127 | 128 | import org.openstreetmap.josm.tools.MemoryManager.MemoryHandle; |
128 | 129 | import org.openstreetmap.josm.tools.MemoryManager.NotEnoughMemoryException; |
129 | | import org.openstreetmap.josm.tools.PlatformManager; |
130 | 130 | import org.openstreetmap.josm.tools.Utils; |
131 | 131 | import org.openstreetmap.josm.tools.bugreport.BugReport; |
132 | 132 | |
… |
… |
implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeLi
|
168 | 168 | private final AttributionSupport attribution = new AttributionSupport(); |
169 | 169 | |
170 | 170 | /** |
171 | | * Offset between calculated zoom level and zoom level used to download and show tiles. Negative values will result in |
172 | | * lower resolution of imagery useful in "retina" displays, positive values will result in higher resolution |
| 171 | * Offset between calculated zoom level, and zoom level used to download and show tiles. Negative values will result in |
| 172 | * lower resolution of imagery, positive values will result in higher resolution useful in "Retina" displays |
173 | 173 | */ |
174 | 174 | public static final IntegerProperty ZOOM_OFFSET = new IntegerProperty(PREFERENCE_PREFIX + ".zoom_offset", |
175 | | PlatformManager.getPlatform().isHighDpiDisplay() ? 2 : 0); |
| 175 | getDefaultZoomOffset(HiDPISupport.getHiDPIScale())); |
| 176 | |
| 177 | /** |
| 178 | * Calculate the zoom offset for best display results, given the scaling factor of the screen (e.g. 2 for Retina displays) |
| 179 | * @param scalingFactor scaling factor of the screen |
| 180 | * @return suggested zoom offset |
| 181 | */ |
| 182 | static int getDefaultZoomOffset(double scalingFactor) { |
| 183 | return (int) Math.ceil(Math.log(scalingFactor) / (Math.log(2.0) / 2.0)); // calculate logarithm on base sqrt(2), and round up |
| 184 | } |
176 | 185 | |
177 | 186 | /* |
178 | 187 | * use MemoryTileCache instead of tileLoader JCS cache, as tileLoader caches only content (byte[] of image) |
diff --git a/src/org/openstreetmap/josm/tools/HiDPISupport.java b/src/org/openstreetmap/josm/tools/HiDPISupport.java
index f54e3ff2e..368823e9c 100644
a
|
b
|
public final class HiDPISupport {
|
169 | 169 | * only take the default screen device into account. |
170 | 170 | * @return the GUI scale for HiDPI mode, a value of 1.0 means standard mode. |
171 | 171 | */ |
172 | | static double getHiDPIScale() { |
| 172 | public static double getHiDPIScale() { |
173 | 173 | if (GraphicsEnvironment.isHeadless()) |
174 | 174 | return 1.0; |
175 | 175 | GraphicsConfiguration gc = GraphicsEnvironment |
diff --git a/src/org/openstreetmap/josm/tools/PlatformHook.java b/src/org/openstreetmap/josm/tools/PlatformHook.java
index abd99e213..19cffad3a 100644
a
|
b
|
public interface PlatformHook {
|
136 | 136 | GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().isFullScreenSupported(); |
137 | 137 | } |
138 | 138 | |
139 | | /** |
140 | | * Determines if the default screen is a high-dpi device such as a mac Retina display. |
141 | | * @return {@code true} if the default screen is a high-dpi device such as a mac Retina display |
142 | | * @since 15918 |
143 | | */ |
144 | | default boolean isHighDpiDisplay() { |
145 | | // https://stackoverflow.com/a/49770313 |
146 | | return !GraphicsEnvironment.isHeadless() && |
147 | | !GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration() |
148 | | .getDefaultTransform().isIdentity(); |
149 | | } |
150 | | |
151 | 139 | /** |
152 | 140 | * Renames a file. |
153 | 141 | * @param from Source file |
diff --git a/test/unit/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayerTest.java b/test/unit/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayerTest.java
index 9ba10b5bd..1a724a8f5 100644
a
|
b
|
public class AbstractTileSourceLayerTest {
|
204 | 204 | public void testTileSourceLayerPopup() { |
205 | 205 | assertNotNull(testLayer.new TileSourceLayerPopup(100, 100)); |
206 | 206 | } |
| 207 | |
| 208 | /** |
| 209 | * Test {@link AbstractTileSourceLayer#getDefaultZoomOffset} |
| 210 | */ |
| 211 | @Test |
| 212 | public void testGetDefaultZoomOffset() { |
| 213 | assertEquals(-1, AbstractTileSourceLayer.getDefaultZoomOffset(0.7)); |
| 214 | assertEquals(0, AbstractTileSourceLayer.getDefaultZoomOffset(0.8)); |
| 215 | assertEquals(0, AbstractTileSourceLayer.getDefaultZoomOffset(1.0)); |
| 216 | assertEquals(1, AbstractTileSourceLayer.getDefaultZoomOffset(1.25)); |
| 217 | assertEquals(2, AbstractTileSourceLayer.getDefaultZoomOffset(1.5)); |
| 218 | assertEquals(2, AbstractTileSourceLayer.getDefaultZoomOffset(2.0)); |
| 219 | assertEquals(4, AbstractTileSourceLayer.getDefaultZoomOffset(3.0)); |
| 220 | } |
207 | 221 | } |