Ticket #18720: default-zoom-offset-based-on-HiDPISupport.patch

File default-zoom-offset-based-on-HiDPISupport.patch, 5.4 KB (added by johsin18, 4 years ago)

Patch for setting the default zoom offset based on HiDPISupport class.

  • src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java

    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;  
    121121import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    122122import org.openstreetmap.josm.gui.util.GuiHelper;
    123123import org.openstreetmap.josm.tools.GBC;
     124import org.openstreetmap.josm.tools.HiDPISupport;
    124125import org.openstreetmap.josm.tools.HttpClient;
    125126import org.openstreetmap.josm.tools.Logging;
    126127import org.openstreetmap.josm.tools.MemoryManager;
    127128import org.openstreetmap.josm.tools.MemoryManager.MemoryHandle;
    128129import org.openstreetmap.josm.tools.MemoryManager.NotEnoughMemoryException;
    129 import org.openstreetmap.josm.tools.PlatformManager;
    130130import org.openstreetmap.josm.tools.Utils;
    131131import org.openstreetmap.josm.tools.bugreport.BugReport;
    132132
    implements ImageObserver, TileLoaderListener, ZoomChangeListener, FilterChangeLi  
    168168    private final AttributionSupport attribution = new AttributionSupport();
    169169
    170170    /**
    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
    173173     */
    174174    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    }
    176185
    177186    /*
    178187     *  use MemoryTileCache instead of tileLoader JCS cache, as tileLoader caches only content (byte[] of image)
  • src/org/openstreetmap/josm/tools/HiDPISupport.java

    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 {  
    169169     * only take the default screen device into account.
    170170     * @return the GUI scale for HiDPI mode, a value of 1.0 means standard mode.
    171171     */
    172     static double getHiDPIScale() {
     172    public static double getHiDPIScale() {
    173173        if (GraphicsEnvironment.isHeadless())
    174174            return 1.0;
    175175        GraphicsConfiguration gc = GraphicsEnvironment
  • src/org/openstreetmap/josm/tools/PlatformHook.java

    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 {  
    136136                GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().isFullScreenSupported();
    137137    }
    138138
    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 
    151139    /**
    152140     * Renames a file.
    153141     * @param from Source file
  • test/unit/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayerTest.java

    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 {  
    204204    public void testTileSourceLayerPopup() {
    205205        assertNotNull(testLayer.new TileSourceLayerPopup(100, 100));
    206206    }
     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    }
    207221}