net.sf.latexdraw.parsers.svg
Class SVGTransform

java.lang.Object
  extended by net.sf.latexdraw.parsers.svg.SVGTransform

public class SVGTransform
extends java.lang.Object

Defines an SVG transformation.

This file is part of LaTeXDraw
Copyright (c) 2005-2012 Arnaud BLOUIN

LaTeXDraw is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or any later version.

LaTeXDraw is distributed without any warranty; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

10/16/07

Since:
0.1
Version:
3.0
Author:
Arnaud BLOUIN

Field Summary
protected  double angle
          The angle of a possible rotation or skew.
protected  double cx
          The possible rotation X-position.
protected  double cy
          The possible rotation Y-position.
protected  SVGMatrix matrix
          The matrix of the transformation.
static int SVG_TRANSFORM_MATRIX
           
static int SVG_TRANSFORM_ROTATE
           
static int SVG_TRANSFORM_SCALE
           
static int SVG_TRANSFORM_SKEWX
           
static int SVG_TRANSFORM_SKEWY
           
static int SVG_TRANSFORM_TRANSLATE
           
static int SVG_TRANSFORM_UNKNOWN
           
protected  int type
          The type of the transformation.
 
Constructor Summary
SVGTransform()
          Creates a transformation with no type.
SVGTransform(java.lang.String transformation)
          The constructor using a string containing the transformation.
 
Method Summary
 boolean cancels(SVGTransform transform)
          Tests if the given transformation cancels the calling one.
private  boolean cancelsRotation(SVGTransform transform)
           
private  boolean cancelsScale(SVGTransform transform)
           
private  boolean cancelsTranslation(SVGTransform transform)
           
private  boolean cancelsXSkew(SVGTransform transform)
           
private  boolean cancelsYSkew(SVGTransform transform)
           
static SVGTransform createRotation(double angle, double cx, double cy)
          Creates a rotation.
static SVGTransform createTranslation(double x, double y)
          Creates a translation.
 double getCx()
           
 double getCy()
           
 SVGMatrix getMatrix()
           
 double getRotationAngle()
           
 double getTX()
           
 double getTY()
           
 int getType()
           
 double getXScaleFactor()
           
 double getXSkewAngle()
           
 double getYScaleFactor()
           
 double getYSkewAngle()
           
 boolean isRotation()
           
 boolean isScale()
           
 boolean isTranslation()
           
 boolean isXSkew()
           
 boolean isYSkew()
           
 void setMatrix(double a, double b, double c, double d, double e, double f)
          The transformation will be set by the given values.
 void setRotate(double angle, double cx, double cy)
          The transformation will be a rotation form the origin.
 void setScale(double sx, double sy)
          The transformation will be a scaling.
 void setSkewX(double angle)
          The transformation will be a X skew.
 void setSkewY(double angle)
          The transformation will be a Y skew.
 void setTransformation(java.lang.String transformation)
          Parses a string containing the SVG transformation in order to set the transformation.
 void setTranslate(double tx, double ty)
          The transformation will be a translation.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SVG_TRANSFORM_UNKNOWN

public static final int SVG_TRANSFORM_UNKNOWN
See Also:
Constant Field Values

SVG_TRANSFORM_MATRIX

public static final int SVG_TRANSFORM_MATRIX
See Also:
Constant Field Values

SVG_TRANSFORM_TRANSLATE

public static final int SVG_TRANSFORM_TRANSLATE
See Also:
Constant Field Values

SVG_TRANSFORM_SCALE

public static final int SVG_TRANSFORM_SCALE
See Also:
Constant Field Values

SVG_TRANSFORM_ROTATE

public static final int SVG_TRANSFORM_ROTATE
See Also:
Constant Field Values

SVG_TRANSFORM_SKEWX

public static final int SVG_TRANSFORM_SKEWX
See Also:
Constant Field Values

SVG_TRANSFORM_SKEWY

public static final int SVG_TRANSFORM_SKEWY
See Also:
Constant Field Values

type

protected int type
The type of the transformation.


matrix

protected SVGMatrix matrix
The matrix of the transformation.


angle

protected double angle
The angle of a possible rotation or skew.


cx

protected double cx
The possible rotation X-position.


cy

protected double cy
The possible rotation Y-position.

Constructor Detail

SVGTransform

public SVGTransform()
Creates a transformation with no type.


SVGTransform

public SVGTransform(java.lang.String transformation)
The constructor using a string containing the transformation. The transformation is not added if it is not valid.

Parameters:
transformation - The SVG transformation.
Throws:
java.lang.IllegalArgumentException - If the transformation is no valid.
Since:
0.1
Method Detail

setTransformation

public void setTransformation(java.lang.String transformation)
Parses a string containing the SVG transformation in order to set the transformation.

Parameters:
transformation - The string to parse.
Throws:
java.lang.IllegalArgumentException - If the transformation is no valid.
Since:
0.1

setTranslate

public void setTranslate(double tx,
                         double ty)
The transformation will be a translation.

Parameters:
tx - The X translation.
ty - The Y translation.
Since:
0.1

setMatrix

public void setMatrix(double a,
                      double b,
                      double c,
                      double d,
                      double e,
                      double f)
The transformation will be set by the given values.

Parameters:
a - The values of the matrix: [a, c, e, b, d, f, 0, 0, 1].
b - The values of the matrix: [a, c, e, b, d, f, 0, 0, 1].
c - The values of the matrix: [a, c, e, b, d, f, 0, 0, 1].
d - The values of the matrix: [a, c, e, b, d, f, 0, 0, 1].
e - The values of the matrix: [a, c, e, b, d, f, 0, 0, 1].
f - The values of the matrix: [a, c, e, b, d, f, 0, 0, 1].
Since:
0.1

setScale

public void setScale(double sx,
                     double sy)
The transformation will be a scaling.

Parameters:
sx - The X scaling.
sy - The Y scaling.
Since:
0.1

setRotate

public void setRotate(double angle,
                      double cx,
                      double cy)
The transformation will be a rotation form the origin.

Parameters:
angle - The rotation angle in degree.
cx - The X centre of the rotation.
cy - The Y centre of the rotation.
Since:
0.1

setSkewX

public void setSkewX(double angle)
The transformation will be a X skew.

Parameters:
angle - The angle of the skew in degree.
Since:
0.1

setSkewY

public void setSkewY(double angle)
The transformation will be a Y skew.

Parameters:
angle - The angle of the skew in degree.
Since:
0.1

getType

public int getType()
Returns:
the type of the transformation.
Since:
0.1

isRotation

public boolean isRotation()
Returns:
True if the transformation is a rotation.
Since:
0.1

isTranslation

public boolean isTranslation()
Returns:
True if the transformation is a translation.
Since:
0.1

isScale

public boolean isScale()
Returns:
True if the transformation is a scale.
Since:
0.1

isXSkew

public boolean isXSkew()
Returns:
True if the transformation is a X skew.
Since:
0.1

isYSkew

public boolean isYSkew()
Returns:
True if the transformation is a Y skew.
Since:
0.1

getRotationAngle

public double getRotationAngle()
Returns:
The rotation angle in degree if the transformation is a rotation. NaN otherwise.

getXSkewAngle

public double getXSkewAngle()
Returns:
The skew angle in degree if the transformation is a X skew. NaN otherwise.

getYSkewAngle

public double getYSkewAngle()
Returns:
The skew angle in degree if the transformation is a Y skew. NaN otherwise.

getXScaleFactor

public double getXScaleFactor()
Returns:
The X scale factor if the transformation is a scaling. NaN otherwise.

getYScaleFactor

public double getYScaleFactor()
Returns:
The Y scale factor if the transformation is a scaling. NaN otherwise.

getTX

public double getTX()
Returns:
The X translation if the transformation is a translation. NaN otherwise.

getTY

public double getTY()
Returns:
The Y translation if the transformation is a translation. NaN otherwise.

getMatrix

public SVGMatrix getMatrix()
Returns:
the matrix.
Since:
0.1

getCx

public double getCx()
Returns:
The rotation X-position or NaN is the transformation is not a rotation.
Since:
3.0

getCy

public double getCy()
Returns:
The rotation Y-position or NaN is the transformation is not a rotation.
Since:
3.0

createTranslation

public static SVGTransform createTranslation(double x,
                                             double y)
Creates a translation.

Parameters:
x - The tx.
y - The ty.
Returns:
The created translation.
Since:
2.0.0

createRotation

public static SVGTransform createRotation(double angle,
                                          double cx,
                                          double cy)
Creates a rotation.

Parameters:
cx - The X centre of the rotation.
cy - The Y centre of the rotation.
angle - The angle of rotation in radian.
Returns:
The created translation.
Since:
0.1

cancels

public boolean cancels(SVGTransform transform)
Tests if the given transformation cancels the calling one.

Parameters:
transform - The transformation to test.
Returns:
True if the given transformation cancels the calling one.
Since:
3.0

cancelsRotation

private boolean cancelsRotation(SVGTransform transform)
Parameters:
transform - The transformation to test.
Returns:
True: if the given transformation is a rotation that cancels the calling one.
Since:
3.0

cancelsTranslation

private boolean cancelsTranslation(SVGTransform transform)
Parameters:
transform - The transformation to test.
Returns:
True: if the given transformation is a translation that cancels the calling one.
Since:
3.0

cancelsScale

private boolean cancelsScale(SVGTransform transform)
Parameters:
transform - The transformation to test.
Returns:
True: if the given transformation is a scaling that cancels the calling one.
Since:
3.0

cancelsXSkew

private boolean cancelsXSkew(SVGTransform transform)
Parameters:
transform - The transformation to test.
Returns:
True: if the given transformation is an X-skewing that cancels the calling one.
Since:
3.0

cancelsYSkew

private boolean cancelsYSkew(SVGTransform transform)
Parameters:
transform - The transformation to test.
Returns:
True: if the given transformation is an Y-skewing that cancels the calling one.
Since:
3.0

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object