From 75406ef4630486b15f7ba0fc55e2ab13eb6749d6 Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Sat, 1 Jun 2013 12:55:40 -0400 Subject: [PATCH 1/2] fighting with fonts --- app/src/processing/app/Base.java | 10 +++---- app/src/processing/app/Toolkit.java | 42 +++++++++++++++-------------- 2 files changed, 27 insertions(+), 25 deletions(-) mode change 100644 => 100755 app/src/processing/app/Base.java mode change 100644 => 100755 app/src/processing/app/Toolkit.java diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java old mode 100644 new mode 100755 index 35bd2efde..2fe9278a6 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -44,7 +44,7 @@ import processing.core.*; * files and images, etc) that comes from that. */ public class Base { - // Added accessors for 0218 because the UpdateCheck class was not properly + // Added accessors for 0218 because the UpdateCheck class was not properly // updating the values, because javac was inlining the static final values. static private final int REVISION = 218; /** This might be replaced by main() if there's a lib/version.txt file. */ @@ -53,8 +53,8 @@ public class Base { // static private boolean RELEASE = false; /** True if heavy debugging error/log messages are enabled */ - static public boolean DEBUG = false; -// static public boolean DEBUG = true; + // static public boolean DEBUG = false; + static public boolean DEBUG = true; static HashMap platformNames = new HashMap(); @@ -1556,7 +1556,7 @@ public class Base { static public int getRevision() { return REVISION; } - + /** * Return the version name, something like 1.5 or 2.0b8 or 0213 if it's not @@ -1566,7 +1566,7 @@ public class Base { return VERSION_NAME; } - + //................................................................... diff --git a/app/src/processing/app/Toolkit.java b/app/src/processing/app/Toolkit.java old mode 100644 new mode 100755 index 79774446b..a4656869e --- a/app/src/processing/app/Toolkit.java +++ b/app/src/processing/app/Toolkit.java @@ -233,16 +233,16 @@ public class Toolkit { } return false; } - - + + // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . - + // static Font monoFont; // static Font plainFont; // static Font boldFont; -// -// +// +// // static public Font getMonoFont(int size) { // if (monoFont == null) { // try { @@ -253,7 +253,7 @@ public class Toolkit { // } // return monoFont; // } -// +// // // static public Font getPlainFont(int size) { // if (plainFont == null) { @@ -265,8 +265,8 @@ public class Toolkit { // } // return plainFont; // } -// -// +// +// // static public Font getBoldFont(int size) { // if (boldFont == null) { // try { @@ -277,20 +277,21 @@ public class Toolkit { // } // return boldFont; // } - - + + static Font monoFont; static Font monoBoldFont; static Font sansFont; static Font sansBoldFont; - - + + static public Font getMonoFont(int size, int style) { if (monoFont == null) { try { monoFont = createFont("SourceCodePro-Regular.otf", size); monoBoldFont = createFont("SourceCodePro-Semibold.otf", size); } catch (Exception e) { + Base.log("Could not load mono font", e); monoFont = new Font("Monospaced", Font.PLAIN, size); monoBoldFont = new Font("Monospaced", Font.BOLD, size); } @@ -310,11 +311,11 @@ public class Toolkit { return monoFont.deriveFont((float) size); } } -// return style == Font.BOLD ? -// monoBoldFont.deriveFont((float) size) : -// monoFont.deriveFont((float) size); +// return style == Font.BOLD ? +// monoBoldFont.deriveFont((float) size) : +// monoFont.deriveFont((float) size); } - + static public Font getSansFont(int size, int style) { if (sansFont == null) { @@ -322,13 +323,14 @@ public class Toolkit { sansFont = createFont("SourceSansPro-Regular.otf", size); sansBoldFont = createFont("SourceSansPro-Semibold.otf", size); } catch (Exception e) { + Base.log("Could not load sans font", e); sansFont = new Font("Monospaced", Font.PLAIN, size); sansBoldFont = new Font("Monospaced", Font.BOLD, size); } } // System.out.println("deriving new font"); -// return style == Font.BOLD ? -// sansBoldFont.deriveFont((float) size) : +// return style == Font.BOLD ? +// sansBoldFont.deriveFont((float) size) : // sansFont.deriveFont((float) size); if (style == Font.BOLD) { if (size == sansBoldFont.getSize()) { @@ -346,8 +348,8 @@ public class Toolkit { } } } - - + + static private Font createFont(String filename, int size) throws IOException, FontFormatException { InputStream is = Base.getLibStream("fonts/" + filename); BufferedInputStream input = new BufferedInputStream(is); From 765a5c4ea1bc4543447a9cfbfee2176aebf36d6a Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Sat, 1 Jun 2013 13:07:29 -0400 Subject: [PATCH 2/2] trying to fix header --- app/src/processing/app/EditorHeader.java | 33 ++++++++++++------------ 1 file changed, 17 insertions(+), 16 deletions(-) mode change 100644 => 100755 app/src/processing/app/EditorHeader.java diff --git a/app/src/processing/app/EditorHeader.java b/app/src/processing/app/EditorHeader.java old mode 100644 new mode 100755 index afe31b836..ea2bc998e --- a/app/src/processing/app/EditorHeader.java +++ b/app/src/processing/app/EditorHeader.java @@ -47,7 +47,7 @@ public class EditorHeader extends JComponent { static final int TAB_HEIGHT = 27; // amount of margin on the left/right for the text on the tab static final int TEXT_MARGIN = 5; - // width of the tab when no text visible + // width of the tab when no text visible // (total tab width will be this plus TEXT_MARGIN*2) static final int NO_TEXT_WIDTH = 10; @@ -85,7 +85,7 @@ public class EditorHeader extends JComponent { static final int PIECE_WIDTH = 4; static final int PIECE_HEIGHT = 33; Image[][] pieces; - + static final int ARROW_WIDTH = 14; static final int ARROW_HEIGHT = 14; static Image tabArrow; @@ -156,13 +156,13 @@ public class EditorHeader extends JComponent { // protected String tabFile(int status, int where) { // return "theme/tab-" + STATUS[status] + "-" + WHERE[where]; // } - - + + public void updateMode() { Mode mode = editor.getMode(); // int res = Toolkit.isRetina() ? 2 : 1; // String suffix = "-2x.png"; // wishful thinking -// // Some modes may not have a 2x version. If a mode doesn't have a 1x +// // Some modes may not have a 2x version. If a mode doesn't have a 1x // // version, this will cause an error... they should always have 1x. // if (res == 2) { // if (!mode.getContentFile(tabFile(0, 0) + suffix).exists()) { @@ -175,7 +175,7 @@ public class EditorHeader extends JComponent { // suffix = ".gif"; // } // } -// +// // pieces = new Image[STATUS.length][WHERE.length]; // for (int status = 0; status < STATUS.length; status++) { // for (int where = 0; where < WHERE.length; where++) { @@ -183,7 +183,7 @@ public class EditorHeader extends JComponent { // pieces[status][where] = mode.loadImage(tabFile(status, where) + suffix); // } // } - + if (tabArrow == null) { String suffix = Toolkit.highResDisplay() ? "-2x.png" : ".png"; tabArrow = Toolkit.getLibImage("tab-arrow" + suffix); @@ -193,7 +193,7 @@ public class EditorHeader extends JComponent { textColor[SELECTED] = mode.getColor("header.text.selected.color"); textColor[UNSELECTED] = mode.getColor("header.text.unselected.color"); font = mode.getFont("header.text.font"); - + tabColor[SELECTED] = mode.getColor("header.tab.selected.color"); tabColor[UNSELECTED] = mode.getColor("header.tab.unselected.color"); } @@ -238,7 +238,7 @@ public class EditorHeader extends JComponent { fontAscent = metrics.getAscent(); Graphics2D g2 = (Graphics2D) g; - + if (Toolkit.highResDisplay()) { // scale everything 2x, will be scaled down when drawn to the screen g2.scale(2, 2); @@ -251,12 +251,12 @@ public class EditorHeader extends JComponent { // set the background for the offscreen g.setColor(backgroundColor); g.fillRect(0, 0, imageW, imageH); - + // EditorToolbar toolbar = editor.toolbar; // if (toolbar != null && toolbar.backgroundImage != null) { -// g.drawImage(toolbar.backgroundImage, -// 0, -toolbar.getHeight(), -// EditorToolbar.BACKGROUND_WIDTH, +// g.drawImage(toolbar.backgroundImage, +// 0, -toolbar.getHeight(), +// EditorToolbar.BACKGROUND_WIDTH, // EditorToolbar.BACKGROUND_HEIGHT, null); // } editor.getMode().drawBackground(g, EditorToolbar.BUTTON_HEIGHT); @@ -277,7 +277,7 @@ public class EditorHeader extends JComponent { // menuRight = sizeW - 16; // menuLeft = menuRight - pieces[0][MENU].getWidth(this); // menuLeft = menuRight - 50; // FIXME!! - int leftover = + int leftover = ARROW_GAP_WIDTH + ARROW_WIDTH + MARGIN_WIDTH; // + SCROLLBAR_WIDTH; int tabMax = getWidth() - leftover; @@ -329,7 +329,7 @@ public class EditorHeader extends JComponent { menuLeft = tabs[tabs.length - 1].right + ARROW_GAP_WIDTH; menuRight = menuLeft + ARROW_WIDTH; int arrowY = (getHeight() - TAB_HEIGHT) + (TAB_HEIGHT - ARROW_HEIGHT)/2; - g.drawImage(tabArrow, menuLeft, arrowY, + g.drawImage(tabArrow, menuLeft, arrowY, ARROW_WIDTH, ARROW_HEIGHT, null); // g.drawImage(pieces[popup.isVisible() ? SELECTED : UNSELECTED][MENU], // menuLeft, 0, null); @@ -345,7 +345,7 @@ public class EditorHeader extends JComponent { final int bottom = getHeight(); final int top = bottom - TAB_HEIGHT; GeneralPath path = null; - + for (int i = 0; i < sketch.getCodeCount(); i++) { SketchCode code = sketch.getCode(i); Tab tab = tabs[i]; @@ -404,6 +404,7 @@ public class EditorHeader extends JComponent { //g.drawString(sketch.code[i].name, textLeft, baseline); g.drawString(tab.text, textLeft, baseline); g.drawLine(tab.left, baseline-fontAscent, tab.right, baseline-fontAscent); + g.drawLine(tab.left, baseline, tab.right, baseline); } }