mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
better option for setting code font
This commit is contained in:
@@ -123,8 +123,8 @@ public class Preferences {
|
||||
JComboBox displaySelectionBox;
|
||||
int displayCount;
|
||||
|
||||
//List<Font> monoFontList;
|
||||
Font[] monoFontList;
|
||||
//Font[] monoFontList;
|
||||
String[] monoFontFamilies;
|
||||
JComboBox fontSelectionBox;
|
||||
|
||||
/** Base object so that updates can be applied to the list of editors. */
|
||||
@@ -320,7 +320,7 @@ public class Preferences {
|
||||
"though the list may be imperfect.";
|
||||
fontLabel.setToolTipText(fontTip);
|
||||
fontBox.add(fontLabel);
|
||||
// needs to happen here for getPreferredSize()
|
||||
// get a wide name in there before getPreferredSize() is called
|
||||
fontSelectionBox = new JComboBox(new Object[] { Toolkit.getMonoFontName() });
|
||||
fontSelectionBox.setToolTipText(fontTip);
|
||||
// fontSelectionBox.addItem(Toolkit.getMonoFont(size, style));
|
||||
@@ -646,7 +646,8 @@ public class Preferences {
|
||||
* then send a message to the editor saying that it's time to do the same.
|
||||
*/
|
||||
protected void applyFrame() {
|
||||
setBoolean("editor.antialias", editorAntialiasBox.isSelected()); //$NON-NLS-1$
|
||||
setBoolean("editor.antialias", //$NON-NLS-1$
|
||||
editorAntialiasBox.isSelected());
|
||||
|
||||
setBoolean("export.delete_target_folder", //$NON-NLS-1$
|
||||
deletePreviousBox.isSelected());
|
||||
@@ -721,6 +722,9 @@ public class Preferences {
|
||||
}
|
||||
*/
|
||||
|
||||
//set("editor.font", fontSelectionBox.getSelectedItem());
|
||||
String fontFamily = (String) fontSelectionBox.getSelectedItem();
|
||||
|
||||
String newSizeText = fontSizeField.getText();
|
||||
try {
|
||||
int newSize = Integer.parseInt(newSizeText.trim());
|
||||
@@ -837,10 +841,12 @@ public class Preferences {
|
||||
|
||||
|
||||
void initFontList() {
|
||||
/*
|
||||
if (monoFontList == null) {
|
||||
Font[] list = Toolkit.getMonoFontList().toArray(new Font[0]);
|
||||
fontSelectionBox.setModel(new DefaultComboBoxModel(list));
|
||||
monoFontList = Toolkit.getMonoFontList().toArray(new Font[0]);
|
||||
fontSelectionBox.setModel(new DefaultComboBoxModel(monoFontList));
|
||||
fontSelectionBox.setRenderer(new FontNamer());
|
||||
|
||||
// Preferred size just makes it extend to the container
|
||||
//fontSelectionBox.setSize(fontSelectionBox.getPreferredSize());
|
||||
// Minimum size is better, but cuts things off (on OS X), so we add 20
|
||||
@@ -848,7 +854,28 @@ public class Preferences {
|
||||
//Dimension minSize = fontSelectionBox.getPreferredSize();
|
||||
//fontSelectionBox.setSize(minSize.width + 20, minSize.height);
|
||||
fontSelectionBox.setEnabled(true);
|
||||
monoFontList = list; // signal that we're finished
|
||||
}
|
||||
*/
|
||||
if (monoFontFamilies == null) {
|
||||
monoFontFamilies = Toolkit.getMonoFontFamilies();
|
||||
fontSelectionBox.setModel(new DefaultComboBoxModel(monoFontFamilies));
|
||||
String family = get("editor.font.family");
|
||||
// System.out.println("family is " + family);
|
||||
// System.out.println("font sel items = " + fontSelectionBox.getItemCount());
|
||||
// for (int i = 0; i < fontSelectionBox.getItemCount(); i++) {
|
||||
// String item = (String) fontSelectionBox.getItemAt(i);
|
||||
// if (fontSelectionBox.getItemAt(i) == family) {
|
||||
// System.out.println("found at index " + i);
|
||||
// } else if (item.equals(family)) {
|
||||
// System.out.println("equals at index " + i);
|
||||
// } else {
|
||||
// System.out.println("nothing doing: " + item);
|
||||
// }
|
||||
// }
|
||||
// Set a reasonable default, in case selecting the family fails
|
||||
fontSelectionBox.setSelectedItem("Monospaced");
|
||||
fontSelectionBox.setSelectedItem(family);
|
||||
fontSelectionBox.setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
@@ -322,7 +323,8 @@ public class Toolkit {
|
||||
// }
|
||||
|
||||
|
||||
static public List<Font> getMonoFontList() {
|
||||
// Gets the plain (not bold, not italic) version of each
|
||||
static private List<Font> getMonoFontList() {
|
||||
GraphicsEnvironment ge =
|
||||
GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
Font[] fonts = ge.getAllFonts();
|
||||
@@ -333,7 +335,8 @@ public class Toolkit {
|
||||
Preferences.getBoolean("editor.antialias"),
|
||||
true); // use fractional metrics
|
||||
for (Font font : fonts) {
|
||||
if (font.canDisplay('i') && font.canDisplay('M') &&
|
||||
if (font.getStyle() == Font.PLAIN &&
|
||||
font.canDisplay('i') && font.canDisplay('M') &&
|
||||
font.canDisplay(' ') && font.canDisplay('.')) {
|
||||
|
||||
// The old method just returns 1 or 0, and using deriveFont(size)
|
||||
@@ -349,6 +352,14 @@ public class Toolkit {
|
||||
if (w == font.getStringBounds("i", frc).getWidth() &&
|
||||
w == font.getStringBounds("M", frc).getWidth() &&
|
||||
w == font.getStringBounds(".", frc).getWidth()) {
|
||||
|
||||
// //PApplet.printArray(font.getAvailableAttributes());
|
||||
// Map<TextAttribute,?> attr = font.getAttributes();
|
||||
// System.out.println(font.getFamily() + " > " + font.getName());
|
||||
// System.out.println(font.getAttributes());
|
||||
// System.out.println(" " + attr.get(TextAttribute.WEIGHT));
|
||||
// System.out.println(" " + attr.get(TextAttribute.POSTURE));
|
||||
|
||||
outgoing.add(font);
|
||||
// System.out.println(" good " + w);
|
||||
}
|
||||
@@ -356,6 +367,15 @@ public class Toolkit {
|
||||
}
|
||||
return outgoing;
|
||||
}
|
||||
|
||||
|
||||
static public String[] getMonoFontFamilies() {
|
||||
HashSet<String> families = new HashSet<String>();
|
||||
for (Font font : getMonoFontList()) {
|
||||
families.add(font.getFamily());
|
||||
}
|
||||
return families.toArray(new String[0]);
|
||||
}
|
||||
|
||||
|
||||
static Font monoFont;
|
||||
|
||||
Executable → Regular
Binary file not shown.
@@ -106,8 +106,10 @@ editor.window.height.min.windows = 530
|
||||
# Monaco is nicer on Mac OS X, so use that explicitly
|
||||
#editor.font.macosx = Monaco,plain,10
|
||||
# trying for a built-in, consistent monospace for 2.0
|
||||
editor.font = processing.mono,plain,12
|
||||
#editor.font.size=12
|
||||
#editor.font = processing.mono,plain,12
|
||||
|
||||
editor.font.family = Source Code Pro
|
||||
editor.font.size = 12
|
||||
|
||||
# anti-aliased text, turned off by default
|
||||
#editor.antialias=false
|
||||
|
||||
@@ -16,6 +16,9 @@ X https://github.com/processing/processing/issues/2103
|
||||
X still having right-click issues (re-opened)
|
||||
X https://github.com/processing/processing/issues/2103
|
||||
|
||||
X update with bold version of Source Code Pro
|
||||
X http://www.google.com/fonts#UsePlace:use/Collection:Source+Code+Pro
|
||||
|
||||
cleaning
|
||||
o the first time someone hides a tab, put up a msg explaining what it does
|
||||
o "don't warn me about this anymore"
|
||||
|
||||
Reference in New Issue
Block a user