Package net.codecrete.qrbill.canvas
Class AbstractCanvas
- java.lang.Object
-
- net.codecrete.qrbill.canvas.AbstractCanvas
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,Canvas
public abstract class AbstractCanvas extends java.lang.Object implements Canvas
Abstract base class for simplified implementation ofCanvasclasses.The class mainly implements text measurement and a helper for multi-line text.
-
-
Field Summary
Fields Modifier and Type Field Description protected static doubleMM_TO_PT
-
Constructor Summary
Constructors Constructor Description AbstractCanvas()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description doublegetAscender(int fontSize)Distance between baseline and top of highest letter.doublegetDescender(int fontSize)Distance between baseline and bottom of letter extending the farest below the baseline.doublegetLineHeight(int fontSize)Distance between the baselines of two consecutive text lines.doublegetTextWidth(java.lang.CharSequence text, int fontSize, boolean isBold)Returns the width of the specified text for the specified font sizevoidputTextLines(java.lang.String[] lines, double x, double y, int fontSize, double leading)Adds several lines of text to the graphics.protected voidsetupFontMetrics(java.lang.String fontFamilyList)java.lang.String[]splitLines(java.lang.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, wait
-
Methods inherited from interface net.codecrete.qrbill.canvas.Canvas
addRectangle, closeSubpath, cubicCurveTo, fillPath, getResult, lineTo, moveTo, putText, setTransformation, setupPage, startPath, strokePath
-
-
-
-
Field Detail
-
MM_TO_PT
protected static final double MM_TO_PT
- See Also:
- Constant Field Values
-
-
Method Detail
-
setupFontMetrics
protected void setupFontMetrics(java.lang.String fontFamilyList)
-
putTextLines
public void putTextLines(java.lang.String[] lines, double x, double y, int fontSize, double leading) throws java.io.IOExceptionDescription 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:
java.io.IOException- thrown if the graphics cannot be generated
-
getAscender
public double getAscender(int fontSize)
Description copied from interface:CanvasDistance between baseline and top of 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 farest 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
public double getTextWidth(java.lang.CharSequence text, int fontSize, boolean isBold)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
public java.lang.String[] splitLines(java.lang.String text, double maxLength, int fontSize)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
-
-