X-Git-Url: http://git.megacz.com/?p=org.ibex.core.git;a=blobdiff_plain;f=src%2Forg%2Fxwt%2FVectorGraphics.java;h=fc19ba40ac32be9d825831f63d46cb8fd3a40ddc;hp=cd62d8960be75c649084d3cd4c750cf6e5f78a3f;hb=1019725cfa88d9ad5dfabaf178e87da79c9c3e17;hpb=a40c19a25bdb601346eb6876c99ec200b89d2449 diff --git a/src/org/xwt/VectorGraphics.java b/src/org/xwt/VectorGraphics.java index cd62d89..fc19ba4 100644 --- a/src/org/xwt/VectorGraphics.java +++ b/src/org/xwt/VectorGraphics.java @@ -3,23 +3,18 @@ package org.xwt; import org.xwt.util.*; import java.util.*; -// NOTE: we have to make sure that a box is never smaller than the -// bounding box of its path unless the user specifically forced -// it to be so. - +// FIXME: offer a "subpixel" mode where we pass floats to the Platform and don't do any snapping // FIXME: fracture when realizing instead of when parsing? + /* v1.0 - - Base64 "data:" URL support - textpath - gradients - patterns - clipping/masking - filters (filtering of a group must be performed AFTER the group is assembled; sep. canvas) - - style sheets v1.1 - - markers (do this in the parser; remember the order: fill, stroke, marker) - bump caps [requires Paint that can fill circles...] [remember to distinguish between closed/unclosed] - line joins - mitre (hard) @@ -31,16 +26,18 @@ import java.util.*; - clip on trapezoids, not pixels - faster gradients and patterns: - transform each corner of the trapezoid and then interpolate - - */ +*/ /** XWT's fully conformant Static SVG Viewer; see SVG spec, section G.7 */ public final class VectorGraphics { - /* - // Public entry points ///////////////////////////////////////////////////////////////// - // FIXME - public static SVG.Font currentFont = null; + // Private Constants /////////////////////////////////////////////////////////////////// + + private static final int DEFAULT_PATHLEN = 1000; + private static final float PI = (float)Math.PI; + + + // Public entry points ///////////////////////////////////////////////////////////////// public static VectorPath parseVectorPath(String s) { PathTokenizer t = new PathTokenizer(s); @@ -59,272 +56,10 @@ public final class VectorGraphics { return ret; } - public static void parseNode(String name, String[] keys, Object[] vals, Template t) { - Hash h = new Hash(); - for(int i=0; iname property * / - Hashtable glyphByName = new Hashtable(); - - / ** linked list of glyphs, stored by the first character of their unicode property * / - Hashtable glyphByUnicode = new Hashtable(); - - / ** a Glyph in an SVG font * / - public static class Glyph { - - // FIXME: lang attribute - boolean isVerticallyOriented = false; - Template t = null; - Box b = null; - - float horiz_adv_x = 0; - float vert_origin_x = 0; - float vert_origin_y = 0; - float vert_adv_y = 0; - - String unicode = null; - - / ** forms the linked list in glyphByUnicode; glyphs appear in the order specified in the font * / - public Glyph next = null; - - Glyph(String name, String unicode, Template t, SVG.Font f) { - if (unicode != null) - if (f.glyphByUnicode.get(unicode.substring(0, 1)) == null) { - f.glyphByUnicode.put(unicode.substring(0, 1), this); - } else { - Glyph g; - for(g = (Glyph)f.glyphByUnicode.get(unicode.substring(0, 1)); g.next != null; g = g.next); - g.next = this; - } - if (name != null) f.glyphByUnicode.put(name, this); - this.unicode = unicode; - this.t = t; - horiz_adv_x = f.horiz_adv_x; - vert_origin_x = f.vert_origin_x; - vert_origin_y = f.vert_origin_y; - vert_adv_y = f.vert_adv_y; - } - public void render(DoubleBuffer buf, int x, int y, int fillcolor, int strokecolor, float scaleFactor) { - // FEATURE: make b double-buffered for increased performance - if (b == null) { - b = new Box(t, new org.xwt.util.Vec(), new org.xwt.util.Vec(), null, 0, 0); - b.put("absolute", Boolean.TRUE); - b.prerender(); - t = null; - } - // FIXME - b.put("width", new Integer(1000)); - b.put("height", new Integer(1000)); - b.fillcolor = fillcolor; - b.strokecolor = strokecolor; - - // we toss an extra flip on the ctm so that fonts stick "up" instead of down - b.render(0, 0, buf.getWidth(), buf.getHeight(), buf, - Affine.flip(false, true).multiply(Affine.scale(scaleFactor, scaleFactor).multiply(Affine.translate(x, y))).multiply(buf.a)); - } - } - } // Affine ////////////////////////////////////////////////////////////////////////////// - / ** an affine transform; all operations are destructive * / + /** an affine transform; all operations are destructive */ public static final class Affine { // [ a b e ] @@ -350,7 +85,7 @@ public final class VectorGraphics { return new Affine(c, s, -s, c, 0, 0); } - / ** this = this * a * / + /** this = this * a */ public Affine multiply(Affine A) { float _a = this.a * A.a + this.b * A.c; float _b = this.a * A.b + this.b * A.d; @@ -408,7 +143,7 @@ public final class VectorGraphics { char c = s.charAt(i); if (Character.isWhitespace(c) || c == ',' || (c == '-' && i != start)) break; if (!((c >= '0' && c <= '9') || c == '.' || c == 'e' || c == 'E' || c == '-')) { - if (c == '%') { // FIXME + if (c == '%') { // FIXME } else if (s.regionMatches(i, "pt", 0, i+2)) { // FIXME } else if (s.regionMatches(i, "em", 0, i+2)) { // FIXME } else if (s.regionMatches(i, "pc", 0, i+2)) { // FIXME @@ -429,7 +164,7 @@ public final class VectorGraphics { // Abstract Path ////////////////////////////////////////////////////////////////////////////// - / ** an abstract path; may contain splines and arcs * / + /** an abstract path; may contain splines and arcs */ public static class VectorPath { // the number of vertices on this path @@ -456,7 +191,7 @@ public final class VectorGraphics { static final byte TYPE_CUBIC = 3; static final byte TYPE_QUADRADIC = 4; - / ** Creates a concrete vector path transformed through the given matrix. * / + /** Creates a concrete vector path transformed through the given matrix. */ public RasterPath realize(Affine a) { RasterPath ret = new RasterPath(); @@ -678,7 +413,8 @@ public final class VectorGraphics { default: // FIXME } - / * + + /* // invariant: after this loop, no two lines intersect other than at a vertex // FIXME: cleanup int index = numvertices - 2; @@ -709,7 +445,7 @@ public final class VectorGraphics { } } } - * / + */ } } @@ -717,9 +453,9 @@ public final class VectorGraphics { - // Concrete Vector Path ////////////////////////////////////////////////////////////////////////////// + // Rasterized Vector Path ////////////////////////////////////////////////////////////////////////////// - / ** a vector path * / + /** a vector path */ public static class RasterPath { // the vertices of this path @@ -727,18 +463,15 @@ public final class VectorGraphics { int[] y = new int[DEFAULT_PATHLEN]; int numvertices = 0; - / ** - * A list of the vertices on this path which *start* an edge (rather than a moveto), sorted by increasing y. + /** + * A list of the vertices on this path which *start* an *edge* (rather than a moveto), sorted by increasing y. * example: x[edges[1]],y[edges[1]] - x[edges[i]+1],y[edges[i]+1] is the second-topmost edge * note that if x[i],y[i] - x[i+1],y[i+1] is a MOVETO, then no element in edges will be equal to i - * / + */ int[] edges = new int[DEFAULT_PATHLEN]; int numedges = 0; - / ** FIXME: if a path is closed "manually" you get caps on the ends; otherwise you get a marker... * / - boolean closed = false; - - / ** simple quicksort, from http://sourceforge.net/snippet/detail.php?type=snippet&id=100240 * / + /** simple quicksort, from http://sourceforge.net/snippet/detail.php?type=snippet&id=100240 */ int sort(int left, int right, boolean partition) { if (partition) { int i, j, middle; @@ -761,7 +494,7 @@ public final class VectorGraphics { } } - / ** finds the x value at which the line intercepts the line y=_y * / + /** finds the x value at which the line intercepts the line y=_y */ private int intercept(int i, float _y, boolean includeTop, boolean includeBottom) { if (includeTop ? (_y < Math.min(y[i], y[i+1])) : (_y <= Math.min(y[i], y[i+1]))) return Integer.MIN_VALUE; @@ -771,8 +504,8 @@ public final class VectorGraphics { ((float)(y[i + 1] - y[i])) ) * ((float)(_y - y[i])) + x[i]); } - / ** fill the interior of the path * / - public void fill(DoubleBuffer buf, RasterPath pen, Paint paint) { + /** fill the interior of the path */ + public void fill(PixelBuffer buf, Paint paint) { if (numedges == 0) return; int y0 = y[edges[0]], y1 = y0; boolean useEvenOdd = false; @@ -822,79 +555,91 @@ public final class VectorGraphics { } } - / ** stroke the outline of the path * / - public void stroke(DoubleBuffer buf, int width, int color, boolean mitre, - String dashArray, int dashOffset, float segLength) { - if (dashArray != null) { - float ratio = 1; - if (segLength > 0) { - float actualLength = 0; - for(int i=0; i 0) { + float actualLength = 0; for(int i=0; i