Package net.codecrete.qrbill.canvas
Class SVGCanvas
java.lang.Object
net.codecrete.qrbill.canvas.AbstractCanvas
net.codecrete.qrbill.canvas.SVGCanvas
- All Implemented Interfaces:
Closeable
,AutoCloseable
,ByteArrayResult
,Canvas
Canvas for generating SVG files.
-
Nested Class Summary
Nested classes/interfaces inherited from interface net.codecrete.qrbill.canvas.Canvas
Canvas.LineStyle
-
Field Summary
Fields inherited from class net.codecrete.qrbill.canvas.AbstractCanvas
fontMetrics, MM_TO_PT
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addRectangle
(double x, double y, double width, double height) Adds a rectangle to the pathvoid
close()
void
Closes the current subpathvoid
cubicCurveTo
(double x1, double y1, double x2, double y2, double x, double y) Adds a cubic Beziér curve to the open path going from the previous point to the specified position.void
fillPath
(int color, boolean smoothing) Fills the current path and ends itvoid
lineTo
(double x, double y) Adds a line segment to the open path from the previous point to the specified position.void
moveTo
(double x, double y) Moves the current point of the open path to the specified position.void
Adds text to the graphics.void
Saves the resulting SVG image to the specified path.void
setTransformation
(double translateX, double translateY, double rotate, double scaleX, double scaleY) Sets a translation, rotation and scaling for the subsequent operationsvoid
Starts a path that can be filled or strokedvoid
strokePath
(double strokeWidth, int color, Canvas.LineStyle lineStyle, boolean smoothing) Strokes the current path and ends itbyte[]
Gets the resulting graphics as a byte array.void
writeTo
(OutputStream os) Writes the resulting SVG image to the specified output stream.Methods inherited from class net.codecrete.qrbill.canvas.AbstractCanvas
getAscender, getDescender, getLineHeight, getTextWidth, putTextLines, setupFontMetrics, splitLines
-
Constructor Details
-
SVGCanvas
Creates a new instance of the specified size.For all text, the specified font family list will be used.
- Parameters:
width
- width of image, in mmheight
- height of image, in mmfontFamilyList
- font family list (comma separated list, CSS syntax)- Throws:
IOException
- thrown if the instance cannot be created
-
-
Method Details
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
startPath
Description copied from interface:Canvas
Starts a path that can be filled or stroked- Specified by:
startPath
in interfaceCanvas
- Throws:
IOException
- thrown if the graphics cannot be generated
-
moveTo
Description copied from interface:Canvas
Moves the current point of the open path to the specified position.- Specified by:
moveTo
in interfaceCanvas
- Parameters:
x
- x-coordinate of positiony
- y-coordinate of position- Throws:
IOException
- thrown if the graphics cannot be generated
-
lineTo
Description copied from interface:Canvas
Adds a line segment to the open path from the previous point to the specified position.- Specified by:
lineTo
in interfaceCanvas
- Parameters:
x
- x-coordinate of positiony
- y-coordinate of position- Throws:
IOException
- thrown if the graphics cannot be generated
-
cubicCurveTo
public void cubicCurveTo(double x1, double y1, double x2, double y2, double x, double y) throws IOException Description copied from interface:Canvas
Adds a cubic Beziér curve to the open path going from the previous point to the specified position. Two control points control the curve- Specified by:
cubicCurveTo
in interfaceCanvas
- Parameters:
x1
- x-coordinate of first control pointy1
- y-coordinate of first control pointx2
- x-coordinate of second control pointy2
- y-coordinate of second control pointx
- x-coordinate of positiony
- y-coordinate of position- Throws:
IOException
- thrown if the graphics cannot be generated
-
addRectangle
Description copied from interface:Canvas
Adds a rectangle to the path- Specified by:
addRectangle
in interfaceCanvas
- Parameters:
x
- the rectangle's left position (in mm)y
- the rectangle's top position (in mm)width
- the rectangle's width (in mm)height
- rectangle's height (in mm)- Throws:
IOException
- thrown if the graphics cannot be generated
-
closeSubpath
Description copied from interface:Canvas
Closes the current subpath- Specified by:
closeSubpath
in interfaceCanvas
- Throws:
IOException
- thrown if the graphics cannot be generated
-
fillPath
Description copied from interface:Canvas
Fills the current path and ends it- Specified by:
fillPath
in interfaceCanvas
- Parameters:
color
- the fill color (expressed similar to HTML, e.g. 0xffffff for white)smoothing
-true
for using smoothing techniques such as antialiasing,false
otherwise- Throws:
IOException
- thrown if the graphics cannot be generated
-
strokePath
public void strokePath(double strokeWidth, int color, Canvas.LineStyle lineStyle, boolean smoothing) throws IOException Description copied from interface:Canvas
Strokes the current path and ends it- Specified by:
strokePath
in interfaceCanvas
- Parameters:
strokeWidth
- the stroke width (in pt)color
- the stroke color (expressed similar to HTML, e.g. 0xffffff for white)lineStyle
- the line stylesmoothing
-true
for using smoothing techniques such as antialiasing,false
otherwise- Throws:
IOException
- thrown if the graphics cannot be generated
-
putText
public void putText(String text, double x, double y, int fontSize, boolean isBold) throws IOException Description copied from interface:Canvas
Adds text to the graphics.The text position refers to the left most point on the text's baseline.
- Specified by:
putText
in interfaceCanvas
- Parameters:
text
- the textx
- x position of the text's start (in mm)y
- y position of the text's top (in mm)fontSize
- the font size (in pt)isBold
- indicates if the text is in bold or regular weight- Throws:
IOException
- thrown if the graphics cannot be generated
-
setTransformation
public void setTransformation(double translateX, double translateY, double rotate, double scaleX, double scaleY) throws IOException Description copied from interface:Canvas
Sets a translation, rotation and scaling for the subsequent operationsBefore a new translation is applied, the coordinate system is reset to it's original state.
The transformations are applied in the order translation, rotation, scaling.
- Specified by:
setTransformation
in interfaceCanvas
- Parameters:
translateX
- translation in x direction (in mm)translateY
- translation in y direction (in mm)rotate
- rotation angle, in radiansscaleX
- scale factor in x direction (1.0 = no scaling)scaleY
- scale factor in y direction (1.0 = no scaling)- Throws:
IOException
- thrown if the graphics cannot be generated
-
toByteArray
Description copied from interface:ByteArrayResult
Gets the resulting graphics as a byte array.- Specified by:
toByteArray
in interfaceByteArrayResult
- Returns:
- the byte array
- Throws:
IOException
- thrown if the construction of the byte array fails
-
writeTo
Writes the resulting SVG image to the specified output stream.- Parameters:
os
- the output stream- Throws:
IOException
- thrown if the image cannot be written
-
saveAs
Saves the resulting SVG image to the specified path.- Parameters:
path
- the path to write to- Throws:
IOException
- thrown if the image cannot be written
-