Canvas

open class Canvas

Represents a class for drawing diagram items.

  • Creates a new Canvas from the specified context.

    Declaration

    Swift

    public init(context: CGContext)

    Parameters

    context

    The CGContext used by The canvas.

    Return Value

    The newly created Canvas instance.

  • Undocumented

    Declaration

    Swift

    public init(unit: MeasureUnit)
  • Draws a line between the two points specified as parameters.

    Declaration

    Swift

    open func drawLine(_ p1: Point, p2: Point)

    Parameters

    p1

    The point where the line starts.

    p2

    The point where the line ends.

  • Draws a line between the two points specified with their X and Y coordinates.

    Declaration

    Swift

    open func drawLine(_ x1: Double, y1: Double, x2: Double, y2: Double)

    Parameters

    x1

    A double value that represents the X-coordinate of the point where the line starts.

    y1

    A double value that represents the Y-coordinate of the point where the line starts.

    x2

    A double value that represents the X-coordinate of the point where the line ends.

    y2

    A double value that represents the Y-coordinate of the point where the line ends.

  • Draws lines between each pair of adjacent points from the array provided as a parameter.

    Declaration

    Swift

    open func drawLines(_ points: [Point])

    Parameters

    points

    The array that provides the points.

  • Draws lines between each pair of adjacent points from the array provided as a parameter.

    Declaration

    Swift

    open func drawPolyline(_ points: Array<Point>)

    Parameters

    points

    The array that provides the points.

  • Draws a bezier curve with the control points provided as a parameter.

    Declaration

    Swift

    open func drawBezier(_ points: Array<Point>)

    Parameters

    points

    An array with the control points of the Bezier curve.

  • Draws an ellipse with the specified center, width and height.

    Declaration

    Swift

    open func drawEllipse(_ x: Double, y: Double, width: Double, height: Double)

    Parameters

    x

    A double value that indicates the X-coordinate of the ellipse center.

    y

    A double value that indicates the Y-coordinate of the ellipse center.

    width

    A double value that indicates the width of the ellipse.

    height

    A double value that indicates the height of the ellipse.

  • Draws an ellipse in the rectangle provided as a parameter.

    Declaration

    Swift

    open func drawEllipse(_ rect: Rect)

    Parameters

    rect

    The Rectangle where the ellipse will be drawn.

  • Draws an arc in the specified rectangle from the given start and sweep angles.

    Declaration

    Swift

    open func drawArc(_ rect: Rect, start: Double, sweep: Double)

    Parameters

    rect

    The Rectangle where the arc will be drawn.

    start

    A double value that specifies the start angle of the arc.

    sweep

    A double value that specifies the sweep angle of the arc.

  • Draws a Rectangle. with the specified coordinates.

    Declaration

    Swift

    open func drawRect(_ rect: Rect)

    Parameters

    rect

    A Rectangle that specifies the drawing coordinates.

  • Draws a rectangle at the specified location and with the specified width and height.

    Declaration

    Swift

    open func drawRect(_ x: Double, y: Double, width: Double, height: Double)

    Parameters

    x

    The X-coordinate of the rectangle’s top left corner.

    y

    The Y-coordinate of the rectangle’s top left corner.

    width

    The width of the rectangle.

    height

    The height of the rectangle.

  • Strokes e.g. draws the outlining of the specified Rectangle.

    Declaration

    Swift

    open func strokeRect(_ rect: Rect)

    Parameters

    rect

    A Rectangle that specifies the drawing coordinates.

  • Strokes e.g. draws only the outlining of the rectangle at the specified location and with the specified width and height.

    Declaration

    Swift

    open func strokeRect(_ x: Double, y: Double, width: Double, height: Double)

    Parameters

    x

    The X-coordinate of the rectangle’s top left corner.

    y

    The Y-coordinate of the rectangle’s top left corner.

    width

    The width of the rectangle.

    height

    The height of the rectangle.

  • Fills e.g. draws the interior and not the border of the specified Rectangle.

    Declaration

    Swift

    open func fillRect(_ rect: Rect)

    Parameters

    rect

    A Rectangle that specifies the drawing coordinates.

  • Draws a text with the specified arguments.

    Declaration

    Swift

    open func drawText (
        _ text: String,
        rect: Rect,
        ha: HorizontalAlignment = HorizontalAlignment.left,
        va: VerticalAlignment = VerticalAlignment.top,
        bold: Bool = false,
        italic: Bool = false,
        underline: Bool = false)

    Parameters

    text

    A string with the text to draw.

    rect

    The layout rectangle of the text.

    ha

    The horizontal alignment of the text.

    va

    The vertical alignment of the text.

    bold

    A bool value, which indicates if the text should be drawn bold.

    italic

    A bool value, which indicates if the text should be drawn bold.

    underline

    A bool value, which indicates if the text should be drawn underlined.

  • Measures the height of the specified frame.

    Declaration

    Swift

    open func measureFrameHeight(_ frame: CTFrame) -> CGFloat

    Parameters

    frame

    A CTFrameRef object that provides the frame to measure.

    Return Value

    A CGFloat value that represents the height of the frame.

  • Measures the width of the specified frame.

    Declaration

    Swift

    open func measureFrameWidth(_ frame: CTFrame) -> CGFloat

    Parameters

    frame

    A CTFrameRef object that provides the frame to measure.

    Return Value

    A CGFloat value that represents the width of the frame.

  • Draws the specified text at the specified location.

    Declaration

    Swift

    open func drawText(_ text: String, point: Point)

    Parameters

    text

    The text to draw.

    point

    The top left corner of the rectangle that contains the specified text.

  • Starts a path from the current CGContext to infinity.

    Declaration

    Swift

    open func pathStart()
  • Closes the current CGContext path.

    Declaration

    Swift

    open func pathCloseFigure()
  • Moves the points in the current pathMatrix with the specified point.

    Declaration

    Swift

    open func pathMoveTo(_ point: Point)

    Parameters

    point

    The Point whose coordinates are used for correction of the coordinates of the pathMatrix.

  • Draws a line from the end of the path to the specified Point.

    Declaration

    Swift

    open func pathLineTo(_ point: Point)

    Parameters

    point

    The Point, where the newly drawn line will end.

  • Draws a Bezier curve from the end of the parh through the points provided as parameters.

    Declaration

    Swift

    open func pathBezierTo(_ point2: Point, point3: Point, point4: Point)

    Parameters

    point2

    The second control Point of the Bezier curve that will be drawn.

    point3

    The third control Point of the Bezier curve that will be drawn.

    point4

    The last control Point of the Bezier curve that will be drawn.

  • Draws an ellipse at the end of the path.

    Declaration

    Swift

    open func pathEllipse(_ rect: Rect)

    Parameters

    rect

    The rectangle that bounds the ellipse to be drawn.

  • Draws a rounded rectangle at the end of the path.

    Declaration

    Swift

    public func pathRoundRect(_ rect: Rect, radius: Double)

    Parameters

    rect

    The rectangle to be drawn.

    radius

    A double value that specifies the corner radius of the rectangle.

  • Adds an arc to the current path.

    Declaration

    Swift

    open func pathArcTo(_ rect: Rect, a: Double, s: Double)

    Parameters

    rect

    The rectangle that contains the arc to be drawn.

    a

    Double value that defines the start angle of the arc.

    s

    Double value that defines the sweep angle of the arc.

  • Draws the specified GraphicsPath.

    Declaration

    Swift

    open func drawPath(_ path: GraphicsPath)
  • Draws the path of the current CGContext.

    Declaration

    Swift

    open func pathDraw()
  • Draws the outlining of the path of the current CGContext.

    Declaration

    Swift

    open func pathStroke()
  • Sets the Matrix of the current path.

    Declaration

    Swift

    open func setPathMatrix(_ matrix: Matrix?)
  • Gets the end of the current path.

    Declaration

    Swift

    open func getPathEnd() -> Point

    Return Value

    A Point that specifies the end of the current path.

  • Draws the specified image in the specified rectangle and with the specified alignment.

    Declaration

    Swift

    open func drawImage(_ image: UIImage!, rect: Rect, align: ImageAlign)

    Parameters

    image

    The image to be drawn.

    rect

    The layout rectangle of the image.

    align

    The alignment of the image in the specified layout rectangle.

  • Translates the current CGContext with the specified X and Y values.

    Declaration

    Swift

    open func translateTransform(_ x: Double, y: Double)

    Parameters

    x

    A double value that specifies the X-coordinate of the translation.

    y

    A double value that specifies the Y-coordinate of the translation.

  • Translates the current CGContext with the specified Point.

    Declaration

    Swift

    open func translateTransform(_ point: Point)

    Parameters

    point

    The Point that provides coordinates of the translation.

  • Scales the current CGContext with the specified amount.

    Declaration

    Swift

    open func scaleTransform(_ s: Double)

    Parameters

    s

    A double value that specifies the scale’s value.

  • Undocumented

    Declaration

    Swift

    open func scaleAtCenter(sx: Double, sy: Double, rect: Rect)
  • Rotates the current CGContext with the specified angle.

    Declaration

    Swift

    open func rotateTransform(_ angle: Double)

    Parameters

    angle

    A double value that specifies the angle of the rotation.

  • Rotates the current CGContext with the specified angle around the specified pivot point.

    Declaration

    Swift

    open func rotateTransform(_ angle: Double, pivot: Point)

    Parameters

    angle

    A double value that specifies the angle of the rotation.

    pivot

    A Point value that specifies the pivot of the rotation.

  • Saves the state of the current context.

    Declaration

    Swift

    open func saveState()
  • Restores the state of the current context.

    Declaration

    Swift

    open func restoreState()
  • Clips the state of the current context to the specified rectangle.

    Declaration

    Swift

    open func clip(_ rect: Rect)

    Parameters

    rect

    A rectangle that specifies the clipping region.

  • Undocumented

    Declaration

    Swift

    open func clipToPath(_ path: GraphicsPath)
  • Sets the font for text drawn at this Canvas.

    Declaration

    Swift

    open func setFont(
        _ fontName: String,
        fontSize: Double,
        fontUnit: MeasureUnit)

    Parameters

    fontName

    A string that specifies the name of the font.

    fontSize

    A double value that specifies the size of the font.

    fontUnit

    A MeasureUnit that specifies how font is measured.

  • Sets the color of text drawn at this Canvas.

    Declaration

    Swift

    open func setTextColor(_ color: Color)

    Parameters

    color

    The Color of the text.

  • Defines a variable that keeps information about the MeasureUnit used by The canvas.

    Declaration

    Swift

    open var measureUnit: MeasureUnit { get set }
  • Sets the stroke color.

    Declaration

    Swift

    open func setStroke(_ color: Color)

    Parameters

    color

    The Color of the outlining of objects drawn in this canvas.

  • Sets the thickness of the stroke.

    Declaration

    Swift

    public func setStrokeThickness(_ thickness: Double)

    Parameters

    thickness

    A double value that specifies the thickness of the stroke of objects drawn in this canvas.

  • Sets the Brush of objects drawn in this canvas.

    Declaration

    Swift

    open func setBrush(_ brush: Brush?)

    Parameters

    brush

    The Brush used for drawing objects in this canvas.

  • Sets the dash style for lines drawn in this canvas.

    Declaration

    Swift

    open func setLineDashStyle(_ lengths: [Float])

    Parameters

    lengths

    Array with float values that specify the dash pattern for lines drawn in this canvas.

  • The CGContext used by this canvas.

    Declaration

    Swift

    open var context: CGContext
  • The name of the font used when text is drawn in this canvas.

    Declaration

    Swift

    open var fontName: String
  • The color of the text drawn in this canvas.

    Declaration

    Swift

    open var textColor: Color
  • The size of the text drawn in this canvas.

    Declaration

    Swift

    open var fontSize: Double
  • The Brush currently used by this canvas.

    Declaration

    Swift

    open var currentBrush: Brush?
  • The Point where the path used by this canvas ends.

    Declaration

    Swift

    open var pathEnd: Point
  • The matrix of the path used by this canvas.

    Declaration

    Swift

    open var pathMatrix: Matrix?