Class AbstractCanvas
Abstract base class for simplified implementation of classes implementing ICanvas.
The class mainly implements text measurement and a helper for multi-line text.
Inherited Members
Namespace: Codecrete.SwissQRBill.Generator.Canvas
Assembly: Codecrete.SwissQRBill.Core.dll
Syntax
public abstract class AbstractCanvas : ICanvas, IDisposable
Fields
| Improve this Doc View SourceFontMetrics
Font metrics used by this canvas.
Declaration
protected FontMetrics FontMetrics
Field Value
Type | Description |
---|---|
FontMetrics |
MmToPt
Conversion factor from mm to point
Declaration
protected static readonly double MmToPt
Field Value
Type | Description |
---|---|
System.Double |
Methods
| Improve this Doc View SourceAddRectangle(Double, Double, Double, Double)
Adds a rectangle to the open path.
Declaration
public abstract void AddRectangle(double x, double y, double width, double height)
Parameters
Type | Name | Description |
---|---|---|
System.Double | x | The rectangle's left position (in mm). |
System.Double | y | The rectangle's top position (in mm). |
System.Double | width | The rectangle's width (in mm). |
System.Double | height | The rectangle's height (in mm). |
Ascender(Int32)
Gets the distance between the baseline and the top of the tallest letter.
Declaration
public double Ascender(int fontSize)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | fontSize | The font size (in pt). |
Returns
Type | Description |
---|---|
System.Double | The distance (in mm). |
CloseSubpath()
Closes the current subpath. The next path operation will implicitly open a new subpath.
Declaration
public abstract void CloseSubpath()
CubicCurveTo(Double, Double, Double, Double, Double, Double)
Adds a cubic Beziér curve to the open path going from the previous point to the specified position. Two control points determine the curve.
Declaration
public abstract void CubicCurveTo(double x1, double y1, double x2, double y2, double x, double y)
Parameters
Type | Name | Description |
---|---|---|
System.Double | x1 | The x-coordinate of first control point. |
System.Double | y1 | The y-coordinate of first control point. |
System.Double | x2 | The x-coordinate of second control point. |
System.Double | y2 | The y-coordinate of second control point. |
System.Double | x | The x-coordinate of position. |
System.Double | y | The y-coordinate of position. |
Descender(Int32)
Gets the distance between the baseline and the bottom of the letter extending the farthest below the baseline.
Declaration
public double Descender(int fontSize)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | fontSize | The font size (in pt). |
Returns
Type | Description |
---|---|
System.Double | The distance (in mm). |
Dispose()
Declaration
public void Dispose()
Dispose(Boolean)
Frees and releases resources.
Declaration
protected abstract void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | disposing | indicates whether the method is called from a |
FillPath(Int32, Boolean)
Fills the current path and discards it.
Declaration
public abstract void FillPath(int color, bool smoothing = true)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | color | The fill color (expressed similar to HTML, e.g. 0xffffff for white). |
System.Boolean | smoothing |
|
LineHeight(Int32)
Gets the distance between the baselines of two consecutive text lines.
Declaration
public double LineHeight(int fontSize)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | fontSize | The font size (in pt). |
Returns
Type | Description |
---|---|
System.Double | The distance (in mm). |
LineTo(Double, Double)
Adds a line segment to the open path from the previous point to the specified position.
Declaration
public abstract void LineTo(double x, double y)
Parameters
Type | Name | Description |
---|---|---|
System.Double | x | The x-coordinate of position. |
System.Double | y | The y-coordinate of position. |
MoveTo(Double, Double)
Moves the current point of the open path to the specified position.
Declaration
public abstract void MoveTo(double x, double y)
Parameters
Type | Name | Description |
---|---|---|
System.Double | x | The x-coordinate of position. |
System.Double | y | The y-coordinate of position. |
PutText(String, Double, Double, Int32, Boolean)
Draws text to the canvas.
The text position refers to the left most point on the text's baseline.
Declaration
public abstract void PutText(string text, double x, double y, int fontSize, bool isBold)
Parameters
Type | Name | Description |
---|---|---|
System.String | text | The text to draw. |
System.Double | x | The x position of the text's start (in mm). |
System.Double | y | The y position of the text's top (in mm). |
System.Int32 | fontSize | The font size (in pt). |
System.Boolean | isBold | Flag indicating if the text is in bold or regular weight. |
PutTextLines(String[], Double, Double, Int32, Double)
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.
Declaration
public virtual void PutTextLines(string[] lines, double x, double y, int fontSize, double leading)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | lines | The text lines to draw. |
System.Double | x | The x position of the text's start (in mm). |
System.Double | y | The y position of the text's top (in mm). |
System.Int32 | fontSize | The font size (in pt). |
System.Double | leading | The amount of additional vertical space between text lines (in mm). |
SetTransformation(Double, Double, Double, Double, Double)
Sets a translation, rotation and scaling for the subsequent operations.
Before 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.
Declaration
public abstract void SetTransformation(double translateX, double translateY, double rotate, double scaleX, double scaleY)
Parameters
Type | Name | Description |
---|---|---|
System.Double | translateX | The translation in x direction (in mm). |
System.Double | translateY | The translation in y direction (in mm). |
System.Double | rotate | The rotation angle, in radians. |
System.Double | scaleX | The scale factor in x direction (1.0 = no scaling). |
System.Double | scaleY | The scale factor in y direction (1.0 = no scaling). |
SetupFontMetrics(String)
Sets up the font metrics using the first font family in the specified list.
Declaration
protected void SetupFontMetrics(string fontFamilyList)
Parameters
Type | Name | Description |
---|---|---|
System.String | fontFamilyList | The font family list. |
SplitLines(String, Double, Int32)
Splits the text into lines.
The text is split such that no line is wider the specified maximum width. If possible, the text is split at whitespace characters. If a word is wider than the specified maximum width, the word is split and put onto two or more lines. The text is always split at newlines.
Declaration
public string[] SplitLines(string text, double maxLength, int fontSize)
Parameters
Type | Name | Description |
---|---|---|
System.String | text | The text to split into lines. |
System.Double | maxLength | The maximum line length (in pt). |
System.Int32 | fontSize | The font size (in pt). |
Returns
Type | Description |
---|---|
System.String[] | The resulting array of text lines. |
StartPath()
Starts a path that can be filled or stroked.
Declaration
public abstract void StartPath()
StrokePath(Double, Int32, LineStyle, Boolean)
Strokes the current path and discards it.
Declaration
public abstract void StrokePath(double strokeWidth, int color, LineStyle lineStyle = LineStyle.Solid, bool smoothing = true)
Parameters
Type | Name | Description |
---|---|---|
System.Double | strokeWidth | The stroke width (in pt). |
System.Int32 | color | The stroke color (expressed similar to HTML, e.g. 0xffffff for white). |
LineStyle | lineStyle | The line style |
System.Boolean | smoothing |
|
TextWidth(String, Int32, Boolean)
Measures the width of the specified text for the specified font size.
Declaration
public double TextWidth(string text, int fontSize, bool isBold)
Parameters
Type | Name | Description |
---|---|---|
System.String | text | The text to measure. |
System.Int32 | fontSize | The text's font size (in pt). |
System.Boolean | isBold | Flag indicating if the text is in bold or regular weight. |
Returns
Type | Description |
---|---|
System.Double | The measured width (in mm). |
ToByteArray()
Returns the result as a byte array.
Declaration
public abstract byte[] ToByteArray()
Returns
Type | Description |
---|---|
System.Byte[] | The result. |