Swift : Extended CGContext with Drawing functions

Here is a CGContext extenstion of Swift [iOS] the adds most if not all of the drawing features on the Xojo “Graphic” object. A CGContext cannot be subclassed so a few things had to be done differently.

This is just that basic header info. If you would like a copy of the entire code, drop me an message

I still might be making a few minor tweaks

//
//  Extend_CGContext.swift
//
//  Created by David Sisemore on 5/30/23.
//  Copyright © 2023 R.DavidSisemore. All rights reserved.
//

extension CGContext {
    public enum linePattern : Int {
        case none
        case solid
        case dotted
        case dashed
    }

    var size   : CGSize  { 
    var width  : CGFloat { 
    var height : CGFloat { 
    //
    public func setFillColor(_ color:UIColor)   {  // to remove need to always add .cgColor
    public func setStrokeColor(_ color:UIColor) { // to remove need to always add .cgColor

   public  func penStyle(_ pattern:linePattern) {
    //
    public func drawLine(_ x1:CGFloat,_ y1:CGFloat,_ x2:CGFloat,_ y2:CGFloat, antiAlias:Bool=true) {

    public func drawOval(_ rect:CGRect) {}
    public func drawOval(_ x:CGFloat,_ y:CGFloat,_ width:CGFloat,_ height:CGFloat) { 

    public final func drawPolygon(_ points:[CGPoint] , fill:Bool=false) {

    public final func drawRect(_ rect:CGRect) { 
    public final func drawRect(_ x:CGFloat,_ y:CGFloat,_ width:CGFloat,_ height:CGFloat) { 

    public final func drawRoundrect(_ rect:CGRect,_ radius:CGFloat) { 
    public final func drawRoundrect(_ x:CGFloat,_ y:CGFloat,_ width:CGFloat,_ height:CGFloat,_ radius:CGFloat) { 

    public final func fillOval(_ rect:CGRect) { self.fillEllipse(in: rect)}
    public final func fillOval(_ x:CGFloat,_ y:CGFloat,_ width:CGFloat,_ height:CGFloat) { 

    public final func fillPolygon(_ points:[CGPoint]) { drawPolygon(points,fill: true) }

    public final func fillRect(_ rect:CGRect) { self.fill(rect) }
    public final func fillRect(_ x:CGFloat,_ y:CGFloat,_ width:CGFloat,_ height:CGFloat) { 

    public final func fillRoundrect(_ rect:CGRect,_ radius:CGFloat) { 
    public final func fillRoundrect(_ x:CGFloat,_ y:CGFloat,_ width:CGFloat,_ height:CGFloat,_ radius:CGFloat) {

    //
    // This has different syntax than Xojo as a CGContext cannot be subclassed to hold these properties
    //
    func displayText(_ rect:CGRect,_ str : String,_ font: UIFont, textColor: UIColor,align: NSTextAlignment) {
}