Show / Hide Table of Contents

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
IDisposable.Dispose()
Namespace: Codecrete.SwissQRBill.Generator.Canvas
Assembly: Codecrete.SwissQRBill.Core.dll
Syntax
public interface ICanvas : IDisposable

Methods

| Edit this page View Source

AddRectangle(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
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).

| Edit this page View Source

Ascender(int)

Gets the distance between the baseline and the top of the tallest letter.

Declaration
double Ascender(int fontSize)
Parameters
Type Name Description
int fontSize

The font size (in pt).

Returns
Type Description
double

The distance (in mm).

| Edit this page View Source

CloseSubpath()

Closes the current subpath. The next path operation will implicitly open a new subpath.

Declaration
void CloseSubpath()
| Edit this page View Source

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
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.

| Edit this page View Source

Descender(int)

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
int fontSize

The font size (in pt).

Returns
Type Description
double

The distance (in mm).

| Edit this page View Source

FillPath(int, bool)

Fills the current path and discards it.

Declaration
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

true for using smoothing techniques such as antialiasing, false otherwise

| Edit this page View Source

LineHeight(int)

Gets the distance between the baselines of two consecutive text lines.

Declaration
double LineHeight(int fontSize)
Parameters
Type Name Description
int fontSize

The font size (in pt).

Returns
Type Description
double

The distance (in mm).

| Edit this page View Source

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
double x

The x-coordinate of position.

double y

The y-coordinate of position.

| Edit this page View Source

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
double x

The x-coordinate of position.

double y

The y-coordinate of position.

| Edit this page View Source

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
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.

| Edit this page View Source

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
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).

| Edit this page View Source

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
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).

| Edit this page View Source

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
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.

| Edit this page View Source

StartPath()

Starts a path that can be filled or stroked.

Declaration
void StartPath()
| Edit this page View Source

StrokePath(double, int, LineStyle, bool)

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
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

true for using smoothing techniques such as antialiasing, false otherwise

| Edit this page View Source

TextWidth(string, int, bool)

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
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).

| Edit this page View Source

ToByteArray()

Returns the result as a byte array.

Declaration
byte[] ToByteArray()
Returns
Type Description
byte[]

The result.

  • Edit this page
  • View Source
In this article
Back to top Generated by DocFX