Skip to content

Commit

Permalink
Fix the unreadable font size problem on Mac OS X.
Browse files Browse the repository at this point in the history
  • Loading branch information
andreberg committed Jan 10, 2011
1 parent baec4ef commit 934fd35
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 934fd35

Please sign in to comment.