Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No ImageSurface representation in Swift API #2

Open
UARTman opened this issue Nov 14, 2021 · 2 comments
Open

No ImageSurface representation in Swift API #2

UARTman opened this issue Nov 14, 2021 · 2 comments

Comments

@UARTman
Copy link

UARTman commented Nov 14, 2021

Current Swift Cairo API lacks a way to operate an ImageSurface. There's a function to create one, but that's it. You can't import a PNG or arbitrarily access surface data without calling CCairo api.

Are there any technical limitations behind this absence, or is it just something that isn't done yet? If it's the second, I'd like to take a shot at fixing it.

@UARTman
Copy link
Author

UARTman commented Nov 14, 2021

Also, another related problem is the absence of setSourceSurface method from Swift Context API. This means I need to use C API to render an image onto a DrawingArea. Again, if possible, I'd like to implement this functionality, but I'm not sure where to start.

@rhx
Copy link
Owner

rhx commented Nov 15, 2021

Yes, it appears that the .gir file that comes with Cairo lacks some functions and documentation. It is possible to add convenience functions manually, see SwiftCairoSurfaceConvenienceAdditions.swift for example (feel free to file pull requests for missing functions).

Also, you can wrap any surface you get from a C function into a Surface or SurfaceRef and then use it with the Swift API, e.g.:

if let surface = Surface(cairo_image_surface_create_from_png("some.png")) {
    /// do something with the surface;
    /// the Surface class will automatically call cairo_surface_destroy() on deinit
    /// (if you don't want that, use SurfaceRef instead)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants