Skip to content

Commit

Permalink
Allow option to scale fonts by arbitrary factor. See issue #1373
Browse files Browse the repository at this point in the history
  • Loading branch information
jrobinso committed Dec 6, 2023
1 parent ad926d7 commit 955b102
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/main/java/org/broad/igv/prefs/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ private Constants() {
public static final String DEFAULT_FONT_ATTRIBUTE = "DEFAULT_FONT_ATTRIBUTE";
public static final String ENABLE_ANTIALISING = "ENABLE_ANTIALIASING";
public static final String SCALE_FONTS = "SCALE_FONTS";
public static final String FONT_SCALE_FACTOR = "FONT_SCALE_FACTOR";
public static final String NAME_PANEL_WIDTH = "NAME_PANEL_WIDTH";
public static final String BACKGROUND_COLOR = "BACKGROUND_COLOR";
public static final String SHOW_ATTRIBUTE_VIEWS_KEY = "IGV.track.show.attribute.views";
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/org/broad/igv/prefs/PreferencesManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
import org.broad.igv.logging.Logger;
import org.broad.igv.util.ParsingUtils;

import java.awt.*;
import java.io.*;
import java.util.*;
import java.util.List;

import static org.broad.igv.prefs.Constants.*;

Expand Down Expand Up @@ -65,6 +67,16 @@ private static void init() {

Map<String, String> nullCategory = loadDefaults23();

// Special override -- maintains backward compatibility
if (!nullCategory.containsKey("FONT_SCALE_FACTOR") || nullCategory.get("FONT_SCALE_FACTOR").equals("1")) {
try {
double resolutionScale = Math.max(1, Toolkit.getDefaultToolkit().getScreenResolution() / ((double) Globals.DESIGN_DPI));
nullCategory.put(FONT_SCALE_FACTOR, String.valueOf((float) resolutionScale));
} catch (Exception e) {
log.error("Error overriding font scale factor", e);
}
}

defaultPreferences.put(NULL_CATEGORY, nullCategory);
defaultPreferences.put(RNA, new HashMap<>());
defaultPreferences.put(THIRD_GEN, new HashMap<>());
Expand Down Expand Up @@ -119,6 +131,7 @@ private static void extractMutationColors(IGVPreferences prefs) {
public static String getDefault(String key) {
return genericDefaults.get(key);
}

public static IGVPreferences getPreferences() {
return getPreferences(NULL_CATEGORY);
}
Expand Down
22 changes: 11 additions & 11 deletions src/main/java/org/broad/igv/ui/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.broad.igv.DirectoryManager;
import org.broad.igv.Globals;
import org.broad.igv.oauth.OAuthUtils;
import org.broad.igv.prefs.Constants;
import org.broad.igv.prefs.IGVPreferences;
import org.broad.igv.prefs.PreferencesManager;
import org.broad.igv.util.FileUtils;
Expand Down Expand Up @@ -205,7 +206,7 @@ private static void initApplication(Main.IGVArgs igvArgs) {
log.info("JVM: " + System.getProperty("java.vm.name", "")
+ " " + System.getProperty("java.vendor.version", "")
+ " " + System.getProperty("java.compiler", ""));
log.info("OS: " + System.getProperty("os.name") + " " + System.getProperty("os.version")
log.info("OS: " + System.getProperty("os.name") + " " + System.getProperty("os.version")
+ " " + System.getProperty("os.arch"));
log.info("IGV Directory: " + DirectoryManager.getIgvDirectory().getAbsolutePath());

Expand Down Expand Up @@ -290,9 +291,9 @@ public void windowGainedFocus(WindowEvent windowEvent) {
SeekableStreamFactory.setInstance(IGVSeekableStreamFactory.getInstance());

// Start IGV's UI itself (frame) and other components
IGV igv = IGV.createInstance(frame);
IGV igv = IGV.createInstance(frame);

igv.startUp(igvArgs);
igv.startUp(igvArgs);

// TODO Should this be done here? Will this step on other key dispatchers?
KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(GlobalKeyDispatcher.getInstance());
Expand All @@ -309,18 +310,17 @@ private static void initializeLookAndFeel() {
}

double resolutionScale = Toolkit.getDefaultToolkit().getScreenResolution() / Globals.DESIGN_DPI;
if(resolutionScale != 1.0) {
if (resolutionScale != 1.0) {
log.info("Resoluction scale = " + resolutionScale);
}

final IGVPreferences prefMgr = PreferencesManager.getPreferences();
if (resolutionScale > 1.5) {
if (prefMgr.getAsBoolean(SCALE_FONTS)) {
FontManager.scaleFontSize(resolutionScale);
} else if (prefMgr.hasExplicitValue(DEFAULT_FONT_SIZE)) {
int fs = prefMgr.getAsInt(DEFAULT_FONT_SIZE);
FontManager.updateSystemFontSize(fs);
}
if (prefMgr.getAsBoolean(SCALE_FONTS)) {
float scaleFactor = prefMgr.getAsFloat(FONT_SCALE_FACTOR);
FontManager.scaleFontSize(scaleFactor);
} else if (prefMgr.hasExplicitValue(DEFAULT_FONT_SIZE)) {
int fs = prefMgr.getAsInt(DEFAULT_FONT_SIZE);
FontManager.updateSystemFontSize(fs);
}


Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/org/broad/igv/prefs/preferences.tab
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ NEXT_FLANKING_REGION Padding region in bp, < 0 is interpreted as a percentage. i
BACKGROUND_COLOR Background color color 250,250,250
DEFAULT_FONT_FAMILY Default font family string Arial
DEFAULT_FONT_SIZE Default font size integer 10
SCALE_FONTS Scale fonts for high resolution screens. NOTE: this should not be neccessary for latest release (Java 17). boolean FALSE Scale fonts for high resolution screens. NOTE: this should not be neccessary for latest release (Java 17). If fonts are too large disable this option.

SCALE_FONTS Scale fonts. Useful for some high-resolution screens. ** REQUIRES RESTART ** boolean FALSE
FONT_SCALE_FACTOR Font scale factor float 1
ENABLE_ANTIALIASING Enable anti-aliasing boolean TRUE

##Nucleotide Colors
Expand Down

0 comments on commit 955b102

Please sign in to comment.