Changeset 10392 in josm
- Timestamp:
- 2016-06-15T20:32:03+02:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/util/GuiSizesHelper.java
r10368 r10392 5 5 import java.awt.HeadlessException; 6 6 import java.awt.Toolkit; 7 8 import org.openstreetmap.josm.Main; 7 9 8 10 /** … … 20 22 21 23 /** cache value for screen resolution */ 22 private static int screenDPI = -1;24 private static float screenDPI = -1; 23 25 24 26 /** Request the screen resolution (cached) 25 27 * @return screen resolution in DPI 26 28 */ 27 private static int getScreenDPI() {29 private static float getScreenDPI() { 28 30 if (screenDPI == -1) { 29 31 synchronized (GuiHelper.class) { 30 32 if (screenDPI == -1) { 31 try { 32 screenDPI = Toolkit.getDefaultToolkit().getScreenResolution(); 33 } catch (HeadlessException e) { 34 screenDPI = 96; 33 float scalePref = (float) Main.pref.getDouble("gui.scale", 0); 34 if (scalePref != 0) { 35 screenDPI = 96f * scalePref; 36 } else { 37 try { 38 screenDPI = Toolkit.getDefaultToolkit().getScreenResolution(); 39 } catch (HeadlessException e) { 40 screenDPI = 96; 41 } 35 42 } 36 37 43 } 38 44 } … … 47 53 */ 48 54 public static float getPixelDensity() { 49 int pixelPerInch = getScreenDPI();50 return (float) (pixelPerInch / 96.0);55 float pixelPerInch = getScreenDPI(); 56 return pixelPerInch / 96f; 51 57 } 52 58 … … 66 72 public static int getSizeDpiAdjusted(int size) { 67 73 if (size <= 0) return size; 68 int pixelPerInch = getScreenDPI();69 return size * pixelPerInch / 96;74 float pixelPerInch = getScreenDPI(); 75 return Math.round(size * pixelPerInch / 96); 70 76 } 71 77 … … 77 83 public static float getSizeDpiAdjusted(float size) { 78 84 if (size <= 0f) return size; 79 int pixelPerInch = getScreenDPI();85 float pixelPerInch = getScreenDPI(); 80 86 return size * pixelPerInch / 96; 81 87 } … … 88 94 public static double getSizeDpiAdjusted(double size) { 89 95 if (size <= 0d) return size; 90 int pixelPerInch = getScreenDPI();96 float pixelPerInch = getScreenDPI(); 91 97 return size * pixelPerInch / 96; 92 98 } … … 98 104 */ 99 105 public static Dimension getDimensionDpiAdjusted(Dimension dim) { 100 int pixelPerInch = getScreenDPI();106 float pixelPerInch = getScreenDPI(); 101 107 int width = dim.width, height = dim.height; 102 108 if (dim.width > 0) { 103 width = dim.width * pixelPerInch / 96;109 width = Math.round(dim.width * pixelPerInch / 96); 104 110 } 105 111 106 112 if (dim.height > 0) { 107 height = dim.height * pixelPerInch / 96;113 height = Math.round(dim.height * pixelPerInch / 96); 108 114 } 109 115
Note:
See TracChangeset
for help on using the changeset viewer.