// Code generated by cmd/cgo; DO NOT EDIT.

//line /home/josie/.cache/paru/clone/wiiudownloader/src/pkg/mod/github.com/gotk3/gotk3@v0.6.5-0.20240618185848-ff349ae13f56/cairo/surface.go:1:1
package cairo

// #include <stdlib.h>
// #include <cairo.h>
// #include <cairo-gobject.h>
// #include <cairo-pdf.h>
import _ "unsafe"

import (
	"runtime"
	"unsafe"

	"github.com/gotk3/gotk3/glib"
)

/*
 * cairo_surface_t
 */

// Surface is a representation of Cairo's cairo_surface_t.
type Surface struct {
	surface * /*line :22:11*/_Ctype_cairo_surface_t /*line :22:28*/
}

func NewSurfaceFromPNG(fileName string) (*Surface, error) {

	cstr := ( /*line :27:10*/_Cfunc_CString /*line :27:18*/)(fileName)
	defer func() func() { _cgo0 := /*line :28:15*/unsafe.Pointer(cstr); return func() { _cgoCheckPointer(_cgo0, nil); /*line :28:36*/_Cfunc_free(_cgo0); }}()()

	surfaceNative := ( /*line :30:19*/_Cfunc_cairo_image_surface_create_from_png /*line :30:55*/)(cstr)

	status := Status(func() _Ctype_cairo_status_t{ _cgo0 := /*line :32:42*/surfaceNative; _cgoCheckPointer(_cgo0, nil); return /*line :32:56*/_Cfunc_cairo_surface_status(_cgo0); }())
	if status != STATUS_SUCCESS {
		return nil, ErrorStatus(status)
	}

	return &Surface{surfaceNative}, nil
}

// CreateImageSurfaceForData is a wrapper around cairo_image_surface_create_for_data().
func CreateImageSurfaceForData(data []byte, format Format, width, height, stride int) (*Surface, error) {
	surfaceNative := ( /*line :42:19*/_Cfunc_cairo_image_surface_create_for_data /*line :42:55*/)((* /*line :42:59*/_Ctype_uchar /*line :42:66*/)(unsafe.Pointer(&data[0])),
		 /*line :43:3*/_Ctype_cairo_format_t /*line :43:19*/(format),  /*line :43:29*/_Ctype_int /*line :43:34*/(width),  /*line :43:43*/_Ctype_int /*line :43:48*/(height),  /*line :43:58*/_Ctype_int /*line :43:63*/(stride))

	status := Status(func() _Ctype_cairo_status_t{ _cgo0 := /*line :45:42*/surfaceNative; _cgoCheckPointer(_cgo0, nil); return /*line :45:56*/_Cfunc_cairo_surface_status(_cgo0); }())
	if status != STATUS_SUCCESS {
		return nil, ErrorStatus(status)
	}

	s := wrapSurface(surfaceNative)

	runtime.SetFinalizer(s, func(v *Surface) { glib.FinalizerStrategy(v.destroy) })

	return s, nil
}

// CreateImageSurface is a wrapper around cairo_image_surface_create().
func CreateImageSurface(format Format, width, height int) *Surface {
	c := ( /*line :59:7*/_Cfunc_cairo_image_surface_create /*line :59:34*/)( /*line :59:36*/_Ctype_cairo_format_t /*line :59:52*/(format),
		 /*line :60:3*/_Ctype_int /*line :60:8*/(width),  /*line :60:17*/_Ctype_int /*line :60:22*/(height))
	s := wrapSurface(c)
	runtime.SetFinalizer(s, func(v *Surface) { glib.FinalizerStrategy(v.destroy) })
	return s
}

/// Create a new PDF surface.
func CreatePDFSurface(fileName string, width float64, height float64) (*Surface, error) {
	cstr := ( /*line :68:10*/_Cfunc_CString /*line :68:18*/)(fileName)
	defer func() func() { _cgo0 := /*line :69:15*/unsafe.Pointer(cstr); return func() { _cgoCheckPointer(_cgo0, nil); /*line :69:36*/_Cfunc_free(_cgo0); }}()()

	surfaceNative := ( /*line :71:19*/_Cfunc_cairo_pdf_surface_create /*line :71:44*/)(cstr,  /*line :71:52*/_Ctype_double /*line :71:60*/(width),  /*line :71:69*/_Ctype_double /*line :71:77*/(height))

	status := Status(func() _Ctype_cairo_status_t{ _cgo0 := /*line :73:42*/surfaceNative; _cgoCheckPointer(_cgo0, nil); return /*line :73:56*/_Cfunc_cairo_surface_status(_cgo0); }())
	if status != STATUS_SUCCESS {
		return nil, ErrorStatus(status)
	}

	s := wrapSurface(surfaceNative)

	runtime.SetFinalizer(s, func(v *Surface) { glib.FinalizerStrategy(v.destroy) })

	return s, nil
}

// native returns a pointer to the underlying cairo_surface_t.
func (v *Surface) native() * /*line :86:29*/_Ctype_cairo_surface_t /*line :86:46*/ {
	if v == nil {
		return nil
	}
	return v.surface
}

// Native returns a pointer to the underlying cairo_surface_t.
func (v *Surface) Native() uintptr {
	return uintptr(unsafe.Pointer(v.native()))
}

func (v *Surface) GetCSurface() * /*line :98:34*/_Ctype_cairo_surface_t /*line :98:51*/ {
	return v.native()
}

func marshalSurface(p uintptr) (interface{}, error) {
	c := ( /*line :103:7*/_Cfunc_g_value_get_boxed /*line :103:25*/)((* /*line :103:29*/_Ctype_GValue /*line :103:37*/)(unsafe.Pointer(p)))
	return WrapSurface(uintptr(c)), nil
}

func wrapSurface(surface * /*line :107:27*/_Ctype_cairo_surface_t /*line :107:44*/) *Surface {
	return &Surface{surface}
}

// NewSurface creates a gotk3 cairo Surface from a pointer to a
// C cairo_surface_t.  This is primarily designed for use with other
// gotk3 packages and should be avoided by applications.
func NewSurface(s uintptr, needsRef bool) *Surface {
	surface := WrapSurface(s)
	if needsRef {
		surface.reference()
	}
	runtime.SetFinalizer(surface, func(v *Surface) { glib.FinalizerStrategy(v.destroy) })
	return surface
}

func WrapSurface(s uintptr) *Surface {
	ptr := (* /*line :124:11*/_Ctype_cairo_surface_t /*line :124:28*/)(unsafe.Pointer(s))
	return wrapSurface(ptr)
}

// Closes the surface. The surface must not be used afterwards.
func (v *Surface) Close() {
	v.destroy()
}

// CreateSimilar is a wrapper around cairo_surface_create_similar().
func (v *Surface) CreateSimilar(content Content, width, height int) *Surface {
	c := func() *_Ctype_struct__cairo_surface{ _cgo0 := /*line :135:38*/v.native(); var _cgo1 _Ctype_cairo_content_t = _Ctype_cairo_content_t /*line :136:20*/(content); var _cgo2 _Ctype_int = _Ctype_int /*line :136:36*/(width); var _cgo3 _Ctype_int = _Ctype_int /*line :136:50*/(height); _cgoCheckPointer(_cgo0, nil); return /*line :136:59*/_Cfunc_cairo_surface_create_similar(_cgo0, _cgo1, _cgo2, _cgo3); }()
	s := wrapSurface(c)
	runtime.SetFinalizer(s, func(v *Surface) { glib.FinalizerStrategy(v.destroy) })
	return s
}

// TODO cairo_surface_create_similar_image (since 1.12)

// CreateForRectangle is a wrapper around cairo_surface_create_for_rectangle().
func (v *Surface) CreateForRectangle(x, y, width, height float64) *Surface {
	c := func() *_Ctype_struct__cairo_surface{ _cgo0 := /*line :146:44*/v.native(); var _cgo1 _Ctype_double = _Ctype_double /*line :146:64*/(x); var _cgo2 _Ctype_double = _Ctype_double /*line :147:11*/(y); var _cgo3 _Ctype_double = _Ctype_double /*line :147:24*/(width); var _cgo4 _Ctype_double = _Ctype_double /*line :147:41*/(height); _cgoCheckPointer(_cgo0, nil); return /*line :147:50*/_Cfunc_cairo_surface_create_for_rectangle(_cgo0, _cgo1, _cgo2, _cgo3, _cgo4); }()
	s := wrapSurface(c)
	runtime.SetFinalizer(s, func(v *Surface) { glib.FinalizerStrategy(v.destroy) })
	return s
}

// reference is a wrapper around cairo_surface_reference().
func (v *Surface) reference() {
	v.surface = func() *_Ctype_struct__cairo_surface{ _cgo0 := /*line :155:40*/v.native(); _cgoCheckPointer(_cgo0, nil); return /*line :155:51*/_Cfunc_cairo_surface_reference(_cgo0); }()
}

// destroy is a wrapper around cairo_surface_destroy().
func (v *Surface) destroy() {
	if v.surface != nil {
		func() { _cgo0 := /*line :161:27*/v.native(); _cgoCheckPointer(_cgo0, nil); /*line :161:38*/_Cfunc_cairo_surface_destroy(_cgo0); }()
		v.surface = nil
	}
}

// Status is a wrapper around cairo_surface_status().
func (v *Surface) Status() Status {
	c := func() _Ctype_cairo_status_t{ _cgo0 := /*line :168:30*/v.native(); _cgoCheckPointer(_cgo0, nil); return /*line :168:41*/_Cfunc_cairo_surface_status(_cgo0); }()
	return Status(c)
}

// Flush is a wrapper around cairo_surface_flush().
func (v *Surface) Flush() {
	func() { _cgo0 := /*line :174:24*/v.native(); _cgoCheckPointer(_cgo0, nil); /*line :174:35*/_Cfunc_cairo_surface_flush(_cgo0); }()
}

// TODO(jrick) GetDevice (requires Device bindings)
// cairo_surface_get_device

// TODO(jrick) GetFontOptions (require FontOptions bindings)
// cairo_surface_get_font_options

// TODO(jrick) GetContent (requires Content bindings)
// cairo_surface_get_content

// MarkDirty is a wrapper around cairo_surface_mark_dirty().
func (v *Surface) MarkDirty() {
	func() { _cgo0 := /*line :188:29*/v.native(); _cgoCheckPointer(_cgo0, nil); /*line :188:40*/_Cfunc_cairo_surface_mark_dirty(_cgo0); }()
}

// MarkDirtyRectangle is a wrapper around cairo_surface_mark_dirty_rectangle().
func (v *Surface) MarkDirtyRectangle(x, y, width, height int) {
	func() { _cgo0 := /*line :193:39*/v.native(); var _cgo1 _Ctype_int = _Ctype_int /*line :193:56*/(x); var _cgo2 _Ctype_int = _Ctype_int /*line :193:66*/(y); var _cgo3 _Ctype_int = _Ctype_int /*line :194:8*/(width); var _cgo4 _Ctype_int = _Ctype_int /*line :194:22*/(height); _cgoCheckPointer(_cgo0, nil); /*line :194:31*/_Cfunc_cairo_surface_mark_dirty_rectangle(_cgo0, _cgo1, _cgo2, _cgo3, _cgo4); }()
}

// SetDeviceOffset is a wrapper around cairo_surface_set_device_offset().
func (v *Surface) SetDeviceOffset(x, y float64) {
	func() { _cgo0 := /*line :199:36*/v.native(); var _cgo1 _Ctype_double = _Ctype_double /*line :199:56*/(x); var _cgo2 _Ctype_double = _Ctype_double /*line :199:69*/(y); _cgoCheckPointer(_cgo0, nil); /*line :199:73*/_Cfunc_cairo_surface_set_device_offset(_cgo0, _cgo1, _cgo2); }()
}

// GetDeviceOffset is a wrapper around cairo_surface_get_device_offset().
func (v *Surface) GetDeviceOffset() (x, y float64) {
	var xOffset, yOffset  /*line :204:23*/_Ctype_double /*line :204:31*/
	func() { _cgo0 := /*line :205:36*/v.native(); var _cgo1 *_Ctype_double = /*line :205:48*/&xOffset; var _cgo2 *_Ctype_double = /*line :205:58*/&yOffset; _cgoCheckPointer(_cgo0, nil); /*line :205:67*/_Cfunc_cairo_surface_get_device_offset(_cgo0, _cgo1, _cgo2); }()
	return float64(xOffset), float64(yOffset)
}

// SetFallbackResolution is a wrapper around
// cairo_surface_set_fallback_resolution().
func (v *Surface) SetFallbackResolution(xPPI, yPPI float64) {
	func() { _cgo0 := /*line :212:42*/v.native(); var _cgo1 _Ctype_double = _Ctype_double /*line :212:62*/(xPPI); var _cgo2 _Ctype_double = _Ctype_double /*line :213:11*/(yPPI); _cgoCheckPointer(_cgo0, nil); /*line :213:18*/_Cfunc_cairo_surface_set_fallback_resolution(_cgo0, _cgo1, _cgo2); }()
}

// GetFallbackResolution is a wrapper around cairo_surface_get_fallback_resolution().
func (v *Surface) GetFallbackResolution() (xPPI, yPPI float64) {
	var x, y  /*line :218:11*/_Ctype_double /*line :218:19*/
	func() { _cgo0 := /*line :219:42*/v.native(); var _cgo1 *_Ctype_double = /*line :219:54*/&x; var _cgo2 *_Ctype_double = /*line :219:58*/&y; _cgoCheckPointer(_cgo0, nil); /*line :219:61*/_Cfunc_cairo_surface_get_fallback_resolution(_cgo0, _cgo1, _cgo2); }()
	return float64(x), float64(y)
}

// GetType is a wrapper around cairo_surface_get_type().
func (v *Surface) GetType() SurfaceType {
	c := func() _Ctype_cairo_surface_type_t{ _cgo0 := /*line :225:32*/v.native(); _cgoCheckPointer(_cgo0, nil); return /*line :225:43*/_Cfunc_cairo_surface_get_type(_cgo0); }()
	return SurfaceType(c)
}

// TODO(jrick) SetUserData (depends on UserDataKey and DestroyFunc)
// cairo_surface_set_user_data

// TODO(jrick) GetUserData (depends on UserDataKey)
// cairo_surface_get_user_data

// CopyPage is a wrapper around cairo_surface_copy_page().
func (v *Surface) CopyPage() {
	func() { _cgo0 := /*line :237:28*/v.native(); _cgoCheckPointer(_cgo0, nil); /*line :237:39*/_Cfunc_cairo_surface_copy_page(_cgo0); }()
}

// ShowPage is a wrapper around cairo_surface_show_page().
func (v *Surface) ShowPage() {
	func() { _cgo0 := /*line :242:28*/v.native(); _cgoCheckPointer(_cgo0, nil); /*line :242:39*/_Cfunc_cairo_surface_show_page(_cgo0); }()
}

// HasShowTextGlyphs is a wrapper around cairo_surface_has_show_text_glyphs().
func (v *Surface) HasShowTextGlyphs() bool {
	c := func() _Ctype_cairo_bool_t{ _cgo0 := /*line :247:44*/v.native(); _cgoCheckPointer(_cgo0, nil); return /*line :247:55*/_Cfunc_cairo_surface_has_show_text_glyphs(_cgo0); }()
	return gobool(c)
}

// TODO(jrick) SetMimeData (depends on DestroyFunc)
// cairo_surface_set_mime_data

// GetMimeData is a wrapper around cairo_surface_get_mime_data().  The
// returned mimetype data is returned as a Go byte slice.
func (v *Surface) GetMimeData(mimeType MimeType) []byte {
	cstr := ( /*line :257:10*/_Cfunc_CString /*line :257:18*/)(string(mimeType))
	defer func() func() { _cgo0 := /*line :258:15*/unsafe.Pointer(cstr); return func() { _cgoCheckPointer(_cgo0, nil); /*line :258:36*/_Cfunc_free(_cgo0); }}()()
	var data * /*line :259:12*/_Ctype_uchar /*line :259:19*/
	var length  /*line :260:13*/_Ctype_ulong /*line :260:20*/
	func() { _cgo0 := /*line :261:32*/v.native(); var _cgo1 *_Ctype_char = /*line :261:44*/cstr; _cgoBase2 := /*line :261:50*/&data; _cgo2 := _cgoBase2; var _cgo3 *_Ctype_ulong = /*line :261:57*/&length; _cgoCheckPointer(_cgo0, nil); _cgoCheckPointer(_cgoBase2, 0 == 0); /*line :261:65*/_Cfunc_cairo_surface_get_mime_data(_cgo0, _cgo1, _cgo2, _cgo3); }()
	return func() []byte{ _cgo0 := /*line :262:19*/unsafe.Pointer(data); var _cgo1 _Ctype_int = _Ctype_int /*line :262:46*/(length); _cgoCheckPointer(_cgo0, nil); return /*line :262:55*/_Cfunc_GoBytes(_cgo0, _cgo1); }()
}

// WriteToPNG is a wrapper around cairo_surface_write_png(). It writes the Cairo
// surface to the given file in PNG format.
func (v *Surface) WriteToPNG(fileName string) error {
	cstr := ( /*line :268:10*/_Cfunc_CString /*line :268:18*/)(fileName)
	defer func() func() { _cgo0 := /*line :269:15*/unsafe.Pointer(cstr); return func() { _cgoCheckPointer(_cgo0, nil); /*line :269:36*/_Cfunc_free(_cgo0); }}()()

	status := Status(func() _Ctype_cairo_status_t{ _cgo0 := /*line :271:48*/v.surface; var _cgo1 *_Ctype_char = /*line :271:59*/cstr; _cgoCheckPointer(_cgo0, nil); return /*line :271:64*/_Cfunc_cairo_surface_write_to_png(_cgo0, _cgo1); }())

	if status != STATUS_SUCCESS {
		return ErrorStatus(status)
	}

	return nil
}

// TODO(jrick) SupportsMimeType (since 1.12)
// cairo_surface_supports_mime_type

// TODO(jrick) MapToImage (since 1.12)
// cairo_surface_map_to_image

// TODO(jrick) UnmapImage (since 1.12)
// cairo_surface_unmap_image

// GetHeight is a wrapper around cairo_image_surface_get_height().
func (v *Surface) GetHeight() int {
	return int(func() _Ctype_int{ _cgo0 := /*line :291:46*/v.surface; _cgoCheckPointer(_cgo0, nil); return /*line :291:56*/_Cfunc_cairo_image_surface_get_height(_cgo0); }())
}

// GetWidth is a wrapper around cairo_image_surface_get_width().
func (v *Surface) GetWidth() int {
	return int(func() _Ctype_int{ _cgo0 := /*line :296:45*/v.surface; _cgoCheckPointer(_cgo0, nil); return /*line :296:55*/_Cfunc_cairo_image_surface_get_width(_cgo0); }())
}

// GetData is a wrapper around cairo_image_surface_get_data().
func (v *Surface) GetData() unsafe.Pointer {
	return unsafe.Pointer(func() *_Ctype_uchar{ _cgo0 := /*line :301:55*/v.surface; _cgoCheckPointer(_cgo0, nil); return /*line :301:65*/_Cfunc_cairo_image_surface_get_data(_cgo0); }())
}
