XSLT
XSLT Contents
Summary In some cases, espessially if you want to reduce a number of SVG objects and simplify an SVG object model, it has a sence to provide a server side "SVG Basic Shapes to Paths" conversion.
Basic Shapes to Paths conversion is a well-known industry approach. If you take a look, for example, at the Adobe Illustrator, you will see, that when you create a circle, in fact you create a path. SVG 1.1 also mentioned that: Mathematically, these shapeelements are equivalent to a 'path' element that would construct the same shape.
The more detailed information about the SVG Model reduction and differenttranscoding schemes along with the source code you will find athttp://www.tinyline.com/svgm/svgminute/index.html or you can download it from
http://www.tinyline.com/svgm/download/svgminute.zip
As an example, lets see what we can do with the SVG Circle element.The 'circle' element defines a circle based on a center point (cx, cy) and aradius r.The following file consists of a 'circle' element that is filled withred and stroked with blue.http://www.tinyline.com/svgm/svgminute/svg-t/shapes-circle-01-t.svg
The same file that is transcoded by the server:http://www.tinyline.com/svgm/svgminute/svg-m/shapes-circle-01-t.svg
As you can see both files produce the same geometry and the same picture.
Below is the source code of the TinyPath class that producesBasic Shapes to Paths conversion
* @author Andrew Girow * @version 1.4 *
*/ public class TinyPath { StringBuffer sb; public TinyPath() { sb = new StringBuffer(); } /** * Adds a straight line segment from the * current point to (x,y). * The new current point is (x,y). * @param x, y the specified coordinates */ public void lineTo(double x, double y) { sb.append("L"+x+" "+y+" "); } /** * Moves the current point to (x,y) * @param x, y the specified coordinates */ public void moveTo(double x, double y) { sb.append("M"+x+" "+y+" "); } /** * Closes the current subpath by drawing a straight line back to * the coordinates of the last moveTo. If the TinyPath is already * closed then this method has no effect. */ public void closePath() { sb.append("Z"); } /** * Adds a Bézier curve to the TinyPath between the current * point to (x3,y3) using the current point and (x2,y2) * as Bézier control point. * The new current point is (x3,y3). * @param x2, y2 the Bézier control point * @param x3, y3 the final endpoint */ public void curveTo(double x2, double y2, double x3, double y3) { sb.append("Q"+x2+" "+y2+" "+ x3+" "+y3+" "); } /** * Adds a Bézier curve to the TinyPath between the current * point to (x3,y3) using the current point and (x1,y1), (x2,y2) * as Bézier control points. * The new current point is (x3,y3). * @param x1, y1 the first Bézier control point * @param x2, y2 the second Bézier control point * @param x3, y3 the final endpoint */ public void curveToCubic(double x1, double y1, double x2, double y2, double x3, double y3) { sb.append("C"+x1+" "+y1+" "+ x2+" "+y2+" "+x3+" "+y3+" "); } /** * Returns the SVG path data or 'd' attribute of the SVG path */ public String getPathData() { return sb.toString(); } /** * Returns the outline path of a line. *
* @return a path object that represents the outline of a line * whose start point is specified as (x0, y0) * and whose end point is specified as (x1, y1). * @param x0, y0, x1, y1 the specified coordinates */ public static TinyPath lineToPath(double x0, double y0, double x1 ,double y1) { TinyPath path = new TinyPath(); path.moveTo(x0, y0); path.lineTo(x1, y1); return path; } /** * Returns the outline path of a rectangle. *
* @return a path object that represents the outline of a rectangle * whose top-left corner is specified as (x0, y0) * and whose down-right corner is specified as (x1, y1). * @param x0, y0, x1, y1 the specified coordinates */ public static TinyPath rectToPath(double x0, double y0, double x1 ,double y1) { TinyPath path = new TinyPath(); path.moveTo(x0, y0); path.lineTo(x1, y0); path.lineTo(x1, y1); path.lineTo(x0, y1); path.closePath(); return path; } /** * Returns the outline path of a circle. *
* @return a path object. * @param cx the x-axis coordinate of the center of the circle * @param cy the y-axis coordinate of the center of the circle * @param r the radius of the circle. */ public static TinyPath circleToPath(double cx, double cy, double r) { return ovalToPath(cx-r , cy-r, 2D*r, 2D*r); } /** * Returns the outline path of an ellipse. *
* @return a path object. * @param cx the x-axis coordinate of the center of the ellipse * @param cy the y-axis coordinate of the center of the ellipse * @param rx the x-axis radius of the ellipse. * @param ry the y-axis radius of the ellipse. */ public static TinyPath ellipseToPath(double cx, double cy, double rx, double ry) { return ovalToPath(cx-rx , cy -ry, 2D*rx, 2D*ry); } /** * Returns the outline path of an oval. * The result is a circle or ellipse that fits within the * rectangle specified by the x, y, * width, and height arguments. *
x
y
width
height
* @return a path object. * @param x the x coordinate of the upper left * corner of the oval to be drawn. * @param y the y coordinate of the upper left * corner of the oval to be drawn. * @param width the width of the oval to be drawn. * @param height the height of the oval to be drawn. */ public static TinyPath ovalToPath(double x, double y, double width ,double height) { return roundRectToPath (x, y, width ,height, width/2, height/2); } /** * Returns an outlined path of round-cornered rectangle. The left * and right edges of the rectangle are at x and * x + width, respectively. The top and bottom edges * of the rectangle are at y and * y + height. * @return a path object * @param xmin the x coordinate of the rectangle to be drawn. * @param ymin the y coordinate of the rectangle to be drawn. * @param width the width of the rectangle to be drawn. * @param height the height of the rectangle to be drawn. * @param rx the horizontal diameter of the arc * at the four corners. * @param ry the vertical diameter of the arc * at the four corners. */ public static TinyPath roundRectToPath(double xmin, double ymin, double width ,double height, double rx, double ry) { TinyPath path = new TinyPath(); rx = Math.min(rx, width / 2D); ry = Math.min(ry, height / 2D); double xmax = xmin + width; double ymax = ymin + height; if(rx == 0 || ry == 0) // degradate { path.moveTo(xmin, ymin); path.lineTo(xmax, ymin); path.lineTo(xmax, ymax); path.lineTo(xmin, ymax); path.closePath(); } else { double d6 = (1.0D - kappa) * rx; double d7 = (1.0D - kappa) * ry; path.moveTo(xmax - rx, ymin); path.curveToCubic(xmax - d6, ymin, xmax, ymin + d7, xmax, ymin + ry); path.lineTo(xmax, ymax - ry); path.curveToCubic(xmax, ymax - d7, xmax - d6, ymax, xmax - rx, ymax); path.lineTo(xmin + rx, ymax); path.curveToCubic(xmin + d6, ymax, xmin, ymax - d7, xmin, ymax - ry); path.lineTo(xmin, ymin + ry); path.curveToCubic(xmin, ymin + d7, xmin + d6, ymin, xmin + rx, ymin); path.closePath(); } return path; } private static final double kappa = (4D * (Math.sqrt(2D) - 1.0D)) / 3D; }
x + width
y + height
Partners
Dream.In.Code dotNet Slackers dotNet Spider Your HTML Source VisualBuilder.com DevGuru Planet Source Code ZVON.ORG Web Design ASPAlliance XML Pitstop Scripts
The Spot 4 SAP Bitshop Web Hosting