UIKit-cross-platform icon indicating copy to clipboard operation
UIKit-cross-platform copied to clipboard

Implement CGContext

Open ephemer opened this issue 8 years ago • 4 comments

CGContext is a drawing canvas. We can use it to render fonts, convert 32bit PNGs to 8bit Alpha maps etc.

Implementation

The easiest method available to us is to make CGContext a thin wrapper over SDLSurface - both have similar initialisers, properties, and methods. And a SDLSurface can be easily converted to a CGImage (as can a CGContext). If we need more advanced drawing capabilities (rounded circles etc) we can use (lib) Cairo to draw on the SDLSurface internally.

This work has been done in Cacao: https://github.com/PureSwift/Cacao. @colemancda has indicated to us that it'd be fine to use the implementation he implemented using Cairo, we "just" need to build Cairo for Android and adapt his internal UIKit code to match our structures.

ephemer avatar Oct 30 '17 13:10 ephemer

The actual code is here: https://github.com/PureSwift/Silica CoreGraphics is actually one of the really solid parts of the Cacao project. You need the get Cairo compiling via the SwiftPM or an Android binary.

colemancda avatar Oct 19 '18 01:10 colemancda

Alternatively, you can use skia for 2D. It is pretty close to CGContext from my experience.

3d4m-volodymyr avatar Aug 12 '21 20:08 3d4m-volodymyr

Great, how to you use C++ Skia from Swift? Is there a wrapper library somewhere? I would love to use Skia and Swift on Linux and Android.

colemancda avatar Aug 12 '21 20:08 colemancda

Yea, for some features it will require writing a thin layer to make C APIs. :) Some APIs are available as C.

3d4m-volodymyr avatar Aug 12 '21 20:08 3d4m-volodymyr