fixes for gradients

This commit is contained in:
benfry
2006-12-13 21:36:18 +00:00
parent ba92a4dfcb
commit 1b0ab430b9
3 changed files with 58 additions and 9 deletions
@@ -1,3 +1,19 @@
/*
Candy 2 - SVG Importer for Processing - http://processing.org
Code to handle linear and radial gradients
Copyright (c) 2006- Ben Fry and Casey Reas
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License version 2.1 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
*/
package processing.candy;
import java.awt.Paint;
@@ -6,7 +22,6 @@ import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.geom.AffineTransform;
import java.awt.geom.Point2D;
//import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.ColorModel;
import java.awt.image.Raster;
@@ -1,3 +1,19 @@
/*
Candy 2 - SVG Importer for Processing - http://processing.org
Code to handle linear and radial gradients
Copyright (c) 2006- Ben Fry and Casey Reas
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License version 2.1 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
*/
package processing.candy;
import java.awt.Paint;
@@ -5,7 +21,6 @@ import java.awt.PaintContext;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.geom.AffineTransform;
//import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.ColorModel;
import java.awt.image.Raster;
+26 -7
View File
@@ -21,8 +21,7 @@ package processing.candy;
import java.awt.*;
import java.awt.geom.AffineTransform;
//import java.awt.geom.*;
//import java.awt.image.*;
import java.awt.geom.Point2D;
import java.util.Hashtable;
import processing.core.*;
@@ -860,6 +859,8 @@ public class SVG {
abstract private class Gradient extends BaseObject {
AffineTransform transform;
float[] offset;
int[] color;
int count;
@@ -905,6 +906,7 @@ public class SVG {
abstract protected void drawShape();
}
static protected Hashtable parseStyleAttributes(String style) {
Hashtable table = new Hashtable();
String[] pieces = style.split(";");
@@ -918,7 +920,6 @@ public class SVG {
private class LinearGradient extends Gradient {
float x1, y1, x2, y2;
AffineTransform transform;
public LinearGradient(XMLElement properties) {
super(properties);
@@ -932,7 +933,14 @@ public class SVG {
properties.getStringAttribute("gradientTransform");
if (transformStr != null) {
this.transform = parseTransform(transformStr);
System.out.println(transform);
Point2D t1 = transform.transform(new Point2D.Float(x1, y1), null);
Point2D t2 = transform.transform(new Point2D.Float(x2, y2), null);
this.x1 = (float) t1.getX();
this.y1 = (float) t1.getY();
this.x2 = (float) t2.getX();
this.y2 = (float) t2.getY();
}
}
@@ -958,13 +966,24 @@ public class SVG {
private class RadialGradient extends Gradient {
float cx, cy, r;
public RadialGradient(XMLElement properties) {
super(properties);
this.cx = properties.getFloatAttribute("cx");
this.cy = properties.getFloatAttribute("cy");
this.r = properties.getFloatAttribute("r");
String transformStr =
properties.getStringAttribute("gradientTransform");
if (transformStr != null) {
this.transform = parseTransform(transformStr);
Point2D t1 = transform.transform(new Point2D.Float(cx, cy), null);
Point2D t2 = transform.transform(new Point2D.Float(cx + r, cy), null);
this.cx = (float) t1.getX();
this.cy = (float) t1.getY();
this.r = (float) (t2.getX() - t1.getX());
}
}
protected void drawShape() {
@@ -975,7 +994,7 @@ public class SVG {
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
private class Line extends VectorObject{
private class Line extends VectorObject {
float x1, y1, x2, y2;
@@ -996,7 +1015,7 @@ public class SVG {
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
private class Circle extends VectorObject{
private class Circle extends VectorObject {
float x, y, radius;