Interface ICanvas
Common interface for all output formats to draw the QR bill.
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).
Inherited Members
Namespace: Codecrete.SwissQRBill.Generator.Canvas
Assembly: Codecrete.SwissQRBill.Core.dll
Syntax
public interface ICanvas : IDisposable
Methods
| Improve this Doc View SourceAddRectangle(Double, Double, Double, Double)
Adds a rectangle to the open path.
Declaration
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
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
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
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
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). |
FillPath(Int32, Boolean)
Fills the current path and discards it.
Declaration
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
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
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
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
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
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
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). |
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
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
void StartPath()
StrokePath(Double, Int32, LineStyle, Boolean)
Strokes the current path and discards it.
Declaration
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
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
byte[] ToByteArray()
Returns
Type | Description |
---|---|
System.Byte[] | The result. |