Skip to content

Commit de57b37

Browse files
committed
in-progress font work
1 parent 5f94c59 commit de57b37

7 files changed

Lines changed: 143 additions & 53 deletions

File tree

app/src/processing/app/EditorHeader.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,10 +398,12 @@ private boolean placeTabs(int left, int right, Graphics2D g) {
398398
int textLeft = tab.left + ((tab.right - tab.left) - tab.textWidth) / 2;
399399
g.setColor(textColor[state]);
400400
// int baseline = (int) Math.ceil((sizeH + fontAscent) / 2.0);
401-
int baseline = bottom - (TAB_HEIGHT - fontAscent)/2;
401+
//int baseline = bottom - (TAB_HEIGHT - fontAscent)/2;
402+
int tabHeight = TAB_HEIGHT; //bottom - top;
403+
int baseline = top + (tabHeight + fontAscent) / 2;
402404
//g.drawString(sketch.code[i].name, textLeft, baseline);
403405
g.drawString(tab.text, textLeft, baseline);
404-
// g.drawLine(tab.left, baseline-fontAscent, tab.right, baseline-fontAscent);
406+
g.drawLine(tab.left, baseline-fontAscent, tab.right, baseline-fontAscent);
405407
}
406408
}
407409

app/src/processing/app/Preferences.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -969,13 +969,9 @@ static public Font getFont(String attr) {
969969

970970
} else {
971971
if (pieces[0].equals("processing.sans")) {
972-
if (style == Font.BOLD) {
973-
return Toolkit.getBoldFont(size);
974-
} else {
975-
return Toolkit.getPlainFont(size);
976-
}
972+
return Toolkit.getSansFont(size, style);
977973
} else if (pieces[0].equals("processing.mono")) {
978-
return Toolkit.getMonoFont(size);
974+
return Toolkit.getMonoFont(size, style);
979975
}
980976
}
981977

app/src/processing/app/Settings.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,9 @@ public Font getFont(String attr) {
215215

216216
} else {
217217
if (pieces[0].equals("processing.sans")) {
218-
if (style == Font.BOLD) {
219-
return Toolkit.getBoldFont(size);
220-
} else {
221-
return Toolkit.getPlainFont(size);
222-
}
218+
return Toolkit.getSansFont(size, style);
223219
} else if (pieces[0].equals("processing.mono")) {
224-
return Toolkit.getMonoFont(size);
220+
return Toolkit.getMonoFont(size, style);
225221
}
226222
}
227223

app/src/processing/app/Toolkit.java

Lines changed: 91 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -238,47 +238,116 @@ static public boolean highResDisplay() {
238238
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
239239

240240

241+
// static Font monoFont;
242+
// static Font plainFont;
243+
// static Font boldFont;
244+
//
245+
//
246+
// static public Font getMonoFont(int size) {
247+
// if (monoFont == null) {
248+
// try {
249+
// monoFont = createFont("DroidSansMono.ttf", size);
250+
// } catch (Exception e) {
251+
// monoFont = new Font("Monospaced", Font.PLAIN, size);
252+
// }
253+
// }
254+
// return monoFont;
255+
// }
256+
//
257+
//
258+
// static public Font getPlainFont(int size) {
259+
// if (plainFont == null) {
260+
// try {
261+
// plainFont = createFont("DroidSans.ttf", size);
262+
// } catch (Exception e) {
263+
// plainFont = new Font("SansSerif", Font.PLAIN, size);
264+
// }
265+
// }
266+
// return plainFont;
267+
// }
268+
//
269+
//
270+
// static public Font getBoldFont(int size) {
271+
// if (boldFont == null) {
272+
// try {
273+
// boldFont = createFont("DroidSans-Bold.ttf", size);
274+
// } catch (Exception e) {
275+
// boldFont = new Font("SansSerif", Font.BOLD, size);
276+
// }
277+
// }
278+
// return boldFont;
279+
// }
280+
281+
241282
static Font monoFont;
242-
static Font plainFont;
243-
static Font boldFont;
283+
static Font monoBoldFont;
284+
static Font sansFont;
285+
static Font sansBoldFont;
244286

245287

246-
static public Font getMonoFont(int size) {
288+
static public Font getMonoFont(int size, int style) {
247289
if (monoFont == null) {
248290
try {
249-
monoFont = createFont("DroidSansMono.ttf", size);
291+
monoFont = createFont("SourceCodePro-Regular.otf", size);
292+
monoBoldFont = createFont("SourceCodePro-Semibold.otf", size);
250293
} catch (Exception e) {
251294
monoFont = new Font("Monospaced", Font.PLAIN, size);
295+
monoBoldFont = new Font("Monospaced", Font.BOLD, size);
296+
}
297+
}
298+
if (style == Font.BOLD) {
299+
if (size == monoBoldFont.getSize()) {
300+
return monoBoldFont;
301+
} else {
302+
// System.out.println("deriving new font");
303+
return monoBoldFont.deriveFont((float) size);
304+
}
305+
} else {
306+
if (size == monoFont.getSize()) {
307+
return monoFont;
308+
} else {
309+
// System.out.println("deriving new font");
310+
return monoFont.deriveFont((float) size);
252311
}
253312
}
254-
return monoFont;
313+
// return style == Font.BOLD ?
314+
// monoBoldFont.deriveFont((float) size) :
315+
// monoFont.deriveFont((float) size);
255316
}
256317

257318

258-
static public Font getPlainFont(int size) {
259-
if (plainFont == null) {
319+
static public Font getSansFont(int size, int style) {
320+
if (sansFont == null) {
260321
try {
261-
plainFont = createFont("DroidSans.ttf", size);
322+
sansFont = createFont("SourceSansPro-Regular.otf", size);
323+
sansBoldFont = createFont("SourceSansPro-Semibold.otf", size);
262324
} catch (Exception e) {
263-
plainFont = new Font("SansSerif", Font.PLAIN, size);
325+
sansFont = new Font("Monospaced", Font.PLAIN, size);
326+
sansBoldFont = new Font("Monospaced", Font.BOLD, size);
264327
}
265328
}
266-
return plainFont;
267-
}
268-
269-
270-
static public Font getBoldFont(int size) {
271-
if (boldFont == null) {
272-
try {
273-
boldFont = createFont("DroidSans-Bold.ttf", size);
274-
} catch (Exception e) {
275-
boldFont = new Font("SansSerif", Font.BOLD, size);
329+
// System.out.println("deriving new font");
330+
// return style == Font.BOLD ?
331+
// sansBoldFont.deriveFont((float) size) :
332+
// sansFont.deriveFont((float) size);
333+
if (style == Font.BOLD) {
334+
if (size == sansBoldFont.getSize()) {
335+
return sansBoldFont;
336+
} else {
337+
// System.out.println("deriving new font");
338+
return sansBoldFont.deriveFont((float) size);
339+
}
340+
} else {
341+
if (size == sansFont.getSize()) {
342+
return sansFont;
343+
} else {
344+
// System.out.println("deriving new font");
345+
return sansFont.deriveFont((float) size);
276346
}
277347
}
278-
return boldFont;
279348
}
280-
281-
349+
350+
282351
static private Font createFont(String filename, int size) throws IOException, FontFormatException {
283352
InputStream is = Base.getLibStream("fonts/" + filename);
284353
BufferedInputStream input = new BufferedInputStream(is);

app/src/processing/app/syntax/SyntaxStyle.java

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,32 +78,60 @@ public Font getStyledFont(Font font)
7878
if(font.equals(lastFont))
7979
return lastStyledFont;
8080
lastFont = font;
81-
lastStyledFont = new Font(font.getFamily(),
82-
(bold ? Font.BOLD : 0)
83-
| (italic ? Font.ITALIC : 0),
84-
font.getSize());
81+
// lastStyledFont = new Font(font.getFamily(),
82+
// (bold ? Font.BOLD : 0)
83+
// | (italic ? Font.ITALIC : 0),
84+
// font.getSize());
85+
lastStyledFont =
86+
findFont(font.getFamily(), bold ? Font.BOLD : Font.PLAIN, font.getSize());
8587
return lastStyledFont;
8688
}
8789

8890
/**
8991
* Returns the font metrics for the styled font.
9092
*/
91-
public FontMetrics getFontMetrics(Font font, JComponent comp)
92-
{
93-
if(font == null)
94-
throw new NullPointerException("font param must not"
95-
+ " be null");
96-
if(font.equals(lastFont) && fontMetrics != null)
93+
public FontMetrics getFontMetrics(Font font, JComponent comp) {
94+
if (font == null) {
95+
throw new NullPointerException("font param must not be null");
96+
}
97+
if (font.equals(lastFont) && fontMetrics != null) {
9798
return fontMetrics;
99+
}
98100
lastFont = font;
99-
lastStyledFont = new Font(font.getFamily(),
100-
(bold ? Font.BOLD : 0)
101-
| (italic ? Font.ITALIC : 0),
102-
font.getSize());
101+
// lastStyledFont = new Font(font.getFamily(),
102+
// (bold ? Font.BOLD : 0)
103+
// | (italic ? Font.ITALIC : 0),
104+
// font.getSize());
105+
lastStyledFont =
106+
findFont(font.getFamily(), bold ? Font.BOLD : Font.PLAIN, font.getSize());
107+
103108
//fontMetrics = Toolkit.getDefaultToolkit().getFontMetrics(lastStyledFont);
104109
fontMetrics = comp.getFontMetrics(lastStyledFont);
105110
return fontMetrics;
106111
}
112+
113+
private String monoFontFamily;
114+
115+
private Font findFont(String familyName, int style, int size) {
116+
if (monoFontFamily == null) {
117+
// Just get the font family name for comparison
118+
monoFontFamily =
119+
processing.app.Toolkit.getMonoFont(size, style).getFamily();
120+
//processing.app.Toolkit.getMonoFont(size, style).getFamily();
121+
// Font mono = processing.app.Toolkit.getMonoFont(size, style);
122+
// System.out.println("mono family " + mono.getFamily());
123+
// System.out.println("mono fontname " + mono.getFontName());
124+
// System.out.println("mono name " + mono.getName());
125+
// System.out.println("mono psname " + mono.getPSName());
126+
}
127+
if (familyName.equals(monoFontFamily)) {
128+
// System.out.println("getting style bold? " + (style == Font.BOLD));
129+
return processing.app.Toolkit.getMonoFont(size, style);
130+
} else {
131+
// System.out.println("name is " + name + " mono name is " + monoFontName + " " + style);
132+
return new Font(familyName, style, size);
133+
}
134+
}
107135

108136
/**
109137
* Sets the foreground color and font of the specified graphics

app/src/processing/app/syntax/TextAreaPainter.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
* @author Slava Pestov
2727
*/
2828
public class TextAreaPainter extends JComponent
29-
implements TabExpander, Printable
30-
{
29+
implements TabExpander, Printable {
3130
/** True if inside printing, will handle disabling the highlight */
3231
boolean printing;
3332
/** Current setting for editor.antialias preference */

build/shared/lib/theme.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ header.text.selected.color = #000000
1818
header.text.unselected.color = #ffffff
1919
#header.text.font = SansSerif,plain,12
2020
#header.text.font.macosx = Helvetica,plain,12
21-
header.text.font = processing.sans,plain,12
21+
header.text.font = processing.sans,plain,16
2222
header.tab.selected.color = #a2afba
2323
header.tab.unselected.color = #2a4159
2424

0 commit comments

Comments
 (0)