net.sf.latexdraw.generators.svg
Class LShapeSVGGenerator<S extends IShape>

java.lang.Object
  extended by net.sf.latexdraw.generators.svg.LShapeSVGGenerator<S>
Direct Known Subclasses:
LAxeSVGGenerator, LBezierCurveSVGGenerator, LDotSVGGenerator, LEllipseSVGGenerator, LFreeHandSVGGenerator, LGridSVGGenerator, LGroupSVGGenerator, LModifiablePointsGenerator, LPictureSVGGenerator, LRectangleSVGGenerator, LRhombusSVGGenerator, LTextSVGGenerator, LTriangleSVGGenerator

abstract class LShapeSVGGenerator<S extends IShape>
extends java.lang.Object

This class allows the generation or the importation of SVG parameters to a general LaTeXDraw shape.

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 (at your option) 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.

05/30/10

Version:
3.0
Author:
Arnaud BLOUIN

Field Summary
protected  S shape
          The shape model use for the generation.
protected static java.lang.String SVG_URL_TOKEN_BEGIN
          The beginning of the token used to declare a URL in an SVG document.
 
Constructor Summary
protected LShapeSVGGenerator(S sh)
          Creates the SVG generator.
 
Method Summary
 void applyTransformation(SVGTransform t)
          Applies an SVG transformation on the shape.
 void applyTransformations(SVGElement elt)
          Applies the set of transformations that concerned the given SVG element to the shape.
protected  void getGradientPoints(java.awt.geom.Point2D.Float p1, java.awt.geom.Point2D.Float p2, boolean ignoreMidPt)
          Gets the points needed to the gradient definition.
protected  SVGElement getLaTeXDrawElement(SVGGElement elt, java.lang.String type)
           
protected  double getPositionGap()
          If a figure can move its border, we have to compute the difference between the PSTricks shape and the SVG shape.
 S getShape()
           
protected static SVGCircleElement getShowPointsDot(SVGDocument doc, double rad, IPoint pt, java.awt.Color col)
          Creates an SVG circle that represents a dot for the option 'show points'.
protected static SVGLineElement getShowPointsLine(SVGDocument doc, double thickness, java.awt.Color col, IPoint p1, IPoint p2, double blackDash, double whiteDash, boolean hasDble, double dotSep, double doubleSep)
          Creates a line with the style of the 'show points' option.
 SVGPathSegList getSVGHatchingsPath()
           
private  void getSVGHatchingsPath2(SVGPathSegList path, double hAngle, IRectangle bound)
           
 java.lang.String getSVGID()
           
protected  void homogeniseArrowFrom(IArrow source, IArrow target)
          Copies the parameters of the first arrow to the second arrow (only the parameters of the current style are copied).
 void homogeniseArrows(IArrow ah1, IArrow ah2)
          When the arrows are read from an SVG document, we need to set the parameters of the first arrow to the second arrow and vise et versa; because the arrows of a shape share the same parameters.
static void setDashedDotted(org.w3c.dom.Element elt, double blackDash, double whiteDash, double dotSep, java.lang.String lineStyle, boolean hasDoubleBorders, double thickness, double doubleSep)
          Sets the line style to the given SVG element.
static void setDashedDotted(IShape shape, java.lang.String dashArray, java.lang.String linecap)
          Sets the figure properties concerning the line properties.
static void setFill(IShape shape, java.lang.String fill, SVGDefsElement defs)
          Sets the fill properties to the given figure.
static void setLineColour(IShape shape, java.lang.String stoke)
          Sets the colour of the line of the shape with the given SVG stroke.
 void setNumber(SVGGElement g)
          Sets the ID of the figure according to the ID attribute of the SVGGElement, or an increment of meter if a problem occur.
protected  void setSVGArrow(IArrow ah, java.lang.String arrowID, SVGElement elt)
          Sets the given arrow head using the SVG arrow with the ID arrowID
protected  void setSVGArrow(SVGElement parent, int arrowPos, boolean isShadow, SVGDocument doc, SVGDefsElement defs)
           
protected  void setSVGAttributes(SVGDocument doc, SVGElement root, boolean shadowFills)
          Sets the SVG attribute of the current figure.
protected  void setSVGBorderBackground(SVGElement elt, SVGElement root)
          When a shape has a shadow and is filled, the background of its borders must be filled with the colour of the interior of the shape.
protected  void setSVGDbleBordersParameters(SVGElement elt)
          Sets the double borders parameters of the figure by using an SVG element.
protected  void setSVGDoubleBordersAttributes(org.w3c.dom.Element elt)
          Sets the double borders parameters to the given SVG element if the current figure has double borders.
protected  void setSVGLatexdrawParameters(SVGElement elt)
           
protected  void setSVGParameters(SVGElement elt)
          Sets the global parameters of the figure by using an SVG element.
protected  void setSVGRotationAttribute(org.w3c.dom.Element elt)
           
protected  void setSVGShadowAttributes(org.w3c.dom.Element elt, boolean shadowFills)
           
protected  void setSVGShadowParameters(SVGElement elt)
          Sets the shadow parameters of the figure by using an SVG element having "type:shadow".
static void setThickness(IShape shape, java.lang.String strokeWidth, java.lang.String stroke)
          Sets the thickness of the given figure with the given SVG stroke-width.
static void setThickness(SVGElement elt, double thickness, boolean hasDoubleBorders, double doubleSep)
          Sets the given thickness to the given SVG element.
abstract  SVGElement toSVG(SVGDocument doc)
          Creates an SVG element from the current latexdraw shape.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

shape

protected S extends IShape shape
The shape model use for the generation.


SVG_URL_TOKEN_BEGIN

protected static final java.lang.String SVG_URL_TOKEN_BEGIN
The beginning of the token used to declare a URL in an SVG document.

See Also:
Constant Field Values
Constructor Detail

LShapeSVGGenerator

protected LShapeSVGGenerator(S sh)
Creates the SVG generator.

Parameters:
sh - The shape used for the generation.
Throws:
java.lang.IllegalArgumentException - If the given shape is null.
Since:
2.0
Method Detail

getSVGID

public java.lang.String getSVGID()
Returns:
The SVG ID of the shape (starting with the token "id" followed by the number of the shape).
Since:
2.0.0

setNumber

public void setNumber(SVGGElement g)
Sets the ID of the figure according to the ID attribute of the SVGGElement, or an increment of meter if a problem occur.

Parameters:
g - The SVGGElement.
Since:
2.0.0

applyTransformations

public void applyTransformations(SVGElement elt)
Applies the set of transformations that concerned the given SVG element to the shape.

Parameters:
elt - The element that contains the SVG transformation list.
Since:
2.0.0

applyTransformation

public void applyTransformation(SVGTransform t)
Applies an SVG transformation on the shape.

Parameters:
t - The SVG transformation to apply.
Since:
2.0.0

homogeniseArrows

public void homogeniseArrows(IArrow ah1,
                             IArrow ah2)
When the arrows are read from an SVG document, we need to set the parameters of the first arrow to the second arrow and vise et versa; because the arrows of a shape share the same parameters. This method carries out this job.

Parameters:
ah1 - The first arrow.
ah2 - The second arrow.
Since:
2.0.0

setSVGArrow

protected void setSVGArrow(SVGElement parent,
                           int arrowPos,
                           boolean isShadow,
                           SVGDocument doc,
                           SVGDefsElement defs)

homogeniseArrowFrom

protected void homogeniseArrowFrom(IArrow source,
                                   IArrow target)
Copies the parameters of the first arrow to the second arrow (only the parameters of the current style are copied).

Parameters:
source - The arrow that will be copied.
target - The arrow that will be set.
Since:
2.0.0
See Also:
homogeniseArrows(IArrow, IArrow)

setSVGShadowParameters

protected void setSVGShadowParameters(SVGElement elt)
Sets the shadow parameters of the figure by using an SVG element having "type:shadow".

Parameters:
elt - The source element.
Since:
2.0.0

setSVGDbleBordersParameters

protected void setSVGDbleBordersParameters(SVGElement elt)
Sets the double borders parameters of the figure by using an SVG element.

Parameters:
elt - The SVG element.
Since:
2.0.0

setSVGLatexdrawParameters

protected void setSVGLatexdrawParameters(SVGElement elt)

setSVGParameters

protected void setSVGParameters(SVGElement elt)
Sets the global parameters of the figure by using an SVG element.

Parameters:
elt - The SVG element.
Since:
2.0.0

setSVGArrow

protected void setSVGArrow(IArrow ah,
                           java.lang.String arrowID,
                           SVGElement elt)
Sets the given arrow head using the SVG arrow with the ID arrowID

Parameters:
ah - The arrow head to set.
arrowID - The SVG ID of the SVG arrow head.
elt - An element of the SVG document (useful to get the defs of the document).
Since:
2.0.0

getLaTeXDrawElement

protected SVGElement getLaTeXDrawElement(SVGGElement elt,
                                         java.lang.String type)
Parameters:
elt - The source g element.
type - The type of the latexdraw element (double borders, shadow, main), if null, the main element is returned.
Returns:
The Researched element.
Since:
2.0.0

setThickness

public static void setThickness(IShape shape,
                                java.lang.String strokeWidth,
                                java.lang.String stroke)
Sets the thickness of the given figure with the given SVG stroke-width.

Parameters:
shape - The figure to set.
strokeWidth - The SVG stroke-width to convert.
stroke - The stroke.
Since:
2.0.0

toSVG

public abstract SVGElement toSVG(SVGDocument doc)
Creates an SVG element from the current latexdraw shape.

Parameters:
doc - The SVG document.
Returns:
The created SVGElement or null.
Since:
2.0.0

setSVGRotationAttribute

protected void setSVGRotationAttribute(org.w3c.dom.Element elt)
Parameters:
elt - Rotates the SVG element.
Throws:
java.lang.IllegalArgumentException - If elt is null.
Since:
2.0.0

setSVGDoubleBordersAttributes

protected void setSVGDoubleBordersAttributes(org.w3c.dom.Element elt)
Sets the double borders parameters to the given SVG element if the current figure has double borders.

Parameters:
elt - The element to set.
Throws:
java.lang.IllegalArgumentException - If elt is null.
Since:
2.0.0

setSVGShadowAttributes

protected void setSVGShadowAttributes(org.w3c.dom.Element elt,
                                      boolean shadowFills)
Parameters:
elt - The element to set if the current figure has a shadow.
shadowFills - True if a shadow must fill the figure.
Throws:
java.lang.IllegalArgumentException - If elt is null.
Since:
2.0.0

setSVGAttributes

protected void setSVGAttributes(SVGDocument doc,
                                SVGElement root,
                                boolean shadowFills)
Sets the SVG attribute of the current figure.

Parameters:
doc - The original document with which, all the elements will be created.
root - The root element of the document.
shadowFills - True if a shadow must fill the figure.
Throws:
java.lang.IllegalArgumentException - If the root or the "defs" part of the document is null.
Since:
2.0.0

getSVGHatchingsPath

public SVGPathSegList getSVGHatchingsPath()
Returns:
The path of the hatchings of the shape.
Since:
2.0.0

getSVGHatchingsPath2

private void getSVGHatchingsPath2(SVGPathSegList path,
                                  double hAngle,
                                  IRectangle bound)
See Also:
getSVGHatchingsPath()

getGradientPoints

protected void getGradientPoints(java.awt.geom.Point2D.Float p1,
                                 java.awt.geom.Point2D.Float p2,
                                 boolean ignoreMidPt)
Gets the points needed to the gradient definition. The given points must not be null, there value will be set in the method.

Parameters:
p1 - The first point to set.
p2 - The second point to set.
ignoreMidPt - True, gradientMidPt will be ignored.
Throws:
java.lang.IllegalArgumentException - If p1 or p2 is null.
Since:
2.0.0

setLineColour

public static void setLineColour(IShape shape,
                                 java.lang.String stoke)
Sets the colour of the line of the shape with the given SVG stroke.

Parameters:
shape - The shape to set.
stoke - The stroke of the shape.
Since:
2.0.0

setFill

public static void setFill(IShape shape,
                           java.lang.String fill,
                           SVGDefsElement defs)
Sets the fill properties to the given figure.

Parameters:
shape - The figure to set.
fill - The fill properties
defs - The definition that may be useful to the the fill properties (url), may be null.
Since:
2.0.0

setDashedDotted

public static void setDashedDotted(IShape shape,
                                   java.lang.String dashArray,
                                   java.lang.String linecap)
Sets the figure properties concerning the line properties.

Parameters:
shape - The figure to set.
dashArray - The dash array SVG property.
linecap - The line cap SVG property.
Since:
2.0.0

setThickness

public static void setThickness(SVGElement elt,
                                double thickness,
                                boolean hasDoubleBorders,
                                double doubleSep)
Sets the given thickness to the given SVG element.

Parameters:
elt - The element to set.
thickness - The thickness to set.
hasDoubleBorders - True: the shape has double borders and it must be considered during the computation of the thickness.
doubleSep - The size of the double borders.
Since:
3.0

setDashedDotted

public static void setDashedDotted(org.w3c.dom.Element elt,
                                   double blackDash,
                                   double whiteDash,
                                   double dotSep,
                                   java.lang.String lineStyle,
                                   boolean hasDoubleBorders,
                                   double thickness,
                                   double doubleSep)
Sets the line style to the given SVG element.

Parameters:
elt - The element to set.
blackDash - The black dash of the line for dashed line style.
whiteDash - The white dash of the line for dashed line style.
dotSep - The separation between dots for dotted line style.
lineStyle - The line style to set to the SVG element.
hasDoubleBorders - True: the shape has double borders.
thickness - The thickness to set to the element.
doubleSep - The size of the double borders.
Since:
3.0

getPositionGap

protected double getPositionGap()
If a figure can move its border, we have to compute the difference between the PSTricks shape and the SVG shape.

Returns:
The gap computed with the border position, the thickness and the double boundary. Or NaN if the shape cannot move its border.
Since:
2.0.0

getShowPointsLine

protected static SVGLineElement getShowPointsLine(SVGDocument doc,
                                                  double thickness,
                                                  java.awt.Color col,
                                                  IPoint p1,
                                                  IPoint p2,
                                                  double blackDash,
                                                  double whiteDash,
                                                  boolean hasDble,
                                                  double dotSep,
                                                  double doubleSep)
Creates a line with the style of the 'show points' option.

Parameters:
doc - The document owner.
thickness - The thickness of the line to create.
col - The colour of the line.
p1 - The first point of the line.
p2 - The second point of the line.
blackDash - The black dash interval.
whiteDash - The white dash interval.
hasDble - Defines if the shape had double borders.
dotSep - The dot interval.
Returns:
The created SVG line or null.
Since:
2.0.0

setSVGBorderBackground

protected void setSVGBorderBackground(SVGElement elt,
                                      SVGElement root)
When a shape has a shadow and is filled, the background of its borders must be filled with the colour of the interior of the shape. This method does not test if it must be done, it sets a SVG element which carries out that.

Parameters:
elt - The element that will be set to define the background of the borders.
root - The root element to which 'elt' will be appended.
Since:
2.0.0

getShowPointsDot

protected static SVGCircleElement getShowPointsDot(SVGDocument doc,
                                                   double rad,
                                                   IPoint pt,
                                                   java.awt.Color col)
Creates an SVG circle that represents a dot for the option 'show points'.

Parameters:
doc - The document owner.
rad - The radius of the circle.
pt - The position of the point.
col - The colour of the dot.
Returns:
The created dot or null.
Since:
2.0.0

getShape

public S getShape()
Returns:
the shape.
Since:
2.0.0