X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2FVectorGraphics.java;h=988c18ae5f01432de94e279cf403bad8aaa88696;hb=73b7b3d9c3e6ecd20d7f67b68971f756eafbcd4e;hp=55c0930f36c31a570c8220b32c1afc9a4527ea6d;hpb=5e8485ac88b45693b5cdb8e70f346b92732eb91f;p=org.ibex.core.git diff --git a/src/org/xwt/VectorGraphics.java b/src/org/xwt/VectorGraphics.java index 55c0930..988c18a 100644 --- a/src/org/xwt/VectorGraphics.java +++ b/src/org/xwt/VectorGraphics.java @@ -1,3 +1,4 @@ +// FIXME // Copyright 2002 Adam Megacz, see the COPYING file for licensing [GPL] package org.xwt; import org.xwt.util.*; @@ -40,6 +41,7 @@ public final class VectorGraphics { // Public entry points ///////////////////////////////////////////////////////////////// public static VectorPath parseVectorPath(String s) { + if (s == null) return null; PathTokenizer t = new PathTokenizer(s); VectorPath ret = new VectorPath(); char last_command = 'M'; @@ -119,6 +121,72 @@ public final class VectorGraphics { // PathTokenizer ////////////////////////////////////////////////////////////////////////////// + public static Affine parseTransform(String t) { + if (t == null) return null; + t = t.trim(); + Affine ret = VectorGraphics.Affine.identity(); + while (t.length() > 0) { + if (t.startsWith("skewX(")) { + // FIXME + + } else if (t.startsWith("shear(")) { + // FIXME: nonstandard; remove this + ret.multiply(VectorGraphics.Affine.shear(Float.parseFloat(t.substring(t.indexOf('(') + 1, t.indexOf(')'))))); + + } else if (t.startsWith("skewY(")) { + // FIXME + + } else if (t.startsWith("rotate(")) { + String sub = t.substring(t.indexOf('(') + 1, t.indexOf(')')); + if (sub.indexOf(',') != -1) { + float angle = Float.parseFloat(sub.substring(0, sub.indexOf(','))); + sub = sub.substring(sub.indexOf(',') + 1); + float cx = Float.parseFloat(sub.substring(0, sub.indexOf(','))); + sub = sub.substring(sub.indexOf(',') + 1); + float cy = Float.parseFloat(sub); + ret.multiply(VectorGraphics.Affine.translate(cx, cy)); + ret.multiply(VectorGraphics.Affine.rotate(angle)); + ret.multiply(VectorGraphics.Affine.translate(-1 * cx, -1 * cy)); + } else { + ret.multiply(VectorGraphics.Affine.rotate(Float.parseFloat(t.substring(t.indexOf('(') + 1, t.indexOf(')'))))); + } + + } else if (t.startsWith("translate(")) { + String sub = t.substring(t.indexOf('(') + 1, t.indexOf(')')); + if (sub.indexOf(',') > -1) { + ret.multiply(VectorGraphics.Affine.translate(Float.parseFloat(t.substring(t.indexOf('(') + 1, t.indexOf(','))), + Float.parseFloat(t.substring(t.indexOf(',') + 1, t.indexOf(')'))))); + } else { + ret.multiply(VectorGraphics.Affine.translate(Float.parseFloat(t.substring(t.indexOf('(') + 1, t.indexOf(','))), 0)); + } + + } else if (t.startsWith("flip(")) { + String which = t.substring(t.indexOf('(') + 1, t.indexOf(')')); + ret.multiply(VectorGraphics.Affine.flip(which.equals("horizontal"), which.equals("vertical"))); + + } else if (t.startsWith("scale(")) { + String sub = t.substring(t.indexOf('(') + 1, t.indexOf(')')); + if (sub.indexOf(',') > -1) { + ret.multiply(VectorGraphics.Affine.scale(Float.parseFloat(t.substring(t.indexOf('(') + 1, t.indexOf(','))), + Float.parseFloat(t.substring(t.indexOf(',') + 1, t.indexOf(')'))))); + } else { + ret.multiply(VectorGraphics.Affine.scale(Float.parseFloat(t.substring(t.indexOf('(') + 1, t.indexOf(','))), + Float.parseFloat(t.substring(t.indexOf('(') + 1, t.indexOf(','))))); + } + + } else if (t.startsWith("matrix(")) { + // FIXME: is this mapped right? + float d[] = new float[6]; + StringTokenizer st = new StringTokenizer(t, ",", false); + for(int i=0; i<6; i++) + d[i] = Float.parseFloat(st.nextToken()); + ret.multiply(new VectorGraphics.Affine(d[0], d[1], d[2], d[3], d[4], d[5])); + } + t = t.substring(t.indexOf(')') + 1).trim(); + } + return ret; + } + public static final float PX_PER_INCH = 72; public static final float INCHES_PER_CM = (float)0.3937; public static final float INCHES_PER_MM = INCHES_PER_CM / 10;