;Ported to Autoit by UEZ build 2024-04-01
#include-once

Global $g_hCairoDLL = 0

#Region enums and constants
;cairo_status as long
Global Enum $CAIRO_STATUS_SUCCESS = 0, $CAIRO_STATUS_NO_MEMORY, $CAIRO_STATUS_INVALID_RESTORE, $CAIRO_STATUS_INVALID_POP_GROUP, $CAIRO_STATUS_NO_CURRENT_POINT, $CAIRO_STATUS_INVALID_MATRIX, _
			$CAIRO_STATUS_INVALID_STATUS, $CAIRO_STATUS_NULL_POINTER, $CAIRO_STATUS_INVALID_STRING, $CAIRO_STATUS_INVALID_PATH_DATA, $CAIRO_STATUS_READ_ERROR, $CAIRO_STATUS_WRITE_ERROR, _
			$CAIRO_STATUS_SURFACE_FINISHED, $CAIRO_STATUS_SURFACE_TYPE_MISMATCH, $CAIRO_STATUS_PATTERN_TYPE_MISMATCH, $CAIRO_STATUS_INVALID_CONTENT, $CAIRO_STATUS_INVALID_FORMAT, $CAIRO_STATUS_INVALID_VISUAL, _
			$CAIRO_STATUS_FILE_NOT_FOUND, $CAIRO_STATUS_INVALID_DASH, $CAIRO_STATUS_INVALID_DSC_COMMENT, $CAIRO_STATUS_INVALID_INDEX, $CAIRO_STATUS_CLIP_NOT_REPRESENTABLE, $CAIRO_STATUS_TEMP_FILE_ERROR, _
			$CAIRO_STATUS_INVALID_STRIDE, $CAIRO_STATUS_FONT_TYPE_MISMATCH, $CAIRO_STATUS_USER_FONT_IMMUTABLE, $CAIRO_STATUS_USER_FONT_ERROR, $CAIRO_STATUS_NEGATIVE_COUNT, $CAIRO_STATUS_INVALID_CLUSTERS, _
			$CAIRO_STATUS_INVALID_SLANT, $CAIRO_STATUS_INVALID_WEIGHT, $CAIRO_STATUS_INVALID_SIZE, $CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED, $CAIRO_STATUS_DEVICE_TYPE_MISMATCH, $CAIRO_STATUS_DEVICE_ERROR, _
			$CAIRO_STATUS_INVALID_MESH_CONSTRUCTION, $CAIRO_STATUS_DEVICE_FINISHED, $CAIRO_STATUS_JBIG2_GLOBAL_MISSING, $CAIRO_STATUS_LAST_STATUS

Global Const $g_aCairoStatus[] = ["CAIRO_STATUS_SUCCESS", "CAIRO_STATUS_NO_MEMORY", "CAIRO_STATUS_INVALID_RESTORE", "CAIRO_STATUS_INVALID_POP_GROUP", "CAIRO_STATUS_NO_CURRENT_POINT", "CAIRO_STATUS_INVALID_MATRIX", _
			"CAIRO_STATUS_INVALID_STATUS", "CAIRO_STATUS_NULL_POINTER", "CAIRO_STATUS_INVALID_STRING", "CAIRO_STATUS_INVALID_PATH_DATA", "CAIRO_STATUS_READ_ERROR", "CAIRO_STATUS_WRITE_ERROR", _
			"CAIRO_STATUS_SURFACE_FINISHED", "CAIRO_STATUS_SURFACE_TYPE_MISMATCH", "CAIRO_STATUS_PATTERN_TYPE_MISMATCH", "CAIRO_STATUS_INVALID_CONTENT", "CAIRO_STATUS_INVALID_FORMAT", "CAIRO_STATUS_INVALID_VISUAL", _
			"CAIRO_STATUS_FILE_NOT_FOUND", "CAIRO_STATUS_INVALID_DASH", "CAIRO_STATUS_INVALID_DSC_COMMENT", "CAIRO_STATUS_INVALID_INDEX", "CAIRO_STATUS_CLIP_NOT_REPRESENTABLE", "CAIRO_STATUS_TEMP_FILE_ERROR", _
			"CAIRO_STATUS_INVALID_STRIDE", "CAIRO_STATUS_FONT_TYPE_MISMATCH", "CAIRO_STATUS_USER_FONT_IMMUTABLE", "CAIRO_STATUS_USER_FONT_ERROR", "CAIRO_STATUS_NEGATIVE_COUNT", "CAIRO_STATUS_INVALID_CLUSTERS", _
			"CAIRO_STATUS_INVALID_SLANT", "CAIRO_STATUS_INVALID_WEIGHT", "CAIRO_STATUS_INVALID_SIZE", "CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED", "CAIRO_STATUS_DEVICE_TYPE_MISMATCH", "CAIRO_STATUS_DEVICE_ERROR", _
			"CAIRO_STATUS_INVALID_MESH_CONSTRUCTION", "CAIRO_STATUS_DEVICE_FINISHED", "CAIRO_STATUS_JBIG2_GLOBAL_MISSING", "CAIRO_STATUS_LAST_STATUS"]


;cairo_content as long
Global Enum $CAIRO_CONTENT_COLOR = 0x1000, $CAIRO_CONTENT_ALPHA = 0x2000, $CAIRO_CONTENT_COLOR_ALPHA = 0x3000

;cairo_format as long
Global Enum	$CAIRO_FORMAT_INVALID = -1, $CAIRO_FORMAT_ARGB32, $CAIRO_FORMAT_RGB24, $CAIRO_FORMAT_A8, $CAIRO_FORMAT_A1, $CAIRO_FORMAT_RGB16_565, $CAIRO_FORMAT_RGB30

;cairo_operator as long
Global Enum $CAIRO_OPERATOR_CLEAR, $CAIRO_OPERATOR_SOURCE, $CAIRO_OPERATOR_OVER, $CAIRO_OPERATOR_IN, $CAIRO_OPERATOR_OUT, $CAIRO_OPERATOR_ATOP, $CAIRO_OPERATOR_DEST, $CAIRO_OPERATOR_DEST_OVER, $CAIRO_OPERATOR_DEST_IN, _
			$CAIRO_OPERATOR_DEST_OUT, $CAIRO_OPERATOR_DEST_ATOP, $CAIRO_OPERATOR_XOR, $CAIRO_OPERATOR_ADD, $CAIRO_OPERATOR_SATURATE, $CAIRO_OPERATOR_MULTIPLY, $CAIRO_OPERATOR_SCREEN, $CAIRO_OPERATOR_OVERLAY, _
			$CAIRO_OPERATOR_DARKEN, $CAIRO_OPERATOR_LIGHTEN, $CAIRO_OPERATOR_COLOR_DODGE, $CAIRO_OPERATOR_COLOR_BURN, $CAIRO_OPERATOR_HARD_LIGHT, $CAIRO_OPERATOR_SOFT_LIGHT, $CAIRO_OPERATOR_DIFFERENCE, _
			$CAIRO_OPERATOR_EXCLUSION, $CAIRO_OPERATOR_HSL_HUE, $CAIRO_OPERATOR_HSL_SATURATION, $CAIRO_OPERATOR_HSL_COLOR, $CAIRO_OPERATOR_HSL_LUMINOSITY

;cairo_antialias as long
Global Enum $CAIRO_ANTIALIAS_DEFAULT, $CAIRO_ANTIALIAS_NONE, $CAIRO_ANTIALIAS_GRAY, $CAIRO_ANTIALIAS_SUBPIXEL, $CAIRO_ANTIALIAS_FAST, $CAIRO_ANTIALIAS_GOOD, $CAIRO_ANTIALIAS_BEST

;cairo_fill_rule as long
Global Enum $CAIRO_FILL_RULE_WINDING, $CAIRO_FILL_RULE_EVEN_ODD

;cairo_line_join as long
Global Enum $CAIRO_LINE_JOIN_MITER, $CAIRO_LINE_JOIN_ROUND, $CAIRO_LINE_JOIN_BEVEL

;cairo_line_cap as long
Global Enum $CAIRO_LINE_CAP_BUTT, $CAIRO_LINE_CAP_ROUND, $CAIRO_LINE_CAP_SQUARE

;cairo_text_cluster_flags as long
Global Const $CAIRO_TEXT_CLUSTER_FLAG_BACKWARD = 0x00000001

;cairo_font_slant as long
Global Enum	$CAIRO_FONT_SLANT_NORMAL, $CAIRO_FONT_SLANT_ITALIC, $CAIRO_FONT_SLANT_OBLIQUE

;cairo_font_weight as long
Global Enum	$CAIRO_FONT_WEIGHT_NORMAL, $CAIRO_FONT_WEIGHT_BOLD

;cairo_subpixel_order as long
Global Enum	$CAIRO_SUBPIXEL_ORDER_DEFAULT, $CAIRO_SUBPIXEL_ORDER_RGB, $CAIRO_SUBPIXEL_ORDER_BGR, $CAIRO_SUBPIXEL_ORDER_VRGB, $CAIRO_SUBPIXEL_ORDER_VBGR

;cairo_hint_style as long
Global Enum	$CAIRO_HINT_STYLE_DEFAULT, $CAIRO_HINT_STYLE_NONE, $CAIRO_HINT_STYLE_SLIGHT, $CAIRO_HINT_STYLE_MEDIUM, $CAIRO_HINT_STYLE_FULL

;cairo_hint_metrics as long
Global Enum	$CAIRO_HINT_METRICS_DEFAULT, $CAIRO_HINT_METRICS_OFF, $CAIRO_HINT_METRICS_ON

;cairo_font_type as long
Global Enum	$CAIRO_FONT_TYPE_TOY, $CAIRO_FONT_TYPE_FT, $CAIRO_FONT_TYPE_WIN32, $CAIRO_FONT_TYPE_QUARTZ, $CAIRO_FONT_TYPE_USER

;cairo_path_data_type as long
Global Enum	$CAIRO_PATH_MOVE_TO, $CAIRO_PATH_LINE_TO, $CAIRO_PATH_CURVE_TO, $CAIRO_PATH_CLOSE_PATH

;cairo_device_type as long
Global Enum	$CAIRO_DEVICE_TYPE_DRM, $CAIRO_DEVICE_TYPE_GL, $CAIRO_DEVICE_TYPE_SCRIPT, $CAIRO_DEVICE_TYPE_XCB, $CAIRO_DEVICE_TYPE_XLIB, $CAIRO_DEVICE_TYPE_XML, $CAIRO_DEVICE_TYPE_COGL, _
			$CAIRO_DEVICE_TYPE_WIN32, $CAIRO_DEVICE_TYPE_INVALID = -1

;cairo_surface_observer_mode_t as long
Global Enum $CAIRO_SURFACE_OBSERVER_NORMAL, $CAIRO_SURFACE_OBSERVER_RECORD_OPERATIONS

;cairo_surface_type as long
Global Enum $CAIRO_SURFACE_TYPE_IMAGE, $CAIRO_SURFACE_TYPE_PDF, $CAIRO_SURFACE_TYPE_PS, $CAIRO_SURFACE_TYPE_XLIB, $CAIRO_SURFACE_TYPE_XCB, $CAIRO_SURFACE_TYPE_GLITZ, $CAIRO_SURFACE_TYPE_QUARTZ,$CAIRO_SURFACE_TYPE_WIN32, _
			$CAIRO_SURFACE_TYPE_BEOS, $CAIRO_SURFACE_TYPE_DIRECTFB, $CAIRO_SURFACE_TYPE_SVG, $CAIRO_SURFACE_TYPE_OS2, $CAIRO_SURFACE_TYPE_WIN32_PRINTING, $CAIRO_SURFACE_TYPE_QUARTZ_IMAGE, $CAIRO_SURFACE_TYPE_SCRIPT, _
			$CAIRO_SURFACE_TYPE_QT, $CAIRO_SURFACE_TYPE_RECORDING, $CAIRO_SURFACE_TYPE_VG, $CAIRO_SURFACE_TYPE_GL, $CAIRO_SURFACE_TYPE_DRM, $CAIRO_SURFACE_TYPE_TEE, $CAIRO_SURFACE_TYPE_XML, $CAIRO_SURFACE_TYPE_SKIA, _
			$CAIRO_SURFACE_TYPE_SUBSURFACE, $CAIRO_SURFACE_TYPE_COGL

;cairo_pattern_type as long
Global Enum $CAIRO_PATTERN_TYPE_SOLID, $CAIRO_PATTERN_TYPE_SURFACE, $CAIRO_PATTERN_TYPE_LINEAR, $CAIRO_PATTERN_TYPE_RADIAL, $CAIRO_PATTERN_TYPE_MESH, $CAIRO_PATTERN_TYPE_RASTER_SOURCE

;cairo_extend as long
Global Enum $CAIRO_EXTEND_NONE, $CAIRO_EXTEND_REPEAT, $CAIRO_EXTEND_REFLECT, $CAIRO_EXTEND_PAD

;cairo_filter as long
Global Enum $CAIRO_FILTER_FAST, $CAIRO_FILTER_GOOD, $CAIRO_FILTER_BEST, $CAIRO_FILTER_NEAREST, $CAIRO_FILTER_BILINEAR, $CAIRO_FILTER_GAUSSIAN

;cairo_region_overlap as long
Global Enum $CAIRO_REGION_OVERLAP_IN, $CAIRO_REGION_OVERLAP_OUT, $CAIRO_REGION_OVERLAP_PART

;cairo_svg_unit as long
Global Enum $CAIRO_SVG_UNIT_USER = 0, $CAIRO_SVG_UNIT_EM, $CAIRO_SVG_UNIT_EX, $CAIRO_SVG_UNIT_PX, $CAIRO_SVG_UNIT_IN, $CAIRO_SVG_UNIT_CM, $CAIRO_SVG_UNIT_MM, $CAIRO_SVG_UNIT_PT, $CAIRO_SVG_UNIT_PC, $CAIRO_SVG_UNIT_PERCENT

;cairo_pdf_unit as long
Global Enum $CAIRO_PDF_VERSION_1_4, $CAIRO_PDF_VERSION_1_5, $CAIRO_PDF_VERSION_1_6, $CAIRO_PDF_VERSION_1_7

;cairo_pdf_metadata as long
Global Enum $CAIRO_PDF_METADATA_TITLE, $CAIRO_PDF_METADATA_AUTHOR, $CAIRO_PDF_METADATA_SUBJECT, $CAIRO_PDF_METADATA_KEYWORDS, $CAIRO_PDF_METADATA_CREATOR, $CAIRO_PDF_METADATA_CREATE_DATE, $CAIRO_PDF_METADATA_MOD_DATE

;cairo_pdf_outline_flags as long
Global Enum $CAIRO_PDF_OUTLINE_ROOT = 0, $CAIRO_PDF_OUTLINE_FLAG_OPEN = 1, $CAIRO_PDF_OUTLINE_FLAG_BOLD = 2, $CAIRO_PDF_OUTLINE_FLAG_ITALIC = 4
#EndRegion

#Region tag structs
;structs
Global Const $tagCairo_rectangle_int = "long x;long y;long width;long height;"
Global Const $tagCairo_rectangle_list = "long status;ptr rectangles;long num_rectangles;"
Global Const $tagCairo_matrix = "double xx;double yx;double xy;double yy;double x0;double y0;"
Global Const $tagCairo_glyph_t = (@AutoItX64 ? "uinteger" : "ulong") & " index;double x;double y;"
Global Const $tagCairo_text_cluster_t = "long num_bytes;long num_glyphs;"
Global Const $tagCairo_text_extents_t = "double x_bearing;double y_bearing;double width;double height;double x_advance;double y_advance;"
Global Const $tagCairo_font_extents_t = "double ascent;double descent;double height;double max_x_advance;double max_y_advance;"
Global Const $tagCairo_path_data_t_header = "long type;long length;"
Global Const $tagCairo_path_data_t_point = "double x;double y;"
Global Const $tagCairo_path_data_t = "ptr path;"
Global Const $tagCairo_path = "long status;ptr data;long num_data;"
#EndRegion

;-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Func Cairo_Init($sPath = Default)
	Local Const $sDLL = ($sPath = Default ? (@AutoItX64 ? (@ScriptDir & "\cairo64.dll") : (@ScriptDir & "\cairo.dll")) : $sPath)
	If Not FileExists($sDLL) Then Return SetError(1, 0, 0)
	$g_hCairoDLL = DllOpen($sDLL)
	If $g_hCairoDLL = -1 Or @error Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Close()
	If $g_hCairoDLL Then Return DllClose($g_hCairoDLL)
	Return 0
EndFunc

Func Cairo_Version()
	Local Const $aVersion = DllCall($g_hCairoDLL, "long:cdecl", "cairo_version")
	If @error Or Not IsArray($aVersion) Then Return SetError(2, 0, 0)
	If Not $aVersion[0] Then Return SetError(2, 0, $aVersion[0])
	Return $aVersion[0]
EndFunc

Func Cairo_VersionString()
	Local Const $aVersion = DllCall($g_hCairoDLL, "str:cdecl", "cairo_version_string")
	If @error Or Not IsArray($aVersion) Then Return SetError(2, 0, 0)
	If Not $aVersion[0] Then Return SetError(2, 0, $aVersion[0])
	Return $aVersion[0]
EndFunc

;-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Func Cairo_GetStride($iW, $iFormat = $CAIRO_FORMAT_ARGB32)
	Local Const $aStride = DllCall($g_hCairoDLL, "long:cdecl", "cairo_format_stride_for_width", "long", $iFormat, "long", $iW) ;BitShift($iW * 32 + 15, 4) * 2 * $iH
	If @error Or Not IsArray($aStride) Then Return SetError(1, 0, 0)
	If Not $aStride[0] Then Return SetError(2, 0, $aStride[0])
	Return $aStride[0]
EndFunc

Func Cairo_RectList_Destroy($pRectangleList)
	If Not $pRectangleList Then Return SetError(1, 0, 0)
	Local Const $aRectangleList = DllCall($g_hCairoDLL, "none:cdecl", "cairo_rectangle_list_destroy", "ptr", $pRectangleList)
	If @error Or Not IsArray($aRectangleList) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

;-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#Region Surface
Func Cairo_Surface_CreateWin32($hDC)
	Local Const $aSurface = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_win32_surface_create", "ptr", $hDC)
	If @error Or Not IsArray($aSurface) Then Return SetError(2, 0, 0)
	If Not $aSurface[0] Then Return SetError(3, 0, $aSurface[0])
	Return $aSurface[0]
EndFunc

Func Cairo_Surface_CreateWin32Printing($hDC)
	Local Const $aSurface = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_win32_printing_surface_create", "ptr", $hDC)
	If @error Or Not IsArray($aSurface) Then Return SetError(2, 0, 0)
	If Not $aSurface[0] Then Return SetError(3, 0, $aSurface[0])
	Return $aSurface[0]
EndFunc

Func Cairo_Surface_CreateWin32WithFormat($hDC, $iFormat = $CAIRO_FORMAT_ARGB32)
	Local Const $aSurface = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_win32_surface_create_with_format", "ptr", $hDC, "long", $iFormat)
	If @error Or Not IsArray($aSurface) Then Return SetError(2, 0, 0)
	If Not $aSurface[0] Then Return SetError(3, 0, $aSurface[0])
	Return $aSurface[0]
EndFunc

Func Cairo_Surface_CreateWin32WithDDB($hDC, $iW, $iH, $iFormat = $CAIRO_FORMAT_ARGB32)
	Local Const $aSurface = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_win32_surface_create_with_ddb", "ptr", $hDC, "long", $iFormat, "long", $iW, "long", $iH)
	If @error Or Not IsArray($aSurface) Then Return SetError(2, 0, 0)
	If Not $aSurface[0] Then Return SetError(3, 0, $aSurface[0])
	Return $aSurface[0]
EndFunc

Func Cairo_Surface_CreateWin32WithDIB($iW, $iH, $iFormat = $CAIRO_FORMAT_ARGB32)
	Local Const $aSurface = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_win32_surface_create_with_dib", "long", $iFormat, "long", $iw, "long", $ih)
	If @error Or Not IsArray($aSurface) Then Return SetError(2, 0, 0)
	If Not $aSurface[0] Then Return SetError(3, 0, $aSurface[0])
	Return $aSurface[0]
EndFunc

Func Cairo_Surface_GetDC($pSurface)
	Local Const $aSurface = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_win32_surface_get_dc", "ptr", $pSurface)
	If @error Or Not IsArray($aSurface) Then Return SetError(2, 0, 0)
	If Not $aSurface[0] Then Return SetError(3, 0, $aSurface[0])
	Return $aSurface[0]
EndFunc

Func Cairo_Surface_GetImageWin32($pSurface)
	Local Const $aSurface = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_win32_surface_get_image", "ptr", $pSurface)
	If @error Or Not IsArray($aSurface) Then Return SetError(2, 0, 0)
	If Not $aSurface[0] Then Return SetError(2, 0, $aSurface[0])
	Return $aSurface[0]
EndFunc

Func Cairo_Surface_GetStatus($pSurface)
	If Not $pSurface Then Return SetError(1, 0, 0)
	Local Const $aSurface = DllCall($g_hCairoDLL, "long:cdecl", "cairo_surface_status", "ptr", $pSurface)
	If @error Or Not IsArray($aSurface) Then Return SetError(2, 0, 0)
	Return $aSurface[0]
EndFunc

Func Cairo_Surface_Destroy($pSurface)
	If Not $pSurface Then Return SetError(1, 0, 0)
	DllCall($g_hCairoDLL, "none:cdecl", "cairo_surface_destroy", "ptr", $pSurface)
	Return 1
EndFunc

Func Cairo_Surface_Finish($pSurface)
	If Not $pSurface Then Return SetError(1, 0, 0)
	DllCall($g_hCairoDLL, "none:cdecl", "cairo_surface_finish", "ptr", $pSurface)
	Return 1
EndFunc

Func Cairo_Surface_Flush($pSurface)
	If Not $pSurface Then Return SetError(1, 0, 0)
	DllCall($g_hCairoDLL, "none:cdecl", "cairo_surface_flush", "ptr", $pSurface)
	Return 1
EndFunc

Func Cairo_Surface_MapToImage($pSurface, $tCairo_rectangle_int)
	Local Const $aSurface = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_surface_map_to_image", "ptr", $pSurface, "struct*", $tCairo_rectangle_int)
	If @error Or Not IsArray($aSurface) Then Return SetError(2, 0, 0)
	If Not $aSurface[0] Then Return SetError(3, 0, $aSurface[0])
	Return $aSurface[0]
EndFunc

Func Cairo_Surface_UnmapImage($pSurface, $pImage)
	If Not $pSurface Then Return SetError(1, 0, 0)
	If Not $pImage Then Return SetError(2, 0, 0)
	DllCall($g_hCairoDLL, "none:cdecl", "cairo_surface_unmap_image", "ptr", $pSurface, "ptr", $pImage)
	Return 1
EndFunc

Func Cairo_Surface_MarkDirty($pSurface)
	If Not $pSurface Then Return SetError(1, 0, 0)
	DllCall($g_hCairoDLL, "none:cdecl", "cairo_surface_mark_dirty", "ptr", $pSurface)
	Return 1
EndFunc

Func Cairo_Surface_MarkDirtyRect($pSurface, $iX, $iY, $iW, $iH)
	If Not $pSurface Then Return SetError(1, 0, 0)
	DllCall($g_hCairoDLL, "none:cdecl", "cairo_surface_mark_dirty_rectangle", "ptr", $pSurface, "long", $iX, "long", $iY, "long", $iW, "long", $iH)
	Return 1
EndFunc

Func Cairo_Surface_CreateRectangle($pSurface, $fX, $fY, $fW, $fH)
	If Not $pSurface Then Return SetError(1, 0, 0)
	Local Const $aSurface = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_surface_create_for_rectangle", "ptr", $pSurface, "double", $fX, "double", $fY, "double", $fW, "double", $fH)
	If @error Or Not IsArray($aSurface) Then Return SetError(2, 0, 0)
	Return $aSurface[0]
EndFunc

Func Cairo_Surface_IncreaseReference($pSurface)
	If Not $pSurface Then Return SetError(1, 0, 0)
	Local Const $aSurface = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_surface_reference", "ptr", $pSurface)
	If @error Or Not IsArray($aSurface) Then Return SetError(2, 0, 0)
	Return $aSurface[0]
EndFunc

Func Cairo_Surface_SurfaceDecreaseReference($pSurface)
	Return Cairo_Surface_Destroy($pSurface)
EndFunc

Func Cairo_Surface_CreateSimilar($pPixelData, $iW, $iH, $iContent = $CAIRO_CONTENT_COLOR_ALPHA)
	If Not $pPixelData Then Return SetError(1, 0, 0)
	Local Const $aSurface = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_surface_create_similar", "ptr", $pPixelData, "long", $iContent, "long", $iW, "long", $iH)
	If @error Or Not IsArray($aSurface) Then Return SetError(2, 0, 0)
	Return $aSurface[0]
EndFunc

Func Cairo_Surface_CreateImageSimilar($pPixelData, $iW, $iH, $iContent = $CAIRO_CONTENT_COLOR_ALPHA)
	If Not $pPixelData Then Return SetError(1, 0, 0)
	Local Const $aSurface = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_surface_create_similar_image", "ptr", $pPixelData, "long", $iContent, "long", $iW, "long", $iH)
	If @error Or Not IsArray($aSurface) Then Return SetError(2, 0, 0)
	Return $aSurface[0]
EndFunc
#EndRegion Surface

;-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#Region Context
Func Cairo_Context_Create($pSurface)
	Local Const $aContext = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_create", "ptr", $pSurface)
	If @error Or Not IsArray($aContext) Then Return SetError(1, 0, 0)
	If Not $aContext[0] Then Return SetError(2, 0, $aContext[0])
	Return $aContext[0]
EndFunc

Func Cairo_Context_Destroy($pContext)
	If Not $pContext Then Return SetError(1, 0, 0)
	DllCall($g_hCairoDLL, "none:cdecl", "cairo_destroy", "ptr", $pContext)
	Return 1
EndFunc

Func Cairo_Context_Reference($pContext)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_reference", "ptr", $pContext)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	If Not $aContext[0] Then Return SetError(3, 0, $aContext[0])
	Return $aContext[0]
EndFunc

Func Cairo_Context_Status($pContext)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "long:cdecl", "cairo_status", "ptr", $pContext)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return $aContext[0]
EndFunc

Func Cairo_Context_StatusToString($pContext)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "str:cdecl", "cairo_status_to_string", "ptr", $pContext)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return $aContext[0]
EndFunc

Func Cairo_Context_Save($pContext)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_save", "ptr", $pContext)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_Restore($pContext)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_restore", "ptr", $pContext)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_GetTarget($pContext)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_get_target", "ptr", $pContext)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	If Not $aContext[0] Then Return SetError(3, 0, $aContext[0])
	Return $aContext[0]
EndFunc

Func Cairo_Context_PushGroup($pContext)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_push_group", "ptr", $pContext)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_PushGroupWithContent($pContext, $iCairoContent)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_push_group_with_content", "ptr", $pContext, "long", $iCairoContent)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_PopGroup($pContext)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_pop_group", "ptr", $pContext)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	If Not $aContext[0] Then Return SetError(3, 0, $aContext[0])
	Return $aContext[0]
EndFunc

Func Cairo_Context_PopGroupToSource($pContext)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_pop_group_to_source", "ptr", $pContext)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_GetGroupTarget($pContext)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_get_group_target", "ptr", $pContext)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	If Not $aContext[0] Then Return SetError(3, 0, $aContext[0])
	Return $aContext[0]
EndFunc

Func Cairo_Context_SetSourceRGB($pContext, $fR, $fG, $fB)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_set_source_rgb", "ptr", $pContext, "double", $fR, "double", $fG, "double", $fB)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_SetSourceRGBA($pContext, $fR, $fG, $fB, $fA = 1.0)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_set_source_rgba", "ptr", $pContext, "double", $fR, "double", $fG, "double", $fB, "double", $fA)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_SetSourceSurface($pContext, $pSurface, $fX, $fY)
	If Not $pContext Then Return SetError(1, 0, 0)
	If Not $pSurface Then Return SetError(2, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_set_source_surface", "ptr", $pContext, "ptr", $pSurface, "double", $fX, "double", $fY)
	If @error Or Not IsArray($aContext) Then Return SetError(3, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_GetSource($pContext)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_get_source", "ptr", $pContext)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	If Not $aContext[0] Then Return SetError(3, 0, $aContext[0])
	Return $aContext[0]
EndFunc

Func Cairo_Context_SetAntialias($pContext, $iAntialias = $CAIRO_ANTIALIAS_DEFAULT)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_set_antialias", "ptr", $pContext, "long", $iAntialias)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_GetAntialias($pContext)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_get_antialias", "ptr", $pContext)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	If Not $aContext[0] Then Return SetError(3, 0, $aContext[0])
	Return $aContext[0]
EndFunc

Func Cairo_Context_SetDash($pContext, $tDashes, $iLenght, $iOffset)
	If Not $pContext Then Return SetError(1, 0, 0)
	If Not IsDllStruct($tDashes) Then Return SetError(2, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_set_dash", "ptr", $pContext, "struct*", $tDashes, "long", $iLenght, "long", $iOffset)
	If @error Or Not IsArray($aContext) Then Return SetError(3, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_GetDashCount($pContext)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local $tDashes = DllStructCreate("double dashes"), $tOffset = DllStructCreate("double offset")
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_get_dash", "ptr", $pContext, "struct*", $tDashes, "struct*", $tOffset)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	If Not $aContext[0] Then Return SetError(3, 0, $aContext[0])
	Local $aResult[1] = [$tDashes.dashes, $tOffset.offset]
	Return $aResult
EndFunc

Func Cairo_Context_SetFillRule($pContext, $iFillRule)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_set_fill_rule", "ptr", $pContext, "long", $iFillRule)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_GetFillRule($pContext)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "long:cdecl", "cairo_get_fill_rule", "ptr", $pContext)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return $aContext[0]
EndFunc

Func Cairo_Context_SetLineCap($pContext, $iLineCap)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_set_line_cap", "ptr", $pContext, "long", $iLineCap)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_GetLineCap($pContext)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "long:cdecl", "cairo_get_line_cap", "ptr", $pContext)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return $aContext[0]
EndFunc

Func Cairo_Context_SetLineJoin($pContext, $iLineJoin)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_set_line_join", "ptr", $pContext, "long", $iLineJoin)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_GetLineJoin($pContext)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "long:cdecl", "cairo_get_line_join", "ptr", $pContext)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return $aContext[0]
EndFunc

Func Cairo_Context_SetLineWidth($pContext, $fWidth)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_set_line_width", "ptr", $pContext, "double", $fWidth)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_GetLineWidth($pContext)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "double:cdecl", "cairo_get_line_width", "ptr", $pContext)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	If Not $aContext[0] Then Return SetError(3, 0, $aContext[0])
	Return $aContext[0]
EndFunc

Func Cairo_Context_SetMiterLimit($pContext, $fLimit)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_set_miter_limit", "ptr", $pContext, "double", $fLimit)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_GetMiterLimit($pContext)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "double:cdecl", "cairo_get_miter_limit", "ptr", $pContext)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	If Not $aContext[0] Then Return SetError(3, 0, $aContext[0])
	Return $aContext[0]
EndFunc

Func Cairo_Context_SetCompOperator($pContext, $iCompOperator)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_set_operator", "ptr", $pContext, "long", $iCompOperator)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_GetCompOperator($pContext)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "long:cdecl", "cairo_get_operator", "ptr", $pContext)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return $aContext[0]
EndFunc

Func Cairo_Context_SetTolerance($pContext, $fTolerance)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_set_tolerance", "ptr", $pContext, "double", $fTolerance)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_GetTolerance($pContext)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "double:cdecl", "cairo_get_tolerance", "ptr", $pContext)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	If Not $aContext[0] Then Return SetError(3, 0, $aContext[0])
	Return $aContext[0]
EndFunc

Func Cairo_Context_Clip($pContext)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_clip", "ptr", $pContext)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_ClipPreserve($pContext)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_clip_preserve", "ptr", $pContext)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_ClipExtents($pContext, $fX1, $fY1, $fX2, $fY2)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_clip_extents", "ptr", $pContext, "double", $fX1, "double", $fY1, "double", $fX2, "double", $fY2)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_InClip($pContext, $fX, $fY)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "bool:cdecl", "cairo_in_clip", "ptr", $pContext, "double", $fX, "double", $fY)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	If Not $aContext[0] Then Return SetError(3, 0, $aContext[0])
	Return $aContext[0]
EndFunc

Func Cairo_Context_ClipReset($pContext)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_reset_clip", "ptr", $pContext)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_RectListCopyClip($pContext)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_copy_clip_rectangle_list", "ptr", $pContext)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	If Not $aContext[0] Then Return SetError(3, 0, $aContext[0])
	Return $aContext[0]
EndFunc

Func Cairo_Context_Fill($pContext)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_fill", "ptr", $pContext)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_FillPreserve($pContext)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_fill_preserve", "ptr", $pContext)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_FillExtents($pContext, $fX1, $fY1, $fX2, $fY2)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_fill_extents", "ptr", $pContext, "double", $fX1, "double", $fY1, "double", $fX2, "double", $fY2)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_InFill($pContext, $fX, $fY)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "bool:cdecl", "cairo_in_fill", "ptr", $pContext, "double", $fX, "double", $fY)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	If Not $aContext[0] Then Return SetError(3, 0, $aContext[0])
	Return $aContext[0]
EndFunc

Func Cairo_Context_Mask($pContext, $pPattern)
	If Not $pContext Then Return SetError(1, 0, 0)
	If Not $pPattern Then Return SetError(2, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_mask", "ptr", $pContext, "ptr", $pPattern)
	If @error Or Not IsArray($aContext) Then Return SetError(3, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_MaskSurface($pContext, $pSurface, $fX, $fY)
	If Not $pContext Then Return SetError(1, 0, 0)
	If Not $pSurface Then Return SetError(2, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_mask_surface", "ptr", $pContext, "ptr", $pSurface, "double", $fX, "double", $fY)
	If @error Or Not IsArray($aContext) Then Return SetError(3, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_Paint($pContext)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_paint", "ptr", $pContext)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_PaintWithAlpha($pContext)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_paint_with_alpha", "ptr", $pContext)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_Stroke($pContext)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_stroke", "ptr", $pContext)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_StrokePreserve($pContext)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_stroke_preserve", "ptr", $pContext)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_StrokeExtents($pContext, $fX1, $fY1, $fX2, $fY2)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_stroke_extents", "ptr", $pContext, "double", $fX1, "double", $fY1, "double", $fX2, "double", $fY2)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_InStroke($pContext, $fX, $fY)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "bool:cdecl", "cairo_in_stroke", "ptr", $pContext, "double", $fX, "double", $fY)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	If Not $aContext[0] Then Return SetError(3, 0, $aContext[0])
	Return $aContext[0]
EndFunc

Func Cairo_Context_PageCopy($pContext)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_copy_page", "ptr", $pContext)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_PageShow($pContext)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_show_page", "ptr", $pContext)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_GetRefCount($pContext)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "ulong:cdecl", "cairo_get_reference_count", "ptr", $pContext)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	If Not $aContext[0] Then Return SetError(3, 0, $aContext[0])
	Return $aContext[0]
EndFunc

Func Cairo_Context_HairlineSet($pContext, $bSet = True)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_set_hairline", "ptr", $pContext, "bool", $bSet)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_HairlineGet($pContext)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "bool:cdecl", "cairo_get_hairline", "ptr", $pContext)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	If Not $aContext[0] Then Return SetError(3, 0, $aContext[0])
	Return $aContext[0]
EndFunc

Func Cairo_Context_PathCopy($pContext)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_copy_path", "ptr", $pContext)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	If Not $aContext[0] Then Return SetError(3, 0, $aContext[0])
	Return $aContext[0]
EndFunc

Func Cairo_Context_PathCopyFlat($pContext)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_copy_path_flat", "ptr", $pContext)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	If Not $aContext[0] Then Return SetError(3, 0, $aContext[0])
	Return $aContext[0]
EndFunc

Func Cairo_Context_PathDestroy($pContext)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_path_destroy", "ptr", $pContext)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_PathAppend($pContext, $pPath)
	If Not $pContext Then Return SetError(1, 0, 0)
	If Not $pPath Then Return SetError(2, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_append_path", "ptr", $pContext, "ptr", $pPath)
	If @error Or Not IsArray($aContext) Then Return SetError(3, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_PathHasCurrentPoint($pContext)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "bool:cdecl", "cairo_has_current_point", "ptr", $pContext)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	If Not $aContext[0] Then Return SetError(3, 0, $aContext[0])
	Return $aContext[0]
EndFunc

Func Cairo_Context_PathGetCurrentPoint($pContext, $fX, $fY)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local $tPointX = DllStructCreate("double x;"), $tPointY = DllStructCreate("double y;")
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_get_current_point", "ptr", $pContext, "struct*", $tPointX, "struct*", $tPointY)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Local $aResult[1] = [$tPointX.x, $tPointY.y]
	Return $aResult
EndFunc

Func Cairo_Context_PathNew($pContext)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_new_path", "ptr", $pContext)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_PathClear($pContext)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_close_path", "ptr", $pContext)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_PathBeginNewSub($pContext)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_new_sub_path", "ptr", $pContext)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_PathClose($pContext)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_close_path", "ptr", $pContext)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_PathAddArc($pContext, $fXC, $fYC, $fRadius, $fAngle1, $fAngle2)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_arc", "ptr", $pContext, "double", $fXC, "double", $fYC, "double", $fRadius, "double", $fAngle1, "double", $fAngle2)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_PathAddArcNegative($pContext, $fXC, $fYC, $fRadius, $fAngle1, $fAngle2)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_arc_negative", "ptr", $pContext, "double", $fXC, "double", $fYC, "double", $fRadius, "double", $fAngle1, "double", $fAngle2)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_PathAddCurveTo($pContext, $fX1, $fY1, $fX2, $fY2, $fX3, $fY3)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_curve_to", "ptr", $pContext, "double", $fX1, "double", $fY1, "double", $fX2, "double", $fX2, "double", $fX3, "double", $fY3)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_PathAddRelCurveTo($pContext, $fX1, $fY1, $fX2, $fY2, $fX3, $fY3)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_rel_curve_to", "ptr", $pContext, "double", $fX1, "double", $fY1, "double", $fX2, "double", $fX2, "double", $fX3, "double", $fY3)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_PathAddLineTo($pContext, $fX, $fY)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_line_to", "ptr", $pContext, "double", $fX, "double", $fY)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_PathAddRelLineTo($pContext, $fX, $fY)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_rel_line_to", "ptr", $pContext, "double", $fX, "double", $fY)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_PathAddMoveTo($pContext, $fX, $fY)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_move_to", "ptr", $pContext, "double", $fX, "double", $fY)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_PathAdReldMoveTo($pContext, $fX, $fY)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_rel_move_to", "ptr", $pContext, "double", $fX, "double", $fY)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_PathAddRectangle($pContext, $fX, $fY, $fWidth, $fHeight)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_rectangle", "ptr", $pContext, "double", $fX, "double", $fY, "double", $fWidth, "double", $fHeight)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_PathAddGlypth($pContext, $pGlyphs, $iNumberOfGlyphs)
	If Not $pContext Then Return SetError(1, 0, 0)
	If Not $pGlyphs Then Return SetError(2, 0, 0)
	If $iNumberOfGlyphs < 1 Then Return SetError(3, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_glyph_path", "ptr", $pContext, "ptr", $pGlyphs, "long", $iNumberOfGlyphs)
	If @error Or Not IsArray($aContext) Then Return SetError(4, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_PathAddText($pContext, $sText)
	If Not $pContext Then Return SetError(1, 0, 0)
	If $sText = "" Then Return SetError(2, 0, 0)
	Local $tText = DllStructCreate("wchar string[" & StringLen & "];")
	$tText.string = $sText
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_text_path", "ptr", $pContext, "struct*", $tText)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_PathCalcExtents($pContext)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local $tPointX1 = DllStructCreate("double x1;"), $tPointY1 = DllStructCreate("double y1;"), _
		  $tPointX2 = DllStructCreate("double x2;"), $tPointY2 = DllStructCreate("double y2;")
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_path_extents", "ptr", $pContext, "struct*", $tPointX1, "struct*", $tPointY1, "struct*", $tPointX2, "struct*", $tPointY2)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Local $aResult[3] = [$tPointX1.x1, $tPointY1.y1, $tPointX1.x2, $tPointY1.y2]
	Return $aResult
EndFunc

Func Cairo_Context_Translate($pContext, $fTx, $fTy)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_translate", "ptr", $pContext, "double", $fTx, "double", $fTy)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_Scale($pContext, $fSx, $fSy)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_scale", "ptr", $pContext, "double", $fSx, "double", $fSy)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_Rotate($pContext, $fAngle)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_rotate", "ptr", $pContext, "double", $fAngle)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_Transform($pContext, $tCairo_matrix)
	If Not $pContext Then Return SetError(1, 0, 0)
	If Not IsDllStruct($tCairo_matrix) Then Return SetError(2, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_transform", "ptr", $pContext, "struct*", $tCairo_matrix)
	If @error Or Not IsArray($aContext) Then Return SetError(3, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_Set($pContext, $tCairo_matrix)
	If Not $pContext Then Return SetError(1, 0, 0)
	If Not IsDllStruct($tCairo_matrix) Then Return SetError(2, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_set_matrix", "ptr", $pContext, "struct*", $tCairo_matrix)
	If @error Or Not IsArray($aContext) Then Return SetError(3, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_Get($pContext)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local $tMatrix = DllStructCreate($tagCairo_matrix)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_get_matrix", "ptr", $pContext, "struct*", $tMatrix)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	If Not $aContext[0] Then Return SetError(3, 0, 0)
	Return $tMatrix
EndFunc

Func Cairo_Context_ResetIdentity($pContext)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_identity_matrix", "ptr", $pContext)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Context_UserToDevice($pContext, ByRef $fX, ByRef $fY)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local $tX = DllStructCreate("double x;"), $tY = DllStructCreate("double y;")
	$tX.x = $fY
	$tY.y = $fY
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_user_to_device", "ptr", $pContext, "struct*", $tX, "struct*", $tY)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	$fX = $tX.x
	$fY = $tX.y
	Return 1
EndFunc

Func Cairo_Context_UserToDeviceDistance($pContext, ByRef $fX, ByRef $fY)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local $tX = DllStructCreate("double x;"), $tY = DllStructCreate("double y;")
	$tX.x = $fY
	$tY.y = $fY
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_user_to_device_distance", "ptr", $pContext, "struct*", $tX, "struct*", $tY)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	$fX = $tX.x
	$fY = $tX.y
	Return 1
EndFunc

Func Cairo_Context_DeviceToUser($pContext, ByRef $fX, ByRef $fY)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local $tX = DllStructCreate("double x;"), $tY = DllStructCreate("double y;")
	$tX.x = $fY
	$tY.y = $fY
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_device_to_user", "ptr", $pContext, "struct*", $tX, "struct*", $tY)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	$fX = $tX.x
	$fY = $tX.y
	Return 1
EndFunc

Func Cairo_Context_DeviceToUserDistance($pContext, ByRef $fX, ByRef $fY)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local $tX = DllStructCreate("double x;"), $tY = DllStructCreate("double y;")
	$tX.x = $fY
	$tY.y = $fY
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_device_to_user_distance", "ptr", $pContext, "struct*", $tX, "struct*", $tY)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	$fX = $tX.x
	$fY = $tX.y
	Return 1
EndFunc
#EndRegion Context

;-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#Region Pattern
Func Cairo_Pattern_AddRGBColorStop($pPattern, $fOffset, $fRed = 1.0, $fGReen = 1.0, $fBlue = 1.0)
	If Not $pPattern Then Return SetError(1, 0, 0)
	Local Const $aPattern = DllCall($g_hCairoDLL, "none:cdecl", "cairo_pattern_add_color_stop_rgb", "ptr", $pPattern, "double", $fOffset, "double", $fRed, "double", $fGReen, "double", $fBlue)
	If @error Or Not IsArray($aPattern) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Pattern_GetRGBColorStopCount($pPattern, $iCount)
	If Not $pPattern Then Return SetError(1, 0, 0)
	Local Const $aPattern = DllCall($g_hCairoDLL, "long:cdecl", "cairo_pattern_get_color_stop_count", "ptr", $pPattern, "long", $iCount)
	If @error Or Not IsArray($aPattern) Then Return SetError(2, 0, 0)
	Return $aPattern[0]
EndFunc

Func Cairo_Pattern_AddRGBAColorStop($pPattern, $fOffset = 0.0, $fRed = 1.0, $fGReen = 1.0, $fBlue = 1.0, $fAlpha = 1.0)
	If Not $pPattern Then Return SetError(1, 0, 0)
	Local Const $aPattern = DllCall($g_hCairoDLL, "none:cdecl", "cairo_pattern_add_color_stop_rgba", "ptr", $pPattern, "double", $fOffset, "double", $fRed, "double", $fGReen, "double", $fBlue, "double", $fAlpha)
	If @error Or Not IsArray($aPattern) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Pattern_GetRGBAColorStop($pPattern, $iIndex)
	If Not $pPattern Then Return SetError(1, 0, 0)
	Local $tOffset = DllStructCreate("double offset;"), $tRed = DllStructCreate("double r;"), $tGreen = DllStructCreate("double g;"), _
		  $tBlue = DllStructCreate("double b;"), $tAlpha = DllStructCreate("double a;")
	Local Const $aPattern = DllCall($g_hCairoDLL, "long:cdecl", "cairo_pattern_get_color_stop_rgba", "ptr", $pPattern, "long", $iIndex, "struct*", $tOffset, _
							"struct*", $tRed, "struct*", $tGreen, "struct*", $tBlue, "struct*", $tAlpha)
	If @error Or Not IsArray($aPattern) Then Return SetError(2, 0, 0)
	Local $aResult[4] = [$tOffset.offset, $tRed.r, $tGreen.g, $tBlue.b, $tAlpha.a]
	Return $aResult
EndFunc

Func Cairo_Pattern_CreateRGB($fRed = 1.0, $fGReen = 1.0, $fBlue = 1.0)
	Local Const $aPattern = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_pattern_create_rgb", "double", $fRed, "double", $fGReen, "double", $fBlue)
	If @error Or Not IsArray($aPattern) Then Return SetError(1, 0, 0)
	If Not $aPattern[0] Then Return SetError(2, 0, 0)
	Return $aPattern[0]
EndFunc

Func Cairo_Pattern_CreateRGBA($fRed = 1.0, $fGReen = 1.0, $fBlue = 1.0, $fAlpha = 1.0)
	Local Const $aPattern = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_pattern_create_rgba", "double", $fRed, "double", $fGReen, "double", $fBlue, "double", $fAlpha)
	If @error Or Not IsArray($aPattern) Then Return SetError(1, 0, 0)
	If Not $aPattern[0] Then Return SetError(2, 0, 0)
	Return $aPattern[0]
EndFunc

Func Cairo_Pattern_GetRGBAColor($pPattern)
	If Not $pPattern Then Return SetError(1, 0, 0)
	Local $tOffset = DllStructCreate("double offset;"), $tRed = DllStructCreate("double r;"), $tGreen = DllStructCreate("double g;"), _
		  $tBlue = DllStructCreate("double b;"), $tAlpha = DllStructCreate("double a;")
	Local Const $aPattern = DllCall($g_hCairoDLL, "long:cdecl", "cairo_pattern_get_rgba", "ptr", $pPattern, "struct*", $tRed, "struct*", $tGreen, "struct*", $tBlue, "struct*", $tAlpha)
	If @error Or Not IsArray($aPattern) Then Return SetError(2, 0, 0)
	Local $aResult[3] = [$tRed.r, $tGreen.g, $tBlue.b, $tAlpha.a]
	Return $aResult
EndFunc

Func Cairo_Pattern_CreateForSurface($pSurface)
	If Not $pSurface Then Return SetError(1, 0, 0)
	Local Const $aPattern = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_pattern_create_for_surface", "ptr", $pSurface)
	If @error Or Not IsArray($aPattern) Then Return SetError(2, 0, 0)
	If Not $aPattern[0] Then Return SetError(3, 0, 0)
	Return $aPattern[0]
EndFunc

Func Cairo_Pattern_GetSurface($pPattern, $pPatternSurface)
	If Not $pPattern Then Return SetError(1, 0, 0)
	If Not $pPatternSurface Then Return SetError(2, 0, 0)
	Local Const $aPattern = DllCall($g_hCairoDLL, "long:cdecl", "cairo_pattern_get_surface", "ptr", $pPattern, "ptr", $pPatternSurface)
	If @error Or Not IsArray($aPattern) Then Return SetError(3, 0, 0)
	Return $aPattern[0]
EndFunc

Func Cairo_Pattern_CreateLiniearGradient($fX1, $fY1, $fX2, $fY2)
	Local Const $aPattern = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_pattern_create_linear", "double", $fX1, "double", $fY1, "double", $fX2, "double", $fY2)
	If @error Or Not IsArray($aPattern) Then Return SetError(2, 0, 0)
	If Not $aPattern[0] Then Return SetError(3, 0, 0)
	Return $aPattern[0]
EndFunc

Func Cairo_Pattern_GetLiniearGradientPoints($pPattern)
	If Not $pPattern Then Return SetError(1, 0, 0)
	Local $tX1 = DllStructCreate("double x1;"), $tY1 = DllStructCreate("double y1;"), $tX2 = DllStructCreate("double x2;"), $tY2 = DllStructCreate("double y2;")
	Local Const $aPattern = DllCall($g_hCairoDLL, "long:cdecl", "cairo_pattern_get_linear_points", "ptr", $pPattern, "struct*", $tX1, "struct*", $tY1, "struct*", $tX2, "struct*", $tY2)
	If @error Or Not IsArray($aPattern) Then Return SetError(2, 0, 0)
	Local $aResult[3] = [$tX1.x1, $tY1.y1, $tX1.x2, $tY1.y2]
	Return $aResult
EndFunc

Func Cairo_Pattern_CreateRadialGradient($fCX1, $fCY1, $fRadius0, $fCX2, $fCY2, $fRadius1)
	Local Const $aPattern = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_pattern_create_radial", "double", $fCX1, "double", $fCY1, "double", $fRadius0, "double", $fCX2, "double", $fCY2, "double", $fRadius1)
	If @error Or Not IsArray($aPattern) Then Return SetError(2, 0, 0)
	If Not $aPattern[0] Then Return SetError(3, 0, 0)
	Return $aPattern[0]
EndFunc

Func Cairo_Pattern_GetRadialGradient($pPattern)
	If Not $pPattern Then Return SetError(1, 0, 0)
	Local $tX1 = DllStructCreate("double x1;"), $tY1 = DllStructCreate("double y1;"), $tX2 = DllStructCreate("double x2;"), $tY2 = DllStructCreate("double y2;"), _
		  $tR1 = DllStructCreate("double r1;"), $tR2 = DllStructCreate("double r2;")
	Local Const $aPattern = DllCall($g_hCairoDLL, "long:cdecl", "cairo_pattern_get_radial_circles", "ptr", $pPattern, "struct*", $tX1, "struct*", $tY1, "struct*", $tR1, "struct*", $tX2, "struct*", $tY2, "struct*", $tR2)
	If @error Or Not IsArray($aPattern) Then Return SetError(2, 0, 0)
	Local $aResult[5] = [$tX1.x1, $tY1.y1, $tR1.r1, $tX1.x2, $tY1.y2, $tR1.r2]
	Return $aResult
EndFunc

Func Cairo_Pattern_MeshCreate()
	Local Const $aPattern = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_pattern_create_mesh")
	If @error Or Not IsArray($aPattern) Then Return SetError(1, 0, 0)
	If Not $aPattern[0] Then Return SetError(2, 0, 0)
	Return $aPattern[0]
EndFunc

Func Cairo_Pattern_MeshBeginPatch($pPattern)
	If Not $pPattern Then Return SetError(1, 0, 0)
	Local Const $aPattern = DllCall($g_hCairoDLL, "none:cdecl", "cairo_mesh_pattern_begin_patch", "ptr", $pPattern)
	If @error Or Not IsArray($aPattern) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Pattern_MeshEndPatch($pPattern)
	If Not $pPattern Then Return SetError(1, 0, 0)
	Local Const $aPattern = DllCall($g_hCairoDLL, "none:cdecl", "cairo_mesh_pattern_end_patch", "ptr", $pPattern)
	If @error Or Not IsArray($aPattern) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Pattern_MeshMoveTo($pPattern, $fX, $fY)
	If Not $pPattern Then Return SetError(1, 0, 0)
	Local Const $aPattern = DllCall($g_hCairoDLL, "none:cdecl", "cairo_mesh_pattern_move_to", "ptr", $pPattern, "double", $fX, "double", $fY)
	If @error Or Not IsArray($aPattern) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Pattern_MeshLineTo($pPattern, $fX, $fY)
	If Not $pPattern Then Return SetError(1, 0, 0)
	Local Const $aPattern = DllCall($g_hCairoDLL, "none:cdecl", "cairo_mesh_pattern_line_to", "ptr", $pPattern, "double", $fX, "double", $fY)
	If @error Or Not IsArray($aPattern) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Pattern_MeshCurveTo($pPattern, $fX1, $fY1, $fX2, $fY2, $fX3, $fY3)
	If Not $pPattern Then Return SetError(1, 0, 0)
	Local Const $aPattern = DllCall($g_hCairoDLL, "none:cdecl", "cairo_mesh_pattern_curve_to", "ptr", $pPattern, "double", $fX1, "double", $fY1, "double", $fX2, "double", $fX2, "double", $fX3, "double", $fY3)
	If @error Or Not IsArray($aPattern) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Pattern_MeshSetControlPoint($pPattern, $iNum, $fX, $fY)
	If Not $pPattern Then Return SetError(1, 0, 0)
	Local Const $aPattern = DllCall($g_hCairoDLL, "none:cdecl", "cairo_mesh_pattern_set_control_point", "ptr", $pPattern, "ulong", $iNum, "double", $fX, "double", $fY)
	If @error Or Not IsArray($aPattern) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Pattern_MeshSetCornerColorRGBA($pPattern, $iNum, $fRed = 1.0, $fGReen = 1.0, $fBlue = 1.0, $fAlpha = 1.0)
	If Not $pPattern Then Return SetError(1, 0, 0)
	Local Const $aPattern = DllCall($g_hCairoDLL, "none:cdecl", "cairo_mesh_pattern_set_corner_color_rgba", "ptr", $pPattern, "ulong", $iNum, "double", $fRed, "double", $fGReen, "double", $fBlue, "double", $fAlpha)
	If @error Or Not IsArray($aPattern) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Pattern_MeshGetCornerColorRGBA($pPattern, $iPatchNum, $iPointNum)
	If Not $pPattern Then Return SetError(1, 0, 0)
	Local $tOffset = DllStructCreate("double offset;"), $tRed = DllStructCreate("double r;"), $tGreen = DllStructCreate("double g;"), _
		  $tBlue = DllStructCreate("double b;"), $tAlpha = DllStructCreate("double a;")
	Local Const $aPattern = DllCall($g_hCairoDLL, "long:cdecl", "cairo_mesh_pattern_get_corner_color_rgba", "ptr", $pPattern, "ulong", $iPatchNum, "ulong", $iPointNum, "struct*", $tRed, "struct*", $tGreen, "struct*", $tBlue, "struct*", $tAlpha)
	If @error Or Not IsArray($aPattern) Then Return SetError(2, 0, 0)
	Local $aResult[3] = [$tRed.r, $tGreen.g, $tBlue.b, $tAlpha.a]
	Return $aResult
EndFunc

Func Cairo_Pattern_MeshGetPatchCount($pPattern, $iCount)
	If Not $pPattern Then Return SetError(1, 0, 0)
	Local $tCount = DllStructCreate("ulong c;")
	Local Const $aPattern = DllCall($g_hCairoDLL, "long:cdecl", "cairo_mesh_pattern_get_patch_count", "ptr", $pPattern, "struct*", $tCount)
	If @error Or Not IsArray($aPattern) Then Return SetError(2, 0, 0)
	Return $tCount.c
EndFunc

Func Cairo_Pattern_MeshGetPatchPath($pPattern, $iCount)
	If Not $pPattern Then Return SetError(1, 0, 0)
	If Not $iCount Then Return SetError(2, 0, 0)
	Local Const $aPattern = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_mesh_pattern_get_path", "ptr", $pPattern, "ulong", $iCount)
	If @error Or Not IsArray($aPattern) Then Return SetError(3, 0, 0)
	If $aPattern[0] Then Return SetError(4, 0, $aPattern[0])
	Return $aPattern[0]
EndFunc

Func Cairo_Pattern_MeshGetControlPoint($pPattern, $iPatchNum, $iPointNum)
	If Not $pPattern Then Return SetError(1, 0, 0)
	Local $tPx = DllStructCreate("ulong x;"), $tPy = DllStructCreate("ulong y;")
	Local Const $aPattern = DllCall($g_hCairoDLL, "long:cdecl", "cairo_mesh_pattern_get_control_point", "ptr", $pPattern, "ulong", $iPatchNum, "ulong", $iPointNum, "struct*", $tPx, "struct*", $tPy)
	If @error Or Not IsArray($aPattern) Then Return SetError(2, 0, 0)
	Local $aResult[1] = [$tPx.x, $tPy.y]
	Return $aResult
EndFunc

Func Cairo_Pattern_IncreaseReference($pPattern)
	If Not $pPattern Then Return SetError(1, 0, 0)
	Local Const $aPattern = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_pattern_reference", "ptr", $pPattern)
	If @error Or Not IsArray($aPattern) Then Return SetError(2, 0, 0)
	If Not $aPattern[0] Then Return SetError(3, 0, $aPattern[0])
	Return $aPattern[0]
EndFunc

Func Cairo_Pattern_Destroy($pPattern)
	If Not $pPattern Then Return SetError(1, 0, 0)
	Local Const $aPattern = DllCall($g_hCairoDLL, "none:cdecl", "cairo_mesh_pattern_set_corner_color_rgba", "ptr", $pPattern)
	If @error Or Not IsArray($aPattern) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Pattern_CheckStatus($pPattern)
	If Not $pPattern Then Return SetError(1, 0, 0)
	Local Const $aPattern = DllCall($g_hCairoDLL, "long:cdecl", "cairo_pattern_status", "ptr", $pPattern)
	If @error Or Not IsArray($aPattern) Then Return SetError(2, 0, 0)
	Return $aPattern[0]
EndFunc

Func Cairo_Pattern_SetExtend($pPattern, $iExtend)
	If Not $pPattern Then Return SetError(1, 0, 0)
	Local Const $aPattern = DllCall($g_hCairoDLL, "none:cdecl", "cairo_pattern_set_extend", "ptr", $pPattern, "long", $iExtend)
	If @error Or Not IsArray($aPattern) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Pattern_GetExtend($pPattern)
	If Not $pPattern Then Return SetError(1, 0, 0)
	Local Const $aPattern = DllCall($g_hCairoDLL, "long:cdecl", "cairo_pattern_get_extend", "ptr", $pPattern)
	If @error Or Not IsArray($aPattern) Then Return SetError(2, 0, 0)
	Return $aPattern[0]
EndFunc

Func Cairo_Pattern_SetFilter($pPattern, $iFilter)
	If Not $pPattern Then Return SetError(1, 0, 0)
	Local Const $aPattern = DllCall($g_hCairoDLL, "none:cdecl", "cairo_pattern_set_filter", "ptr", $pPattern, "long", $iFilter)
	If @error Or Not IsArray($aPattern) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Pattern_GetFilter($pPattern)
	If Not $pPattern Then Return SetError(1, 0, 0)
	Local Const $aPattern = DllCall($g_hCairoDLL, "long:cdecl", "cairo_pattern_get_filter", "ptr", $pPattern)
	If @error Or Not IsArray($aPattern) Then Return SetError(2, 0, 0)
	Return $aPattern[0]
EndFunc

Func Cairo_Pattern_SetMatrix($pPattern, $tMatrix)
	If Not $pPattern Then Return SetError(1, 0, 0)
	If Not IsDllStruct($tMatrix) Then Return SetError(2, 0, 0)
	Local Const $aPattern = DllCall($g_hCairoDLL, "none:cdecl", "cairo_pattern_set_matrix", "ptr", $pPattern, "struct*", $tMatrix)
	If @error Or Not IsArray($aPattern) Then Return SetError(3, 0, 0)
	Return 1
EndFunc

Func Cairo_Pattern_GetMatrix($pPattern)
	If Not $pPattern Then Return SetError(1, 0, 0)
	Local $tMatrix = DllStructCreate($tagCairo_matrix)
	Local Const $aPattern = DllCall($g_hCairoDLL, "none:cdecl", "cairo_pattern_get_matrix", "ptr", $pPattern, "struct*", $tMatrix)
	If @error Or Not IsArray($aPattern) Then Return SetError(2, 0, 0)
	Return $tMatrix
EndFunc

Func Cairo_Pattern_GetType($pPattern)
	If Not $pPattern Then Return SetError(1, 0, 0)
	Local Const $aPattern = DllCall($g_hCairoDLL, "long:cdecl", "cairo_pattern_get_type", "ptr", $pPattern)
	If @error Or Not IsArray($aPattern) Then Return SetError(2, 0, 0)
	Return $aPattern[0]
EndFunc

Func Cairo_Pattern_GetReferenceCount($pPattern)
	If Not $pPattern Then Return SetError(1, 0, 0)
	Local Const $aPattern = DllCall($g_hCairoDLL, "ulong:cdecl", "cairo_pattern_get_reference_count", "ptr", $pPattern)
	If @error Or Not IsArray($aPattern) Then Return SetError(1, 0, 0)
	If Not $aPattern[0] Then Return SetError(2, 0, $aPattern[0])
	Return $aPattern[0]
EndFunc

Func Cairo_Pattern_SetDither($pPattern, $iDither)
	If Not $pPattern Then Return SetError(1, 0, 0)
	Local Const $aPattern = DllCall($g_hCairoDLL, "none:cdecl", "cairo_pattern_set_dither", "ptr", $pPattern, "long", $iDither)
	If @error Or Not IsArray($aPattern) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Pattern_GetDither($pPattern)
	If Not $pPattern Then Return SetError(1, 0, 0)
	Local Const $aPattern = DllCall($g_hCairoDLL, "long:cdecl", "cairo_pattern_get_dither", "ptr", $pPattern)
	If @error Or Not IsArray($aPattern) Then Return SetError(2, 0, 0)
	Return $aPattern[0]
EndFunc

Func Cairo_Pattern_SetSource($pContext, $pPattern)
	If Not $pContext Then Return SetError(1, 0, 0)
	If Not $pPattern Then Return SetError(2, 0, 0)
	Local Const $aPattern = DllCall($g_hCairoDLL, "none:cdecl", "cairo_set_source", "ptr", $pContext, "ptr", $pPattern)
	If @error Or Not IsArray($aPattern) Then Return SetError(3, 0, 0)
	Return 1
EndFunc
#EndRegion Pattern

;-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#Region Region
Func Cairo_Region_Create()
	Local Const $aRegion = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_region_create")
	If @error Or Not IsArray($aRegion) Then Return SetError(1, 0, 0)
	If Not $aRegion[0] Then Return SetError(2, 0, 0)
	Return $aRegion[0]
EndFunc

Func Cairo_Region_CreateRectangle($tCairo_rectangle_int)
	If Not IsDllStruct($tCairo_rectangle_int) Then Return SetError(1, 0, 0)
	Local Const $aRegion = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_region_create_rectangle", "struct*", $tCairo_rectangle_int)
	If @error Or Not IsArray($aRegion) Then Return SetError(2, 0, 0)
	If Not $aRegion[0] Then Return SetError(3, 0, 0)
	Return $aRegion[0]
EndFunc

Func Cairo_Region_CreateRectangles($taCairo_rectangle_int, $iCount)
	If Not IsDllStruct($taCairo_rectangle_int) Then Return SetError(1, 0, 0)
	Local Const $aRegion = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_region_create_rectangles", "struct*", $taCairo_rectangle_int, "ulong", $iCount)
	If @error Or Not IsArray($aRegion) Then Return SetError(2, 0, 0)
	If Not $aRegion[0] Then Return SetError(3, 0, 0)
	Return $aRegion[0]
EndFunc

Func Cairo_Region_Copy($pRegion)
	If Not $pRegion Then Return SetError(1, 0, 0)
	Local Const $aRegion = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_region_copy", "ptr", $pRegion)
	If @error Or Not IsArray($aRegion) Then Return SetError(2, 0, 0)
	If Not $aRegion[0] Then Return SetError(3, 0, 0)
	Return $aRegion[0]
EndFunc

Func Cairo_Region_IncreaseReference($pRegion)
	If Not $pRegion Then Return SetError(1, 0, 0)
	Local Const $aRegion = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_region_reference", "ptr", $pRegion)
	If @error Or Not IsArray($aRegion) Then Return SetError(2, 0, 0)
	If Not $aRegion[0] Then Return SetError(3, 0, 0)
	Return $aRegion[0]
EndFunc

Func Cairo_Region_Destroy($pRegion)
	If Not $pRegion Then Return SetError(1, 0, 0)
	Local Const $aRegion = DllCall($g_hCairoDLL, "none:cdecl", "cairo_region_destroy", "ptr", $pRegion)
	If @error Or Not IsArray($aRegion) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Region_GetStatus($pRegion)
	If Not $pRegion Then Return SetError(1, 0, 0)
	Local Const $aRegion = DllCall($g_hCairoDLL, "long:cdecl", "cairo_region_status", "ptr", $pRegion)
	If @error Or Not IsArray($aRegion) Then Return SetError(2, 0, 0)
	Return $aRegion[0]
EndFunc

Func Cairo_Region_GetExtents($pRegion)
	If Not $pRegion Then Return SetError(1, 0, 0)
	Local $tCairo_rectangle_int = DllStructCreate($tagCairo_rectangle_int)
	Local Const $aRegion = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_region_get_extents", "ptr", $pRegion, "struct*", $tCairo_rectangle_int)
	If @error Or Not IsArray($aRegion) Then Return SetError(2, 0, 0)
	If Not $aRegion[0] Then Return SetError(3, 0, 0)
	Return $tCairo_rectangle_int
EndFunc

Func Cairo_Region_GetNumberOfRectangles($pRegion)
	If Not $pRegion Then Return SetError(1, 0, 0)
	Local $tCairo_rectangle_int = DllStructCreate($tagCairo_rectangle_int)
	Local Const $aRegion = DllCall($g_hCairoDLL, "long:cdecl", "cairo_region_num_rectangles", "ptr", $pRegion)
	If @error Or Not IsArray($aRegion) Then Return SetError(2, 0, 0)
	Return $aRegion[0]
EndFunc

Func Cairo_Region_GetRectangle($pRegion, $iNth = 0)
	If Not $pRegion Then Return SetError(1, 0, 0)
	Local $tCairo_rectangle_int = DllStructCreate($tagCairo_rectangle_int)
	Local Const $aRegion = DllCall($g_hCairoDLL, "none:cdecl", "cairo_region_get_rectangle", "ptr", $pRegion, "long", $iNth, "struct*", $tCairo_rectangle_int)
	If @error Or Not IsArray($aRegion) Then Return SetError(2, 0, 0)
	Return $tCairo_rectangle_int
EndFunc

Func Cairo_Region_IsEmpty($pRegion)
	If Not $pRegion Then Return SetError(1, 0, 0)
	Local Const $aRegion = DllCall($g_hCairoDLL, "bool:cdecl", "cairo_region_is_empty", "ptr", $pRegion)
	If @error Or Not IsArray($aRegion) Then Return SetError(2, 0, 0)
	If Not $aRegion[0] Then Return SetError(3, 0, 0)
	Return $aRegion[0]
EndFunc

Func Cairo_Region_ContainsPoint($pRegion, $iX, $iY)
	If Not $pRegion Then Return SetError(1, 0, 0)
	Local Const $aRegion = DllCall($g_hCairoDLL, "bool:cdecl", "cairo_region_contains_point", "ptr", $pRegion, "long", $iX, "long", $iY)
	If @error Or Not IsArray($aRegion) Then Return SetError(2, 0, 0)
	If Not $aRegion[0] Then Return SetError(3, 0, 0)
	Return $aRegion[0]
EndFunc

Func Cairo_Region_ContainsRectangle($pRegion, $tCairo_rectangle_int)
	If Not $pRegion Then Return SetError(1, 0, 0)
	If Not IsDllStruct($tCairo_rectangle_int) Then Return SetError(2, 0, 0)
	Local Const $aRegion = DllCall($g_hCairoDLL, "long:cdecl", "cairo_region_contains_rectangle", "ptr", $pRegion, "struct*", $tCairo_rectangle_int)
	If @error Or Not IsArray($aRegion) Then Return SetError(3, 0, 0)
	Return $aRegion[0]
EndFunc

Func Cairo_Region_IsEqual($pRegion1, $pRegion2)
	If Not $pRegion1 Then Return SetError(1, 0, 0)
	If Not $pRegion2 Then Return SetError(2, 0, 0)
	Local Const $aRegion = DllCall($g_hCairoDLL, "bool:cdecl", "cairo_region_equal", "ptr", $pRegion1, "ptr", $pRegion2)
	If @error Or Not IsArray($aRegion) Then Return SetError(3, 0, 0)
	If Not $aRegion[0] Then Return SetError(4, 0, 0)
	Return $aRegion[0]
EndFunc

Func Cairo_Region_Translate($pRegion, $iDX = 0, $iDY = 0)
	If Not $pRegion Then Return SetError(1, 0, 0)
	Local Const $aRegion = DllCall($g_hCairoDLL, "none:cdecl", "cairo_region_translate", "ptr", $pRegion, "long", $iDX, "long", $iDY)
	If @error Or Not IsArray($aRegion) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Region_Intersect($pRegion1, $pRegion2)
	If Not $pRegion1 Then Return SetError(1, 0, 0)
	If Not $pRegion2 Then Return SetError(2, 0, 0)
	Local Const $aRegion = DllCall($g_hCairoDLL, "long:cdecl", "cairo_region_intersect", "ptr", $pRegion1, "ptr", $pRegion2)
	If @error Or Not IsArray($aRegion) Then Return SetError(3, 0, 0)
	Return $aRegion[0]
EndFunc

Func Cairo_Region_IntersectRectangle($pRegion, $tCairo_rectangle_int)
	If Not $pRegion Then Return SetError(1, 0, 0)
	If Not IsDllStruct($tCairo_rectangle_int) Then Return SetError(2, 0, 0)
	Local Const $aRegion = DllCall($g_hCairoDLL, "long:cdecl", "cairo_region_intersect_rectangle", "ptr", $pRegion, "struct*", $tCairo_rectangle_int)
	If @error Or Not IsArray($aRegion) Then Return SetError(3, 0, 0)
	Return $aRegion[0]
EndFunc

Func Cairo_Region_Subtract($pRegion1, $pRegion2)
	If Not $pRegion1 Then Return SetError(1, 0, 0)
	If Not $pRegion2 Then Return SetError(2, 0, 0)
	Local Const $aRegion = DllCall($g_hCairoDLL, "long:cdecl", "cairo_region_subtract", "ptr", $pRegion1, "ptr", $pRegion2)
	If @error Or Not IsArray($aRegion) Then Return SetError(3, 0, 0)
	Return $aRegion[0]
EndFunc

Func Cairo_Region_SubtractRectangle($pRegion, $tCairo_rectangle_int)
	If Not $pRegion Then Return SetError(1, 0, 0)
	If Not IsDllStruct($tCairo_rectangle_int) Then Return SetError(2, 0, 0)
	Local Const $aRegion = DllCall($g_hCairoDLL, "long:cdecl", "cairo_region_subtract_rectangle", "ptr", $pRegion, "struct*", $tCairo_rectangle_int)
	If @error Or Not IsArray($aRegion) Then Return SetError(3, 0, 0)
	Return $aRegion[0]
EndFunc

Func Cairo_Region_Union($pRegion1, $pRegion2)
	If Not $pRegion1 Then Return SetError(1, 0, 0)
	If Not $pRegion2 Then Return SetError(2, 0, 0)
	Local Const $aRegion = DllCall($g_hCairoDLL, "long:cdecl", "cairo_region_union", "ptr", $pRegion1, "ptr", $pRegion2)
	If @error Or Not IsArray($aRegion) Then Return SetError(3, 0, 0)
	Return $aRegion[0]
EndFunc

Func Cairo_Region_UnionRectangle($pRegion, $tCairo_rectangle_int)
	If Not $pRegion Then Return SetError(1, 0, 0)
	If Not IsDllStruct($tCairo_rectangle_int) Then Return SetError(2, 0, 0)
	Local Const $aRegion = DllCall($g_hCairoDLL, "long:cdecl", "cairo_region_union_rectangle", "ptr", $pRegion, "struct*", $tCairo_rectangle_int)
	If @error Or Not IsArray($aRegion) Then Return SetError(3, 0, 0)
	Return $aRegion[0]
EndFunc

Func Cairo_Region_Xor($pRegion1, $pRegion2)
	If Not $pRegion1 Then Return SetError(1, 0, 0)
	If Not $pRegion2 Then Return SetError(2, 0, 0)
	Local Const $aRegion = DllCall($g_hCairoDLL, "long:cdecl", "cairo_region_xor", "ptr", $pRegion1, "ptr", $pRegion2)
	If @error Or Not IsArray($aRegion) Then Return SetError(3, 0, 0)
	Return $aRegion[0]
EndFunc

Func Cairo_Region_XorRectangle($pRegion, $tCairo_rectangle_int)
	If Not $pRegion Then Return SetError(1, 0, 0)
	If Not IsDllStruct($tCairo_rectangle_int) Then Return SetError(2, 0, 0)
	Local Const $aRegion = DllCall($g_hCairoDLL, "long:cdecl", "cairo_region_xor_rectangle", "ptr", $pRegion, "struct*", $tCairo_rectangle_int)
	If @error Or Not IsArray($aRegion) Then Return SetError(3, 0, 0)
	Return $aRegion[0]
EndFunc
#EndRegion Region

;-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#Region Matrix Transformations
Func Cairo_Matrix_Init(ByRef $tCairo_matrix_t, $fXX, $fYX, $fXY, $fYY, $fX0, $fY0)
	If Not IsDllStruct($tCairo_matrix_t) Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_matrix_init", "struct*", $tCairo_matrix_t, "double", $fXX, "double", $fYX, "double", $fXY, "double", $fYY, "double", $fX0, "double", $fY0)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Matrix_InitIdentity(ByRef $tCairo_matrix_t)
	If Not IsDllStruct($tCairo_matrix_t) Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_matrix_init_identity", "struct*", $tCairo_matrix_t)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Matrix_InitTranslate(ByRef $tCairo_matrix_t, $fTX, $fTY)
	If Not IsDllStruct($tCairo_matrix_t) Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_matrix_init_translate", "struct*", $tCairo_matrix_t, "double", $fTX, "double", $fTY)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Matrix_InitScale(ByRef $tCairo_matrix_t, $fSX, $fSY)
	If Not IsDllStruct($tCairo_matrix_t) Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_matrix_init_scale", "struct*", $tCairo_matrix_t, "double", $fSX, "double", $fSY)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Matrix_InitRotate(ByRef $tCairo_matrix_t, $fAngleR)
	If Not IsDllStruct($tCairo_matrix_t) Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_matrix_init_rotate", "struct*", $tCairo_matrix_t, "double", $fAngleR)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Matrix_Translate(ByRef $tCairo_matrix_t, $fTX, $fTY)
	If Not IsDllStruct($tCairo_matrix_t) Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_matrix_translate", "struct*", $tCairo_matrix_t, "double", $fTX, "double", $fTY)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Matrix_Scale(ByRef $tCairo_matrix_t, $fSX, $fSY)
	If Not IsDllStruct($tCairo_matrix_t) Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_matrix_scale", "struct*", $tCairo_matrix_t, "double", $fSX, "double", $fSY)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Matrix_Rotate(ByRef $tCairo_matrix_t, $fSX, $fSY)
	If Not IsDllStruct($tCairo_matrix_t) Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_matrix_rotate", "struct*", $tCairo_matrix_t, "double", $fSX, "double", $fSY)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Matrix_Invert(ByRef $tCairo_matrix_t)
	If Not IsDllStruct($tCairo_matrix_t) Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_matrix_invert", "struct*", $tCairo_matrix_t)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Matrix_Multiply(ByRef $tCairo_matrix_t, $tCairo_matrix_t_A, $tCairo_matrix_t_B)
	If Not IsDllStruct($tCairo_matrix_t) Then Return SetError(1, 0, 0)
	If Not IsDllStruct($tCairo_matrix_t_A) Then Return SetError(2, 0, 0)
	If Not IsDllStruct($tCairo_matrix_t_B) Then Return SetError(3, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_matrix_multiply", "struct*", $tCairo_matrix_t, "struct*", $tCairo_matrix_t_A, "struct*", $tCairo_matrix_t_B)
	If @error Or Not IsArray($aContext) Then Return SetError(4, 0, 0)
	Return 1
EndFunc

Func Cairo_Matrix_TransformDistance(ByRef $tCairo_matrix_t, $fDX, $fDY)
	If Not IsDllStruct($tCairo_matrix_t) Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_matrix_transform_distance", "struct*", $tCairo_matrix_t, "double", $fDX, "double", $fDY)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Matrix_TransformPoint(ByRef $tCairo_matrix_t, ByRef $fX, ByRef $fY)
	If Not IsDllStruct($tCairo_matrix_t) Then Return SetError(1, 0, 0)
	Local Const $aContext = DllCall($g_hCairoDLL, "none:cdecl", "cairo_matrix_transform_point", "struct*", $tCairo_matrix_t, "double", $fX, "double", $fY)
	If @error Or Not IsArray($aContext) Then Return SetError(2, 0, 0)
	Return 1
EndFunc
#EndRegion Matrix Transformations

;-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#Region Fonts
Func Cairo_Font_SelectFace($pContext, $sFamily = "Arial", $iSlant = $CAIRO_FONT_SLANT_NORMAL, $iWeight = $CAIRO_FONT_WEIGHT_NORMAL)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aFont = DllCall($g_hCairoDLL, "none:cdecl", "cairo_select_font_face", "ptr", $pContext, "wstr", $sFamily, "long", $iSlant, "long", $iWeight)
	If @error Or Not IsArray($aFont) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Font_SetSize($pContext, $fSize)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aFont = DllCall($g_hCairoDLL, "none:cdecl", "cairo_set_font_size", "ptr", $pContext, "double", $fSize)
	If @error Or Not IsArray($aFont) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_Font_SetMatrix($pContext, $tCairo_matrix)
	If Not $pContext Then Return SetError(1, 0, 0)
	If Not IsDllStruct($tCairo_matrix) Then Return SetError(2, 0, 0)
	Local Const $aFont = DllCall($g_hCairoDLL, "none:cdecl", "cairo_set_font_matrix", "ptr", $pContext, "struct*", $tCairo_matrix)
	If @error Or Not IsArray($aFont) Then Return SetError(3, 0, 0)
	Return 1
EndFunc

Func Cairo_Font_GetMatrix($pContext)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local $tMatrix = DllStructCreate($tagCairo_matrix)
	Local Const $aFont = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_get_font_matrix", "ptr", $pContext, "struct*", $tMatrix)
	If @error Or Not IsArray($aFont) Then Return SetError(2, 0, 0)
	If Not $aFont[0] Then Return SetError(3, 0, 0)
	Return $tMatrix
EndFunc

Func Cairo_Font_Show($pContext, $sString)
	If Not $pContext Then Return SetError(1, 0, 0)
	Local Const $aFont = DllCall($g_hCairoDLL, "none:cdecl", "cairo_show_text", "ptr", $pContext, "str", $sString)
	If @error Or Not IsArray($aFont) Then Return SetError(2, 0, 0)
	Return 1
EndFunc
#EndRegion Fonts
;-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#Region Fonts Scaled
Func Cairo_FontScaled_Create($pFont, $tFontMatrix, $tCTMatrix, $iFontOptions)
	If Not $pFont Then Return SetError(1, 0, 0)
	If Not IsDllStruct($tFontMatrix) Then Return SetError(2, 0, 0)
	If Not IsDllStruct($tCTMatrix) Then Return SetError(3, 0, 0)
	Local Const $aFont = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_scaled_font_create", "ptr", $pFont, "struct*", $tFontMatrix, "struct*", $tCTMatrix, "long", $iFontOptions)
	If @error Or Not IsArray($aFont) Then Return SetError(4, 0, 0)
	If Not $aFont[0] Then Return SetError(5, 0, 0)
	Return $aFont[0]
EndFunc

Func Cairo_FontScaled_Destroy($pFontScaled)
	If Not $pFontScaled Then Return SetError(1, 0, 0)
	Local Const $aFont = DllCall($g_hCairoDLL, "none:cdecl", "cairo_scaled_font_destroy", "ptr", $pFontScaled)
	If @error Or Not IsArray($aFont) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_FontScaled_IncreaseReference($pFontScaled)
	If Not $pFontScaled Then Return SetError(1, 0, 0)
	Local Const $aFont = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_scaled_font_reference", "ptr", $pFontScaled)
	If @error Or Not IsArray($aFont) Then Return SetError(2, 0, 0)
	If Not $aFont[0] Then Return SetError(3, 0, 0)
	Return $aFont[0]
EndFunc

Func Cairo_FontScaled_GetStatus($pFontScaled)
	If Not $pFontScaled Then Return SetError(1, 0, 0)
	Local Const $aFont = DllCall($g_hCairoDLL, "long:cdecl", "cairo_scaled_font_status", "ptr", $pFontScaled)
	If @error Or Not IsArray($aFont) Then Return SetError(2, 0, 0)
	If Not $aFont[0] Then Return SetError(3, 0, 0)
	Return $aFont[0]
EndFunc

Func Cairo_FontScaled_GetExtents($pFontScaled)
	If Not $pFontScaled Then Return SetError(1, 0, 0)
	Local $tExtents = DllStructCreate($tagCairo_font_extents_t)
	Local Const $aFont = DllCall($g_hCairoDLL, "none:cdecl", "cairo_scaled_font_extents", "ptr", $pFontScaled, "struct*", $tExtents)
	If @error Or Not IsArray($aFont) Then Return SetError(2, 0, 0)
	Return $tExtents
EndFunc

Func Cairo_FontScaled_GetTextExtents($pFontScaled, $sText)
	If Not $pFontScaled Then Return SetError(1, 0, 0)
	Local $tExtents = DllStructCreate($tagCairo_font_extents_t)
	Local Const $aFont = DllCall($g_hCairoDLL, "none:cdecl", "cairo_scaled_font_text_extents", "ptr", $pFontScaled, "wstr", $sText, "struct*", $tExtents)
	If @error Or Not IsArray($aFont) Then Return SetError(2, 0, 0)
	Return $tExtents
EndFunc

Func Cairo_FontScaled_GetGlyphExtents($pFontScaled, $tGlyph, $iNum)
	If Not $pFontScaled Then Return SetError(1, 0, 0)
	Local $tExtents = DllStructCreate($tagCairo_font_extents_t)
	Local Const $aFont = DllCall($g_hCairoDLL, "none:cdecl", "cairo_scaled_font_glyph_extents", "ptr", $pFontScaled, "struct*", $tGlyph, "long", $iNum, "struct*", $tExtents)
	If @error Or Not IsArray($aFont) Then Return SetError(2, 0, 0)
	Return $tExtents
EndFunc

Func Cairo_FontScaled_TextToGlyphs($pFontScaled, $fX, $fY, $sText)
	If Not $pFontScaled Then Return SetError(1, 0, 0)
	Local $tGlyph = DllStructCreate($tagCairo_glyph_t), $tCluster = DllStructCreate($tagCairo_text_cluster_t), $tGlyphNum = DllStructCreate("long num;"), $tClusterNum = DllStructCreate("long num;")
	Local Const $aFont = DllCall($g_hCairoDLL, "long:cdecl", "cairo_scaled_font_text_to_glyphs", "ptr", $pFontScaled, "double", $fX, "double", $fY, "wstr", $sText, "long", StringLen($sText) * 2, _
						 "struct*", $tGlyph, "struct*", $tGlyphNum, "struct*", $tCluster, "struct*", $tClusterNum, $CAIRO_TEXT_CLUSTER_FLAG_BACKWARD)
	If @error Or Not IsArray($aFont) Then Return SetError(2, 0, 0)
	Local $aResult[4] = [$tGlyph, $tGlyphNum.num, $tCluster, $tClusterNum.Num]
	Return SetExtended($aFont[0], $aResult)
EndFunc

Func Cairo_FontScaled_GetFontFace($pFontScaled)
	If Not $pFontScaled Then Return SetError(1, 0, 0)
	Local Const $aFont = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_scaled_font_get_font_face", "ptr", $pFontScaled)
	If @error Or Not IsArray($aFont) Then Return SetError(2, 0, 0)
	If Not $aFont[0] Then Return SetError(3, 0, 0)
	Return $aFont[0]
EndFunc

;~ Func Cairo_FontScaled_GetFontOptions($pFontScaled, $pFontOptions)
;~ 	If Not $pFontScaled Then Return SetError(1, 0, 0)
;~ 	If Not $pFontOptions Then Return SetError(2, 0, 0)
;~ 	Local Const $aFont = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_scaled_font_get_font_options", "ptr", $pFontScaled, "ptr", $pFontOptions)
;~ 	If @error Or Not IsArray($aFont) Then Return SetError(3, 0, 0)
;~ 	If Not $aFont[0] Then Return SetError(4, 0, 0)
;~ 	Return 1
;~ EndFunc

Func Cairo_FontScaled_GetFontMatrix($pFontScaled)
	If Not $pFontScaled Then Return SetError(1, 0, 0)
	Local $tMatrix = DllStructCreate($tagCairo_matrix)
	Local Const $aFont = DllCall($g_hCairoDLL, "none:cdecl", "cairo_scaled_font_get_font_matrix", "ptr", $pFontScaled, "struct*", $tMatrix)
	If @error Or Not IsArray($aFont) Then Return SetError(2, 0, 0)
	Return $tMatrix
EndFunc

Func Cairo_FontScaled_GetCTMatrix($pFontScaled)
	If Not $pFontScaled Then Return SetError(1, 0, 0)
	Local $tMatrix = DllStructCreate($tagCairo_matrix)
	Local Const $aFont = DllCall($g_hCairoDLL, "none:cdecl", "cairo_scaled_font_get_ctm", "ptr", $pFontScaled, "struct*", $tMatrix)
	If @error Or Not IsArray($aFont) Then Return SetError(2, 0, 0)
	Return $tMatrix
EndFunc

Func Cairo_FontScaled_GetScaleMatrix($pFontScaled)
	If Not $pFontScaled Then Return SetError(1, 0, 0)
	Local $tMatrix = DllStructCreate($tagCairo_matrix)
	Local Const $aFont = DllCall($g_hCairoDLL, "none:cdecl", "cairo_scaled_font_get_scale_matrix", "ptr", $pFontScaled, "struct*", $tMatrix)
	If @error Or Not IsArray($aFont) Then Return SetError(2, 0, 0)
	Return $tMatrix
EndFunc

Func Cairo_FontScaled_GetType($pFontScaled)
	If Not $pFontScaled Then Return SetError(1, 0, 0)
	Local Const $aFont = DllCall($g_hCairoDLL, "long:cdecl", "cairo_scaled_font_get_type", "ptr", $pFontScaled)
	If @error Or Not IsArray($aFont) Then Return SetError(2, 0, 0)
	If Not $aFont[0] Then Return SetError(3, 0, 0)
	Return $aFont[0]
EndFunc

Func Cairo_FontScaled_ReferenceCount($pFontScaled)
	If Not $pFontScaled Then Return SetError(1, 0, 0)
	Local Const $aFont = DllCall($g_hCairoDLL, "ulong:cdecl", "cairo_scaled_font_get_reference_count", "ptr", $pFontScaled)
	If @error Or Not IsArray($aFont) Then Return SetError(2, 0, 0)
	If Not $aFont[0] Then Return SetError(3, 0, 0)
	Return $aFont[0]
EndFunc

#EndRegion Fonts Scaled

;-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#Region Font Win32
Func Cairo_FontWin32_CreateLOGFONTW($tLOGFONTW)
	If Not IsDllStruct($tLOGFONTW) Then Return SetError(1, 0, 0)
	Local Const $aFontWin32 = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_win32_font_face_create_for_logfontw", "struct*", $tLOGFONTW)
	If @error Or Not IsArray($aFontWin32) Then Return SetError(2, 0, 0)
	If Not $aFontWin32[0] Then Return SetError(3, 0, 0)
	Return $aFontWin32[0]
EndFunc

Func Cairo_FontWin32_CreateHFONT($hFont)
	If Not $hFont Then Return SetError(1, 0, 0)
	Local Const $aFontWin32 = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_win32_font_face_create_for_hfont", "ptr", $hFont)
	If @error Or Not IsArray($aFontWin32) Then Return SetError(2, 0, 0)
	If Not $aFontWin32[0] Then Return SetError(3, 0, 0)
	Return $aFontWin32[0]
EndFunc

Func Cairo_FontWin32_CreateLOGFONTW_HFONT($tLOGFONTW, $hFont)
	If Not IsDllStruct($tLOGFONTW) Then Return SetError(1, 0, 0)
	If Not $hFont Then Return SetError(2, 0, 0)
	Local Const $aFontWin32 = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_win32_font_face_create_for_logfontw_hfont", "struct*", $tLOGFONTW, "ptr", $hFont)
	If @error Or Not IsArray($aFontWin32) Then Return SetError(3, 0, 0)
	If Not $aFontWin32[0] Then Return SetError(4, 0, 0)
	Return $aFontWin32[0]
EndFunc

Func Cairo_FontWin32_ScaledFontSelectFont($pFontScaled, $hDC)
	If Not $pFontScaled Then Return SetError(1, 0, 0)
	If Not $hDC Then Return SetError(2, 0, 0)
	Local Const $aFontWin32 = DllCall($g_hCairoDLL, "long:cdecl", "cairo_win32_scaled_font_select_font", "ptr", $pFontScaled, "ptr", $hDC)
	If @error Or Not IsArray($aFontWin32) Then Return SetError(3, 0, 0)
	If Not $aFontWin32[0] Then Return SetError(4, 0, 0)
	Return $aFontWin32[0]
EndFunc

Func Cairo_FontWin32_ReleaseFont($pFontScaled)
	If Not $pFontScaled Then Return SetError(1, 0, 0)
	Local Const $aFontWin32 = DllCall($g_hCairoDLL, "none:cdecl", "cairo_win32_scaled_font_done_font", "ptr", $pFontScaled)
	If @error Or Not IsArray($aFontWin32) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_FontWin32_GetMetricsFactor($pFontScaled)
	If Not $pFontScaled Then Return SetError(1, 0, 0)
	Local Const $aFontWin32 = DllCall($g_hCairoDLL, "double:cdecl", "cairo_win32_scaled_font_get_metrics_factor", "ptr", $pFontScaled)
	If @error Or Not IsArray($aFontWin32) Then Return SetError(2, 0, 0)
	If Not $aFontWin32[0] Then Return SetError(3, 0, 0)
	Return $aFontWin32[0]
EndFunc

Func Cairo_FontWin32_GetMatrixLogicalToDevice($pFontScaled)
	If Not $pFontScaled Then Return SetError(1, 0, 0)
	Local $tMatrix = DllStructCreate($tagCairo_matrix)
	Local Const $aFontWin32 = DllCall($g_hCairoDLL, "none:cdecl", "cairo_win32_scaled_font_get_logical_to_device", "ptr", $pFontScaled)
	If @error Or Not IsArray($aFontWin32) Then Return SetError(2, 0, 0)
	If Not $aFontWin32[0] Then Return SetError(3, 0, 0)
	Return $tMatrix
EndFunc

Func Cairo_FontWin32_GetMatrixDeviceToLogical($pFontScaled)
	If Not $pFontScaled Then Return SetError(1, 0, 0)
	Local $tMatrix = DllStructCreate($tagCairo_matrix)
	Local Const $aFontWin32 = DllCall($g_hCairoDLL, "none:cdecl", "cairo_win32_scaled_font_get_device_to_logical", "ptr", $pFontScaled)
	If @error Or Not IsArray($aFontWin32) Then Return SetError(2, 0, 0)
	If Not $aFontWin32[0] Then Return SetError(3, 0, 0)
	Return $tMatrix
EndFunc
#EndRegion Font Win32
;-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#Region Fonts Options
Func Cairo_FontOption_Create()
	Local Const $aFont = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_font_options_create")
	If @error Or Not IsArray($aFont) Then Return SetError(1, 0, 0)
	If Not $aFont[0] Then Return SetError(2, 0, 0)
	Return $aFont[0]
EndFunc

Func Cairo_FontOption_Destroy($pFontOption)
	If Not $pFontOption Then Return SetError(1, 0, 0)
	Local Const $aFont = DllCall($g_hCairoDLL, "none:cdecl", "cairo_font_options_destroy", "ptr", $pFontOption)
	If @error Or Not IsArray($aFont) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_FontOption_Copy($pFontOption)
	If Not $pFontOption Then Return SetError(1, 0, 0)
	Local Const $aFont = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_font_options_copy", "ptr", $pFontOption)
	If @error Or Not IsArray($aFont) Then Return SetError(2, 0, 0)
	If Not $aFont[0] Then Return SetError(3, 0, 0)
	Return $aFont[0]
EndFunc

Func Cairo_FontOption_Status($pFontOption)
	If Not $pFontOption Then Return SetError(1, 0, 0)
	Local Const $aFont = DllCall($g_hCairoDLL, "long:cdecl", "cairo_font_options_status", "ptr", $pFontOption)
	If @error Or Not IsArray($aFont) Then Return SetError(2, 0, 0)
	Return $aFont[0]
EndFunc

Func Cairo_FontOption_Merge($pFontOption1, $pFontOption2)
	If Not $pFontOption1 Then Return SetError(1, 0, 0)
	If Not $pFontOption2 Then Return SetError(2, 0, 0)
	Local Const $aFont = DllCall($g_hCairoDLL, "none:cdecl", "cairo_font_options_merge", "ptr", $pFontOption1, "ptr", $pFontOption2)
	If @error Or Not IsArray($aFont) Then Return SetError(3, 0, 0)
	Return 1
EndFunc

Func Cairo_FontOption_Hash($pFontOption)
	If Not $pFontOption Then Return SetError(1, 0, 0)
	Local Const $aFont = DllCall($g_hCairoDLL, "ulong:cdecl", "cairo_font_options_hash", "ptr", $pFontOption)
	If @error Or Not IsArray($aFont) Then Return SetError(2, 0, 0)
	If Not $aFont[0] Then Return SetError(3, 0, 0)
	Return $aFont[0]
EndFunc

Func Cairo_FontOption_Equal($pFontOption1, $pFontOption2)
	If Not $pFontOption1 Then Return SetError(1, 0, 0)
	If Not $pFontOption2 Then Return SetError(2, 0, 0)
	Local Const $aFont = DllCall($g_hCairoDLL, "bool:cdecl", "cairo_font_options_equal", "ptr", $pFontOption1, "ptr", $pFontOption2)
	If @error Or Not IsArray($aFont) Then Return SetError(3, 0, 0)
	Return $aFont[0]
EndFunc

Func Cairo_FontOption_SetAntialias($pFontOption, $iAntialias = $CAIRO_ANTIALIAS_DEFAULT)
	If Not $pFontOption Then Return SetError(1, 0, 0)
	Local Const $aFont = DllCall($g_hCairoDLL, "none:cdecl", "cairo_font_options_set_antialias", "ptr", $pFontOption, "long", $iAntialias)
	If @error Or Not IsArray($aFont) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_FontOption_GetAntialias($pFontOption)
	If Not $pFontOption Then Return SetError(1, 0, 0)
	Local Const $aFont = DllCall($g_hCairoDLL, "long:cdecl", "cairo_font_options_get_antialias", "ptr", $pFontOption)
	If @error Or Not IsArray($aFont) Then Return SetError(2, 0, 0)
	Return $aFont[0]
EndFunc

Func Cairo_FontOption_SetSubpixelOrder($pFontOption, $iSubpixel)
	If Not $pFontOption Then Return SetError(1, 0, 0)
	Local Const $aFont = DllCall($g_hCairoDLL, "none:cdecl", "cairo_font_options_set_subpixel_order", "ptr", $pFontOption, "long", $iSubpixel)
	If @error Or Not IsArray($aFont) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_FontOption_GetSubpixelOrder($pFontOption)
	If Not $pFontOption Then Return SetError(1, 0, 0)
	Local Const $aFont = DllCall($g_hCairoDLL, "long:cdecl", "cairo_font_options_get_subpixel_order", "ptr", $pFontOption)
	If @error Or Not IsArray($aFont) Then Return SetError(2, 0, 0)
	Return $aFont[0]
EndFunc

Func Cairo_FontOption_SetHintStyle($pFontOption, $iHintStyle)
	If Not $pFontOption Then Return SetError(1, 0, 0)
	Local Const $aFont = DllCall($g_hCairoDLL, "none:cdecl", "cairo_font_options_set_hint_style", "ptr", $pFontOption, "long", $iHintStyle)
	If @error Or Not IsArray($aFont) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_FontOption_GetHintStyle($pFontOption)
	If Not $pFontOption Then Return SetError(1, 0, 0)
	Local Const $aFont = DllCall($g_hCairoDLL, "long:cdecl", "cairo_font_options_get_hint_style", "ptr", $pFontOption)
	If @error Or Not IsArray($aFont) Then Return SetError(2, 0, 0)
	Return $aFont[0]
EndFunc

Func Cairo_FontOption_SetHintMetrics($pFontOption, $iHintMetrics)
	If Not $pFontOption Then Return SetError(1, 0, 0)
	Local Const $aFont = DllCall($g_hCairoDLL, "none:cdecl", "cairo_font_options_set_hint_metrics", "ptr", $pFontOption, "long", $iHintMetrics)
	If @error Or Not IsArray($aFont) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_FontOption_GetHintMetrics($pFontOption)
	If Not $pFontOption Then Return SetError(1, 0, 0)
	Local Const $aFont = DllCall($g_hCairoDLL, "long:cdecl", "cairo_font_options_get_hint_metrics", "ptr", $pFontOption)
	If @error Or Not IsArray($aFont) Then Return SetError(2, 0, 0)
	Return $aFont[0]
EndFunc

Func Cairo_FontOption_SetVariations($pFontOption, $iVariations)
	If Not $pFontOption Then Return SetError(1, 0, 0)
	Local Const $aFont = DllCall($g_hCairoDLL, "none:cdecl", "cairo_font_options_set_variations", "ptr", $pFontOption, "long", $iVariations)
	If @error Or Not IsArray($aFont) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_FontOption_GetVariations($pFontOption)
	If Not $pFontOption Then Return SetError(1, 0, 0)
	Local Const $aFont = DllCall($g_hCairoDLL, "long:cdecl", "cairo_font_options_get_variations", "ptr", $pFontOption)
	If @error Or Not IsArray($aFont) Then Return SetError(2, 0, 0)
	Return $aFont[0]
EndFunc

Func Cairo_FontOption_SetColorMode($pFontOption, $iColorMode)
	If Not $pFontOption Then Return SetError(1, 0, 0)
	Local Const $aFont = DllCall($g_hCairoDLL, "none:cdecl", "cairo_font_options_set_color_mode", "ptr", $pFontOption, "long", $iColorMode)
	If @error Or Not IsArray($aFont) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_FontOption_GetColorMode($pFontOption)
	If Not $pFontOption Then Return SetError(1, 0, 0)
	Local Const $aFont = DllCall($g_hCairoDLL, "long:cdecl", "cairo_font_options_get_color_mode", "ptr", $pFontOption)
	If @error Or Not IsArray($aFont) Then Return SetError(2, 0, 0)
	Return $aFont[0]
EndFunc

Func Cairo_FontOption_SetColorPalette($pFontOption, $iColorPalette = 0)
	If Not $pFontOption Then Return SetError(1, 0, 0)
	Local Const $aFont = DllCall($g_hCairoDLL, "none:cdecl", "cairo_font_options_set_color_mode", "ptr", $pFontOption, "ulong", $iColorPalette)
	If @error Or Not IsArray($aFont) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_FontOption_GetColorPalette($pFontOption)
	If Not $pFontOption Then Return SetError(1, 0, 0)
	Local Const $aFont = DllCall($g_hCairoDLL, "ulong:cdecl", "cairo_font_options_get_color_palette", "ptr", $pFontOption)
	If @error Or Not IsArray($aFont) Then Return SetError(2, 0, 0)
	Return $aFont[0]
EndFunc

Func Cairo_FontOption_SetColorCustomPalette($pFontOption, $iIndex, $fR, $fG, $fB, $fA = 1.0)
	If Not $pFontOption Then Return SetError(1, 0, 0)
	Local Const $aFont = DllCall($g_hCairoDLL, "none:cdecl", "cairo_font_options_set_custom_palette_color", "ptr", $pFontOption, "ulong", $iIndex, "double", $fR, "double", $fG, "double", $fB, "double", $fA)
	If @error Or Not IsArray($aFont) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_FontOption_GetColorCustomPalette($pFontOption, $iIndex = 0)
	If Not $pFontOption Then Return SetError(1, 0, 0)
	Local $tRed = DllStructCreate("double r;"), $tGreen = DllStructCreate("double g;"), _
		  $tBlue = DllStructCreate("double b;"), $tAlpha = DllStructCreate("double a;")
	Local Const $aFont = DllCall($g_hCairoDLL, "long:cdecl", "cairo_font_options_get_color_palette", "ptr", $pFontOption, "ulong", $iIndex, "struct*", $tRed, "struct*", $tGreen, "struct*", $tBlue, "struct*", $tAlpha)
	If @error Or Not IsArray($aFont) Then Return SetError(2, 0, 0)
	Local $aResult[3] = [$tRed.r, $tGreen.g, $tBlue.b, $tAlpha.a]
	Return $aResult
EndFunc
#EndRegion Fonts Options

;-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#Region Image Surface
Func Cairo_Image_Create($iW, $iH, $iFormat = $CAIRO_FORMAT_ARGB32)
	Local Const $aImage = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_image_surface_create", "long", $iFormat, "long", $iW, "long", $iH)
	If @error Or Not IsArray($aImage) Then Return SetError(1, 0, 0)
	If Not $aImage[0] Then Return SetError(2, 0, 0)
	Return $aImage[0]
EndFunc

Func Cairo_Image_CreateForData($pPixelData, $iW, $iH, $iStride, $iFormat = $CAIRO_FORMAT_ARGB32)
	If Not $pPixelData Then Return SetError(1, 0, 0)
	Local Const $aImage = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_image_surface_create_for_data", "ptr", $pPixelData, "long", $iFormat, "long", $iW, "long", $iH, "long", $iStride)
	If @error Or Not IsArray($aImage) Then Return SetError(2, 0, 0)
	If Not $aImage[0] Then Return SetError(3, 0, 0)
	Return $aImage[0]
EndFunc

Func Cairo_Image_GetData($pImage)
	If Not $pImage Then Return SetError(1, 0, 0)
	Local Const $aImage = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_image_surface_get_data", "ptr", $pImage)
	If @error Or Not IsArray($aImage) Then Return SetError(2, 0, 0)
	If Not $aImage[0] Then Return SetError(3, 0, 0)
	Return $aImage[0]
EndFunc

Func Cairo_Image_GetFormat($pImage)
	If Not $pImage Then Return SetError(1, 0, 0)
	Local Const $aImage = DllCall($g_hCairoDLL, "long:cdecl", "cairo_image_surface_get_format", "ptr", $pImage)
	If @error Or Not IsArray($aImage) Then Return SetError(2, 0, 0)
	If Not $aImage[0] Then Return SetError(3, 0, 0)
	Return $aImage[0]
EndFunc

Func Cairo_Image_GetWidth($pImage)
	If Not $pImage Then Return SetError(1, 0, 0)
	Local Const $aImage = DllCall($g_hCairoDLL, "long:cdecl", "cairo_image_surface_get_width", "ptr", $pImage)
	If @error Or Not IsArray($aImage) Then Return SetError(2, 0, 0)
	If Not $aImage[0] Then Return SetError(3, 0, 0)
	Return $aImage[0]
EndFunc

Func Cairo_Image_GetHeight($pImage)
	If Not $pImage Then Return SetError(1, 0, 0)
	Local Const $aImage = DllCall($g_hCairoDLL, "long:cdecl", "cairo_image_surface_get_height", "ptr", $pImage)
	If @error Or Not IsArray($aImage) Then Return SetError(2, 0, 0)
	If Not $aImage[0] Then Return SetError(3, 0, 0)
	Return $aImage[0]
EndFunc

Func Cairo_Image_GetStride($pImage)
	If Not $pImage Then Return SetError(1, 0, 0)
	Local Const $aImage = DllCall($g_hCairoDLL, "long:cdecl", "cairo_image_surface_get_stride", "ptr", $pImage)
	If @error Or Not IsArray($aImage) Then Return SetError(2, 0, 0)
	If Not $aImage[0] Then Return SetError(3, 0, 0)
	Return $aImage[0]
EndFunc

Func Cairo_Image_CreateFromPNG($sFilename)
	If Not FileExists($sFilename) Then Return SetError(1, 0, 0)
	Local Const $aImage = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_image_surface_create_from_png", "str", $sFilename)
	If @error Or Not IsArray($aImage) Then Return SetError(2, 0, 0)
	If Not $aImage[0] Then Return SetError(3, 0, 0)
	Return $aImage[0]
EndFunc

Func Cairo_Image_WriteToPNG($pSurface, $sFilename)
	If Not $pSurface Then Return SetError(1, 0, 0)
	If $sFilename = "" Then Return SetError(2, 0, 0)
	Local Const $aImage = DllCall($g_hCairoDLL, "long:cdecl", "cairo_surface_write_to_png", "ptr", $pSurface, "str", $sFilename)
	If @error Or Not IsArray($aImage) Then Return SetError(3, 0, 0)
	Return $aImage[0]
EndFunc
#EndRegion Image Surface

;-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#Region Image Raster
Func Cairo_Raster_CreateSource($pPixelData, $iW, $iH, $iContent = $CAIRO_CONTENT_COLOR_ALPHA)
	If Not $pPixelData Then Return SetError(1, 0, 0)
	Local Const $aPattern = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_pattern_create_raster_source", "ptr", $pPixelData, "long", $iContent, "long", $iW, "long", $iH)
	If @error Or Not IsArray($aPattern) Then Return SetError(2, 0, 0)
	Return $aPattern[0]
EndFunc
#EndRegion Image Raster

;-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#Region SVG
Func Cairo_SVG_VersionString()
	Local Const $aVersion = DllCall($g_hCairoDLL, "str:cdecl", "cairo_svg_version_to_string")
	If @error Or Not IsArray($aVersion) Then Return SetError(2, 0, 0)
	If Not $aVersion[0] Then Return SetError(2, 0, $aVersion[0])
	Return $aVersion[0]
EndFunc

Func Cairo_SVG_Create($sFilename, $fPointW, $fPointH) ;1 point == 1/72.0 inch
	Local Const $aSVG = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_svg_surface_create", "str", $sFilename, "double", $fPointW, "double", $fPointH)
	If @error Or Not IsArray($aSVG) Then Return SetError(1, 0, 0)
	If Not $aSVG[0] Then Return SetError(2, 0, 0)
	Return $aSVG[0]
EndFunc

Func Cairo_SVG_SetDocumentUnit($pSVG, $iUnit)
	If Not $pSVG Then Return SetError(1, 0, 0)
	Local Const $aSVG = DllCall($g_hCairoDLL, "none:cdecl", "cairo_svg_surface_set_document_unit", "ptr", $pSVG, "long", $iUnit)
	If @error Or Not IsArray($aSVG) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_SVG_GetDocumentUnit($pSVG)
	If Not $pSVG Then Return SetError(1, 0, 0)
	Local Const $aSVG = DllCall($g_hCairoDLL, "long:cdecl", "cairo_svg_surface_get_document_unit", "ptr", $pSVG)
	If @error Or Not IsArray($aSVG) Then Return SetError(2, 0, 0)
	Return $aSVG[0]
EndFunc

#EndRegion SVG

;-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#Region PDF
Func Cairo_PDF_VersionString()
	Local Const $aVersion = DllCall($g_hCairoDLL, "str:cdecl", "cairo_pdf_version_to_string")
	If @error Or Not IsArray($aVersion) Then Return SetError(2, 0, 0)
	If Not $aVersion[0] Then Return SetError(2, 0, $aVersion[0])
	Return $aVersion[0]
EndFunc

Func Cairo_PDF_Create($sFilename, $fPointW, $fPointH) ;1 point == 1/72.0 inch
	Local Const $aPDF = DllCall($g_hCairoDLL, "ptr:cdecl", "cairo_pdf_surface_create", "str", $sFilename, "double", $fPointW, "double", $fPointH)
	If @error Or Not IsArray($aPDF) Then Return SetError(1, 0, 0)
	If Not $aPDF[0] Then Return SetError(2, 0, 0)
	Return $aPDF[0]
EndFunc

Func Cairo_PDF_RestrictToVersion($pPDFSurface, $iPDFVersion)
	If Not $pPDFSurface Then Return SetError(1, 0, 0)
	Local Const $aPDF = DllCall($g_hCairoDLL, "none:cdecl", "cairo_pdf_surface_restrict_to_version", "ptr", $pPDFSurface, "long", $iPDFVersion)
	If @error Or Not IsArray($aPDF) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_PDF_SetSize($pPDFSurface, $fPointW, $fPointH)
	If Not $pPDFSurface Then Return SetError(1, 0, 0)
	Local Const $aPDF = DllCall($g_hCairoDLL, "none:cdecl", "cairo_pdf_surface_set_size", "ptr", $pPDFSurface, "double", $fPointW, "double", $fPointH)
	If @error Or Not IsArray($aPDF) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_PDF_AddOutline($pPDFSurface, $iParentID, $sOutline, $sLinkAttrib, $iOutlineFlag) ;1 point == 1/72.0 inch
	Local Const $aPDF = DllCall($g_hCairoDLL, "long:cdecl", "cairo_pdf_surface_add_outline", "ptr", $pPDFSurface, "long", $iParentID, "wstr", $sOutline, "wstr", $sLinkAttrib, "long", $iOutlineFlag)
	If @error Or Not IsArray($aPDF) Then Return SetError(1, 0, 0)
	If Not $aPDF[0] Then Return SetError(2, 0, 0)
	Return $aPDF[0]
EndFunc

Func Cairo_PDF_SetMetadata($pPDFSurface, $iMetadataItem, $sMetadataValue)
	If Not $pPDFSurface Then Return SetError(1, 0, 0)
	Local Const $aPDF = DllCall($g_hCairoDLL, "none:cdecl", "cairo_pdf_surface_set_metadata", "ptr", $pPDFSurface, "long", $iMetadataItem, "wstr", $sMetadataValue)
	If @error Or Not IsArray($aPDF) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_PDF_SetCustomMetadata($pPDFSurface, $sMetadataName, $sMetadataValue)
	If Not $pPDFSurface Then Return SetError(1, 0, 0)
	Local Const $aPDF = DllCall($g_hCairoDLL, "none:cdecl", "cairo_pdf_surface_set_custom_metadata", "ptr", $pPDFSurface, "wstr", $sMetadataName, "wstr", $sMetadataValue)
	If @error Or Not IsArray($aPDF) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_PDF_SetPageLabel($pPDFSurface, $sPageLabel)
	If Not $pPDFSurface Then Return SetError(1, 0, 0)
	Local Const $aPDF = DllCall($g_hCairoDLL, "none:cdecl", "cairo_pdf_surface_set_page_label", "ptr", $pPDFSurface, "wstr", $sPageLabel)
	If @error Or Not IsArray($aPDF) Then Return SetError(2, 0, 0)
	Return 1
EndFunc

Func Cairo_PDF_SetThumbnailSize($pPDFSurface, $iW, $iH)
	If Not $pPDFSurface Then Return SetError(1, 0, 0)
	Local Const $aPDF = DllCall($g_hCairoDLL, "none:cdecl", "cairo_pdf_surface_set_thumbnail_size", "ptr", $pPDFSurface, "long", $iW, "long", $iH)
	If @error Or Not IsArray($aPDF) Then Return SetError(2, 0, 0)
	Return 1
EndFunc
#EndRegion PDF
;-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#Region Self-defined functions
Func Cairo_ClearContext($pContext, $fR = 0, $fG = 0, $fB = 0, $fA = 1.0)
	If Not $pContext Then Return SetError(1, 0, 0)
	DllCall($g_hCairoDLL, "none:cdecl", "cairo_set_source_rgb", "ptr", $pContext, "double", $fR, "double", $fG, "double", $fB, "double", $fA)
	DllCall($g_hCairoDLL, "none:cdecl", "cairo_paint", "ptr", $pContext)
	Return 1
EndFunc

Func Cairo_SetColor($pContext, $fR = 0, $fG = 0, $fB = 0, $fA = 1.0)
	If Not $pContext Then Return SetError(1, 0, 0)
	DllCall($g_hCairoDLL, "none:cdecl", "cairo_set_source_rgb", "ptr", $pContext, "double", $fR, "double", $fG, "double", $fB, "double", $fA)
	Return 1
EndFunc

Func Cairo_SetLineWidth($pContext, $fLineWidth = 1)
	If Not $pContext Then Return SetError(1, 0, 0)
	DllCall($g_hCairoDLL, "none:cdecl", "cairo_set_line_width", "ptr", $pContext, "double", $fLineWidth)
	Return 1
EndFunc

Func Cairo_DrawRectangle($pContext, $x, $y, $w, $h)
	If Not $pContext Then Return SetError(1, 0, 0)
	DllCall($g_hCairoDLL, "none:cdecl", "cairo_rectangle", "ptr",  $pContext, "double", Int($x), "double", Int($y), "double", $w, "double", $h)
	DllCall($g_hCairoDLL, "none:cdecl", "cairo_stroke", "ptr", $pContext)
	Return 1
EndFunc

Func Cairo_FillRectangle($pContext, $x, $y, $w, $h)
	If Not $pContext Then Return SetError(1, 0, 0)
	DllCall($g_hCairoDLL, "none:cdecl", "cairo_rectangle", "ptr",  $pContext, "double", Int($x), "double", Int($y), "double", $w, "double", $h)
	DllCall($g_hCairoDLL, "none:cdecl", "cairo_fill", "ptr", $pContext)
	Return 1
EndFunc
#EndRegion Self-defined functions