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
| Edit this page 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 |
|---|---|
| double |
Methods
| Edit this page 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 |
|---|---|---|
| double | x | The rectangle's left position (in mm). |
| double | y | The rectangle's top position (in mm). |
| double | width | The rectangle's width (in mm). |
| double | height | The rectangle's height (in mm). |
Ascender(int)
Gets the distance between the baseline and the top of the tallest letter.
Declaration
public double Ascender(int fontSize)
Parameters
| Type | Name | Description |
|---|---|---|
| int | fontSize | The font size (in pt). |
Returns
| Type | Description |
|---|---|
| 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 |
|---|---|---|
| double | x1 | The x-coordinate of first control point. |
| double | y1 | The y-coordinate of first control point. |
| double | x2 | The x-coordinate of second control point. |
| double | y2 | The y-coordinate of second control point. |
| double | x | The x-coordinate of position. |
| double | y | The y-coordinate of position. |
Descender(int)
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 |
|---|---|---|
| int | fontSize | The font size (in pt). |
Returns
| Type | Description |
|---|---|
| double | The distance (in mm). |
Dispose()
Declaration
public void Dispose()
Dispose(bool)
Frees and releases resources.
Declaration
protected abstract void Dispose(bool disposing)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | disposing | indicates whether the method is called from a |
FillPath(int, bool)
Fills the current path and discards it.
Declaration
public abstract void FillPath(int color, bool smoothing = true)
Parameters
| Type | Name | Description |
|---|---|---|
| int | color | The fill color (expressed similar to HTML, e.g. 0xffffff for white). |
| bool | smoothing |
|
LineHeight(int)
Gets the distance between the baselines of two consecutive text lines.
Declaration
public double LineHeight(int fontSize)
Parameters
| Type | Name | Description |
|---|---|---|
| int | fontSize | The font size (in pt). |
Returns
| Type | Description |
|---|---|
| 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 |
|---|---|---|
| double | x | The x-coordinate of position. |
| 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 |
|---|---|---|
| double | x | The x-coordinate of position. |
| double | y | The y-coordinate of position. |
PutText(string, double, double, int, bool)
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 |
|---|---|---|
| string | text | The text to draw. |
| double | x | The x position of the text's start (in mm). |
| double | y | The y position of the text's top (in mm). |
| int | fontSize | The font size (in pt). |
| bool | isBold | Flag indicating if the text is in bold or regular weight. |
PutTextLines(string[], double, double, int, 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 |
|---|---|---|
| string[] | lines | The text lines to draw. |
| double | x | The x position of the text's start (in mm). |
| double | y | The y position of the text's top (in mm). |
| int | fontSize | The font size (in pt). |
| 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 |
|---|---|---|
| double | translateX | The translation in x direction (in mm). |
| double | translateY | The translation in y direction (in mm). |
| double | rotate | The rotation angle, in radians. |
| double | scaleX | The scale factor in x direction (1.0 = no scaling). |
| 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 |
|---|---|---|
| string | fontFamilyList | The font family list. |
SplitLines(string, double, int)
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 |
|---|---|---|
| string | text | The text to split into lines. |
| double | maxLength | The maximum line length (in pt). |
| int | fontSize | The font size (in pt). |
Returns
| Type | Description |
|---|---|
| string[] | The resulting array of text lines. |
StartPath()
Starts a path that can be filled or stroked.
Declaration
public abstract void StartPath()
StrokePath(double, int, LineStyle, bool)
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 |
|---|---|---|
| double | strokeWidth | The stroke width (in pt). |
| int | color | The stroke color (expressed similar to HTML, e.g. 0xffffff for white). |
| LineStyle | lineStyle | The line style |
| bool | smoothing |
|
TextWidth(string, int, bool)
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 |
|---|---|---|
| string | text | The text to measure. |
| int | fontSize | The text's font size (in pt). |
| bool | isBold | Flag indicating if the text is in bold or regular weight. |
Returns
| Type | Description |
|---|---|
| double | The measured width (in mm). |
ToByteArray()
Returns the result as a byte array.
Declaration
public abstract byte[] ToByteArray()
Returns
| Type | Description |
|---|---|
| byte[] | The result. |