aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Schweinsberg <[email protected]>2016-01-04 17:28:51 -0800
committerDavid Schweinsberg <[email protected]>2016-01-04 17:28:51 -0800
commit49b6c2a3a3d852a31c8a09ae49e1ab953eec318b (patch)
tree428a061d715a960149aba8f4da8da0d1ef41b23e
parentbe490e50806d78ce81697f6bf360f522d5a44f02 (diff)
Added building of contours with cubic curves
-rw-r--r--src/net/java/dev/typecast/edit/GlyphEdit.java56
-rw-r--r--src/net/java/dev/typecast/render/GlyphPathFactory.java53
2 files changed, 55 insertions, 54 deletions
diff --git a/src/net/java/dev/typecast/edit/GlyphEdit.java b/src/net/java/dev/typecast/edit/GlyphEdit.java
index 1dd8a2d..66f76c9 100644
--- a/src/net/java/dev/typecast/edit/GlyphEdit.java
+++ b/src/net/java/dev/typecast/edit/GlyphEdit.java
@@ -1,9 +1,7 @@
/*
- * $Id: GlyphEdit.java,v 1.4 2004-12-21 10:24:57 davidsch Exp $
- *
* Typecast - The Font Development Environment
*
- * Copyright (c) 2004 David Schweinsberg
+ * Copyright (c) 2004-2016 David Schweinsberg
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,39 +18,29 @@
package net.java.dev.typecast.edit;
-//import java.beans.*;
-
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
-
+import java.awt.event.MouseEvent;
import java.awt.geom.AffineTransform;
import java.awt.geom.GeneralPath;
import java.awt.geom.Line2D;
import java.awt.geom.Rectangle2D;
-
-import java.awt.event.MouseEvent;
-
import java.util.HashSet;
import java.util.Set;
-
import javax.swing.JPanel;
import javax.swing.Scrollable;
-
import javax.swing.event.MouseInputListener;
-
-import net.java.dev.typecast.ot.Point;
-import net.java.dev.typecast.ot.OTFont;
import net.java.dev.typecast.ot.Glyph;
-
+import net.java.dev.typecast.ot.OTFont;
+import net.java.dev.typecast.ot.Point;
import net.java.dev.typecast.render.GlyphPathFactory;
/**
- * The glyph editor. The user will perform operatons on the glyph within this
+ * The glyph editor. The user will perform operations on the glyph within this
* window using a variety of tools derived from {@link Tool Tool}.
* @author <a href="mailto:[email protected]">David Schweinsberg</a>
- * @version $Id: GlyphEdit.java,v 1.4 2004-12-21 10:24:57 davidsch Exp $
*/
public class GlyphEdit extends JPanel implements Scrollable {
@@ -69,21 +57,13 @@ public class GlyphEdit extends JPanel implements Scrollable {
private boolean _drawControlPoints = true;
private boolean _preview = false;
- private Set<Point> _selectedPoints = new HashSet<Point>();
-
- //private static final String PROP_SAMPLE_PROPERTY = "SampleProperty";
-
- //private String sampleProperty;
-
- //private PropertyChangeSupport _propertySupport;
+ private final Set<Point> _selectedPoints = new HashSet<>();
/** Creates new GlyphEdit */
public GlyphEdit() {
-// _propertySupport = new PropertyChangeSupport(this);
setName("ContourView");
setLayout(null);
-// setPreferredSize(new Dimension(1024, 1024));
_tool = new PointTool(this);
@@ -117,24 +97,6 @@ public class GlyphEdit extends JPanel implements Scrollable {
addMouseMotionListener(mil);
}
- //public String getSampleProperty () {
- // return sampleProperty;
- //}
-
- //public void setSampleProperty (String value) {
- // String oldValue = sampleProperty;
- // sampleProperty = value;
- // _propertySupport.firePropertyChange (PROP_SAMPLE_PROPERTY, oldValue, sampleProperty);
- //}
-
-// public void addPropertyChangeListener (PropertyChangeListener listener) {
-// _propertySupport.addPropertyChangeListener (listener);
-// }
-//
-// public void removePropertyChangeListener (PropertyChangeListener listener) {
-// _propertySupport.removePropertyChangeListener (listener);
-// }
-
public void paint(Graphics graphics) {
super.paint(graphics);
@@ -307,23 +269,27 @@ public class GlyphEdit extends JPanel implements Scrollable {
// public void executeCommand(Command command) {
// }
+ @Override
public boolean getScrollableTracksViewportWidth() {
return false;
}
+ @Override
public int getScrollableBlockIncrement(java.awt.Rectangle rectangle, int param, int param2) {
return 10;
}
+ @Override
public boolean getScrollableTracksViewportHeight() {
return false;
}
+ @Override
public java.awt.Dimension getPreferredScrollableViewportSize() {
return getPreferredSize();
-// return new Dimension(1024, 1024);
}
+ @Override
public int getScrollableUnitIncrement(java.awt.Rectangle rectangle, int param, int param2) {
return 1;
}
diff --git a/src/net/java/dev/typecast/render/GlyphPathFactory.java b/src/net/java/dev/typecast/render/GlyphPathFactory.java
index b6b165e..ff8a1d9 100644
--- a/src/net/java/dev/typecast/render/GlyphPathFactory.java
+++ b/src/net/java/dev/typecast/render/GlyphPathFactory.java
@@ -1,9 +1,7 @@
/*
- * $Id: GlyphPathFactory.java,v 1.1 2004-12-21 10:18:11 davidsch Exp $
- *
* Typecast - The Font Development Environment
*
- * Copyright (c) 2004 David Schweinsberg
+ * Copyright (c) 2004-2016 David Schweinsberg
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,19 +18,18 @@
package net.java.dev.typecast.render;
+import java.awt.Shape;
+import java.awt.geom.CubicCurve2D;
import java.awt.geom.GeneralPath;
import java.awt.geom.Line2D;
import java.awt.geom.QuadCurve2D;
-
-import java.awt.Shape;
-
import net.java.dev.typecast.ot.Glyph;
import net.java.dev.typecast.ot.Point;
+import net.java.dev.typecast.ot.T2Glyph;
/**
* A factory for generating Graphics2D paths from glyph outlines.
* @author <a href="mailto:[email protected]">David Schweinsberg</a>
- * @version $Id: GlyphPathFactory.java,v 1.1 2004-12-21 10:18:11 davidsch Exp $
*/
public class GlyphPathFactory {
@@ -40,6 +37,8 @@ public class GlyphPathFactory {
* Build a {@link java.awt.geom.GeneralPath GeneralPath} from a
* {@link net.java.dev.typecast.ot.Glyph Glyph}. This glyph path can then
* be transformed and rendered.
+ * @param glyph
+ * @return
*/
public static GeneralPath buildPath(Glyph glyph) {
@@ -56,7 +55,11 @@ public class GlyphPathFactory {
for (int i = 0; i < glyph.getPointCount(); i++) {
count++;
if (glyph.getPoint(i).endOfContour) {
- addContourToPath(glyphPath, glyph, firstIndex, count);
+ if (glyph instanceof T2Glyph) {
+ addContourToPath(glyphPath, (T2Glyph) glyph, firstIndex, count);
+ } else {
+ addContourToPath(glyphPath, glyph, firstIndex, count);
+ }
firstIndex = i + 1;
count = 0;
}
@@ -113,7 +116,39 @@ public class GlyphPathFactory {
-point_plus1.y);
offset++;
} else {
- System.out.println("drawGlyph case not catered for!!");
+ System.out.println("addContourToPath case not catered for!!");
+ break;
+ }
+ gp.append(s, connect);
+ connect = true;
+ }
+ }
+
+ private static void addContourToPath(GeneralPath gp, T2Glyph glyph, int startIndex, int count) {
+ int offset = 0;
+ boolean connect = false;
+ while (offset < count) {
+ Shape s;
+ 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);
+ Point point_plus3 = glyph.getPoint(startIndex + (offset+3)%count);
+ if (point.onCurve && point_plus1.onCurve) {
+ s = new Line2D.Float(point.x, -point.y, point_plus1.x, -point_plus1.y);
+ offset++;
+ } else if (point.onCurve && !point_plus1.onCurve && !point_plus2.onCurve && point_plus3.onCurve) {
+ s = new CubicCurve2D.Float(
+ point.x,
+ -point.y,
+ point_plus1.x,
+ -point_plus1.y,
+ point_plus2.x,
+ -point_plus2.y,
+ point_plus3.x,
+ -point_plus3.y);
+ offset+=3;
+ } else {
+ System.out.println("addContourToPath case not catered for!!");
break;
}
gp.append(s, connect);