Skip to content

Commit bf7749c

Browse files
committed
clearing up this font mess to debug the plain/bold/family issue
1 parent 9074ec5 commit bf7749c

7 files changed

Lines changed: 126 additions & 112 deletions

File tree

app/src/processing/app/syntax/HtmlSelection.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
import java.util.ArrayList;
1010
import java.util.List;
1111

12+
1213
public class HtmlSelection implements Transferable {
1314

14-
private static List<DataFlavor> flavors = new ArrayList<DataFlavor>();
15+
private static List<DataFlavor> flavors;
1516

1617
static {
1718
try {
19+
flavors = new ArrayList<DataFlavor>();
1820
flavors.add(DataFlavor.stringFlavor);
1921
flavors.add(new DataFlavor("text/html;class=java.lang.String"));
2022
flavors.add(new DataFlavor("text/html;class=java.io.Reader"));
@@ -26,18 +28,22 @@ public class HtmlSelection implements Transferable {
2628

2729
private String html;
2830

31+
2932
public HtmlSelection(String html) {
3033
this.html = html;
3134
}
3235

36+
3337
public DataFlavor[] getTransferDataFlavors() {
3438
return flavors.toArray(new DataFlavor[flavors.size()]);
3539
}
3640

41+
3742
public boolean isDataFlavorSupported(DataFlavor flavor) {
3843
return flavors.contains(flavor);
3944
}
4045

46+
4147
public Object getTransferData(DataFlavor flavor)
4248
throws UnsupportedFlavorException {
4349
if (flavor.equals(DataFlavor.stringFlavor)) {

app/src/processing/app/syntax/KeywordMap.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,44 @@ public byte lookup(Segment text, int offset, int length, boolean paren) {
7676
// continue;
7777
// }
7878
if (length == k.keyword.length) {
79-
if (SyntaxUtilities.regionMatches(ignoreCase, text, offset, k.keyword)) {
79+
if (regionMatches(ignoreCase, text, offset, k.keyword)) {
8080
return k.id;
8181
}
8282
}
8383
k = k.next;
8484
}
8585
return Token.NULL;
8686
}
87+
88+
89+
/**
90+
* Checks if a subregion of a <code>Segment</code> is equal to a
91+
* character array.
92+
* @param ignoreCase True if case should be ignored, false otherwise
93+
* @param text The segment
94+
* @param offset The offset into the segment
95+
* @param match The character array to match
96+
*/
97+
static public boolean regionMatches(boolean ignoreCase, Segment text,
98+
int offset, char[] match) {
99+
int length = offset + match.length;
100+
char[] textArray = text.array;
101+
if(length > text.offset + text.count)
102+
return false;
103+
for(int i = offset, j = 0; i < length; i++, j++)
104+
{
105+
char c1 = textArray[i];
106+
char c2 = match[j];
107+
if(ignoreCase)
108+
{
109+
c1 = Character.toUpperCase(c1);
110+
c2 = Character.toUpperCase(c2);
111+
}
112+
if(c1 != c2)
113+
return false;
114+
}
115+
return true;
116+
}
87117

88118

89119
/**

app/src/processing/app/syntax/PdeTextAreaDefaults.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,11 @@ public PdeTextAreaDefaults(Mode mode) {
197197
rows = 5;
198198

199199
//font = Preferences.getFont("editor.font");
200-
font = new Font(Preferences.get("editor.font.family"),
201-
Font.PLAIN, Preferences.getInteger("editor.font.size"));
202-
System.out.println("font is " + font.getFamily() + " / " + font.getName() + " / " + font.getFontName() + " / " + font.getPSName());
200+
String fontFamily = Preferences.get("editor.font.family");
201+
int fontSize = Preferences.getInteger("editor.font.size");
202+
plainFont = new Font(fontFamily, Font.PLAIN, fontSize);
203+
boldFont = new Font(fontFamily, Font.BOLD, fontSize);
204+
//System.out.println("font is " + plainFont.getFamily() + " / " + plainFont.getName() + " / " + plainFont.getFontName() + " / " + plainFont.getPSName());
203205
antialias = Preferences.getBoolean("editor.antialias");
204206

205207
styles = new SyntaxStyle[Token.ID_COUNT];

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515

1616
/**
17-
* A simple text style class. It can specify the color, italic flag,
18-
* and bold flag of a run of text.
17+
* A simple text style class.
18+
* It can specify the color and bold flag of a run of text.
1919
* @author Slava Pestov
2020
* @version $Id$
2121
*/
@@ -27,6 +27,7 @@ public class SyntaxStyle {
2727
private Font lastStyledFont;
2828
private FontMetrics fontMetrics;
2929

30+
3031
/**
3132
* Creates a new SyntaxStyle.
3233
* @param color The text color

app/src/processing/app/syntax/SyntaxUtilities.java

Lines changed: 29 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -22,64 +22,34 @@
2222
*/
2323
public class SyntaxUtilities {
2424

25-
/**
26-
* Checks if a subregion of a <code>Segment</code> is equal to a
27-
* string.
28-
* @param ignoreCase True if case should be ignored, false otherwise
29-
* @param text The segment
30-
* @param offset The offset into the segment
31-
* @param match The string to match
32-
*/
33-
public static boolean regionMatches(boolean ignoreCase, Segment text,
34-
int offset, String match) {
35-
int length = offset + match.length();
36-
char[] textArray = text.array;
37-
if(length > text.offset + text.count)
38-
return false;
39-
for(int i = offset, j = 0; i < length; i++, j++)
40-
{
41-
char c1 = textArray[i];
42-
char c2 = match.charAt(j);
43-
if(ignoreCase)
44-
{
45-
c1 = Character.toUpperCase(c1);
46-
c2 = Character.toUpperCase(c2);
47-
}
48-
if(c1 != c2)
49-
return false;
50-
}
51-
return true;
52-
}
53-
54-
55-
/**
56-
* Checks if a subregion of a <code>Segment</code> is equal to a
57-
* character array.
58-
* @param ignoreCase True if case should be ignored, false otherwise
59-
* @param text The segment
60-
* @param offset The offset into the segment
61-
* @param match The character array to match
62-
*/
63-
public static boolean regionMatches(boolean ignoreCase, Segment text,
64-
int offset, char[] match) {
65-
int length = offset + match.length;
66-
char[] textArray = text.array;
67-
if(length > text.offset + text.count)
68-
return false;
69-
for(int i = offset, j = 0; i < length; i++, j++)
70-
{
71-
char c1 = textArray[i];
72-
char c2 = match[j];
73-
if(ignoreCase)
74-
{
75-
c1 = Character.toUpperCase(c1);
76-
c2 = Character.toUpperCase(c2);
77-
}
78-
if(c1 != c2)
79-
return false;
80-
}
81-
return true;
82-
}
25+
// /**
26+
// * Checks if a subregion of a <code>Segment</code> is equal to a
27+
// * string.
28+
// * @param ignoreCase True if case should be ignored, false otherwise
29+
// * @param text The segment
30+
// * @param offset The offset into the segment
31+
// * @param match The string to match
32+
// */
33+
// public static boolean regionMatches(boolean ignoreCase, Segment text,
34+
// int offset, String match) {
35+
// int length = offset + match.length();
36+
// char[] textArray = text.array;
37+
// if(length > text.offset + text.count)
38+
// return false;
39+
// for(int i = offset, j = 0; i < length; i++, j++)
40+
// {
41+
// char c1 = textArray[i];
42+
// char c2 = match.charAt(j);
43+
// if(ignoreCase)
44+
// {
45+
// c1 = Character.toUpperCase(c1);
46+
// c2 = Character.toUpperCase(c2);
47+
// }
48+
// if(c1 != c2)
49+
// return false;
50+
// }
51+
// return true;
52+
// }
8353

8454

8555
// /**
@@ -107,50 +77,7 @@ public static boolean regionMatches(boolean ignoreCase, Segment text,
10777
// }
10878

10979

110-
/**
111-
* Paints the specified line onto the graphics context. Note that this
112-
* method munges the offset and count values of the segment.
113-
* @param line The line segment
114-
* @param tokens The token list for the line
115-
* @param styles The syntax style list
116-
* @param expander The tab expander used to determine tab stops. May
117-
* be null
118-
* @param gfx The graphics context
119-
* @param x The x co-ordinate
120-
* @param y The y co-ordinate
121-
* @return The x co-ordinate, plus the width of the painted string
122-
*/
123-
public static int paintSyntaxLine(Segment line, Token tokens,
124-
SyntaxStyle[] styles,
125-
TabExpander expander, Graphics gfx,
126-
int x, int y) {
127-
Font defaultFont = gfx.getFont();
128-
Color defaultColor = gfx.getColor();
129-
130-
for (;;) {
131-
byte id = tokens.id;
132-
if(id == Token.END)
133-
break;
134-
135-
int length = tokens.length;
136-
if (id == Token.NULL) {
137-
if(!defaultColor.equals(gfx.getColor()))
138-
gfx.setColor(defaultColor);
139-
if(!defaultFont.equals(gfx.getFont()))
140-
gfx.setFont(defaultFont);
141-
} else {
142-
styles[id].setGraphicsFlags(gfx,defaultFont);
143-
}
144-
line.count = length;
145-
x = Utilities.drawTabbedText(line,x,y,gfx,expander,0);
146-
line.offset += length;
147-
148-
tokens = tokens.next;
149-
}
150-
151-
return x;
152-
}
15380

15481
// private members
155-
private SyntaxUtilities() {}
82+
// private SyntaxUtilities() {}
15683
}

app/src/processing/app/syntax/TextAreaDefaults.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ public class TextAreaDefaults {
4141
public boolean paintInvalid;
4242

4343
// moved from TextAreaPainter [fry]
44-
public Font font;
44+
public Font plainFont;
45+
public Font boldFont;
4546
public Color fgcolor;
4647
public Color bgcolor;
4748
public boolean antialias;

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

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import javax.swing.ToolTipManager;
1616
import javax.swing.text.*;
1717
import javax.swing.JComponent;
18+
1819
import java.awt.event.MouseEvent;
1920
import java.awt.*;
2021
import java.awt.print.*;
@@ -54,7 +55,7 @@ public TextAreaPainter(JEditTextArea textArea, TextAreaDefaults defaults) {
5455
setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
5556

5657
// unfortunately probably can't just do setDefaults() since things aren't quite set up
57-
setFont(defaults.font);
58+
setFont(defaults.plainFont);
5859
// System.out.println("defaults font is " + defaults.font);
5960
setForeground(defaults.fgcolor);
6061
setBackground(defaults.bgcolor);
@@ -611,6 +612,7 @@ protected void paintPlainLine(Graphics gfx, int line, Font defaultFont,
611612
gfx.drawString(".",x,y);
612613
}
613614
}
615+
614616

615617
protected void paintSyntaxLine(Graphics gfx, TokenMarker tokenMarker,
616618
int line, Font defaultFont,
@@ -624,7 +626,7 @@ protected void paintSyntaxLine(Graphics gfx, TokenMarker tokenMarker,
624626
gfx.setFont(defaultFont);
625627
gfx.setColor(defaultColor);
626628
y += fm.getHeight();
627-
x = SyntaxUtilities.paintSyntaxLine(currentLine,
629+
x = paintSyntaxLine(currentLine,
628630
currentLineTokens,
629631
styles, this, gfx, x, y);
630632
/*
@@ -638,6 +640,51 @@ protected void paintSyntaxLine(Graphics gfx, TokenMarker tokenMarker,
638640
gfx.drawString(".",x,y);
639641
}
640642
}
643+
644+
645+
/**
646+
* Paints the specified line onto the graphics context. Note that this
647+
* method munges the offset and count values of the segment.
648+
* @param line The line segment
649+
* @param tokens The token list for the line
650+
* @param styles The syntax style list
651+
* @param expander The tab expander used to determine tab stops. May
652+
* be null
653+
* @param gfx The graphics context
654+
* @param x The x co-ordinate
655+
* @param y The y co-ordinate
656+
* @return The x co-ordinate, plus the width of the painted string
657+
*/
658+
static public int paintSyntaxLine(Segment line, Token tokens,
659+
SyntaxStyle[] styles,
660+
TabExpander expander, Graphics gfx,
661+
int x, int y) {
662+
Font defaultFont = gfx.getFont();
663+
Color defaultColor = gfx.getColor();
664+
665+
for (;;) {
666+
byte id = tokens.id;
667+
if(id == Token.END)
668+
break;
669+
670+
int length = tokens.length;
671+
if (id == Token.NULL) {
672+
if(!defaultColor.equals(gfx.getColor()))
673+
gfx.setColor(defaultColor);
674+
if(!defaultFont.equals(gfx.getFont()))
675+
gfx.setFont(defaultFont);
676+
} else {
677+
styles[id].setGraphicsFlags(gfx,defaultFont);
678+
}
679+
line.count = length;
680+
x = Utilities.drawTabbedText(line,x,y,gfx,expander,0);
681+
line.offset += length;
682+
683+
tokens = tokens.next;
684+
}
685+
686+
return x;
687+
}
641688

642689

643690
protected void paintHighlight(Graphics gfx, int line, int y) {

0 commit comments

Comments
 (0)