diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/diagram/figures/AbstractDiagramModelObjectFigure.java b/com.archimatetool.editor/src/com/archimatetool/editor/diagram/figures/AbstractDiagramModelObjectFigure.java index e9f6ee091..0d039a805 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/diagram/figures/AbstractDiagramModelObjectFigure.java +++ b/com.archimatetool.editor/src/com/archimatetool/editor/diagram/figures/AbstractDiagramModelObjectFigure.java @@ -27,7 +27,6 @@ import com.archimatetool.editor.ui.ImageFactory; import com.archimatetool.editor.ui.factory.IGraphicalObjectUIProvider; import com.archimatetool.editor.ui.factory.ObjectUIFactory; -import com.archimatetool.editor.utils.PlatformUtils; import com.archimatetool.editor.utils.StringUtils; import com.archimatetool.model.IArchimateElement; import com.archimatetool.model.IDiagramModelArchimateObject; @@ -164,12 +163,11 @@ protected void setFont() { } @Override - public void setFont(Font f) { - if(PlatformUtils.isWindows()) { - f = FontFactory.getAdjustedWindowsFont(f); - } + public void setFont(Font font) { + // Possible font scaling for non 96 DPI on Windows or if property set + font = FontFactory.checkScaledFont96DPI(font); - super.setFont(f); + super.setFont(font); } /** diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/diagram/figures/connections/AbstractDiagramConnectionFigure.java b/com.archimatetool.editor/src/com/archimatetool/editor/diagram/figures/connections/AbstractDiagramConnectionFigure.java index ed3503020..92620c0f0 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/diagram/figures/connections/AbstractDiagramConnectionFigure.java +++ b/com.archimatetool.editor/src/com/archimatetool/editor/diagram/figures/connections/AbstractDiagramConnectionFigure.java @@ -32,7 +32,6 @@ import com.archimatetool.editor.ui.ColorFactory; import com.archimatetool.editor.ui.FontFactory; import com.archimatetool.editor.ui.textrender.TextRenderer; -import com.archimatetool.editor.utils.PlatformUtils; import com.archimatetool.editor.utils.StringUtils; import com.archimatetool.model.IDiagramModelConnection; @@ -201,10 +200,8 @@ protected void setLabelFont() { String fontName = getModelConnection().getFont(); Font font = FontFactory.get(fontName); - // Adjust for Windows DPI - if(PlatformUtils.isWindows()) { - font = FontFactory.getAdjustedWindowsFont(font); - } + // Possible font scaling for non 96 DPI on Windows or if property set + font = FontFactory.checkScaledFont96DPI(font); getConnectionLabel().setFont(font); } diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/ui/FontFactory.java b/com.archimatetool.editor/src/com/archimatetool/editor/ui/FontFactory.java index 1047915f1..ca22c0b2d 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/ui/FontFactory.java +++ b/com.archimatetool.editor/src/com/archimatetool/editor/ui/FontFactory.java @@ -24,8 +24,15 @@ * * @author Phillip Beauvoir */ +@SuppressWarnings("nls") public final class FontFactory { + // Property to set if we will check to adjust font scaling + public static final String ADJUST_FONT_SIZE_PROPERTY = "com.archimatetool.adjustFontSize"; + + // Whether to check to adjust font size on Windows non 96 DPI or if property set + private static final boolean CHECK_ADJUST_FONT_SIZE = PlatformUtils.isWindows() || "true".equals(System.getProperty(ADJUST_FONT_SIZE_PROPERTY)); + private static final String DEFAULT_VIEW_FONT_NAME = "defaultViewFont"; //$NON-NLS-1$ /** @@ -33,14 +40,9 @@ public final class FontFactory { */ private static FontRegistry FontRegistry = new FontRegistry(); - /** - * Temporary Font Registry to hold adjusted size fonts on Windows - */ - private static FontRegistry windowsFontRegistry = new FontRegistry(); - - public static Font SystemFontBold = JFaceResources.getFontRegistry().getBold(""); //$NON-NLS-1$ + public static Font SystemFontBold = JFaceResources.getFontRegistry().getBold(""); - public static Font SystemFontItalic = JFaceResources.getFontRegistry().getItalic(""); //$NON-NLS-1$ + public static Font SystemFontItalic = JFaceResources.getFontRegistry().getItalic(""); /** * @param fontName @@ -112,19 +114,19 @@ public static void setDefaultUserViewFont(FontData fd) { */ public static FontData getDefaultViewOSFontData() { // Default - FontData fd = new FontData("Sans", 9, SWT.NORMAL); //$NON-NLS-1$ + FontData fd = new FontData("Sans", 9, SWT.NORMAL); // Windows if(PlatformUtils.isWindows()) { - fd = new FontData("Segoe UI", 9, SWT.NORMAL); //$NON-NLS-1$ + fd = new FontData("Segoe UI", 9, SWT.NORMAL); } // Linux else if(PlatformUtils.isLinux()) { - fd = new FontData("Sans", 9, SWT.NORMAL); //$NON-NLS-1$ + fd = new FontData("Sans", 9, SWT.NORMAL); } // Mac else if(PlatformUtils.isMac()) { - fd = new FontData("Lucida Grande", 12, SWT.NORMAL); //$NON-NLS-1$ + fd = new FontData("Lucida Grande", 12, SWT.NORMAL); } return fd; @@ -136,25 +138,31 @@ private static void setDefaultViewOSFontData() { } /** - * On Windows OS if the system DPI is not 96 DPI we need to adjust the size - * of the font on the diagram View. - * @param font - * @return The adjusted font + * Return a font scaled from 96 DPI if the current DPI is not 96 + * This can happen on Windows if the DPI is not 96 or on Mac if we set a property. + * @return The adjusted font if DPI is not 96 or the same font, or null */ - public static Font getAdjustedWindowsFont(Font font) { - if(font != null && PlatformUtils.isWindows()) { - int DPI = font.getDevice().getDPI().y; - if(DPI != 96) { - FontData[] fd = font.getFontData(); - String fontName = fd[0].toString(); - if(!windowsFontRegistry.hasValueFor(fontName)) { - float factor = (float)96 / DPI; - int newHeight = (int)(fd[0].getHeight() * factor); - fd[0].setHeight(newHeight); - windowsFontRegistry.put(fontName, fd); - } - font = windowsFontRegistry.get(fontName); + public static Font checkScaledFont96DPI(Font font) { + if(font == null || !CHECK_ADJUST_FONT_SIZE) { + return font; + } + + int DPI = font.getDevice().getDPI().y; + + if(DPI != 96) { + FontData[] fd = font.getFontData(); + + float factor = (float)96 / DPI; + int newHeight = (int)(fd[0].getHeight() * factor); + + fd[0].setHeight(newHeight); + String fontName = fd[0].toString(); + + if(!FontRegistry.hasValueFor(fontName)) { + FontRegistry.put(fontName, fd); } + + font = FontRegistry.get(fontName); } return font;