Interface Canvas
- All Superinterfaces:
AutoCloseable
,Closeable
- All Known Implementing Classes:
AbstractCanvas
,Graphics2DCanvas
,PDFCanvas
,PNGCanvas
,SVGCanvas
The coordinate system has its origin in the bottom left corner. The y-axis extends from the bottom to the top.
The graphics model is similar to the one used by PDF, in particular with regards to the orientation of the y axis, the concept of a current path, and using the baseline for positioning text.
Instance of this class are expected to use a single font family for the QR bill (regular and bold font weight).
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addRectangle
(double x, double y, double width, double height) Adds a rectangle to the pathvoid
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 itdouble
getAscender
(int fontSize) Distance between baseline and top of the highest letter.double
getDescender
(int fontSize) Distance between baseline and bottom of letter extending the farthest below the baseline.double
getLineHeight
(int fontSize) Distance between the baselines of two consecutive text lines.double
getTextWidth
(CharSequence text, int fontSize, boolean isBold) Returns the width of the specified text for the specified font sizevoid
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
putTextLines
(String[] lines, double x, double y, int fontSize, double leading) Adds several lines of text to the graphics.void
setTransformation
(double translateX, double translateY, double rotate, double scaleX, double scaleY) Sets a translation, rotation and scaling for the subsequent operationsString[]
splitLines
(String text, double maxLength, int fontSize) Splits the text into lines.void
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 it
-
Method Details
-
setTransformation
void setTransformation(double translateX, double translateY, double rotate, double scaleX, double scaleY) throws IOException 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.
- 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
-
putText
Adds text to the graphics.The text position refers to the left most point on the text's baseline.
- 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
-
putTextLines
void putTextLines(String[] lines, double x, double y, int fontSize, double leading) throws IOException Adds several lines of text to the graphics.The text position refers to the left most point on the baseline of the first text line. Additional lines then follow below.
- Parameters:
lines
- the text linesx
- 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)leading
- additional vertical space between text lines (in mm)- Throws:
IOException
- thrown if the graphics cannot be generated
-
startPath
Starts a path that can be filled or stroked- Throws:
IOException
- thrown if the graphics cannot be generated
-
moveTo
Moves the current point of the open path to the specified position.- Parameters:
x
- x-coordinate of positiony
- y-coordinate of position- Throws:
IOException
- thrown if the graphics cannot be generated
-
lineTo
Adds a line segment to the open path from the previous point to the specified position.- Parameters:
x
- x-coordinate of positiony
- y-coordinate of position- Throws:
IOException
- thrown if the graphics cannot be generated
-
cubicCurveTo
void cubicCurveTo(double x1, double y1, double x2, double y2, double x, double y) throws IOException 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- 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
Adds a rectangle to the path- 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
Closes the current subpath- Throws:
IOException
- thrown if the graphics cannot be generated
-
fillPath
Fills the current path and ends it- 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
void strokePath(double strokeWidth, int color, Canvas.LineStyle lineStyle, boolean smoothing) throws IOException Strokes the current path and ends it- 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
-
getAscender
double getAscender(int fontSize) Distance between baseline and top of the highest letter.- Parameters:
fontSize
- the font size (in pt)- Returns:
- the distance (in mm)
-
getDescender
double getDescender(int fontSize) Distance between baseline and bottom of letter extending the farthest below the baseline.- Parameters:
fontSize
- the font size (in pt)- Returns:
- the distance (in mm)
-
getLineHeight
double getLineHeight(int fontSize) Distance between the baselines of two consecutive text lines.- Parameters:
fontSize
- the font size (in pt)- Returns:
- the distance (in mm)
-
getTextWidth
Returns the width of the specified text for the specified font size- Parameters:
text
- textfontSize
- font size (in pt)isBold
- indicates if the text is in bold or regular weight- Returns:
- width (in mm)
-
splitLines
Splits the text into lines.If a line would exceed the specified maximum length, line breaks are inserted. Newlines are treated as fixed line breaks.
- Parameters:
text
- the textmaxLength
- the maximum line length (in pt)fontSize
- the font size (in pt)- Returns:
- an array of text lines
-