mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
clearing up this font mess to debug the plain/bold/family issue
This commit is contained in:
@@ -9,12 +9,14 @@ import java.io.StringReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class HtmlSelection implements Transferable {
|
||||
|
||||
private static List<DataFlavor> flavors = new ArrayList<DataFlavor>();
|
||||
private static List<DataFlavor> flavors;
|
||||
|
||||
static {
|
||||
try {
|
||||
flavors = new ArrayList<DataFlavor>();
|
||||
flavors.add(DataFlavor.stringFlavor);
|
||||
flavors.add(new DataFlavor("text/html;class=java.lang.String"));
|
||||
flavors.add(new DataFlavor("text/html;class=java.io.Reader"));
|
||||
@@ -26,18 +28,22 @@ public class HtmlSelection implements Transferable {
|
||||
|
||||
private String html;
|
||||
|
||||
|
||||
public HtmlSelection(String html) {
|
||||
this.html = html;
|
||||
}
|
||||
|
||||
|
||||
public DataFlavor[] getTransferDataFlavors() {
|
||||
return flavors.toArray(new DataFlavor[flavors.size()]);
|
||||
}
|
||||
|
||||
|
||||
public boolean isDataFlavorSupported(DataFlavor flavor) {
|
||||
return flavors.contains(flavor);
|
||||
}
|
||||
|
||||
|
||||
public Object getTransferData(DataFlavor flavor)
|
||||
throws UnsupportedFlavorException {
|
||||
if (flavor.equals(DataFlavor.stringFlavor)) {
|
||||
|
||||
@@ -76,7 +76,7 @@ public class KeywordMap {
|
||||
// continue;
|
||||
// }
|
||||
if (length == k.keyword.length) {
|
||||
if (SyntaxUtilities.regionMatches(ignoreCase, text, offset, k.keyword)) {
|
||||
if (regionMatches(ignoreCase, text, offset, k.keyword)) {
|
||||
return k.id;
|
||||
}
|
||||
}
|
||||
@@ -84,6 +84,36 @@ public class KeywordMap {
|
||||
}
|
||||
return Token.NULL;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if a subregion of a <code>Segment</code> is equal to a
|
||||
* character array.
|
||||
* @param ignoreCase True if case should be ignored, false otherwise
|
||||
* @param text The segment
|
||||
* @param offset The offset into the segment
|
||||
* @param match The character array to match
|
||||
*/
|
||||
static public boolean regionMatches(boolean ignoreCase, Segment text,
|
||||
int offset, char[] match) {
|
||||
int length = offset + match.length;
|
||||
char[] textArray = text.array;
|
||||
if(length > text.offset + text.count)
|
||||
return false;
|
||||
for(int i = offset, j = 0; i < length; i++, j++)
|
||||
{
|
||||
char c1 = textArray[i];
|
||||
char c2 = match[j];
|
||||
if(ignoreCase)
|
||||
{
|
||||
c1 = Character.toUpperCase(c1);
|
||||
c2 = Character.toUpperCase(c2);
|
||||
}
|
||||
if(c1 != c2)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -197,9 +197,11 @@ public class PdeTextAreaDefaults extends TextAreaDefaults {
|
||||
rows = 5;
|
||||
|
||||
//font = Preferences.getFont("editor.font");
|
||||
font = new Font(Preferences.get("editor.font.family"),
|
||||
Font.PLAIN, Preferences.getInteger("editor.font.size"));
|
||||
System.out.println("font is " + font.getFamily() + " / " + font.getName() + " / " + font.getFontName() + " / " + font.getPSName());
|
||||
String fontFamily = Preferences.get("editor.font.family");
|
||||
int fontSize = Preferences.getInteger("editor.font.size");
|
||||
plainFont = new Font(fontFamily, Font.PLAIN, fontSize);
|
||||
boldFont = new Font(fontFamily, Font.BOLD, fontSize);
|
||||
//System.out.println("font is " + plainFont.getFamily() + " / " + plainFont.getName() + " / " + plainFont.getFontName() + " / " + plainFont.getPSName());
|
||||
antialias = Preferences.getBoolean("editor.antialias");
|
||||
|
||||
styles = new SyntaxStyle[Token.ID_COUNT];
|
||||
|
||||
@@ -14,8 +14,8 @@ import javax.swing.JComponent;
|
||||
|
||||
|
||||
/**
|
||||
* A simple text style class. It can specify the color, italic flag,
|
||||
* and bold flag of a run of text.
|
||||
* A simple text style class.
|
||||
* It can specify the color and bold flag of a run of text.
|
||||
* @author Slava Pestov
|
||||
* @version $Id$
|
||||
*/
|
||||
@@ -27,6 +27,7 @@ public class SyntaxStyle {
|
||||
private Font lastStyledFont;
|
||||
private FontMetrics fontMetrics;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new SyntaxStyle.
|
||||
* @param color The text color
|
||||
|
||||
@@ -22,64 +22,34 @@ import java.awt.*;
|
||||
*/
|
||||
public class SyntaxUtilities {
|
||||
|
||||
/**
|
||||
* Checks if a subregion of a <code>Segment</code> is equal to a
|
||||
* string.
|
||||
* @param ignoreCase True if case should be ignored, false otherwise
|
||||
* @param text The segment
|
||||
* @param offset The offset into the segment
|
||||
* @param match The string to match
|
||||
*/
|
||||
public static boolean regionMatches(boolean ignoreCase, Segment text,
|
||||
int offset, String match) {
|
||||
int length = offset + match.length();
|
||||
char[] textArray = text.array;
|
||||
if(length > text.offset + text.count)
|
||||
return false;
|
||||
for(int i = offset, j = 0; i < length; i++, j++)
|
||||
{
|
||||
char c1 = textArray[i];
|
||||
char c2 = match.charAt(j);
|
||||
if(ignoreCase)
|
||||
{
|
||||
c1 = Character.toUpperCase(c1);
|
||||
c2 = Character.toUpperCase(c2);
|
||||
}
|
||||
if(c1 != c2)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if a subregion of a <code>Segment</code> is equal to a
|
||||
* character array.
|
||||
* @param ignoreCase True if case should be ignored, false otherwise
|
||||
* @param text The segment
|
||||
* @param offset The offset into the segment
|
||||
* @param match The character array to match
|
||||
*/
|
||||
public static boolean regionMatches(boolean ignoreCase, Segment text,
|
||||
int offset, char[] match) {
|
||||
int length = offset + match.length;
|
||||
char[] textArray = text.array;
|
||||
if(length > text.offset + text.count)
|
||||
return false;
|
||||
for(int i = offset, j = 0; i < length; i++, j++)
|
||||
{
|
||||
char c1 = textArray[i];
|
||||
char c2 = match[j];
|
||||
if(ignoreCase)
|
||||
{
|
||||
c1 = Character.toUpperCase(c1);
|
||||
c2 = Character.toUpperCase(c2);
|
||||
}
|
||||
if(c1 != c2)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// /**
|
||||
// * Checks if a subregion of a <code>Segment</code> is equal to a
|
||||
// * string.
|
||||
// * @param ignoreCase True if case should be ignored, false otherwise
|
||||
// * @param text The segment
|
||||
// * @param offset The offset into the segment
|
||||
// * @param match The string to match
|
||||
// */
|
||||
// public static boolean regionMatches(boolean ignoreCase, Segment text,
|
||||
// int offset, String match) {
|
||||
// int length = offset + match.length();
|
||||
// char[] textArray = text.array;
|
||||
// if(length > text.offset + text.count)
|
||||
// return false;
|
||||
// for(int i = offset, j = 0; i < length; i++, j++)
|
||||
// {
|
||||
// char c1 = textArray[i];
|
||||
// char c2 = match.charAt(j);
|
||||
// if(ignoreCase)
|
||||
// {
|
||||
// c1 = Character.toUpperCase(c1);
|
||||
// c2 = Character.toUpperCase(c2);
|
||||
// }
|
||||
// if(c1 != c2)
|
||||
// return false;
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
|
||||
|
||||
// /**
|
||||
@@ -107,50 +77,7 @@ public class SyntaxUtilities {
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* Paints the specified line onto the graphics context. Note that this
|
||||
* method munges the offset and count values of the segment.
|
||||
* @param line The line segment
|
||||
* @param tokens The token list for the line
|
||||
* @param styles The syntax style list
|
||||
* @param expander The tab expander used to determine tab stops. May
|
||||
* be null
|
||||
* @param gfx The graphics context
|
||||
* @param x The x co-ordinate
|
||||
* @param y The y co-ordinate
|
||||
* @return The x co-ordinate, plus the width of the painted string
|
||||
*/
|
||||
public static int paintSyntaxLine(Segment line, Token tokens,
|
||||
SyntaxStyle[] styles,
|
||||
TabExpander expander, Graphics gfx,
|
||||
int x, int y) {
|
||||
Font defaultFont = gfx.getFont();
|
||||
Color defaultColor = gfx.getColor();
|
||||
|
||||
for (;;) {
|
||||
byte id = tokens.id;
|
||||
if(id == Token.END)
|
||||
break;
|
||||
|
||||
int length = tokens.length;
|
||||
if (id == Token.NULL) {
|
||||
if(!defaultColor.equals(gfx.getColor()))
|
||||
gfx.setColor(defaultColor);
|
||||
if(!defaultFont.equals(gfx.getFont()))
|
||||
gfx.setFont(defaultFont);
|
||||
} else {
|
||||
styles[id].setGraphicsFlags(gfx,defaultFont);
|
||||
}
|
||||
line.count = length;
|
||||
x = Utilities.drawTabbedText(line,x,y,gfx,expander,0);
|
||||
line.offset += length;
|
||||
|
||||
tokens = tokens.next;
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
// private members
|
||||
private SyntaxUtilities() {}
|
||||
// private SyntaxUtilities() {}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,8 @@ public class TextAreaDefaults {
|
||||
public boolean paintInvalid;
|
||||
|
||||
// moved from TextAreaPainter [fry]
|
||||
public Font font;
|
||||
public Font plainFont;
|
||||
public Font boldFont;
|
||||
public Color fgcolor;
|
||||
public Color bgcolor;
|
||||
public boolean antialias;
|
||||
|
||||
@@ -15,6 +15,7 @@ import processing.app.syntax.im.CompositionTextPainter;
|
||||
import javax.swing.ToolTipManager;
|
||||
import javax.swing.text.*;
|
||||
import javax.swing.JComponent;
|
||||
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.*;
|
||||
import java.awt.print.*;
|
||||
@@ -54,7 +55,7 @@ implements TabExpander, Printable {
|
||||
setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
|
||||
|
||||
// unfortunately probably can't just do setDefaults() since things aren't quite set up
|
||||
setFont(defaults.font);
|
||||
setFont(defaults.plainFont);
|
||||
// System.out.println("defaults font is " + defaults.font);
|
||||
setForeground(defaults.fgcolor);
|
||||
setBackground(defaults.bgcolor);
|
||||
@@ -611,6 +612,7 @@ implements TabExpander, Printable {
|
||||
gfx.drawString(".",x,y);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void paintSyntaxLine(Graphics gfx, TokenMarker tokenMarker,
|
||||
int line, Font defaultFont,
|
||||
@@ -624,7 +626,7 @@ implements TabExpander, Printable {
|
||||
gfx.setFont(defaultFont);
|
||||
gfx.setColor(defaultColor);
|
||||
y += fm.getHeight();
|
||||
x = SyntaxUtilities.paintSyntaxLine(currentLine,
|
||||
x = paintSyntaxLine(currentLine,
|
||||
currentLineTokens,
|
||||
styles, this, gfx, x, y);
|
||||
/*
|
||||
@@ -638,6 +640,51 @@ implements TabExpander, Printable {
|
||||
gfx.drawString(".",x,y);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Paints the specified line onto the graphics context. Note that this
|
||||
* method munges the offset and count values of the segment.
|
||||
* @param line The line segment
|
||||
* @param tokens The token list for the line
|
||||
* @param styles The syntax style list
|
||||
* @param expander The tab expander used to determine tab stops. May
|
||||
* be null
|
||||
* @param gfx The graphics context
|
||||
* @param x The x co-ordinate
|
||||
* @param y The y co-ordinate
|
||||
* @return The x co-ordinate, plus the width of the painted string
|
||||
*/
|
||||
static public int paintSyntaxLine(Segment line, Token tokens,
|
||||
SyntaxStyle[] styles,
|
||||
TabExpander expander, Graphics gfx,
|
||||
int x, int y) {
|
||||
Font defaultFont = gfx.getFont();
|
||||
Color defaultColor = gfx.getColor();
|
||||
|
||||
for (;;) {
|
||||
byte id = tokens.id;
|
||||
if(id == Token.END)
|
||||
break;
|
||||
|
||||
int length = tokens.length;
|
||||
if (id == Token.NULL) {
|
||||
if(!defaultColor.equals(gfx.getColor()))
|
||||
gfx.setColor(defaultColor);
|
||||
if(!defaultFont.equals(gfx.getFont()))
|
||||
gfx.setFont(defaultFont);
|
||||
} else {
|
||||
styles[id].setGraphicsFlags(gfx,defaultFont);
|
||||
}
|
||||
line.count = length;
|
||||
x = Utilities.drawTabbedText(line,x,y,gfx,expander,0);
|
||||
line.offset += length;
|
||||
|
||||
tokens = tokens.next;
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
protected void paintHighlight(Graphics gfx, int line, int y) {
|
||||
|
||||
Reference in New Issue
Block a user