Package net.codecrete.qrbill.canvas
Class AbstractCanvas
java.lang.Object
net.codecrete.qrbill.canvas.AbstractCanvas
- All Implemented Interfaces:
Closeable,AutoCloseable,Canvas
- Direct Known Subclasses:
Graphics2DCanvas,PDFCanvas,SVGCanvas
Abstract base class for simplified implementation of
Canvas classes.
The class mainly implements text measurement and a helper for multi-line text.
-
Nested Class Summary
Nested classes/interfaces inherited from interface net.codecrete.qrbill.canvas.Canvas
Canvas.LineStyle -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected FontMetricsFont metrics information.protected static final doubleFactor for converting mm to points (1/72in) -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondoublegetAscender(int fontSize) Distance between baseline and top of the highest letter.doublegetDescender(int fontSize) Distance between baseline and bottom of letter extending the farthest below the baseline.doublegetLineHeight(int fontSize) Distance between the baselines of two consecutive text lines.doublegetTextWidth(CharSequence text, int fontSize, boolean isBold) Returns the width of the specified text for the specified font sizevoidputTextLines(String[] lines, double x, double y, int fontSize, double leading) Adds several lines of text to the graphics.protected voidsetupFontMetrics(String fontFamilyList) Initializes the font metrics information for the specified font.String[]splitLines(String text, double maxLength, int fontSize) Splits the text into lines.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.codecrete.qrbill.canvas.Canvas
addRectangle, closeSubpath, cubicCurveTo, fillPath, lineTo, moveTo, putText, setTransformation, startPath, strokePath
-
Field Details
-
MM_TO_PT
protected static final double MM_TO_PTFactor for converting mm to points (1/72in)- See Also:
-
fontMetrics
Font metrics information.Available once
setupFontMetrics(String)has been called.
-
-
Constructor Details
-
AbstractCanvas
protected AbstractCanvas()Creates a new instance.
-
-
Method Details
-
setupFontMetrics
Initializes the font metrics information for the specified font.The first font in the specified list of fonts is used.
- Parameters:
fontFamilyList- list of font families
-
putTextLines
public void putTextLines(String[] lines, double x, double y, int fontSize, double leading) throws IOException Description copied from interface:CanvasAdds 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.
- Specified by:
putTextLinesin interfaceCanvas- 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
-
getAscender
public double getAscender(int fontSize) Description copied from interface:CanvasDistance between baseline and top of the highest letter.- Specified by:
getAscenderin interfaceCanvas- Parameters:
fontSize- the font size (in pt)- Returns:
- the distance (in mm)
-
getDescender
public double getDescender(int fontSize) Description copied from interface:CanvasDistance between baseline and bottom of letter extending the farthest below the baseline.- Specified by:
getDescenderin interfaceCanvas- Parameters:
fontSize- the font size (in pt)- Returns:
- the distance (in mm)
-
getLineHeight
public double getLineHeight(int fontSize) Description copied from interface:CanvasDistance between the baselines of two consecutive text lines.- Specified by:
getLineHeightin interfaceCanvas- Parameters:
fontSize- the font size (in pt)- Returns:
- the distance (in mm)
-
getTextWidth
Description copied from interface:CanvasReturns the width of the specified text for the specified font size- Specified by:
getTextWidthin interfaceCanvas- Parameters:
text- textfontSize- font size (in pt)isBold- indicates if the text is in bold or regular weight- Returns:
- width (in mm)
-
splitLines
Description copied from interface:CanvasSplits the text into lines.If a line would exceed the specified maximum length, line breaks are inserted. Newlines are treated as fixed line breaks.
- Specified by:
splitLinesin interfaceCanvas- Parameters:
text- the textmaxLength- the maximum line length (in pt)fontSize- the font size (in pt)- Returns:
- an array of text lines
-