From 934fd3544f13e49df3535d862466dbe9ecb4c102 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Berg?= Date: Mon, 10 Jan 2011 01:47:32 +0100 Subject: [PATCH] Fix the unreadable font size problem on Mac OS X. See also http://aptanastudio.tenderapp.com/discussions/problems/2052-some-dialogs-have-unreadable-small-font-size --- .../python/pydev/core/bundle/ImageCache.java | 27 +++++++++++++-- .../codecoverage/PyCodeCoverageView.java | 15 +++++++- .../StyledTextForShowingCodeFactory.java | 27 ++++++++++++++- .../CommentBlocksPreferences.java | 14 +++++++- .../pydev/ui/actions/resources/Py2To3.java | 34 +++++++++++++++++-- 5 files changed, 110 insertions(+), 7 deletions(-) diff --git a/plugins/org.python.pydev.core/src/org/python/pydev/core/bundle/ImageCache.java b/plugins/org.python.pydev.core/src/org/python/pydev/core/bundle/ImageCache.java index 28478f1b5..3e3a8b1ef 100644 --- a/plugins/org.python.pydev.core/src/org/python/pydev/core/bundle/ImageCache.java +++ b/plugins/org.python.pydev.core/src/org/python/pydev/core/bundle/ImageCache.java @@ -13,6 +13,9 @@ import org.eclipse.jface.resource.CompositeImageDescriptor; import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.core.runtime.Platform; +import org.eclipse.osgi.service.environment.Constants; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Font; @@ -206,8 +209,17 @@ public Image getStringDecorated(String key, String stringToAddToDecoration) { Display display = Display.getCurrent(); image = new Image(display, get(key), SWT.IMAGE_COPY); imageHash.put(cacheKey, image); //put it there (even though it'll still be changed). + + int base = 10; + String fontName = "Courier New"; + + if (Platform.getOS().equals(Constants.OS_MACOSX)) { + // see org.python.pydev.ui.actions.resources.Py2To3#confirmRun() + // for an explanation why a different font and size is neccesary on OS X + fontName = "Monaco"; + base = 12; + } - int base=10; GC gc = new GC(image); // Color color = new Color(display, 0, 0, 0); @@ -223,7 +235,18 @@ public Image getStringDecorated(String key, String stringToAddToDecoration) { Color colorBackground = new Color(display, 255, 255, 255); Color colorForeground = new Color(display, 0, 83, 41); - Font font = new Font(display, new FontData("Courier New", base-1, SWT.BOLD)); + + FontData labelFontData; + + // get TextFont from preferences + FontData[] textFontData = JFaceResources.getTextFont().getFontData(); + if (textFontData.length == 1) { + labelFontData = textFontData[0]; + } else { + labelFontData = new FontData(fontName, base-1, SWT.BOLD); + } + + Font font = new Font(display, labelFontData); try { gc.setForeground(colorForeground); diff --git a/plugins/org.python.pydev.debug/src/org/python/pydev/debug/codecoverage/PyCodeCoverageView.java b/plugins/org.python.pydev.debug/src/org/python/pydev/debug/codecoverage/PyCodeCoverageView.java index 8c646cfa0..9edd486a1 100644 --- a/plugins/org.python.pydev.debug/src/org/python/pydev/debug/codecoverage/PyCodeCoverageView.java +++ b/plugins/org.python.pydev.debug/src/org/python/pydev/debug/codecoverage/PyCodeCoverageView.java @@ -38,6 +38,8 @@ import org.eclipse.ui.IFileEditorInput; import org.eclipse.ui.dialogs.ContainerSelectionDialog; import org.eclipse.ui.texteditor.MarkerUtilities; +import org.eclipse.core.runtime.Platform; +import org.eclipse.osgi.service.environment.Constants; import org.python.pydev.core.ExtensionHelper; import org.python.pydev.debug.pyunit.ViewPartWithOrientation; import org.python.pydev.editor.PyEdit; @@ -358,7 +360,18 @@ public void createPartControl(Composite parent) { text = new Text(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); try { - text.setFont(new Font(null, "Courier new", 10, 0)); + int fheight = 10; + String fontName; + if (Platform.getOS().equals(Constants.OS_MACOSX)) { + // see org.python.pydev.ui.actions.resources.Py2To3#confirmRun() + // for an explanation why a different font and size is neccesary on OS X + fontName = "Monaco"; + fheight = 9; + } else { + fontName = "Courier new"; + fheight = 10; + } + text.setFont(new Font(null, fontName, fheight, 0)); } catch (Exception e) { //ok, might mot be available. } diff --git a/plugins/org.python.pydev/src/org/python/pydev/editor/StyledTextForShowingCodeFactory.java b/plugins/org.python.pydev/src/org/python/pydev/editor/StyledTextForShowingCodeFactory.java index a69aa5f4e..c789d66d8 100644 --- a/plugins/org.python.pydev/src/org/python/pydev/editor/StyledTextForShowingCodeFactory.java +++ b/plugins/org.python.pydev/src/org/python/pydev/editor/StyledTextForShowingCodeFactory.java @@ -3,9 +3,12 @@ import java.util.ArrayList; import java.util.Iterator; +import org.eclipse.core.runtime.Platform; +import org.eclipse.osgi.service.environment.Constants; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.PreferenceConverter; import org.eclipse.jface.preference.PreferenceStore; +import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.text.Document; import org.eclipse.jface.text.ITypedRegion; import org.eclipse.jface.text.TextAttribute; @@ -62,8 +65,30 @@ public StyledText createStyledTextForCodePresentation(Composite parent){ styledText = new StyledText(parent, SWT.BORDER|SWT.READ_ONLY); this.backgroundColorCache = new ColorAndStyleCache(new PreferenceStore()); this.colorCache = new ColorAndStyleCache(null); + + int fontHeight; + String fontName = "Courier New"; + + if (Platform.getOS().equals(Constants.OS_MACOSX)) { + // see org.python.pydev.ui.actions.resources.Py2To3#confirmRun() + // for an explanation why a different font and size is neccesary on OS X + fontName = "Monaco"; + fontHeight = 11; + } else { + fontHeight = 10; + } + try { - FontData labelFontData = new FontData("Courier New", 10, SWT.NONE); + FontData labelFontData; + + // get TextFont from preferences + FontData[] textFontData = JFaceResources.getTextFont().getFontData(); + if (textFontData.length == 1) { + labelFontData = textFontData[0]; + } else { + labelFontData = new FontData(fontName, fontHeight, SWT.NONE); + } + styledText.setFont(new Font(parent.getDisplay(), labelFontData)); } catch (Throwable e) { //ignore diff --git a/plugins/org.python.pydev/src/org/python/pydev/editor/commentblocks/CommentBlocksPreferences.java b/plugins/org.python.pydev/src/org/python/pydev/editor/commentblocks/CommentBlocksPreferences.java index e0daa5764..6cf66decd 100644 --- a/plugins/org.python.pydev/src/org/python/pydev/editor/commentblocks/CommentBlocksPreferences.java +++ b/plugins/org.python.pydev/src/org/python/pydev/editor/commentblocks/CommentBlocksPreferences.java @@ -1,5 +1,7 @@ package org.python.pydev.editor.commentblocks; +import org.eclipse.core.runtime.Platform; +import org.eclipse.osgi.service.environment.Constants; import org.eclipse.jface.preference.BooleanFieldEditor; import org.eclipse.jface.preference.FieldEditorPreferencePage; import org.eclipse.jface.preference.IPreferenceStore; @@ -81,7 +83,17 @@ protected void createFieldEditors() { private void setLabelFont(Composite composite, Label label) { try { - FontData labelFontData = new FontData("Courier New", 10, SWT.BOLD); + int fontHeight; + String fontName = "Courier New"; + if (Platform.getOS().equals(Constants.OS_MACOSX)) { + // see org.python.pydev.ui.actions.resources.Py2To3#confirmRun() + // for an explanation why a different font and size is neccesary on OS X + fontName = "Monaco"; + fontHeight = 9; + } else { + fontHeight = 10; + } + FontData labelFontData = new FontData(fontName, fontHeight , SWT.BOLD); label.setFont(new Font(composite.getDisplay(), labelFontData)); } catch (Throwable e) { //ignore diff --git a/plugins/org.python.pydev/src/org/python/pydev/ui/actions/resources/Py2To3.java b/plugins/org.python.pydev/src/org/python/pydev/ui/actions/resources/Py2To3.java index 13181febf..3c0e5ac87 100644 --- a/plugins/org.python.pydev/src/org/python/pydev/ui/actions/resources/Py2To3.java +++ b/plugins/org.python.pydev/src/org/python/pydev/ui/actions/resources/Py2To3.java @@ -10,6 +10,8 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Platform; +import org.eclipse.osgi.service.environment.Constants; import org.eclipse.jface.dialogs.InputDialog; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Font; @@ -119,10 +121,38 @@ protected boolean confirmRun() { null){ int averageCharWidth; int height; + protected boolean isResizable() { + return true; + } protected Control createDialogArea(Composite parent) { - try { - FontData labelFontData = new FontData("Courier New", 8, SWT.NONE); + int fheight; + String fontName; + if (Platform.getOS().equals(Constants.OS_MACOSX)) { + // on OS X we need a different font because + // under Mac SWT the bitmap font rasterizer + // doesn't take hinting into account and thus + // makes small fonts rendered as bitmaps unreadable + // see http://aptanastudio.tenderapp.com/discussions/problems/2052-some-dialogs-have-unreadable-small-font-size + fontName = "Courier"; + fheight = 11; + } else { + fontName = "Courier New"; + fheight = 8; + } + + //FontData labelFontData; + // + //// get Dialog Font from preferences + //FontData[] textFontData = JFaceResources.getDialogFont().getFontData(); + //if (textFontData.length == 1) { + // labelFontData = textFontData[0]; + //} else { + // labelFontData = new FontData(fontName, fheight , SWT.NONE); + //} + + FontData labelFontData = new FontData(fontName, fheight , SWT.NONE); + Display display = parent.getDisplay(); Font font = new Font(display, labelFontData); parent.setFont(font);