aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Schweinsberg <[email protected]>2004-12-09 23:43:33 +0000
committerDavid Schweinsberg <[email protected]>2004-12-09 23:43:33 +0000
commitd7b12ac4bd00a2ab4baa224b73765b7da627528d (patch)
tree8591ba9d2d55843ba5865a0df9242125f7c0fd31
parent66ea4e3dcb2798446fdc6cde948d65b157b52c03 (diff)
Performance enhanced with the handling of the GeneralPath generation
-rw-r--r--src/net/java/dev/typecast/edit/GlyphEdit.java139
-rw-r--r--src/net/java/dev/typecast/edit/PointTool.java42
-rw-r--r--src/net/java/dev/typecast/edit/Tool.java18
3 files changed, 71 insertions, 128 deletions
diff --git a/src/net/java/dev/typecast/edit/GlyphEdit.java b/src/net/java/dev/typecast/edit/GlyphEdit.java
index 131afee..df83264 100644
--- a/src/net/java/dev/typecast/edit/GlyphEdit.java
+++ b/src/net/java/dev/typecast/edit/GlyphEdit.java
@@ -1,5 +1,5 @@
/*
- * $Id: GlyphEdit.java,v 1.1.1.1 2004-12-05 23:14:20 davidsch Exp $
+ * $Id: GlyphEdit.java,v 1.2 2004-12-09 23:43:33 davidsch Exp $
*
* Typecast - The Font Development Environment
*
@@ -44,7 +44,7 @@ import net.java.dev.typecast.ot.Glyph;
/**
*
* @author <a href="mailto:[email protected]">David Schweinsberg</a>
- * @version $Id: GlyphEdit.java,v 1.1.1.1 2004-12-05 23:14:20 davidsch Exp $
+ * @version $Id: GlyphEdit.java,v 1.2 2004-12-09 23:43:33 davidsch Exp $
*/
public class GlyphEdit extends JPanel implements Scrollable {
@@ -53,13 +53,14 @@ public class GlyphEdit extends JPanel implements Scrollable {
private Glyph _glyph = null;
private OTFont _font = null;
private Tool _tool = null;
+ private GeneralPath _glyphPath;
private int _translateX = 0;
private int _translateY = 0;
private float _scaleFactor = 0.25f;
private boolean _drawControlPoints = true;
- private boolean _preview = true;
+ private boolean _preview = false;
private Set<Point> _selectedPoints = new HashSet<Point>();
//private static final String PROP_SAMPLE_PROPERTY = "SampleProperty";
@@ -164,20 +165,26 @@ public class GlyphEdit extends JPanel implements Scrollable {
int count = 0;
int i;
- GeneralPath gp = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
- for (i = 0; i < _glyph.getPointCount(); i++) {
- count++;
- if (_glyph.getPoint(i).endOfContour) {
-// drawContour(g2d, firstIndex, count);
- addContourToPath(gp, firstIndex, count);
- firstIndex = i + 1;
- count = 0;
+ if (_glyphPath == null) {
+ _glyphPath = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
+
+ // Iterate through all of the points in the glyph. Each time we find a
+ // contour end point, add the point range to the path.
+ for (i = 0; i < _glyph.getPointCount(); i++) {
+ count++;
+ if (_glyph.getPoint(i).endOfContour) {
+ addContourToPath(_glyphPath, firstIndex, count);
+ firstIndex = i + 1;
+ count = 0;
+ }
}
}
+
+ // Render the glyph path
if (_preview) {
- g2d.fill(gp);
+ g2d.fill(_glyphPath);
} else {
- g2d.draw(gp);
+ g2d.draw(_glyphPath);
}
if (_drawControlPoints) {
@@ -264,95 +271,6 @@ public class GlyphEdit extends JPanel implements Scrollable {
}
}
- private void drawContour(Graphics2D g2d, int startIndex, int count) {
- int offset = 0;
-// while (offset < (startIndex + count)) {
- while (offset < count) {
- Point point_minus1 = _glyph.getPoint((offset==0) ? startIndex+count-1 : startIndex+(offset-1)%count);
- Point point = _glyph.getPoint(startIndex + offset%count);
- Point point_plus1 = _glyph.getPoint(startIndex + (offset+1)%count);
- Point point_plus2 = _glyph.getPoint(startIndex + (offset+2)%count);
- if (point.onCurve && point_plus1.onCurve) {
- Line2D.Float line = new Line2D.Float(point.x, -point.y, point_plus1.x, -point_plus1.y);
- if (_preview) {
- g2d.fill(line);
- } else {
- g2d.draw(line);
- }
- offset++;
- } else if (point.onCurve && !point_plus1.onCurve && point_plus2.onCurve) {
- QuadCurve2D.Float curve = new QuadCurve2D.Float(
- point.x,
- -point.y,
- point_plus1.x,
- -point_plus1.y,
- point_plus2.x,
- -point_plus2.y);
- if (_preview) {
- g2d.fill(curve);
- } else {
- g2d.draw(curve);
- }
- offset+=2;
- } else if (point.onCurve && !point_plus1.onCurve && !point_plus2.onCurve) {
- QuadCurve2D.Float curve = new QuadCurve2D.Float(
- point.x,
- -point.y,
- point_plus1.x,
- -point_plus1.y,
- midValue(point_plus1.x, point_plus2.x),
- -midValue(point_plus1.y, point_plus2.y));
- if (_preview) {
- g2d.fill(curve);
- } else {
- g2d.draw(curve);
- }
- offset+=2;
- } else if (!point.onCurve && !point_plus1.onCurve) {
- QuadCurve2D.Float curve = new QuadCurve2D.Float(
- midValue(point_minus1.x, point.x),
- -midValue(point_minus1.y, point.y),
- point.x,
- -point.y,
- midValue(point.x, point_plus1.x),
- -midValue(point.y, point_plus1.y));
- if (_preview) {
- g2d.fill(curve);
- } else {
- g2d.draw(curve);
- }
- offset++;
- } else if (!point.onCurve && point_plus1.onCurve) {
- QuadCurve2D.Float curve = new QuadCurve2D.Float(
- midValue(point_minus1.x, point.x),
- -midValue(point_minus1.y, point.y),
- point.x,
- -point.y,
- point_plus1.x,
- -point_plus1.y);
- if (_preview) {
- g2d.fill(curve);
- } else {
- g2d.draw(curve);
- }
- offset++;
- } else {
- System.out.println("drawGlyph case not catered for!!");
- break;
- }
- }
- }
-/*
- private static int getCurveValue(long t, long p0, long p1, long p2) {
- return (int)((((0x40-t)*(0x40-t)*p0)>>12)
- + ((0x80*t*(0x40-t)*p1)>>18)
- + ((t*t*p2)>>12));
- }
-*/
-// public int getGlyphIndex() {
-// return glyphIndex;
-// }
-
private static int midValue(int a, int b) {
return a + (b - a)/2;
}
@@ -362,7 +280,13 @@ public class GlyphEdit extends JPanel implements Scrollable {
}
public void setGlyph(Glyph glyph) {
- this._glyph = glyph;
+
+ // Check if we actually have any work to do
+ //if (_glyph == glyph) {
+ // return;
+ //}
+
+ _glyph = glyph;
// How much space does this glyph need?
// xOrigin = 0x5000;
@@ -370,9 +294,16 @@ public class GlyphEdit extends JPanel implements Scrollable {
setPreferredSize(new Dimension(1024, 1024));
setSize(new Dimension(1024, 1024));
+
+ // We have a new glyph, so repaint
+ _glyphPath = null;
invalidate();
repaint();
}
+
+ public void modified() {
+ _glyphPath = null;
+ }
public int getTranslateX() {
return _translateX;
@@ -427,7 +358,7 @@ public class GlyphEdit extends JPanel implements Scrollable {
// }
public void setFont(OTFont font) {
- this._font = font;
+ _font = font;
// glyph = font.getGlyph(glyphIndex);
_glyph = null;
// repaint();
diff --git a/src/net/java/dev/typecast/edit/PointTool.java b/src/net/java/dev/typecast/edit/PointTool.java
index 27a9394..bf3f0d1 100644
--- a/src/net/java/dev/typecast/edit/PointTool.java
+++ b/src/net/java/dev/typecast/edit/PointTool.java
@@ -1,5 +1,5 @@
/*
- * $Id: PointTool.java,v 1.1.1.1 2004-12-05 23:14:20 davidsch Exp $
+ * $Id: PointTool.java,v 1.2 2004-12-09 23:43:33 davidsch Exp $
*
* Typecast - The Font Development Environment
*
@@ -30,7 +30,7 @@ import net.java.dev.typecast.ot.Glyph;
/**
*
* @author <a href="mailto:[email protected]">David Schweinsberg</a>
- * @version $Id: PointTool.java,v 1.1.1.1 2004-12-05 23:14:20 davidsch Exp $
+ * @version $Id: PointTool.java,v 1.2 2004-12-09 23:43:33 davidsch Exp $
*/
public class PointTool extends Tool {
@@ -39,11 +39,18 @@ public class PointTool extends Tool {
/** Creates new PointTool */
public PointTool(GlyphEdit glyphEdit) {
- this._glyphEdit = glyphEdit;
- glyphEdit.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
+ _glyphEdit = glyphEdit;
+
+ // BUG: The crosshair cursor keeps coming up as a text cursor on my
+ // Windows XP system :-(
+ //_glyphEdit.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
+ _glyphEdit.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
- void pressed(Point p) {
+ /**
+ * Selects a point
+ */
+ public void pressed(Point p) {
_glyphEdit.getSelectedPoints().clear();
Glyph glyph = _glyphEdit.getGlyph();
for (int i = 0; i < glyph.getPointCount(); i++) {
@@ -55,10 +62,14 @@ public class PointTool extends Tool {
_glyphEdit.getSelectedPoints().add(gp);
}
}
+ _glyphEdit.modified();
_glyphEdit.repaint();
}
- void pressedControl(Point p) {
+ /**
+ * Toggles the selected point between on-curve and off-curve
+ */
+ public void pressedControl(Point p) {
Glyph glyph = _glyphEdit.getGlyph();
for (int i = 0; i < glyph.getPointCount(); i++) {
net.java.dev.typecast.ot.Point gp = glyph.getPoint(i);
@@ -69,10 +80,14 @@ public class PointTool extends Tool {
gp.onCurve = !gp.onCurve;
}
}
+ _glyphEdit.modified();
_glyphEdit.repaint();
}
- void dragged(Point p) {
+ /**
+ * Moves the selected points
+ */
+ public void dragged(Point p) {
int x = (int)(p.x / _glyphEdit.getScaleFactor() - _glyphEdit.getTranslateX());
int y = -(int)(p.y / _glyphEdit.getScaleFactor() - _glyphEdit.getTranslateY());
Iterator iter = _glyphEdit.getSelectedPoints().iterator();
@@ -81,14 +96,13 @@ public class PointTool extends Tool {
gp.x = x;
gp.y = y;
}
+ _glyphEdit.modified();
_glyphEdit.repaint();
}
-
- void released(Point p) {
+
+ /**
+ * nop
+ */
+ public void released(Point p) {
}
-
-// void setCursor(Window window) {
-// window.setCursor(Cursor.CROSSHAIR_CURSOR);
-// }
-
}
diff --git a/src/net/java/dev/typecast/edit/Tool.java b/src/net/java/dev/typecast/edit/Tool.java
index 967dfa2..a1a710f 100644
--- a/src/net/java/dev/typecast/edit/Tool.java
+++ b/src/net/java/dev/typecast/edit/Tool.java
@@ -1,5 +1,5 @@
/*
- * $Id: Tool.java,v 1.1.1.1 2004-12-05 23:14:20 davidsch Exp $
+ * $Id: Tool.java,v 1.2 2004-12-09 23:43:33 davidsch Exp $
*
* Typecast - The Font Development Environment
*
@@ -26,17 +26,15 @@ import java.awt.Window;
/**
*
* @author <a href="mailto:[email protected]">David Schweinsberg</a>
- * @version $Id: Tool.java,v 1.1.1.1 2004-12-05 23:14:20 davidsch Exp $
+ * @version $Id: Tool.java,v 1.2 2004-12-09 23:43:33 davidsch Exp $
*/
public abstract class Tool {
- /** Creates new Tool */
-// public Tool() {
-// }
+ public abstract void pressed(Point p);
-// abstract void setCursor(Window window);
- abstract void pressed(Point p);
- abstract void pressedControl(Point p);
- abstract void released(Point p);
- abstract void dragged(Point p);
+ public abstract void pressedControl(Point p);
+
+ public abstract void released(Point p);
+
+ public abstract void dragged(Point p);
}